/* ═════════════ fonts (self-hosted, latin subset) ═════════════ */
@font-face { font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 300 700; font-display: swap; src: url('../fonts/cormorant-garamond-latin.woff2') format('woff2'); }
@font-face { font-family: 'Cormorant Garamond'; font-style: italic; font-weight: 500; font-display: swap; src: url('../fonts/cormorant-garamond-italic-latin.woff2') format('woff2'); }
@font-face { font-family: 'Manrope'; font-style: normal; font-weight: 200 800; font-display: swap; src: url('../fonts/manrope-latin.woff2') format('woff2'); }

/* ═════════════ Aurum — design tokens ═════════════ */
:root {
  --font-display: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --font-ui: 'Manrope', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 18px;
  --radius-sm: 12px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --sidebar: 252px;
  --maxw: 1120px;
}

:root, [data-theme='dark'] {
  color-scheme: dark;
  --bg: #0c0b0a;
  --bg-glow: rgba(201, 169, 110, .09);
  --surface: #151311;
  --surface-2: #1d1a17;
  --surface-3: #26221d;
  --line: rgba(201, 169, 110, .14);
  --line-strong: rgba(201, 169, 110, .32);
  --text: #f3ede2;
  --muted: #9a9184;
  --gold: #c9a96e;
  --gold-2: #e3c993;
  --on-gold: #17130d;
  --income: #8fb996;
  --expense: #d98b7a;
  --warn: #d9a25f;
  --shadow: 0 24px 60px -24px rgba(0, 0, 0, .7);
  --track: rgba(243, 237, 226, .07);
  --chart-in: #4b9bcf;
  --chart-out: #d17d3e;
  --grid: rgba(243, 237, 226, .07);
}

[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f2ea;
  --bg-glow: rgba(156, 122, 60, .10);
  --surface: #fffdf8;
  --surface-2: #f2ece1;
  --surface-3: #e9e1d2;
  --line: rgba(120, 90, 40, .14);
  --line-strong: rgba(120, 90, 40, .3);
  --text: #1f1a14;
  --muted: #776d5f;
  --gold: #9c7a3c;
  --gold-2: #b8934f;
  --on-gold: #fffaf0;
  --income: #3f7a4c;
  --expense: #b4533f;
  --warn: #a8691f;
  --shadow: 0 24px 50px -28px rgba(70, 50, 20, .35);
  --track: rgba(31, 26, 20, .07);
  --chart-in: #1870a1;
  --chart-out: #ba5d1d;
  --grid: rgba(31, 26, 20, .08);
}

/* ═════════════ base ═════════════ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font: 500 15px/1.5 var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 85% -10%, var(--bg-glow), transparent 60%),
    radial-gradient(800px 500px at -10% 110%, var(--bg-glow), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 10px; }
::selection { background: var(--gold); color: var(--on-gold); }

.muted { color: var(--muted); }
.income { color: var(--income); }
.expense, .over { color: var(--expense); }
.warn { color: var(--warn); }
.center { text-align: center; }
.pad { padding: 8px 0 4px; }
.link { color: var(--gold); font-weight: 600; font-size: 13px; letter-spacing: .02em; }
.link:hover { color: var(--gold-2); }
.ico { flex-shrink: 0; }

/* ═════════════ layout ═════════════ */
.app { display: grid; grid-template-columns: 1fr; min-height: 100dvh; }
.main { min-width: 0; padding: 0 16px 120px; }
.view { max-width: var(--maxw); margin: 0 auto; display: grid; gap: 16px; }
.view.enter > * { animation: rise .42s var(--ease) both; }
.view.enter > *:nth-child(2) { animation-delay: .04s; }
.view.enter > *:nth-child(3) { animation-delay: .08s; }
.view.enter > *:nth-child(4) { animation-delay: .12s; }
.view.enter > *:nth-child(5) { animation-delay: .16s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.sidebar { display: none; }
.mobile-only { display: inline-grid; }

@media (min-width: 960px) {
  .app { grid-template-columns: var(--sidebar) 1fr; }
  .main { padding: 0 40px 64px; }
  .mobile-only, .tabbar, .fab { display: none !important; }
  .sidebar {
    display: flex; flex-direction: column; gap: 28px;
    position: sticky; top: 0; height: 100dvh;
    padding: 28px 20px;
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  }
  .sidebar-cta { width: 100%; justify-content: center; }
  .sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); letter-spacing: .06em; }
}

