/* Prep Stock – mobile-first styles, light/dark */
:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --text: #1d2520;
  --muted: #66706a;
  --border: #e3e0d6;
  --brand: #1f4d3a;
  --brand-2: #2f6f55;
  --brand-contrast: #ffffff;
  --ok: #1f7a4d;
  --warn: #b26a00;
  --danger: #b3261e;
  --ok-bg: #e3f3e9;
  --warn-bg: #fff1d6;
  --danger-bg: #fde4e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1b211e;
    --text: #e8ece9;
    --muted: #9aa59f;
    --border: #2c3531;
    --brand: #7cc4a0;
    --brand-2: #9bd6b8;
    --brand-contrast: #0e1a14;
    --ok: #6fd19f;
    --warn: #f0b552;
    --danger: #ff8a80;
    --ok-bg: #173226;
    --warn-bg: #3a2c12;
    --danger-bg: #3d1a18;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--brand-2); }
@media (prefers-color-scheme: light) { a { color: var(--brand); } }
h1 { font-size: 1.5rem; margin: 0 0 .2rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.lead { font-size: 1.1rem; }
.center-text { text-align: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-danger { color: var(--danger); }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.household-chip {
  margin-left: auto; font-size: .85rem; padding: .25rem .7rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none;
  max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topnav { display: none; }
.offline-banner { background: var(--warn-bg); color: var(--warn); text-align: center; padding: .4rem 1rem; font-size: .9rem; }

/* Bottom tab bar (mobile) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .72rem; color: var(--muted); text-decoration: none;
}
.tabbar a span { font-size: 1.3rem; line-height: 1; }
.tabbar a[aria-current] { color: var(--brand); font-weight: 600; }
.tabbar .tab-scan span {
  background: var(--brand); color: var(--brand-contrast); border-radius: 50%;
  width: 42px; height: 42px; display: grid; place-items: center; margin-top: -14px; box-shadow: var(--shadow);
}

@media (min-width: 900px) {
  body { padding-bottom: 2rem; }
  .tabbar { display: none; }
  .topnav { display: flex; gap: .25rem; margin-left: 1rem; }
  .topnav a { padding: .4rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .95rem; }
  .topnav a[aria-current] { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
  .household-chip { order: 3; }
}

.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin: .5rem 0 1rem; }
.section-title { margin: 1.4rem 0 .6rem; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow); margin-bottom: .75rem;
}
.card.empty { text-align: center; padding: 1.5rem 1rem; }
.grid-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (min-width: 700px) { .grid-cards { grid-template-columns: repeat(3, 1fr); } }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 600px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.cov-card { display: block; color: inherit; text-decoration: none; margin: 0; }
.cov-head { display: flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.cov-big { font-size: 1.1rem; font-weight: 700; margin-bottom: .35rem; }
meter { width: 100%; height: 10px; }
.meter-wide { margin-bottom: .5rem; }
.cat-icon { font-size: 1.15rem; width: 1.6rem; text-align: center; flex: none; }

.score-card { display: flex; align-items: center; gap: 1rem; }
.score-ring { position: relative; width: 84px; height: 84px; flex: none; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring circle { fill: none; stroke-width: 3.6; }
.ring-bg { stroke: var(--border); }
.ring-fg { stroke: var(--brand); stroke-linecap: round; }
.score-ring strong { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.5rem; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .6rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li > a { display: flex; align-items: center; gap: .6rem; flex: 1; color: inherit; text-decoration: none; }
.list a.grow { display: block; }
.nav-list li a { padding: .2rem 0; font-weight: 500; }
.log-delta { font-weight: 700; min-width: 3.2rem; font-variant-numeric: tabular-nums; }

/* Stock rows */
.search-row { display: flex; gap: .5rem; margin-bottom: .75rem; }
.search-row input { flex: 1; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .4rem; margin-bottom: .5rem; scrollbar-width: none; }
.chip {
  flex: none; padding: .35rem .75rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; font-size: .88rem; white-space: nowrap;
}
.chip[aria-current] { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }
.item-row {
  display: flex; align-items: center; gap: .5rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .6rem .6rem .9rem; margin-bottom: .5rem;
}
.item-row.is-empty { opacity: .65; }
.item-main { flex: 1; min-width: 0; color: inherit; text-decoration: none; display: flex; flex-direction: column; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.item-badges { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .2rem; }
.item-badges:empty { display: none; }
.qty-ctl { display: flex; align-items: center; gap: .35rem; flex: none; }
.qty-ctl form { margin: 0; }
.qty { min-width: 3.6rem; text-align: center; font-variant-numeric: tabular-nums; line-height: 1.1; }
.qty strong { display: block; font-size: 1.1rem; }
.qty small { color: var(--muted); font-size: .72rem; }
.qty-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 1.35rem; line-height: 1; cursor: pointer; touch-action: manipulation;
}
.qty-btn:active { transform: scale(.94); }
.qty-btn:disabled { opacity: .35; cursor: default; }
.qty-card { text-align: center; }
.qty-ctl-lg { justify-content: center; gap: 1.25rem; margin: .5rem 0; }
.qty-ctl-lg .qty-btn { width: 56px; height: 56px; font-size: 1.8rem; }
.qty-ctl-lg .qty strong { font-size: 2.2rem; }
.bump { animation: bump .25s ease; }
@keyframes bump { 50% { transform: scale(1.18); } }

.batch-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.batch-row:last-of-type { border-bottom: 0; }
.batch-row input[type=date] { width: auto; flex: 1 1 150px; }
.input-qty { width: 5rem !important; flex: none; }
.batch-actions { display: flex; gap: .3rem; margin-left: auto; }
.add-batch { margin-top: .5rem; }
.add-batch summary { cursor: pointer; font-weight: 600; color: var(--brand); padding: .4rem 0; }

/* Badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* Forms */
.stack { display: flex; flex-direction: column; gap: .85rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .92rem; }
label small { font-weight: 400; }
input, select, textarea {
  font: inherit; font-size: 16px; width: 100%; padding: .6rem .7rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 1px; }
input:disabled, select:disabled { opacity: .7; }
.check-label { flex-direction: row; align-items: flex-start; gap: .6rem; font-weight: 400; cursor: pointer; }
.check-label input { width: 1.3rem; height: 1.3rem; margin: .1rem 0 0; flex: none; accent-color: var(--brand); }
.checklist li { padding: .5rem 0; }
.checklist form { width: 100%; }
.inline-form { display: inline-flex; }
.inline-form select { width: auto; padding: .35rem .5rem; }
.member-row { flex-wrap: wrap; }
.copy-input { margin-top: .5rem; font-size: .85rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: .95rem;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-small { padding: .35rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.row-gap { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: inherit; }
.danger-zone { margin: 1.5rem 0; text-align: center; }

.flash { padding: .7rem .9rem; border-radius: 10px; margin-bottom: .75rem; font-size: .95rem; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-info { background: var(--warn-bg); color: var(--warn); }

/* Scanner */
.scan-view { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 25% 12%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .25); }
.scan-status { min-height: 1.2em; text-align: center; }

/* Guest pages */
body.guest { padding: 0; display: grid; place-items: center; min-height: 100vh; }
.guest-card { width: min(420px, 100%); padding: 2rem 1.25rem; }
.guest-brand { text-align: center; margin-bottom: 1.5rem; }
.guest-brand h1 { margin-top: .5rem; }
.guest-links { text-align: center; margin-top: 1rem; font-size: .92rem; }

/* Print */
.print-page { padding: 1.5rem; background: #fff; color: #000; }
.print-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.print-table th, .print-table td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid #ddd; vertical-align: top; }
.print-table .cat-row th { background: #f0f0f0; padding-top: .6rem; }
@media print {
  .no-print { display: none; }
  .print-page { padding: 0; }
  body { padding: 0; }
}

/* Photos */
.thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; background: var(--bg); border: 1px solid var(--border); }
.thumb-sm { width: 40px; height: 40px; border-radius: 8px; }
.thumb-icon { display: grid; place-items: center; font-size: 1.4rem; }
.thumb-sm.thumb-icon { font-size: 1.15rem; }
.item-row { padding-left: .6rem; }
.item-thumb-link { flex: none; display: flex; }
.photo-card { margin-bottom: .75rem; text-align: center; }
.photo-large { width: 100%; max-height: 360px; object-fit: contain; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); display: block; margin-bottom: .5rem; }
.photo-upload { display: inline-block; margin: 0; }
.photo-upload label.btn { cursor: pointer; flex-direction: row; font-weight: 600; }
.photo-field { display: flex; flex-direction: column; gap: .5rem; }
.photo-preview { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); }
