/* Food (the trainer app). Black surfaces, white text, one green accent --
   deliberately not personal_web's red, so the two apps are never mistaken
   for each other on a phone (runbook/BUILD-foodkit.md). Covers every class
   name foodkit/templates/diary.html, _plan_card.html and their JS
   (diary.js, plan.js, scanner.js) reference, plus this app's own
   nav/settings/setup screens. iOS specifics: viewport-fit=cover is set in
   each template's <meta>, safe-area padding below, overscroll-behavior:
   none on body, every input at 16px minimum so Safari never auto-zooms. */

:root {
  --bg: #0b0b0d;
  --surface: #17171b;
  --surface-2: #202024;
  --border: #2c2c31;
  --fg: #f4f4f5;
  --fg-dim: #a4a4ab;
  --fg-faint: #6f6f76;
  --accent: #34d399; /* the one green accent */
  --accent-dim: #1f7a58;
  --danger: #f87171;
  --radius: 14px;
  --nav-h: calc(64px + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }

/* Several elements below set their own `display`, which otherwise beats the
   UA stylesheet's `[hidden] { display: none }` at equal specificity (author
   origin wins over user-agent origin regardless). Without this, toggling
   `.hidden`/the `hidden` attribute on the barcode scanner overlay or the
   Undo toast silently does nothing visually -- both rendered on top of the
   Food page on first load (design review B3, 2026-09-26). Matches
   gateway/personal_web/static/styles.css:31. */
[hidden] { display: none !important; }

html, body {
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
}

a { color: var(--accent); text-decoration: none; }

input, select, textarea, button {
  font-size: 16px; /* never smaller: Safari zooms on focus below this */
  font-family: inherit;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }
.app.has-nav { padding-bottom: var(--nav-h); }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-name { font-size: 20px; font-weight: 700; }
.brand-tag { color: var(--fg-dim); font-size: 13px; }

.date-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 12px 8px;
}
.date-arrow {
  background: none; border: none; color: var(--fg-dim); font-size: 26px;
  width: 44px; height: 44px; line-height: 1;
}
.date-center { background: none; border: none; color: var(--fg); text-align: center;
  min-height: 44px; display: flex; flex-direction: column; justify-content: center; }
.date-label { display: block; font-size: 16px; font-weight: 600; }
.date-jump { display: block; font-size: 12px; color: var(--accent); }

main.diary-scroll, main { flex: 1; padding: 0 12px 24px; overflow-y: auto; }

.summary-card, .plan-card, .quickadd-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.summary-title, .plan-title { font-size: 14px; font-weight: 700; color: var(--fg-dim);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }

.daystrip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.daycell { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 6px; text-align: center; }
.dayvalue { font-size: 20px; font-weight: 700; }
.daylabel { font-size: 11px; color: var(--fg-dim); }

.calorie-row { display: flex; align-items: center; justify-content: space-between; }
.cal-cell { text-align: center; flex: 1; }
.cal-value { font-size: 22px; font-weight: 700; }
.cal-remaining { color: var(--accent); }
.cal-label { font-size: 11px; color: var(--fg-dim); }
.cal-op { color: var(--fg-faint); font-size: 18px; padding: 0 6px; }

.goal-bars { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.goal-bar-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--fg-dim); }
.goal-track { background: var(--surface-2); border-radius: 8px; height: 8px; overflow: hidden; margin-top: 2px; }
.goal-fill { background: var(--accent); height: 100%; border-radius: 8px; }
.plain-totals { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.plain-total { text-align: center; }
.plain-total-value { font-weight: 700; }
.plain-total-label { font-size: 11px; color: var(--fg-dim); }

.meal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px; }
.meal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.meal-title { font-weight: 700; }
.meal-head-kcal, .meal-subtotal { color: var(--fg-dim); font-size: 13px; }
.meal-empty { color: var(--fg-faint); font-size: 14px; padding: 8px 0; }

.item-row { display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-top: 1px solid var(--border); gap: 8px; }
.item-row:first-child { border-top: none; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub, .item-sub-portion { font-size: 12px; color: var(--fg-dim); }
.item-macros { font-size: 12px; color: var(--fg-dim); }
.item-kcal { font-weight: 700; min-width: 44px; text-align: right; }
/* 40px floor (design review round two nit 2, 2026-09-26): the ◔ portion
   button, the × delete/move buttons and (below) the My foods ☆ pin and ×
   hide had no explicit tap-target size at all -- each one was just its
   glyph's own ink box (measured 32x27, 20x18 and 25x23). Sized as real
   buttons here without changing the glyph's own font-size. */
.item-portion-btn { display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; color: var(--fg); padding: 0 10px; font-size: 12px; }
.item-portion-on { color: var(--accent); border-color: var(--accent-dim); }
.item-del, .item-move { display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--fg-faint);
  width: 40px; height: 40px; font-size: 16px; }

