/* Apron — design tokens and layout.
   Every colour is a token in the blocks below; no colour literal appears in JS
   or anywhere under the token blocks (a test checks, as in Cardigan and
   VitalitySync). Light and dark follow the phone. */

:root {
  --bg: #f7f4ee; --surface: #ffffff; --surface-2: #eee9df; --line: #ddd5c6;
  --text: #1f2a24; --muted: #5f6b63; --accent: #2f5d46; --accent-text: #ffffff; --focus: #c9771f;
  --good: #2f7a4a; --good-bg: #e3f3e8; --bad: #b23a2e; --bad-bg: #fbe6e3; --warn: #8a5a00; --warn-bg: #fdf1d8;
  --soon: #b8590f; --scrim: #00000066;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px; --tap: 48px; --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131815; --surface: #1c2420; --surface-2: #26302a; --line: #34403a;
    --text: #edf2ee; --muted: #a6b3ab; --accent: #8fd1ad; --accent-text: #0f1a14; --focus: #f2b15e;
    --good: #7fd19b; --good-bg: #1d3325; --bad: #ff9d90; --bad-bg: #3d1f1b; --warn: #f2c14e; --warn-bg: #3a2e12;
    --soon: #f2a35e; --scrim: #000000a6;
  }
}

/* ---------------------------------------------------------------- base ---- */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 17px; line-height: 1.45; -webkit-text-size-adjust: 100%;
  min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
body.sheet-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2, h3 { line-height: 1.2; }
.wrap { max-width: 720px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.help { color: var(--muted); font-size: 15px; margin: 4px 0 12px; }
h2.screen { font-size: 26px; margin: 4px 0 2px; }

/* -------------------------------------------------------------- header ---- */

header.top {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  display: flex; align-items: center; gap: 8px;
}
header.top h1 { font-size: 22px; margin: 0 0 0 4px; flex: 1; min-width: 0; color: var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; max-width: 62%;
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 15px; white-space: nowrap; overflow: hidden;
}
.pill span:last-child { overflow: hidden; text-overflow: ellipsis; }
.pill .dot { width: 10px; height: 10px; border-radius: 999px; background: var(--muted); flex: none; }
.pill[data-tone="good"] .dot { background: var(--good); }
.pill[data-tone="warn"] .dot { background: var(--warn); }
.pill[data-tone="bad"] { color: var(--bad); border-color: var(--bad); }
.pill[data-tone="bad"] .dot { background: var(--bad); }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 999px;
  background: transparent; font-size: 24px; line-height: 1; display: inline-grid; place-items: center;
}
.icon-btn.small { min-width: 36px; min-height: 36px; font-size: 20px; }
.icon-btn:active { background: var(--surface-2); }

/* The unsynced strip (Hometracker R1.20): full width, impossible to miss. */
.strip { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.strip[data-tone="bad"] { background: var(--bad-bg); color: var(--bad); }
.strip-text { flex: 1; }

.notice {
  display: flex; align-items: center; gap: 8px; margin: 8px 16px 0; padding: 6px 6px 6px 14px;
  border-radius: var(--radius); background: var(--surface-2);
}
.notice span { flex: 1; }
.notice.good { background: var(--good-bg); color: var(--good); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
@media (min-width: 752px) { .notice { max-width: 688px; margin: 8px auto 0; } }

/* ---------------------------------------------------------------- tabs ---- */

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabstrip { display: flex; max-width: 720px; margin: 0 auto; }
.tabstrip button {
  flex: 1; min-width: 0; min-height: var(--nav-h); border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; color: var(--muted);
}
.tabstrip button .tab-icon { font-size: 22px; line-height: 1; }
.tabstrip button[aria-selected="true"] { color: var(--accent); font-weight: 700; }
.tabstrip button[aria-selected="true"] .tab-icon { transform: scale(1.1); }

/* ------------------------------------------------------------- buttons ---- */

.btn {
  min-height: var(--tap); padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; width: 100%; margin-top: 24px; }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: 15px; }
.btn:disabled { opacity: .45; cursor: default; }
.link-btn { border: 0; background: none; padding: 4px 8px; color: var(--accent); font-weight: 600; text-decoration: underline; min-height: 38px; }

/* --------------------------------------------------------- empty state ---- */

.empty-state { text-align: center; padding-top: 32px; }
.empty-state p { color: var(--muted); max-width: 440px; margin: 8px auto; }
.empty-state .phase { font-size: 15px; }
.empty-state .btn { margin-top: 12px; }
.hello-icon { font-size: 56px; }

/* -------------------------------------------------------------- pantry ---- */

.quick-add { display: flex; gap: 8px; margin: 12px 0 8px; }
.quick-add input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
}

section.group { margin-top: 20px; }
section.group h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 6px; }
section.group .help { margin-top: -2px; }
ul.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
li.row { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 0; border-top: 1px solid var(--line); border-left: 4px solid transparent; }
li.row:first-child { border-top: 0; }
li.row[data-urgency="soon"] { border-left-color: var(--soon); }
li.row[data-unsynced="true"] { border-left-color: var(--warn); }
.row-main {
  flex: 1; min-width: 0; min-height: var(--tap); border: 0; background: transparent; text-align: left;
  padding: 6px 4px 6px 12px; display: flex; flex-direction: column; justify-content: center;
}
.row-name { font-weight: 600; overflow-wrap: anywhere; }
.row-meta { font-size: 14px; color: var(--muted); }
li.row[data-urgency="soon"] .row-meta { color: var(--soon); font-weight: 600; }
.unsynced-tag { display: none; font-size: 13px; color: var(--warn); font-weight: 600; }
li.row[data-unsynced="true"] .unsynced-tag { display: inline; }

/* -------------------------------------------------------------- sheets ---- */

.sheet-scrim { position: fixed; inset: 0; z-index: 20; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .sheet-scrim { align-items: center; } .sheet { border-radius: 20px; max-height: 86dvh; } }
.sheet-head { display: flex; align-items: center; gap: 8px; position: sticky; top: -8px; background: var(--bg); padding-top: 8px; z-index: 1; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 22px; }

/* ---------------------------------------------------------------- form ---- */

.form label, .form .label { display: block; font-weight: 600; margin: 16px 0 6px; }
.form input:not([type="radio"]):not([type="checkbox"]), .settings input[type="text"] {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
}
.segs { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg { border: 0; background: transparent; min-height: 42px; padding: 6px 18px; font-size: 16px; }
.seg.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.form-actions { display: flex; gap: 10px; margin-top: 28px; }
.form-actions .btn { flex: 1; }

/* ------------------------------------------------------------ settings ---- */

.settings section { border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.settings section:last-child { border-bottom: 0; }
.settings h2 { font-size: 19px; margin: 18px 0 6px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 8px 0 14px; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
@media (max-width: 420px) { .facts { grid-template-columns: 1fr; gap: 0; } .facts dd { margin-bottom: 8px; } }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
details.fold { margin-top: 16px; }
details.fold summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