/* brand */
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%;
  font: 600 20px/1 var(--font-display);
  color: var(--on-gold);
  background: linear-gradient(140deg, var(--gold-2), var(--gold) 55%, color-mix(in srgb, var(--gold) 70%, #000));
  box-shadow: 0 0 0 1px var(--line-strong), 0 8px 22px -8px var(--gold);
}
.brand-mark-sm { width: 30px; height: 30px; font-size: 17px; }
.brand-name { font: 600 26px/1 var(--font-display); letter-spacing: .04em; }

/* nav */
.nav { display: grid; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px;
  color: var(--muted); font-weight: 600; font-size: 14px;
  transition: color .2s, background .2s;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.active { color: var(--text); background: var(--surface-2); box-shadow: inset 2px 0 0 var(--gold); }
.nav-link.active .ico { color: var(--gold); }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-top: 1px solid var(--line);
}
.tabbar .nav-link { flex-direction: column; gap: 3px; padding: 6px 0; font-size: 11px; justify-content: center; }
.tabbar .nav-link.active { background: none; box-shadow: none; }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 21;
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%;
  color: var(--on-gold);
  background: linear-gradient(140deg, var(--gold-2), var(--gold));
  box-shadow: 0 14px 30px -10px var(--gold), 0 0 0 1px var(--line-strong);
  transition: transform .2s var(--ease);
}
.fab:active { transform: scale(.94); }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  max-width: var(--maxw); margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 18px 0 14px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar-title { display: flex; align-items: center; gap: 10px; }
.topbar h1 { font: 600 30px/1.1 var(--font-display); letter-spacing: .01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.month-picker {
  display: flex; align-items: center; gap: 2px;
  padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.month-picker[hidden] { display: none; }
.month-label { min-width: 128px; text-align: center; font-size: 13.5px; font-weight: 600; text-transform: capitalize; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  color: var(--muted); transition: color .2s, background .2s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.theme-btn { border: 1px solid var(--line); width: 42px; height: 42px; background: var(--surface); }
[data-theme='dark'] .i-sun, [data-theme='light'] .i-moon { display: none; }

@media (min-width: 960px) {
  .topbar { padding: 28px 0 18px; }
  .topbar h1 { font-size: 36px; }
}
@media (max-width: 520px) {
  .topbar h1 { font-size: 26px; }
  .month-label { min-width: 104px; font-size: 12.5px; }
  #month-today { display: none; }
}

/* ═════════════ components ═════════════ */
.card {
  position: relative;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 96%, var(--gold) 4%), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
@media (min-width: 720px) { .card { padding: 24px 26px; } }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head h3 { font: 600 22px/1.2 var(--font-display); letter-spacing: .01em; }
.card-head p { font-size: 13px; margin-top: 2px; }
.head-stat { text-align: right; font-size: 13px; white-space: nowrap; }
.head-stat small { display: block; color: var(--muted); }
.head-stat b { font-size: 16px; }

.grid-2 { display: grid; gap: 16px; }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
.label { font-size: 13px; color: var(--muted); margin-top: 18px; }
.display { font-family: var(--font-display); font-weight: 500; letter-spacing: -.01em; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px; border-radius: 999px;
  font-weight: 600; font-size: 14px; letter-spacing: .01em; white-space: nowrap;
  transition: transform .15s var(--ease), background .2s, border-color .2s, color .2s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-gold {
  color: var(--on-gold);
  background: linear-gradient(140deg, var(--gold-2), var(--gold));
  box-shadow: 0 10px 24px -12px var(--gold);
}
.btn-gold:hover { box-shadow: 0 12px 28px -10px var(--gold); }
.btn-outline { border: 1px solid var(--line-strong); color: var(--text); }
.btn-outline:hover { border-color: var(--gold); color: var(--gold); }
.btn-ghost { color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger { border: 1px solid color-mix(in srgb, var(--expense) 50%, transparent); color: var(--expense); }
.btn-danger:hover { background: color-mix(in srgb, var(--expense) 12%, transparent); }
.btn-danger-ghost { color: var(--expense); padding-left: 8px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface);
  transition: all .2s;
}
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip.active { color: var(--on-gold); background: var(--gold); border-color: var(--gold); }
.chip-sm { padding: 5px 11px; font-size: 12px; margin-left: 4px; }
.chip[hidden] { display: none; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill-income { color: var(--income); background: color-mix(in srgb, var(--income) 14%, transparent); }
.pill-expense { color: var(--expense); background: color-mix(in srgb, var(--expense) 14%, transparent); }
.pill-gold { color: var(--gold); background: color-mix(in srgb, var(--gold) 14%, transparent); }

.bubble {
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 13px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 22%, transparent);
}
.bubble-sm { width: 30px; height: 30px; border-radius: 10px; }

/* hero */
.hero { overflow: hidden; padding: 26px 22px; }
.hero::after {
  content: ''; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none;
  background: radial-gradient(500px 200px at 100% 0%, color-mix(in srgb, var(--gold) 16%, transparent), transparent 70%);
}
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.balance { font-size: clamp(44px, 9vw, 68px); line-height: 1.05; margin: 4px 0 20px; }
.hero h2.display { font-size: clamp(36px, 7vw, 56px); line-height: 1.05; margin: 14px 0 12px; }
.hero h2 em { color: var(--gold); font-style: italic; }
.lead { max-width: 520px; font-size: 15px; }
.flows { display: flex; gap: 12px; flex-wrap: wrap; }
.flow {
  flex: 1 1 200px; display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line);
}
.flow small { display: block; color: var(--muted); font-size: 12px; }
.flow b { font-size: 17px; font-weight: 700; }
.flow-ico { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: color-mix(in srgb, currentColor 14%, transparent); }
.insight { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13.5px; color: var(--muted); }
.insight b { color: var(--text); font-weight: 700; }
@media (min-width: 720px) { .hero { padding: 34px 36px; } }

/* donut */
.card { container-type: inline-size; }
.breakdown { display: grid; gap: 22px; align-items: center; }
@container (min-width: 500px) { .breakdown { grid-template-columns: auto 1fr; } }
.donut { position: relative; width: var(--size); height: var(--size); margin: 0 auto; }
.donut svg { display: block; }
.donut circle, .ring circle { transition: stroke-dasharray .6s var(--ease); }
.track { stroke: var(--track); }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-center small { color: var(--muted); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.donut-center b { font: 600 26px/1.1 var(--font-display); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 40px; align-items: center; gap: 10px; font-size: 13.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent); }
.legend-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-val { font-weight: 700; white-space: nowrap; }
.legend-pct { color: var(--muted); text-align: right; font-size: 12.5px; }

/* budget bars */
.budgets, .plan-list { display: grid; gap: 18px; }
.budget-head, .budget-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.budget-name { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; min-width: 0; }
.budget-name small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.budget-num { font-size: 13px; color: var(--muted); white-space: nowrap; }
.budget-num b { color: var(--text); }
.budget-foot { font-size: 12px; color: var(--muted); margin-top: 6px; }
.bar { height: 6px; border-radius: 99px; background: var(--track); overflow: hidden; margin-top: 10px; }
.bar span {
  display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--gold) 70%, transparent), var(--gold-2));
  transition: width .6s var(--ease);
}
.bar.warn span { background: linear-gradient(90deg, color-mix(in srgb, var(--warn) 70%, transparent), var(--warn)); }
.bar.over span { background: linear-gradient(90deg, color-mix(in srgb, var(--expense) 70%, transparent), var(--expense)); }

