/* One stylesheet. Mobile-first, light and dark, no framework.
   Type scale and spacing are deliberately generous: this is an app used one-handed, mid-meal. */

:root {
  color-scheme: light dark;
  --bg: #faf9f7;
  --surface: #ffffff;
  --ink: #14130f;
  --ink-muted: #6f6a60;
  --line: #e9e5dd;
  --accent: #2f6f4f;
  --accent-soft: #e6f0ea;
  --danger: #b3261e;
  --over: #c2761b;
  --radius: 16px;
  --tabbar: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1c1c1a;
    --ink: #f2f0ea;
    --ink-muted: #9c968a;
    --line: #2c2c29;
    --accent: #6cc296;
    --accent-soft: #1e3329;
    --danger: #ef8b84;
    --over: #e0a75c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body.sheet-open { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }

.main { padding: 12px 14px calc(var(--tabbar) + var(--safe-b) + 12px); max-width: 620px; margin: 0 auto; }
.loading, .setup { padding: 48px 20px; text-align: center; color: var(--ink-muted); }
.setup pre { text-align: left; background: var(--surface); padding: 12px; border-radius: 12px; overflow: auto; }
.bottom-space { height: 24px; }
.muted { color: var(--ink-muted); margin: 0 0 10px; }

/* ---------- header + cards ---------- */
.screen { display: flex; flex-direction: column; gap: 12px; }
.screen-head { display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 0; }
.screen-title { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }

.datebar { display: flex; align-items: center; gap: 8px; padding: 2px 0 4px; }
.datebar-label { flex: 1; background: none; border: 0; padding: 6px; text-align: center; }
.datebar-day { display: block; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.datebar-hint { display: block; font-size: 12px; color: var(--accent); margin-top: 2px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.card-head { display: flex; align-items: center; gap: 8px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0; }
.card-sub { font-size: 13px; color: var(--ink-muted); margin-left: auto; }
.card-head .add-chip { margin-left: 0; }
.empty { margin: 0; color: var(--ink-muted); font-size: 14px; }

/* ---------- stats ---------- */
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat-value { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.stat-unit { font-size: 11px; font-weight: 600; color: var(--ink-muted); margin-left: 2px; }
.stat-label { font-size: 11px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-target { font-size: 11px; color: var(--ink-muted); }
.bar { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar-empty { opacity: 0.5; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .25s ease; }
.bar-fill.over { background: var(--over); }

.group { border-top: 1px solid var(--line); padding-top: 8px; }
.group > summary { list-style: none; cursor: pointer; font-size: 13px; font-weight: 600;
                   color: var(--ink-muted); padding: 4px 0; display: flex; gap: 6px; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "›"; display: inline-block; transition: transform .15s ease; }
.group[open] > summary::before { transform: rotate(90deg); }
.group .count { color: var(--accent); }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
               color: var(--ink-muted); margin: 10px 0 2px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.tight { gap: 2px; }

.nrow { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.nrow:last-child { border-bottom: 0; }
.nrow-label { flex: 1; font-size: 14px; }
.nrow-value { font-size: 14px; font-variant-numeric: tabular-nums; }
.nrow-pct { width: 46px; text-align: right; font-size: 13px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.nrow-pct.good { color: var(--accent); }
.nrow-pct.over { color: var(--over); }
.nrow-value.muted { color: var(--ink-muted); font-style: italic; }
.nrow.partial .nrow-value { color: var(--ink-muted); }

/* ---------- entries ---------- */
.entries { display: flex; flex-direction: column; }
.entry {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; border-top: 1px solid var(--line);
  padding: 11px 2px; text-align: left; min-height: 46px;
}
.entry:first-child { border-top: 0; }
.entry-main { flex: 1; min-width: 0; }
.entry-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-detail { font-size: 12.5px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-kcal { font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink-muted); }
/* Fixed width so the names line up down the timeline however the locale writes the time. */
.entry-time { width: 62px; flex: none; font-size: 12.5px; color: var(--ink-muted);
              font-variant-numeric: tabular-nums; }
.time { font-variant-numeric: tabular-nums; }
.entry-remove { color: var(--ink-muted); font-size: 13px; }
.entry-slim { min-height: 38px; padding: 7px 2px; }
.entry-check .check {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 13px; color: transparent; flex: none;
}
.entry-check.on .check { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- controls ---------- */
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); font-size: 18px; line-height: 1; flex: none;
}
.add-chip {
  width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--accent);
  color: #fff; font-size: 18px; line-height: 1; flex: none;
}
.add-chip.quiet { background: none; color: var(--ink-muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 14px;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip-quiet { color: var(--ink-muted); }

.btn {
  border: 0; border-radius: 13px; padding: 14px 16px; font-size: 15px; font-weight: 600;
  width: 100%; background: var(--line);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-quiet { background: none; border: 1px solid var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-quiet { background: none; color: var(--danger); }
.btn:disabled { opacity: .5; }
.row-buttons { display: flex; gap: 10px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar) + var(--safe-b) + 14px);
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 28px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; color: var(--ink-muted); font-weight: 600; }
.field-hint { font-size: 12px; color: var(--ink-muted); margin: 0; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input, .search {
  width: 100%; padding: 12px 14px; border-radius: 12px; font-size: 16px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
input:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
/* **No spinner arrows.** They are a 12px hit target beside a field you are typing into, they
   change the value on a stray scroll over the input, and every place a step is genuinely useful
   has its own − / + buttons at a real size. Both rules are needed: WebKit draws its spinner as a
   pseudo-element, Firefox as an appearance. */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.num.big { font-size: 26px; font-weight: 700; padding: 14px; }
.qty-row { display: flex; align-items: center; gap: 10px; }
.amount-wrap { position: relative; flex: 1; display: flex; align-items: center; }
.amount-wrap input { padding-right: 46px; }
.amount-unit { position: absolute; right: 14px; font-size: 15px; color: var(--ink-muted);
               pointer-events: none; }
.base-row { display: flex; align-items: center; gap: 10px; }
.base-row input { width: 110px; }
.step-btn { width: 48px; height: 52px; border-radius: 12px; border: 1px solid var(--line);
            background: var(--surface); font-size: 22px; flex: none; }
.qty-preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
               background: var(--accent-soft); border-radius: 12px; padding: 12px; }
.qty-stat { display: flex; flex-direction: column; gap: 2px; }
.qty-stat-value { font-size: 17px; font-weight: 700; }
.qty-stat-label { font-size: 11px; color: var(--ink-muted); }

.form-heading { font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
                color: var(--ink-muted); margin: 6px 0 0; }
.nfields { display: flex; flex-direction: column; }
.nfield { display: flex; align-items: center; gap: 10px; padding: 7px 0;
          border-bottom: 1px solid var(--line); }
.nfield-label { flex: 1; font-size: 14px; display: flex; flex-direction: column; }
.nfield-note { font-size: 11px; color: var(--ink-muted); }
/* Children of another nutrient, nested the way a nutrition label nests them. */
.nfield-sub .nfield-label, .nrow-sub .nrow-label { padding-left: 16px; color: var(--ink-muted); }
.nfield-input { display: flex; align-items: center; gap: 6px; }
.nfield-input input { width: 96px; padding: 8px 10px; font-size: 15px; }
.unit { font-size: 12px; color: var(--ink-muted); width: 30px; }

.setting-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.setting-label { flex: 1; font-size: 15px; }

.weight-value { display: flex; align-items: baseline; gap: 6px; background: none; border: 0; padding: 0; }
.weight-number { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.weight-unit { font-size: 14px; color: var(--ink-muted); }
.weight-bf { font-size: 13px; color: var(--ink-muted); margin-left: 8px; }

/* ---------- picker ---------- */
.picker-list { display: flex; flex-direction: column; max-height: 52vh; overflow: auto;
               -webkit-overflow-scrolling: touch; }
.picker-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
              background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px 2px; }
.picker-main { flex: 1; min-width: 0; }
.picker-name { font-size: 15px; font-weight: 600; }
.picker-detail { font-size: 12.5px; color: var(--ink-muted); }
.picker-kcal { font-size: 14px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.picker-new .picker-name { color: var(--accent); }
.picker-row .check { width: 22px; text-align: center; color: var(--accent); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.tab { flex: 1; background: none; border: 0; display: flex; flex-direction: column;
       align-items: center; justify-content: center; gap: 2px; color: var(--ink-muted); }
.tab.on { color: var(--accent); }
.tab-glyph { font-size: 19px; line-height: 1; }
.tab-label { font-size: 11px; font-weight: 600; }

/* ---------- sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); opacity: 0;
  transition: opacity .22s ease; display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.sheet-backdrop.in { opacity: 1; }
.sheet {
  width: 100%; max-width: 620px; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 6px 16px calc(16px + var(--safe-b));
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
  max-height: 92vh; overflow: auto; -webkit-overflow-scrolling: touch;
}
.sheet.in { transform: translateY(0); }
.sheet-grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-title { font-size: 17px; font-weight: 700; margin: 0; flex: 1; }
.sheet-head .icon-btn { width: 34px; height: 34px; font-size: 15px; }
.sheet-body { padding-bottom: 8px; }

/* ---------- auth + toasts ---------- */
.auth { max-width: 380px; margin: 12vh auto; padding: 0 20px; display: flex;
        flex-direction: column; gap: 14px; }
.auth-title { font-size: 30px; margin: 0; letter-spacing: -0.03em; }

#toasts { position: fixed; top: calc(8px + env(safe-area-inset-top, 0px)); left: 0; right: 0;
          display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 90;
          pointer-events: none; }
.toast {
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; opacity: 0; transform: translateY(-10px);
  transition: opacity .2s ease, transform .2s ease; max-width: 90vw;
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--danger); color: #fff; }
