/* You & Me Fitness — one narrow, phone-first column. Tokens shared with calculator.html. */
:root {
  --bg: #F3F6F5;
  --surface: #FFFFFF;
  --ink: #17262B;
  --muted: #5A6B70;
  --line: #DCE4E2;
  --accent: #1F6F5C;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3F0EC;
  --protein: #C2553A;
  --carbs: #D9A21B;
  --fat: #3D7CB8;
  --warn-bg: #FFF4DB; --warn-ink: #7A5200;
  --bad-bg: #FDE7E4;  --bad-ink: #9A2B1C;
  --font-display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --font-body: "Inter", -apple-system, system-ui, sans-serif;
  --r: 14px;
  color-scheme: light;
}
/* Dark colors apply when the iPhone is in dark mode (unless Light was chosen in the app),
   or whenever Dark was chosen in the app. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1719; --surface: #182326; --ink: #E7EFEE; --muted: #9AABAE; --line: #2A393C;
    --accent: #4FB89A; --accent-ink: #0F1719; --accent-soft: #1C3530;
    --protein: #E57E63; --carbs: #E9BC4A; --fat: #6FA6DB;
    --warn-bg: #3A2E10; --warn-ink: #F1CF7A; --bad-bg: #3D1C17; --bad-ink: #F2A193;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1719; --surface: #182326; --ink: #E7EFEE; --muted: #9AABAE; --line: #2A393C;
  --accent: #4FB89A; --accent-ink: #0F1719; --accent-soft: #1C3530;
  --protein: #E57E63; --carbs: #E9BC4A; --fat: #6FA6DB;
  --warn-bg: #3A2E10; --warn-ink: #F1CF7A; --bad-bg: #3D1C17; --bad-ink: #F2A193;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
[hidden] { display: none !important; }
.wrap { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; padding-top: 16px; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 28px; font-weight: 700; line-height: 1.1; }
h2 { font-size: 20px; font-weight: 700; }
p { margin: 0; }
.sub { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 13px; }

/* Cards & forms */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label, .flabel { font-size: 13px; font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); }
input, select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.unit { position: relative; }
.unit input { padding-right: 40px; }
.unit span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { font: inherit; font-size: 14px; border: 0; background: transparent; color: var(--ink); padding: 9px 4px; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; line-height: 1.25; }
.seg button small { font-size: 11px; color: var(--muted); font-weight: 400; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.14); font-weight: 600; color: var(--accent); }

