/* Our Future — mobile first; sidebar layout from 900px. Light & dark themes. */
:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76746e;
  --line: #e1e0d9;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --good: #006300;
  --good-bg: #e3f3e3;
  --warn: #8a5a00;
  --warn-bg: #fdf1d6;
  --critical: #d03b3b;
  --critical-bg: #fbe5e5;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
  --tabbar: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --text: #f0efec; --text-2: #c3c2b7; --muted: #9a988f;
    --line: #2c2c2a; --accent: #3987e5; --accent-soft: #14243a; --good: #3ccb3c; --good-bg: #12280f; --warn: #fab219; --warn-bg: #2d2210;
    --critical: #e66767; --critical-bg: #331616; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --grid: #2c2c2a; --axis: #383835;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --text: #f0efec; --text-2: #c3c2b7; --muted: #9a988f;
  --line: #2c2c2a; --accent: #3987e5; --accent-soft: #14243a; --good: #3ccb3c; --good-bg: #12280f; --warn: #fab219; --warn-bg: #2d2210;
  --critical: #e66767; --critical-bg: #331616; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --grid: #2c2c2a; --axis: #383835;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; } h2 { font-size: 17px; } h3 { font-size: 16px; }
p { margin: 8px 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small, small { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; display: block; }
.hint.info { color: var(--text-2); background: var(--accent-soft); padding: 8px 10px; border-radius: 8px; }
.center { text-align: center; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg, .money.neg { color: var(--critical); }

/* Layout */
.app { min-height: 100vh; }
.content { padding: 12px 16px calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.sidebar { display: none; }
.tabbar {
  position: fixed; inset: auto 0 0 0; height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); z-index: 20;
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 12px; }
.tabbar a.on { color: var(--accent); font-weight: 600; }
@media (min-width: 900px) {
  .app:not(.setup) { display: grid; grid-template-columns: 220px 1fr; }
  .tabbar { display: none; }
  .content { padding-bottom: 40px; width: 100%; }
  .sidebar { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 0; height: 100vh; padding: 20px 12px; background: var(--surface); border-right: 1px solid var(--line); }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text-2); text-decoration: none; }
  .sidebar nav a:hover { background: var(--surface-2); }
  .sidebar nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; margin: 24px 0 16px; }
.brand.small { flex-direction: row; margin: 0 8px; font-weight: 700; text-align: left; }
.brand img { border-radius: 12px; }

