/* feedlot-frontend · src/css/styles.css
   All application styles — imported by index.html.
   Variables are declared on :root for easy theming.
*/

/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-brand:       #14532d;
  --color-brand-mid:   #166534;
  --color-brand-light: #bbf7d0;
  --color-brand-pale:  #86efac;
  --color-accent:      #16a34a;
  --color-accent-dark: #15803d;
  --color-bg:          #f1f5f2;
  --color-surface:     #ffffff;
  --color-border:      #e5e7eb;
  --color-text:        #1a3a2a;
  --color-muted:       #6b7280;
  --color-blue:        #2563eb;
  --color-blue-dark:   #1d4ed8;
  --color-orange:      #ea580c;
  --color-red:         #dc2626;
  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --shadow-sm:  0 1px 4px rgba(0,0,0,.08);
  --transition: .15s ease;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  margin: 0;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: 240px;
  background: var(--color-brand);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  overflow: hidden;
}
#sidebar .brand {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--color-brand-mid);
}
#sidebar .brand h1 { font-size: 18px; font-weight: 700; color: var(--color-brand-light); }
#sidebar .brand p  { font-size: 11px; color: var(--color-brand-pale); margin-top: 3px; }

#sidebar nav { flex: 1; padding: 16px 10px; }
#sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-md);
  color: var(--color-brand-light); text-decoration: none;
  font-size: 13px; font-weight: 500; margin-bottom: 4px;
  transition: background var(--transition);
}
#sidebar nav a:hover, #sidebar nav a.active {
  background: var(--color-brand-mid); color: #fff;
}
#sidebar .footer {
  padding: 14px 20px;
  border-top: 1px solid var(--color-brand-mid);
  font-size: 11px; color: #4ade80;
}

/* ── Connection banner ────────────────────────────────────────────────────── */
#conn-banner {
  display: none;
  background: #fef2f2; border-bottom: 2px solid #fca5a5;
  padding: 8px 20px; font-size: 12px; color: #991b1b; text-align: center;
}
#conn-banner.visible { display: block; }

/* ── Top-level layout ─────────────────────────────────────────────────────── */
/* app-wrapper stacks the connection banner above the main body row */
#app-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* body-row holds sidebar (left) + main content (right) side by side */
#body-row {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
}

/* ── Main content area ────────────────────────────────────────────────────── */
#main        { flex: 1; overflow: auto; padding: 28px; }
.page        { display: none; }
.page.active { display: block; }

h2 { font-size: 24px; font-weight: 700; color: var(--color-text); margin-bottom: 6px; }
.sub { color: var(--color-muted); font-size: 13px; margin-bottom: 24px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px; margin-bottom: 20px;
}
.card h3 {
  font-size: 15px; font-weight: 600; color: var(--color-text);
  padding-bottom: 10px; border-bottom: 1px solid var(--color-border);
  margin-bottom: 16px;
}