.plan-row {
  display: grid; grid-template-columns: 1fr; gap: 10px;
  padding-bottom: 16px; border-bottom: 1px solid var(--line);
}
.plan-row:last-child { border-bottom: 0; padding-bottom: 0; }
.plan-bar { display: flex; align-items: center; gap: 10px; }
.plan-bar .bar { flex: 1; margin: 0; }
.plan-bar small { font-size: 12px; font-weight: 600; min-width: 36px; text-align: right; }
@media (min-width: 720px) {
  .plan-row { grid-template-columns: minmax(180px, 1.1fr) 1.4fr 180px; align-items: center; gap: 20px; }
}

/* inputs */
.money-input, .search, .field input, .select {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2);
  transition: border-color .2s, box-shadow .2s;
}
.money-input { padding: 0 12px; }
.money-input span { color: var(--muted); font-size: 13px; }
.money-input input, .search input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 10px 0; text-align: right; font-weight: 600;
}
.search input { text-align: left; font-weight: 500; }
.money-input:focus-within, .search:focus-within, .field input:focus, .select:focus {
  border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent); outline: none;
}
.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.field input { padding: 11px 14px; width: 100%; }
.field-row { display: grid; gap: 12px; }
@media (min-width: 520px) { .field-row { grid-template-columns: auto 1fr; } .field-row .grow { min-width: 0; } }
.select { padding: 10px 14px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.check { display: flex; gap: 10px; align-items: center; font-size: 13.5px; color: var(--muted); }
.check input { accent-color: var(--gold); width: 18px; height: 18px; }

/* transactions */
.toolbar { display: grid; gap: 10px; }
.search { padding: 0 14px; color: var(--muted); }
@media (min-width: 860px) { .toolbar { grid-template-columns: 1fr auto 220px; align-items: center; } }
.summary-line { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); padding: 4px 4px 12px; }
.summary-line span:not(:first-child) { font-weight: 700; }
#tx-list { display: grid; gap: 14px; }
#tx-list > .summary-line { margin-bottom: -6px; }
.day-group { padding: 14px 16px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 6px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 13px; }
.day-head h4 { font-weight: 600; text-transform: capitalize; }
.tx-list { display: grid; }
.tx-row, .bill-main {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 10px 6px; border-radius: 12px; transition: background .2s;
}
.tx-row:hover, .bill-main:hover { background: var(--surface-2); }
.tx-main { flex: 1; min-width: 0; display: grid; }
.tx-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12.5px; color: var(--muted); }
.tx-amount { font-weight: 700; white-space: nowrap; font-size: 14.5px; }
.tx-amount.expense { color: var(--text); }
.tx-amount.income { color: var(--income); }

