:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --border: #e3e3df;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #1f6feb;
  --good: #0a7d32;
  --bad: #c62828;
  --warn-bg: #fdecea;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e6e5e1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #262624;
    --border: #33332f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #5b9bf0;
    --good: #4cc675;
    --bad: #ff7b72;
    --warn-bg: #3a1f1d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #2c2c29;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #262624;
  --border: #33332f;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #9a998f;
  --accent: #5b9bf0;
  --good: #4cc675;
  --bad: #ff7b72;
  --warn-bg: #3a1f1d;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: #2c2c29;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, select, input { font: inherit; color: inherit; }

/* шапка */
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(8px + env(safe-area-inset-top)) 16px 0; border-bottom: 1px solid var(--border);
}
.row { display: flex; align-items: center; gap: 8px; }
.row h1 { font-size: 18px; margin: 0; }
.spacer { flex: 1; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  width: 36px; height: 36px; cursor: pointer; font-size: 16px;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; align-items: center; }
.filters select, .filters input {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  max-width: 100%;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--surface); border: 0; padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; }
nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
nav::-webkit-scrollbar { display: none; }
nav button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; white-space: nowrap;
  cursor: pointer; color: var(--text-2);
}
nav button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
h2 { font-size: 16px; margin: 20px 0 8px; }
.loading { color: var(--muted); padding: 24px 0; }
.error { background: var(--warn-bg); padding: 12px; border-radius: 8px; }

/* плитки */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  min-width: 0;
}
.tile .t { color: var(--text-2); font-size: 13px; display: flex; gap: 4px; align-items: flex-start; }
.tile .t span { flex: 1; }
.tile .v { font-size: 22px; font-weight: 650; margin: 4px 0 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile .p { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tile .d { font-size: 12px; font-variant-numeric: tabular-nums; }
.d.good { color: var(--good); } .d.bad { color: var(--bad); } .d.neutral { color: var(--text-2); }
.hint-btn {
  border: 1px solid var(--border); background: none; border-radius: 50%; width: 18px; height: 18px;
  font-size: 11px; line-height: 16px; padding: 0; cursor: pointer; color: var(--muted); flex: none;
}
.hint { font-size: 12px; color: var(--text-2); margin-top: 6px; background: var(--surface-2); padding: 6px 8px; border-radius: 6px; }
.pulse .tile .v { font-size: 18px; }

/* блоки */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-top: 8px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.list { margin: 0; padding: 0; list-style: none; }
.list li { padding: 8px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.note { color: var(--muted); font-size: 12px; margin-top: 6px; }
.chart-box { position: relative; height: 280px; }

/* таблицы */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th { color: var(--text-2); font-weight: 500; position: sticky; top: 0; background: var(--surface); }
th:first-child, td:first-child, th.txt, td.txt { text-align: left; }
td.warn { color: var(--bad); font-weight: 600; }
td small { display: block; color: var(--muted); font-size: 11px; }
td input { width: 90px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); text-align: right; }

footer { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }

/* вход */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px; max-width: 380px; width: 100%; text-align: center; }
.login-box .logo { width: 96px; height: 96px; border-radius: 22px; }
.login-box h1 { font-size: 20px; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 12px 18px; font-size: 16px; cursor: pointer; width: 100%; }
.btn-2 { background: var(--surface-2); color: var(--text); }
.code-form { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.code-form input {
  font-size: 24px; letter-spacing: 6px; text-align: center; padding: 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.ok { color: var(--good); } .err { color: var(--bad); } .muted { color: var(--muted); font-size: 13px; }

@media (max-width: 600px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .v { font-size: 18px; }
  .chart-box { height: 220px; }
}
.row h1 { display: flex; align-items: center; gap: 8px; }
.brand { width: 28px; height: 28px; border-radius: 7px; }
