/* MoneyBook. shadcn/ui-style tokens in plain CSS (zinc neutrals, bordered cards, 10px radius). */
:root {
  color-scheme: light dark;
  --paper: #fafafa;          /* page background */
  --card: #ffffff;
  --ink: #09090b;            /* foreground */
  --muted: #71717a;          /* muted foreground */
  --line: #e4e4e7;           /* border */
  --soft: #f4f4f5;           /* muted / secondary background */
  --neg: #dc2626;
  --pos: #16a34a;
  --on-neg: #ffffff;
  --on-ink: #fafafa;
  --ring: #a1a1aa;
  --shadow: 0 1px 2px rgb(0 0 0 / .05);
  --chart-1: #2563eb; --chart-2: #f97316; --chart-3: #0d9488; --chart-4: #e11d48;
  --chart-5: #8b5cf6; --chart-6: #eab308; --chart-7: #0891b2; --chart-8: #a1a1aa;
  --r: 12px;
  --font: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans Thai", "Helvetica Neue", sans-serif;
  --tabs-h: 64px;
  --w: 560px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #09090b; --card: #111113; --ink: #fafafa; --muted: #a1a1aa; --line: #27272a; --soft: #1c1c1f;
    --neg: #f87171; --pos: #4ade80; --on-neg: #1a0505; --on-ink: #09090b; --ring: #52525b; --shadow: none;
    --chart-1: #3b82f6; --chart-2: #fb923c; --chart-3: #2dd4bf; --chart-4: #fb7185;
    --chart-5: #a78bfa; --chart-6: #facc15; --chart-7: #22d3ee; --chart-8: #71717a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 8px; }

.lucide { width: 20px; height: 20px; flex: none; display: block; }
.emoji { font-size: 18px; line-height: 1; }
.amt { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }
.expense { color: var(--neg); }
.income { color: var(--pos); }
.transfer { color: var(--muted); }
.muted { color: var(--muted); }

/* ---------- frame ---------- */
#app { max-width: var(--w); margin: 0 auto; min-height: 100dvh; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; min-height: 56px;
  background: color-mix(in srgb, var(--paper) 85%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.month-nav { display: flex; align-items: center; flex: 1; min-width: 0; }
.month { font-size: 17px; font-weight: 600; letter-spacing: -.01em; padding: 6px 4px; white-space: nowrap; }
.title-tab { display: none; flex: 1; margin: 0 4px; font-size: 17px; font-weight: 600; }
.top.no-month .month-nav { display: none; }
.top.no-month .title-tab { display: block; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.icon-btn.on { background: var(--ink); color: var(--on-ink); }
.badge {
  font-size: 12px; font-weight: 500; padding: 4px 10px 4px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; background: var(--card);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.badge[data-state="synced"]::before { background: var(--pos); }
.badge[data-state="dirty"]::before { background: #eab308; }
.badge[data-state="error"] { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }
.badge[data-state="error"]::before { background: var(--neg); }

#view { padding: 4px 16px calc(var(--tabs-h) + 96px + env(safe-area-inset-bottom)); }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: center; gap: 4px;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs button { flex: 0 1 140px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; border-radius: 8px; color: var(--muted); font-size: 11px; font-weight: 500; }
.tabs .lucide { width: 22px; height: 22px; }
.tabs button[aria-current="page"] { color: var(--ink); }
.tabs button[aria-current="page"] .lucide { stroke-width: 2.25; }

#fab {
  position: fixed; z-index: 6; width: 56px; height: 56px; border-radius: 16px;
  right: max(16px, calc(50vw - var(--w) / 2 + 16px)); bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--on-ink); display: grid; place-items: center; box-shadow: 0 4px 14px rgb(0 0 0 / .2);
}
#fab .lucide { width: 26px; height: 26px; stroke-width: 2.25; }
#fab:active { transform: scale(.96); }

/* ---------- shared ---------- */
.card, .day, .list, .chart-card, .cal, .summary, .stats {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); margin: 0 0 12px; overflow: hidden;
}
.card > header, .day > header {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 10px 16px; font-size: 13px; font-weight: 500; color: var(--muted); background: var(--soft); border-bottom: 1px solid var(--line);
}

.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { padding: 6px 12px; border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .1); }
.seg.full { display: flex; margin-bottom: 12px; }
.seg.full button { flex: 1; }

.row {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  width: 100%; padding: 10px 16px; text-align: left; border-top: 1px solid var(--line);
}
header + .row, .row:first-child { border-top: 0; }
button.row:hover { background: var(--soft); }
.ico { width: 36px; height: 36px; border-radius: 10px; background: var(--soft); display: grid; place-items: center; color: var(--ink); }
.main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { display: inline-block; font-size: 11px; font-weight: 500; padding: 0 6px; margin-right: 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--ink); vertical-align: 1px; }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; max-width: 46vw; min-width: 0; }
.right > * { max-width: 100%; }
.chev { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); font-size: 13px; }
.chev .lucide { width: 16px; height: 16px; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty strong { display: block; color: var(--ink); font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.link { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-size: 14px; padding: 8px 0; }
.danger { color: var(--neg); }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 6px 12px 0; padding: 4px 6px 4px 10px;
  border-radius: 8px; background: var(--ink); color: var(--on-ink); font-size: 13px; font-weight: 500;
}
.filter-chip .lucide { width: 14px; height: 14px; opacity: .7; }

/* ---------- ledger ---------- */
.summary, .stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { background: var(--card); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .amt { font-size: 17px; font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; }
.toolbar { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; }
.toolbar input { flex: 1; min-width: 0; }
.more { text-align: center; font-size: 13px; color: var(--muted); }

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; padding: 10px; }
.dow { text-align: center; font-size: 12px; font-weight: 500; color: var(--muted); padding-bottom: 2px; }
.cell {
  min-width: 0; aspect-ratio: 1 / 1.05; border-radius: 8px; display: flex; flex-direction: column; justify-content: space-between;
  padding: 5px 5px 4px; text-align: left; border: 1px solid transparent; color: var(--ink);
}
.cell .d { font-size: 13px; font-weight: 600; line-height: 1; }
.cell .n { font-size: 11px; font-weight: 600; text-align: right; overflow: hidden; white-space: nowrap; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.cell .n.pos { color: var(--pos); }
.cell.none .d { color: var(--muted); font-weight: 500; }
.cell.h1 { background: color-mix(in srgb, var(--neg) 12%, var(--card)); }
.cell.h2 { background: color-mix(in srgb, var(--neg) 24%, var(--card)); }
.cell.h3 { background: color-mix(in srgb, var(--neg) 42%, var(--card)); }
.cell.h4 { background: var(--neg); color: var(--on-neg); }
.cell.h4 .n.pos { color: var(--on-neg); }
.cell.inc { background: color-mix(in srgb, var(--pos) 14%, var(--card)); }
.cell.today { border-color: var(--ink); }
.cell[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.cell[aria-pressed="true"] .d, .cell[aria-pressed="true"] .n { color: var(--on-ink); }
.cal-key { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; padding: 8px 2px 0; font-size: 12px; color: var(--muted); }
.cal-key .sw { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line); }
.cal-key .sw.h1 { background: color-mix(in srgb, var(--neg) 12%, var(--card)); }
.cal-key .sw.h2 { background: color-mix(in srgb, var(--neg) 24%, var(--card)); }
.cal-key .sw.h3 { background: color-mix(in srgb, var(--neg) 42%, var(--card)); }
.cal-key .sw.h4 { background: var(--neg); }
.cal-key .sw.inc { background: color-mix(in srgb, var(--pos) 14%, var(--card)); margin-left: 10px; }

/* ---------- wallet ---------- */
.worth { padding: 6px 2px 18px; }
.worth .label { font-size: 13px; color: var(--muted); }
.worth .big { display: block; font-size: clamp(32px, 9vw, 42px); font-weight: 700; letter-spacing: -.03em; line-height: 1.15; margin: 2px 0 14px; }
.beam { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--soft); gap: 2px; }
.beam span { display: block; height: 100%; }
.beam .a { background: var(--pos); flex: var(--a) 0 0; }
.beam .d { background: var(--neg); flex: var(--d) 0 0; }
.beam-legend { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; }
.beam-legend div { display: flex; flex-direction: column; }
.beam-legend div:last-child { text-align: right; }
.beam-legend .amt { font-size: 15px; font-weight: 600; }

/* ---------- charts ---------- */
.chart-card { padding: 16px; }
.chart-card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.chart-box { position: relative; height: 200px; }
.donut { position: relative; width: min(240px, 70vw); margin: 0 auto 8px; }
.donut-box { position: relative; height: min(240px, 70vw); }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center span { font-size: 12px; color: var(--muted); }
.donut-center strong { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.legend { margin: 0 -16px -16px; border-top: 1px solid var(--line); }
.legend .row { grid-template-columns: 8px 28px minmax(0, 1fr) auto auto; gap: 10px; padding: 9px 16px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.legend .ico { width: 28px; height: 28px; border-radius: 8px; }
.legend .ico .lucide { width: 16px; height: 16px; }
.pct { font-size: 12px; color: var(--muted); width: 3em; text-align: right; font-variant-numeric: tabular-nums; }
.key { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.key span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; background: currentColor; }
.key .income { color: var(--pos); } .key .expense { color: var(--neg); }
.budget .row { grid-template-columns: 36px minmax(0, 1fr); }
.budget .head { display: flex; flex-wrap: wrap; justify-content: space-between; column-gap: 8px; min-width: 0; } /* a long name pushes the amount to its own line instead of being cut */
.bar { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; margin: 6px 0 2px; }
.bar span { display: block; height: 100%; width: calc(var(--p) * 100%); background: var(--ink); border-radius: 3px; }
.bar.over span { background: var(--neg); }

/* ---------- sheet ---------- */
dialog {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; width: min(var(--w), 100%); max-width: 100%;
  max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0;
  background: var(--paper); color: var(--ink); overflow: auto; overscroll-behavior: contain;
}
dialog[open] { animation: up .22s cubic-bezier(.2, .8, .2, 1); }
dialog::backdrop { background: rgb(0 0 0 / .5); }
@keyframes up { from { transform: translateY(24px); opacity: .4; } }
@media (prefers-reduced-motion: reduce) { dialog[open] { animation: none; } }
.sheet-head {
  position: sticky; top: 0; z-index: 1; display: grid; grid-template-columns: 36px 1fr 36px; align-items: center;
  padding: 10px 10px 6px; background: var(--paper);
}
.sheet-head h2 { margin: 0; text-align: center; font-size: 16px; font-weight: 600; }
.sheet-body { padding: 6px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.sheet-body h3 { margin: 12px 0 -6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 500; }
.field .hint { font-size: 12px; font-weight: 400; color: var(--muted); }
input, select {
  width: 100%; font-size: 16px; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); -webkit-appearance: none; appearance: none; box-shadow: var(--shadow);
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input:focus, select:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 35%, transparent); }
input[type="date"] { padding-right: 8px; }
.amount-wrap { display: flex; align-items: baseline; gap: 6px; border-bottom: 1px solid var(--line); padding: 4px 2px 6px; }
.amount-wrap:focus-within { border-color: var(--ink); }
.amount-wrap .cur { font-size: 28px; font-weight: 600; color: var(--muted); }
.amount-input { border: 0; background: none; padding: 0; height: auto; box-shadow: none; border-radius: 0; font-size: 40px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.amount-input:focus { border: 0; box-shadow: none; }
.preview { font-size: 13px; color: var(--muted); min-height: 1.2em; margin: -8px 0 0; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px 0 10px; border-radius: 8px;
  background: var(--card); border: 1px solid var(--line); font-size: 14px; font-weight: 500;
}
.chip .lucide { width: 16px; height: 16px; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.chip[aria-pressed="true"] .lucide { color: var(--on-ink); }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions .spacer { flex: 1; }
.btn, .primary {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 8px; font-size: 14px; font-weight: 500;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.btn .lucide, .primary .lucide { width: 16px; height: 16px; }
.btn:hover { background: var(--soft); }
.primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.primary:hover { opacity: .9; }
.btn.danger { color: var(--neg); }
.error { color: var(--neg); font-size: 13px; margin: 0; }
.error:empty { display: none; }
.note-box { font-size: 13px; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
.note-box.warn { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }
.list .row { grid-template-columns: 36px minmax(0, 1fr) auto; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; max-height: 232px; overflow: auto; padding: 2px; }
.pick { height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; color: var(--ink); }
.pick:hover { background: var(--soft); }
.pick[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

/* ---------- lock & toast ---------- */
#lock { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.lock-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.lock-card h1 { font-size: 24px; font-weight: 700; margin: 0; }
.lock-card p { margin: 0; color: var(--muted); }
.lock-card .primary { justify-content: center; }
.lock-card .link.danger { color: var(--neg); }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 88px + env(safe-area-inset-bottom)); transform: translate(-50%, 8px);
  background: var(--ink); color: var(--on-ink); padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 500; z-index: 20;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- tinted icons, category grid, more tab ---------- */
.ico.tinted { background: color-mix(in srgb, var(--tint) 16%, var(--card)); color: var(--tint); }
.ico.tinted .lucide { stroke-width: 2; }
.cat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px 8px; min-width: 0;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 12px; font-weight: 500;
}
.cat span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: var(--soft); }
.status { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; text-align: left; color: var(--muted); }
.status .title { color: var(--ink); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 6px 12px; min-width: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); text-align: center;
}
.tile .ico { width: 44px; height: 44px; border-radius: 12px; }
.tile .ico .lucide { width: 22px; height: 22px; }
.tile-label { font-size: 13px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-sub { font-size: 12px; color: var(--muted); min-height: 1.2em; }
.fine { font-size: 12px; color: var(--muted); text-align: center; margin: 20px 0 0; }

/* ---------- motion (off when the system asks for reduced motion) ---------- */
button { transition: transform .12s ease, background-color .15s ease, color .15s ease, border-color .15s ease; }
.seg button { transition: background-color .2s ease, color .2s ease, box-shadow .2s ease; }
@media (prefers-reduced-motion: no-preference) {
  .tile:active, .cat:active, .pick:active, .btn:active, .primary:active, .icon-btn:active { transform: scale(.95); }
  button.row:active, .status:active { transform: scale(.99); }
  .animate > *, .animate .day, .animate .tile { animation: rise .32s cubic-bezier(.2, .8, .2, 1) both; }
  .animate > :nth-child(2) { animation-delay: 40ms; } .animate > :nth-child(3) { animation-delay: 80ms; }
  .animate > :nth-child(4) { animation-delay: 120ms; } .animate > :nth-child(n+5) { animation-delay: 160ms; }
  .animate .day:nth-child(n+3) { animation-delay: 120ms; }
  .animate .tile { animation-delay: calc(var(--i) * 35ms); }
  .animate .beam span { animation: grow .7s cubic-bezier(.2, .8, .2, 1) both; }
  .animate .beam .a { transform-origin: left; } .animate .beam .d { transform-origin: right; }
  .tabs button[aria-current="page"] .lucide { animation: pop .3s ease; }
  .cell[aria-pressed="true"], .cat[aria-pressed="true"], .pick[aria-pressed="true"] { animation: pop .22s ease; }
  #toast { transition: opacity .2s, transform .25s cubic-bezier(.2, .8, .2, 1); }
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes grow { from { transform: scaleX(0); } }
@keyframes pop { 50% { transform: scale(1.08); } }

.acct-head { display: flex; align-items: center; gap: 14px; padding: 4px 2px 6px; }
.acct-head .ico { width: 48px; height: 48px; border-radius: 14px; }
.acct-head .ico .lucide { width: 24px; height: 24px; }
.acct-head > div { display: flex; flex-direction: column; }
.acct-head .muted { font-size: 13px; }
.acct-head .big { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.sheet-body .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (prefers-reduced-motion: no-preference) { dialog[open] .tile { animation: rise .3s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i) * 40ms + 60ms); } }

.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: -6px; font-size: 13px; font-weight: 500; }
.link-btn { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { color: var(--ink); background: var(--soft); }
.link-btn .lucide { width: 14px; height: 14px; }
.row.sortable { grid-template-columns: 28px minmax(0, 1fr); padding: 0 8px 0 4px; gap: 0; }
.row-main { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 8px; text-align: left; border-radius: 8px; min-width: 0; }
.row-main:hover { background: var(--soft); }
.list > .row:not(.sortable) { padding: 0 8px; }
.list > .row:not(.sortable):not(.book-row) .row-main { grid-column: 1 / -1; }
.grip { display: grid; place-items: center; height: 44px; color: var(--muted); cursor: grab; touch-action: none; border-radius: 6px; }
.grip:active { cursor: grabbing; }
.grip .lucide { width: 18px; height: 18px; }
.row.dragging { background: var(--soft); box-shadow: 0 6px 20px rgb(0 0 0 / .15); position: relative; z-index: 1; }
.hint-line { font-size: 12px; color: var(--muted); margin: -6px 0 0; }

.pick-btn {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) 16px; align-items: center; gap: 10px; width: 100%; min-height: 52px;
  padding: 7px 12px 7px 8px; text-align: left; border: 1px solid var(--line); border-radius: 10px; background: var(--card); box-shadow: var(--shadow);
}
.pick-btn:hover { background: var(--soft); }
.pick-btn > .lucide { width: 16px; height: 16px; color: var(--muted); }
.pick-btn .main.muted { grid-column: 1 / 3; padding-left: 4px; }
.list .row[aria-pressed="true"] { background: var(--soft); }
.list .row .right .lucide { width: 16px; height: 16px; color: var(--pos); }
.more-files { border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--card); }
.more-files summary { cursor: pointer; padding: 12px 0; font-size: 14px; font-weight: 500; }
.more-files .list { margin: 0 0 10px; }
.more-files .hint-line { margin: 0 0 12px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- friendlier layer: rounded type, softer shapes, pastel tints (kept quiet on purpose) ---------- */
:root {
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  --paper: #f5f6fa; --soft: #eef0f6; --line: #e3e5ee; --r: 18px;
  --shadow: 0 1px 2px rgb(30 35 60 / .04), 0 4px 14px rgb(30 35 60 / .04);
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #0c0d12; --card: #15161d; --soft: #1e2029; --line: #272a35; --shadow: none; }
}
.seg { border-radius: 999px; padding: 4px; }
.seg button { border-radius: 999px; padding: 7px 14px; }
.ico { border-radius: 12px; }
.ico.tinted { background: color-mix(in srgb, var(--tint) 18%, var(--card)); }
.cell { border-radius: 10px; }
.cat, .tile, .pick, .btn, .primary, input, select, .pick-btn, .note-box, .more-files { border-radius: 14px; }
.btn, .primary { border-radius: 999px; padding: 0 18px; }
.filter-chip { border-radius: 999px; }
#fab { border-radius: 50%; background: linear-gradient(145deg, color-mix(in srgb, var(--ink) 82%, var(--chart-1)), var(--ink)); }
.tabs button { position: relative; }
.tabs button .lucide { padding: 3px 14px; width: 52px; height: 28px; border-radius: 999px; transition: background-color .2s ease; }
.tabs button[aria-current="page"] .lucide { background: color-mix(in srgb, var(--chart-1) 16%, transparent); color: var(--chart-1); }
.day > header, .card > header { background: transparent; border-bottom: 1px dashed var(--line); }
.worth {
  padding: 18px 18px 16px; margin-bottom: 14px; border-radius: 22px; border: 1px solid var(--line);
  background: radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--chart-1) 16%, transparent), transparent 60%),
              radial-gradient(90% 120% at 0% 100%, color-mix(in srgb, var(--chart-5) 12%, transparent), transparent 60%), var(--card);
}
.empty-art { width: 64px; height: 64px; border-radius: 22px; display: grid; place-items: center; margin: 0 auto 12px;
  background: color-mix(in srgb, var(--chart-1) 14%, var(--card)); color: var(--chart-1); }