/* bills */
.bills { display: grid; gap: 4px; }
.bill-row { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.bill-row .bill-main { flex: 1; min-width: 0; display: grid; gap: 0; padding: 8px; }
.bill-row.paid { opacity: .62; }
.bill-day {
  display: grid; place-items: center; width: 46px; height: 50px; flex-shrink: 0;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
  font: 600 22px/1 var(--font-display);
}
.bill-day small { font: 600 10px/1 var(--font-ui); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); margin-bottom: -6px; }

/* goals */
.goals { display: grid; gap: 14px; }
@media (min-width: 720px) { .goals { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); } }
.goal {
  display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center;
  padding: 18px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2);
}
.goal-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.goal h4 { font: 600 20px/1.2 var(--font-display); }
.goal-amount { font-size: 14px; margin-top: 2px; }
.goal-meta { font-size: 12.5px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.goals-compact { display: grid; gap: 10px; }
.goal-compact { padding: 12px 14px; background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; }
.goal-compact:last-child { border-bottom: 0; }
.goal-compact h4 { font-size: 18px; }
.ring { position: relative; width: var(--size); height: var(--size); }
.ring svg { display: block; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; }

/* empty */
.empty { text-align: center; padding: 48px 20px; display: grid; justify-items: center; gap: 8px; }
.empty-mark { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; color: var(--gold); border: 1px solid var(--line-strong); margin-bottom: 8px; }
.empty h3 { font: 600 24px/1.2 var(--font-display); }
.empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }
.hero .empty-actions { justify-content: flex-start; margin-top: 26px; }

/* settings */
.settings { display: grid; gap: 18px; }
.settings .card-head { margin-bottom: 0; }
.setting-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.shortcuts { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; font-size: 14px; color: var(--muted); }
kbd {
  display: inline-block; min-width: 26px; padding: 2px 7px; margin-right: 6px; text-align: center;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 7px;
  font: 600 12px var(--font-ui); color: var(--text); background: var(--surface-2);
}
.colophon { text-align: center; font-size: 12px; color: var(--muted); letter-spacing: .08em; padding: 8px 0 24px; }