.quickadd-search, .text-input, input[type="text"], input[type="search"], input[type="number"] {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; color: var(--fg); margin-bottom: 8px;
}
.quickadd-list { display: flex; flex-direction: column; gap: 6px; }
.quickadd-row { display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.quickadd-main { flex: 1; }
.quickadd-pct { color: var(--fg-dim); font-size: 12px; }
.quickadd-star { display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; min-height: 40px; background: none; border: none;
  color: var(--fg-faint); font-size: 16px; }
.quickadd-hide { display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; min-height: 40px; background: none; border: none;
  color: var(--fg-faint); font-size: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--fg); font-weight: 600; cursor: pointer; }
.btn-block { width: 100%; }
/* 40px floor (design review round two nit 2, 2026-09-26): this class sizes
   the Add sheet's Close button, the search tab's own "Add", and Settings'
   "Log today's weight" -- all measured 34px. */
.btn-small { min-height: 40px; padding: 0 12px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06120c; }
.btn-ghost { background: transparent; }
.plan-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--fg);
  border-radius: 10px; min-height: 40px; padding: 0 14px; font-weight: 600; }
.plan-btn-primary { background: var(--accent); border-color: var(--accent); color: #06120c; }

.results { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.sheet-note { color: var(--fg-dim); font-size: 13px; margin: 6px 0; }

/* Sheets: bottom modal, 28px top radius (Material 3 bottom-sheet convention). */
.sheet { position: fixed; inset: 0; z-index: 40; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow-y: auto;
  background: var(--surface); border-radius: 28px 28px 0 0; border: 1px solid var(--border);
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-tabs { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.sheet-tab { display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--fg-dim); border-radius: 999px; padding: 0 14px; font-size: 13px;
  white-space: nowrap; }
.sheet-tab-on { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.tab-panel[hidden] { display: none; }

.move-panel { text-align: center; }
.move-option { display: block; width: 100%; min-height: 48px; margin: 6px 0;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--fg); font-weight: 600; }

.portion-panel { text-align: center; }
.portion-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.portion-chip { min-width: 44px; min-height: 44px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--fg); }
.portion-custom-row { display: flex; gap: 8px; align-items: center; }
.portion-custom-input { flex: 1; margin-bottom: 0; }

.scan-overlay { position: fixed; inset: 0; z-index: 50; background: #000; display: flex;
  flex-direction: column; align-items: center; justify-content: center; }
.scan-video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.scan-frame { width: 70vw; max-width: 320px; aspect-ratio: 8 / 5; border: 3px solid var(--accent);
  border-radius: 14px; z-index: 1; }
.scan-hint { color: #fff; z-index: 1; margin-top: 12px; }
.scan-cancel { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 1; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 12px);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; display: flex; justify-content: space-between; align-items: center;
  z-index: 60; }
.toast-undo { background: none; border: none; color: var(--accent); font-weight: 700; }

.estimate-panel, .estimate-summary, .estimate-items, .estimate-meta,
.estimate-row, .estimate-main, .estimate-kcal, .estimate-range, .estimate-why {
  color: var(--fg); font-size: 13px;
}
.estimate-items { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.estimate-row { display: flex; justify-content: space-between; background: var(--surface-2);
  border-radius: 8px; padding: 6px 10px; }

.pick-row, .pick-head, .pick-actions { display: flex; align-items: center; gap: 8px; }
.pick-macros, .pick-why, .pick-leaves, .pick-kind { font-size: 12px; color: var(--fg-dim); }
.pick-name { font-weight: 600; }

/* Plan grid */
.plan-week { display: flex; flex-direction: column; gap: 10px; }
.plan-day { border-top: 1px solid var(--border); padding-top: 8px; }
.plan-section-label { font-size: 12px; color: var(--fg-dim); text-transform: uppercase; }
.plan-items { display: flex; flex-direction: column; gap: 6px; }
.plan-item-body { flex: 1; }
.plan-item-check, .plan-item-skip { min-width: 32px; }
.plan-item-note, .plan-flex, .plan-training { font-size: 12px; color: var(--fg-dim); }
.plan-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.plan-status, .plan-sub, .plan-rule { color: var(--fg-dim); font-size: 13px; }
.plan-stores { display: flex; gap: 8px; margin-top: 8px; }
.result-main, .result-row, .result-controls { font-size: 14px; }
/* Real <input type=number>, not display text -- 16px minimum or Safari
   zooms the page on focus (nit 1, design review 2026-09-26). The 44px
   min-height keeps it a real tap target too. */
.servings-input {
  width: 64px; min-height: 44px; font-size: 16px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--fg); padding: 0 8px;
}
.add-food {
  width: 100%; min-height: 44px; margin-top: 8px; padding: 10px 4px;
  background: transparent; border: none; color: var(--accent);
  font-weight: 700; text-align: left; cursor: pointer;
}
.water-row { display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 10px; }
.water-info { display: flex; flex-direction: column; }
.water-label { font-size: 12px; color: var(--fg-dim); }
.water-value { font-weight: 700; }
.water-taps { display: flex; gap: 8px; }
.water-tap {
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--fg); font-weight: 600;
}
.quicktag-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.quicktag-chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--fg); font-size: 14px; font-weight: 600;
}
select {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--fg); padding: 8px 10px; min-height: 40px;
}

