/* Finance: Origin's look (a pale neutral-grey page, white cards with a hairline edge, mono uppercase labels, outlined
   pill buttons, forest green for money in and coral for money out; Biccy, 9 Nov: "not beige, follow Origin") with
   Copilot's card pictures, rings, status colours and flags. Dark mode keeps the structure on a neutral near-black. */

:root {
  --page: #f6f6f5;
  --paper: #ffffff;
  --ink: #161616;
  --ink-2: #3f3f3f;
  --mute: #767675;
  --faint: #c8c8c6;
  --hair: #e5e5e3;
  --soft: #efefed;
  --on-ink: #ffffff;
  /* status (Copilot) */
  --good: #3f7d3a; --warn: #dd8410; --bad: #d8463a;
  /* money in and out (Origin: deep forest green above, coral below) */
  --in: #2c4a26; --out: #ff7c52; --out-text: #e0603a;
  /* groups: muted and earthy (Origin) */
  --g-food: #e8955a; --g-shop: #e2715e; --g-move: #2a6e6b; --g-bills: #c99a33; --g-other: #868a4c; --g-none: #a19d95; --g-ns: #8e8e94;
  /* card issuers and banks */
  --cc-bar-ktc: #1c1c1e; --cc-bar-wisdom: #55585e; --cc-bar-uob: #9aa1aa; --cc-bar-slate: #5f6a78;
  --bank-scb: #5b2d86; --bank-kbank: #138d48; --bank-ktb: #1aa1dd; --bank-other: #8a8a88;
  /* Origin's cards sit flat: a hairline edge, almost no shadow */
  --shadow: 0 0 0 1px var(--hair), 0 1px 2px rgba(0, 0, 0, .025);
  --lift: 0 14px 34px rgba(0, 0, 0, .2), 0 3px 8px rgba(0, 0, 0, .1);
  --scrim: rgba(0, 0, 0, .32);
  --safe-b: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --safe-t: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --tab-h: 64px;
  --tab-b: calc(var(--safe-b) + 10px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --page: #0c0c0c; --paper: #191919; --ink: #f2f2f2; --ink-2: #d0d0d0; --mute: #8e8e8e; --faint: #474747; --hair: #2b2b2b; --soft: #242424;
  --on-ink: #0b0b0a;
  --good: #7cc073; --warn: #f2a43c; --bad: #f2695c;
  --in: #6fa865; --out: #ff8f6b; --out-text: #ff9b7a;
  --g-food: #f0a46c; --g-shop: #ec8370; --g-move: #46a29d; --g-bills: #dcb355; --g-other: #a6a966; --g-none: #8d8a84; --g-ns: #8f8b83;
  --cc-bar-ktc: #f2f2f4; --cc-bar-wisdom: #868a92; --cc-bar-uob: #c4cad2; --cc-bar-slate: #8a96a4;
  --shadow: 0 0 0 1px var(--hair);
  --lift: 0 14px 34px rgba(0, 0, 0, .7);
  --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0c0c0c; --paper: #191919; --ink: #f2f2f2; --ink-2: #d0d0d0; --mute: #8e8e8e; --faint: #474747; --hair: #2b2b2b; --soft: #242424;
    --on-ink: #0b0b0a;
    --good: #7cc073; --warn: #f2a43c; --bad: #f2695c;
    --in: #6fa865; --out: #ff8f6b; --out-text: #ff9b7a;
    --g-food: #f0a46c; --g-shop: #ec8370; --g-move: #46a29d; --g-bills: #dcb355; --g-other: #a6a966; --g-none: #8d8a84; --g-ns: #8f8b83;
    --cc-bar-ktc: #f2f2f4; --cc-bar-wisdom: #868a92; --cc-bar-uob: #c4cad2; --cc-bar-slate: #8a96a4;
    --shadow: 0 0 0 1px var(--hair);
    --lift: 0 14px 34px rgba(0, 0, 0, .7);
    --scrim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--page); }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 17px/1.35 var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overflow-x: hidden; min-height: 100vh;
  padding-top: var(--safe-t);
  padding-bottom: calc(var(--tab-h) + var(--tab-b) + 28px);
  user-select: none; -webkit-user-select: none;
}
body.dev { padding-top: calc(var(--safe-t) + 22px); }
body.sheet-open { overflow: hidden; }
input { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
b { font-weight: 700; }
.ic { flex: none; display: block; }
#view { max-width: 600px; margin: 0 auto; }
.mute { color: var(--mute); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.center { text-align: center; }

#dev-strip {
  position: fixed; top: var(--safe-t); left: 0; right: 0; z-index: 100; height: 22px;
  padding: 3px 12px; font: 11px/16px var(--mono);
  background: var(--ink); color: var(--on-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none; opacity: .9;
}

/* labels: small UPPERCASE mono with letter-spacing (Origin) */
.label { font: 600 11px/1.3 var(--mono); letter-spacing: .09em; text-transform: uppercase; color: var(--mute); }
.card-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; margin-bottom: 8px; }
.label-aside { font: 600 11px/1.3 var(--mono); letter-spacing: .06em; color: var(--mute); display: inline-flex; align-items: center; gap: 6px; }
.as-of { text-align: center; margin: 18px 0 0; }

/* amounts: a small raised baht sign before tabular digits */
.amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt sup { font-size: .56em; font-weight: 600; line-height: 0; position: relative; top: -.02em; vertical-align: .62em; margin-right: .07em; opacity: .85; }
.amt.in { color: var(--good); }

/* ---------------------------------------------------------------- shared controls (from the Planner) */
.circle {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow);
}
.circle.spinning .ic { animation: spin .6s ease; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 20px; border-radius: 999px; font-size: 16px; font-weight: 650; letter-spacing: -.01em;
  transition: transform .12s ease, opacity .2s ease, background .2s ease;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.ink { background: var(--ink); color: var(--on-ink); }
/* Origin's outlined pill: a thin ink edge, spaced uppercase mono */
.btn.outline { background: var(--paper); color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font: 600 13px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.btn.sm { height: 38px; padding: 0 16px; font-size: 15px; }
.btn.block { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .3; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.sh-actions { display: grid; gap: 10px; margin-top: 16px; }
.text-btn { font: 650 13px var(--font); letter-spacing: 0; text-transform: none; color: var(--ink-2); padding: 4px 2px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 4px; padding: 2px 16px 6px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  height: 36px; padding: 0 14px; border-radius: 999px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow);
  font-size: 14.5px; font-weight: 650; white-space: nowrap; transition: background .2s, color .2s;
}
.chip.on { background: var(--ink); color: var(--on-ink); box-shadow: none; }
.fine { font-size: 13px; line-height: 1.4; color: var(--mute); margin: 8px 0 0; }
.fine.pad { padding: 8px 6px 0; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 32px 22px; text-align: center; color: var(--mute); }
.empty b { color: var(--ink); font-size: 17px; }
.empty p { margin: 0; font-size: 15px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px 0; color: var(--mute); font-size: 15px; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--faint); border-top-color: var(--ink); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- page and cards */
.page { padding: 4px 16px 8px; }
.page-hd { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 4px 14px; }
.page-hd h1 { margin: 0; font-size: 32px; font-weight: 800; letter-spacing: -.025em; line-height: 1.1; }
.page-hd .label { margin-top: 4px; }
.card { background: var(--paper); border-radius: 24px; padding: 18px 18px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card.list { padding: 2px 0; overflow: hidden; }
.card.empty { padding: 28px 22px; }
.sec-hd { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 6px 10px; }
.big-num { font-size: 32px; font-weight: 800; letter-spacing: -.025em; line-height: 1.15; }
.big-num.good .amt { color: var(--good); }
.big-num.bad .amt { color: var(--bad); }
.big-aside { font-size: 15px; font-weight: 600; color: var(--mute); letter-spacing: 0; }

/* rows (from the Planner's grouped list) */
.grow { position: relative; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 14px 0 16px; width: 100%; text-align: left; }
.grow + .grow::before, .txn + .txn::before, .grp + .grp::before, .card-line + .card-line::before, .bank + .bank::before {
  content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: 1px solid var(--hair);
}
.card-line + .card-line::before { left: 16px; }
.bank + .bank::before { left: 42px; }
.grow-label { font-size: 16px; color: var(--ink); flex: none; }
.grow-label.strong { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grow-value { margin-left: auto; font-size: 15.5px; font-weight: 700; text-align: right; white-space: nowrap; }
.grow-aside { font: 600 12px var(--mono); color: var(--mute); flex: none; }
.grow .ic:last-child { color: var(--faint); }
.list .grow + .grow::before { left: 16px; }
.card:not(.list) .list { margin: 0 -18px -8px; }

/* ---------------------------------------------------------------- groups: colour, dot, chip */
.g-food { --g: var(--g-food); }
.g-shop { --g: var(--g-shop); }
.g-move { --g: var(--g-move); }
.g-bills { --g: var(--g-bills); }
.g-other { --g: var(--g-other); }
.g-none { --g: var(--g-none); }
.g-ns { --g: var(--g-ns); } /* Not spending: neutral grey, never a group colour */
.g-in { --g: var(--good); }
.gdot, .gchip, .sort-chip, .gtext, .ring { --g-text: color-mix(in srgb, var(--g) 78%, var(--ink)); }
.gdot {
  display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: 50%;
  background: color-mix(in srgb, var(--g) 17%, var(--paper)); color: var(--g-text);
}
.gdot.big { width: 56px; height: 56px; }
.gchip { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; background: color-mix(in srgb, var(--g) 15%, var(--paper)); color: var(--g-text); flex: none; }
.gtext { color: var(--g-text); }
.k { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; flex: none; }
.k.in { background: var(--in); }
.k.out { background: var(--out); }
.bdot { display: inline-block; border-radius: 50%; flex: none; background: var(--bank-other); }
.b-scb { background: var(--bank-scb); }
.b-kbank { background: var(--bank-kbank); }
.b-ktb { background: var(--bank-ktb); }
.pill-ch { display: inline-flex; align-items: center; gap: 2px; height: 22px; padding: 0 8px 0 6px; border-radius: 999px; font: 750 12px var(--font); letter-spacing: 0; }
.pill-ch.good { background: color-mix(in srgb, var(--good) 15%, var(--paper)); color: var(--good); }
.pill-ch.bad { background: color-mix(in srgb, var(--bad) 14%, var(--paper)); color: var(--bad); }
.pill-ch.flat { background: var(--soft); color: var(--mute); }

/* ---------------------------------------------------------------- tab bar (the Planner's floating pill) */
#tabs { position: fixed; z-index: 40; left: 0; right: 0; bottom: var(--tab-b); margin: 0 auto; width: calc(100% - 32px); max-width: 520px; }
.tabbar { display: flex; height: var(--tab-h); padding: 6px; border-radius: 32px; background: var(--paper); box-shadow: var(--shadow), 0 0 0 .5px var(--hair); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 26px; color: var(--mute); transition: background .25s ease, color .25s ease; min-width: 0; }
/* Origin's tab bar: mono uppercase labels; the open tab sits on a soft grey pill */
.tab-label { font: 600 10px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.tab.on { background: var(--soft); color: var(--ink); }
.tab.on .tab-label { font-weight: 700; }

/* ---------------------------------------------------------------- Home */
.hero { padding: 18px 18px 16px; }
.hero-amount { font-size: 46px; font-weight: 800; letter-spacing: -.035em; line-height: 1.05; margin-top: 2px; }
.hero-amount.bad .amt { color: var(--bad); }
.hero-amount.over, .hero-amount.over .amt { color: var(--bad); }
.hero-amount.over { font-size: 38px; }
.hero-hint { display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 10px; padding: 10px 12px; border-radius: 14px; background: var(--soft); text-align: left; font-size: 14px; line-height: 1.3; color: var(--ink-2); }
.hero-hint .ic { flex: none; color: var(--mute); }
.hero-hint:active { transform: scale(.98); }
.hero-sub { margin: 6px 0 0; font-size: 15px; color: var(--mute); }
.hero-sub .amt { color: var(--ink); font-weight: 700; }
.hero-none { margin: 6px 0 4px; font-size: 17px; color: var(--mute); }
.month-track { height: 6px; border-radius: 3px; background: var(--soft); margin-top: 16px; overflow: hidden; }
.mt-gone { display: block; height: 100%; border-radius: 3px; background: var(--ink); }
.month-track-words { display: flex; justify-content: space-between; margin-top: 7px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 30px; font-size: 12.5px; color: var(--mute); }
.legend.tight { margin: 0; gap: 10px; font: 600 11px var(--font); letter-spacing: 0; text-transform: none; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg-now { width: 16px; height: 3px; border-radius: 2px; background: var(--ink); display: inline-block; }
.lg-last { width: 16px; border-top: 2px dashed var(--faint); display: inline-block; }
.lg-budget { width: 16px; border-top: 1.5px dashed var(--mute); display: inline-block; }
.lg-net { width: 14px; border-top: 2px dashed var(--ink); display: inline-block; margin-right: 0; }
.rings { display: grid; gap: 14px 4px; margin-top: 4px; }
.ring-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0; min-width: 0; }
.ring-name { font-size: 13.5px; font-weight: 700; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ring-left { font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.set-budgets { cursor: pointer; }
.sb-row { display: flex; align-items: center; gap: 14px; }
.sb-ring { width: 52px; height: 52px; border-radius: 50%; flex: none; border: 3px dashed var(--faint); display: flex; align-items: center; justify-content: center; color: var(--mute); }
.sb-text { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; color: var(--mute); }
.sb-text b { color: var(--ink); font-size: 17px; }
.sb-row > .ic { color: var(--faint); }
.to-sort-hd { display: flex; align-items: center; gap: 12px; margin: 2px 0 8px; font-size: 17px; }
.cards-card { padding-bottom: 14px; }
.card-row { display: flex; gap: 12px; overflow-x: auto; margin: 0 -18px; padding: 4px 18px 6px; scrollbar-width: none; scroll-snap-type: x proximity; }
.card-row::-webkit-scrollbar { display: none; }
.card-cell { flex: none; width: 142px; display: flex; flex-direction: column; gap: 8px; text-align: left; scroll-snap-align: start; transition: transform .15s ease; }
.card-cell:active { transform: scale(.97); }
.cell-amt { font-size: 14px; font-weight: 750; }
.cell-amt .mute { font-weight: 550; font-size: 12.5px; }
.two-tone { display: flex; gap: 3px; height: 12px; margin: 14px 0 8px; }
.tt-in, .tt-out { display: block; height: 100%; border-radius: 6px; min-width: 6px; transform-origin: left; animation: fill-in .8s cubic-bezier(.2, .8, .2, 1) both; }
.tt-in { background: var(--in); }
.tt-out { background: var(--out); }
.tt-words { display: flex; justify-content: space-between; font-size: 14px; color: var(--mute); }
.tt-words > span { display: inline-flex; align-items: center; gap: 3px; }
.tt-words .amt { color: var(--ink); font-weight: 700; }

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; }
.chart-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; display: block; }
.chart.cum { margin-top: 14px; }
.chart.bars { margin: 10px 0 26px; }
.chart.div { margin: 10px 0 6px; }
.axis { stroke: var(--hair); stroke-width: 1; }
.axis.strong { stroke: var(--faint); }
.line-now { fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.line-last { fill: none; stroke: var(--faint); stroke-width: 2; stroke-dasharray: 4 4; stroke-linejoin: round; }
.line-budget { stroke: var(--mute); stroke-width: 1.3; stroke-dasharray: 5 5; }
.line-net { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-dasharray: 5 4; stroke-linejoin: round; }
.draw { animation: reveal 1.1s cubic-bezier(.3, .7, .2, 1) both; }
.fade-in { animation: fade 1.1s ease both; }
@keyframes reveal { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes fade { from { opacity: 0; } }
.edge-tag { position: absolute; right: 0; transform: translateY(-50%); font: 650 10.5px/16px var(--mono); padding: 0 6px; border-radius: 999px; background: var(--soft); color: var(--ink-2); white-space: nowrap; }
.y-tag { position: absolute; right: 0; transform: translateY(-50%); font: 600 10px var(--mono); color: var(--mute); white-space: nowrap; }
.dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 2.5px var(--paper); pointer-events: none; }
.net-dot { width: 8px; height: 8px; margin: -4px 0 0 -4px; box-shadow: 0 0 0 2px var(--paper); }
.net-dot.neg { background: var(--bad); }
.flag {
  position: absolute; z-index: 1; transform: translate(-50%, calc(-100% - 13px)); white-space: nowrap; pointer-events: none;
  font-size: 12.5px; font-weight: 750; line-height: 16px; color: #fff; padding: 4px 9px; border-radius: 999px;
}
.flag::after { content: ""; position: absolute; bottom: -3px; left: 50%; width: 8px; height: 8px; margin-left: -4px; background: inherit; transform: rotate(45deg); border-radius: 1.5px; }
.flag.right { transform: translate(calc(-100% + 16px), calc(-100% - 13px)); }
.flag.right::after { left: calc(100% - 16px); }
.flag.left { transform: translate(-16px, calc(-100% - 13px)); }
.flag.left::after { left: 16px; }
.flag.good { background: var(--good); }
.flag.bad { background: var(--bad); }
.flag.pop { animation: pop .45s .8s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes pop { from { opacity: 0; scale: .7; } }
.x-labels { position: absolute; left: 0; right: 14.3%; bottom: -20px; display: flex; justify-content: space-between; font: 600 10.5px var(--mono); color: var(--mute); }
.bar-labels { position: absolute; left: 0; bottom: -22px; display: flex; }
.bar-labels.static { position: static; padding-right: 15.5%; margin-top: 2px; }
.bar-label { flex: 1; text-align: center; font: 600 10.5px var(--mono); letter-spacing: .04em; text-transform: uppercase; color: var(--mute); }
.bar-label.on { color: var(--ink); font-weight: 800; }
.bar { transition: fill .2s ease; }
.bar.live { stroke-width: 1.6; }
.bar.in { fill: var(--in); }
.bar.out { fill: var(--out); }
.bar.rise { transform-box: fill-box; transform-origin: 50% 100%; animation: grow-y .7s cubic-bezier(.2, .8, .2, 1) both; animation-delay: var(--d, 0ms); }
.bar.drop { transform-box: fill-box; transform-origin: 50% 0; animation: grow-y .7s cubic-bezier(.2, .8, .2, 1) both; animation-delay: var(--d, 0ms); }
@keyframes grow-y { from { transform: scaleY(0); } }
@keyframes fill-in { from { transform: scaleX(0); } }
.col-pick { fill: var(--soft); }
.hit-row { position: absolute; top: 0; bottom: 0; left: 0; display: flex; }
.hit { flex: 1; height: 100%; border-radius: 10px; }
.tip-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: var(--soft); font-size: 14px; }
.tip-row > span { display: inline-flex; align-items: center; gap: 4px; }
.tip-row .k { margin-right: 2px; }
.tip-row .amt { font-weight: 700; }
.tip-row .good .amt { color: var(--good); }
.tip-row .bad .amt { color: var(--bad); }

/* ring */
.ring { position: relative; flex: none; }
.ring-svg { width: 100%; height: 100%; display: block; }
.ring-track { fill: none; stroke: var(--soft); stroke-width: 6; }
.ring-fill { fill: none; stroke-width: 6; stroke-linecap: round; }
.ring-fill.sweep { animation: sweep 1s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes sweep { from { stroke-dasharray: 0 100; } }
.ring-ic { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--g-text); }

/* donut */
.donut { position: relative; width: min(62vw, 228px); aspect-ratio: 1; margin: 4px auto 6px; }
.donut.grow-in { animation: donut-in .8s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes donut-in { from { transform: rotate(-50deg) scale(.88); opacity: 0; } }
.donut-svg { width: 100%; height: 100%; display: block; }
.donut-track { fill: none; stroke: var(--soft); stroke-width: 22; }
.donut-seg { fill: none; stroke-width: 22; stroke: var(--g); }
.donut-mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.donut-total { font-size: 27px; font-weight: 800; letter-spacing: -.025em; }

/* mini bars in month tiles */
.mp-in { fill: var(--in); }
.mp-out { fill: var(--out); }

/* ---------------------------------------------------------------- Spending */
.mtiles { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 12px; padding: 2px 16px 8px; scrollbar-width: none; scroll-snap-type: x proximity; }
.mtiles::-webkit-scrollbar { display: none; }
.mtile {
  flex: none; width: 76px; padding: 10px 6px 9px; border-radius: 18px; background: var(--paper); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 6px; scroll-snap-align: start; transition: background .2s, color .2s, transform .15s;
}
.mtile:active { transform: scale(.96); }
.mtile.on { background: var(--ink); color: var(--on-ink); }
.mtile-label { font: 650 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.mtile-amt { font-size: 12.5px; font-weight: 750; }
.mtile.on .mp-in { fill: color-mix(in srgb, var(--in) 70%, var(--on-ink)); }
.donut-card { padding-bottom: 18px; }
.grp { position: relative; display: flex; align-items: center; gap: 11px; width: 100%; padding: 13px 14px 13px 14px; text-align: left; }
.grp-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.grp-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 8px; }
.grp-name { font-size: 15.5px; font-weight: 650; white-space: nowrap; }
.grp-amt { font-size: 14.5px; font-weight: 750; white-space: nowrap; }
.grp-amt .mute { font-weight: 550; font-size: 12px; }
.grp-bar { display: block; height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.grp-fill { display: block; height: 100%; border-radius: 4px; transform-origin: left; animation: fill-in .8s cubic-bezier(.2, .8, .2, 1) both; }
.grp-share { width: 32px; flex: none; text-align: right; font: 650 12px var(--mono); color: var(--mute); }
.pay .sec-hd { margin-top: 24px; }
.txns .day-hd { margin: 16px 6px 8px; }
.txns .day:first-child .day-hd { margin-top: 6px; }
.txns .card { margin-bottom: 4px; }
.txn { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 14px; text-align: left; }
.txn:active { background: var(--soft); }
.txn-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.txn-merchant { font-size: 16px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-sub { display: flex; align-items: center; gap: 7px; min-width: 0; }
.acct { display: inline-flex; align-items: center; gap: 5px; min-width: 0; font-size: 12px; color: var(--mute); }
.acct-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.txn-end .amt { font-size: 16px; font-weight: 750; }
.txn.unconf .txn-end .amt { color: var(--mute); }
.amt.nc, .txn.not-counted .txn-end .amt { color: var(--mute); font-weight: 600; }
.txn-unconf { font-size: 11px; color: var(--mute); font-weight: 600; }

/* ---------------------------------------------------------------- card pictures (Copilot), 1.586:1 */
/* KTC black, Wisdom dark grey, UOB silver (Biccy, 9 Nov) */
.cc-ktc { --cc-bg: radial-gradient(130% 150% at 0% 0%, #2c2c2e 0%, #121213 45%, #000 100%); }
.cc-wisdom { --cc-bg: radial-gradient(130% 150% at 0% 0%, #6b6e74 0%, #4a4d52 48%, #2e3034 100%); }
.cc-uob { --cc-bg: linear-gradient(125deg, #f4f5f7 0%, #c9ced5 32%, #e6e9ed 55%, #a9b0b9 100%); }
.cc-slate { --cc-bg: radial-gradient(130% 150% at 0% 0%, #8a96a4 0%, #5f6a78 50%, #3e4652 100%); }
.cc {
  position: relative; display: block; width: 100%; aspect-ratio: 1.586; border-radius: 7% / 11%; overflow: hidden;
  container-type: inline-size; color: #fff; background: var(--cc-bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .18), 0 8px 18px -6px rgba(0, 0, 0, .35);
}
.cc::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(115deg, rgba(255, 255, 255, .18) 0%, rgba(255, 255, 255, 0) 38%), radial-gradient(90% 70% at 100% 100%, rgba(255, 255, 255, .08), transparent 60%); }
.cc-ktc { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12), 0 1px 2px rgba(0, 0, 0, .2), 0 8px 18px -6px rgba(0, 0, 0, .45); }
.cc-uob { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .14), 0 8px 18px -6px rgba(0, 0, 0, .28); }
.cc-bank { position: absolute; left: 7cqw; top: 6.5cqw; font-size: 9.5cqw; font-weight: 800; letter-spacing: -.01em; line-height: 1; }
.cc-chip {
  position: absolute; left: 7cqw; top: 33cqw; width: 12.5cqw; height: 9.5cqw; border-radius: 2cqw; opacity: .5;
  background: linear-gradient(135deg, rgba(255, 255, 255, .75), rgba(255, 255, 255, .25));
}
.cc-chip::before { content: ""; position: absolute; inset: 28% 0; border-top: 1px solid rgba(0, 0, 0, .25); border-bottom: 1px solid rgba(0, 0, 0, .25); }
.cc.cc-uob { color: #1f2329; }
.cc-uob .cc-chip { background: linear-gradient(135deg, #d9dde2, #8d949d); opacity: .9; }
.cc-name { position: absolute; left: 7cqw; bottom: 6.5cqw; max-width: 55cqw; font-size: 6.6cqw; font-weight: 650; line-height: 1.1; opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-digits { position: absolute; right: 7cqw; bottom: 6.5cqw; font: 600 6.4cqw/1.1 var(--mono); letter-spacing: .04em; opacity: .9; }
.cc.off::before { content: ""; position: absolute; inset: 0; z-index: 1; background: color-mix(in srgb, var(--page) 58%, transparent); }
.cc.off { box-shadow: 0 0 0 1px var(--hair); filter: saturate(.55); }
.cc.cc-uob.off::before { background: color-mix(in srgb, var(--page) 25%, transparent); }
.cc-off {
  position: absolute; z-index: 2; left: 50%; top: 50%; transform: translate(-50%, -50%); white-space: nowrap;
  padding: 1.6cqw 4.4cqw; border-radius: 999px; background: rgba(20, 20, 20, .72); color: #fff; font-size: 6.4cqw; font-weight: 750;
}
.cc-tiny { display: inline-block; flex: none; width: 23px; height: 14.5px; border-radius: 3.5px; background: var(--cc-bg); box-shadow: 0 0 0 .5px rgba(0, 0, 0, .15); }
.cc-tiny.cc-ktc { box-shadow: 0 0 0 .5px rgba(255, 255, 255, .25); }

/* ---------------------------------------------------------------- Cards */
.cards-hd { padding: 0 6px 14px; }
.cards-hd .big-num { margin-top: 4px; }
.card-line { position: relative; display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; text-align: left; }
.card-line:active { background: var(--soft); }
.cl-art { width: 36%; flex: none; }
.cl-stats { flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; }
.card-line.off .cl-stats { display: flex; flex-direction: column; gap: 2px; }
.cl-stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cl-stat + .cl-stat { text-align: right; align-items: flex-end; }
.cl-val { font-size: 17px; font-weight: 750; white-space: nowrap; }
.cl-val.due { font-size: 15px; }
.due.soon { color: var(--warn); }
.due.late { color: var(--bad); }
.cl-off { font-size: 15px; font-weight: 700; color: var(--mute); }
.card-line.off .fine { margin: 0; }
.bank { position: relative; display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.bank-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bank-mid .fine { margin: 2px 0 0; }
.bank-name { font-size: 16px; font-weight: 650; }
.bank-stat { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; min-width: 72px; }
.bank-stat .amt { font-size: 15px; font-weight: 700; }

/* ---------------------------------------------------------------- tiles (Cash flow, card sheet) */
.tiles { display: grid; gap: 10px; margin-bottom: 12px; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tiles.two { grid-template-columns: repeat(2, 1fr); }
.tile { background: var(--paper); border-radius: 18px; padding: 12px 12px 12px; box-shadow: var(--shadow); min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.tile .label { font-size: 10px; letter-spacing: .07em; }
.tile-value { font-size: 18px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tiles.two .tile-value { font-size: 22px; }
.tile .pill-ch { margin-top: 6px; }
.tile.in .amt { color: var(--good); }
.tile.out .amt { color: var(--out-text); }
.tile.good .amt { color: var(--good); }
.tile.bad .amt { color: var(--bad); }

/* ---------------------------------------------------------------- bottom sheets (from the Planner, stacked) */
#sheet-root { position: relative; z-index: 70; }
.scrim { position: fixed; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .28s ease; }
.scrim.in { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 600px; max-height: calc(92vh - var(--safe-t));
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: none;
  background: var(--page); border-radius: 28px 28px 0 0; padding-bottom: calc(var(--safe-b) + 24px);
  transform: translateY(105%); transition: transform .34s cubic-bezier(.2, .8, .2, 1), filter .3s ease;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .18);
}
.sheet.in { transform: translateY(0); }
.sheet.in.under { transform: translateY(-10px) scale(.95); filter: brightness(.9); }
.grabber { position: sticky; top: 0; height: 0; z-index: 3; }
.grabber::before { content: ""; position: absolute; top: 8px; left: 50%; margin-left: -18px; width: 36px; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--mute) 70%, transparent); }
.sh-head { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 30px 56px 6px; text-align: center; }
.sh-head.plain { padding: 0; }
.sh-x { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; box-shadow: none; background: var(--soft); color: var(--ink); z-index: 2; }
.sh-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; overflow-wrap: anywhere; }
.sh-sub { font-size: 14px; color: var(--mute); }
.sh-body { padding: 12px 16px 4px; }
.sh-amount { font-size: 40px; font-weight: 800; letter-spacing: -.03em; text-align: center; margin: 0 0 4px; }
.sh-left { font-size: 15px; font-weight: 700; margin-bottom: 16px; }
.sh-left .mute { font-weight: 550; }
.sh-sec { margin: 22px 6px 2px; }
.big-card { align-self: stretch; width: 100%; padding: 56px 28px 4px; }
.big-card .cc { width: min(100%, 340px); margin: 0 auto; }
.note { display: flex; align-items: center; gap: 8px; margin: 10px 0; padding: 10px 12px; border-radius: 14px; background: var(--soft); font-size: 14px; color: var(--ink-2); }
.kv { padding: 6px 16px; margin-top: 12px; }
.kv-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; }
.kv-row + .kv-row { border-top: 1px solid var(--hair); }
.kv-card { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; }
.kv-card .cc { width: 64px; }
.kv .acct { font-size: 15px; color: var(--ink); font-weight: 650; gap: 8px; }
.field-label { margin: 20px 4px 10px; }
.sort-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.sort-chip {
  display: inline-flex; align-items: center; gap: 7px; height: 42px; padding: 0 15px 0 11px; border-radius: 999px;
  background: color-mix(in srgb, var(--g) 15%, var(--paper)); color: var(--g-text); font-size: 15px; font-weight: 700;
  transition: transform .12s ease, background .2s, opacity .2s;
}
.sort-chip:active:not(:disabled) { transform: scale(.95); }
.sort-chip.on { background: var(--g); color: #fff; }
.sort-chip.busy { opacity: .45; }
.sort .fine { margin: 10px 4px 0; }
.bill-line { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; padding: 13px 14px; border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); font-size: 15px; }
.bill-line b { margin-left: auto; font-weight: 750; }
.bill-line.soon b { color: var(--warn); }
.bill-line.late b { color: var(--bad); }
.bill-line.mute { color: var(--mute); }

/* budget editor */
.amount-field { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 10px 0 4px; }
.amount-baht { font-size: 26px; font-weight: 700; color: var(--mute); }
.amount-input {
  width: 6.2ch; min-width: 0; border: 0; border-bottom: 2px solid var(--hair); border-radius: 0; background: transparent; outline: none;
  color: var(--ink); font: 800 42px/1.1 var(--font); letter-spacing: -.03em; text-align: center; font-variant-numeric: tabular-nums; padding: 0 0 2px;
}
.amount-input:focus { border-bottom-color: var(--ink); }
.amount-input::placeholder { color: var(--faint); }
.amount-unit { font-size: 15px; color: var(--mute); font-weight: 600; }
.field-warn { margin: 6px 0 0; text-align: center; font-size: 14px; font-weight: 650; color: var(--bad); }
.field-warn[hidden] { display: none; }
.verdict { margin: 4px 0 0; font-size: 14px; font-weight: 650; }

/* ---------------------------------------------------------------- toasts (from the Planner) */
#toasts { position: fixed; z-index: 80; left: 0; right: 0; margin: 0 auto; width: calc(100% - 32px); max-width: 520px; bottom: calc(var(--tab-b) + var(--tab-h) + 12px); pointer-events: none; }
body.sheet-open #toasts { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + var(--safe-t) + 12px); }
body.dev.sheet-open #toasts { top: calc(env(safe-area-inset-top, 0px) + var(--safe-t) + 30px); }
.toast {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 10px 10px 18px; border-radius: 20px;
  background: var(--ink); color: var(--on-ink); font-size: 15px; font-weight: 550; line-height: 1.3;
  box-shadow: var(--lift); pointer-events: auto;
  transform: translateY(16px); opacity: 0; transition: transform .3s cubic-bezier(.2, .8, .2, 1), opacity .25s;
}
.toast.in { transform: none; opacity: 1; }
.toast-text { flex: 1; }
.toast-undo { flex: none; height: 34px; padding: 0 16px; border-radius: 999px; font-weight: 800; color: var(--on-ink); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--on-ink) 45%, transparent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* ---------------------------------------------------------------- installments (Cards) */
.card-rows > * + *::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px; background: var(--hair); }
.card-rows > .card-line + .card-line::before { left: 16px; }
.card-item { position: relative; }
.inst-strip {
  display: flex; align-items: center; gap: 10px; width: calc(100% - 32px); margin: -4px 16px 14px; padding: 10px 10px 10px 12px;
  border-radius: 14px; background: var(--soft); text-align: left;
}
.inst-strip:active { background: var(--hair); }
.inst-ic { width: 30px; height: 30px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--paper); color: var(--ink); box-shadow: 0 0 0 1px var(--hair); }
.inst-words { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.inst-words b { font-size: 15px; }
.inst-words .fine { margin: 0; font-size: 12.5px; }
.inst-amt { font-size: 17px; font-weight: 750; white-space: nowrap; }
.inst-amt small { font-size: 12px; font-weight: 600; color: var(--mute); margin-left: 1px; }
.sh-card .cc-tiny { width: 46px; height: 29px; border-radius: 6px; }
.inst-list { padding: 0; }
.plan { position: relative; padding: 16px 18px; }
.plan + .plan::before { content: ""; position: absolute; top: 0; left: 18px; right: 0; height: 1px; background: var(--hair); }
.plan-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.plan-name { font-size: 16px; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-left { font-size: 17px; font-weight: 750; white-space: nowrap; }
.plan-left small { font-size: 12px; font-weight: 600; color: var(--mute); }
.plan-bar { display: flex; gap: 3px; margin: 10px 0 8px; }
.plan-bar i { flex: 1; height: 8px; border-radius: 3px; background: var(--soft); box-shadow: inset 0 0 0 1px var(--hair); }
.plan-bar i.on { background: var(--in); box-shadow: none; }
.plan-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; color: var(--mute); }
.plan-meta b { color: var(--ink); }
.plan-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--hair); }
.fact { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fact .label { font-size: 10px; }
.fact-v { font-size: 13.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inst-strip.in-sheet { width: 100%; margin: 4px 0 6px; background: var(--paper); box-shadow: var(--shadow); }
