:root {
  --bg: #f5f7f6;
  --card: #ffffff;
  --text: #14211f;
  --muted: #5d6b68;
  --line: #dbe3e0;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d9f0ec;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok-soft: #dcfce7;
  --ok: #166534;
  --danger: #b91c1c;
  --radius: 14px;
  --tab-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513;
    --card: #17211f;
    --text: #e8f0ee;
    --muted: #9fb0ac;
    --line: #2a3835;
    --accent: #2dd4bf;
    --accent-ink: #052e2a;
    --accent-soft: #123b36;
    --warn: #fbbf24;
    --warn-soft: #3a2c08;
    --ok-soft: #12351f;
    --ok: #86efac;
    --danger: #f87171;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--accent); color: var(--accent-ink);
}
.top h1 { margin: 0; font-size: 20px; font-weight: 650; }
.top-btn { background: transparent; color: inherit; border: 1.5px solid currentColor; border-radius: 99px; padding: 4px 12px; font-size: 13px; font-weight: 600; cursor: pointer; opacity: .9; }

/* sign-in screen: only shown when login is on and nobody is signed in */
.login { display: none; padding: 32px 16px; max-width: 460px; margin: 0 auto; }
.login h2 { margin: 0 0 8px; font-size: 24px; }
.login .btn { width: 100%; margin: 8px 0 14px; }
body.logged-out .login { display: block; }
body.logged-out main, body.logged-out .tabs { display: none; }

.badge { background: var(--warn-soft); color: var(--warn); border-radius: 99px; padding: 2px 10px; font-size: 12px; font-weight: 600; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }
.hint { margin: 0 0 14px; color: var(--muted); }

/* form */
.form { display: grid; gap: 16px; }
.field { scroll-margin-top: 76px; }  /* keep focused fields clear of the sticky header */
.field label, .field .label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field.uncertain label, .field.uncertain .label { color: var(--warn); }
.field.uncertain input[type=text], .field.uncertain input[type=date] { border-color: var(--warn); background: var(--warn-soft); }
.field .why { display: none; font-size: 12px; color: var(--warn); margin-top: 4px; }
.field.uncertain .why { display: block; }
input[type=text], input[type=date], select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  font: inherit; color: var(--text); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px;
}
input:focus-visible, select:focus-visible, button:focus-visible, .big-btn:focus-within {
  outline: 3px solid var(--accent); outline-offset: 1px;
}
.amount-wrap { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 0 12px; }
.field.uncertain .amount-wrap { border-color: var(--warn); background: var(--warn-soft); }
.amount-wrap span { font-size: 28px; font-weight: 600; color: var(--muted); }
.amount-wrap input { border: 0; background: transparent; font-size: 32px; font-weight: 650; min-height: 60px; padding: 0; outline: none; }
.amount-wrap:focus-within { outline: 3px solid var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 6px 14px; border-radius: 99px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit;
}
.chip[aria-checked=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.add { border-style: dashed; color: var(--accent); }
.field-error { color: var(--danger); font-size: 13px; margin-top: 4px; min-height: 0; }

/* buttons */
.btn {
  min-height: 52px; width: 100%; border: 0; border-radius: 12px; cursor: pointer;
  font: inherit; font-weight: 650; font-size: 17px;
  background: var(--accent); color: var(--accent-ink);
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid var(--line); }
.btn-row { display: grid; gap: 10px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font-size: 24px; cursor: pointer; }

/* scan */
.big-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 180px; border: 2px dashed var(--accent); border-radius: var(--radius);
  background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 18px; cursor: pointer;
}
.big-ico { font-size: 44px; }
.preview { width: 100%; max-height: 240px; object-fit: contain; background: #0001; border-radius: var(--radius); margin-bottom: 12px; }
.status { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-weight: 500; }
.status.busy { background: var(--accent-soft); color: var(--accent); }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.status.check { background: var(--warn-soft); color: var(--warn); }
.status.err { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) { .status.err { background: #3b1212; color: #fecaca; } }
.status ul { margin: 6px 0 0; padding-left: 20px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
#scan-cancel { margin-top: 12px; }

/* month */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.total-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-align: center; }
.big-number { font-size: 36px; font-weight: 700; margin: 2px 0; }
.cats { margin: 16px 0; display: grid; gap: 10px; }
.cat-row .cat-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.section-title { font-size: 15px; margin: 20px 0 8px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; color: var(--text); font: inherit;
}
.item .date { min-width: 46px; text-align: center; font-size: 13px; color: var(--muted); line-height: 1.2; }
.item .date b { display: block; font-size: 18px; color: var(--text); }
.item .mid { flex: 1; min-width: 0; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 700; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tab {
  min-height: var(--tab-h); border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tab.active { color: var(--accent); }
.tab-ico { font-size: 22px; }

/* toast + dialog */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: all .2s;
  background: #111; color: #fff; padding: 12px 18px; border-radius: 12px; max-width: 90vw; z-index: 30; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #991b1b; }
dialog { width: min(520px, 94vw); max-height: 92vh; overflow: auto; border: 0; border-radius: var(--radius); padding: 18px; background: var(--bg); color: var(--text); }
dialog::backdrop { background: #0008; }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } .toast { transition: none; } }

/* shop */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item.static { cursor: default; }
.chip.add-btn { white-space: nowrap; }
.chip.add-btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
#shop-root .chips { margin-top: 10px; }
#shop-root .list { margin-top: 12px; }
.sticky-btn { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 10px); margin-top: 14px; box-shadow: 0 4px 14px #0003; }
.small-x { width: 38px; height: 38px; font-size: 16px; }
.chg { font-size: 13px; font-weight: 650; white-space: nowrap; }
.chg.up { color: var(--danger); }
.chg.down { color: var(--ok); }
.chg.same, .chg.none { color: var(--muted); }
.chg.brand { color: var(--warn); }
.big-number.up { color: var(--danger); }
.big-number.down { color: var(--ok); }
.total-bar {
  position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 4; margin: 12px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px;
}
.total-bar .big-number { font-size: 28px; margin: 0; }
.total-bar .vs { text-align: right; }
.cart-row { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; display: grid; gap: 6px; }
.cart-row.done { border-color: var(--accent); }
.cart-head { display: flex; align-items: center; gap: 10px; }
.cart-head .name { flex: 1; font-weight: 650; }
.cart-head input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
.x-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; min-width: 40px; min-height: 40px; cursor: pointer; }
.cart-inputs { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.mini { display: grid; gap: 2px; font-size: 12px; color: var(--muted); font-weight: 600; }
.mini input { min-height: 44px; font-size: 18px; padding: 6px 10px; text-align: right; }
.eq { text-align: right; min-width: 74px; }
.line-total { display: block; font-size: 17px; }
.brand-in { min-height: 38px; font-size: 14px; padding: 4px 10px; }
.cart-foot { min-height: 18px; }
.status.check:empty { display: none; }

/* long names must shrink with an ellipsis, not stretch the page past the phone screen */
.list > li { min-width: 0; }
