: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); }

/* admin page */
nav a[hidden] { display: none; }
input.w-email { width: 280px; }
input.w-num { width: 70px; }
input.invite-link { flex: 1; min-width: 320px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
/* OAuth consent page (app/oauth.py) and Connected apps */
.login.consent { max-width: 520px; }
.login.consent .warn { background: var(--surface-2, transparent); border-left: 3px solid var(--critical-text); padding: 8px 12px; }
.login.consent ul { padding-left: 20px; }
.connect-url { width: 100%; box-sizing: border-box; font-family: ui-monospace, monospace; }

/* imports from connected apps */
nav a .badge { display: inline-block; min-width: 1.3em; margin-left: .35em; padding: 0 .35em; border-radius: 1em; background: var(--critical); color: #fff; font-size: .75em; line-height: 1.5em; text-align: center; }
.pending-import { border-left: 4px solid var(--warning); }
.pending-import.focus, #import-history .focus { outline: 2px solid var(--accent); }
.pending-import .concerns li { margin: .25em 0; }
.pending-import details { margin: .5em 0 1em; }
.consent-import { display: block; margin: 1em 0 .25em; padding: .6em .8em; border: 1px solid var(--border); border-radius: 6px; }
.consent-import input { margin-right: .4em; }

/* "check this": an opening cash placeholder below zero (registered accounts: stronger) */
.check-this { margin: .3em 0; }
.check-this.strong { border-left: 4px solid var(--neg, #c0392b); padding-left: .6em; font-weight: 600; }

/* public demo */
body.demo .w { display: none !important; }
.demo-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: center; padding: 8px 20px;
  background: var(--accent); color: #fff; font-size: 13px; }
.demo-bar a { color: #fff; text-decoration: underline; }
.demo-bar .btn.primary { background: #fff; color: var(--accent); border-color: #fff; text-decoration: none; }
.demo-actions { display: flex; gap: 12px; align-items: center; }

/* landing page (signed-out visitors) */
.landing-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; max-width: 1100px; margin: 0 auto; }
.landing { max-width: 1100px; margin: 0 auto; padding: 0 24px 64px; }
.landing .hero { text-align: center; padding: 40px 0 24px; }
.landing .hero h1 { font-size: clamp(28px, 4.5vw, 44px); line-height: 1.15; margin: 0 auto 16px; max-width: 18em; letter-spacing: -0.01em; }
.landing .lead { font-size: 18px; color: var(--text-secondary); max-width: 36em; margin: 0 auto 24px; }
.hero-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 32px; }
.btn.big { padding: 10px 22px; font-size: 16px; text-decoration: none; display: inline-block; }
.landing .shot { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08); background: var(--surface-1); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 28px 36px; padding: 40px 0; }
.feature h2 { font-size: 17px; margin-bottom: 6px; }
.feature p, .privacy p { margin: 0; color: var(--text-secondary); font-size: 15px; line-height: 1.55; }
.shots { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; }
.shots figure { margin: 0; }
.shots figcaption { color: var(--text-muted); font-size: 13px; margin-top: 8px; text-align: center; }
.privacy { max-width: 44em; margin: 48px auto 0; }
.closing { text-align: center; margin-top: 48px; display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.closing p { flex-basis: 100%; margin-top: 8px; }
@media (max-width: 600px) {
  .landing-top, .landing { padding-left: 16px; padding-right: 16px; }
  .landing .lead { font-size: 16px; }
  .shots { grid-template-columns: 1fr; }
}
.demo-owner { font-weight: 600; padding: 0 4px; white-space: nowrap; }
.landing-top-right { display: flex; gap: 8px; align-items: center; }
/* landing screenshots: a light and a dark copy of each; show the one matching the theme (same rules as the colours) */
.landing .shot.dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .landing .shot.light { display: none; }
  :root:where(:not([data-theme="light"])) .landing .shot.dark { display: block; }
}
:root[data-theme="dark"] .landing .shot.light { display: none; }
:root[data-theme="dark"] .landing .shot.dark { display: block; }
/* contact form and the privacy policy page */
.landing.doc { max-width: 720px; padding-top: 8px; }
.landing.doc h1 { font-size: 28px; margin: 16px 0 12px; }
.landing.doc h2 { font-size: 18px; margin: 28px 0 8px; }
.landing.doc p, .landing.doc li { font-size: 15px; line-height: 1.6; color: var(--text-secondary); }
.landing.doc strong { color: var(--text-primary); }
.contact-form { display: flex; flex-direction: column; gap: 14px; margin: 20px 0; }
.contact-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.contact-form input, .contact-form select, .contact-form textarea { font-weight: 400; padding: 8px 10px; }
.contact-form button { align-self: flex-start; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
a.brand { color: var(--text-primary); text-decoration: none; }
.landing-footer { text-align: center; padding: 24px; color: var(--text-muted); font-size: 13px; }
.landing-footer a { color: var(--text-muted); margin: 0 8px; }
.msg-body { white-space: pre-wrap; margin: 10px 0 0; }
.menu-links { display: flex; gap: 14px; padding: 8px 12px 4px; border-top: 1px solid var(--border); font-size: 12px; }
.copy-row { display: flex; gap: 8px; max-width: 560px; }
.copy-row .connect-url { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; padding: 8px 10px; }
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  overflow-x: auto; font-size: 13px; white-space: pre-wrap; word-break: break-all; }
.landing.doc ol li, .landing.doc ul li { margin-bottom: 6px; }
.asks li { font-style: italic; }
.ai-band { margin: 8px auto 48px; padding: 28px 32px; max-width: 820px; text-align: center; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 14px; }
.ai-band h2 { font-size: 22px; margin-bottom: 10px; }
.ai-band p { font-size: 16px; line-height: 1.55; color: var(--text-secondary); margin: 0 0 12px; }
.ai-band p.muted { font-size: 14px; color: var(--text-muted); }
.tip-card { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; justify-content: space-between;
  border-color: var(--accent); }
.tip-card .row { margin: 0; }
#dlg h3 { font-size: 14px; margin: 18px 0 6px; }
.drop-hint { margin: 8px 2px 16px; }
