/* Home Stock - phone-first, light + dark. No external fonts or scripts. */
:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #efede6;
  --ink: #1d2623;
  --muted: #5c6a64;
  --line: #e2e0d7;
  --brand: #1f6f54;
  --brand-ink: #ffffff;
  --brand-soft: #dcefe6;
  --danger: #b3261e;
  --s-expired-bg: #fde6e3; --s-expired-ink: #8f1f16; --s-expired-bar: #d93a2b;
  --s-now-bg: #fde6e3;     --s-now-ink: #8f1f16;     --s-now-bar: #e5533d;
  --s-soon-bg: #fff0cf;    --s-soon-ink: #6b4300;    --s-soon-bar: #e39a0d;
  --s-later-bg: #e6eefb;   --s-later-ink: #1f4a82;   --s-later-bar: #4a86d6;
  --s-ok-bg: #e0f2e8;      --s-ok-ink: #165a3a;      --s-ok-bar: #2e9e6b;
  --s-none-bg: #ecebe5;    --s-none-ink: #55605b;    --s-none-bar: #b9b8ae;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(30, 40, 35, .06), 0 4px 14px rgba(30, 40, 35, .05);
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715; --surface: #1a2220; --surface-2: #232d2a; --ink: #e8eeeb; --muted: #9db0a8;
    --line: #2b3733; --brand: #56b890; --brand-ink: #06231a; --brand-soft: #1d3a2f; --danger: #ff8a80;
    --s-expired-bg: #4a1f1b; --s-expired-ink: #ffb4ab; --s-expired-bar: #ef6b5b;
    --s-now-bg: #4a1f1b;     --s-now-ink: #ffb4ab;     --s-now-bar: #ef7b5f;
    --s-soon-bg: #46340d;    --s-soon-ink: #ffd886;    --s-soon-bar: #e8a526;
    --s-later-bg: #1e3350;   --s-later-ink: #a9c9f5;   --s-later-bar: #5b94dc;
    --s-ok-bg: #173b2b;      --s-ok-ink: #9be0bd;      --s-ok-bar: #3fb37d;
    --s-none-bg: #2a3330;    --s-none-ink: #a9b8b1;    --s-none-bar: #55615c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5; -webkit-font-smoothing: antialiased;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
img { max-width: 100%; display: block; }
a { color: var(--brand); }
h1 { font-size: 1.6rem; line-height: 1.15; margin: 0 0 var(--space-1); letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 var(--space-3); }
h3 { font-size: 1rem; margin: 0; line-height: 1.25; }
p { margin: var(--space-1) 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 8px; }

/* ---- shell */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: 12px max(16px, calc((100vw - 1040px) / 2));
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; color: var(--ink); text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 1rem; }
.topnav { display: none; gap: var(--space-2); }
.topnav a { padding: 8px 14px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 600; }
.topnav a[aria-current="page"], .topnav a:hover { background: var(--brand-soft); color: var(--brand); }
main { max-width: 1040px; margin: 0 auto; padding: var(--space-5) 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .72rem; font-weight: 600; color: var(--muted); text-decoration: none; border-radius: 12px;
}
.tabbar a[aria-current="page"] { color: var(--brand); }
.tabbar a.primary .ic { background: var(--brand); color: var(--brand-ink); border-radius: 14px; width: 44px; height: 32px; padding: 5px 12px; }
@media (min-width: 760px) {
  .tabbar { display: none; }
  .topnav { display: flex; }
  body { padding-bottom: 32px; }
}

/* ---- flash */
.flash { background: var(--brand-soft); color: var(--ink); border-radius: 12px; padding: 12px 14px; margin-bottom: var(--space-3); border: 1px solid var(--line); }

/* ---- buttons + forms */
button, .button {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 0 16px; min-height: 44px;
  background: var(--brand); color: var(--brand-ink); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(1.06); }
