:root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --grid: #e9e8e4;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --series-1: #2a78d6;   /* blue  */
  --series-2: #eb6834;   /* orange */
  --series-3: #1baf7a; --series-4: #eda100; --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --pos: #2a78d6;        /* diverging: blue pole */
  --neg: #e34948;        /* diverging: red pole */
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b;
  --good-text: #006300; --critical-text: #b42a2a;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #262624; --border: #33332f; --grid: #2b2b28;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
    --series-1: #3987e5; --series-2: #d95926;
    --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --pos: #3987e5; --neg: #e66767;
    --good-text: #4cc44c; --critical-text: #ef7a7a; --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #262624; --border: #33332f; --grid: #2b2b28;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
  --series-1: #3987e5; --series-2: #d95926;
--series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --pos: #3987e5; --neg: #e66767;
  --good-text: #4cc44c; --critical-text: #ef7a7a; --accent: #3987e5;
}

* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
       background: var(--surface-0); color: var(--text-primary); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--surface-1);
       border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: var(--text-secondary); padding: 6px 10px; border-radius: 6px; }
nav a.on { background: var(--surface-2); color: var(--text-primary); font-weight: 600; text-decoration: none; }
.top-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
select, input, textarea { font: inherit; color: inherit; background: var(--surface-1); border: 1px solid var(--border);
       border-radius: 6px; padding: 5px 8px; }
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
       border-radius: 6px; padding: 5px 12px; cursor: pointer; }
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.status { padding: 0 20px; color: var(--text-secondary); font-size: 12px; min-height: 18px; }
main { padding: 8px 20px 40px; max-width: 1500px; margin: 0 auto; }
h1 { font-size: 20px; margin: 12px 0 14px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--text-muted); }
.sec { color: var(--text-secondary); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 2fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1000px) { .g2, .g3 { grid-template-columns: 1fr; } }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--text-secondary); }
.tile .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .s { font-size: 12px; color: var(--text-muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: var(--surface-1); color: var(--text-secondary); padding: 4px 10px; cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--text-secondary); background: var(--surface-1); cursor: pointer; }
td.n, th.n { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.sub td { color: var(--text-secondary); font-weight: 600; background: var(--surface-2); }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
.wrap { overflow-x: auto; }
.pos { color: var(--good-text); }
.neg { color: var(--critical-text); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--surface-2); color: var(--text-secondary); }
.tag.warn::before { content: "⚠ "; }
.tag.ok::before { content: "✓ "; color: var(--good-text); }
.note { font-size: 12px; color: var(--text-secondary); white-space: normal; overflow: hidden; display: -webkit-box;
        -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-width: 120px; overflow-wrap: anywhere; }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--text-muted); stroke-width: 1; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin: 0 0 8px; }
.legend .key { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; }
.legend .key.box { height: 10px; width: 10px; border-radius: 2px; }
.tooltip { position: fixed; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
           border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 20; }
.tooltip .t { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .r { display: flex; align-items: center; gap: 6px; }
.tooltip .r b { font-variant-numeric: tabular-nums; }
.tooltip .r .ln { width: 12px; height: 2px; display: inline-block; }
.drop { border: 2px dashed var(--border); border-radius: 10px; padding: 40px; text-align: center; color: var(--text-secondary); }
.drop.over { border-color: var(--accent); background: var(--surface-2); }
dialog { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-1); color: var(--text-primary); min-width: 460px; }
dialog form label { display: grid; grid-template-columns: 130px 1fr; gap: 8px; align-items: center; margin-bottom: 8px; }
.bar-pos { fill: var(--pos); } .bar-neg { fill: var(--neg); }
.bar-pos:hover, .bar-neg:hover { opacity: .8; }
details summary { cursor: pointer; color: var(--text-secondary); }
/* ---------------------------------------------------------------- assistant panel */
.chat { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); z-index: 15; display: flex; flex-direction: column;
        background: var(--surface-1); border-left: 1px solid var(--border); box-shadow: -8px 0 24px rgba(0,0,0,.06); }
