/* Plate. Monochrome base, one accent (the + button, the Log button, the protein bar fill).
   Solid backgrounds, hierarchy by line weight, nothing floats, nothing animates except the
   bar fill and the Undo toast. Type is the plain system sans (never rounded). */

:root {
  --bg: #ffffff;
  --ink: #141414;
  --ink-2: #5c5c5c;      /* quiet text, 6.3:1 on white */
  --line: #d6d6d6;
  --line-2: #141414;     /* bolder line for emphasis */
  --fill: #e9e9e9;       /* bar track, chip background */
  --fill-2: #141414;     /* bar fill for calories, carbs, fat */
  --accent: #1f5eff;     /* white on this: 4.9:1 */
  --accent-ink: #ffffff;
  --alert: #c0272d;      /* 6.1:1 on white */
  --alert-ink: #ffffff;
  --good: #1a7a3c;       /* Week screen only */
  --press: #e0e0e0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111112;
    --ink: #f2f2f2;
    --ink-2: #ababab;    /* 7.7:1 on #111112 */
    --line: #2e2e30;
    --line-2: #f2f2f2;
    --fill: #242426;
    --fill-2: #f2f2f2;
    --accent: #2f6df0;   /* white on this: 4.6:1 */
    --accent-ink: #ffffff;
    --alert: #ff5a5f;    /* 5.5:1 on #111112 as text; dark text on it 7.6:1 */
    --alert-ink: #111112;
    --good: #45d06c;
    --press: #2a2a2c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111112;
  --ink: #f2f2f2;
  --ink-2: #ababab;
  --line: #2e2e30;
  --line-2: #f2f2f2;
  --fill: #242426;
  --fill-2: #f2f2f2;
  --accent: #2f6df0;
  --accent-ink: #ffffff;
  --alert: #ff5a5f;
  --alert-ink: #111112;
  --good: #45d06c;
  --press: #2a2a2c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, Helvetica, Arial, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  touch-action: manipulation;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.4; cursor: default; }
a { color: var(--ink); }
h1, h2, h3 { margin: 0; font-weight: 700; }
p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
input[type="text"], input[type="search"], input[type="date"], input[type="password"] {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  -webkit-appearance: none;
  appearance: none;
}
input:focus { outline: none; border-color: var(--line-2); }
input::placeholder { color: var(--ink-2); opacity: 1; }
.num { font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.quiet { color: var(--ink-2); }
.small { font-size: 14px; }
.alert-text { color: var(--alert); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 16px calc(72px + max(12px, env(safe-area-inset-bottom)));
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  margin-bottom: 8px;
}
.topbar h1 { font-size: 22px; flex: 1; }
.topbar .btn { flex: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 48px;
  padding: 0 16px;
  border: 2px solid var(--line-2);
  border-radius: 12px;
  font-weight: 700;
  background: var(--bg);
  color: var(--ink);
}
.btn:active, .btn.pressed { background: var(--press); }
.btn-quiet { border-color: var(--line); font-weight: 600; }
.btn-accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-accent:active, .btn-accent.pressed { filter: brightness(0.85); }
.btn-alert { color: var(--alert); border-color: var(--alert); }
.btn-wide { width: 100%; min-height: 56px; font-size: 18px; }
.btn-row { display: flex; gap: 10px; margin: 12px 0; }
.btn-row .btn { flex: 1; padding: 0 6px; font-size: 15px; white-space: nowrap; }
.link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: -8px 0;
  padding: 0 4px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-quiet { color: var(--ink-2); font-size: 15px; }

/* ---------- Tab bar and + ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-top: 2px solid var(--line);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 20;
}
.tabbar-inner {
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr 72px 1fr 1fr;
  align-items: end;
}
.tab {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
}
.tab[aria-current="page"] { color: var(--ink); font-weight: 800; }
.tab:active { background: var(--press); }
.plus {
  width: 64px; height: 64px;
  margin: -24px auto 4px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  border: 4px solid var(--bg);
}
.plus:active, .plus.pressed { filter: brightness(0.85); }

/* ---------- Today ---------- */
.datestrip {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  min-height: 48px;
  margin-bottom: 4px;
}
.datestrip .btn { padding: 0; font-size: 22px; }
.datestrip h1 { text-align: center; font-size: 20px; }
.bars { border-top: 3px solid var(--line-2); padding-top: 2px; }
.bar { padding: 6px 0 8px; border-bottom: 2px solid var(--line); }
.bar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.bar-label { font-weight: 700; }
.bar-rem { font-size: 26px; line-height: 1.1; }
.bar-hero .bar-label { font-size: 20px; }
.bar-hero .bar-rem { font-size: 40px; line-height: 1.1; }
.bar-rem.over { color: var(--alert); }
.bar-track { height: 8px; background: var(--fill); border-radius: 4px; margin: 4px 0 3px; overflow: hidden; }
.bar-hero .bar-track { height: 12px; border-radius: 6px; }
.bar-fill { height: 100%; width: 0; background: var(--fill-2); border-radius: inherit; transition: width 240ms ease-out; }
.bar-hero .bar-fill { background: var(--accent); }
.bar-fill.over { background: var(--alert); }
.bar-sub { font-size: 13px; color: var(--ink-2); }
.bar-hero .bar-sub { font-size: 14px; }
.bar-hero .bar-sub strong { color: var(--ink); font-weight: 800; }
@media (prefers-reduced-motion: reduce) { .bar-fill { transition: none; } }

.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 48px; padding: 8px 12px; margin: 8px 0;
  border: 2px solid var(--line-2); border-radius: 12px;
}
.notice-alert { background: var(--alert); color: var(--alert-ink); border-color: var(--alert); font-weight: 700; width: 100%; text-align: left; }
.empty-line { padding: 12px 0; color: var(--ink-2); text-align: center; }

.bucket { margin-top: 10px; }
.bucket-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-height: 32px; }
.bucket-head h2 { font-size: 18px; }
.bucket-sub { font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.bucket-links { display: flex; gap: 12px; flex-wrap: wrap; }
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  width: 100%;
  min-height: 52px;
  padding: 6px 0;
  border-bottom: 2px solid var(--line);
  text-align: left;
  align-items: center;
}
.row:active { background: var(--press); }
.row-name { font-weight: 700; grid-column: 1; }
.row-sub { font-size: 14px; color: var(--ink-2); grid-column: 1; }
.row-right { grid-column: 2; grid-row: 1 / span 2; text-align: right; font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.row-right .num { font-size: 16px; color: var(--ink); display: block; }
.row-mark { display: inline-block; font-size: 12px; font-weight: 700; color: var(--ink-2); border: 1.5px solid var(--line); border-radius: 6px; padding: 0 6px; margin-left: 6px; }
.badge {
  display: inline-block; font-size: 12px; font-weight: 700; color: var(--ink-2);
  border: 1.5px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: middle;
}
.more { width: 100%; min-height: 44px; font-weight: 600; color: var(--ink-2); text-align: left; padding: 0 2px; }

/* ---------- Add ---------- */
.search { margin-bottom: 10px; }
.search input { font-size: 18px; min-height: 52px; }
.group-title { font-size: 14px; font-weight: 700; color: var(--ink-2); margin: 14px 0 2px; }
.result { grid-template-columns: 1fr auto; }
.plate-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--ink); margin-right: 8px; vertical-align: -1px; }
.inline-msg { padding: 10px 0; color: var(--ink-2); }

