@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #FAF5EE;
  --surface: #FFFDF9;
  --surface2: #F6EFE5;
  --ink: #2B1D14;
  --ink2: #5C4636;
  --muted: #9A8573;
  --line: #EDE2D3;
  --accent: #6B3A22;
  --accent-ink: #FFF8EE;
  --rust: #B5532A;
  --gold: #D39B35;
  --olive: #6E7B34;
  --pos: #5E7A2E;
  --neg: #A63A2A;
  --warn: #C77A2A;
  --shadow: 0 1px 2px rgba(80, 45, 20, .04), 0 8px 24px rgba(80, 45, 20, .06);
  --r: 18px;
  --tab-h: 64px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110D; --surface: #211813; --surface2: #1C1410; --ink: #F5EBDD; --ink2: #CDB9A3;
    --muted: #9A8573; --line: #34271F; --accent: #E09A55; --accent-ink: #2B1D14; --rust: #D9774A;
    --gold: #E2B357; --olive: #A3B060; --pos: #A9C46A; --neg: #E58A73; --warn: #E3A15B; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num, .amt { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ------------------------------------------------ layout */
.app { min-height: 100vh; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); }
.side { display: none; }
.main { max-width: 1120px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.top h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand svg { width: 28px; height: 28px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 500; text-decoration: none; }
.tab svg { width: 22px; height: 22px; }
.tab.on { color: var(--ink); }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); z-index: 21;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.fab svg { width: 26px; height: 26px; }

.grid { display: grid; gap: 14px; }
@media (min-width: 700px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.two > .wide { grid-column: 1 / -1; }
  .main { padding-left: 24px; padding-right: 24px; }
}
@media (min-width: 1000px) {
  .app { display: grid; grid-template-columns: 240px 1fr; padding-bottom: 32px; }
  .tabs { display: none; }
  .side { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; padding: 28px 16px; border-right: 1px solid var(--line); background: var(--surface2); }
  .side .brand { padding: 0 10px 22px; font-size: 19px; }
  .side a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--ink2); text-decoration: none; font-weight: 500; }
  .side a svg { width: 20px; height: 20px; }
  .side a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
  .side .add { margin-top: 14px; }
  .fab { display: none; }
  .main { padding-top: 30px; width: 100%; }
  .grid.three { grid-template-columns: 1.3fr 1fr; }
  .top .brand { display: none; }
}

/* ------------------------------------------------ cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h2 .link { font-size: 13px; font-weight: 500; color: var(--muted); background: none; border: 0; padding: 0; }
.hero { background: var(--accent); color: var(--accent-ink); border: 0; }
.hero .label { opacity: .7; font-size: 13px; font-weight: 500; }
.hero .big { font-size: 38px; font-weight: 700; letter-spacing: -.03em; margin: 4px 0 10px; }
.hero .hrow { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; }
.hero .hrow span { opacity: .7; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 99px; font-size: 13px; font-weight: 500; color: var(--ink2); white-space: nowrap; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.hero .chip { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.15); color: inherit; }
@media (prefers-color-scheme: dark) { .hero .chip { background: rgba(0,0,0,.06); border-color: rgba(0,0,0,.1); } }
.scroll-x { overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.scroll-x::-webkit-scrollbar { display: none; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat .v { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.monthbar { display: flex; align-items: center; gap: 6px; }
.iconbtn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; padding: 0; color: var(--ink2); }
.iconbtn svg { width: 18px; height: 18px; }

/* donut */
.donut-wrap { display: flex; gap: 18px; align-items: center; }
.donut { width: 124px; height: 124px; flex: none; }
@media (max-width: 420px) { .donut-wrap { gap: 12px; } .legend div { font-size: 13px; } }
.legend { flex: 1; display: grid; gap: 7px; min-width: 0; }
.legend div { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.legend .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* bars */
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--ink); }
.budget { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.budget:last-child { border-bottom: 0; }
.budget .t { display: flex; justify-content: space-between; font-size: 14px; gap: 10px; }

/* lists */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%; color: inherit; }
.list > .row:last-child { border-bottom: 0; }
.row .av { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; color: #fff; }
.row .mid { flex: 1; min-width: 0; }
.row .mid b { display: block; font-weight: 550; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .mid span { display: block; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; flex: none; }
.row .end b { display: block; font-weight: 600; font-size: 15px; }
.row .end span { display: block; font-size: 12px; color: var(--muted); }
.dayhead { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 16px 0 2px; display: flex; justify-content: space-between; }
.group-h { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 4px; }
.group-h h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.badge { display: inline-block; white-space: nowrap; flex: none; font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--surface2); border: 1px solid var(--line); color: var(--ink2); vertical-align: 1px; margin-left: 4px; }
.badge.live { color: var(--pos); }
.row .mid span.badge { display: inline-block; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }

/* filters */
.filters { display: grid; gap: 10px; margin-bottom: 14px; }
.search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.selects { display: flex; gap: 8px; }
.selects select { flex: 1; min-width: 0; }

/* forms */
label.f { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink2); }
input.in, select.in, textarea.in, .selects select {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface2); color: var(--ink); font-size: 16px; appearance: none;
}
select.in, .selects select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input.in:focus, select.in:focus, textarea.in:focus, .search:focus { outline: 2px solid color-mix(in srgb, var(--gold) 55%, transparent); outline-offset: 1px; }
.form { display: grid; gap: 14px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.amount-in { font-size: 34px !important; font-weight: 700; text-align: center; letter-spacing: -.02em; padding: 14px !important; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 550; font-size: 14px; color: var(--ink2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface2); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: none; color: var(--neg); border: 1px solid var(--line); }
.btn.sm { padding: 8px 12px; font-size: 14px; }
.btn[disabled] { opacity: .5; }
.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--ink2); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.err { color: var(--neg); font-size: 14px; min-height: 0; }
.note { background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 13.5px; color: var(--ink2); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; word-break: break-all; background: var(--surface2); border: 1px dashed var(--line); padding: 10px 12px; border-radius: 10px; user-select: all; }

