:root {
  --bg: #f6f7f4; --card: #ffffff; --ink: #1b2118; --muted: #5f6b5b; --line: #dde2d8;
  --accent: #2b8a4b; --accent-ink: #ffffff; --accent-soft: #e3f3e8; --danger: #c0392b;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512; --card: #1c211b; --ink: #eef2ea; --muted: #a2ae9d; --line: #2f372d;
    --accent: #4cc472; --accent-ink: #0c1a10; --accent-soft: #1f3526; --danger: #ff7b6b;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(24px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}
.top { display: flex; align-items: center; gap: 10px; padding: 14px 16px 8px; max-width: 640px; margin: 0 auto; }
.top h1 { font-size: 26px; margin: 0; flex: 1; letter-spacing: -.2px; }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.status.ok::before { background: var(--accent); }
.status.warn::before { background: #d99a1c; }
.status:empty { display: none; }
main, .banner { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.banner { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; margin: 6px auto 4px; width: calc(100% - 32px); font-size: 15px; }
.banner[hidden] { display: none; }

.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.small { min-height: 40px; padding: 0 12px; font-size: 15px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.summary { display: flex; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); margin: 8px 0 12px; }
.sum-col { flex: 1; padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.sum-col + .sum-col { border-left: 1px solid var(--line); }
.sum-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.sum-col strong { font-size: 20px; font-variant-numeric: tabular-nums; }

.add { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.add-row { display: flex; gap: 8px; align-items: stretch; }
.add-row.opts { margin-top: 8px; }
input[type=text] {
  font: inherit; font-size: 17px; min-height: 48px; width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 0 12px; background: var(--bg); color: var(--ink);
}
#addName { flex: 1; }
.stepper { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; flex: 0 0 auto; }
.stepper button { width: 46px; min-height: 48px; border: 0; background: transparent; color: var(--ink); font-size: 24px; cursor: pointer; }
.stepper input { width: 52px; border: 0; border-radius: 0; text-align: center; background: transparent; padding: 0; }
.price { flex: 1; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding-left: 12px; min-width: 0; }
.price input { border: 0; background: transparent; padding-left: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px 0 8px; border-radius: 22px;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: 15px; cursor: pointer;
}
.chip[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.chip svg, .cat-ico svg { width: 24px; height: 24px; display: block; }

.list { margin-top: 14px; }
.group { margin-bottom: 14px; }
.group h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; padding: 0 4px; font-size: 15px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.group h2 .count { font-weight: 400; margin-left: auto; text-transform: none; letter-spacing: 0; }
.rows { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.row-item { display: flex; align-items: center; min-height: 60px; border-top: 1px solid var(--line); }
.row-item:first-child { border-top: 0; }
.tick { flex: 0 0 56px; height: 60px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.tick .box { width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--muted); display: flex; align-items: center; justify-content: center; color: transparent; font-size: 18px; font-weight: 700; }
.row-item.done .tick .box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tick[disabled] { cursor: default; }
.info { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; color: inherit; font: inherit; padding: 8px 4px; min-height: 60px; cursor: pointer; }
.info[disabled] { cursor: default; }
.info .name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.info .meta { display: block; font-size: 14px; color: var(--muted); }
.row-item.done .name { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.line-total { font-variant-numeric: tabular-nums; font-weight: 600; padding: 0 6px; white-space: nowrap; }
.row-item.done .line-total { color: var(--muted); font-weight: 400; }
.del { flex: 0 0 52px; height: 60px; border: 0; background: transparent; color: var(--muted); font-size: 26px; cursor: pointer; }
.del:hover, .del:active { color: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.foot { display: flex; justify-content: center; margin: 8px 0; }
.fine { font-size: 13px; color: var(--muted); text-align: center; }
.muted { color: var(--muted); font-size: 15px; margin: 4px 0 8px; }
.err { color: var(--danger); margin: 8px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222a20; color: #fff; border-radius: 14px; padding: 6px 8px 6px 16px; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.3); z-index: 50; max-width: calc(100% - 24px);
}
.toast[hidden] { display: none; }
.toast button { min-height: 44px; border: 0; background: transparent; color: #8ff0ae; font: inherit; font-weight: 700; padding: 0 12px; cursor: pointer; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100% - 24px)); background: var(--card); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form, .dlg-body { padding: 18px; }
dialog h2 { margin: 0 0 10px; font-size: 21px; }
dialog h3 { margin: 12px 0 0; font-size: 16px; }
.field { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.field input { margin-top: 4px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.dlg-actions .danger { margin-right: auto; }
.linkbox input { margin: 6px 0; font-size: 14px; }
.row { display: flex; gap: 8px; } .row .btn { flex: 1; }
.linkbox { padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.readonly .add, .readonly .foot { display: none; }
@media (max-width: 380px) { .sum-col strong { font-size: 17px; } .top h1 { font-size: 23px; } }
@media (prefers-reduced-motion: reduce) { .btn:active { transform: none; } }

/* ---- tabs, views ---- */
body { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
.view[hidden] { display: none; }
.view-title { font-size: 22px; margin: 6px 4px 10px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  position: relative; flex: 1; max-width: 160px; min-height: 60px; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 12px; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.tab svg { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--accent); }
.badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px; background: #d9534f; color: #fff; font-size: 11px; line-height: 18px; text-align: center; padding: 0 5px; font-style: normal; }
.badge[hidden] { display: none; }
.toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-top: 14px; padding: 3px; }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); }
.hint { font-size: 14px; color: var(--muted); margin: 8px 2px 0; min-height: 0; }
.hint:empty { display: none; }
.sub { margin: 14px 0 0; font-size: 15px; color: var(--muted); }

.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); margin-left: 6px; border: 1px solid transparent; vertical-align: 1px; }
.tag.auto { border: 1px dashed var(--muted); background: transparent; color: var(--muted); }
.tag.bad { background: #fde3e0; color: #8c1d12; }
.tag.warn { background: #fdf0cf; color: #6b4a00; }
@media (prefers-color-scheme: dark) { .tag.bad { background: #4a1f1a; color: #ffb4a9; } .tag.warn { background: #4a3a10; color: #ffd98a; } }

.usefirst, .alert { background: #fdf0cf; color: #4d3800; border-radius: 14px; padding: 10px 12px; margin: 8px 0; }
.alert.bad { background: #fde3e0; color: #7a1a10; }
@media (prefers-color-scheme: dark) { .usefirst, .alert { background: #3d3112; color: #ffe2a0; } .alert.bad { background: #451d18; color: #ffc9c1; } }
.usefirst[hidden], .alert[hidden] { display: none; }
.usefirst h3 { margin: 0 0 6px; font-size: 15px; }
.usefirst .pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { min-height: 36px; border: 0; border-radius: 18px; padding: 0 12px; font: inherit; font-size: 14px; background: rgba(0,0,0,.08); color: inherit; cursor: pointer; }
.pill.expired { background: #d9534f; color: #fff; }

.group h2 .link { margin-left: auto; font-size: 13px; text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--accent); background: none; border: 0; min-height: 36px; cursor: pointer; font-family: inherit; }
.row-item .cat-ico { flex: 0 0 auto; padding: 0 4px 0 12px; }
.row-item.expired .name { color: var(--danger); }
.row-item .acts { display: flex; align-items: center; }
.used { min-height: 44px; padding: 0 12px; border: 1.5px solid var(--accent); border-radius: 12px; background: transparent; color: var(--accent); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; margin-right: 2px; }
.price.date { padding-right: 8px; }
.price.date span { color: var(--muted); font-size: 14px; }
.price.date input { min-width: 0; font-size: 16px; padding-left: 8px; }
input[type=date] { font: inherit; }
.settings { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin: 14px 4px; font-size: 15px; }
select { font: inherit; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 0 10px; }
.foot { flex-wrap: wrap; gap: 8px; }

/* stores */
.note { background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; margin: 0 0 12px; font-size: 15px; }
details.store { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; box-shadow: var(--shadow); overflow: hidden; }
details.store > summary { list-style: none; display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 8px 14px; cursor: pointer; }
details.store > summary::-webkit-details-marker { display: none; }
details.store > summary::after { content: "\203A"; margin-left: 6px; font-size: 28px; line-height: 1; color: var(--muted); transition: transform .15s; }
details.store[open] > summary::after { transform: rotate(90deg); }
.store-name { font-weight: 700; font-size: 18px; }
.store-blurb { display: block; font-size: 13px; color: var(--muted); font-weight: 400; }
.count { font-size: 13px; color: var(--muted); }
.offers { padding: 0 14px 12px; }
.offer { border-top: 1px solid var(--line); padding: 10px 0; }
.offer h4 { margin: 0 0 2px; font-size: 16px; }
.offer p { margin: 2px 0; font-size: 14px; color: var(--muted); }
.offer .price-line { font-weight: 700; font-size: 17px; color: var(--ink); }
.offer .meta { font-size: 13px; }
.offer a { color: var(--accent); font-weight: 600; }
.yours { font-size: 14px; background: var(--accent-soft); border-radius: 10px; padding: 6px 10px; margin-bottom: 6px; }

/* tips */
.tip { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.tip .emoji { font-size: 30px; line-height: 1.1; flex: 0 0 auto; }
.tip h3 { margin: 0 0 2px; font-size: 17px; }
.tip p { margin: 2px 0; font-size: 15px; }
.tip .src { font-size: 13px; color: var(--muted); }
.tip a { color: var(--accent); font-weight: 600; }
.tip .pills { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.toast { width: max-content; min-width: 220px; }
details.store > summary { font-size: 16px; }
details.store > summary .count { white-space: nowrap; }