/* ═════════════ sheet (dialog) ═════════════ */
dialog { color: var(--text); padding: 0; border: 0; background: transparent; }
dialog::backdrop { background: rgba(8, 7, 6, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.sheet {
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0;
}
.sheet[open] { animation: sheet-up .32s var(--ease); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.sheet-form {
  display: grid; grid-template-rows: auto 1fr auto; max-height: 92dvh;
  background: var(--surface); border: 1px solid var(--line-strong); border-bottom: 0;
  border-radius: 24px 24px 0 0; box-shadow: var(--shadow);
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 22px 8px; }
.sheet-head h3 { font: 600 26px/1.2 var(--font-display); }
.sheet-body { overflow-y: auto; padding: 10px 22px 18px; display: grid; gap: 18px; align-content: start; }
.sheet-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 14px 22px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
}
@media (min-width: 640px) {
  .sheet { width: 520px; margin: auto; }
  .sheet[open] { animation: pop .26s var(--ease); }
  .sheet-form { border-radius: 24px; border-bottom: 1px solid var(--line-strong); }
  .sheet-foot { padding-bottom: 18px; }
}
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }

.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 9px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--muted); transition: all .2s; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 2px 10px -4px rgba(0, 0, 0, .4), 0 0 0 1px var(--line-strong); }
.seg input:focus-visible + span { outline: 2px solid var(--gold); }

.amount-field {
  display: flex; align-items: baseline; justify-content: center; gap: 10px;
  padding: 14px 10px 10px; border-bottom: 1px solid var(--line-strong);
}
.amount-field span { font: 500 22px var(--font-display); color: var(--muted); }
.amount-field input {
  width: 100%; max-width: 360px; border: 0; background: none; outline: none; text-align: center;
  font: 500 clamp(40px, 11vw, 54px)/1.1 var(--font-display); letter-spacing: -.01em;
}
.amount-field input::placeholder { color: var(--surface-3); }
.amount-field[data-type='income'] input { color: var(--income); }
.amount-field:focus-within { border-color: var(--gold); }

.cat-grid { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.cat-grid legend { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 8px; padding: 0; }
.cat-opt {
  position: relative; display: grid; justify-items: center; gap: 6px; padding: 12px 6px;
  border-radius: 14px; border: 1px solid var(--line); cursor: pointer; text-align: center;
  font-size: 12px; font-weight: 600; color: var(--muted); transition: all .2s;
}
.cat-opt input { position: absolute; opacity: 0; }
.cat-opt:hover { border-color: var(--line-strong); color: var(--text); }
.cat-opt:has(input:checked) { border-color: var(--c); color: var(--text); background: color-mix(in srgb, var(--c) 10%, transparent); }
.cat-opt:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }

.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* confirm */
.confirm { width: min(420px, calc(100% - 32px)); margin: auto; }
.confirm-form { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 22px; padding: 24px; display: grid; gap: 10px; box-shadow: var(--shadow); }
.confirm-form h3 { font: 600 24px/1.2 var(--font-display); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 50;
  display: flex; align-items: center; gap: 14px;
  max-width: calc(100% - 32px); padding: 12px 14px 12px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .5);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  transition: transform .3s var(--ease), opacity .3s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast-btn { color: var(--gold); font-weight: 700; padding: 4px 8px; border-radius: 999px; }
[data-theme='dark'] .toast-btn { color: #8a6a2e; }
@media (min-width: 960px) { .toast { bottom: 32px; left: calc(50% + var(--sidebar) / 2); } }

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

/* Amount input hugs its content so the "Rp" prefix sits right next to the number. */
@supports (field-sizing: content) {
  .amount-field input { field-sizing: content; width: auto; min-width: 1.2ch; text-align: left; }
}

/* Narrow screens: let rows wrap instead of overflowing the viewport. */
.grid-2 > *, .view > * { min-width: 0; }
.budget-head { flex-wrap: wrap; }
@media (max-width: 380px) {
  .main { padding-inline: 12px; }
  .card { padding: 16px; }
  .balance { font-size: 38px; }
  .month-label { min-width: 0; padding: 0 2px; }
  .theme-btn { width: 36px; height: 36px; }
  .topbar-actions { flex: 1; justify-content: space-between; }
}

/* PWA */
.offline-pill[hidden] { display: none; }
.offline-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 2px; }
.hint { font-size: 13px; }
.hint b { color: var(--text); }

