:root {
  color-scheme: light dark;
  --surface: #fcfcfb;
  --raised: #ffffff;
  --sunken: #f3f2ef;
  --line: #e2e0da;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #807e78;
  --accent: #1c5cab;
  --on-accent: #ffffff;
  --protein: #2a78d6;
  --carbs: #eb6834;
  --fat: #1baf7a;
  --good: #0a7d0a;
  --warn: #9a5b00;
  --bad: #c22f2f;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1a1a19;
    --raised: #242423;
    --sunken: #131312;
    --line: #383835;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-3: #94928a;
    --accent: #6da7ec;
    --on-accent: #0b0b0b;
    --protein: #3987e5;
    --carbs: #d95926;
    --fat: #199e70;
    --good: #4cc04c;
    --warn: #fab219;
    --bad: #e66767;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2, h3, h4, p { margin: 0; }
h2 { font-size: 18px; letter-spacing: -.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- chrome ---- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 17px; letter-spacing: -.01em; }
.save { margin-left: auto; font-size: 12px; color: var(--ink-3); }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0; background: none; padding: 7px 12px; border-radius: 8px; color: var(--ink-2);
  display: flex; align-items: center; gap: 6px;
}
.tabs button[aria-current="page"] { background: var(--sunken); color: var(--ink); font-weight: 600; }
.tabs svg { display: none; }
main { max-width: 1240px; margin: 0 auto; padding: 16px; }

@media (max-width: 720px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    background: var(--raised); border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .tabs button { flex-direction: column; gap: 2px; font-size: 11px; padding: 4px 10px; min-width: 64px; }
  .tabs button[aria-current="page"] { background: none; color: var(--accent); }
  .tabs svg { display: block; }
  main { padding: 12px; }
}
@media (min-width: 721px) { body { padding-bottom: 32px; } }