/* sheet (bottom on phones, centered on bigger screens) */
.scrim { position: fixed; inset: 0; background: rgba(15, 14, 12, .38); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
.sheet .grab { width: 38px; height: 4px; background: var(--line); border-radius: 9px; margin: 0 auto 12px; }
.sheet .sh { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet .sh h3 { margin: 0; font-size: 18px; }
@media (min-width: 700px) {
  .scrim { align-items: center; }
  .sheet { border-radius: 22px; padding-bottom: 22px; }
  .sheet .grab { display: none; }
}
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 86px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: up .2s; max-width: 90vw; }
@media (min-width: 1000px) { .toast { bottom: 30px; } }

.demo { background: color-mix(in srgb, var(--gold) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--gold) 35%, var(--line)); color: var(--ink); border-radius: 12px; padding: 9px 12px; font-size: 13px; margin-bottom: 14px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .box { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; font-size: 26px; margin-bottom: 6px; }
.login .brand svg { width: 40px; height: 40px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; }

/* goals */
.goal { display: flex; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.goal:last-child { border-bottom: 0; }
.ring { width: 52px; height: 52px; flex: none; }

.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.keyrow { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.keyrow i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

table.map { width: 100%; border-collapse: collapse; font-size: 13px; }
table.map td, table.map th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }

/* autumn look */
.row .av.n { background: var(--surface2); color: var(--ink2); border: 1px solid var(--line); }
.row .av.t { background: color-mix(in srgb, var(--c) 17%, var(--surface)); color: var(--c); }
.bdot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.hero { background: linear-gradient(135deg, #7E3520 0%, #B5532A 55%, #D39B35 120%); color: #FFF8EE; border: 0; }
.hero .label, .hero .hrow span, .hero .small { color: rgba(255, 248, 238, .8); opacity: 1; }
.hero .chip { background: rgba(255, 248, 238, .14); border-color: rgba(255, 248, 238, .22); color: #FFF8EE; }
.hero.branded { background-image: none; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tab.on { color: var(--rust); }
.side a.on { color: var(--rust); }
.demo { background: color-mix(in srgb, var(--gold) 14%, var(--surface)); border-color: color-mix(in srgb, var(--gold) 35%, var(--line)); }
.badge.live { color: var(--olive); }
input.in:focus, select.in:focus, textarea.in:focus, .search:focus { outline-color: color-mix(in srgb, var(--rust) 45%, transparent); }

/* pay-back card */
.card.payback { width: 100%; text-align: left; color: inherit; font: inherit; display: grid; gap: 12px; border-left: 4px solid var(--rust); }
.pb-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 600; font-size: 14.5px; }
.pb-row { display: flex; justify-content: space-between; gap: 14px; }
.pb-row .k { font-size: 12px; color: var(--muted); font-weight: 500; }
.pb-row .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.badge.due { color: var(--rust); border-color: color-mix(in srgb, var(--rust) 40%, var(--line)); background: color-mix(in srgb, var(--rust) 8%, var(--surface)); }

/* currency converter */
.amtrow { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
.amtrow .cur-pick { width: auto; min-width: 92px; font-weight: 600; font-size: 17px; }
.fxbox { display: grid; gap: 10px; background: color-mix(in srgb, var(--gold) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--gold) 30%, var(--line)); border-radius: 14px; padding: 12px 14px; }
.fx-line { display: grid; gap: 2px; }
.fx-line b { font-size: 16px; }
.fx-line span, .fxbox label { font-size: 12.5px; color: var(--ink2); }
.conv { display: grid; grid-template-columns: 1.3fr 1fr auto 1fr; gap: 8px; align-items: center; }
.conv .iconbtn { width: 40px; height: 40px; }
.conv-res { display: grid; gap: 2px; margin: 14px 0 12px; }
.conv-res b { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
@media (max-width: 560px) { .conv { grid-template-columns: 1fr auto 1fr; } .conv #cvAmt { grid-column: 1 / -1; } .conv #cvFrom { grid-column: 1; } }