/* Bottom nav */
.navbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.navitem { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px; color: var(--fg-faint); position: relative; }
.navitem-on { color: var(--accent); }
.navglyph { font-size: 20px; }
.navlabel { font-size: 11px; }
.navbadge { position: absolute; top: 4px; right: calc(50% - 26px); background: var(--danger);
  color: #fff; border-radius: 999px; font-size: 10px; padding: 1px 5px; }
.navbadge[hidden] { display: none; }

/* Auth screens (enroll / login / session-expired) */
.auth-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px; text-align: center; gap: 14px; }
.auth-title { font-size: 24px; font-weight: 800; }
.auth-sub { color: var(--fg-dim); max-width: 320px; }
.auth-status { color: var(--danger); min-height: 20px; }

/* Setup questionnaire */
.setup-screen { max-width: 420px; margin: 0 auto; padding: 20px 16px calc(24px + env(safe-area-inset-bottom, 0px)); }
.setup-progress { display: flex; gap: 6px; justify-content: center; margin-bottom: 18px; }
.setup-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--border); }
.setup-dot-on { background: var(--accent); }
.setup-question { font-size: 20px; font-weight: 700; margin-bottom: 14px; text-align: center; }
.setup-cards { display: flex; flex-direction: column; gap: 10px; }
.setup-card { min-height: 56px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--fg); font-size: 16px; font-weight: 600; }
.setup-card-on { border-color: var(--accent); color: var(--accent); }
.setup-actions { display: flex; justify-content: space-between; margin-top: 18px; }
.setup-skip { color: var(--fg-dim); background: none; border: none; }

/* Settings */
.settings-section { margin-bottom: 18px; }
.settings-row { display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-top: 1px solid var(--border); }
.settings-row:first-child { border-top: none; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--fg); font-size: 18px; }
.stepper-value { min-width: 56px; text-align: center; font-weight: 700; }

.coachmark { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 10px);
  background: var(--surface-2); border: 1px solid var(--accent-dim); border-radius: 14px;
  padding: 12px 14px; z-index: 45; font-size: 13px; }
.coachmark[hidden] { display: none; }
.coachmark-close { float: right; background: none; border: none; color: var(--fg-dim);
  min-width: 40px; min-height: 40px; font-size: 20px; line-height: 1; }

/* /welcome (first open): seven day chips on one row at phone width. */
.welcome-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin: 8px 0 4px; }
.welcome-day { min-height: 44px; padding: 0; font-size: 13px; }

/* Coach tab (flag off): client list, week strip, one day, comments. */
.coach-client-row { display: block; padding: 12px 0; border-top: 1px solid var(--border);
  color: var(--fg); text-decoration: none; font-weight: 600; }
.coach-client-row:first-child { border-top: none; }
.coach-week-strip { display: flex; gap: 6px; overflow-x: auto; margin-top: 10px; }
.coach-week-day { flex: 0 0 auto; min-height: 36px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--fg-dim); text-decoration: none;
  display: flex; align-items: center; font-size: 13px; }
.coach-week-day-on { border-color: var(--accent); color: var(--accent); }
.coach-slot { margin-top: 12px; }
.coach-slot-label { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.coach-item { font-size: 14px; padding: 3px 0; color: var(--fg-dim); }
.coach-comment { font-size: 14px; padding: 6px 0; border-top: 1px solid var(--border); }
.coach-comment:first-child { border-top: none; }
.coach-note-body { width: 100%; min-height: 44px; margin: 10px 0; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--fg);
  padding: 8px; font: inherit; resize: vertical; }
.setup-screen .settings-row label { flex: 1; margin-right: 12px; }


/* UX polish 2026-11-08: balanced headings, tabular numbers, page transitions. */
h1, h2, h3, h4, .brand-name, .page-title { text-wrap: balance; }
body { font-variant-numeric: tabular-nums; }
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}


/* Skeleton loaders: grey bars that shimmer while a screen's data is on its way. */
.skeleton { display: block; }
.skeleton-bar {
  display: block;
  height: 14px;
  margin: 10px 0;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--surface-2) 25%, rgba(255, 255, 255, 0.10) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.skeleton-bar.is-title { height: 20px; width: 55%; }
.skeleton-bar.is-short { width: 70%; }
.skeleton-card { height: 76px; border-radius: 14px; margin: 12px 0; }
@keyframes skeleton-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton-bar { animation: none; } }
