:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --text: #1f2a24;
  --muted: #5d6b63;
  --border: #ddd5c4;
  --brand: #2f6b4f;
  --brand-ink: #ffffff;
  --accent: #e07a5f;
  --warn-bg: #fff3d6;
  --warn-ink: #6b4a00;
  --ok: #2f6b4f;
  --over: #b23a2b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a17;
    --surface: #1d2420;
    --text: #e8ece9;
    --muted: #a3b0a8;
    --border: #34403a;
    --brand: #6fbf94;
    --brand-ink: #0d1a13;
    --accent: #f0957d;
    --warn-bg: #3a2f12;
    --warn-ink: #f4d58d;
    --ok: #6fbf94;
    --over: #ff8a7a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
.container { max-width: 720px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: 0.25rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
a { color: var(--brand); }
p { margin: 0.5rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons and forms */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--brand);
  background: var(--brand); color: var(--brand-ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn.secondary, button.secondary { background: transparent; color: var(--brand); }
.btn.danger, button.danger { background: transparent; color: var(--over); border-color: var(--over); }
.btn.small, button.small { min-height: 36px; padding: 0 10px; font-size: 0.875rem; }
button[disabled], .btn[aria-disabled="true"] { opacity: 0.6; cursor: progress; }
label { display: block; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 160px; resize: vertical; }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--brand); }
.field { margin-bottom: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.card-link { display: block; color: inherit; text-decoration: none; }
.cards { display: grid; gap: 10px; }
.card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
}
.macros { display: flex; gap: 14px; font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.macros b { font-weight: 700; }

.notice { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; }
.flash { background: var(--surface); border-left: 4px solid var(--brand); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.error { border-left-color: var(--over); }

/* Bottom nav */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; text-align: center; color: var(--muted); text-decoration: none; font-size: 0.75rem;
  padding: 6px 0; min-height: 44px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar a[aria-current="page"] { color: var(--brand); font-weight: 700; }
.tabbar svg { width: 22px; height: 22px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
td.num, th.num { text-align: right; }

.mt { margin-top: 24px; }
.mt0 { margin-top: 0; }
.prewrap { white-space: pre-wrap; }
textarea.short { min-height: 80px; }
.ingredients { padding-left: 1.2rem; }
.ingredients li { margin: 4px 0; }
.ing-row { border: 1px solid var(--border); padding: 10px; margin: 0; box-shadow: none; }
.ing-main { display: grid; grid-template-columns: 1fr 72px 80px 40px; gap: 6px; }
.ing-extra { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 6px; margin-top: 6px; }
.ing-extra input, .ing-extra select { min-height: 38px; font-size: 0.9rem; }
.sticky-actions {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--bg);
  padding: 10px 0; border-top: 1px solid var(--border);
}
details > summary { cursor: pointer; min-height: 32px; }

/* Browse filters */
.search { margin-bottom: 10px; }
.chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; margin: 0; padding: 8px 0; overflow: visible; }
.chip {
  flex: none; display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); text-decoration: none; font-size: 0.9rem; white-space: nowrap;
}
.chip[aria-current] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chip-sort { font-size: 0.85rem; }
.tags-filter { margin-bottom: 4px; }
.meal-card h3 { line-height: 1.25; }

/* Targets */
.targets { display: grid; gap: 10px; }
.target-status { color: var(--muted); }
.target-over .target-status { color: var(--over); font-weight: 700; }
.target-ok.target .target-status { color: var(--ok); }
.bar { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 4px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.target-over .bar > span { background: var(--over); }
.target-todo .bar > span { background: var(--accent); }
.w-0 { width: 0%; }
.w-5 { width: 5%; }
.w-10 { width: 10%; }
.w-15 { width: 15%; }
.w-20 { width: 20%; }
.w-25 { width: 25%; }
.w-30 { width: 30%; }
.w-35 { width: 35%; }
.w-40 { width: 40%; }
.w-45 { width: 45%; }
.w-50 { width: 50%; }
.w-55 { width: 55%; }
.w-60 { width: 60%; }
.w-65 { width: 65%; }
.w-70 { width: 70%; }
.w-75 { width: 75%; }
.w-80 { width: 80%; }
.w-85 { width: 85%; }
.w-90 { width: 90%; }
.w-95 { width: 95%; }
.w-100 { width: 100%; }
.totals-card { position: sticky; top: 0; z-index: 5; }
.targets.compact .bar { height: 6px; }

/* Day builder */
.slot-section { margin-top: 18px; }
.slot-head { display: flex; justify-content: space-between; align-items: center; }
.slot-head h2 { margin: 0; }
.entry { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: 0; }
.entry-name { font-weight: 600; }
.entry-controls { display: flex; gap: 6px; align-items: center; grid-column: 1 / -1; }
.entry-controls input { width: 84px; min-height: 40px; }
.entry-controls .unit { color: var(--muted); font-size: 0.9rem; }
.empty-slot { color: var(--muted); font-size: 0.9rem; padding: 6px 0; }
.pick-list form { margin: 0; }
.pick { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 4px; text-align: left; background: var(--surface); color: var(--text); border: 1px solid var(--border); font-weight: 400; padding: 10px 12px; min-height: 56px; }
.pick .macros { font-size: 0.85rem; color: var(--muted); }
.pick .add { color: var(--brand); font-weight: 700; align-self: center; }
.js .js-hide { display: none; }
button.is-current, button.secondary.is-current { background: var(--brand); color: var(--brand-ink); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); }
fieldset label.row { font-weight: 400; min-height: 44px; }

/* Eyebrow labels on compact fields */
label.ef { display: flex; flex-direction: column; gap: 2px; margin: 0; font-weight: 400; min-width: 0; }
.eyebrow { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); line-height: 1.2; }
.ing-main { align-items: end; }
.ing-remove { align-self: end; min-height: 44px; }
.ing-extra { align-items: end; }

/* Shopping list */
.mt-s { margin-top: 8px; }
.check-row { font-weight: 400; min-height: 44px; }
.shop-section h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.shop-list { list-style: none; padding: 4px 12px; margin: 0; }
.shop-list li + li { border-top: 1px solid var(--border); }
.shop-item { margin: 0; }
.check {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; min-height: 52px; padding: 6px 0;
  background: transparent; color: var(--text); border: 0; font-weight: 400; border-radius: 0;
}
.check .box { flex: none; width: 24px; height: 24px; border: 2px solid var(--brand); border-radius: 6px; display: grid; place-items: center; }
.check[aria-checked="true"] .box { background: var(--brand); }
.check[aria-checked="true"] .box::after { content: ""; width: 6px; height: 12px; border: solid var(--brand-ink); border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check .item-name { flex: 1; }
.check .item-qty { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.check[aria-checked="true"] .item-name, .check[aria-checked="true"] .item-qty { text-decoration: line-through; color: var(--muted); }
textarea[readonly] { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
.staples { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.staples form { margin: 0; }
.staples button { min-height: 36px; padding: 0 6px 0 12px; border-radius: 999px; font-weight: 400; background: var(--surface); color: var(--text); border-color: var(--border); }
.grow { flex: 1; width: auto; }
