:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe8d9;
  --ink: #26231e;
  --ink-2: #6b6458;
  --line: #e2d9c6;
  --brand: #2f5d50;
  --brand-ink: #f6f1e7;
  --accent: #c8553d;
  --good: #3f7d4e;
  --warn: #c98a1b;
  --bad: #b8402b;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 6px 20px -8px rgba(60, 45, 20, .14);
  --radius: 16px;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171611;
    --surface: #211f19;
    --surface-2: #2b2820;
    --ink: #f0eadc;
    --ink-2: #a49c8b;
    --line: #38342a;
    --brand: #6fb39e;
    --brand-ink: #14211d;
    --accent: #e27a61;
    --good: #7dc08c;
    --warn: #e3ae4b;
    --bad: #e57762;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -10px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font-body); -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 1.9rem; line-height: 1.15; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--ink-2); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 24px 16px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.2rem; font-weight: 650; padding: 0 10px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; color: var(--brand-ink); }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); }
.nav svg { width: 20px; height: 20px; flex: none; }
.side-foot { margin-top: auto; padding: 10px; font-size: .85rem; }
main { padding: 28px clamp(16px, 4vw, 44px) 96px; max-width: 1080px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.stack { display: grid; gap: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card > h2, .card > .row > h2 { margin-bottom: 14px; }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 9px 16px; border-radius: 999px; font-weight: 500;
  transition: transform .08s, background .15s; white-space: nowrap; text-decoration: none; color: var(--ink);
  display: inline-block; text-align: center;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 12px; font-size: .85rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.icon-btn { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border-radius: 50%; }
.field { display: grid; gap: 6px; }
.field > span { font-size: .82rem; color: var(--ink-2); font-weight: 500; }
input, select {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); min-height: 42px; font-size: 16px;
}
input:focus, select:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 999px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; font-weight: 500; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg button.exp[aria-pressed="true"] { color: var(--accent); }
.seg button.inc[aria-pressed="true"] { color: var(--good); }
.month-nav { display: inline-flex; align-items: center; gap: 4px; }
.month-nav .label { min-width: 132px; text-align: center; font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; }

/* ---------- dashboard ---------- */
.hero { background: var(--brand); color: var(--brand-ink); border: 0; position: relative; overflow: hidden; }
.hero::after {
  content: ''; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.14), transparent 70%);
}
.hero .label { opacity: .8; font-size: .85rem; }
.hero .big { font-family: var(--font-display); font-size: clamp(2.2rem, 7vw, 3.2rem); font-weight: 600; line-height: 1.1; margin: 4px 0 18px; }
.hero .pair { display: flex; gap: 32px; flex-wrap: wrap; }
.hero .pair b { display: block; font-size: 1.2rem; font-weight: 600; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--good); transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--bad); }
.hero .bar { background: rgba(255,255,255,.2); }
.hero .bar > i { background: var(--brand-ink); }
.legend { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.legend li { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; font-size: .92rem; }
.dot { width: 12px; height: 12px; border-radius: 4px; }
.donut-wrap { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; justify-content: center; }
.donut-wrap .legend { flex: 1 1 200px; }
.chart-tip { fill: var(--ink-2); font-size: 11px; }
.person { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.person + .person { border-top: 1px solid var(--line); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; flex: none; }
.avatar.sm { width: 24px; height: 24px; font-size: .72rem; }
.pill { font-size: .75rem; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }

/* ---------- lists ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.filters > * { flex: 1 1 140px; width: auto; }
.filters input[type=search] { flex: 2 1 200px; }
.day-head { font-size: .8rem; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; padding: 14px 4px 6px; }
.tx {
  display: grid; grid-template-columns: 42px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left;
  padding: 10px 8px; border: 0; background: transparent; border-radius: 12px;
}
.tx:hover { background: var(--surface-2); }
.tx .ico { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 1.2rem; }
.tx .t { font-weight: 500; }
.tx .meta { font-size: .82rem; color: var(--ink-2); display: flex; gap: 6px; align-items: center; }
.amt { font-weight: 600; white-space: nowrap; }
.amt.inc { color: var(--good); }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.empty .big-emoji { font-size: 2.4rem; display: block; margin-bottom: 6px; }
.budget-row { display: grid; gap: 8px; padding: 14px 0; }
.budget-row + .budget-row { border-top: 1px solid var(--line); }
.budget-row input { width: 130px; text-align: right; padding: 6px 10px; min-height: 34px; }
.goal .ring-row { display: flex; gap: 16px; align-items: center; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.list-row + .list-row { border-top: 1px solid var(--line); }
.list-row .grow { flex: 1; min-width: 0; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(440px, 100%); display: grid; gap: 18px; }
.auth-card h1 { font-size: 2.2rem; }
.auth form { display: grid; gap: 14px; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2em; margin: 0; }

/* ---------- dialog / toast ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 22px; padding: 0; width: min(480px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0,0,0,.45);
}
dialog::backdrop { background: rgba(30, 24, 12, .5); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 14px; padding: 22px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
dialog .actions .spacer { margin-right: auto; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.amount-input { font-family: var(--font-display); font-size: 1.8rem; text-align: center; min-height: 58px; }
.cat-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-pick button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 5px 12px; font-size: .88rem;
}
.cat-pick button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
#toast {
  position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: .9rem; transition: .25s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.fab {
  position: fixed; right: 28px; bottom: 28px; z-index: 20; height: 56px; padding: 0 24px 0 20px; border-radius: 99px;
  border: 0; background: var(--accent); color: #fff; font-weight: 600; display: flex; gap: 8px; align-items: center;
  box-shadow: 0 10px 30px -8px color-mix(in srgb, var(--accent) 70%, black); transition: transform .1s;
}
.fab:hover { transform: translateY(-2px); }
.fab svg { width: 22px; height: 22px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; z-index: 30; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px);
  }
  .brand, .side-foot { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: .68rem; padding: 6px 8px; border-radius: 12px; }
  main { padding-top: 20px; padding-bottom: 130px; }
  .fab { right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); height: 52px; }
  #toast { bottom: 150px; }
  h1 { font-size: 1.6rem; }
}
