/* LedgerLeaf design tokens: forest ink, sage paper, saffron accent */
:root {
  --paper: #f0f4ef; --surface: #fbfcfa; --raised: #ffffff; --ink: #10281f; --muted: #5d7468; --line: #d3ddd3;
  --side: #10281f; --side-ink: #dbe8df; --side-muted: #8fa89a;
  --income: #1f7a55; --expense: #c2412d; --accent: #e59a12; --accent-ink: #2b1c00; --focus: #2f8fbf;
  --warn-bg: #fdf3dc; --good-bg: #e3f3ea; --info-bg: #e6eef3; --bad-bg: #fbe7e3;
  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Bricolage Grotesque", "DM Sans", system-ui, sans-serif;
  --shadow: 0 18px 48px rgba(16, 40, 31, .22);
}
[data-theme="dark"] {
  --paper: #0c1813; --surface: #12211a; --raised: #172a21; --ink: #e6f0e9; --muted: #8fa89a; --line: #23372c;
  --side: #091410; --income: #43b888; --expense: #ec7a66; --shadow: 0 18px 48px rgba(0, 0, 0, .55);
  --warn-bg: #2d2610; --good-bg: #123325; --info-bg: #132a35; --bad-bg: #351a15;
}
* { box-sizing: border-box; }
html { color-scheme: light dark; }
[data-theme="light"] { color-scheme: light; } [data-theme="dark"] { color-scheme: dark; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.55 var(--font-body); }
h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); } .income { color: var(--income); } .expense { color: var(--expense); }
.num { font-variant-numeric: tabular-nums; font-family: var(--font-display); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
kbd { font: 600 .72rem var(--font-body); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); }