/* ---- controls ---- */
.btn {
  border: 1px solid var(--line); background: var(--raised); border-radius: 8px;
  padding: 7px 12px; display: inline-flex; align-items: center; gap: 6px; text-align: left;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.quiet { border-color: transparent; background: none; color: var(--ink-2); }
.btn.quiet:hover { background: var(--sunken); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  border: 0; background: none; width: 30px; height: 30px; border-radius: 7px;
  display: inline-grid; place-items: center; color: var(--ink-3);
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
svg.ic { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
input[type=text], input[type=number], input[type=url], input[type=password], input[type=search], textarea, select {
  border: 1px solid var(--line); background: var(--raised); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 120px; resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
label.check { display: flex; gap: 8px; align-items: center; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.card { background: var(--raised); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.stack { display: grid; gap: 16px; }
.stack > *, .two > *, .fields > * { min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--raised); border-radius: 999px; padding: 4px 11px; font-size: 13px;
  color: var(--ink-2);
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.tag { font-size: 11px; color: var(--ink-2); background: var(--sunken); border-radius: 5px; padding: 1px 6px; white-space: nowrap; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; }

/* ---- plan ---- */
.plan-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.week-nav { display: flex; align-items: center; gap: 2px; }
.week-nav strong { min-width: 132px; text-align: center; }
.plan-bar .spacer { flex: 1; }
.summary { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 14px; }
.summary .goal { display: grid; gap: 2px; }
.summary .goal b { font-size: 22px; letter-spacing: -.02em; }
.prep { flex: 1 1 240px; min-width: 0; display: grid; gap: 6px; }
.prep ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.prep li { overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; font-size: 13px; background: var(--raised); }

.daystrip { display: none; gap: 6px; margin-bottom: 12px; }
.daystrip button {
  flex: 1; border: 1px solid var(--line); background: var(--raised); border-radius: 9px; padding: 6px 0;
  display: grid; justify-items: center; gap: 1px; font-size: 12px; color: var(--ink-2);
}
.daystrip button b { font-size: 15px; color: var(--ink); }
.daystrip button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.daystrip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.daystrip .dot.ok { background: var(--good); }
.daystrip .dot.off { background: var(--warn); }

.day {
  display: grid; grid-template-columns: 210px 1fr; gap: 14px;
  padding: 14px 0; border-top: 1px solid var(--line);
}
.day-head { display: grid; gap: 8px; align-content: start; }
.day-head h3 { font-size: 15px; display: flex; align-items: baseline; gap: 6px; }
.day-head h3 span { font-weight: 400; color: var(--ink-3); font-size: 13px; }
.day-head h3 .icon-btn { margin-left: auto; align-self: center; }
.kcal { display: flex; align-items: baseline; gap: 6px; }
.kcal b { font-size: 20px; letter-spacing: -.02em; }
.status { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.status.ok { color: var(--good); }
.status.off { color: var(--warn); }
.status svg { width: 13px; height: 13px; }
.meter { display: grid; grid-template-columns: 54px 1fr 84px; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
.meter .track { position: relative; height: 6px; border-radius: 3px; background: var(--sunken); }
.meter .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; min-width: 2px; }
.meter .tick { position: absolute; top: -3px; bottom: -3px; left: 80%; width: 2px; background: var(--ink-3); border-radius: 1px; }
.meter.kc .fill { background: var(--ink-2); }
.meter.p .fill { background: var(--protein); }
.meter.c .fill { background: var(--carbs); }
.meter.f .fill { background: var(--fat); }
.meter .num { text-align: right; }
.meter .key { display: inline-flex; align-items: center; gap: 5px; }
.meter .key i { width: 8px; height: 8px; border-radius: 2px; }
.meter.p .key i { background: var(--protein); }
.meter.c .key i { background: var(--carbs); }
.meter.f .key i { background: var(--fat); }

.meals { display: grid; grid-template-columns: repeat(auto-fill, minmax(224px, 1fr)); gap: 10px; }
.meal {
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r);
  padding: 10px 10px 6px; display: grid; gap: 4px; align-content: start; min-width: 0;
}
.meal.locked { border-color: var(--accent); }
.meal.empty { border-style: dashed; background: none; }
.meal .slot { display: flex; justify-content: space-between; align-items: center; gap: 6px; min-width: 0; }
.meal .slot .row { gap: 4px; flex-wrap: nowrap; min-width: 0; }
.meal .slot > span:first-child { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; }
.meal-name {
  border: 0; background: none; padding: 0; text-align: left; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em;
}
.meal-name:hover { text-decoration: underline; }
.meal-macros { font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.meal ul.items li { overflow-wrap: anywhere; }
.meal-macros b { color: var(--ink); }
.meal-actions { display: flex; align-items: center; flex-wrap: wrap; margin: 0 -4px; }
.meal-actions .x { font-size: 13px; min-width: 40px; text-align: center; }
.meal-actions .gap { flex: 1; }
.meal ul.items { list-style: none; margin: 2px 0 6px; padding: 6px 0 0; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); display: grid; gap: 2px; }
.add-meal { border: 0; background: none; color: var(--accent); padding: 12px 0; text-align: left; font-weight: 600; }
.empty-plan { text-align: center; padding: 56px 16px; display: grid; gap: 12px; justify-items: center; }
.empty-plan p { max-width: 46ch; color: var(--ink-2); }

@media (max-width: 860px) {
  .plan { display: flex; flex-direction: column; }
  .plan .summary { order: 9; margin: 16px 0 0; }
  .daystrip { display: flex; }
  .day { grid-template-columns: 1fr; display: none; border-top: 0; padding-top: 0; }
  .day.sel { display: grid; }
  .meals { grid-template-columns: 1fr; }
  .meal-name { min-height: 0; }
  .summary .goal b { font-size: 18px; }
}

/* ---- dialog ---- */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(640px, calc(100vw - 20px)); max-height: min(86vh, 820px); box-shadow: var(--shadow);
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dlg-head { padding: 14px 16px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.dlg-head .row { flex-wrap: nowrap; }
.dlg-head h2 { font-size: 16px; }
.dlg-body { overflow: auto; padding: 6px 8px 10px; }
.cand {
  width: 100%; border: 0; background: none; text-align: left; padding: 9px 8px; border-radius: 9px;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
}
.cand:hover, .cand:focus-visible { background: var(--sunken); }
.cand .nm { font-weight: 600; }
.cand .meta { grid-column: 1; font-size: 12.5px; color: var(--ink-2); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.cand .land { grid-row: 1 / span 2; grid-column: 2; text-align: right; font-size: 12px; color: var(--ink-2); display: grid; gap: 1px; justify-items: end; }
.cand.current { background: var(--sunken); }

@media (max-width: 520px) {
  .cand { grid-template-columns: 1fr; }
  .cand .land { grid-row: auto; grid-column: 1; justify-items: start; text-align: left; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
}

/* ---- groceries ---- */
.groc-cols { columns: 2 320px; column-gap: 20px; }
.aisle { break-inside: avoid; margin-bottom: 18px; }
.aisle h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 4px; }
.aisle ul { list-style: none; margin: 0; padding: 0; }
.g-item { display: flex; gap: 10px; align-items: flex-start; padding: 7px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.g-item .q { margin-left: auto; color: var(--ink-2); white-space: nowrap; font-size: 13px; padding-top: 1px; }
.g-item small { display: block; color: var(--ink-3); font-size: 12px; }
.g-item.done span.n { text-decoration: line-through; color: var(--ink-3); }

/* ---- recipes / goals ---- */
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.lib-item { display: flex; gap: 10px; align-items: center; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.lib-item .nm { font-weight: 600; overflow-wrap: anywhere; }
.lib-item.off .nm { color: var(--ink-3); text-decoration: line-through; }
.note { font-size: 13px; color: var(--ink-2); }
.error { color: var(--bad); font-size: 13px; }
.spinner { width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.ing { font-size: 13px; color: var(--ink-2); columns: 2 200px; padding-left: 18px; margin: 0; }

.login { max-width: 320px; margin: 18vh auto 0; display: grid; gap: 12px; }

.toasts { position: fixed; left: 0; right: 0; bottom: calc(76px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 20; pointer-events: none; padding: 0 12px; }
@media (min-width: 721px) { .toasts { bottom: 24px; } }
.toast {
  pointer-events: auto; background: var(--ink); color: var(--surface); border-radius: 10px; padding: 10px 14px;
  display: flex; gap: 14px; align-items: center; max-width: 560px; box-shadow: var(--shadow); font-size: 14px;
}
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 0; }