.btn-soft { background: var(--brand-soft); color: var(--brand); }
.btn-quiet { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.linkbtn { background: none; color: var(--brand); padding: 0; min-height: 44px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; min-height: 46px; width: 100%; min-width: 0;
}
textarea { min-height: 84px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; }
label small { font-weight: 400; color: var(--muted); }
.form { display: grid; gap: var(--space-4); max-width: 640px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.row3 { display: grid; grid-template-columns: 1.3fr 1fr .7fr; gap: var(--space-3); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 22px; min-height: 22px; height: 22px; }
.formactions { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4); box-shadow: var(--shadow); margin: var(--space-4) 0; }
.flat { margin: 0; }
fieldset.panel { border: 1px solid var(--line); display: grid; gap: var(--space-3); }
.narrow { max-width: 420px; margin: 40px auto; }
.narrow form { display: grid; gap: var(--space-4); }

/* ---- page header */
.pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.pagehead p { color: var(--muted); }

/* ---- stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); margin-bottom: var(--space-4); }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); border-left: 5px solid var(--s-none-bar); }
.stat strong { display: block; font-size: 1.9rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat.s-now { border-left-color: var(--s-now-bar); }
.stat.s-soon { border-left-color: var(--s-soon-bar); }
.stat.s-ok { border-left-color: var(--s-ok-bar); }

/* ---- expiry chips */
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.chip.s-expired, .chip.s-now { background: var(--s-now-bg); color: var(--s-now-ink); }
.chip.s-soon { background: var(--s-soon-bg); color: var(--s-soon-ink); }
.chip.s-later { background: var(--s-later-bg); color: var(--s-later-ink); }
.chip.s-ok { background: var(--s-ok-bg); color: var(--s-ok-ink); }
.chip.s-none { background: var(--s-none-bg); color: var(--s-none-ink); }
.chip.check { background: var(--s-soon-bg); color: var(--s-soon-ink); }

/* ---- use first */
.scroller { display: flex; gap: var(--space-3); overflow-x: auto; padding: 2px 2px 10px; scroll-snap-type: x proximity; margin: 0 -16px; padding-inline: 16px; }
.mini { scroll-snap-align: start; flex: 0 0 216px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3); box-shadow: var(--shadow); display: grid; gap: 8px; border-top: 5px solid var(--s-none-bar); }
.mini.s-expired, .mini.s-now { border-top-color: var(--s-now-bar); }
.mini.s-soon { border-top-color: var(--s-soon-bar); }
.mini.s-later { border-top-color: var(--s-later-bar); }
.mini.s-ok { border-top-color: var(--s-ok-bar); }
.mini .top { display: flex; gap: 10px; align-items: center; }
.mini h3 { font-size: .93rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- thumbs */
/* built-in product art: a tin or jar, label colour by food type, symbol on the label */
.pack {
  --label: #7d9a93; --lid: #b9c0c3;
  width: 60px; height: 72px; flex-shrink: 0; display: grid; place-items: center; font-size: 1.5rem;
  border-radius: 10px 10px 12px 12px;
  background: linear-gradient(var(--lid) 0 11%, rgba(255, 255, 255, .55) 11% 14%, var(--label) 14% 86%, rgba(0, 0, 0, .18) 86% 89%, var(--lid) 89% 100%);
  box-shadow: inset 7px 0 9px -7px rgba(255, 255, 255, .6), inset -7px 0 9px -7px rgba(0, 0, 0, .22), 0 1px 2px rgba(0, 0, 0, .15);
}
.pack.jar {
  border-radius: 9px 9px 15px 15px;
  background: linear-gradient(var(--lid) 0 24%, rgba(255, 255, 255, .6) 24% 27%, var(--label) 27% 100%);
}
.pack .sym { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .25)); line-height: 1; }
.pack.jar .sym { margin-top: 10px; }
.pack.lg { width: 76px; height: 96px; font-size: 1.9rem; }
.k-soup { --label: #e8735a; } .k-beans { --label: #e59a3c; } .k-curry { --label: #d9a21f; }
.k-chilli { --label: #c0432f; } .k-veg { --label: #5fae6b; } .k-potato { --label: #c9a56b; }
.k-sauce { --label: #d6563f; } .k-meat { --label: #a8674c; } .k-pudding { --label: #e3a3b5; }
.k-pasta { --label: #e0aa45; } .k-fish { --label: #5b8fc7; } .k-fruit { --label: #f0a04b; }
.k-dairy { --label: #9ec1e3; } .k-drink { --label: #8a6a4f; } .k-plain { --label: #7d9a93; }
.thumb { width: 60px; height: 76px; border-radius: 12px; object-fit: contain; background: #fafaf8; flex-shrink: 0; }
.ph { display: grid; place-items: center; font-size: 1.7rem; }
.thumb.lg { width: 76px; height: 96px; }

/* ---- filters */
.toolbar { display: grid; gap: var(--space-3); margin: var(--space-5) 0 var(--space-3); }
.search { display: flex; gap: var(--space-2); }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg a { flex: 1; text-align: center; padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: .9rem; text-decoration: none; color: var(--muted); min-height: 40px; display: grid; place-items: center; }
.seg a[aria-current="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: 6px; margin: 0 -16px; padding-inline: 16px; }
.chips a { flex-shrink: 0; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: .88rem; font-weight: 600; min-height: 40px; display: inline-flex; align-items: center; gap: 6px; }
.chips a[aria-current="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chips a span { opacity: .7; font-weight: 500; }

/* ---- stock cards */
.list { display: grid; gap: var(--space-3); }
@media (min-width: 760px) { .list.cols { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); border-left: 6px solid var(--s-none-bar); overflow: hidden; }
.card.s-expired, .card.s-now { border-left-color: var(--s-now-bar); }
.card.s-soon { border-left-color: var(--s-soon-bar); }
.card.s-later { border-left-color: var(--s-later-bar); }
.card.s-ok { border-left-color: var(--s-ok-bar); }
.card-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); }
.card-body { min-width: 0; flex: 1; display: grid; gap: 4px; }
.card-body h3 { overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: .85rem; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
details.card > summary { list-style: none; cursor: pointer; min-height: 44px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary .caret { transition: transform .15s; color: var(--muted); }
details.card[open] > summary .caret { transform: rotate(90deg); }
.batches { border-top: 1px solid var(--line); background: var(--surface-2); display: grid; gap: 1px; }
.batch { background: var(--surface); padding: var(--space-3); display: grid; gap: 8px; }
.batch + .batch, .batch.solo { border-top: 1px solid var(--line); }
.batch-top { display: flex; justify-content: space-between; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.actions form { margin: 0; }
.actions a.edit { font-weight: 600; font-size: .9rem; min-height: 40px; display: inline-flex; align-items: center; padding: 0 6px; }
.shelfhead { margin: var(--space-5) 0 var(--space-2); font-size: 1rem; display: flex; justify-content: space-between; align-items: baseline; }
.empty { text-align: center; padding: var(--space-6) var(--space-4); color: var(--muted); }
.empty .big { font-size: 2.4rem; }

/* ---- history / lists */
.lines { display: grid; }
.line { display: flex; justify-content: space-between; gap: var(--space-3); padding: 12px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.qty-pos { color: var(--s-ok-ink); font-weight: 700; }
.qty-neg { color: var(--s-now-ink); font-weight: 700; }
.menu { display: grid; gap: var(--space-2); }
.menu a, .menu button { width: 100%; justify-content: flex-start; background: var(--surface); color: var(--ink); border: 1px solid var(--line); min-height: 52px; border-radius: 14px; text-decoration: none; padding: 0 16px; display: flex; align-items: center; gap: 12px; font-weight: 600; }
.inline-rename { display: flex; gap: var(--space-2); }
.confirm summary { color: var(--danger); font-weight: 600; cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.photo-preview { max-width: 220px; border-radius: 14px; }

/* ---- read from photo */
.readbox { max-width: 640px; }
.readresult { margin-top: var(--space-3); }
.readmsg { display: flex; gap: var(--space-3); align-items: flex-start; border-radius: 12px; padding: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.readmsg.ok { background: var(--brand-soft); }
.readmsg.bad { background: var(--s-now-bg); color: var(--s-now-ink); }
.readmsg p { margin: 2px 0; }
.readpic { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; flex-shrink: 0; }
fieldset.confirm-me { outline: 3px solid var(--s-soon-bar); outline-offset: 2px; }

/* ---- scan page */
.scanbox { display: grid; gap: var(--space-3); }
.reader { width: 100%; max-width: 460px; margin: 0 auto; border-radius: 14px; overflow: hidden; background: #000; }
.filelabel { margin-top: var(--space-3); }
.filelabel input { padding: 9px; }
.result { margin: var(--space-4) 0; display: grid; gap: var(--space-3); }
.scan-card h2 { margin: 0; font-size: 1.15rem; overflow-wrap: anywhere; }
.scan-total { padding: 10px var(--space-3); font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); }
.linkbox { display: grid; gap: var(--space-2); margin-top: var(--space-3); }
.linkbox select { min-height: 46px; }