/* ── Grid layouts ─────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ── Form controls ────────────────────────────────────────────────────────── */
label {
  display: block; font-size: 12px; font-weight: 600;
  color: #374151; margin-bottom: 4px; margin-top: 10px;
}
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select {
  width: 100%; padding: 8px 10px;
  border: 1px solid #d1d5db; border-radius: var(--radius-sm);
  font-size: 13px; outline: none; background: #fff;
  transition: border var(--transition);
}
input:focus, select:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(22,163,74,.15);
}
.info-box {
  background: #eff6ff; border: 1px solid #bfdbfe;
  border-radius: var(--radius-md); padding: 12px 16px;
  font-size: 12px; color: #1e40af; margin-top: 12px; line-height: 1.6;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-md); border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all var(--transition); text-decoration: none;
}
.btn-green  { background: var(--color-accent);  color: #fff; }
.btn-green:hover  { background: var(--color-accent-dark); }
.btn-blue   { background: var(--color-blue);  color: #fff; }
.btn-blue:hover   { background: var(--color-blue-dark); }
.btn-orange { background: var(--color-orange); color: #fff; }
.btn-orange:hover { background: #c2410c; }
.btn-red    { background: var(--color-red);    color: #fff; }
.btn-red:hover    { background: #b91c1c; }
.btn-gray   { background: #6b7280;  color: #fff; }
.btn-gray:hover   { background: #4b5563; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr  { background: var(--color-brand); color: #fff; }
thead th  { padding: 10px 14px; text-align: left; font-weight: 600; white-space: nowrap; }
tbody tr  { border-top: 1px solid #f3f4f6; }
tbody tr:hover { background: #f9fafb; }
tbody td  { padding: 9px 14px; }
.center   { text-align: center; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge       { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-blue  { background: #dbeafe; color: var(--color-blue-dark); }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert         { border-radius: var(--radius-md); padding: 14px 16px; font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
.alert-red     { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-yellow  { background: #fefce8; border: 1px solid #fde047; color: #92400e; }
.alert-green   { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.alert h4      { font-weight: 700; margin-bottom: 6px; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stat-card       { background: var(--color-surface); border-radius: 10px; padding: 16px; border: 1px solid var(--color-border); text-align: center; }
.stat-card .lbl  { font-size: 11px; color: var(--color-muted); margin-bottom: 4px; }
.stat-card .val  { font-size: 20px; font-weight: 700; color: var(--color-brand); }

/* ── Ingredient picker ────────────────────────────────────────────────────── */
.ing-list { max-height: 340px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.ing-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid #f3f4f6;
  cursor: pointer; transition: background var(--transition);
}
.ing-item:hover { background: #f0fdf4; }
.ing-item input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--color-accent); }
.ing-item .name { flex: 1; font-size: 13px; }
.ing-item .cp   { font-size: 11px; color: var(--color-muted); }

/* ── Selected ingredient config ───────────────────────────────────────────── */
.sel-card { border: 1px solid #d1d5db; border-radius: var(--radius-md); padding: 12px; margin-bottom: 10px; background: #fafafa; }
.sel-card .sel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sel-card .sel-name   { font-weight: 600; font-size: 13px; color: var(--color-text); }
.sel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* ── Nutrient table status ────────────────────────────────────────────────── */
.ok   { color: #15803d; font-weight: 600; }
.viol { color: var(--color-red);  font-weight: 600; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: var(--color-surface); border-radius: 14px; padding: 28px; width: 440px; max-width: 95vw; max-height: 90vh; overflow-y: auto; }
.modal h3 { font-size: 17px; font-weight: 700; color: var(--color-text); margin-bottom: 18px; }
.modal-btns { display: flex; gap: 10px; margin-top: 20px; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .6s linear infinite;
  vertical-align: middle; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Search row ───────────────────────────────────────────────────────────── */
.search-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-row input { flex: 1; min-width: 160px; }

/* ── Dashboard grid ───────────────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-top: 10px; }
.dash-card {
  background: var(--color-surface); border-radius: var(--radius-lg);
  border: 2px solid var(--color-border); padding: 22px;
  text-decoration: none; color: inherit; display: block;
  transition: box-shadow var(--transition), border-color var(--transition);
}
.dash-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); border-color: var(--color-accent); }
.dash-card .icon { font-size: 32px; margin-bottom: 10px; }
.dash-card h3    { font-size: 15px; font-weight: 700; color: var(--color-text); margin-bottom: 6px; }
.dash-card p     { font-size: 12px; color: var(--color-muted); line-height: 1.5; }

/* ── Saved rations list ───────────────────────────────────────────────────── */
.ration-row  { padding: 14px 16px; border-bottom: 1px solid #f3f4f6; display: flex; align-items: center; justify-content: space-between; }
.ration-row:hover { background: #f9fafb; }
.ration-name { font-weight: 600; font-size: 14px; color: var(--color-text); }
.ration-meta { font-size: 12px; color: var(--color-muted); margin-top: 2px; }

/* ── Editable inclusion inputs in results table ───────────────────────────── */
.inclusion-input {
  width: 72px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #f0fdf4;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-brand);
  text-align: center;
  transition: border var(--transition), background var(--transition), box-shadow var(--transition);
}
.inclusion-input:hover {
  border-color: var(--color-brand-pale);
  background: #dcfce7;
}
.inclusion-input:focus {
  border-color: var(--color-accent);
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(22,163,74,.2);
  outline: none;
}

/* ── Editable As-Fed inputs (per head / per pen) ─────────────────────────── */
.asfed-input {
  width: 82px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #eff6ff;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-blue-dark);
  text-align: center;
  transition: border var(--transition), background var(--transition), box-shadow var(--transition);
}
.asfed-input:hover {
  border-color: #bfdbfe;
  background: #dbeafe;
}
.asfed-input:focus {
  border-color: var(--color-blue);
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
  outline: none;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ── Authentication UI ────────────────────────────────────────────────────── */
/* ── Authentication UI ────────────────────────────────────────────────────── */
body.auth-mode #sidebar { display: none; }
body.auth-mode {
  background: linear-gradient(135deg, #14532d 0%, #166534 100%);
  position: relative;
}
/* Abstract background pattern for auth */
body.auth-mode::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: radial-gradient(circle at 20% 30%, rgba(187, 247, 208, 0.1) 0%, transparent 40%),
                    radial-gradient(circle at 80% 80%, rgba(187, 247, 208, 0.1) 0%, transparent 40%);
  z-index: 0;
}

body.auth-mode #main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  z-index: 1;
  background: transparent;
}
.auth-card {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.4);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  border: 1px solid rgba(255,255,255,0.2);
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo-bg {
  width: 100px;
  height: 100px;
  background: #ffffff;
  border-radius: 22px;
  box-shadow: 0 10px 20px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  border: 1px solid #f3f4f6;
}
.auth-logo {
  width: 70px;
  height: 70px;
  object-fit: contain;
}
.auth-header h2 {
  font-size: 26px;
  color: #111827;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}
.auth-header p {
  color: #6b7280;
  font-size: 14px;
}

.auth-card label {
  color: #4b5563;
  font-size: 13px;
  margin-bottom: 6px;
  margin-top: 14px;
}
.auth-card input {
  padding: 11px 14px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 14px;
  background: #f9fafb;
}
.auth-card input:focus {
  background: #ffffff;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}
.auth-card .btn-green {
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 4px 6px -1px rgba(22,163,74,0.2), 0 2px 4px -1px rgba(22,163,74,0.1);
  margin-top: 24px;
  letter-spacing: 0.2px;
}
.auth-card .btn-green:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 8px -1px rgba(22,163,74,0.25), 0 4px 6px -1px rgba(22,163,74,0.15);
}

.auth-card .auth-link {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: #6b7280;
}
.auth-card .auth-link a {
  color: var(--color-accent-dark);
  font-weight: 600;
  text-decoration: none;
}
.auth-card .auth-link a:hover {
  text-decoration: underline;
}

.auth-page { display: none; }
.auth-page.active { display: block; width: 100%; display: flex; justify-content: center; }

/* ── OTP verification inputs ─────────────────────────────────────────────── */
.otp-inputs {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 24px 0 8px;
}
input.otp-box {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  padding: 0;
  border: 2px solid #d1d5db;
  border-radius: 10px;
  background: #f9fafb;
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  caret-color: var(--color-accent);
}
input.otp-box:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
  background: #fff;
}
.otp-resend-row {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--color-muted);
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.otp-resend-btn {
  font-size: 13px;
  padding: 8px 16px;
}
.otp-spam-note {
  text-align: center;
  font-size: 12px;
  color: var(--color-muted);
  background: #fefce8;
  border: 1px solid #fde047;
  border-radius: 8px;
  padding: 9px 14px;
  margin-top: 14px;
  line-height: 1.5;
}
@media (max-width: 480px) {
  input.otp-box { width: 40px; height: 48px; font-size: 18px; }
  .otp-inputs   { gap: 7px; }
}

/* ── AI Nutrition Advisor Panel ─────────────────────────────────────────────── */

#ai-advisor-panel {
  /* Flex child of #body-row — pushes #main aside when open */
  flex-shrink: 0;
  width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #ffffff;
  transition: width .3s cubic-bezier(.4,0,.2,1), border-width .3s;
  border-left: 0 solid #d1fae5;
}
#ai-advisor-panel.open {
  width: 380px;
  border-left: 2px solid #d1fae5;
  box-shadow: -4px 0 20px rgba(0,0,0,.10);
}

.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #14532d 0%, #166534 100%);
  color: white;
  flex-shrink: 0;
}
.ai-panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-avatar {
  font-size: 28px;
  line-height: 1;
}
.ai-panel-title strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
}
.ai-subtitle {
  font-size: 11px;
  opacity: .8;
  display: block;
}
.ai-close-btn {
  background: rgba(255,255,255,.2);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.ai-close-btn:hover { background: rgba(255,255,255,.35); }

.ai-chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f9fafb;
}
.ai-msg {
  max-width: 92%;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 12px;
  word-break: break-word;
}
.ai-msg-user {
  align-self: flex-end;
  background: #14532d;
  color: white;
  border-bottom-right-radius: 2px;
}
.ai-msg-assistant {
  align-self: flex-start;
  background: white;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 2px;
  box-shadow: var(--shadow-sm);
  max-width: 100%;
}
.ai-msg-text {
  color: #1a3a2a;
  line-height: 1.6;
}
.ai-msg-user .ai-msg-text { color: white; }
.ai-msg-warning {
  margin-top: 8px;
  padding: 6px 10px;
  background: #fefce8;
  border-left: 3px solid #ca8a04;
  border-radius: 4px;
  font-size: 12px;
  color: #713f12;
}
.ai-mode-badge {
  margin-top: 8px;
  font-size: 11px;
  color: var(--color-muted);
  opacity: .75;
}

/* Typing indicator */
.ai-msg-loading { padding: 14px 16px; }
.ai-typing { display: flex; gap: 4px; align-items: center; }
.ai-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #14532d;
  animation: ai-bounce .8s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes ai-bounce {
  0%,80%,100% { transform: scale(0); opacity:.4; }
  40%         { transform: scale(1); opacity:1; }
}

/* Suggestions */
.ai-suggestions {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-suggestion {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 12px;
}
.sug-header {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.sug-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.sug-up   { background: #dcfce7; color: #15803d; }
.sug-down { background: #fee2e2; color: #b91c1c; }
.sug-pct  { margin-left: auto; font-weight: 700; color: #1d4ed8; font-size: 11px; }
.sug-reason { color: #374151; margin-bottom: 3px; }
.sug-impact { color: #6b7280; font-size: 11px; margin-bottom: 6px; }
.sug-apply-btn {
  padding: 5px 14px !important;
  font-size: 11px !important;
  border-radius: 999px !important;
}

/* Chat input row */
.ai-chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: white;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}
#ai-chat-input {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  resize: none;
  font-family: inherit;
  line-height: 1.5;
}
#ai-chat-input:focus { outline: none; border-color: var(--color-accent); }
#ai-chat-send { align-self: flex-end; padding: 8px 14px; }

/* Floating re-open button */
.ai-panel-fab {
  position: fixed;
  bottom: 28px;
  right: 24px;
  z-index: 400;
  background: linear-gradient(135deg, #14532d, #16a34a);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(20,83,45,.4);
  transition: transform .15s, box-shadow .15s;
}
.ai-panel-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(20,83,45,.5);
}

/* ── Mobile header ────────────────────────────────────────────────────────── */
#mobile-header {
  display: none;
}

/* ── Sidebar backdrop ─────────────────────────────────────────────────────── */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
}
#sidebar-backdrop.visible { display: block; }

/* ── Tablet breakpoint (≤ 900px) ──────────────────────────────────────────── */
@media (max-width: 900px) {
  /* Show mobile header */
  #mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    height: 54px;
    background: var(--color-brand);
    flex-shrink: 0;
    z-index: 100;
    position: relative;
  }

  /* Hamburger button */
  #hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
  }
  #hamburger-btn:hover { background: rgba(255,255,255,0.1); }
  #hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: #bbf7d0;
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.3s ease;
  }
  /* Animate hamburger → X when sidebar is open */
  #sidebar.open ~ * #hamburger-btn span:nth-child(1),
  body.sidebar-open #hamburger-btn span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  body.sidebar-open #hamburger-btn span:nth-child(2) { opacity: 0; }
  body.sidebar-open #hamburger-btn span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    color: #bbf7d0;
    letter-spacing: -0.3px;
  }
  .mobile-brand img {
    width: 30px;
    height: 30px;
    object-fit: contain;
    background: white;
    border-radius: 6px;
    padding: 3px;
  }

  #mobile-ai-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: var(--radius-md);
    padding: 7px 12px;
    font-size: 18px;
    cursor: pointer;
    color: white;
    transition: background var(--transition);
  }
  #mobile-ai-btn:hover { background: rgba(255,255,255,0.25); }

  /* Sidebar — slide-in overlay on mobile */
  #sidebar {
    position: fixed;
    left: -270px;
    top: 0;
    height: 100%;
    width: 260px;
    z-index: 200;
    transition: left 0.28s cubic-bezier(.4,0,.2,1);
    box-shadow: none;
  }
  #sidebar.open {
    left: 0;
    box-shadow: 6px 0 24px rgba(0,0,0,0.25);
  }

  /* Body row — no sidebar space needed */
  #body-row {
    position: relative;
  }

  /* Main — full width, reduced padding */
  #main { padding: 18px 16px; }

  /* Headings */
  h2 { font-size: 20px; }

  /* AI panel — full-screen overlay on mobile */
  #ai-advisor-panel.open {
    position: fixed;
    inset: 0;
    width: 100% !important;
    z-index: 300;
    border-left: none !important;
  }

  /* FAB reposition */
  .ai-panel-fab {
    bottom: 16px;
    right: 16px;
    padding: 10px 16px;
    font-size: 12px;
  }

  /* Search row — stack on tablet */
  .search-row {
    flex-direction: column;
    align-items: stretch;
  }
  .search-row input,
  .search-row select { width: 100%; min-width: unset; }
  .search-row .btn,
  .search-row label.btn { width: 100%; justify-content: center; text-align: center; }

  /* Ration rows — stack name & buttons */
  .ration-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .ration-row > div:last-child { width: 100%; display: flex; gap: 8px; }
  .ration-row > div:last-child .btn { flex: 1; justify-content: center; }

  /* sel-grid: 2 columns instead of 3 */
  .sel-grid { grid-template-columns: 1fr 1fr; }

  /* btn-row — stack action buttons */
  .btn-row { flex-direction: column; }
  .btn-row .btn { width: 100%; justify-content: center; }

  /* grid-4 stays 2 cols (already handled above at 900px) */
}

/* ── Small phone breakpoint (≤ 480px) ────────────────────────────────────── */
@media (max-width: 480px) {
  #main { padding: 12px; }

  .card { padding: 14px; }

  h2 { font-size: 18px; }
  .sub { font-size: 12px; margin-bottom: 16px; }

  /* Dashboard — single column on very small screens */
  .dash-grid { grid-template-columns: 1fr; }

  /* Dash card compact */
  .dash-card { padding: 16px; }
  .dash-card .icon { font-size: 26px; margin-bottom: 8px; }

  /* Ingredient config — single column */
  .sel-grid { grid-template-columns: 1fr; }

  /* Auth card — tighter padding */
  .auth-card { padding: 24px 18px; }
  .auth-header h2 { font-size: 22px; }
  .auth-logo-bg { width: 80px; height: 80px; }
  .auth-logo { width: 56px; height: 56px; }

  /* Stat cards */
  .stat-card .val { font-size: 17px; }

  /* grid-4: 2 cols on small phone too */
  .grid-4 { grid-template-columns: 1fr 1fr; }

  /* Modal: ensure full comfort */
  .modal { padding: 20px 16px; }

  /* Profile cards — override inline max-width */
  #page-profile .card { max-width: 100% !important; }

  /* Connection settings buttons — stack */
  #page-profile .card > div[style*="display:flex"] {
    flex-direction: column;
  }
  #page-profile .card > div[style*="display:flex"] .btn {
    width: 100%;
    justify-content: center;
  }

  /* Formulate results header flex — stack on very small */
  #results-section .card > div[style*="display:flex"] {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Inclusion table reset button — full width on tiny screens */
  #btn-reset-optimizer { width: 100%; justify-content: center; margin-top: 8px; }
}

/* ── Global loading overlay ───────────────────────────────────────────────── */
#global-loader {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 8000;
  background: rgba(20, 83, 45, 0.10);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
}
#global-loader.visible {
  display: flex;
}
.loader-card {
  background: #ffffff;
  border-radius: 18px;
  padding: 36px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(187, 247, 208, 0.6);
  min-width: 180px;
}
.loader-ring {
  width: 48px;
  height: 48px;
  border: 4px solid #bbf7d0;
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
#loader-msg {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  letter-spacing: 0.1px;
}
