:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --surface-3: #e9e8e4;
  --border: #e3e2de;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #8a8984;
  --grid: #e8e7e3;
  --accent: #2a78d6;
  --accent-soft: #e7f0fc;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #7a6fe0;
  --series-other: #a3a29d;
  --good: #1a7f37;
  --warning: #b26a00;
  --critical: #c93434;
  --good-bg: #e3f4e8;
  --warning-bg: #fdf0d9;
  --critical-bg: #fbe4e4;
  --neutral-bg: #ecebe7;
  --shadow: 0 10px 30px rgba(20, 24, 32, .08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --surface-3: #2b2b28;
    --border: #2f2f2c;
    --text-primary: #fff;
    --text-secondary: #c3c2b7;
    --text-muted: #8d8c84;
    --grid: #2a2a27;
    --accent: #3987e5;
    --accent-soft: #1b2b41;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #8d82ef;
    --series-other: #6b6a64;
    --good: #4cc26a;
    --warning: #e0a030;
    --critical: #ef6b6b;
    --good-bg: #1c3123;
    --warning-bg: #3a2c12;
    --critical-bg: #3d1d1d;
    --neutral-bg: #2a2a27;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2b2b28;
  --border: #2f2f2c;
  --text-primary: #fff;
  --text-secondary: #c3c2b7;
  --text-muted: #8d8c84;
  --grid: #2a2a27;
  --accent: #3987e5;
  --accent-soft: #1b2b41;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #8d82ef;
  --series-other: #6b6a64;
  --good: #4cc26a;
  --warning: #e0a030;
  --critical: #ef6b6b;
  --good-bg: #1c3123;
  --warning-bg: #3a2c12;
  --critical-bg: #3d1d1d;
  --neutral-bg: #2a2a27;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.small, .updated, .timing { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 11px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 750; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; }
.brand span { color: var(--text-muted); font-weight: 500; }
.tabs { display: flex; gap: 3px; flex-wrap: wrap; }
.tabs button {
  padding: 6px 11px; border: 0; border-radius: 7px; background: transparent;
  color: var(--text-secondary); cursor: pointer;
}
.tabs button:hover { background: var(--surface-2); }
.tabs button.active { background: var(--surface-2); color: var(--text-primary); font-weight: 650; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.updated { color: var(--text-muted); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.updated .dot { color: var(--good); }

/* ---------- filters ---------- */
.filters {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 11px 24px; border-bottom: 1px solid var(--border); background: var(--surface-1);
}
.presets { display: flex; gap: 3px; }
.presets button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 650; }
.days-input { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.days-input input { width: 76px; }
.tz-note {
  margin-left: auto; font-size: 12px; color: var(--text-secondary);
  background: var(--surface-2); border-radius: 6px; padding: 4px 8px;
}

/* ---------- controls ---------- */
input, select, button {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 9px;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button { cursor: pointer; transition: background .12s ease, border-color .12s ease; }
button:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.danger { color: var(--critical); }
button.icon { border: 0; background: transparent; font-size: 17px; color: var(--text-secondary); padding: 4px 7px; }
code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px;
  background: var(--surface-2); padding: 1px 4px; border-radius: 4px;
}

/* ---------- layout ---------- */
main { padding: 20px 24px 64px; max-width: 1680px; margin: 0 auto; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 650; color: var(--text-secondary); }
.section { margin-bottom: 22px; }
.section-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.section-head h2 { margin: 0; }
.meta-line { color: var(--text-secondary); font-size: 12.5px; }
.meta-line b { color: var(--text-primary); font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 11px;
  padding: 12px 14px; min-width: 0;
}
.kpi .label { color: var(--text-secondary); font-size: 12px; }
.kpi .value { font-size: 24px; line-height: 1.18; font-weight: 700; margin: 3px 0 2px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .value.sm { font-size: 20px; }
.kpi .sub { color: var(--text-muted); font-size: 12px; min-height: 17px; }
.kpi .sub b { color: var(--text-secondary); font-weight: 600; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(390px, 1fr)); margin-bottom: 16px; }
.grid.one { grid-template-columns: 1fr; }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 11px;
  padding: 14px 16px; min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card-sub { color: var(--text-muted); font-size: 12px; }

/* ---------- bars ---------- */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { min-width: 0; }
.bar-label { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; font-size: 12.5px; }
.bar-label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-label .num { white-space: nowrap; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.bar-track { height: 9px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; min-width: 1px; transition: width .25s ease; }
.bars.compact { gap: 7px; }
.bars.compact .bar-track { height: 7px; }

/* ---------- donut ---------- */
.donut-wrap { display: grid; grid-template-columns: 158px 1fr; gap: 18px; align-items: center; }
.donut {
  width: 158px; height: 158px; border-radius: 50%; position: relative;
  box-shadow: inset 0 0 0 1px var(--border);
}
.donut-hole {
  position: absolute; inset: 34px; border-radius: 50%; background: var(--surface-1);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 0 0 1px var(--border);
}
.donut-hole b { font-size: 17px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.donut-hole span { font-size: 11px; color: var(--text-muted); }
.donut-legend { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.donut-legend .item { display: flex; align-items: center; gap: 8px; min-width: 0; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.donut-legend .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.donut-legend .val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.donut-legend .share { color: var(--text-muted); width: 52px; text-align: right; white-space: nowrap; }

/* ---------- token stack ---------- */
.token-stack { display: flex; height: 16px; border-radius: 5px; overflow: hidden; background: var(--surface-2); margin: 4px 0 12px; }
.token-stack > span { height: 100%; min-width: 0; }
.token-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 8px 14px; }
.token-legend .item { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 12.5px; }
.token-legend i { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.token-legend .name { color: var(--text-secondary); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.token-legend .val { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- window progress ---------- */
.win { min-width: 120px; }
.win-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12px; margin-bottom: 3px; }
.win-head .pct { font-weight: 650; font-variant-numeric: tabular-nums; }
.win-head .pct.good { color: var(--good); }
.win-head .pct.warning { color: var(--warning); }
.win-head .pct.critical { color: var(--critical); }
.win-head .basis { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.progress { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; border-radius: 4px; background: var(--series-1); }
.progress > div.warning { background: var(--warning); }
.progress > div.critical { background: var(--critical); }
.progress > div.good { background: var(--good); }

/* ---------- tables ---------- */
.table-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.table-tools input[type=search] { min-width: 250px; }
.table-tools select { max-width: 260px; }
.table-tools .count { margin-left: auto; }
.table-wrap { overflow: auto; max-height: 74vh; border: 1px solid var(--border); border-radius: 9px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-weight: 650;
  font-size: 12px; color: var(--text-secondary); cursor: pointer; user-select: none;
}
th:hover { color: var(--text-primary); }
th.sorted::after { content: " ▾"; color: var(--accent); }
th.sorted.asc::after { content: " ▴"; }
td.num, th.num { text-align: right; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tbody tr.muted-row td { color: var(--text-muted); }
tbody tr.error-row td { background: var(--critical-bg); }
tr.total-row td { font-weight: 650; border-top: 2px solid var(--border); }
.more { margin-top: 8px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 10px;
  font-size: 12px; line-height: 1.5; background: var(--neutral-bg); color: var(--text-secondary);
  white-space: nowrap;
}
.badge + .badge { margin-left: 4px; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }
.badge.critical { background: var(--critical-bg); color: var(--critical); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 11px; }
.account-name { font-weight: 600; }
.account-id { color: var(--text-muted); font-size: 11px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* ---------- notices / errors ---------- */
.notice { padding: 11px 14px; border-radius: 9px; background: var(--warning-bg); color: var(--text-primary); margin-bottom: 14px; }
.notice.info { background: var(--accent-soft); }
.notice b { font-weight: 650; }
.error-card { border: 1px solid var(--critical); background: var(--critical-bg); border-radius: 10px; padding: 14px 16px; color: var(--text-primary); }
.error-card .error-title { font-weight: 650; color: var(--critical); font-size: 15px; margin-bottom: 4px; }
.error-card .error-hint { margin-top: 8px; color: var(--text-secondary); }
.error-card .error-hint::before { content: "Что проверить: "; font-weight: 650; color: var(--text-primary); }
.error-card .error-meta { margin-top: 8px; font-size: 12px; color: var(--text-muted); }
.error-card details { margin-top: 8px; font-size: 12px; }
.error-card summary { cursor: pointer; color: var(--text-secondary); }
.error-card pre { white-space: pre-wrap; word-break: break-word; background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; padding: 8px; max-height: 240px; overflow: auto; }
.error-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.error { padding: 10px 12px; border-radius: 8px; background: var(--critical-bg); color: var(--critical); white-space: pre-wrap; }
.loading { color: var(--text-muted); padding: 48px 0; text-align: center; }
.empty { color: var(--text-muted); padding: 24px 0; text-align: center; }

/* ---------- details dialog ---------- */
.details-dialog {
  width: min(680px, calc(100vw - 28px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow);
}
.details-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 13px 18px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; }
.dialog-body { padding: 16px 18px 20px; max-height: calc(100vh - 110px); overflow: auto; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; font-size: 13px; margin: 0; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.dialog-section { margin-top: 18px; }
.dialog-section:first-child { margin-top: 0; }
.dialog-section h3 { margin-bottom: 8px; }

/* ---------- login ---------- */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  padding: 20px; background:
    radial-gradient(900px 500px at 20% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}
.login-wrap { width: min(420px, 100%); }
.login-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 26px 26px 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.login-brand { font-size: 19px; }
.login-field { display: flex; flex-direction: column; gap: 6px; color: var(--text-secondary); font-size: 12px; }
.login-field input { font-size: 15px; padding: 8px 10px; }
.login-submit { padding: 8px 12px; font-weight: 650; }
.login-card .error { margin: 0; font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .donut-legend { width: 100%; }
  .tz-note { margin-left: 0; }
}
@media (max-width: 700px) {
  .topbar, .filters { padding: 10px 14px; }
  main { padding: 14px 14px 44px; }
  .kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .kpi .value { font-size: 21px; }
  .grid { grid-template-columns: 1fr; }
  .table-tools input[type=search] { min-width: 0; width: 100%; }
  .table-tools .count { margin-left: 0; }
  .top-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
  .updated { max-width: 100%; }
  .login-card { padding: 20px; }
}
