:root {
  /* Telegram injects these; sensible fallbacks for out-of-Telegram preview. */
  --bg: var(--tg-theme-bg-color, #0f1115);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #1a1d23);
  --text: var(--tg-theme-text-color, #f5f6f8);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #4ea1ff);
  --accent: var(--tg-theme-button-color, #4ea1ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);

  /* Status (how the day is going) — used by the ring, bars and day summaries. */
  --p: #FF3B5C;   /* off track / over budget / danger */
  --f: #30D158;   /* on track                         */
  --warn: #34C759; /* amber: drifting off target      */

  /* Macro identity — protein / carbs / fat, shown wherever macros appear. */
  --mp: #0A84FF;  /* protein */
  --mc: #FF9F0A;  /* carbs   */
  --mf: #7B61FF;  /* fat     */
  --radius: 18px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  --hairline: rgba(128, 128, 128, 0.16);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }

/* ---- Loader ---- */
.loader { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--secondary-bg);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner-sm { width: 24px; height: 24px; border-width: 2.5px; border-color: rgba(255,255,255,0.25); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Gate (errors / onboarding) ---- */
.gate {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: 32px; gap: 12px;
}
.gate-emoji { font-size: 64px; }
.gate h2 { margin: 0; font-size: 22px; }
.gate p { margin: 0; color: var(--hint); max-width: 300px; line-height: 1.5; }
.gate .btn { margin-top: 16px; }

/* ---- Welcome (first run): scan before goal setup ---- */
.welcome-actions {
  width: 100%; max-width: 320px;
  display: flex; flex-direction: column; gap: 10px;
}
/* The buttons live inside .welcome-actions, so the gap controls spacing — drop
   the .gate .btn top margin that would otherwise stack with it. */
.welcome-actions .btn { margin-top: 0; }
.welcome-logged {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 320px;
  background: var(--secondary-bg); border-radius: 12px; padding: 12px 16px;
  font-size: 14px; font-weight: 600;
}

/* ---- App layout ---- */
.app {
  padding: calc(var(--safe-top, env(safe-area-inset-top, 0px)) + 6px) 16px
           calc(96px + env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto;
}

/* ---- Calorie arc (semicircle) ---- */
.arc-wrap { position: relative; width: 100%; max-width: 300px; margin: 4px auto 2px; }
.arc { display: block; width: 100%; height: auto; overflow: visible; }
.arc-track { fill: none; stroke: var(--secondary-bg); stroke-width: 13; stroke-linecap: round; }
.arc-fill {
  fill: none; stroke: url(#cal-grad); stroke-width: 13; stroke-linecap: round;
  stroke-dasharray: 0 9999;
  transition: stroke-dasharray 0.9s cubic-bezier(.4,0,.2,1), stroke 0.3s;
}
.arc-center {
  position: absolute; left: 0; right: 0; bottom: 8px;
  display: flex; flex-direction: column; align-items: center;
}
.arc-num { font-size: 40px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; color: var(--text); }
.arc-of { font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--hint); font-weight: 600; margin-top: 6px; }
.arc-sub { margin-top: 9px; font-size: 13px; font-weight: 700; color: var(--hint); min-height: 16px; }
.arc-sub.over { color: var(--p); }
.arc-sub.warn { color: var(--warn); }
.arc-sub.good { color: var(--f); }
/* Compact chip in the empty top-right corner above the semicircle arc. */
.streak-badge {
  position: absolute; top: 2px; right: 0; z-index: 2;
  display: inline-flex; align-items: center;
  background: rgba(255, 59, 92, 0.12);
  border: 1px solid rgba(255, 59, 92, 0.28);
  border-radius: 20px;
  padding: 3px 10px 3px 8px;
  font-size: 12px; font-weight: 700; color: var(--text);
}

/* ---- Cards ---- */
.card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

/* ---- Macro rings (protein / carbs / fat vs. target) ---- */
.dot-p { background: var(--mp); } .dot-c { background: var(--mc); } .dot-f { background: var(--mf); }
.macros { margin: 18px 0 4px; }
.m-eyebrow { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--hint); font-weight: 700; margin-bottom: 14px; }
.ring-row { display: flex; justify-content: space-between; gap: 6px; }
.ring-cell { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 9px; }
.mring { position: relative; width: 76px; height: 76px; }
.mring svg { display: block; width: 76px; height: 76px; }
.mring-track { fill: none; stroke: var(--secondary-bg); stroke-width: 6.5; }
.mring-fill {
  fill: none; stroke-width: 6.5; stroke-linecap: round;
  stroke-dasharray: 0 9999;
  transition: stroke-dasharray 0.8s cubic-bezier(.4,0,.2,1), stroke 0.3s;
}
.mring-inner { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 1px; }
.mring-val { font-size: 16px; font-weight: 800; line-height: 1; letter-spacing: -0.01em; }
.mring-u { font-size: 10px; font-weight: 700; opacity: .6; }
.ring-meta { text-align: center; }
.ring-name { font-size: 12px; font-weight: 600; color: var(--text); opacity: .82; }
.ring-of { font-size: 11px; color: var(--hint); margin-top: 2px; }
.over-badge {
  display: inline-block; margin-top: 4px; padding: 2px 7px; border-radius: 6px;
  font-size: 9px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  background: rgba(255, 59, 92, .14); color: var(--p);
}
/* Base ring + value colours per macro; JS recolours to --p when over target. */
#rp { stroke: var(--mp); } #vp, #up { color: var(--mp); }
#rc { stroke: var(--mc); } #vc, #uc { color: var(--mc); }
#rf { stroke: var(--mf); } #vf, #uf { color: var(--mf); }

/* Empty day (no meals logged yet) */
.macros-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 18px 0 4px; padding: 14px 0 6px; }
.macros-empty-icon { font-size: 30px; opacity: .25; }
.macros-empty-txt { font-size: 13px; color: var(--hint); text-align: center; line-height: 1.5; }

/* ---- Sections ---- */
.section { margin-top: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-head h3 { margin: 0; font-size: 17px; font-weight: 700; }

.btn-ghost {
  background: none; border: none; color: var(--link);
  font-size: 15px; font-weight: 600; cursor: pointer; padding: 6px 4px;
}

/* ---- Weekly bar chart ---- */
.week-card { padding: 18px 16px 12px; }
.week-bars {
  position: relative; display: flex; align-items: flex-end; gap: 8px;
  height: 110px; padding-left: 30px;
}
/* Calorie y-axis: numeric labels in a left gutter + faint gridlines behind the
   bars (auto 500/1000 step). Gridlines start at the bars (left: 30px) so they
   align with the goal/extreme reference lines. */
.wk-yaxis { position: absolute; left: 0; top: 0; bottom: 0; width: 28px; pointer-events: none; }
.wk-yaxis span { position: absolute; left: 0; transform: translateY(50%);
  font-size: 10px; color: var(--hint); font-weight: 600; }
.wk-grid { position: absolute; left: 30px; right: 0; height: 0;
  border-top: 1px solid var(--hairline); opacity: 0.5; pointer-events: none; }
.wk-col {
  flex: 1; min-width: 0; border-radius: 6px 6px 3px 3px;
  background: var(--accent); opacity: 0.85;
  min-height: 4px; transition: height 0.6s cubic-bezier(.4,0,.2,1);
}
/* Traffic-light tone: on track / drifting / off track for the day's goal.
   Default (no goal) stays neutral accent; logged days get a tone class. */
.wk-col.good { background: var(--f); opacity: 0.9; }
.wk-col.warn { background: var(--warn); opacity: 0.9; }
.wk-col.bad { background: var(--p); opacity: 0.9; }
.wk-col.today { opacity: 1; }
.wk-col.empty { background: var(--hint); opacity: 0.18; }
.week-labels { display: flex; gap: 8px; margin-top: 8px; padding-left: 30px; }
.wk-label { flex: 1; text-align: center; font-size: 11px; color: var(--hint); font-weight: 600; }
.wk-label.today { color: var(--text); }
/* Legend explaining the chart's dashed reference lines (shown to match the
   lines actually drawn: goal always, the safe-minimum floor only for cuts). */
.week-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.week-legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--hint); font-weight: 600; }
.week-legend-dash { width: 18px; height: 0; flex-shrink: 0; }
.week-legend-dash.goal { border-top: 1.5px dashed var(--hint); opacity: 0.7; }
.week-legend-dash.extreme { border-top: 1.5px dashed var(--p); opacity: 0.85; }

/* "?" help button + the title group it sits in (keeps it next to the heading
   rather than pushed to the far edge by the section-head's space-between). */
.head-left { display: flex; align-items: center; gap: 7px; min-width: 0; }
.info-btn {
  width: 18px; height: 18px; flex-shrink: 0; padding: 0; cursor: pointer;
  border: 1.5px solid var(--hint); border-radius: 50%; background: transparent;
  color: var(--hint); font-size: 11px; font-weight: 700; line-height: 1;
}
.info-btn:active { opacity: 0.55; }
.macro-split-title { display: flex; align-items: center; gap: 7px; }

/* Weekly chart: week pager, stepped goal/floor overlay, tapped-day popover. */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.week-nav .date-label { font-size: 13px; }
.week-plot { position: relative; }
/* Stepped dashed target (and safe-min) line, drawn over the bars. Aligned to the
   bars area (left: 30px) like .wk-grid; non-scaling stroke keeps dashes uniform
   despite the non-uniform viewBox scaling. */
.wk-overlay { position: absolute; left: 30px; top: 0; width: calc(100% - 30px); height: 100%;
  pointer-events: none; overflow: visible; z-index: 2; }
.wk-overlay path { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.wk-overlay path.goal { stroke: var(--hint); opacity: 0.75; stroke-dasharray: 4 3; }
.wk-overlay path.extreme { stroke: var(--p); opacity: 0.85; stroke-dasharray: 4 3; }
.bar-pop {
  position: absolute; z-index: 6; transform: translateX(-50%); pointer-events: none;
  min-width: 196px; padding: 9px 11px; border-radius: 12px;
  background: var(--secondary-bg); border: 1px solid var(--hairline);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.bar-pop-date { font-size: 11px; color: var(--hint); font-weight: 700; margin-bottom: 2px; }
.bar-pop-cal { font-size: 15px; font-weight: 800; }
.bar-pop-goal { font-size: 11px; color: var(--hint); font-weight: 600; margin-left: 3px; }
.bar-pop-macros {
  display: flex; flex-direction: column; gap: 7px;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--hairline);
}
.bp-macro { display: flex; flex-direction: column; gap: 3px; }
.bp-macro-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; font-weight: 600; }
.bp-macro-name { display: flex; align-items: center; gap: 5px; color: var(--text); }
.bp-macro-name i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.bp-macro-val { color: var(--hint); white-space: nowrap; }
.bp-macro-pct { color: var(--text); font-weight: 700; margin-left: 6px; }
.bp-bar { height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.bp-fill { height: 100%; width: 0; border-radius: 2px; transition: width 0.4s ease; }

/* ---- Meals ---- */
.meals-list { display: flex; flex-direction: column; gap: 8px; }
.meal {
  display: flex; align-items: center; gap: 12px;
  background: var(--secondary-bg); border-radius: 14px; padding: 10px 14px 10px 10px;
  animation: slidein 0.25s ease;
}
@keyframes slidein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.meal-thumb {
  width: 46px; height: 46px; border-radius: 10px; object-fit: cover;
  flex-shrink: 0; background: var(--bg);
}
.meal-time {
  font-size: 12px; font-weight: 700; color: var(--hint);
  min-width: 46px; text-align: center;
}
.meal-info { flex: 1; min-width: 0; }
.meal-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-macros { font-size: 12px; color: var(--hint); margin-top: 2px; }
.meal-cal { font-weight: 700; font-size: 15px; white-space: nowrap; }
.meal-cal small { font-size: 11px; color: var(--hint); font-weight: 600; }
.meal-del {
  background: none; border: none; color: var(--hint); font-size: 20px;
  cursor: pointer; padding: 4px 2px; line-height: 1;
}
.empty { text-align: center; color: var(--hint); padding: 20px 0; }
.empty-text { font-size: 15px; margin-bottom: 14px; }
.btn-inline { width: auto; display: inline-flex; align-items: center; gap: 6px; padding: 11px 20px; }

/* ---- Weight ---- */
.weight-card { display: flex; flex-direction: column; }
.weight-now { display: flex; align-items: baseline; gap: 6px; }
.weight-val { font-size: 30px; font-weight: 800; }
.weight-unit { font-size: 15px; color: var(--hint); font-weight: 600; }
.spark { width: 100%; height: 80px; margin-top: 8px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.spark .area { fill: var(--accent); opacity: 0.12; stroke: none; }
.weight-meta { font-size: 13px; color: var(--hint); margin-top: 6px; }

/* ---- Water ---- */
.water-card { display: flex; flex-direction: column; }
.water-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.water-now { display: flex; align-items: baseline; gap: 6px; }
.water-val { font-size: 30px; font-weight: 800; }
.water-unit { font-size: 15px; color: var(--hint); font-weight: 600; }
.water-goal-meta { font-size: 13px; color: var(--hint); }
.water-bar { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; margin: 12px 0 14px; }
.water-fill {
  height: 100%; width: 0; border-radius: 5px;
  background: #4ea1ff; transition: width 0.5s ease;
}
.water-fill.full { background: #34C759; }
.water-actions { display: flex; gap: 8px; }
.water-add {
  flex: 1; min-width: 0; border: 1.5px solid var(--hairline);
  background: var(--secondary-bg); color: var(--text);
  border-radius: 12px; padding: 11px 8px; font-size: 15px; font-weight: 700;
  cursor: pointer; transition: transform 0.12s, border-color 0.15s;
}
.water-add:active { transform: scale(0.97); border-color: var(--accent); }
.water-undo {
  border: none; background: none; color: var(--hint);
  font-size: 14px; font-weight: 600; padding: 11px 12px; cursor: pointer;
}
.water-undo:disabled { opacity: 0.4; cursor: default; }

/* Barcode "looking up" spinner is inline in the sheet (not overlaying a photo). */
.barcode-searching {
  position: static; inset: auto; flex-direction: row; justify-content: flex-start;
  background: none; color: var(--hint); margin-top: 12px;
}
/* "or" divider between the camera-scan button and manual entry. */
.bc-or { text-align: center; color: var(--hint); font-size: 13px; margin: 14px 0; }

/* ---- Buttons ---- */
.btn {
  width: 100%; border: none; border-radius: 14px; padding: 15px;
  font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; }

/* ---- Floating scan button (quick food-photo upload, lower-right) ---- */
.fab {
  position: fixed; z-index: 40;
  right: max(16px, calc(50vw - 260px + 16px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border: none; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  display: grid; place-items: center; font-size: 27px;
  cursor: pointer; transition: transform 0.15s;
}
.fab:active { transform: scale(0.92); }
.fab-icon { line-height: 1; }

/* ---- Bottom sheets ---- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,0.3);
  animation: slideup 0.28s cubic-bezier(.16,1,.3,1);
  max-width: 520px; margin: 0 auto;
  max-height: 92vh; overflow-y: auto;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: var(--hint); opacity: 0.4; margin: 4px auto 14px; }
.sheet-body h3 { margin: 0 0 16px; font-size: 19px; }

/* ---- Photo capture ---- */
/* Two equal-width meal-entry tiles: 📷 Scan and ✍️ Describe, side by side. */
.entry-tiles { display: flex; gap: 10px; }
.entry-tile {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--secondary-bg); border: 1.5px dashed var(--hairline);
  border-radius: 16px; padding: 18px 12px; cursor: pointer; color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.entry-tile:active { transform: scale(0.99); }
.entry-tile-icon {
  font-size: 26px; width: 48px; height: 48px; flex-shrink: 0;
  display: grid; place-items: center; border-radius: 12px;
  background: var(--accent); color: var(--accent-text);
}
.entry-tile-label { font-weight: 700; font-size: 15px; }

.photo-preview {
  position: relative; border-radius: 16px; overflow: hidden;
  background: var(--secondary-bg); aspect-ratio: 16 / 10;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-clear {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px;
  border: none; border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff;
  font-size: 20px; line-height: 1; cursor: pointer; z-index: 2;
}
.photo-analyzing {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  background: rgba(0,0,0,0.55); color: #fff; font-weight: 600; font-size: 14px;
}

.ai-hint {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--hint); margin-top: 12px; line-height: 1.4;
}
.ai-hint::before { content: "✨"; font-size: 15px; }

/* AI result summary — the scanned meal at a glance, so Save is one tap. The
   editor below it is collapsed by default (opt-in depth). */
.meal-result {
  background: var(--secondary-bg); border-radius: 16px;
  padding: 16px; margin-top: 14px; text-align: center;
}
.meal-result-food { font-size: 18px; font-weight: 700; line-height: 1.3; }
.meal-result-cal { font-size: 30px; font-weight: 800; margin-top: 4px; }
.meal-result-cal #meal-result-unit { font-size: 15px; font-weight: 600; color: var(--hint); }
.meal-result-macros { font-size: 13px; font-weight: 600; color: var(--hint); margin-top: 4px; }
.meal-result .ai-hint { justify-content: center; margin-top: 10px; }

/* "Edit details" disclosure that reveals the editor after a scan. */
.details-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: none; border: none; color: var(--link);
  font-size: 15px; font-weight: 600; cursor: pointer; padding: 14px 4px;
}
.details-toggle-chev { font-size: 18px; }
.meal-details.collapsed { display: none; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 13px; color: var(--hint); font-weight: 600; }
.field input, .field textarea {
  width: 100%; min-width: 0;
  background: var(--secondary-bg); border: 1px solid transparent; color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; outline: none;
  transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field-row { display: flex; gap: 10px; }
/* min-width:0 lets the inputs shrink below their intrinsic width so a 3-column
   row (protein/carbs/fat) fits the viewport instead of overflowing off-screen. */
.field-row .field { flex: 1; min-width: 0; }
.field textarea {
  resize: none; font-family: inherit; line-height: 1.4; min-height: 64px;
}

/* "Estimate from description" button — secondary action below the description
   field that re-runs the LLM on the typed text. */
.btn-estimate {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--secondary-bg); color: var(--text);
  border: none; border-radius: 14px; padding: 13px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform 0.15s, opacity 0.15s; margin-bottom: 14px;
}
.btn-estimate:active { transform: scale(0.985); }
.btn-estimate:disabled { opacity: 0.5; cursor: default; }
.btn-estimate .spinner-sm { margin: 0; }

/* Helper line under the Description field: makes it obvious the field both
   refines the AI estimate and accepts a free-text description. */
.field-help { font-size: 12px; color: var(--hint); margin: -6px 0 14px; line-height: 1.4; }
.activity-desc { font-size: 13px; color: var(--hint); margin: -8px 0 14px; padding: 0 2px; min-height: 18px; }

/* ---- Editable nutrition block (Add-a-meal) ----
   The atomic recognized ingredients above an editable total-calories field.
   Editing an item's grams OR the total calories live-recomputes everything
   else (a calculator under the hood). */
.items-editor-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-bottom: 8px;
}
#items-editor-title, #em-items-title { font-size: 14px; font-weight: 700; }
.items-editor-hint { font-size: 12px; color: var(--hint); }
.items-editor-list { display: flex; flex-direction: column; gap: 8px; }
/* Gap below the ingredient list only when there are rows. */
.items-editor-list:not(:empty) { margin-bottom: 12px; }
.item-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--secondary-bg); border-radius: 12px; padding: 10px 12px;
  animation: slidein 0.2s ease;
}
.item-emoji { font-size: 20px; flex-shrink: 0; width: 24px; text-align: center; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-kcal { font-size: 12px; color: var(--hint); margin-top: 1px; }
.item-weight { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.item-weight-input {
  width: 62px; text-align: right; -moz-appearance: textfield;
  background: var(--bg); border: 1px solid var(--hairline); color: var(--text);
  border-radius: 9px; padding: 8px; font-size: 15px; outline: none;
  transition: border-color 0.15s;
}
.item-weight-input:focus { border-color: var(--accent); }
.item-weight-unit { font-size: 13px; color: var(--hint); font-weight: 600; }
/* Recalculated macro summary under the total-calories field. */
.items-editor-macros { font-size: 13px; color: var(--hint); font-weight: 600; margin: -8px 0 14px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 20px;
  border-radius: 12px; font-weight: 600; font-size: 14px; z-index: 100;
  box-shadow: var(--shadow); animation: toastin 0.25s ease; max-width: 90%;
  text-align: center;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ============================================================ PAGES + NAV */
.page { display: none; }
.page.active { display: block; }
.page-head { padding: 18px 0 4px; }
.page-head h2 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }

/* Bottom tab bar */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex; background: var(--secondary-bg);
  border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 520px; margin: 0 auto;
}
.nav-btn {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 7px; color: var(--hint);
}
.nav-icon { font-size: 21px; line-height: 1; opacity: 0.65; }
.nav-label { font-size: 11px; font-weight: 600; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active .nav-icon { opacity: 1; }

/* The bottom nav needs clearance; lift the FAB and toast above it. */
.fab { bottom: calc(80px + env(safe-area-inset-bottom)); }
.toast { bottom: calc(80px + env(safe-area-inset-bottom)); }

/* ============================================================ HISTORY */
.search-row { position: relative; margin: 12px 0 4px; }
.search-row input {
  width: 100%; background: var(--secondary-bg); border: 1px solid transparent;
  color: var(--text); border-radius: 12px; padding: 12px 38px 12px 14px;
  font-size: 15px; outline: none;
}
.search-row input:focus { border-color: var(--accent); }
.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border: none; border-radius: 50%;
  background: var(--hairline); color: var(--text); font-size: 18px;
  cursor: pointer; line-height: 1;
}
.search-banner { font-size: 13px; color: var(--hint); font-weight: 600; margin: 10px 2px; }

.date-nav { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 12px; }
.date-arrow {
  width: 40px; height: 40px; border: none; border-radius: 12px;
  background: var(--secondary-bg); color: var(--text); font-size: 22px; cursor: pointer;
}
.date-arrow:disabled { opacity: 0.3; }
.date-label { font-weight: 700; font-size: 16px; }

.day-summary { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.day-cal { font-size: 30px; font-weight: 800; }
.day-cal-goal { font-size: 16px; color: var(--hint); font-weight: 600; }
.day-status { font-size: 14px; color: var(--hint); font-weight: 600; min-height: 18px; }
.day-status.over { color: var(--p); }
.day-status.warn { color: var(--warn); }
.day-status.good { color: var(--f); }
.day-macros { display: flex; gap: 16px; font-size: 13px; color: var(--hint); font-weight: 600; }
.day-macros i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.day-macros .dot-p { background: var(--mp); }
.day-macros .dot-c { background: var(--mc); }
.day-macros .dot-f { background: var(--mf); }

/* ============================================================ PROGRESS */
.muted { font-size: 12px; color: var(--hint); font-weight: 600; }
.month-chart { width: 100%; height: 130px; display: block; }
.month-chart .area { fill: var(--accent); opacity: 0.12; stroke: none; }
.month-chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.month-chart .chart-goal { stroke: var(--hint); stroke-width: 1.2; stroke-dasharray: 4 4; opacity: 0.6; }
.month-chart .chart-grid { stroke: var(--hairline); stroke-width: 1; opacity: 0.5; }
/* Crisp HTML calorie labels layered over the (horizontally distorted) SVG. */
.chart-wrap { position: relative; }
.chart-yaxis { position: absolute; left: 0; top: 0; bottom: 0; width: 34px; pointer-events: none; }
.chart-yaxis span { position: absolute; left: 2px; transform: translateY(-50%);
  font-size: 10px; color: var(--hint); font-weight: 600; }

.stats-grid { display: flex; gap: 10px; }
.stat { flex: 1; text-align: center; }
.stat-val { font-size: 22px; font-weight: 800; }
.stat-name { font-size: 11px; color: var(--hint); margin-top: 3px; font-weight: 600; }

.macro-split-title { font-size: 13px; color: var(--hint); font-weight: 600; margin-bottom: 12px; }
.msplit { display: flex; flex-direction: column; gap: 10px; }
.msplit-row { display: flex; align-items: center; gap: 10px; }
.msplit-lbl { width: 64px; font-size: 13px; color: var(--hint); font-weight: 600; }
.msplit-bar { flex: 1; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.msplit-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.fill-p { background: var(--mp); }
.fill-c { background: var(--mc); }
.fill-f { background: var(--mf); }
.msplit-pct { width: 40px; text-align: right; font-size: 13px; font-weight: 700; }

.top-foods { display: flex; flex-direction: column; gap: 10px; }
.top-food { display: flex; justify-content: space-between; font-size: 14px; }
.tf-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 10px; }
.tf-count { color: var(--hint); font-weight: 700; }

.goal-progress { margin-top: 14px; }
.goal-bar { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.goal-fill { height: 100%; background: var(--accent); border-radius: 5px; transition: width 0.6s ease; }
.goal-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 13px; color: var(--hint); font-weight: 600; }
.goal-pct { color: var(--text); font-weight: 700; }

.advice-card { display: flex; flex-direction: column; gap: 14px; }
.advice-content { display: flex; flex-direction: column; gap: 10px; }
.advice-text { margin: 0; font-size: 15px; line-height: 1.5; }
.advice-recs { margin: 0; padding-left: 18px; color: var(--hint); font-size: 14px; line-height: 1.6; }

/* ============================================================ SETTINGS */
.list { padding: 4px 0; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--hairline);
}
.list-row:last-child { border-bottom: none; }
.list-row > span:first-child { color: var(--text); font-size: 15px; }
.list-val { color: var(--hint); font-weight: 600; font-size: 15px; }
.list-btn { width: 100%; background: none; border: none; cursor: pointer; font: inherit; text-align: left; color: var(--text); }
.list-btn .chev { color: var(--hint); font-size: 18px; }
.list-btn.danger > span:first-child { color: var(--p); }

.lang-toggle { display: flex; gap: 6px; }
.lang-chip {
  border: 1px solid var(--hairline); background: none; color: var(--hint);
  border-radius: 9px; padding: 6px 12px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.lang-chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* ============================================================ CHIPS + SELECT */
.chip-group { display: flex; gap: 8px; margin-bottom: 14px; }
.chip-group.vertical { flex-direction: column; }
.chip {
  flex: 1; border: 1.5px solid var(--hairline); background: var(--secondary-bg);
  color: var(--text); border-radius: 12px; padding: 13px 10px; font-size: 15px;
  font-weight: 600; cursor: pointer; transition: border-color 0.15s, color 0.15s;
}
.chip.selected { border-color: var(--accent); color: var(--accent); font-weight: 700; }

.field select {
  background: var(--secondary-bg); border: 1px solid transparent; color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; outline: none;
  appearance: none; -webkit-appearance: none;
}
.field select:focus { border-color: var(--accent); }

/* ============================================================ BUTTONS (extra) */
.btn-danger { background: var(--p); color: #fff; }
.btn-ghost-full { background: var(--secondary-bg); color: var(--text); }
.btn-danger-ghost { background: none; color: var(--p); margin-top: 8px; }

/* ============================================================ CONFIRM MODAL */
.modal-body {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--bg); border-radius: 18px; padding: 24px;
  width: calc(100% - 48px); max-width: 360px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); animation: pop 0.2s ease;
}
@keyframes pop {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.modal-body h3 { margin: 0 0 8px; font-size: 19px; }
.modal-body p { margin: 0 0 18px; color: var(--hint); line-height: 1.5; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* ============================================================ ONBOARDING */
.onboarding {
  min-height: 100vh; max-width: 520px; margin: 0 auto;
  padding: 0 20px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
}
.onb-progress { height: 4px; background: var(--secondary-bg); border-radius: 2px; margin-top: 18px; overflow: hidden; }
.onb-progress-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.3s ease; }
.onb-body { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.onb-step { display: flex; flex-direction: column; gap: 22px; }
.onb-step.center { align-items: center; }
.onb-q { margin: 0; font-size: 26px; font-weight: 800; line-height: 1.25; }
.onb-choices { display: flex; gap: 10px; flex-wrap: wrap; }
.onb-choices.vertical { flex-direction: column; }
.onb-choice {
  flex: 1; min-width: 120px; border: 1.5px solid var(--hairline); background: var(--secondary-bg);
  color: var(--text); border-radius: 14px; padding: 18px; font-size: 17px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left;
}
.onb-choice.selected { border-color: var(--accent); color: var(--accent); }
.onb-choice-label { font-size: 17px; font-weight: 600; }
.onb-choice-desc { font-size: 13px; font-weight: 400; color: var(--hint); line-height: 1.3; }
.onb-choice.selected .onb-choice-desc { color: var(--accent); opacity: 0.75; }
.onb-input {
  background: var(--secondary-bg); border: 1.5px solid transparent; color: var(--text);
  border-radius: 14px; padding: 18px; font-size: 22px; font-weight: 700; outline: none; text-align: center;
}
.onb-input:focus { border-color: var(--accent); }
.onb-actions { display: flex; gap: 10px; margin-top: 6px; }
.onb-actions .btn { flex: 1; }

/* ============================================================ GOAL WIZARD */
.gw-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; min-height: 28px; }
.gw-link { background: none; border: none; color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; padding: 4px 0; }
.gw-counter { font-size: 14px; color: var(--hint); font-weight: 600; }
.gw-body { justify-content: flex-start; padding-top: 18px; }
.gw-body .onb-q { text-transform: uppercase; letter-spacing: 0.01em; }
.gw-error { color: var(--p); font-size: 14px; font-weight: 600; }
.gw-context {
  background: var(--secondary-bg); border-radius: 14px; padding: 14px 16px;
  font-size: 15px; color: var(--hint); font-weight: 600;
}
.gw-context b { color: var(--text); }

/* Pace step */
.pace-value { text-align: center; font-size: 38px; font-weight: 800; color: var(--accent); letter-spacing: -0.02em; }
.pace-value small { font-size: 20px; font-weight: 700; }
.pace-cards { display: flex; gap: 10px; }
.pace-card {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 1.5px solid var(--hairline); background: var(--secondary-bg); color: var(--text);
  border-radius: 16px; padding: 18px 8px; font-size: 14px; font-weight: 700; cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.pace-card .pace-emoji { font-size: 26px; line-height: 1; }
.pace-card.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.pace-info { display: flex; flex-direction: column; gap: 6px; }
.pace-info-main { font-size: 15px; font-weight: 700; }
.pace-info-hint { font-size: 14px; color: var(--hint); }
.pace-info-kcal { font-size: 15px; font-weight: 700; color: var(--f); }

/* Building step */
.build-pct { font-size: 56px; font-weight: 800; color: var(--accent); text-align: center; }
.build-label { text-align: center; color: var(--hint); font-size: 16px; font-weight: 600; }
.build-bar { width: 100%; height: 8px; background: var(--secondary-bg); border-radius: 4px; overflow: hidden; }
.build-bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width 0.3s ease; }
.build-list { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.build-item { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 600; color: var(--hint); }
.build-item.done { color: var(--text); }
.build-check {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 14px; font-weight: 800;
  background: var(--secondary-bg); color: transparent; transition: background 0.2s, color 0.2s;
}
.build-item.done .build-check { background: var(--f); color: var(--bg); }

/* Plan-ready step */
.gw-done { gap: 16px; padding-bottom: 24px; }
.gw-check {
  width: 76px; height: 76px; border-radius: 50%; margin: 8px auto 0;
  background: var(--f); color: var(--bg); font-size: 38px; font-weight: 800;
  display: grid; place-items: center;
}
.gw-done .onb-q { text-align: center; font-size: 22px; }
.plan-chip {
  align-self: center; display: inline-block;
  background: rgba(48, 209, 136, 0.16); color: var(--f);
  border-radius: 999px; padding: 9px 16px; font-size: 14px; font-weight: 700;
  margin-bottom: 10px;
}
.gw-card-title { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.gw-card-sub { font-size: 13px; color: var(--hint); margin-bottom: 12px; }
.gw-consistent { text-align: center; font-size: 13px; color: var(--hint); margin-top: 10px; }
.plan-chart { width: 100%; height: 150px; display: block; margin-top: 8px; }
.plan-chart .pc-line { fill: none; stroke: var(--f); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.plan-chart .pc-area { fill: var(--f); opacity: 0.12; stroke: none; }
.plan-chart .pc-target { stroke: var(--hint); stroke-width: 1.2; stroke-dasharray: 5 5; opacity: 0.7; }
.plan-chart .pc-dot { fill: var(--bg); stroke: var(--f); stroke-width: 2.5; }
/* Adherence band between the actual and planned lines: green where ahead of
 * plan, red where behind. crispEdges hides hairline seams between the quads. */
.plan-chart .pc-fill-good { fill: var(--f); opacity: 0.30; stroke: none; shape-rendering: crispEdges; }
.plan-chart .pc-fill-bad { fill: var(--p); opacity: 0.30; stroke: none; shape-rendering: crispEdges; }
/* Actual progress so far (overlaid on the planned curve). */
.plan-chart .pc-actual { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.plan-chart .pc-here { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }
.plan-chart .pc-label { fill: var(--text); font-size: 12px; font-weight: 700; }
.plan-chart .pc-trophy { font-size: 16px; }
.plan-axis { display: flex; justify-content: space-between; padding: 4px 6px 0; font-size: 11px; color: var(--hint); font-weight: 600; }
/* Plan chart legend: which line/shade is which. */
.plan-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; margin-top: 8px; font-size: 11px; color: var(--hint); font-weight: 600; }
.plan-legend:empty { display: none; }
.pl-item { display: inline-flex; align-items: center; gap: 5px; }
.pl-swatch { width: 12px; height: 4px; border-radius: 2px; display: inline-block; }
.pl-swatch.pl-plan { background: var(--f); }
.pl-swatch.pl-you { background: var(--accent); }
.pl-swatch.pl-ahead { background: var(--f); height: 10px; opacity: 0.45; }
.pl-swatch.pl-behind { background: var(--p); height: 10px; opacity: 0.45; }

/* Daily recommendation rings */
.rec-rings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 10px; }
.rec-ring { display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.rec-ring svg { width: 84px; height: 84px; transform: rotate(-90deg); }
.rec-ring .rr-track { fill: none; stroke: var(--secondary-bg); stroke-width: 7; }
.rec-ring .rr-fill { fill: none; stroke-width: 7; stroke-linecap: round; }
.rec-ring .rr-val {
  position: absolute; top: 30px; left: 0; right: 0; text-align: center;
  font-size: 17px; font-weight: 800;
}
.rec-ring .rr-label { font-size: 13px; color: var(--hint); font-weight: 600; }
.rec-ring .rr-edit { background: none; border: none; color: var(--hint); font-size: 14px; cursor: pointer; padding: 2px 8px; }
.gw-tips { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.7; color: var(--text); }

.sheet-body .btn + .btn { margin-top: 10px; }

/* ---- Medical disclaimer + legal (Tasks 1 & 2) ---- */
/* Small muted footnote: "estimates, not medical advice". */
.disclaimer-note {
  font-size: 11.5px; line-height: 1.45; color: var(--hint);
  margin: 12px 0 0; padding: 0 2px; text-align: center;
}
/* Legal consent line on the welcome screen. */
.legal-note {
  font-size: 12px; line-height: 1.5; color: var(--hint);
  margin: 10px 0 0; max-width: 320px; text-align: center;
}
.legal-link { color: var(--link); cursor: pointer; white-space: nowrap; }
.legal-sep { color: var(--hint); margin: 0 2px; }
/* Settings "About" disclaimer sits left-aligned under the legal rows. */
#about-disclaimer { text-align: left; }

/* ---- Feedback threads (user thread list + admin inbox) ---- */
.feedback-threads { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.fb-thread {
  border: 1px solid var(--border, rgba(128,128,128,0.25)); border-radius: 12px;
  padding: 12px 14px; background: var(--card, rgba(128,128,128,0.06));
}
.fb-thread-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 6px;
}
.fb-thread-who { font-size: 13px; font-weight: 600; color: var(--text); }
.fb-thread-date { font-size: 11.5px; color: var(--hint); white-space: nowrap; }
.fb-status {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
}
.fb-status.open { background: rgba(255, 159, 10, 0.18); color: var(--mc, #e08600); }
.fb-status.answered { background: rgba(52, 199, 89, 0.16); color: var(--good, #2faa55); }
.fb-msg { font-size: 14px; line-height: 1.45; color: var(--text); white-space: pre-wrap; }
.fb-reply {
  margin-top: 8px; padding: 8px 10px; border-radius: 10px;
  background: rgba(52, 199, 89, 0.10); font-size: 13.5px; line-height: 1.45;
  white-space: pre-wrap; color: var(--text);
}
.fb-reply-label { font-size: 11px; font-weight: 600; color: var(--hint); display: block; margin-bottom: 3px; }
.fb-reply-box { margin-top: 10px; }
.fb-reply-box textarea {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 56px;
  border-radius: 10px; padding: 8px 10px; font: inherit;
  border: 1px solid var(--border, rgba(128,128,128,0.3)); background: var(--bg, transparent);
  color: var(--text);
}
.fb-reply-box .btn { margin-top: 8px; }

/* Extreme-deficit safety warning banner (goal-wizard "plan ready"). */
.warn-banner {
  background: rgba(255, 159, 10, 0.14); border: 1px solid var(--mc);
  color: var(--text); border-radius: 12px;
  padding: 12px 14px; margin: 4px 0 0; font-size: 13px; line-height: 1.5;
}
.warn-banner::before { content: "⚠️ "; }

/* ---- Estimate-uncertainty badge on the AI result card (Task 10) ---- */
.estimate-badge {
  display: inline-block; margin-top: 8px;
  background: var(--secondary-bg); border: 1px solid var(--hairline);
  border-radius: 999px; padding: 3px 12px;
  font-size: 12px; font-weight: 700; color: var(--hint);
}

/* ---- Recent meals: one-tap re-add (Task 9) ---- */
.recent-meals { margin-top: 16px; }
.recent-meals-title { font-size: 13px; font-weight: 700; color: var(--hint); margin-bottom: 8px; }
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--secondary-bg); border: none; border-radius: 12px;
  padding: 12px 14px; cursor: pointer; color: var(--text); text-align: left;
  font: inherit; transition: transform 0.12s;
}
.recent-item:active { transform: scale(0.99); }
.recent-item:disabled { opacity: 0.5; }
.recent-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.recent-item-name {
  font-size: 15px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.recent-item-cal { font-size: 12px; color: var(--hint); }
.recent-item-add {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}

/* ---- Meal time / backfill (Task 12) ---- */
.when-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 14px;
}
.when-label { font-size: 13px; color: var(--hint); font-weight: 600; }
.when-controls { display: flex; align-items: center; gap: 8px; min-width: 0; }
.when-input {
  background: var(--secondary-bg); border: 1px solid transparent; color: var(--text);
  border-radius: 12px; padding: 10px 12px; font-size: 15px; outline: none;
  min-width: 0; transition: border-color 0.15s;
}
.when-input:focus { border-color: var(--accent); }
.when-now {
  flex-shrink: 0; background: none; border: none; color: var(--link);
  font-size: 14px; font-weight: 700; cursor: pointer; padding: 6px 4px;
}

/* ============================================================ DATE BAR + CALENDAR */
/* Home top date selector: ‹ [label] › + search, the label opens the calendar. */
.day-bar { display: flex; align-items: center; gap: 6px; margin: 2px 0 14px; }
.day-bar .date-arrow { width: 36px; height: 36px; font-size: 20px; flex-shrink: 0; }
.day-bar-date {
  flex: 1; text-align: center; font-weight: 700; font-size: 16px;
  background: var(--secondary-bg); color: var(--text);
  border: none; border-radius: 12px; padding: 9px 12px; cursor: pointer;
}
.day-bar-icon {
  width: 36px; height: 36px; flex-shrink: 0; line-height: 1;
  border: none; border-radius: 12px; background: var(--secondary-bg);
  color: var(--text); font-size: 16px; cursor: pointer;
}

/* Month calendar overlay. */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 12px; }
.cal-title { font-weight: 800; font-size: 17px; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekdays { margin-bottom: 6px; }
.cal-wd {
  text-align: center; font-size: 11px; font-weight: 700;
  color: var(--hint); text-transform: uppercase;
}
.cal-cell {
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 10px; background: var(--secondary-bg);
  color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer;
}
.cal-cell.blank { background: transparent; cursor: default; }
.cal-cell.future { opacity: 0.3; cursor: default; }
.cal-cell.selected { background: var(--hairline); }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Tracked days colour their number by adherence (WHOOP-style). */
.cal-cell.tone-good { color: var(--f); font-weight: 800; }
.cal-cell.tone-warn { color: var(--mc); font-weight: 800; }
.cal-cell.tone-bad  { color: var(--p); font-weight: 800; }
.cal-legend { display: flex; justify-content: center; gap: 16px; margin-top: 16px; }
.cal-legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--hint); }
.cal-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.cal-dot.tone-good { background: var(--f); }
.cal-dot.tone-warn { background: var(--mc); }
.cal-dot.tone-bad  { background: var(--p); }
