:root {
  --bg: #F5F6F2; --panel: #FFFFFF; --panel2: #EEF1EC; --ink: #1E2622; --muted: #5B6862; --faint: #85918A;
  --line: #DDE3DE; --accent: #2E7D55; --accent-ink: #FFFFFF; --danger: #B83227; --warn-bg: #FFF1D6; --warn-ink: #7A4B00;
  --c-grocery: #3E9B4F; --c-household: #3B7DD8; --c-restaurant: #D9701C; --c-kidshop: #8E5BD6; --c-kiduber: #22908C; --c-other: #85918A;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --panel: #1C221F; --panel2: #262E2A; --ink: #E8EEEA; --muted: #A5B2AB; --faint: #77837C;
    --line: #2F3833; --accent: #6CC594; --accent-ink: #0E1A13; --danger: #F08A7E; --warn-bg: #3A2C10; --warn-ink: #F6CD7E;
    --c-grocery: #67C177; --c-household: #78A9EE; --c-restaurant: #F0A060; --c-kidshop: #B595EE; --c-kiduber: #5EC5C0;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.4; -webkit-tap-highlight-color: transparent; }
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 40px) max(16px, env(safe-area-inset-left));
}
.loading { padding: 40vh 0; text-align: center; color: var(--muted); }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 12px; }
.top h1 { margin: 0; font-size: 26px; letter-spacing: -.01em; }
.hello { font-size: 14px; color: var(--muted); }
.badge { background: var(--panel2); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600; }
.iconbtn { width: 44px; height: 44px; flex: none; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 20px; display: grid; place-items: center; }

.banner { border-radius: 14px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; }
.banner.demo { background: var(--panel2); color: var(--muted); }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 16px; margin-bottom: 14px; }

/* category colours */
.cat-grocery { --cc: var(--c-grocery); }
.cat-household { --cc: var(--c-household); }
.cat-restaurant { --cc: var(--c-restaurant); }
.cat-kidshop { --cc: var(--c-kidshop); }
.cat-kiduber { --cc: var(--c-kiduber); }
.cat-other { --cc: var(--c-other); }

/* month summary */
.sum-hd { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.sum-hd span { color: var(--muted); font-size: 15px; }
.sum-hd b { font-size: 26px; font-variant-numeric: tabular-nums; }
.sum-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sum-c { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  background: var(--panel2); border-radius: 14px; padding: 8px 10px; border-left: 4px solid var(--cc); }
.sum-c .e { grid-row: 1 / 3; font-size: 20px; }
.sum-c .n { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-c b { font-size: 15px; font-variant-numeric: tabular-nums; }

/* form */
.bill { display: flex; flex-direction: column; gap: 10px; }
.amt { display: flex; align-items: center; gap: 4px; border: 1.5px solid var(--line); border-radius: 16px; padding: 0 14px; background: var(--bg); }
.amt:focus-within, .store:focus { border-color: var(--accent); }
.amt .cur { font-size: 30px; font-weight: 600; color: var(--muted); }
.amt input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 34px; font-weight: 700; padding: 8px 0; outline: none; font-variant-numeric: tabular-nums; }
.store { height: 48px; border: 1.5px solid var(--line); border-radius: 14px; padding: 0 14px; font-size: 17px; background: var(--bg); outline: none; }
.sugs { display: flex; flex-wrap: wrap; gap: 6px; }
.sugs:empty { display: none; }
.sug { border: 1px dashed var(--faint); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--ink); }
.cats { display: flex; flex-wrap: wrap; gap: 8px; }
.cat { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 6px 14px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--panel); font-size: 15px; font-weight: 500; }
.cat .e { font-size: 17px; }
.cat.on { background: var(--cc); border-color: var(--cc); color: #fff; font-weight: 700; }
.row2 { display: flex; gap: 8px; align-items: stretch; }
.seg { display: flex; flex: 1; background: var(--panel2); border-radius: 14px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 11px; min-height: 42px; font-size: 15px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.datebtn { position: relative; display: flex; align-items: center; justify-content: center; min-width: 128px; border-radius: 14px;
  background: var(--panel2); font-size: 15px; font-weight: 500; padding: 0 12px; white-space: nowrap; }
.datebtn input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; border: 0; }
.links { display: flex; gap: 18px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 15px; padding: 6px 0; }
textarea { border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 14px; font-size: 16px; background: var(--bg); resize: vertical; outline: none; }
textarea:focus { border-color: var(--accent); }
.split { background: var(--panel2); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.split-hd { font-weight: 600; font-size: 14px; color: var(--muted); }
.prow { display: flex; gap: 6px; align-items: center; }
.prow select { flex: 1; min-width: 0; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px; font-size: 16px; }
.pamt { display: flex; align-items: center; width: 116px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); padding: 0 8px; }
.pamt span { color: var(--muted); }
.pamt input { width: 100%; min-width: 0; border: 0; background: transparent; font-size: 16px; outline: none; }
.x { width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); font-size: 16px; }
.remain { font-size: 14px; color: var(--muted); }
.remain.bad, .err { color: var(--danger); }
.err { font-size: 14px; font-weight: 600; }
.err:empty { display: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 0 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel); font-size: 16px; font-weight: 600; }
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-size: 17px; min-height: 52px; }
.btn.primary:disabled { opacity: .6; }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.card .btn.wide + .btn.wide { margin-top: 8px; }