/* ═════════════ trend chart ═════════════ */
.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
@container (min-width: 640px) { .stat-row { grid-template-columns: repeat(4, 1fr); } }
.stat { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.stat small { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat b { display: inline-flex; align-items: center; gap: 4px; font-size: 18px; font-weight: 700; font-variant-numeric: proportional-nums; }

.chart-legend { display: flex; gap: 18px; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 8px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.key-in { background: var(--chart-in); }
.key-out { background: var(--chart-out); }
.key-line { width: 12px; height: 2px; border-radius: 2px; }
.key-none { width: 12px; height: 2px; }

.trend-plot { position: relative; min-height: 210px; }
.trend-plot svg { display: block; overflow: visible; }
.trend-plot .grid, .trend-plot .baseline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.trend-plot .baseline { stroke: var(--line-strong); }
.trend-plot .axis { fill: var(--muted); font: 500 11px var(--font-ui); font-variant-numeric: tabular-nums; }
.trend-plot .axis-sel { fill: var(--text); font-weight: 700; }
.trend-plot .sel-band { fill: var(--surface-2); }
.trend-plot .col { transition: opacity .2s; }
.trend-plot .col-in { fill: var(--chart-in); }
.trend-plot .col-out { fill: var(--chart-out); }
.trend-hit { position: absolute; top: 0; border-radius: 10px; }
.trend-hit:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.trend-hit.hover { background: color-mix(in srgb, var(--text) 4%, transparent); }

.trend-tip {
  position: absolute; top: -6px; z-index: 3; pointer-events: none; width: max-content;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow); font-size: 12.5px;
}
.trend-tip[hidden] { display: none; }
.tip-head { font-weight: 700; margin-bottom: 6px; text-transform: capitalize; }
.tip-row { display: grid; grid-template-columns: 12px auto 1fr; align-items: center; gap: 8px; line-height: 1.7; }
.tip-row b { font-weight: 700; color: var(--text); white-space: nowrap; }
.tip-row span { white-space: nowrap; }
.tip-row span { color: var(--muted); }

.trend-table { margin-top: 14px; font-size: 13px; }
.trend-table summary { cursor: pointer; color: var(--gold); font-weight: 600; width: max-content; list-style: none; }
.trend-table summary::-webkit-details-marker { display: none; }
.trend-table summary::before { content: '▸ '; }
.trend-table[open] summary::before { content: '▾ '; }
.table-wrap { overflow-x: auto; margin-top: 10px; }
.trend-table table { width: 100%; border-collapse: collapse; min-width: 460px; font-variant-numeric: tabular-nums; }
.trend-table th, .trend-table td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.trend-table th:first-child, .trend-table td:first-child { text-align: left; text-transform: capitalize; }
.trend-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.trend-table tr.sel td { color: var(--text); font-weight: 700; background: var(--surface-2); }

/* ═════════════ category manager ═════════════ */
.cat-list { display: grid; }
.cat-row { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.cat-row.is-hidden .bubble, .cat-row.is-hidden .tx-title { opacity: .55; }
.cat-row .pill { padding: 1px 8px; font-size: 11px; margin-left: 6px; vertical-align: 1px; }
.cat-order { display: grid; }
.icon-btn-sm { width: 26px; height: 22px; border-radius: 7px; }
.icon-btn:disabled { opacity: .25; cursor: default; background: none; }
.cat-row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 12px; text-align: left; transition: background .2s; }
.cat-row-main:hover { background: var(--surface-2); }

.cat-preview { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); }
.cat-preview b { display: block; font: 600 22px/1.2 var(--font-display); }
.cat-preview .bubble { color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 22%, transparent); }
.bubble-lg { width: 56px; height: 56px; border-radius: 17px; }

