:root {
  --bg: #f5f3ef; --card: #ffffff; --text: #1f2522; --muted: #6b726e; --line: #e3e0da;
  --brand: #2f5d50; --brand-ink: #ffffff; --red: #c0392b; --red-bg: #fdecea;
  --amber: #b7791f; --amber-bg: #fff6e0; --green: #2e7d4f; --green-bg: #e7f5ec;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151917; --card: #1f2522; --text: #ecefed; --muted: #9aa39e; --line: #2f3633;
    --brand: #5fa58f; --brand-ink: #0d1110; --red: #ff6b5b; --red-bg: #3a1f1c;
    --amber: #f0b44c; --amber-bg: #3a2f1a; --green: #6fcf97; --green-bg: #1b3326;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 8px 14px; min-height: 40px; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--red); }
button.ghost { background: transparent; border-color: transparent; color: inherit; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  background: var(--card); min-height: 42px; }
label { display: block; margin: 10px 0; color: var(--muted); font-size: 14px; }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }
.err { color: var(--red); min-height: 1.2em; }
.muted { color: var(--muted); font-size: 14px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--brand); color: var(--brand-ink); }
.top h1 { font-size: 18px; margin: 0; }
.top button { color: var(--brand-ink); }
main { max-width: 900px; margin: 0 auto; padding: 12px 16px 96px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { flex: 1; text-align: center; padding: 8px 0 6px; text-decoration: none; color: var(--muted); font-size: 20px; }
.tabs a span { display: block; font-size: 12px; }
.tabs a.active { color: var(--brand); font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.login h1 { margin-top: 0; font-size: 22px; }
.login button { width: 100%; margin-top: 8px; }

.banner { border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.banner.red { background: var(--red-bg); color: var(--red); }
.banner.amber { background: var(--amber-bg); color: var(--amber); }
.banner.green { background: var(--green-bg); color: var(--green); }
.banner h3 { margin: 0 0 6px; font-size: 15px; }
.banner ul { margin: 0; padding-inline-start: 18px; }
.banner li { margin: 4px 0; }
.banner a { color: inherit; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.toolbar input[type=search] { flex: 1; min-width: 160px; }
.chip { border-radius: 999px; padding: 6px 12px; min-height: 34px; font-size: 14px; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.list { list-style: none; padding: 0; margin: 0; }
.row { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; overflow-wrap: anywhere; }
.row.low { border-color: var(--red); }
.row.neg { border-color: var(--red); background: var(--red-bg); }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 42px; padding: 0; font-size: 20px; }
.qty .num { min-width: 64px; text-align: center; font-weight: 700; font-size: 18px; border: none; background: none; }
.row.low .num, .row.neg .num { color: var(--red); }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.green { background: var(--green-bg); color: var(--green); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.plus { color: var(--green); font-weight: 600; } .minus { color: var(--red); font-weight: 600; }
.tablewrap { overflow-x: auto; }

dialog { border: none; border-radius: var(--radius); padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 16px; }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
.actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 14px; flex-wrap: wrap; }
.recipe-line { display: flex; gap: 6px; align-items: center; margin: 6px 0; }
.recipe-line select { flex: 1; }
.recipe-line input { width: 90px; }

.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; }
.cats label { display: flex; align-items: center; gap: 8px; color: var(--text); margin: 4px 0; }
.cats input { width: auto; min-height: 0; }
.cats .child { padding-inline-start: 22px; }
h2.section { font-size: 17px; margin: 18px 0 6px; }
.tabs a { font-size: 18px; } .tabs a span { font-size: 11px; }

/* home */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 10px 0; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  text-decoration: none; color: var(--text); }
.tile b { display: block; font-size: 24px; }
.tile span { color: var(--muted); font-size: 13px; }
.tile.red b { color: var(--red); }
.bars { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.bar .bl { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 3px; }
.bar .bn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.bar .bv { color: var(--muted); white-space: nowrap; }
.bar .bt { position: relative; height: 12px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar .bf, .bar .bb { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 6px; }
.bar .bf { background: var(--brand); }
.bar .bb { background: var(--amber-bg); border: 1px solid var(--amber); }
.bar .bm { position: absolute; inset-block: -2px; width: 2px; background: var(--red); }
.bar.low .bf, .bar.neg .bf { background: var(--red); }
.bar.neg .bv { color: var(--red); }
.bar.buy .bv b { color: var(--amber); }
.legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sw { display: inline-block; width: 14px; height: 10px; border-radius: 3px; }
.sw.qty { background: var(--brand); } .sw.th { width: 3px; background: var(--red); }
.sw.need { background: var(--amber-bg); border: 1px solid var(--amber); }
.invimg { display: block; max-width: 100%; margin-top: 10px; border-radius: 8px; border: 1px solid var(--line); }
