/* Theme-aware by default: the palette lives on :root and only the tokens
   are redefined for dark, so every rule below is written once. */
:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --border: #e3ded6;
  --text: #1e1c19;
  --muted: #6d675e;
  --accent: #b4531f;
  --accent-soft: #fdf0e7;
  --warn-bg: #fff8e6;
  --warn-border: #e8d08a;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --surface: #211f1c;
    --border: #35322d;
    --text: #ece8e2;
    --muted: #a09990;
    --accent: #e8874f;
    --accent-soft: #2c2119;
    --warn-bg: #2b2313;
    --warn-border: #5c4a1f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }

.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--border); }

.net {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 2px 9px;
}

main { max-width: 780px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-left)) 64px; }

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.controls input[type="search"] { flex: 1 1 220px; }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.check input { padding: 0; }

button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { color: var(--muted); }

.source-note, .count { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.source-note a { color: var(--accent); }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.item {
  display: flex;
  gap: 12px;
  align-items: baseline;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.item:hover { border-color: var(--accent); }
.item .name { font-weight: 500; }
.item .meta { color: var(--muted); font-size: 13px; }
.item .kcal { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 99px;
  padding: 1px 7px;
}

dialog {
  width: min(540px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-close { position: absolute; top: 8px; right: 8px; margin: 0; }
.dialog-close button { border: none; background: none; color: var(--muted); font-size: 15px; }
#item-detail { padding: 22px; }
#item-detail h2 { margin: 0 6px 2px 0; font-size: 19px; }

.facts { width: 100%; border-collapse: collapse; margin: 14px 0; }
.facts th, .facts td { text-align: left; padding: 5px 0; border-bottom: 1px solid var(--border); font-weight: 400; }
.facts td { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.facts tr.headline th, .facts tr.headline td { font-size: 17px; font-weight: 600; }

.components { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.components li { display: flex; align-items: center; gap: 8px; }
.components .fixed { color: var(--muted); font-size: 12px; }

.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  margin: 12px 0;
}

.total-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.total-card .big { font-size: 26px; font-variant-numeric: tabular-nums; }
.total-card .split { color: var(--muted); font-size: 13px; margin-top: 4px; }

.empty { color: var(--muted); padding: 28px 0; text-align: center; }
.row-actions { margin-left: auto; display: flex; gap: 6px; }
.text-note { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* --- customizable groups -------------------------------------------------
   A variation and an add-on look alike on purpose: from a reader's side
   they are both "a thing to choose", and the difference is what the
   resolver does with the answer, not how it is asked. */
.group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px 12px;
  margin: 14px 0 0;
}
.group legend { padding: 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.group .hint { font-weight: 400; margin-left: 8px; color: var(--muted); font-size: 12px; }

/* The group the resolver is waiting on. Highlighted rather than shown as an
   error: an unconfigured burrito is on its way to being valid. */
.group.needs-choice { border-color: var(--accent); background: var(--accent-soft); }

.options { display: grid; gap: 4px; }
.opt { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.opt .side { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.qty-opt { color: var(--muted); font-size: 13px; padding-left: 24px; }
.qty-opt input { width: 5em; }

/* Nesting is expressed with a rule rather than indentation alone, so it
   stays legible however deep an option's own options go. */
.nested {
  margin: 4px 0 8px 22px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}
.nested .group { margin-top: 8px; }

.summary { min-height: 40px; }
.prov { margin: 10px 0 0; }
.conf {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.conf-exact { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.conf-solid_derived, .conf-estimated { background: var(--warn-bg); border-color: var(--warn-border); }

.basis { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.basis li { margin: 2px 0; }

.kcal.muted { color: var(--muted); font-size: 13px; }
.actions { display: flex; align-items: center; gap: 14px; margin-top: 18px; }
.actions .check { gap: 8px; }
.actions input[type="number"] { width: 5.5em; }

/* A disabled "Add to log" is the normal state of a half-configured item,
   so it has to *look* unavailable rather than merely refusing the click. */
button.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
