/* Themes: dark is the default; light is picked in the sidebar (stored per browser, see app.js). */
:root {
  --bg: #111418; --panel: #181c21; --panel-2: #1f242a; --border: #2b3139; --text: #e6e9ed; --muted: #95a0ac;
  --accent: #5fb39b; --accent-2: #1c2d29; --danger: #f0776f; --warn: #d6a64a; --ok: #56c271;
  --income: #5fb39b; --expense: #e48a68; --neutral: #6b7582;
  --c1: #5fb39b; --c2: #e48a68; --c3: #7c9fd6; --c4: #d6b45a; --c5: #a98bd1; --c6: #62b6c1; --c7: #d27d9c; --c8: #9bb062;
  --select-bg: #2e6b44; --select-text: #ffffff;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.4);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #ffffff; --panel: #ffffff; --panel-2: #f3f5f4; --border: #d9dedb; --text: #000000; --muted: #4f565d;
  --accent: #1a7f37; --accent-2: #e2f4e6; --danger: #b3261e; --warn: #9a6700; --ok: #1a7f37;
  --income: #1a7f37; --expense: #c2603d; --neutral: #8a94a3;
  --c1: #1a7f37; --c2: #c2603d; --c3: #4a6fa5; --c4: #b58b2a; --c5: #7d5ba6; --c6: #3d8f9a; --c7: #a34d6d; --c8: #6b7d3a;
  --select-bg: #b7e4c2; --select-text: #000000;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
::selection { background: var(--select-bg); color: var(--select-text); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--accent); }
.layout { display: grid; grid-template-columns: 250px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; padding: 4px 6px 8px; color: var(--accent); }
.brand span { color: var(--text); }
.nb-list { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nb-item { text-align: left; background: none; border: 0; color: var(--text); padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit; }
.nb-item:hover { background: var(--panel-2); }
.nb-item.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.nb-item small { display: block; color: var(--muted); font-weight: 400; }
.sidebar-foot { font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 10px; }
.account { border-top: 1px solid var(--border); padding: 10px 0 8px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.account .who { display: flex; align-items: center; gap: 6px; min-width: 0; }
.account .who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .links { display: flex; flex-wrap: wrap; gap: 6px; }
.theme-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.theme-switch button { border: 0; background: transparent; color: var(--muted); padding: 3px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.theme-switch button.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.auth h1 { font-size: 20px; margin: 0; }
.auth .err { color: var(--danger); font-size: 13px; min-height: 1em; }
.auth .auth-links { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.auth .check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.secret { font-family: var(--mono); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; user-select: all; word-break: break-all; }
[hidden] { display: none !important; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); margin-right: 6px; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--danger); } .dot.warn { background: var(--warn); }
.main { overflow: auto; padding: 0 28px 40px; }
.empty-state { max-width: 560px; margin: 18vh auto; text-align: center; color: var(--muted); }
.empty-state h1 { color: var(--text); font-size: 26px; }
header.nb-head { position: sticky; top: 0; background: var(--bg); z-index: 5; padding: 18px 0 0; }
.nb-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.nb-title h1 { font-size: 22px; margin: 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-top: 12px; overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; cursor: pointer; color: var(--muted); font: inherit; font-weight: 550; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.view { padding-top: 18px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 650; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.pos { color: var(--income); } .neg { color: var(--expense); }
.btn { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 550; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; }
textarea { width: 100%; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:hover td { background: var(--panel-2); }
.table-wrap { overflow: auto; max-height: 65vh; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); } .pill.err { color: var(--danger); } .pill.run { color: var(--warn); }
.pill.accent { background: var(--accent-2); color: var(--accent); }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; background: var(--panel); }
.dropzone.over { border-color: var(--accent); background: var(--accent-2); color: var(--accent); }
.chat { display: grid; grid-template-rows: 1fr auto; height: calc(100vh - 150px); gap: 12px; }
.messages { overflow: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 6px; }
.msg { max-width: 860px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; padding: 9px 14px; border-radius: 14px 14px 4px 14px; }
.msg.assistant { background: var(--panel); border: 1px solid var(--border); padding: 12px 16px; border-radius: 4px 14px 14px 14px; }
.msg .status { color: var(--muted); font-size: 12px; font-style: italic; }
.cites { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.cite { cursor: pointer; border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 12px; background: var(--panel-2); color: var(--text); }
.cite-ref { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .85em; vertical-align: super; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 46px; max-height: 200px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.suggestions button { font-size: 12px; }
.md h1, .md h2, .md h3 { margin: 14px 0 6px; line-height: 1.3; } .md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15px; }
.md p { margin: 6px 0; } .md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md table { margin: 8px 0; font-size: 13px; } .md code { font-family: var(--mono); font-size: 12px; background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.md > :first-child { margin-top: 0; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .axis line, .chart .grid line { stroke: var(--border); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 34%) 1fr 90px; gap: 8px; align-items: center; font-size: 13px; padding: 3px 0; }
.hbar .track { background: var(--panel-2); border-radius: 4px; height: 12px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--c2); border-radius: 4px; }
.hbar .v { text-align: right; font-variant-numeric: tabular-nums; }
.report-list { display: flex; flex-direction: column; gap: 6px; }
.report-item { text-align: left; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 10px; cursor: pointer; font: inherit; color: var(--text); }
.report-item.active { border-color: var(--accent); background: var(--accent-2); }
.report-item.pending { cursor: default; border-style: dashed; }
.report-item .status { color: var(--warn); font-style: italic; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; max-width: 420px; }
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); padding: 20px; min-width: 380px; max-width: min(820px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.snippet { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; background: var(--panel-2); padding: 12px; border-radius: 8px; max-height: 50vh; overflow: auto; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; font-size: 12px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.inline-select { padding: 2px 4px; font-size: 12px; max-width: 170px; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } .sidebar { display: none; } .main { padding: 0 14px 30px; } .g2 { grid-template-columns: 1fr; } }
@media print {
  .sidebar, .tabs, .no-print, header.nb-head .row { display: none !important; }
  .layout { display: block; } .main { overflow: visible; padding: 0; } .card { box-shadow: none; break-inside: avoid; }
}

/* Sidebar: notebooks grouped by section (Budget & Expenses / Investments / Tax) */
.nb-group { margin-bottom: 14px; }
.nb-group-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.nb-group-head .btn { padding: 0 8px; line-height: 20px; }
.nb-empty { padding: 2px 10px 4px; }
.upload-guide { margin-top: 12px; }
.upload-guide ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.upload-guide li { margin: 3px 0; }
.tab-sep { width: 1px; background: var(--border); margin: 6px 6px; flex: none; }
details { border-top: 1px solid var(--border); padding: 8px 0; }
details > summary { cursor: pointer; padding: 2px 0; }
details table td { vertical-align: top; }