.empty-art .lucide { width: 30px; height: 30px; stroke-width: 1.75; }
.stat .amt, .worth .big, .donut-center strong, .amount-input, .month, .sheet-head h2 { font-family: var(--font); }

.welcome { text-align: center; padding: 48px 20px 24px; }
.welcome .empty-art { width: 76px; height: 76px; border-radius: 26px; margin-bottom: 16px; }
.welcome .empty-art .lucide { width: 34px; height: 34px; }
.welcome h2 { margin: 0 0 6px; font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.welcome p { margin: 0 auto 20px; max-width: 260px; color: var(--muted); }
.welcome .primary { height: 44px; padding: 0 22px; font-size: 15px; }
.welcome-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }
.welcome-links .btn { height: 34px; font-size: 13px; padding: 0 14px; }

.empty.compact { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; text-align: left;
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--r); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; flex: none; }

.lifted { position: relative; z-index: 3; transform: scale(1.03); box-shadow: 0 12px 30px rgb(0 0 0 / .22); background: var(--card) !important; border-radius: 14px; transition: transform .15s ease, box-shadow .15s ease; }
.cat, .card .row[data-id], .list .row, .book-chip { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* calendar: over-budget days and scale note */
.cell .d { display: flex; align-items: center; gap: 2px; }
.cell .alert { display: inline-flex; color: var(--neg); }
.cell .alert .lucide { width: 12px; height: 12px; stroke-width: 2.5; }
.cell.over { box-shadow: inset 0 0 0 2px var(--neg); }
.cell.h4 .alert, .cell[aria-pressed="true"] .alert { color: var(--on-neg); }
.cal-key .sw.over { display: inline-grid; place-items: center; border-color: var(--neg); color: var(--neg); margin-left: 10px; }
.cal-key .sw.over .lucide { width: 10px; height: 10px; stroke-width: 2.5; }
.cal-norm { flex-basis: 100%; font-size: 12px; color: var(--muted); }

/* money health */
.health { --lvl: var(--pos); }
.health.lvl1 { --lvl: #d97706; }
.health.lvl2 { --lvl: var(--neg); background: color-mix(in srgb, var(--neg) 6%, var(--card)); border-color: color-mix(in srgb, var(--neg) 35%, var(--line)); }
.health-head { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto 16px; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: left; }
.health-head > .lucide { width: 16px; height: 16px; color: var(--muted); }
.health-icon { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; color: var(--lvl); background: color-mix(in srgb, var(--lvl) 15%, var(--card)); }
.health-head .sub { white-space: normal; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; color: var(--lvl); background: color-mix(in srgb, var(--lvl) 14%, var(--card)); white-space: nowrap; }
.checks { list-style: none; margin: 0; padding: 4px 14px 12px; border-top: 1px dashed var(--line); }
.checks li { display: grid; grid-template-columns: 8px 16px minmax(0, 1fr); align-items: center; gap: 10px; padding: 7px 0; font-size: 14px; }
.checks .lucide { width: 16px; height: 16px; color: var(--muted); }
.checks .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pos); }
.checks .lvl1 .dot { background: #d97706; }
.checks .lvl2 .dot { background: var(--neg); }
.checks .lvl2 { color: var(--neg); font-weight: 500; }

/* books */
.book-bar { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 2px 16px; scrollbar-width: none; }
.book-bar::-webkit-scrollbar { display: none; }
.book-chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px 0 10px; border-radius: 999px; flex: none;
  border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 500; color: var(--muted); }
