:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6ea;
  --text: #0f1216;
  --text-2: #4e5663;
  --text-3: #8a93a0;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --pos: #008300;
  --neg: #e34948;
  --warn: #eda100;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --grid: #eceef1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --radius: 12px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121417;
  --surface: #1a1d21;
  --surface-2: #202429;
  --border: #2c3138;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #868c96;
  --accent: #3987e5;
  --pos: #3fb950;
  --neg: #e66767;
  --warn: #c98500;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #3fb950;
  --series-7: #9085e9;
  --series-8: #e66767;
  --grid: #262a30;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.45; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.05rem; } h3 { font-size: .95rem; color: var(--text-2); }
.muted { color: var(--text-2); } .small { font-size: .8rem; } .mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85em; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.error { color: var(--neg); }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.brand-sub { font-weight: 500; color: var(--text-2); }
.tabs { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.tabs button {
  border: 0; background: transparent; color: var(--text-2); padding: .45rem .65rem; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap;
}
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button.active { background: var(--accent); color: var(--accent-ink); }
.user { display: flex; align-items: center; gap: .6rem; white-space: nowrap; }

main#app { padding: 1.25rem; max-width: 1480px; margin: 0 auto; }
.tab { display: none; } .tab.active { display: block; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: .3rem .6rem; font-size: .8rem; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-google { justify-content: center; width: 100%; padding: .7rem; margin: 1rem 0; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem;
}
input:focus, select:focus { outline: 2px solid color-mix(in oklab, var(--accent) 35%, transparent); border-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .75rem; color: var(--text-2); }
.filters input, .filters select { min-width: 9rem; }
.filters input[type="date"] { min-width: 10.5rem; }
.filters .grow { flex: 1; min-width: 14rem; }

/* Cards */
.grid { display: grid; gap: 1rem; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); margin-bottom: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid.accounts { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); margin-bottom: 1rem; }
.card { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }
.card h2 { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.card h2 .muted { font-weight: 400; font-size: .8rem; }
.kpi .label { font-size: .78rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: clamp(1.05rem, 1.35vw, 1.45rem); font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; margin: .15rem 0; white-space: nowrap; }
.kpi .delta { font-size: .8rem; color: var(--text-2); }
.kpi.hero { grid-column: span 2; }
.kpi.hero .value { font-size: clamp(1.4rem, 2vw, 2rem); }
.account-card { cursor: pointer; transition: border-color .15s; position: relative; }
.account-card:hover { border-color: var(--accent); }
.account-card .name { font-weight: 600; display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.account-card .iban { font-size: .75rem; color: var(--text-3); font-family: ui-monospace, Menlo, monospace; }
.account-card .bal { font-size: 1.35rem; font-weight: 650; margin: .35rem 0 .1rem; font-variant-numeric: tabular-nums; }
.account-card .sub { font-size: .78rem; color: var(--text-2); display: flex; gap: .8rem; flex-wrap: wrap; }
.account-card .spark { position: absolute; right: 1rem; top: 2.4rem; width: 90px; height: 32px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .4rem; vertical-align: -1px; }
.chart-wrap { position: relative; height: 320px; }
.chart-wrap.tall { height: 380px; }
.chart-wrap.short { height: 220px; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .8rem; color: var(--text-2); margin-top: .5rem; }
.legend button { border: 0; background: none; font: inherit; color: inherit; cursor: pointer; display: inline-flex; align-items: center; padding: .1rem .2rem; border-radius: 4px; }
.legend button.off { opacity: .4; text-decoration: line-through; }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text-2); padding: .35rem .7rem; font: inherit; cursor: pointer; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--text-2); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; position: sticky; top: 52px; background: var(--surface); z-index: 1; }
th.sortable { cursor: pointer; } th.sortable:hover { color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
td.purpose { max-width: 520px; color: var(--text-2); word-break: break-word; }
td .cp { font-weight: 500; color: var(--text); }
td .meta { color: var(--text-3); font-size: .75rem; }
.badge { display: inline-block; padding: .05rem .4rem; border-radius: 999px; font-size: .7rem; border: 1px solid var(--border); color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
.badge.warn { border-color: var(--warn); color: var(--warn); }
.badge.pend { border-color: var(--accent); color: var(--accent); }
.badge.int { border-color: var(--series-7); color: var(--series-7); }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: .75rem; flex-wrap: wrap; color: var(--text-2); font-size: .85rem; }
.pager { display: flex; gap: .3rem; align-items: center; }
.bars { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem .75rem; align-items: center; font-size: .85rem; }
.bars .row { display: contents; }
.bars .bar { position: relative; height: 22px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bars .bar span { position: absolute; inset: 0 auto 0 0; background: var(--series-1); border-radius: 4px; opacity: .85; }
.bars .bar.neg span { background: var(--series-2); }
.bars .bar em { position: absolute; left: .5rem; top: 0; line-height: 22px; font-style: normal; color: var(--text); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100% - 1rem); mix-blend-mode: normal; }
.bars .val { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.list-table td:first-child { font-weight: 500; }
.note { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 8px; padding: .6rem .8rem; color: var(--text-2); font-size: .85rem; }
.status-ok { color: var(--pos); } .status-bad { color: var(--neg); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; font-size: .88rem; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 50; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.loading { opacity: .5; pointer-events: none; }
.empty { padding: 2rem; text-align: center; color: var(--text-3); }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem; font-size: .78rem; box-shadow: var(--shadow); z-index: 5; white-space: nowrap; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(420px, 92vw); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2rem; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 1.2rem; }
.test-login { display: flex; gap: .5rem; align-items: end; margin-top: 1rem; }
.test-login label { display: flex; flex-direction: column; gap: .2rem; font-size: .75rem; color: var(--text-2); flex: 1; }

@media (max-width: 1350px) {
  .user span.muted:not(#asof) { display: none; }
  .brand-sub { display: none; }
}
@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; gap: .5rem; padding: .5rem .75rem; }
  .tabs { order: 3; width: 100%; }
  .user span.muted:not(#asof) { display: none; }
  main#app { padding: .75rem; }
  .grid.two { grid-template-columns: 1fr; }
  th { top: 0; position: static; }
  td.purpose { max-width: none; }
  .account-card .spark { display: none; }
}
@media print {
  .topbar, .filters, .toolbar, .table-foot { display: none; }
  body { background: #fff; }
}