.chat[hidden] { display: none; }
body.chat-open main { margin-right: min(520px, 100vw); }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chat-head .title { font-weight: 650; flex: 1; }
.chat-head select { font: inherit; font-size: 12px; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }
.msg { line-height: 1.45; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 85%; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; white-space: pre-wrap; }
.msg.bot p { margin: 0 0 8px; } .msg.bot p:last-child { margin-bottom: 0; }
.msg.bot ul, .msg.bot ol { margin: 0 0 8px; padding-left: 20px; }
.msg.bot h3, .msg.bot h4 { font-size: 14px; margin: 10px 0 6px; }
.msg.bot table { width: auto; margin: 4px 0 8px; font-size: 13px; }
.msg.bot th { cursor: default; }
.msg.bot code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.msg.err { color: var(--critical-text); }
.msg .tools { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.msg .meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.typing::after { content: "…"; animation: blink 1s steps(2) infinite; } @keyframes blink { 50% { opacity: 0; } }
.chat-input { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { flex: 1; font: inherit; resize: none; min-height: 38px; max-height: 160px; padding: 8px; border-radius: 8px;
                       border: 1px solid var(--border); background: var(--surface-0); color: var(--text-primary); }
.chat-foot { font-size: 11px; color: var(--text-muted); padding: 0 12px 8px; }
.chat-setup { padding: 16px; display: flex; flex-direction: column; gap: 12px; line-height: 1.45; }
.chat-setup input, .chat-setup select { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
                                         background: var(--surface-0); color: var(--text-primary); }
.chat-setup .notice { font-size: 12px; color: var(--text-secondary); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.suggest { display: flex; flex-direction: column; gap: 6px; }
.suggest button { text-align: left; font: inherit; font-size: 13px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
                  background: var(--surface-1); color: var(--text-secondary); cursor: pointer; }
.suggest button:hover { background: var(--surface-2); color: var(--text-primary); }

/* search boxes on long tables */
.tsearch { min-width: 260px; }
.legend { flex-wrap: wrap; }
.legend .key.dash { background: none; height: 0; border-top: 2px dashed; }
/* cash tile */
.tile.cash .seg { margin-top: 6px; }
.tile .v .cur { font-size: 12px; font-weight: 400; color: var(--text-muted); }
.tile .v.two { font-size: 18px; line-height: 1.3; }
.tile label.s { display: block; margin-top: 2px; cursor: pointer; }
.seg.tiny button { padding: 1px 6px; font-size: 11px; }
label.check { display: flex; gap: 8px; align-items: center; }
details.card > summary { cursor: pointer; margin-bottom: 8px; }
dialog { max-width: 620px; }
dialog form label > div { min-width: 0; }
dialog form details { margin: 4px 0 8px; }
dialog form details summary { cursor: pointer; margin-bottom: 8px; }
.small { font-size: 12px; margin-top: 3px; }
.row.tight { margin: 0; gap: 6px; flex-wrap: nowrap; }
dialog form label > div > input:not([type=checkbox]), dialog form label > div > select { width: 100%; box-sizing: border-box; }
dialog form .fixed { padding: 6px 0; font-weight: 600; }
select.btn.primary option { background: var(--surface-1); color: var(--text-primary); }

/* tags: clickable where they filter or navigate */
.filterable .tag, .tag.act { cursor: pointer; }
.filterable .tag:hover, .tag.act:hover { background: var(--border); color: var(--text-primary); }
.filterable .tag[data-nofilter] { cursor: default; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 4px 2px 10px; border-radius: 12px;
        background: var(--surface-2); border: 1px solid var(--border); }
.chip button { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 0 4px; }
.chip button:hover { color: var(--text-primary); }
.notice-card { border-left: 3px solid var(--accent); }
.notice-card h2 { margin-top: 0; }
.why { font-size: 12px; color: var(--text-secondary); display: inline-block; min-width: 280px; max-width: 380px; white-space: normal; }
.acts { display: inline-flex; gap: 6px; white-space: nowrap; }
.card.rec .issue { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 8px 0; border-top: 1px solid var(--grid); }
.card.rec .issue.carried { color: var(--text-muted); }

/* tables fit their card: long text wraps (see .note), low-priority columns hide (see table() in app.js) */
.hidden-cols { padding: 6px 8px 0; }
.hidden-cols:empty { display: none; }
th { white-space: normal; }

.acct-table td { padding: 4px 6px; }
.acct-table input, .acct-table select { font-size: 13px; }
dialog:has(.acct-table) { max-width: 1000px; }
.newsec { border-left: 3px solid var(--border); padding-left: 10px; margin: 0 0 8px; }

/* sign-in page */
.login { max-width: 420px; margin: 12vh auto; padding: 32px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; }
.login h1 { margin-top: 0; }
.login-buttons { display: flex; flex-direction: column; gap: 10px; margin: 20px 0; }
.login-btn { text-align: center; padding: 10px 14px; text-decoration: none; }
.user-menu { position: relative; }
.user-menu .menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px; min-width: 220px; z-index: 20; box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.user-menu .menu button, .user-menu .menu a { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px;
  border-radius: 6px; color: var(--text-primary); font: inherit; cursor: pointer; }
.user-menu .menu button:hover, .user-menu .menu a:hover { background: var(--surface-2); text-decoration: none; }
.user-menu .menu .who { padding: 7px 10px; font-size: 12px; color: var(--text-secondary); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.btn.danger, .user-menu .menu button.danger { color: var(--critical-text); }
