:root {
  --bg-dark: #0b0f19;
  --bg-card: rgba(23, 31, 48, 0.78);
  --bg-card-hover: rgba(30, 41, 64, 0.9);
  --bg-input: #0f172a;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #10b981;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #0ea5e9;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px -5px var(--primary-glow);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.08) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  /* Extra bottom padding reserves space for the floating mobile bottom bar */
  padding: 12px 10px calc(80px + env(safe-area-inset-bottom, 0px)) 10px;
}

.app-container {
  max-width: 1320px;
  margin: 0 auto;
}

/* ==========================================================================
   Header (Mobile First)
   ========================================================================== */
.main-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.header-branding {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-glow);
  flex-shrink: 0;
}

h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.4px;
  background: linear-gradient(135deg, #ffffff 40%, #10b981 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.header-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-primary {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge-info {
  background: rgba(14, 165, 233, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(14, 165, 233, 0.3);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-admin {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  text-decoration: none;
  transition: var(--transition);
}

.badge-admin:hover,
.badge-admin:focus-visible {
  color: var(--text-main);
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.12);
}

/* ==========================================================================
   Sticky Mobile Step Navigation Pills
   ========================================================================== */
.mobile-step-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0 10px 0;
  margin-bottom: 12px;
  scrollbar-width: none;
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mobile-step-nav::-webkit-scrollbar {
  display: none;
}

.step-nav-pill {
  white-space: nowrap;
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  text-decoration: none;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.step-nav-pill:hover,
.step-nav-pill.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}

/* ==========================================================================
   Presets Bar (Mobile First Horizontal Swipeable Carousel)
   ========================================================================== */
.preset-card {
  padding: 12px 14px;
  margin-bottom: 14px;
}

.preset-header {
  margin-bottom: 8px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.preset-buttons {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 8px;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.preset-buttons::-webkit-scrollbar {
  display: none;
}

.btn-preset {
  white-space: nowrap;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}

.btn-preset:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-preset.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--primary);
  color: #34d399;
  box-shadow: 0 2px 8px -2px var(--primary-glow);
}

/* ==========================================================================
   Cards & Layout
   ========================================================================== */
.two-column-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px 14px;
  box-shadow: var(--shadow-card);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #042f2e;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: #ffffff;
  flex: 1;
  letter-spacing: -0.2px;
}