/* shell */
body.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 22px 14px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font: 700 1.25rem var(--font-display); text-decoration: none; padding: 0 10px; display: flex; align-items: center; gap: 8px; }
.brand i { width: 14px; height: 14px; background: var(--accent); border-radius: 2px 50% 2px 50%; display: inline-block; }
.jump { display: flex; justify-content: space-between; align-items: center; width: 100%; border: 1px solid rgba(255,255,255,.16); background: transparent; color: var(--side-muted); border-radius: 6px; padding: 7px 10px; font: 500 .85rem var(--font-body); cursor: pointer; }
.jump:hover { color: var(--side-ink); border-color: rgba(255,255,255,.3); }
.jump kbd { background: transparent; border-color: rgba(255,255,255,.2); color: var(--side-muted); }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav h3 { font: 500 .78rem var(--font-body); color: var(--side-muted); padding: 12px 10px 4px; }
.nav a { padding: 7px 10px; border-radius: 6px; text-decoration: none; color: var(--side-muted); font-weight: 500; }
.nav a:hover { color: var(--side-ink); background: rgba(255,255,255,.06); }
.nav a.active { color: var(--side-ink); background: rgba(255,255,255,.1); box-shadow: inset 3px 0 0 var(--accent); }
.side-foot { margin-top: auto; display: grid; gap: 6px; padding: 0 10px; font-size: .85rem; color: var(--side-muted); }
.side-foot strong { color: var(--side-ink); display: block; }
.content { padding: 30px clamp(16px, 4vw, 48px) 72px; width: 100%; }
body.guest { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
body.guest .content { padding: 0; max-width: 400px; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--ink); background: transparent; color: var(--ink); padding: 8px 14px; border-radius: 6px; font: 600 .9rem var(--font-body); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; color: var(--side-muted); padding: 4px 0; }
.btn.ghost:hover { background: transparent; color: var(--side-ink); }
.btn.small { padding: 4px 9px; font-size: .8rem; }
.btn.danger:hover { background: var(--expense); border-color: var(--expense); color: #fff; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }
label { display: grid; gap: 5px; font-weight: 500; font-size: .88rem; }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: var(--ink); width: 100%; }
input[type=color] { padding: 2px; height: 40px; cursor: pointer; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=file] { padding: 8px; }
.form { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; padding: 3px; background: var(--paper); }
.seg-opt { display: block; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span { display: block; text-align: center; padding: 7px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg-opt input:checked + span { background: var(--raised); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--focus); }

/* page chrome */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head form, .head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toasts { position: fixed; top: 16px; right: 16px; display: grid; gap: 8px; z-index: 50; width: min(380px, calc(100vw - 32px)); }
.flash { padding: 11px 14px; border-radius: 8px; border-left: 4px solid var(--muted); background: var(--raised); box-shadow: var(--shadow); cursor: pointer; }
.flash.success { border-color: var(--income); } .flash.error { border-color: var(--expense); } .flash.info { border-color: var(--focus); }
@media (prefers-reduced-motion: no-preference) { .flash { animation: drop .25s ease-out; } @keyframes drop { from { opacity: 0; transform: translateY(-8px); } } }

/* ledger strip: one panel, columns split by hairlines */
.strip { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); background: var(--surface); border-radius: 10px; margin-bottom: 14px; }
.strip > div { padding: 18px 20px; border-left: 1px solid var(--line); }
.strip > div:first-child { border-left: 0; }
.strip.three { grid-template-columns: repeat(3, 1fr); }
.strip .label { color: var(--muted); font-size: .85rem; }
.strip .value { font: 700 1.7rem var(--font-display); font-variant-numeric: tabular-nums; }
.strip .hero .value { font-size: 2.2rem; }
.accounts-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.chip { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: 999px; font-size: .88rem; text-decoration: none; }
.chip b { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.chip.total { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; margin-bottom: 18px; }
.grid.even { grid-template-columns: 1fr 1fr; } .grid.side { grid-template-columns: 1.5fr 1fr; }
.panel { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 20px; min-width: 0; }
.panel h2 { margin-bottom: 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel h2 a { font: 500 .85rem var(--font-body); color: var(--muted); }
.chart-box { position: relative; height: 250px; }

/* notes (insights) */
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.notes li { padding: 9px 12px; border-radius: 6px; border-left: 4px solid var(--focus); background: var(--info-bg); }
.notes li.good { border-color: var(--income); background: var(--good-bg); }
.notes li.warn { border-color: var(--accent); background: var(--warn-bg); }

/* heatmap: Monday-first columns, saffron intensity = spending */
.heat-wrap { overflow-x: auto; padding-bottom: 4px; }
.heat-months { display: grid; grid-auto-flow: column; grid-auto-columns: 15px; gap: 3px; margin-left: 28px; font-size: .72rem; color: var(--muted); height: 16px; }
.heat-body { display: flex; gap: 6px; }
.heat-days { display: grid; grid-template-rows: repeat(7, 15px); gap: 3px; font-size: .7rem; color: var(--muted); width: 22px; }
.heat { display: grid; grid-template-rows: repeat(7, 15px); grid-auto-flow: column; grid-auto-columns: 15px; gap: 3px; }
.heat i { border-radius: 3px; background: var(--line); }
.heat i.l-1 { background: color-mix(in srgb, var(--accent) 30%, var(--surface)); }
.heat i.l-2 { background: color-mix(in srgb, var(--accent) 55%, var(--surface)); }
.heat i.l-3 { background: color-mix(in srgb, var(--accent) 80%, var(--surface)); }
.heat i.l-4 { background: var(--expense); }
.heat i.l--1 { background: transparent; }
.legend { display: flex; gap: 4px; align-items: center; font-size: .75rem; color: var(--muted); margin-top: 10px; }
.legend i { width: 13px; height: 13px; border-radius: 3px; background: var(--line); display: inline-block; }

/* ledger rows */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: .82rem; padding: 0 10px 8px; border-bottom: 2px solid var(--ink); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table td.r, .table th.r { text-align: right; }
.table tr:hover td { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.table-scroll { overflow-x: auto; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; flex: none; }
.pill { font-size: .72rem; padding: 1px 8px; border-radius: 999px; background: var(--info-bg); color: var(--muted); margin-left: 6px; white-space: nowrap; }
.actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.inline { display: inline-flex; gap: 6px; align-items: center; }
.empty { text-align: center; padding: 34px 12px; color: var(--muted); }
.empty a { font-weight: 600; }
.toolbar { display: grid; grid-template-columns: 1.6fr 1fr 1fr .8fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }

/* meters, goals */
.meter { margin-bottom: 14px; }
.meter-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; font-size: .9rem; }
.meter-bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.meter-bar span { display: block; height: 100%; background: var(--income); }
.meter.warn .meter-bar span { background: var(--accent); } .meter.over .meter-bar span { background: var(--expense); }
@media (prefers-reduced-motion: no-preference) { .meter-bar span { transition: width .5s ease; } }
.limit-row { display: grid; grid-template-columns: 1fr auto 170px; gap: 14px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.goals { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; margin-bottom: 18px; }
.goal { display: grid; gap: 14px; }
.goal-top { display: flex; gap: 16px; align-items: center; }
.ring { --p: 0; --c: var(--accent); width: 84px; height: 84px; border-radius: 50%; flex: none; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0); }
.ring span { width: 66px; height: 66px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font: 700 1.05rem var(--font-display); }
.goal form.inline input { max-width: 110px; }

/* auth + misc */
.auth-card { border: 1px solid var(--line); background: var(--surface); padding: 28px; border-radius: 10px; }
.auth-card h1 { margin-bottom: 6px; } .auth-card p { margin: 0 0 20px; }
.narrow { max-width: 540px; }
.danger-zone { border-color: color-mix(in srgb, var(--expense) 55%, var(--line)); }
pre.code { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow-x: auto; font-size: .82rem; }
.error-page { text-align: center; padding: 14vh 0; } .error-page .big { font: 700 5rem var(--font-display); color: var(--accent); line-height: 1; }

/* dialogs: quick add + command palette */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 0; box-shadow: var(--shadow); width: min(460px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(8, 20, 15, .55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.dlg-body { padding: 16px 20px 20px; }
.x { background: none; border: 0; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }
#palette { width: min(540px, calc(100vw - 24px)); margin-top: 12vh; }
#palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 16px 20px; font-size: 1.05rem; background: transparent; }
#palette ul { list-style: none; margin: 0; padding: 8px; max-height: 50vh; overflow-y: auto; }
#palette li button { display: flex; justify-content: space-between; width: 100%; text-align: left; border: 0; background: none; color: inherit; padding: 9px 12px; border-radius: 6px; font: inherit; cursor: pointer; }
#palette li.sel button, #palette li button:hover { background: var(--info-bg); }

@media (max-width: 1000px) { .toolbar { grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px) {
  body.app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; gap: 10px; overflow: visible; }
  .jump { width: auto; gap: 14px; }
  .nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; padding-bottom: 4px; }
  .nav h3 { display: none; } .nav a { white-space: nowrap; }
  .side-foot { margin: 0 0 0 auto; display: flex; align-items: center; gap: 14px; }
  .side-foot strong, .side-foot span { display: none; }
  .strip, .strip.three { grid-template-columns: 1fr 1fr; }
  .strip > div:nth-child(3) { border-left: 0; } .strip > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .grid, .grid.even, .grid.side { grid-template-columns: 1fr; }
  .limit-row { grid-template-columns: 1fr 120px; } .limit-row .muted { display: none; }
}
@media (max-width: 520px) { .toolbar, .row2 { grid-template-columns: 1fr; } }
