:root {
  --bg: #f6f3ee; --surface: #ffffff; --surface-2: #f0ece4; --text: #24231f; --muted: #6d6a62;
  --border: #e2ddd3; --primary: #2f6b4f; --primary-fg: #ffffff; --primary-soft: #e3efe8;
  --danger: #b3261e; --danger-soft: #fbe5e3; --warn: #9a6200; --warn-soft: #fdf0d5;
  --good: #2f6b4f; --good-soft: #e3efe8; --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161714; --surface: #20221e; --surface-2: #2a2c27; --text: #ebe8e1; --muted: #a29e94;
    --border: #363831; --primary: #5fae86; --primary-fg: #0f1a14; --primary-soft: #1f3329;
    --danger: #ef8a80; --danger-soft: #3a1f1c; --warn: #e8b552; --warn-soft: #3a2f17;
    --good: #5fae86; --good-soft: #1f3329; --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: 76px; }
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.narrow { max-width: 420px; margin: 8vh auto; }

/* Top bar + nav (bottom tab bar on phones) */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: 0 16px; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); padding: 14px 0; white-space: nowrap; }
.nav { display: flex; gap: 2px; margin-left: auto; }
.nav a { text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 8px; display: flex; gap: 6px; align-items: center; font-size: .95rem; }
.nav a.active, .nav a:hover { color: var(--primary); background: var(--primary-soft); }
@media (max-width: 760px) {
  .topbar { justify-content: center; }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); justify-content: space-around; padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); margin: 0; }
  .nav a { flex-direction: column; gap: 0; font-size: .7rem; padding: 6px 4px; flex: 1; }
  .nav .ico { font-size: 1.25rem; }
}
@media (min-width: 761px) { body { padding-bottom: 0; } }