.icon-grid, .swatches { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.icon-grid { grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); }
.swatches { grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); }
.icon-grid legend, .swatches legend { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 8px; padding: 0; }
.icon-opt, .swatch { position: relative; display: grid; place-items: center; cursor: pointer; }
.icon-opt input, .swatch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.icon-opt { height: 42px; border-radius: 12px; border: 1px solid var(--line); color: var(--muted); transition: all .15s; }
.icon-opt:hover { color: var(--text); border-color: var(--line-strong); }
.icon-opt:has(input:checked) { color: var(--gold); border-color: var(--gold); background: color-mix(in srgb, var(--gold) 10%, transparent); }
.swatch { width: 34px; height: 34px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); transition: transform .15s; }
.swatch:hover { transform: scale(1.08); }
.swatch:has(input:checked) { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.icon-opt:has(input:focus-visible), .swatch:has(input:focus-visible) { outline: 2px solid var(--gold); outline-offset: 2px; }
.foot-left { display: flex; gap: 4px; flex-wrap: wrap; }
.text { color: var(--text); }

/* ═════════════ v2: wallets, transfers, currency, receipts, recurring ═════════════ */
.tabbar { grid-template-columns: repeat(5, 1fr); }
.tabbar .nav-link { font-size: 10.5px; }
.bubble-neutral { --c: var(--muted); }
.inline-ico { vertical-align: -2px; opacity: .7; }
.tx-amount.transfer { color: var(--muted); }
.tx-row.is-paused { opacity: .55; }
.carry { color: var(--income); font-weight: 600; }
.check-sm { font-size: 12.5px; }
.check-sm input { width: 15px; height: 15px; }
@media (min-width: 720px) { .plan-row .check-sm { grid-column: 1 / -1; justify-self: end; margin-top: -6px; } }

.toolbar-btn { justify-self: start; }
@media (min-width: 860px) {
  .toolbar { grid-template-columns: 1fr auto minmax(160px, 200px) minmax(140px, 180px) auto; }
}

.seg-3 { grid-template-columns: repeat(3, 1fr); }
.amount-wrap { display: flex; align-items: flex-end; gap: 10px; }
.amount-wrap .amount-field { flex: 1; min-width: 0; }
.currency-select { padding: 8px 30px 8px 12px; font-weight: 700; font-size: 13px; margin-bottom: 10px; }
.fx-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.fx-row[hidden] { display: none; }
.fx-result { font: 600 18px var(--font-display); color: var(--gold); padding-bottom: 10px; white-space: nowrap; }
.field-row-2 { grid-template-columns: 1fr 1fr !important; }
.field .select, .field select { width: 100%; }

.receipt-field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.receipt-preview { display: flex; align-items: center; gap: 4px; }
.receipt-preview:empty { display: none; }
.receipt-thumb { width: 64px; height: 64px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line-strong); }
.receipt-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.viewer { max-width: min(92vw, 900px); max-height: 92dvh; margin: auto; position: relative; }
.viewer img { display: block; max-width: 100%; max-height: 88dvh; border-radius: 14px; box-shadow: var(--shadow); }
.viewer-close { position: absolute; top: 10px; right: 10px; background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--text); }

.reminder-card { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.reminder-card h3 { display: flex; align-items: center; gap: 10px; }
.reminder-card h3 .ico { color: var(--warn); }
.reminder-card .bill-main { flex: 1; min-width: 0; display: grid; padding: 8px; }
.bill-day.late { border-color: color-mix(in srgb, var(--expense) 55%, transparent); }
.bill-day.late small { color: var(--expense); }

.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.account-tile {
  display: grid; gap: 2px; justify-items: start; text-align: left; padding: 14px; min-width: 0;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); transition: border-color .2s, transform .15s;
}
.account-tile:hover { border-color: color-mix(in srgb, var(--c, var(--gold)) 60%, transparent); }
.account-tile:active { transform: scale(.98); }
.account-tile .bubble { margin-bottom: 6px; }
.account-name { font-size: 13px; color: var(--muted); font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-tile b { font-size: 16px; font-weight: 700; font-variant-numeric: proportional-nums; }
.account-tile small { font-size: 11.5px; color: var(--muted); }
.account-add { place-content: center; justify-items: center; gap: 6px; color: var(--muted); border-style: dashed; font-size: 13px; font-weight: 600; }

.kind-grid { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.kind-grid legend { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 8px; padding: 0; }
.kind-opt { height: auto; padding: 12px 6px; gap: 6px; text-align: center; font-size: 11.5px; font-weight: 600; }
.money-input-left input { text-align: left; }
.field small { font-size: 12px; }

.rate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px 16px; }
.rate-row { display: grid; grid-template-columns: 1fr 130px; align-items: center; gap: 10px; }
.rate-row > span:first-child { display: grid; }
.rate-row small { color: var(--muted); font-size: 12px; }
.rate-row.used b { color: var(--gold); }
.rate-row .money-input input { padding: 8px 0; }

.notice { display: flex; gap: 12px; padding: 14px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--gold) 8%, var(--surface-2)); border: 1px solid var(--line-strong); }
.notice > .ico { color: var(--gold); margin-top: 2px; }
.notice p { font-size: 13px; margin: 2px 0 10px; }
.field-inline { grid-template-columns: 1fr auto; align-items: center; }
.field-inline .select { width: auto; }

