:root {
  --primary: #1a7ed4;
  --sky: #3fb4ec;
  --good: #2f9e44;
  --primary-d: #135d9e;
  --primary-l: #e2f2fc;
  --bg: #f3f7fb;
  --card: #fff;
  --text: #17222d;
  --muted: #66788a;
  --line: #dfe7ef;
  --warn: #c2410c;
  --red: #c92a2a;
  --amber: #e9a23b;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c; --card: #18212b; --text: #e7eef5; --muted: #93a3b3; --line: #273442; --primary-l: #16324a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; }
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(80px + var(--safe-b)); }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--text); background: var(--card); }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: linear-gradient(120deg, var(--primary), var(--sky)); color: #fff; }
.brand { font-weight: 700; font-size: 19px; }
.sync-badge { border: 0; background: rgba(255,255,255,.18); color: #fff; border-radius: 99px; padding: 4px 10px; font-size: 12px; }
.sync-badge.ok::first-letter { color: #bfe9ff; }
.sync-badge.err::first-letter { color: #ffb4a2; }
.sync-badge.local::first-letter { color: #ffe08a; }

main { padding: 12px 14px; }

.addbar { display: flex; gap: 8px; position: sticky; top: 56px; z-index: 4; background: var(--bg); padding: 4px 0 10px; }
.addbar input { flex: 1; min-width: 0; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.addbar input:focus { outline: none; border-color: var(--primary); }
.icon-btn { width: 48px; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; font-size: 20px; }
.icon-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-size: 26px; }

.hint { display: block; width: 100%; text-align: left; border: 0; border-radius: 12px; background: #fff6dc;
  color: #6a4b00; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
@media (prefers-color-scheme: dark) { .hint { background: #3a3014; color: #f2d98a; } }

.group { background: var(--card); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; border: 1px solid var(--line); }
.group h3 { margin: 0; padding: 10px 14px; font-size: 14px; display: flex; justify-content: space-between;
  background: var(--primary-l); color: var(--primary-d); }
@media (prefers-color-scheme: dark) { .group h3 { color: #8fd0f7; } }
.group h3 small { font-weight: 600; opacity: .8; }
.group.complete { opacity: .55; }
.group ul { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; user-select: none; }
.item:first-child { border-top: 0; }
.item .body { flex: 1; min-width: 0; }
.item .name { font-weight: 600; }
.item .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.item.urgent { box-shadow: inset 4px 0 0 var(--red); }
.urgent-tag { font-size: 10px; background: var(--red); color: #fff; border-radius: 4px; padding: 1px 5px; vertical-align: 2px; }
.warn { color: var(--warn); font-weight: 600; }
.item .check { width: 28px; height: 28px; flex: none; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; font-weight: 800; color: #fff; }
.item.checked .check { background: var(--primary); border-color: var(--primary); }
.item.checked .name { text-decoration: line-through; color: var(--muted); }
.item.checked { background: rgba(26,126,212,.06); }
body.shopping .item { padding: 15px 14px; }
body.shopping .item .name { font-size: 18px; }

.avatar { width: 26px; height: 26px; border-radius: 50%; color: #fff; font-size: 13px; font-weight: 700; flex: none;
  display: inline-grid; place-items: center; vertical-align: middle; }

.progress-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
  position: sticky; top: 56px; z-index: 4; }
.progress-card small { color: var(--muted); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.bar { height: 10px; background: var(--line); border-radius: 99px; margin: 8px 0; overflow: hidden; }
.bar.thin { height: 6px; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; background: var(--line); }
.btn.primary { background: linear-gradient(120deg, var(--primary), var(--sky)); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--red); border: 1.5px solid currentColor; }
.btn.block { display: block; width: 100%; margin-top: 10px; text-align: center; }
.btn.small { padding: 7px 12px; font-size: 14px; }
label.btn { cursor: pointer; }

.list-footer { margin: 16px 0; }
.estimate { text-align: center; color: var(--muted); }
.estimate b { color: var(--text); }
.shopping-actions { position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-b)); display: flex; gap: 10px;
  padding: 10px 14px; max-width: 640px; margin: 0 auto; background: linear-gradient(transparent, var(--bg) 30%); z-index: 6; }
.shopping-actions .btn { flex: 1; padding: 15px; }
.shopping-actions .btn.primary { flex: 2; }
body.shopping main { padding-bottom: 90px; }

.empty { text-align: center; padding: 40px 20px; }
.empty.small { padding: 20px; }
.empty .big, .welcome .big { font-size: 54px; }
.muted { color: var(--muted); }
.tiny { font-size: 12.5px; }
.center { text-align: center; }

.intro h2 { margin: 6px 0 4px; font-size: 21px; }
.intro p { margin: 0 0 14px; }
.subhead { font-size: 15px; margin: 22px 0 10px; }
.cards { list-style: none; padding: 0; margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.card .name { font-weight: 700; }
.card .meta { font-size: 13px; color: var(--muted); }
.card.info { background: var(--primary-l); border-color: transparent; }
.sug .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.sug.late { border-left: 4px solid var(--red); }
.sug.due { border-left: 4px solid var(--amber); }
.sug.soon { border-left: 4px solid var(--primary); }
.sug.late .bar i { background: var(--red); }
.sug.due .bar i { background: var(--amber); }
.trip { cursor: pointer; }
.link { color: var(--primary); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 99px; padding: 7px 12px; font-size: 14px; }
.chip.static { display: inline-flex; align-items: center; gap: 6px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat.wide { grid-column: 1 / -1; }
.stat small { display: block; color: var(--muted); font-size: 12.5px; }
.stat b { display: block; font-size: 22px; margin: 2px 0; }
.stat span { font-size: 12.5px; }
.up { color: var(--red); }
.down { color: var(--good); }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 12px 6px; }
.bars .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.bars i { display: block; width: 100%; max-width: 36px; background: var(--primary); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.bars .v { font-size: 11px; color: var(--muted); }
.bars .l { font-size: 12px; color: var(--muted); }
.breakdown { list-style: none; padding: 0; margin: 0; }
.breakdown li { position: relative; display: flex; justify-content: space-between; padding: 9px 12px; margin-bottom: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; font-size: 14px; }
.breakdown li span, .breakdown li b { position: relative; z-index: 1; }
.breakdown li i { position: absolute; inset: 0 auto 0 0; background: var(--primary-l); }
.plain { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.plain li { display: flex; justify-content: space-between; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 14px; }
.plain li:first-child { border-top: 0; }

.code { font: 700 24px/1.3 ui-monospace, Menlo, monospace; letter-spacing: 2px; margin: 4px 0; }
.warnbox { background: #fff6dc; color: #6a4b00; padding: 10px; border-radius: 10px; }
.okbox { background: var(--primary-l); padding: 10px; border-radius: 10px; }
@media (prefers-color-scheme: dark) { .warnbox { background: #3a3014; color: #f2d98a; } }
.stack .btn.block { margin-top: 8px; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); z-index: 7; max-width: 640px; margin: 0 auto; }
.tabbar button { flex: 1; border: 0; background: none; padding: 8px 0 10px; font-size: 11.5px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.tabbar button span { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--primary); font-weight: 700; }
.tabbar button.active span { filter: none; opacity: 1; }
.dot { position: absolute; top: 4px; right: calc(50% - 22px); background: var(--red); color: #fff; font-style: normal;
  font-size: 10px; min-width: 17px; height: 17px; border-radius: 99px; display: grid; place-items: center; padding: 0 4px; }
.dot[hidden] { display: none; }

.banner { margin: 10px 14px 0; padding: 10px 12px; border-radius: 12px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.shopping-banner { background: #fff1db; color: #7a4a00; }
@media (prefers-color-scheme: dark) { .shopping-banner { background: #3a2a12; color: #f6d39a; } }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop[hidden] { display: none; }
.sheet { background: var(--card); width: 100%; max-width: 640px; border-radius: 20px 20px 0 0; padding: 8px 18px calc(20px + var(--safe-b));
  max-height: 92vh; overflow: auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 40px; height: 5px; background: var(--line); border-radius: 9px; margin: 4px auto 10px; }
.sheet h3 { margin: 4px 0 12px; }
.sheet label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.sheet label input:not([type=checkbox]), .sheet select { display: block; width: 100%; margin-top: 5px; padding: 11px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; font-weight: 400; }
.sheet .two { display: flex; gap: 10px; align-items: flex-end; }
.sheet .two label { flex: 1; }
.sheet label.toggle { display: flex; align-items: center; gap: 8px; padding: 11px 0; }
.sheet label.toggle input { width: 22px; height: 22px; accent-color: var(--red); }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet-actions .btn { flex: 1; }
.trip-items { font-size: 14px; color: var(--muted); }
.welcome { text-align: center; }
.welcome h2 { margin: 0 0 6px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-b)); z-index: 30;
  background: #222; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 28px);
  display: flex; gap: 14px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast[hidden] { display: none; }
.toast button { border: 0; background: none; color: #bfe9ff; font-weight: 700; }
body.shopping .toast { bottom: calc(150px + var(--safe-b)); }