/* Cards & grids */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; margin: 0 0 12px; display: block; }
.grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); margin-bottom: 12px; }
.grid > .card { margin: 0; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.section-title { margin: 20px 4px 10px; font-size: 15px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.link-card { color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 4px; }
.link-card:hover { border-color: var(--accent); }
.big { font-size: 26px; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.pad { padding: 4px 0; }

.hero .hero-label { color: var(--text-2); font-size: 14px; }
.hero .hero-value { font-size: 40px; font-weight: 750; letter-spacing: -.02em; margin: 2px 0 10px; }
.rows { display: flex; flex-direction: column; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row.strong { font-weight: 650; }

.payday { border-top: 4px solid var(--c); }
.payday header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.send { background: var(--accent-soft); border-radius: 10px; margin: 0 0 10px; }
.send summary { display: flex; justify-content: space-between; align-items: center; padding: 12px; cursor: pointer; font-size: 17px; list-style: none; }
.send summary::-webkit-details-marker { display: none; }
.send summary::after { content: '▾'; margin-left: 8px; color: var(--muted); }
.send summary > span::before { content: '→ '; }
.send ul { margin: 0; padding: 0 12px 4px; list-style: none; }
.send li { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; border-top: 1px solid var(--line); }
.send .hint { padding: 0 12px 10px; margin: 0; }

/* Month bar & banners */
.monthbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; margin-bottom: 12px; position: sticky; top: 0; z-index: 10; }
.month-name { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 8px; text-align: center; }
.month-name strong { font-size: 17px; }
.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; margin: 0 0 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 550; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--critical); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn.add { width: 100%; border-style: dashed; color: var(--accent); margin-top: 8px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; font-size: 16px; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; font-size: 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Lists */
.list-card { padding: 12px 12px 12px; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 4px 8px; }
.group-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; padding: 12px 4px 4px; border-bottom: 1px solid var(--line); }
.lines { list-style: none; margin: 0; padding: 0; }
.line { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line-main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px 4px; background: none; border: 0; text-align: left; cursor: pointer; }
.line-main:disabled { cursor: default; opacity: 1; }
.line-main.static { flex-direction: row; align-items: center; gap: 10px; cursor: default; }
.line-name { font-weight: 550; }
.line-meta { display: flex; flex-wrap: wrap; gap: 4px; }
.amount { display: flex; flex-direction: column; align-items: flex-end; padding: 8px 6px; font-weight: 600; border-radius: 8px; border: 0; background: none; min-height: 44px; justify-content: center; }
.amount.editable { cursor: pointer; border: 1px solid transparent; }
.amount.editable:hover { border-color: var(--line); background: var(--surface-2); }
.delta { font-weight: 500; font-size: 11px; }
.delta.up { color: var(--critical); } .delta.down { color: var(--good); }
.tag { --c: var(--muted); display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.tag .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tag.plain { background: transparent; border: 1px solid var(--line); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin: 0 0 8px; flex-wrap: wrap; }

.status { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.status.good { color: var(--good); background: var(--good-bg); }
.status.warn { color: var(--warn); background: var(--warn-bg); }
.status.bad { color: var(--critical); background: var(--critical-bg); }

/* Debts & goals */
.debt header, .goal header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stats div { display: flex; flex-direction: column; gap: 2px; font-size: 15px; }
.stats .muted { font-size: 12px; }
.whatif { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.whatif summary { cursor: pointer; color: var(--accent); font-weight: 550; padding: 6px 0; }
.slider { display: block; margin: 8px 0; }
.slider input { width: 100%; margin-top: 8px; accent-color: var(--accent); height: 32px; }
.bar { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 8px 0; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* Forms & modal */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--surface); width: 100%; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 640px) { .backdrop { align-items: center; } .modal { max-width: 520px; border-radius: 18px; } }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 12px 8px 4px 16px; position: sticky; top: 0; background: var(--surface); }
.modal-body { padding: 4px 16px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; border: 0; padding: 0; min-width: 0; }
.label { font-size: 14px; font-weight: 600; color: var(--text-2); }
input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.money-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding-left: 12px; background: var(--surface); }
.money-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.money-input span { color: var(--muted); }
.money-input input { border: 0 !important; box-shadow: none !important; font-size: 18px !important; font-variant-numeric: tabular-nums; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .two { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented label { flex: 1; text-align: center; white-space: nowrap; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; min-height: 38px; display: flex; align-items: center; justify-content: center; }
.segmented label.on { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; color: var(--accent); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.danger-actions { margin-right: auto; display: flex; flex-wrap: wrap; gap: 4px; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); }
form.inline { display: flex; gap: 8px; align-items: flex-end; }
form.inline .field { flex: 1; margin: 0; }
.swatches { display: flex; gap: 10px; }
.swatches label { cursor: pointer; }
.swatches input { position: absolute; opacity: 0; }
.swatches i { display: block; width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.swatches input:checked + i { box-shadow: 0 0 0 3px var(--text); }
.code { font-size: 28px; font-weight: 700; letter-spacing: .15em; font-family: ui-monospace, monospace; }

/* Upcoming */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline .day { font-weight: 700; color: var(--text-2); margin: 16px 4px 6px; }
.timeline .event { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 6px; }

/* History & charts */
.chart { margin: 0; position: relative; min-width: 0; overflow: hidden; }
.chart figcaption { font-weight: 650; margin-bottom: 6px; }
.chart-wrap { position: relative; }
.chart svg { display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .ring { stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.legend i, .tooltip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tooltip { position: absolute; top: 4px; width: 160px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0, 0, 0, .15); border-radius: 10px; padding: 8px 10px; font-size: 13px; pointer-events: none; }
.tooltip div { display: flex; align-items: center; } .tooltip span { margin-left: auto; font-weight: 600; }
.table-scroll { overflow-x: auto; margin: 8px -16px 0; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
tbody th, thead th:first-child { text-align: left; }
tbody tr { cursor: pointer; } tbody tr:hover { background: var(--surface-2); } tr.current { background: var(--accent-soft); }

/* Setup, auth, misc */
.wizard { max-width: 640px; margin: 0 auto; }
.wizard h1 { margin: 8px 0 4px; }
.steps { display: flex; gap: 6px; margin: 8px 0 12px; padding-top: env(safe-area-inset-top); }
.steps span { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: var(--surface-2); color: var(--muted); }
.steps span.on { background: var(--accent); color: var(--accent-ink); }
.auth { max-width: 420px; margin: 0 auto; padding: 16px; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 12px; }
.auth .card h2 { margin-bottom: 12px; }
.more { display: flex; flex-direction: column; }
.loading { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); padding: 16px; text-align: center; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 14px; max-width: calc(100% - 32px); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