[aria-busy='true'] { opacity: .6; pointer-events: none; }

/* ═════════════ report ═════════════ */
.report-title { font-size: clamp(34px, 6vw, 48px); line-height: 1.05; margin: 6px 0 4px; text-transform: capitalize; }
.report-head .card-head { align-items: flex-end; }
.stat .delta { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 700; margin-left: 8px; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-size: 12.5px; white-space: nowrap; }
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.insights li { position: relative; padding-left: 22px; line-height: 1.6; color: var(--muted); }
.insights li::before { content: '✦'; position: absolute; left: 0; top: 0; color: var(--gold); font-size: 12px; }
.insights b { color: var(--text); }
.report-table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.report-table th, .report-table td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.report-table th:first-child, .report-table td:first-child { text-align: left; white-space: normal; }
.report-table th { color: var(--muted); font-size: 12px; font-weight: 600; }
.report-table .dot { display: inline-block; margin-right: 6px; }
@media (min-width: 900px) { .budgets-2col { grid-template-columns: 1fr 1fr; column-gap: 32px; } }
.print-only { display: none; }

/* ═════════════ lock screen ═════════════ */
.lock {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(800px 500px at 50% 0%, var(--bg-glow), transparent 70%), var(--bg);
}
.lock[hidden] { display: none; }
.lock-card { display: grid; justify-items: center; gap: 14px; width: min(320px, 100%); text-align: center; }
.lock-card .brand-mark { width: 56px; height: 56px; font-size: 30px; }
.lock-card h2 { font-size: 34px; }
.pin-dots { display: flex; gap: 14px; margin: 6px 0 10px; }
.pin-dots span { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--gold); transition: background .15s; }
.pin-dots span.on { background: var(--gold); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center;
  font: 500 30px var(--font-display); color: var(--text); font-variant-numeric: lining-nums;
  background: var(--surface); border: 1px solid var(--line); transition: background .15s, transform .1s;
}
.keypad button:active { transform: scale(.94); background: var(--surface-3); }
.lock-forgot { margin-top: 8px; background: none; }

/* ═════════════ print (report → PDF) ═════════════ */
@media print {
  :root, [data-theme] {
    --bg: #fff; --surface: #fff; --surface-2: #f6f3ee; --text: #1a1612; --muted: #5f574c;
    --line: #e4ddd1; --line-strong: #cdbfa8; --gold: #8a6a2e; --shadow: none; color-scheme: light;
  }
  body { background: #fff; font-size: 12px; }
  .sidebar, .tabbar, .fab, .topbar-actions, .toast, .no-print, #offline-pill { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .topbar { position: static; padding: 0 0 8px; background: none; }
  .card { box-shadow: none; break-inside: avoid; background: #fff; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .view.enter > * { animation: none; }
  .print-only { display: block; }
  .tx-row { padding: 6px 0; }
}

/* Smallest phones (320px): drop the share column and stack the exchange-rate row. */
@container (max-width: 330px) {
  .report-table th:nth-child(3), .report-table td:nth-child(3) { display: none; }
}
@media (max-width: 380px) {
  .fx-row { grid-template-columns: 1fr; gap: 4px; }
  .fx-result { padding-bottom: 0; }
  .amount-wrap { gap: 6px; }
  .amount-field input { font-size: 38px; }
  .sheet-body { padding-inline: 16px; }
}
.amount-field input { min-width: 0; max-width: 100%; }
/* The sheet's single grid column must not grow to its widest child's min-content width. */
.sheet-body { grid-template-columns: minmax(0, 1fr); }
.seg span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 380px) {
  .seg-3 span { padding: 9px 4px; font-size: 12.5px; }
  .cat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