/* ---------- Sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto;
  background: var(--bg);
  border-top: 3px solid var(--line-2);
  border-radius: 18px 18px 0 0;
  min-height: 50vh; max-height: 90vh;
  overflow-y: auto;
  padding: 6px 16px calc(12px + max(12px, env(safe-area-inset-bottom)));
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.sheet-head { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.sheet-head h2 { flex: 1; font-size: 19px; line-height: 1.2; }
.sheet-head .quiet { font-size: 14px; font-weight: 500; }
.amount-row { display: grid; grid-template-columns: 52px 1fr 52px; gap: 10px; align-items: center; margin: 8px 0 4px; }
.amount-row input { text-align: center; font-size: 30px; font-weight: 800; min-height: 60px; font-variant-numeric: tabular-nums; }
.stepper { width: 52px; height: 52px; border: 2px solid var(--line-2); border-radius: 12px; font-size: 28px; font-weight: 700; }
.stepper:active { background: var(--press); }
.conv { text-align: center; font-size: 15px; color: var(--ink-2); min-height: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chips-row { flex-wrap: nowrap; }
.chips-row .chip { flex: 1; padding: 0 4px; font-size: 15px; text-align: center; }
.chip {
  min-height: 44px; min-width: 44px; padding: 0 14px; border-radius: 22px;
  border: 2px solid var(--line); font-weight: 600; background: var(--bg);
}
.chip[aria-pressed="true"] { border-color: var(--line-2); background: var(--ink); color: var(--bg); }
.chip:active { background: var(--press); color: var(--ink); }
.chip-sub { display: block; font-size: 11px; font-weight: 500; line-height: 1.1; }
.live { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; text-align: center; }
.live div { border: 2px solid var(--line); border-radius: 10px; padding: 6px 2px; }
.live .num { display: block; font-size: 18px; }
.live .small { display: block; }
.live .hero { border-color: var(--line-2); }
.field { margin: 10px 0; }
.field label { display: block; font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.field .hint { font-size: 14px; color: var(--ink-2); margin-top: 4px; }
.field .hint.alert-text { color: var(--alert); font-weight: 600; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + max(12px, env(safe-area-inset-bottom)));
  max-width: 528px; margin: 0 auto; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 6px 6px 6px 16px;
  background: var(--ink); color: var(--bg);
  border-radius: 14px;
  font-weight: 600;
  animation: toast-in 160ms ease-out;
}
.toast .btn { background: var(--bg); color: var(--ink); border-color: var(--bg); min-height: 44px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- Scan ---------- */
.scanbox { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 3 / 4; max-height: 60vh; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-line { text-align: center; padding: 12px 0; color: var(--ink-2); }

/* ---------- Week ---------- */
.week { width: 100%; border-collapse: collapse; }
.week td { padding: 10px 4px; border-bottom: 2px solid var(--line); vertical-align: middle; }
.week td:first-child { font-weight: 700; white-space: nowrap; }
.week .num { font-size: 17px; }
.week .sub { font-size: 13px; color: var(--ink-2); display: block; }
.week td.mark { width: 40px; text-align: center; font-size: 22px; font-weight: 800; }
.mark-good { color: var(--good); }
.mark-none { display: inline-block; width: 18px; height: 3px; background: var(--ink-2); border-radius: 2px; vertical-align: middle; }
.week-foot { padding: 14px 0; border-top: 3px solid var(--line-2); margin-top: 4px; }
.week-foot p { padding: 4px 0; }

/* ---------- Settings ---------- */
.section { padding: 14px 0; border-bottom: 2px solid var(--line); }
.section h2 { font-size: 17px; margin-bottom: 8px; }
.section .hint { font-size: 14px; color: var(--ink-2); margin-top: 6px; }
.section a { color: var(--ink); }
.dialog {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.45); padding: 16px;
}
.dialog-box {
  background: var(--bg); color: var(--ink);
  border: 3px solid var(--line-2); border-radius: 16px;
  width: 100%; max-width: 420px; padding: 16px;
}
.dialog-box h2 { font-size: 19px; margin-bottom: 6px; }
.dialog-box p { margin-bottom: 12px; }

/* Pressed state on anything tappable */
.row:active, .chip:active, .tab:active, .link:active, .more:active { opacity: 0.85; }
@media (prefers-contrast: more) { :root { --line: var(--line-2); } }

/* "After this" line on the Quantity and meal sheets */
.after { text-align: center; font-size: 15px; color: var(--ink-2); padding: 2px 0 6px; }
.after .num { color: var(--ink); font-size: 16px; }
.after .num.alert-text { color: var(--alert); }