/* Cards, layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin: 4px 0 16px; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.grid .card { margin: 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 42px; }
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-small { padding: 5px 10px; min-height: 34px; font-size: .875rem; }
.btn-block { width: 100%; }

/* Forms */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; width: 100%; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
label, .field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }
label > input, label > select, label > textarea { font-weight: 400; }
.field-label { font-weight: 600; font-size: .9rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid h2 { margin: 6px 0 0; }
.span-2 { grid-column: 1 / -1; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.login form { display: grid; gap: 14px; }
.check { display: flex; flex-direction: row; gap: 6px; align-items: center; font-weight: 400; }
.check label { font-weight: 400; }
form.inline { display: flex; gap: .5rem; align-items: center; flex: 1; }
.danger-zone { margin: 0 0 16px; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { flex-direction: row; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px; font-weight: 500; background: var(--surface); }
.seg input:checked + span { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.seg input:disabled + span { opacity: .45; cursor: not-allowed; }
.segmented.big .seg { flex: 1 1 220px; }
.segmented.big .seg span { border-radius: 12px; padding: 12px 14px; font-weight: 700; }
.segmented.big small { display: block; font-weight: 400; opacity: .85; }

.quick-dates { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.quick-dates button { font: inherit; font-size: .8rem; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }

/* Barcode */
.scan-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.barcode-manual { display: flex; gap: .5rem; flex: 1; min-width: 220px; }
.scanner { margin-top: 12px; max-width: 480px; border-radius: 10px; overflow: hidden; }
#scan-status:empty { display: none; }
#scan-status { margin: .5rem 0 0; }
.preview { width: 96px; height: 96px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--border); grid-column: 1 / -1; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat:hover { border-color: var(--primary); }
.stat-num { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .9rem; }
.stat-total { background: var(--primary-soft); }

/* Tabs + filters */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.tabs a { white-space: nowrap; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--text); font-weight: 500; }
.tabs a.active { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.tabs .count { opacity: .7; font-size: .85em; }
.filters { display: flex; gap: .5rem; margin-bottom: 12px; }
.filters input { flex: 1; }
.filters select { width: auto; }

/* Item rows */
.item { display: flex; gap: .75rem; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item-main { display: flex; gap: .75rem; align-items: center; min-width: 0; }
.item-text { min-width: 0; }
.item-name { font-weight: 600; color: var(--text); text-decoration: none; }
.item-name:hover { color: var(--primary); }
.item-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: .85rem; color: var(--muted); }
.item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.thumb { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--border); flex-shrink: 0; }
.status-expired { border-left: 3px solid var(--danger); padding-left: 10px; }
.status-soon { border-left: 3px solid var(--warn); padding-left: 10px; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-left: 4px; vertical-align: middle; }
.badge-expired { background: var(--danger-soft); color: var(--danger); }
.badge-soon { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 520px) { .item { flex-wrap: wrap; } .item-actions { margin-left: auto; } }

/* Flash */
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid transparent; }
.flash-success { background: var(--good-soft); color: var(--good); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-info { background: var(--warn-soft); color: var(--warn); }
.flash a { color: inherit; font-weight: 700; }

/* Recipes */
.pick-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 9px; padding: 4px 10px; margin-top: 6px; }
.pick { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; padding: 6px 0; border-bottom: 1px solid var(--border); }
.pick:last-child { border-bottom: 0; }
.recipe-head p { margin: .5rem 0 0; }
.recipe h2 { font-size: 1.35rem; margin-bottom: .5rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .8rem; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); }
.chip-good { background: var(--good-soft); color: var(--good); }
.chip-bad { background: var(--danger-soft); color: var(--danger); }
.uses-expiring { color: var(--warn); font-weight: 600; }
.recipe-body { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 24px; margin-top: 16px; }
@media (max-width: 700px) { .recipe-body { grid-template-columns: 1fr; } }
.ingredients { list-style: none; padding: 0; margin: 0; }
.ingredients li { display: flex; gap: 8px; padding: 4px 0; }
.ing-mark { width: 1.2em; flex-shrink: 0; font-weight: 700; text-align: center; }
.ing-have .ing-mark { color: var(--good); }
.ing-staple .ing-mark { color: var(--muted); }
.ing-missing .ing-mark { color: var(--danger); }
.legend { font-size: .8rem; margin-top: .5rem; }
.steps { padding-left: 1.3rem; margin: 0; }
.steps li { margin-bottom: .6rem; }
.tips { background: var(--surface-2); padding: 10px 12px; border-radius: 9px; }
.recipe-foot { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.spoon-card img { width: 100%; aspect-ratio: 312 / 231; object-fit: cover; border-radius: 9px; margin-bottom: 10px; }
.spoon-card h2 { font-size: 1.05rem; }
.spoon-card h2 a { color: var(--text); text-decoration: none; }
.spoon-card p { margin: .5rem 0; }
.card-actions { display: flex; gap: .5rem; margin-top: 10px; }
.hero-img { width: 100%; max-height: 360px; object-fit: cover; border-radius: 9px; margin-bottom: 12px; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: 0; }
.loc-row { display: flex; align-items: center; gap: .75rem; padding: 6px 0; flex-wrap: wrap; }
.spinner { width: 42px; height: 42px; margin: 12px auto; border: 4px solid var(--surface-2); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.inline-input { display: flex; gap: .5rem; }
.inline-input input { flex: 1; }
.mb { margin-bottom: 12px; }
.bookmarklet { cursor: grab; }
details summary { cursor: pointer; font-weight: 600; margin: .5rem 0; }
textarea.code { font-family: ui-monospace, monospace; font-size: .75rem; }
.step-section { list-style: none; font-weight: 700; margin: .75rem 0 .4rem -1.3rem; }
.have-most { color: var(--good); font-weight: 600; }
.scanner { position: relative; background: #000; }
.scanner video { display: block; width: 100%; max-height: 60vh; object-fit: cover; }
.scan-guide { position: absolute; left: 10%; right: 10%; top: 35%; bottom: 35%; border: 2px solid rgba(255,255,255,.85); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); pointer-events: none; }
.torch-btn { position: absolute; right: 10px; bottom: 10px; }
.product-search { margin-bottom: 12px; position: relative; }
.product-results { margin-top: 6px; border: 1px solid var(--border); border-radius: 10px; max-height: 60vh; overflow-y: auto; background: var(--surface); }
.product-hit { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-bottom: 1px solid var(--border); background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.product-hit:hover, .product-hit:focus { background: var(--primary-soft); outline: none; }
.product-hit:last-child { border-bottom: 0; }
.product-hit img, .product-hit .noimg { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; background: #fff; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.product-hit.plain .noimg { background: var(--surface-2); }
.hit-text { display: flex; flex-direction: column; min-width: 0; }
.hit-text strong { font-weight: 600; }
.hit-tag { margin-left: auto; color: var(--muted); }
.hit-head { margin: 0; padding: 6px 10px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); }
.pad { padding: 8px 10px; margin: 0; }