.book-chip .lucide { width: 16px; height: 16px; }
.book-chip[aria-selected="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.book-chip.add { padding: 0 10px; }
.list .row.book-row { grid-template-columns: 28px minmax(0, 1fr) 36px; padding: 0 8px 0 4px; gap: 4px; }
.book-row .row-main > .lucide { width: 16px; height: 16px; color: var(--pos); }

/* day header opens the day; times in rows */
.day > .day-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; padding: 10px 12px 10px 16px;
  font-size: 13px; font-weight: 500; color: var(--muted); border-bottom: 1px dashed var(--line); text-align: left; }
.day > .day-head:hover { background: var(--soft); }
.day-right { display: inline-flex; align-items: center; gap: 4px; }
.day-right .lucide { width: 16px; height: 16px; }
.sub .at { font-variant-numeric: tabular-nums; margin-right: 6px; }
.timeline { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.timeline li { display: grid; grid-template-columns: 52px minmax(0, 1fr); align-items: center; border-top: 1px solid var(--line); position: relative; }
.timeline li:first-child { border-top: 0; }
.timeline li .row { border-top: 0; padding-left: 4px; }
.tl-time { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; }
/* month picker */
.now-chip { height: 28px; padding: 0 10px; margin-left: 4px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--chart-1);
  background: color-mix(in srgb, var(--chart-1) 12%, var(--card)); white-space: nowrap; flex: none; }