/* list */
h2.sec { font-size: 18px; margin: 18px 4px 4px; }
.dayhd { font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 4px 6px; text-transform: uppercase; letter-spacing: .03em; }
.group { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.bill-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: transparent; padding: 12px 14px; }
.bill-row:first-child { border-top: 0; }
.bill-row:active { background: var(--panel2); }
.dot { width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center; font-size: 19px;
  background: var(--panel2); background: color-mix(in srgb, var(--cc) 18%, transparent); }
.mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mid .m { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mid .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cash { color: var(--warn-ink); background: var(--warn-bg); border-radius: 6px; padding: 0 5px; font-weight: 700; }
.bill-row .val, .del-row .val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
#list > .btn { margin-top: 14px; }

/* sign in */
.signin { padding-top: 6vh; text-align: center; }
.signin .logo { width: 96px; height: 96px; border-radius: 22px; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.signin h1 { margin: 12px 0 0; }
.signin .sub { color: var(--muted); margin: 4px 0 20px; }
.signin .card { text-align: left; }
.signin .card p { margin: 0 0 12px; }
.demo-note { background: var(--panel2); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.fld { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; font-weight: 600; color: var(--muted); }
.fld input { height: 48px; border: 1.5px solid var(--line); border-radius: 14px; padding: 0 14px; font-size: 17px; font-weight: 400; color: var(--ink); background: var(--bg); outline: none; }
.fld input:focus { border-color: var(--accent); }
.fine { font-size: 13px; color: var(--muted); margin: 12px 0 0; }

/* sheets */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto; max-height: calc(100% - env(safe-area-inset-top) - 24px);
  display: flex; flex-direction: column; background: var(--bg); border-radius: 22px 22px 0 0; box-shadow: 0 -6px 30px rgba(0,0,0,.2); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-hd { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.sheet-hd h2 { margin: 0; font-size: 20px; }
.sheet-bd { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px calc(env(safe-area-inset-bottom) + 20px); }
.menu-item { display: block; width: 100%; text-align: left; min-height: 52px; border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 0 16px; margin-bottom: 8px; font-size: 16px; font-weight: 500; }
.who { margin: 0 0 12px; color: var(--muted); }
.radios { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; margin-bottom: 12px; }
.radios label { display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 0 14px; border-top: 1px solid var(--line); }
.radios label:first-child { border-top: 0; }
.radios input { width: 20px; height: 20px; accent-color: var(--accent); }
.custom { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.count { font-weight: 600; margin: 4px 0 12px; }
.detail { display: flex; flex-direction: column; gap: 6px; }
.detail .big { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.parts { padding-left: 0; list-style: none; margin: 8px 0; }
.parts li { padding: 6px 0; border-top: 1px solid var(--line); }
.note { background: var(--panel); border-radius: 12px; padding: 10px 12px; margin: 0; }
.del-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }

/* toast */
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 24px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 15px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } #toast { transition: none; } }
