:root {
  --bg: #F4F5F2;
  --card: #FFFFFF;
  --ink: #1B2420;
  --muted: #5B6660;
  --line: #E2E5E0;
  --line-soft: #EEF0EC;
  --field: #D5DAD4;
  --green: #1F6E4F;
  --green-dark: #14513A;
  --green-soft: #E3F0EA;
  --warn: #8A4B00;
  --warn-soft: #FFF6E6;
  --dark: #1B2420;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
h1, h2, h3, p { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
#app.no-nav { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }

/* ---------- header ---------- */
.page-head { padding: calc(18px + env(safe-area-inset-top)) 18px 10px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.page-head h1 { font-size: 25px; font-weight: 700; }
.kicker { font-size: 13px; color: var(--muted); display: block; margin-bottom: 2px; }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; text-decoration: none; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: #9AA59F; }
.sync.synced .dot { background: #2E9E6A; }
.sync.syncing .dot { background: #2456A4; }
.sync.offline .dot, .sync.error .dot { background: #C98A12; }
.topbar { display: flex; justify-content: flex-start; padding: calc(10px + env(safe-area-inset-top)) 18px 0; }

.wrap { padding: 0 16px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- controls ---------- */
.btn { height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--field); background: var(--card); font-size: 15px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn.dark { background: var(--dark); border-color: var(--dark); color: #fff; font-weight: 600; }
.btn.small { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; height: 52px; font-size: 16px; border-radius: 14px; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.link { border: 0; background: transparent; color: var(--green); padding: 0 6px; }

.field { width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--field); background: #fff; padding: 0 12px; font-size: 16px; }
.field:focus, .btn:focus-visible, .pill:focus-visible, .chip:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
label.lbl { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; }

.search { position: relative; }
.search .field { padding: 0 42px 0 44px; height: 46px; border-color: var(--line); }
.search .icon { position: absolute; right: 13px; top: 13px; color: var(--muted); pointer-events: none; }
.search .clear { position: absolute; left: 5px; top: 5px; width: 36px; height: 36px; border: 0; border-radius: 10px; background: #F0F2EF; display: flex; align-items: center; justify-content: center; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--field); background: #fff; font-size: 13px; font-weight: 500; white-space: nowrap; }
.chip.on { background: var(--dark); border-color: var(--dark); color: #fff; }
.wrap-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; background: #E6E9E4; border-radius: 14px; padding: 4px; }
.seg button { height: 40px; border: 0; border-radius: 11px; background: transparent; font-size: 15px; font-weight: 600; color: #4A5550; display: flex; align-items: center; justify-content: center; gap: 8px; }
.seg button.on { background: #fff; color: var(--ink); }
.seg .dot { width: 10px; height: 10px; border-radius: 50%; }
.seg .count { font-size: 12px; font-weight: 500; color: var(--muted); }

.pill { border: 0; border-radius: 999px; padding: 3px 9px; font-size: 11px; font-weight: 600; }

/* ---------- cards and rows ---------- */
.card { background: var(--card); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card.bordered { border: 1px solid var(--line); }
.card.darkcard { background: var(--dark); color: #fff; }
.card.darkcard .muted { color: #C9D1CC; }
.card.soft { background: #F7F8F6; }
.tag { align-self: flex-start; font-size: 11px; font-weight: 600; border-radius: 999px; padding: 3px 9px; background: #2E3B35; color: #CFE6DA; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

section.group { display: flex; flex-direction: column; gap: 6px; }
section.group > h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 4px; display: flex; align-items: center; gap: 8px; }
.num { width: 22px; height: 22px; border-radius: 7px; background: var(--dark); color: #fff; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }

.row { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 9px 10px 9px 12px; min-height: 60px; }
.row.on { background: var(--green-soft); }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row .name { font-size: 16px; font-weight: 500; }
.row .meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.list-card { background: var(--card); border-radius: 14px; overflow: hidden; }
.list-card .row { border-radius: 0; border-bottom: 1px solid var(--line-soft); }
.list-card .row:last-child { border-bottom: 0; }

.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--field); background: #fff; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); flex: none; }
.icon-btn.plain { border: 0; background: transparent; }

.stepper { display: flex; align-items: center; background: var(--green); border-radius: 12px; height: 44px; color: #fff; flex: none; }
.stepper button { width: 40px; height: 44px; border: 0; background: transparent; color: #fff; display: flex; align-items: center; justify-content: center; }
.stepper span { min-width: 22px; text-align: center; font-weight: 600; }
.stepper.light { background: #F0F2EF; color: var(--ink); height: 38px; border-radius: 10px; }
.stepper.light button { color: var(--ink); width: 34px; height: 38px; }
.add-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--field); background: #fff; color: var(--green); display: flex; align-items: center; justify-content: center; flex: none; }

.banner { display: flex; align-items: center; gap: 10px; background: var(--green-soft); color: var(--green-dark); border-radius: 14px; padding: 10px 8px 10px 14px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); color: #6E3C00; }

.footer-cta { position: fixed; left: 0; right: 0; bottom: calc(78px + env(safe-area-inset-bottom)); padding: 8px 16px; max-width: 560px; margin: 0 auto; }
.no-nav .footer-cta { bottom: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(rgba(244,245,242,0), var(--bg) 30%); }
.cta { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 54px; padding: 0 18px; border-radius: 16px; background: var(--dark); color: #fff; text-decoration: none; border: 0; width: 100%; font-weight: 600; }
.cta.center { justify-content: center; }
.cta .sub { font-size: 12px; color: #C9D1CC; font-weight: 400; display: block; }
.spacer-cta { height: 70px; }

/* ---------- bottom nav ---------- */
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); display: flex; padding: 6px 6px calc(10px + env(safe-area-inset-bottom)); z-index: 5; }
nav.tabs .inner { display: flex; width: 100%; max-width: 560px; margin: 0 auto; }
nav.tabs button { flex: 1; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); padding: 6px 0; }
nav.tabs button.on { color: var(--green); font-weight: 600; }

/* ---------- shopping mode ---------- */
.shop-head { color: #fff; padding: calc(14px + env(safe-area-inset-top)) 18px 16px; display: flex; flex-direction: column; gap: 10px; }
.shop-head a, .shop-head button.back { color: #fff; background: transparent; border: 0; display: inline-flex; align-items: center; gap: 4px; font-size: 14px; padding: 0; height: 36px; }
.shop-head h1 { font-size: 26px; font-weight: 700; }
.bar { height: 8px; border-radius: 999px; background: rgba(255,255,255,.3); overflow: hidden; }
.bar > div { height: 8px; background: #fff; border-radius: 999px; }
.take { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; border: 0; background: transparent; padding: 8px 4px; text-align: right; }
.circle { width: 28px; height: 28px; flex: none; border-radius: 50%; border: 2px solid #9AA59F; display: flex; align-items: center; justify-content: center; }
.circle.done { background: var(--green); border-color: var(--green); }
.taken .name { text-decoration: line-through; color: #5A6B62; }
.row.taken { background: #E9F2ED; }
.row.oos { background: var(--warn-soft); border: 1px dashed #E0B97A; }

.sheet-back { position: fixed; inset: 0; background: rgba(20,25,22,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- prices ---------- */
.ptable { background: #fff; border-radius: 16px; overflow: hidden; }
.prow { display: grid; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); align-items: center; }
.prow.head { background: #F7F8F6; font-size: 12px; font-weight: 600; }
.pcell { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 0; border-radius: 9px; font-size: 13px; text-align: center; }
.pcell.best { background: #DCEFE5; color: var(--green-dark); font-weight: 700; }
.pcell .t { font-size: 10px; color: var(--muted); font-weight: 400; }

/* ---------- settings ---------- */
.switch { width: 52px; height: 32px; border-radius: 999px; border: 0; background: #B8C0BB; padding: 3px; display: flex; justify-content: flex-start; flex: none; }
.switch.on { background: var(--green); justify-content: flex-end; }
.switch span { width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.code { font-size: 28px; font-weight: 700; letter-spacing: 4px; direction: ltr; text-align: center; background: #F7F8F6; border-radius: 12px; padding: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--green); color: #fff; font-weight: 600; display: flex; align-items: center; justify-content: center; flex: none; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); background: var(--dark); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90vw; text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 15px; }