.year-nav { display: flex; align-items: center; justify-content: center; gap: 16px; }
.year-nav strong { font-size: 18px; min-width: 80px; text-align: center; }
.month-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.month-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 4px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.month-cell .m-spent { font-size: 12px; font-weight: 500; color: var(--muted); min-height: 1.2em; font-variant-numeric: tabular-nums; }
.month-cell .m-spent.income { color: var(--pos); } .month-cell .m-spent.expense { color: var(--neg); }
.month-cell.now { border-color: var(--chart-1); }
.month-cell[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.month-cell[aria-pressed="true"] .m-spent { color: var(--on-ink); opacity: .8; }
@media (max-width: 430px) { .top .badge { font-size: 0; gap: 0; padding: 7px; } } /* status shrinks to its dot on phones */

.year-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.year-stats .stat { padding: 10px 12px; }
.year-stats .stat .amt { font-size: 15px; }

/* budgets: room to breathe */
.list.budget > .xgroup > .row { padding: 16px; gap: 14px; align-items: start; }
.list.budget > .xgroup > .row > .ico { margin-top: 2px; }
.budget .main { gap: 6px; }
.budget .head .title { font-size: 15px; }
.budget .bar { height: 8px; border-radius: 4px; margin: 2px 0; }
.budget .bar span { border-radius: 4px; }
.list > .row.salary { grid-template-columns: 36px minmax(0, 1fr) auto 16px; padding: 14px 16px; }
.row.salary > .lucide { width: 16px; height: 16px; color: var(--muted); }

.donut-center span { max-width: 60%; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-center small { font-size: 12px; color: var(--muted); min-height: 1.2em; font-variant-numeric: tabular-nums; }

/* donut selection & month comparison */
.hint-line.center { text-align: center; margin: 4px 0 10px; }
.legend button.row { width: 100%; text-align: left; }
.legend .row.on { background: var(--soft); }
.legend .row.on .title { font-weight: 600; }
.legend .row.dim { opacity: .55; }
.legend .row:disabled { cursor: default; }
.compare { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.compare-head { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto 32px; align-items: center; gap: 10px; }
.compare-head .amt { font-size: 17px; font-weight: 700; }
.compare-row { display: grid; grid-template-columns: 36px minmax(0, 1fr) 36px; align-items: center; gap: 8px; background: var(--soft); border-radius: 12px; padding: 6px; }
.compare-mid { display: flex; flex-direction: column; align-items: center; }
.compare-mid .amt { font-size: 16px; }
.compare-diff { margin: 0; text-align: center; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.compare .btn { align-self: center; }

/* labels drawn on the donut (chart has 10px padding; ring sits between 70% and 100% of the radius) */
.donut { margin: 28px auto 30px; }
.donut-tags { position: absolute; inset: 0; pointer-events: none; }
.donut-tags .tag {
  position: absolute; left: calc(50% + (50% + 8px) * var(--cos)); top: calc(50% + (50% + 8px) * var(--sin)); transform: translate(-50%, -50%);
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; pointer-events: auto;
  background: var(--card); border: 2px solid var(--c); color: var(--c); box-shadow: 0 2px 8px rgb(0 0 0 / .18);
}
.donut-tags .tag .lucide { width: 16px; height: 16px; stroke-width: 2; }
.donut-tags .tag.on { transform: translate(-50%, -50%) scale(1.2); background: var(--c); color: #fff; }
.donut-tags .tag.dim { opacity: .45; }
.donut-tags .tag-pct {
  position: absolute; left: calc(50% + (50% - 10px) * .85 * var(--cos)); top: calc(50% + (50% - 10px) * .85 * var(--sin)); transform: translate(-50%, -50%);
  font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgb(0 0 0 / .45); font-variant-numeric: tabular-nums;
}

/* compare card v2 */
.cmp-boxes { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; gap: 8px; }
.cmp-box { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 12px; background: var(--soft); border-top: 3px solid var(--c); }
.cmp-box.now { --c: var(--neg); }
.cmp-box.then { --c: var(--chart-1); }
.cmp-box .label { font-size: 12px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.cmp-box .label .lucide { width: 14px; height: 14px; }
button.cmp-box { font: inherit; color: inherit; text-align: left; border-left: 0; border-right: 0; border-bottom: 0; cursor: pointer; }
button.cmp-box:hover { filter: brightness(1.15); }
.cmp-see { align-self: center; margin: 0 auto; }
.cmp-box .amt { font-size: 18px; font-weight: 700; }
.cmp-boxes .vs { align-self: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.cmp-chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.chip-sm { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; font-weight: 500; color: var(--muted); }
.chip-sm[aria-pressed="true"] { border-color: var(--chart-1); color: var(--chart-1); background: color-mix(in srgb, var(--chart-1) 10%, var(--card)); }
.year-nav.small { gap: 10px; margin-top: 2px; }
.year-nav.small strong { font-size: 15px; min-width: 64px; }
.cmp-chart { height: 180px; }
.key .accent { color: var(--chart-1); }
.key .plain { color: var(--muted); margin-left: auto; }
.key .plain::before { display: none; }
.compare .key { flex-wrap: wrap; row-gap: 4px; margin-top: 0; }

/* daily chart controls */
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-top h3 { margin: 0; }
.card-top .seg button { padding: 4px 10px; font-size: 12px; }
.check-chip { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 8px; padding: 4px 2px; font-size: 13px; font-weight: 500; color: var(--muted); }
.check-chip .box { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--line); display: grid; place-items: center; background: var(--card); }
.check-chip[aria-checked="true"] { color: var(--ink); }
.check-chip[aria-checked="true"] .box { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.check-chip .box .lucide { width: 12px; height: 12px; stroke-width: 3; }
.key .dashed::before { height: 0; border-top: 2px dashed currentColor; background: none; opacity: .7; }
.pace { margin: 8px 0 0; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.key { flex-wrap: wrap; row-gap: 4px; }
.key span { white-space: nowrap; }

/* split a bill */
.split-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.split-row .check-chip { margin: 0; }
.split-label { font-size: 13px; font-weight: 500; color: var(--muted); flex-basis: 100%; }
.split-pick { display: inline-flex; align-items: center; gap: 6px; }
.split-pct { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.split-pct input { width: 56px; height: 34px; text-align: right; appearance: textfield; -moz-appearance: textfield; }
.split-pct input::-webkit-inner-spin-button, .split-pct input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.split-info { flex-basis: 100%; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.who.split { color: var(--chart-5); border-color: color-mix(in srgb, var(--chart-5) 40%, var(--line)); }
.checks .link.inline { font-size: 13px; padding: 0; margin-left: 6px; color: inherit; opacity: .8; }

/* financial overview */
.fp-open { margin: 12px auto 0; display: flex; }
.fp-hero { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px; margin: 12px 0; border-radius: 16px; background: var(--soft); text-align: center; }
.fp-hero .label, .fp-hero .sub { font-size: 12px; color: var(--muted); }
.fp-hero .amt { font-size: 28px; font-weight: 700; }
.fp-verdict { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 15px; }
.fp-hero.income .fp-verdict { color: var(--pos); }
.fp-hero.expense .fp-verdict { color: var(--neg); }
.fp-verdict .lucide, .fp-change .lucide { width: 16px; height: 16px; }
.fp-chart { height: 200px; }
.fp-h { font-size: 14px; margin: 18px 0 8px; }
.list .row.fp-row { grid-template-columns: 36px minmax(0, 1fr) auto; padding: 8px 12px; }
.fp-change { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.fp-change.income { color: var(--pos); }
.fp-change.expense { color: var(--neg); }
.fp-row .right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.fp-row .right .sub { font-size: 11px; color: var(--muted); }
.row.salary .right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.row.salary .right .sub { font-size: 11px; }
.row.salary .right .sub.income { color: var(--pos); }
.row.salary .right .sub.expense { color: var(--neg); }
.sub.wrap { white-space: normal; }
.flex-tag { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; font-size: 11px; color: var(--chart-1); }
.flex-tag .lucide { width: 12px; height: 12px; }

/* ค้างรับ/ค้างจ่าย: shown but not counted as income or spending */
.row.pending .right .amt { color: var(--muted); }
.pend-tag { display: inline-block; margin-right: 6px; padding: 0 6px; border: 1px dashed var(--muted); border-radius: 999px; font-size: 11px; color: var(--muted); }
.pend-box { display: grid; gap: 8px; padding: 12px; border: 1px dashed var(--line); border-radius: 12px; }
.pend-box p { margin: 0; font-size: 13px; color: var(--muted); }
.pend-box .btn { justify-self: start; }

/* Grouped rows that open to show their entries */
.xgroup + .xgroup { border-top: 1px solid var(--line); }
.list .xgroup > .row { grid-template-columns: 36px minmax(0, 1fr) auto auto; }
.list.budget > .xgroup > .row { grid-template-columns: 36px minmax(0, 1fr) 16px; }
.xchev { display: grid; place-items: center; align-self: center; color: var(--muted); transition: transform .2s; }
.xchev .lucide { width: 16px; height: 16px; }
.xgroup > .row[aria-expanded="true"] .xchev { transform: rotate(180deg); }
.xgroup > .row[aria-expanded="true"] { background: var(--soft); }
.xlist { border-top: 1px solid var(--line); padding: 8px; background: var(--soft); }
.xlist .day { margin: 0 0 8px; box-shadow: none; }
.xlist .empty { padding: 12px; }
.xlist .actions { margin: 0; padding: 0 4px; }
@media (prefers-reduced-motion: reduce) { .xchev { transition: none; } }

/* Financial overview: accounts left out */
.fp-skip { display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 12px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: var(--r); color: var(--muted); font-size: 13px; text-align: left; }
.fp-skip > span { flex: 1; min-width: 0; }
.fp-skip .lucide { width: 16px; height: 16px; flex: none; }
.fp-skip.on { color: var(--ink); border-style: solid; }
.row[role="checkbox"][aria-checked="false"] .right .lucide { visibility: hidden; }
