:root {
  --bg: #f4f1ec; --card: #ffffff; --ink: #1d1f23; --muted: #596070; --line: #e4e0d8;
  --accent: #1a5fd0; --on-accent: #ffffff; --ok: #146c39; --on-ok: #ffffff; --ok-bg: #dcf2e4;
  --warn: #7d4800; --warn-bg: #fff1d6;
  --chip: #e9edf4; --chip-ink: #1c2d49; --change: #e3edff; --danger: #b3261e;
  --shadow: 0 8px 28px rgba(20, 24, 32, .14);
  --radius: 22px;
  --vvh: 100dvh; --vvt: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --card: #1f2227; --ink: #f1f2f4; --muted: #a9afba; --line: #30343b;
    --accent: #7db1ff; --on-accent: #06142a; --ok: #52cc85; --on-ok: #07140d; --ok-bg: #173323;
    --warn: #f3b95a; --warn-bg: #3a2c10;
    --chip: #2a2f38; --chip-ink: #dbe6fa; --change: #1b2c4a; --danger: #ff8a80;
    --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { touch-action: manipulation; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
button { font: inherit; color: inherit; touch-action: manipulation; }
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom); position: relative; overflow: hidden; }

.top { display: flex; align-items: center; gap: 8px; padding: 10px 2px 6px; min-height: 52px; }
.count { background: var(--accent); color: var(--on-accent); border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.count.zero { background: var(--ok-bg); color: var(--ok); }
.link { margin-left: auto; background: none; border: 0; color: var(--accent); font-size: 15px; font-weight: 600; white-space: nowrap; padding: 10px 2px; min-height: 44px; text-align: right; cursor: pointer; }

main { flex: 1; min-height: 0; position: relative; padding: 4px 0 10px; display: flex; }
main.login { display: block; flex: none; min-height: 0; padding: 28px 22px; }
.loading { margin: auto; color: var(--muted); }
.stack { position: relative; flex: 1; min-width: 0; }
.card, .backcard { position: absolute; inset: 0; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.backcard { transform: scale(.955) translateY(14px); opacity: .7; }
.backcard.b2 { transform: scale(.91) translateY(28px); opacity: .45; }
.card { padding: 18px 18px 26px; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; user-select: none; -webkit-user-select: none;
  outline: none; transition: transform .22s ease, opacity .22s ease; will-change: transform; overscroll-behavior: contain; }
.card.dragging { transition: none; }
.card:focus-visible { box-shadow: var(--shadow), 0 0 0 3px var(--accent); }
.card.gone-right { transform: translateX(130%) rotate(14deg); opacity: 0; }
.card.gone-left { transform: translateX(-130%) rotate(-14deg); opacity: 0; }
.stamp { position: absolute; top: 14px; z-index: 2; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  border: 3px solid; border-radius: 10px; padding: 2px 10px; opacity: 0; pointer-events: none; font-size: 17px; background: var(--card); }
.stamp.yes { left: 16px; right: auto; color: var(--ok); border-color: var(--ok); transform: rotate(-8deg); }
.stamp.no { right: 16px; left: auto; color: var(--muted); border-color: var(--muted); transform: rotate(8deg); }

.store-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 16px; }
.store { font-weight: 650; color: var(--ink); font-size: 19px; }
.total { font-size: 46px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0 4px; font-variant-numeric: tabular-nums; }
.total.refund { color: var(--ok); }
.badge { font-size: 14px; font-weight: 700; border-radius: 999px; padding: 3px 10px; background: var(--ok-bg); color: var(--ok); vertical-align: middle; letter-spacing: 0; }
.amountnote { color: var(--muted); font-size: 15px; margin: 0 0 6px; }
.note { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 8px 12px; margin: 6px 0; font-size: 15px; }
.note.info { background: var(--chip); color: var(--chip-ink); }
.note.blocked { font-weight: 650; }
.locked { background: var(--chip); color: var(--chip-ink); border-radius: 12px; padding: 8px 12px; margin: 6px 0; font-size: 15px; }
.err { background: var(--warn-bg); color: var(--warn); }

ul.items { list-style: none; margin: 6px 0 0; padding: 0; }
.itemhead { margin: 12px 0 0; font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.item { padding: 11px 0; border-top: 1px solid var(--line); }
.item.changed { background: var(--change); margin: 0 -10px; padding: 11px 10px 11px 8px; border-radius: 12px; border-top-color: transparent; border-left: 4px solid var(--accent); }
.line { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.title { flex: 1; min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere; background: none; border: 0; padding: 0; text-align: left; font-size: 17px; }
button.title { cursor: pointer; min-height: 44px; padding-right: 22px; position: relative; }
button.title::after { content: "▾"; position: absolute; right: 0; bottom: 8px; color: var(--muted); font-size: 14px; }
button.title.fits { min-height: 0; padding-right: 0; cursor: default; color: var(--ink); opacity: 1; }
button.title.fits::after { content: none; }
button.title.open { display: block; -webkit-line-clamp: unset; }
button.title.open::after { content: "▴"; }
.price { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.chiprow { display: flex; align-items: center; gap: 10px; margin-top: 7px; flex-wrap: wrap; }
.chip { min-height: 44px; border-radius: 999px; border: 1px solid transparent; background: var(--chip); color: var(--chip-ink);
  padding: 6px 14px; font-size: 16px; font-weight: 600; max-width: 100%; text-align: left; cursor: pointer; display: inline-flex; align-items: center; }
.chip::after { content: " ▾"; opacity: .7; white-space: pre; }
.chip.static { cursor: default; background: none; border: 0; padding: 2px 0; min-height: 30px; color: var(--chip-ink); }
.chip.static::after { content: none; }
.chip.empty { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.why { font-size: 14px; color: var(--muted); }
.why.unsure { color: var(--warn); font-weight: 700; }
.was { font-size: 14px; color: var(--chip-ink); margin-top: 4px; }
.splitrow { margin: 8px 0 4px; padding: 10px 12px; border-radius: 12px; background: var(--chip); color: var(--chip-ink); font-size: 15px; }
.revised { margin: 10px 0 6px; padding: 12px; border-radius: 14px; background: var(--change); color: var(--ink); font-size: 16px; border-left: 4px solid var(--accent); }
.revised strong { display: block; font-size: 13px; letter-spacing: .05em; text-transform: uppercase; color: var(--chip-ink); }
.revised .row { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.revised .row span { display: block; }
.revised .row .tiny { margin-top: 8px; }
.tiny { background: none; border: 1px solid var(--muted); color: var(--ink); border-radius: 999px; padding: 6px 14px; min-height: 44px; font-size: 15px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tiny.fill { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.order { display: inline-block; margin: 10px 0 2px; color: var(--accent); font-size: 16px; padding: 8px 0; min-height: 44px; font-weight: 600; }
.updating { margin: 14px 0; text-align: center; color: var(--muted); }
.updating .dots::after { content: "…"; animation: blink 1s steps(3) infinite; }
@keyframes blink { 50% { opacity: .3; } }

.hint { margin: 0 0 6px; text-align: center; color: var(--muted); font-size: 14px; }

.actions { display: grid; grid-template-columns: .9fr 1.1fr 1.5fr; gap: 10px; padding: 4px 0 10px; }
.act { min-height: 62px; border-radius: 18px; border: 1px solid var(--line); background: var(--card); font-weight: 650; font-size: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.06); padding: 4px 3px; line-height: 1.15; text-align: center; }
.act.fix { font-size: 17px; white-space: nowrap; }
.act .ico { font-size: 22px; line-height: 1; height: 22px; display: flex; align-items: center; }
.act .ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.act.ok { background: var(--ok); color: var(--on-ok); border-color: var(--ok); }
.act.ok.off { background: var(--chip); color: var(--chip-ink); border-color: var(--line); font-size: 16px; }
.act.dim { background: none; color: var(--muted); box-shadow: none; }
.act:disabled { opacity: .55; }
.act:focus-visible, .chip:focus-visible, .tiny:focus-visible, .link:focus-visible, .big:focus-visible, .row-btn:focus-visible, .title:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.toasts { position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(92px + env(safe-area-inset-bottom)); max-width: 536px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
body.modal .toasts { bottom: auto; top: calc(10px + env(safe-area-inset-top) + var(--vvt)); }
body.modal .toasts .toast:not([role=alert]) { display: none; }
.toast { pointer-events: auto; position: relative; overflow: hidden; background: #20242b; color: #fff; border-radius: 14px; padding: 4px 6px 4px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; box-shadow: var(--shadow); min-height: 48px; }
.toast .msg { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.toast .msg.wrap { white-space: normal; }
.toast .st { color: #c9d3e3; margin-left: 8px; }
.toast .msg.wrap .st { display: block; margin-left: 0; font-size: 15px; }
.toast button { background: none; border: 0; color: #8fc1ff; font-weight: 700; font-size: 17px; min-height: 44px; min-width: 44px; padding: 0 14px; cursor: pointer; }
.toast .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: #8fc1ff; width: 100%; transform-origin: left; animation: shrink 6s linear forwards; }
@keyframes shrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.overlay { position: fixed; left: 0; right: 0; top: var(--vvt); height: var(--vvh); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet { position: relative; width: 100%; max-width: 560px; max-height: 92%; overflow-y: auto; background: var(--card); border-radius: 24px 24px 0 0;
  padding: 18px 18px 0; box-shadow: var(--shadow); overscroll-behavior: contain; }
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.sheet p { margin: 4px 0 10px; color: var(--muted); font-size: 15px; }
.fixrow { padding: 10px 0; border-top: 1px solid var(--line); }
.fixrow .t { font-size: 15px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; margin-bottom: 6px; }
label.lbl { display: block; font-weight: 650; margin: 12px 0 4px; }
textarea, input[type=search] { width: 100%; font: inherit; font-size: 17px; border: 1px solid var(--muted); border-radius: 14px; padding: 12px; background: var(--bg); color: var(--ink); -webkit-user-select: text; user-select: text; }
textarea { min-height: 96px; resize: none; }
.formerr { margin: 8px 0 0; padding: 8px 12px; border-radius: 12px; background: var(--warn-bg); color: var(--warn); font-size: 15px; font-weight: 600; }
.btns { display: flex; gap: 10px; margin-top: 14px; }
.sheet .btns { position: sticky; bottom: 0; background: var(--card); padding: 10px 0 calc(12px + env(safe-area-inset-bottom)); margin-top: 8px; border-top: 1px solid var(--line); }
.sheet .btns::before { content: ""; position: absolute; left: 0; right: 0; top: -26px; height: 26px; background: linear-gradient(transparent, var(--card)); pointer-events: none; }
.btns button, .big { flex: 1; min-height: 56px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); font-weight: 650; font-size: 18px; cursor: pointer; }
.btns .primary, .big { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btns button:disabled { opacity: .6; }
.big { width: 100%; margin-top: 12px; }
.picker input[type=search] { margin: 8px 0 6px; }
.grp { margin: 14px 0 4px; font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.grp.sug { color: var(--accent); }
.row-btn { display: block; width: 100%; text-align: left; background: none; border: 0; border-top: 1px solid var(--line); padding: 0 4px; min-height: 52px; font-size: 18px; cursor: pointer; }
.row-btn.sel { color: var(--accent); font-weight: 700; }
.row-btn.sel::after { content: "  ✓"; }
.recent-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.recent-row .meta { flex: 1; min-width: 0; }
.recent-row .m1 { font-weight: 650; }
.recent-row .m2 { font-size: 14px; color: var(--muted); }
.recent-row .m1.refund { color: var(--ok); }
.daygrp { margin: 12px 0 2px; font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }

.empty-state { margin: auto; text-align: center; padding: 24px; }
.empty-state .big-check { font-size: 64px; color: var(--ok); line-height: 1; }
.empty-state h2 { font-size: 28px; margin: 10px 0 6px; }
.empty-state p { color: var(--muted); margin: 6px 0; }
.empty-state .tiny { margin: 6px 4px; }

body.plain { display: flex; align-items: center; justify-content: center; min-height: 100%; }
.login { max-width: 420px; padding: 28px 22px; text-align: center; }
.login h1 { font-size: 26px; }
.login p { color: var(--muted); }
.signedout { margin: auto; text-align: center; padding: 24px; }
.signedout h2 { font-size: 26px; }
.signedout p { color: var(--muted); }

.card::after { content: ""; position: sticky; bottom: -26px; display: block; height: 34px; margin: 0 -18px -26px;
  background: linear-gradient(transparent, var(--card)); pointer-events: none; }