.btn-toggle-card {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-toggle-card:hover {
  color: #ffffff;
}

.section-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ==========================================================================
   Step 1: Form Controls (Mobile First Single Column)
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

/* 16px font-size prevents disruptive auto-zooming on iOS devices */
input, select {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
  min-height: 44px;
  width: 100%;
}

input:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ==========================================================================
   Step 2: Calculated Needs KPIs & Details
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.kpi-box {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.kpi-box::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
}

.kpi-box.highlight-energy::after { background: #10b981; }
.kpi-box.highlight-protein::after { background: #6366f1; }
.kpi-box.highlight-roughage::after { background: #f59e0b; }
.kpi-box.highlight-intake::after { background: #0ea5e9; }

.kpi-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.kpi-value {
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
  margin: 2px 0;
}

.kpi-sub {
  font-size: 10.5px;
  color: var(--text-muted);
}

.details-section {
  margin-top: 6px;
}

.btn-full-mobile {
  width: 100%;
  justify-content: center;
  min-height: 38px;
}

.details-table-wrapper {
  margin-top: 10px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  -webkit-overflow-scrolling: touch;
}

/* Responsive Table Wrapper */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  text-align: left;
  min-width: 460px;
}

.data-table th {
  background: rgba(15, 23, 42, 0.95);
  padding: 8px 10px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  white-space: nowrap;
}

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* ==========================================================================
   Dual Mode Switcher
   ========================================================================== */
.mode-switch-wrapper {
  margin-bottom: 14px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  background: rgba(15, 23, 42, 0.7);
  padding: 5px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.mode-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  min-height: 48px;
}

.mode-tab:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.mode-tab.active {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.45);
  color: #ffffff;
  box-shadow: 0 4px 14px -4px var(--primary-glow);
}

.mode-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.mode-text {
  display: flex;
  flex-direction: column;
}

.mode-title {
  font-family: 'Outfit', sans-serif;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.mode-subtitle {
  font-size: 11px;
  color: var(--text-dim);
}

.mode-tab.active .mode-subtitle {
  color: #a7f3d0;
}

/* ==========================================================================
   Step 3: Feeds Selection & Input
   ========================================================================== */
.feed-quick-actions {
  margin-bottom: 12px;
}

.feed-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-action-pill {
  padding: 7px 14px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-action-pill:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-action-pill.btn-highlight {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}

.optimize-maintain-card {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.optimize-maintain-card.is-enabled {
  border-color: rgba(16, 185, 129, 0.5);
  background: rgba(16, 185, 129, 0.08);
}

.maintain-toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.maintain-toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  margin-top: 2px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.maintain-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
}

.maintain-desc {
  display: block;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

.maintain-summary-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.maintain-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 9999px;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #a7f3d0;
}

.feeds-filter-bar {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feeds-search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.feeds-search-box .search-icon {
  position: absolute;
  left: 12px;
  font-size: 14px;
  pointer-events: none;
  opacity: 0.7;
}

.feeds-search-box input {
  padding: 8px 36px;
  font-size: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  min-height: 42px;
}

.btn-clear-search {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
}

.feeds-category-pills {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 6px;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.feeds-category-pills::-webkit-scrollbar {
  display: none;
}

.pill-btn {
  white-space: nowrap;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  min-height: 36px;
}

.pill-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.pill-btn.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}

.pill-in-ration.active {
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fbbf24;
}

.feeds-brand-pills {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 6px;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.feeds-brand-pills::-webkit-scrollbar {
  display: none;
}

.pill-btn-brand.active {
  background: rgba(14, 165, 233, 0.18);
  border-color: rgba(14, 165, 233, 0.5);
  color: #38bdf8;
}

.btn-reset-filters {
  margin-top: 8px;
}

/* Feed List Items (Mobile First Stacked Card) */
.feeds-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 440px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.feed-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: var(--transition);
}

.feed-item.in-ration {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.07);
  box-shadow: 0 2px 10px -2px rgba(16, 185, 129, 0.25);
}

.feed-item.selected {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.05);
}

.feed-name {
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.feed-sub {
  font-size: 11px;
  color: var(--text-dim);
}

/* Feed Mobile Control Bar */
.feed-inputs-group {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: rgba(0, 0, 0, 0.22);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.feed-amount-input-box {
  display: flex;
  align-items: center;
  gap: 4px;
}

.feed-stepper-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 28px;
  height: 36px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.feed-stepper-btn:active {
  background: var(--primary);
  color: #042f2e;
}

.feed-amount-input-box input {
  width: 52px;
  height: 36px;
  min-height: 36px;
  padding: 4px 6px;
  font-size: 15px;
  font-weight: 700;
  text-align: right;
  border-radius: 4px;
}

.feed-amount-unit {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.feed-price-input {
  display: flex;
  align-items: center;
  gap: 2px;
  justify-content: flex-end;
}

.feed-price-input input {
  width: 54px;
  height: 36px;
  min-height: 36px;
  padding: 4px 6px;
  font-size: 14px;
  text-align: right;
  border-radius: 4px;
}

.feed-price-label {
  font-size: 11px;
  color: var(--text-dim);
}

.feed-line-cost {
  font-size: 12px;
  color: #34d399;
  font-weight: 700;
  min-width: 52px;
  text-align: right;
}

/* Optimize Mode Checkbox Row */
.feed-item:has(.feed-checkbox) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.feed-checkbox {
  width: 22px;
  height: 22px;
  min-height: 22px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* ==========================================================================
   Buttons & Action Bars
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-large {
  width: 100%;
  padding: 14px 16px;
  font-size: 15px;
  min-height: 48px;
  border-radius: var(--radius-md);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 14px;
  font-size: 12px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* ==========================================================================
   Floating Mobile Bottom Action Bar
   ========================================================================== */
.mobile-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)) 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

.bottom-bar-summary {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.bottom-summary-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bottom-summary-sub {
  font-size: 11px;
  color: #34d399;
  font-weight: 600;
}

.btn-bottom-action {
  padding: 10px 18px;
  font-size: 14px;
  min-height: 42px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Step 4: Results (Alerts, KPIs, Stacked Chart, Toxicity)
   ========================================================================== */
.results-wrapper {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.analysis-alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 12.5px;
  line-height: 1.5;
}

.analysis-alert.alert-warning {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fef3c7;
}

.analysis-alert.alert-success {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #d1fae5;
}

.analysis-alert-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 13.5px;
}

.analysis-alert ul {
  margin: 0;
  padding-left: 18px;
}

.results-kpi-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.result-kpi {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.result-label {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 700;
  text-transform: uppercase;
}

.result-value {
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  margin: 2px 0;
}

.result-kpi.highlight-cost .result-value {
  color: #34d399;
  font-size: 20px;
}

.result-sub {
  font-size: 10.5px;
  color: var(--text-muted);
}

.results-section {
  margin-bottom: 18px;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 14.5px;
  font-weight: 700;
  color: #ffffff;
}

/* Stacked Nutrient Contribution Breakdown Chart */
.stacked-chart-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.result-section-header-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.section-title-with-badge {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.badge-added {
  background: rgba(14, 165, 233, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(14, 165, 233, 0.4);
}

.res-diff-note {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.nutrient-filter-pills {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 6px;
  margin-bottom: 12px;
  scrollbar-width: none;
}

.nutrient-filter-pills::-webkit-scrollbar {
  display: none;
}

.nut-filter-btn {
  white-space: nowrap;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  min-height: 34px;
}

.nut-filter-btn.active {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.5);
  color: #a5b4fc;
}

.nut-filter-btn-attention.has-issues {
  border-color: rgba(245, 158, 11, 0.35);
  color: #fcd34d;
}

.nut-filter-btn-attention.has-issues.active {
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fbbf24;
}

.nut-filter-btn-attention.all-clear.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}

.feed-color-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 8px 10px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-main);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.stacked-bars-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stacked-bar-card {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 10px;
}

.stacked-bar-card.card-attention-warn {
  border-left: 3px solid var(--warning);
}

.stacked-bar-card.card-attention-danger {
  border-left: 3px solid var(--danger);
}

.tox-exceeded-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 9999px;
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.excess-warn-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 9999px;
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.stacked-excess-note {
  font-size: 11px;
  color: #fcd34d;
  margin-bottom: 6px;
}

.stacked-bar-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.stacked-bar-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #ffffff;
}

.stacked-bar-stats {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stacked-bar-qty {
  color: var(--text-muted);
}

.stacked-bar-pct-badge {
  font-weight: 700;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 9999px;
}

.pct-badge-ok { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.pct-badge-warn { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.pct-badge-danger { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.pct-badge-high { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }

.stacked-track-container {
  position: relative;
  height: 20px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  margin-bottom: 6px;
}

.stacked-segments-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  display: flex;
  border-radius: 6px;
  overflow: hidden;
}

.stacked-segment {
  height: 100%;
  position: relative;
  transition: width 0.3s ease-out;
  cursor: pointer;
}

.norm-marker-line {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  background: #ffffff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.8);
  z-index: 5;
  pointer-events: none;
}

.norm-marker-label {
  position: absolute;
  top: -16px;
  transform: translateX(-50%);
  font-size: 8.5px;
  font-weight: 700;
  color: #e2e8f0;
  background: rgba(15, 23, 42, 0.9);
  padding: 1px 3px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  white-space: nowrap;
}

.stacked-breakdown-details {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 8px;
  font-size: 10.5px;
  color: var(--text-dim);
  padding-top: 2px;
}

.breakdown-feed-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.breakdown-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

/* Optimization Progress Bars */
.coverage-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.coverage-item {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.coverage-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
}

.coverage-name { font-weight: 600; color: #ffffff; }
.coverage-pct { font-weight: 700; }

.progress-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 9999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.4s ease-out;
}

.fill-optimal { background: #10b981; }
.fill-high { background: #3b82f6; }
.fill-warn { background: #f59e0b; }
.fill-danger { background: #ef4444; }

/* Toxicity Badges */
.toxicity-badges {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toxicity-badge-box {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* Footer */
.main-footer {
  text-align: center;
  padding: 20px 0 10px 0;
  font-size: 11.5px;
  color: var(--text-dim);
}

.loading-spinner {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ==========================================================================
   Tablet Enhancements (@media (min-width: 641px))
   ========================================================================== */
@media (min-width: 641px) {
  body {
    padding: 18px 16px 24px 16px;
  }

  .main-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .header-badges {
    width: auto;
  }

  .mobile-step-nav {
    display: none; /* Desktop/tablet has everything easily reachable */
  }

  .mobile-bottom-bar {
    display: none; /* Buttons are contained within the card */
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  .form-group-full {
    grid-column: 1 / -1;
  }

  .mode-switch {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .results-kpi-bar {
    grid-template-columns: repeat(4, 1fr);
  }

  .coverage-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .toxicity-badges {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .toxicity-badge-box {
    width: auto;
    flex: 1 1 calc(33% - 10px);
  }

  .card {
    padding: 20px;
  }
}

/* ==========================================================================
   Desktop Enhancements (@media (min-width: 1024px))
   ========================================================================== */
@media (min-width: 1024px) {
  .two-column-layout {
    display: grid;
    grid-template-columns: 460px 1fr;
    gap: 22px;
    align-items: start;
  }

  h1 {
    font-size: 27px;
  }

  .card {
    padding: 22px;
  }

  .preset-buttons {
    flex-wrap: wrap;
  }

  .btn-toggle-card {
    display: none; /* Always expanded on large desktop screens */
  }
}