.btn { font: inherit; font-weight: 600; font-size: 16px; border-radius: 12px; padding: 13px 16px; border: 1px solid transparent; cursor: pointer; width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn[disabled] { opacity: .6; cursor: default; }
.link { font: inherit; font-size: 14px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; font-weight: 600; }
.link.quiet { color: var(--muted); font-weight: 500; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; padding: 10px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.msg { border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.msg.info { background: var(--accent-soft); color: var(--ink); }
.msg.warn { background: var(--warn-bg); color: var(--warn-ink); }
.msg.bad  { background: var(--bad-bg); color: var(--bad-ink); }
.msgs { display: flex; flex-direction: column; gap: 8px; }

/* Plan */
.big .val { font-family: var(--font-display); font-size: 52px; font-weight: 700; line-height: 1; color: var(--accent); }
.big .val small { font-family: var(--font-body); font-size: 15px; font-weight: 500; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px; min-width: 0; }
.stat .v { font-weight: 600; font-size: 16px; }
.bar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--line); }
.bar i { display: block; height: 100%; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.macro { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.macro .g { font-family: var(--font-display); font-size: 24px; font-weight: 700; line-height: 1.1; }
.macro .k { font-size: 12px; color: var(--muted); }
.macro .n { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.macro .n::before { content: ""; width: 9px; height: 9px; border-radius: 3px; background: var(--mc); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }
.soon { border: 1px dashed var(--line); border-radius: var(--r); padding: 14px 16px; color: var(--muted); font-size: 14px; }
.foot { font-size: 12.5px; color: var(--muted); }
.center { min-height: 50vh; display: grid; place-items: center; color: var(--muted); }

/* Day navigation */
.daybar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; }
.iconbtn { font: inherit; font-size: 26px; line-height: 1; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.iconbtn[disabled] { opacity: .35; cursor: default; }
.daylabel { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; }
.daytitle { font-family: var(--font-display); font-size: 22px; font-weight: 700; line-height: 1.2; }
.daylabel input[type="date"] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; padding: 0; border: 0; cursor: pointer; }
#jumpToday { align-self: center; }

/* Daily totals */
.prog { display: flex; flex-direction: column; gap: 6px; }
.prog-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.prog-head .name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.prog-head .name::before { content: ""; width: 9px; height: 9px; border-radius: 3px; background: var(--mc); }
.prog-head .left { font-size: 13px; color: var(--muted); }
.prog-head .left.over { color: var(--bad-ink); font-weight: 600; }
.prog .track { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.prog .track i { display: block; height: 100%; border-radius: 99px; background: var(--mc); }
.prog.cal .track { height: 14px; }
.prog.cal .amount { font-family: var(--font-display); font-size: 28px; font-weight: 700; line-height: 1.1; }
.prog.cal .amount small { font-family: var(--font-body); font-size: 14px; font-weight: 500; color: var(--muted); }
.macro-progs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.macro-progs .prog-head { flex-direction: column; align-items: flex-start; gap: 0; }
.macro-progs .val { font-weight: 600; font-size: 14px; }

/* Meals */
.meals { display: flex; flex-direction: column; gap: 12px; }
.meal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.meal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; }
.meal-head h3 { font-size: 17px; }
.meal-head .kcal { font-size: 13px; color: var(--muted); }
.entry { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; padding: 11px 16px; border: 0; border-top: 1px solid var(--line); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.entry .info { min-width: 0; display: flex; flex-direction: column; }
.entry .ename { font-weight: 500; overflow-wrap: anywhere; }
.entry .emeta { font-size: 12.5px; color: var(--muted); }
.entry .ecal { font-weight: 600; white-space: nowrap; }
.entry.readonly { cursor: default; }
.meal-empty { padding: 10px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.meal-add { display: block; width: 100%; padding: 11px 16px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--accent); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.btn.danger { background: transparent; color: var(--bad-ink); border-color: var(--line); }

/* Food search */
.search { gap: 8px; }
/* Results sit in a dropdown-style box: about 5–6 rows tall, scrolls inside itself. */
.results-list {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 12px;
  max-height: min(340px, 45vh); overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .10);
}
.results-list:empty { display: none; }
.results-list .group { padding: 8px 12px 4px; background: var(--bg); position: sticky; top: 0; z-index: 1; }
.result { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-top: 1px solid var(--line); background: var(--surface); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.results-list > .result:first-child, .results-list > .group:first-child { border-top: 0; }
.result .info { min-width: 0; display: flex; flex-direction: column; }
.result .rname { font-weight: 500; overflow-wrap: anywhere; }
.result .rmeta { font-size: 12.5px; color: var(--muted); }
.result .rcal { font-size: 13px; font-weight: 600; white-space: nowrap; }
.result.more-brands { color: var(--accent); font-weight: 600; font-size: 14px; justify-content: center; }
.result-row { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.results-list > .result-row:first-child { border-top: 0; }
.result-row .result { border-top: 0; }
.star { font: inherit; font-size: 20px; width: 48px; flex: none; border: 0; border-left: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; }
.star[aria-pressed="true"] { color: var(--carbs); }
.picked { border: 1.5px solid var(--accent); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--accent-soft); }
.picked-name { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.divider { border-top: 1px solid var(--line); padding-top: 12px; gap: 2px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }

.btn.scan { display: block; text-align: center; font-size: 15px; padding: 11px 14px; }
.btn.scan.busy { opacity: .6; pointer-events: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* Bottom menu */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(var(--tabs, 2), 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
.tabbar button { font: inherit; font-size: 14px; font-weight: 600; background: none; border: 0; color: var(--muted); padding: 14px 8px; cursor: pointer; }
.tabbar button[aria-current="page"] { color: var(--accent); }
body.has-tabbar { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }

@media (max-width: 370px) {
  .macro-progs { grid-template-columns: 1fr; }
  .form, .stats { grid-template-columns: 1fr; }
  .big .val { font-size: 44px; }
}
@media (prefers-reduced-motion: no-preference) {
  .bar i { transition: width .35s ease; }
}
