.viz-root {
  color-scheme: light;
  --page: #f9f9f9;
  --surface-1: #ffffff;
  --text-primary: #191919;
  --text-secondary: #666666;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #257de0;
  --series-2: #f47230;
  --good-text: #006c10;
  --critical: #dc3c3d;
  --warning: #fbb315;
  --hover: rgba(11, 11, 11, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface-1: #191919;
    --text-primary: #efefef;
    --text-secondary: #9c9c9c;
    --grid: #303030;
    --axis: #474747;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #338ced;
    --series-2: #e76624;
    --good-text: #53c556;
    --hover: rgba(255, 255, 255, 0.06);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px; }
.viz-root { background: var(--page); color: var(--text-primary); min-height: 100vh; padding: 20px 24px 40px; }

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary); }
.live { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 13px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--axis); }
.live.on .dot { background: #0aac23; box-shadow: 0 0 0 0 rgba(10, 172, 35, .5); animation: pulse 2s infinite; }
.live.syncing .dot { background: var(--series-1); }
.live.flash { color: var(--text-primary); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(10,172,35,.45); } 70% { box-shadow: 0 0 0 8px rgba(10,172,35,0); } 100% { box-shadow: 0 0 0 0 rgba(10,172,35,0); } }
@media (prefers-reduced-motion: reduce) { .live.on .dot { animation: none; } }
.actions { margin-left: auto; display: flex; gap: 8px; }

button, select, input {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px;
}
button { cursor: pointer; }
button:hover { background: var(--hover); }
button.primary { background: var(--text-primary); color: var(--surface-1); border-color: transparent; }
button.primary:hover { opacity: .88; }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

/* ---- alerts ---- */
.alert { display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin-bottom: 12px; border-radius: 10px;
  background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--critical); }
.alert.info { border-left-color: var(--series-1); }
.alert .msg { flex: 1; }
.alert .icon { font-weight: 700; color: var(--critical); }
.alert.info .icon { color: var(--series-1); }

/* ---- filters ---- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--text-primary); color: var(--surface-1); }

/* ---- KPI tiles ---- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile, .card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; }
.tile { padding: 14px 16px; }
.tile .label { color: var(--text-secondary); font-size: 13px; }
.tile .value { font-size: 28px; font-weight: 650; margin: 4px 0 2px; letter-spacing: -0.01em; }
.tile .sub { color: var(--text-secondary); font-size: 12px; min-height: 16px; }
.pos { color: var(--good-text); }
.neg { color: var(--critical); }

/* ---- cards ---- */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.card { padding: 16px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.head-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.hint { margin: 3px 0 0; color: var(--text-secondary); font-size: 12px; }
.legend { display: flex; gap: 14px; color: var(--text-secondary); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-size: 11px; fill: var(--text-secondary); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover, .chart .hit.active { fill: var(--hover); }
.chart .lbl { fill: var(--text-primary); }
.empty { color: var(--text-secondary); padding: 28px 0; text-align: center; }

/* ---- tables ---- */
.table-wrap { overflow: auto; }
.table-wrap.tall { max-height: 520px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface-1); }
td.num, th.num { text-align: right; }
td.muted { color: var(--text-secondary); }
td.desc { white-space: normal; min-width: 180px; }
tr.new td { animation: newrow 3s ease-out; }
@keyframes newrow { from { background: color-mix(in srgb, var(--series-1) 18%, transparent); } to { background: transparent; } }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary); margin-left: 6px; }
.chip { font-size: 12px; padding: 4px 6px 4px 10px; border-radius: 999px; background: var(--hover); display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; padding: 0 4px; background: transparent; }
#search { width: 260px; }

/* ---- accounts ---- */
.accounts { display: flex; flex-direction: column; gap: 2px; }
.acct { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--grid); gap: 10px; }
.acct:last-child { border-bottom: 0; }
.acct .name { font-weight: 500; }
.acct .meta { color: var(--text-secondary); font-size: 12px; }
.acct .bal { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.inst { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--text-secondary); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.inst:first-child { margin-top: 0; }
.inst button { text-transform: none; letter-spacing: 0; }
.acct-total { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--axis); font-weight: 600; }

.user { color: var(--text-secondary); font-size: 13px; align-self: center; margin-left: 8px; }

/* ---- sign-in page ---- */
.auth-page { display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; }
.auth-card h1 { font-size: 22px; }
.auth-sub { margin: 6px 0 18px; font-size: 13px; }
.auth-tabs { display: flex; margin-bottom: 18px; }
.auth-tabs button { flex: 1; }
.auth-card form { display: flex; flex-direction: column; gap: 6px; }
.auth-card label { font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
.auth-card input { width: 100%; }
.auth-card .hint { margin: 2px 0 0; }
.form-error { color: var(--critical); font-size: 13px; margin: 8px 0 0; }
.form-note { font-size: 13px; margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; background: var(--hover); }
.auth-foot { text-align: center; margin-top: 16px; }
.auth-foot a, .auth-card a { color: var(--text-primary); }
.wide-btn + .wide-btn { margin-top: 8px; }
.wide-btn { width: 100%; margin-top: 14px; padding: 10px; }

/* ---- tooltip ---- */
.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  font-variant-numeric: tabular-nums; min-width: 150px; }
.tooltip .t { font-weight: 600; margin-bottom: 4px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 14px; color: var(--text-secondary); }
.tooltip .r b { color: var(--text-primary); font-weight: 600; }
.tooltip .r i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

@media (max-width: 1000px) {
  .grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actions { margin-left: 0; }
}
