/* =============================================================================
   KhamAd · Биикжал — дашборд. Светлая корпоративная тема.
   Палитра: эталонная проверенная палитра dataviz (категориальная — фиксированный порядок,
   статусы — отдельно и только с иконкой и подписью). Шрифт — системный sans.
   ============================================================================= */
:root {
  color-scheme: light;
  --page: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);

  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;

  --good: #0ca30c; --good-text: #006300;
  --warning: #fab219; --serious: #ec835a;
  --critical: #d03b3b; --critical-text: #b42727;

  --accent: #2a78d6;
  --accent-wash: #eaf2fc;
  --accent-ink: #1c5cab;
  --on-accent: #ffffff;
  --filters-bg: rgba(244, 245, 243, 0.94);
  --shadow-color: rgba(11, 11, 11, 0.06);
  --good-wash: #ecf8ec; --good-line: #c9ebc9;
  --warning-wash: #fff6e0; --warning-line: #fbe2a8; --warning-text: #7a5200;
  --serious-wash: #fdeee7; --serious-line: #f6cfbd; --serious-text: #9a3d14;
  --critical-wash: #fbecec; --critical-line: #f1c8c8;
  --hero-line: #cfe0f6;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 1px 1px rgba(11, 11, 11, 0.03);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --header-h: 56px;
  --filters-h: 52px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
a { color: var(--accent); }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.brand-mark { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-mark span { color: var(--accent); }
.brand-sub { color: var(--ink-2); font-size: 13px; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav button {
  border: 0; background: transparent; cursor: pointer;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; white-space: nowrap;
}
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.top-actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(0.94); }
.btn.small { height: 26px; padding: 0 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Строка фильтров ---------- */
.filters {
  position: sticky; top: var(--header-h); z-index: 20;
  min-height: var(--filters-h);
  display: flex; align-items: center; flex-wrap: wrap; gap: 16px;
  padding: 10px 24px;
  background: var(--filters-bg);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.date-control { display: flex; align-items: center; gap: 4px; }
.date-control select {
  height: 32px; padding: 0 28px 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600; cursor: pointer;
}
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.segmented button { border: 0; background: transparent; padding: 0 12px; height: 30px; cursor: pointer; color: var(--ink-2); font-weight: 500; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.filters-info { margin-left: auto; color: var(--ink-2); font-size: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Страница ---------- */
main { padding: 20px 24px 40px; max-width: 1680px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 4px 0 16px; }
.page-head h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); max-width: 900px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; margin: 24px 0 10px; }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }

/* ---------- Плитки KPI ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.tile.hero { grid-column: span 2; }
.tiles.kpi4 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tiles.kpi4 .tile { padding: 14px 18px 12px; gap: 4px; }
.tiles.kpi4 .tile-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.tiles.kpi4 .tile-value { font-size: 32px; font-weight: 750; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--ink); }
.tiles.kpi4 .tile-unit { font-size: 16px; font-weight: 600; color: var(--ink-2); margin-left: 4px; }
.tiles.kpi4 .tile-sub { font-size: 11.5px; color: var(--ink-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tiles.kpi4 .tile-sub:has(.meter) { white-space: normal; overflow: visible; }
.tile-label { color: var(--ink-2); font-size: 13px; font-weight: 500; }
.tile-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; white-space: nowrap; }
.tile.hero .tile-value { font-size: 48px; }
.tile-unit { font-size: 15px; font-weight: 500; color: var(--ink-2); margin-left: 4px; letter-spacing: 0; }
.tile.hero .tile-unit { font-size: 20px; }
.tile-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; min-width: 0; }
.tile-sub { color: var(--ink-2); font-size: 12px; }
.tile-spark { flex: 0 0 auto; }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; white-space: nowrap; padding: 2px 7px; border-radius: 999px; width: fit-content; border: 1px solid transparent; }
.delta.good { color: var(--good-text); background: var(--good-wash); border-color: var(--good-line); }
.delta.bad { color: var(--critical-text); background: var(--critical-wash); border-color: var(--critical-line); }
.delta.neutral { color: var(--ink-2); background: var(--surface-2); border-color: var(--border); }

/* ---------- Статус (иконка + подпись) ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px 2px 6px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.status svg { flex: 0 0 auto; }
.status.good { color: var(--good-text); background: var(--good-wash); border-color: var(--good-line); }
.status.warning { color: var(--warning-text); background: var(--warning-wash); border-color: var(--warning-line); }
.status.serious { color: var(--serious-text); background: var(--serious-wash); border-color: var(--serious-line); }
.status.critical { color: var(--critical-text); background: var(--critical-wash); border-color: var(--critical-line); }
.status.neutral { color: var(--ink-2); background: var(--surface-2); border-color: var(--border); }

/* ---------- Карточка графика ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; }
.card-title { font-size: 15px; font-weight: 650; margin: 0; }
.card-sub { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.card-tools { display: flex; gap: 6px; flex: 0 0 auto; }
.card-body { padding: 4px 16px 14px; position: relative; min-width: 0; flex: 1; display: flex; flex-direction: column; }
.card-body > .chart-box { flex: 1 0 auto; }
.card-foot { padding: 0 16px 12px; color: var(--muted); font-size: 11px; }
.chart-box { position: relative; width: 100%; }
.chart-box.h-180 { height: 180px; } .chart-box.h-220 { height: 220px; } .chart-box.h-260 { height: 260px; }
.chart-box.h-300 { height: 300px; } .chart-box.h-320 { height: 320px; } .chart-box.h-340 { height: 340px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 2px 0 8px; font-size: 12px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.key-line { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.key-rect { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.key-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.empty { color: var(--muted); font-size: 13px; padding: 28px 8px; text-align: center; }
.table-view { display: none; max-height: 340px; overflow: auto; }
.card.show-table .table-view { display: block; }
.card.show-table .chart-box, .card.show-table .legend { display: none; }

/* ---------- Таблицы ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 600; font-size: 12px; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--grid); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.selected td { background: var(--accent-wash); }
table.data td.dim { color: var(--muted); }
.table-scroll { max-height: 460px; overflow: auto; }

/* ---------- Ёмкости ---------- */
.tank-grid { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 10px; }
.tank .tile-row { flex-direction: column; align-items: flex-start; gap: 4px; }
.tank .tile-spark { width: 100%; }
.tank { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.tank-head { display: flex; flex-direction: column; gap: 1px; }
.tank-name { font-weight: 700; font-size: 15px; }
.tank-type { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tank-vol { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.tank-meta { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 12px; }

/* ---------- Тепловая карта ---------- */
.heatmap-wrap { overflow-x: auto; }
.heatmap { border-collapse: separate; border-spacing: 2px; font-size: 11px; }
.heatmap th { color: var(--muted); font-weight: 500; padding: 0 4px; white-space: nowrap; }
.heatmap th.row-h { text-align: right; color: var(--ink-2); font-weight: 600; font-size: 12px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.heatmap td { width: 18px; min-width: 18px; max-width: 18px; height: 22px; border-radius: 3px; cursor: default; }
.heatmap th.hm-d { position: relative; height: 16px; padding: 0; }
.heatmap th.hm-d span { position: absolute; left: 0; bottom: 2px; white-space: nowrap; }
.heatmap td:hover, .heatmap td:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.heatmap td.sel { box-shadow: inset 0 0 0 2px var(--ink); }
.scale { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 8px; }
.scale-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; width: 200px; }
.scale-bar span { flex: 1; }

/* ---------- Малые множества ---------- */
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.multiple { border: 1px solid var(--grid); border-radius: var(--radius-sm); padding: 8px 10px; }
.multiple-title { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.multiple-title span { color: var(--ink-2); font-weight: 500; }
.multiple .chart-box { height: 110px; }

/* ---------- Сигналы ---------- */
.signals { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.signal { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--grid); }
.signal-text { font-size: 13px; }
.signal-text b { font-weight: 650; }
.signal-text div { color: var(--ink-2); font-size: 12px; margin-top: 2px; }

/* ---------- Чипы (выбор скважины / ёмкости) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-weight: 500; font-size: 13px; }
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip small { color: inherit; opacity: .65; margin-left: 4px; }

.note { background: var(--surface-2); border: 1px dashed var(--axis); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--ink-2); font-size: 13px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; }
ul.plain { margin: 0; padding-left: 18px; font-size: 13px; }
ul.plain li { margin: 3px 0; }

/* ---------- Подсказка ---------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; min-width: 160px; max-width: min(320px, calc(100vw - 16px));
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(11, 11, 11, .12); padding: 9px 12px; font-size: 12px; display: none;
}
.tooltip .tt-title { color: var(--ink); font-weight: 650; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid var(--grid); }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.tooltip .tt-val { font-weight: 700; margin-left: auto; font-variant-numeric: tabular-nums; }

.loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--page); z-index: 100; color: var(--ink-2); flex-direction: column; gap: 12px; }
.loading.hidden { display: none; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--grid); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 60; background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 8px; font-size: 13px; display: none; max-width: 420px; }
.footer { color: var(--muted); font-size: 12px; padding: 0 24px 24px; max-width: 1680px; margin: 0 auto; }

@media (max-width: 1640px) { .brand-sub { display: none; } .filters-info > span:first-child { display: none; } }
@media (max-width: 1380px) { .top-actions .btn span { display: none; } }
@media (max-width: 1280px) { .tank-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (max-width: 760px) { .tank-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1200px) {
  .tiles.kpi4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
  .span-3 { grid-column: span 6; }
}
@media (max-width: 760px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .brand-sub, .top-actions .btn span { display: none; }
  .filters { padding: 8px 12px; top: var(--header-h); }
  .filters-info { margin-left: 0; width: 100%; }
  main { padding: 14px 12px 32px; }
  .span-3 { grid-column: span 12; }
  .tile.hero { grid-column: span 1; }
  .tiles.kpi4 { grid-template-columns: minmax(0, 1fr); }
  .tile.hero .tile-value { font-size: 40px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile-row { flex-wrap: wrap; }
  .tile-value { font-size: 24px; }
  .grid { gap: 12px; }
  .card-head { flex-wrap: wrap; }
}
@media print {
  .topbar, .filters, .card-tools, .top-actions { display: none !important; }
  .page { display: block !important; page-break-after: always; }
  body { background: #fff; }
}

/* ---------- Пользователь, справка, свой период ---------- */
.top-actions { align-items: center; }
.help-btn { font-weight: 700; color: var(--ink-2); border-radius: 50%; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 3px 4px 3px 4px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); margin-left: 4px; }
.user-chip .avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; max-width: 160px; }
.user-meta b { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { font-size: 11px; color: var(--muted); }
.user-chip .icon-btn { width: 28px; height: 28px; border-radius: 50%; border-color: transparent; background: transparent; }
.user-chip .icon-btn:hover { background: var(--surface); border-color: var(--border); }
.filter-group { position: relative; }
.range-pop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 40;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(11, 11, 11, 0.12); padding: 10px 12px;
}
.range-pop[hidden] { display: none; }
.range-pop label { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 12px; }
.range-pop input { height: 28px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 0 6px; }
.card-tools .btn.small svg { flex: 0 0 auto; }

.glossary { width: min(720px, calc(100vw - 32px)); max-height: min(80vh, 760px); border: 1px solid var(--border); border-radius: 14px; padding: 0; box-shadow: 0 24px 64px rgba(11, 11, 11, 0.18); color: var(--ink); }
.glossary::backdrop { background: rgba(11, 11, 11, 0.32); backdrop-filter: blur(2px); }
.glossary-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.glossary-head h2 { margin: 0; font-size: 18px; }
.glossary dl { margin: 0; padding: 8px 20px 20px; display: grid; grid-template-columns: 210px 1fr; gap: 0 16px; }
.glossary dt { font-weight: 650; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.glossary dd { margin: 0; padding: 10px 0; border-bottom: 1px solid var(--grid); color: var(--ink-2); }

/* ---------- Полировка ---------- */
.topbar { box-shadow: 0 1px 0 rgba(11, 11, 11, 0.02); }
.topbar::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: linear-gradient(90deg, var(--s1), var(--s3) 60%, var(--s4)); }
.card, .tile { transition: box-shadow .15s ease, border-color .15s ease; }
.card:hover, .tile:hover { box-shadow: 0 4px 14px var(--shadow-color); border-color: var(--border-strong); }
.tile.hero { background: linear-gradient(180deg, var(--accent-wash), var(--surface) 70%); border-color: var(--hero-line); }
.page-head h1 { font-size: 24px; }
.signal { transition: background .15s ease; }

@media (max-width: 1800px) { .user-meta { display: none; } }
@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; row-gap: 4px; padding-top: 8px; padding-bottom: 4px; }
  .topbar .nav { order: 3; flex: 1 0 100%; }
  .filters { position: static; }
  .segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .segmented button { white-space: nowrap; flex: 0 0 auto; }
  .filter-group { flex-wrap: wrap; }
  .glossary dl { grid-template-columns: 1fr; }
  .glossary dt { border-bottom: 0; padding-bottom: 2px; }
  .glossary dd { padding-top: 0; }
  .help-btn { display: none; }
  .range-pop { position: fixed; left: 12px; right: 12px; top: auto; }
}

/* ---------- Ёмкости-шкалы, метры, гантели ---------- */
.tank-body { display: flex; gap: 10px; align-items: flex-end; }
.tank-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tank-pct { font-size: 12px; font-weight: 650; color: var(--ink); }
.tank-pct span { font-weight: 500; color: var(--muted); }
.tank.full { border-color: var(--warning-line); background: linear-gradient(180deg, var(--warning-wash), var(--surface) 60%); }
.gauge { flex: 0 0 auto; }
.meter { height: 8px; border-radius: 999px; background: var(--grid); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 999px; }
.db-cell { padding-top: 2px !important; padding-bottom: 2px !important; }
.db-legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.db-legend .dot-open, .db-legend .dot-fill { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.db-legend .dot-open { border: 2px solid var(--muted); margin-left: 0; }
.db-legend .dot-fill { background: var(--s1); margin-left: 10px; }
.gain-up { color: var(--good-text); }
.gain-down { color: var(--critical-text); }

.passport summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 6px; }
.btn[hidden] { display: none; }

/* ---------- Двухчасовая сводка ---------- */
.slot-strip { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; margin-top: 16px; }
.slot { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 8px 6px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.slot b { font-size: 13px; font-variant-numeric: tabular-nums; }
.slot span { font-size: 11px; color: var(--muted); }
.slot small, table.data th small { display: block; font-size: 10px; color: var(--muted); font-weight: 400; white-space: nowrap; }
.slot.full { border-color: var(--good-line); background: var(--good-wash); }
.slot.full span { color: var(--good-text); }
.slot.part { border-color: var(--warning-line); background: var(--warning-wash); }
.slot.part span { color: var(--warning-text); }
.slot.none { border-style: dashed; }
.slot.future { opacity: .45; }
.slot.acc { box-shadow: inset 0 -3px 0 var(--accent); }
.rd-table td.rd { line-height: 1.15; }
#rd-proc td:first-child, #rd-wells td:nth-child(-n+2), #rd-table td:first-child { white-space: nowrap; }
.rd-table td small, table.data td small { display: block; font-size: 10.5px; color: var(--muted); font-weight: 400; }
table.data th.acc, table.data td.acc { background: var(--accent-wash); }
table.data tr.sum td { font-weight: 650; border-top: 1px solid var(--axis); }
table.data tr.group td { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding-top: 14px; }
@media (max-width: 760px) { .slot-strip { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* ---------- Сводка руководителя: один экран ---------- */
.exec-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin: 0 0 12px; }
.exec-head h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.exec-head span { color: var(--ink-2); font-size: 13px; }
.tiles.kpi7 { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 12px; }
.tiles.kpi7 .tile.hero { grid-column: span 1; }
.tiles.kpi7 .tile { padding: 12px 14px 10px; gap: 4px; }
.tiles.kpi7 .tile-value { font-size: 24px; }
.tiles.kpi7 .tile.hero .tile-value { font-size: 30px; }
.tiles.kpi7 .tile.hero .tile-unit { font-size: 15px; }
.tiles.kpi7 .tile-sub { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tiles.kpi7 .tile-label { font-size: 12.5px; }
.tiles.kpi7 .tile-spark svg { width: 72px; }
.exec-row { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.exec .kv { font-size: 13px; gap: 7px 14px; }
@media (max-width: 1280px) { .tiles.kpi7 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 1200px) {
  .exec-row > .card { grid-column: span 12; }
  .tiles.kpi7 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tiles.kpi4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tiles.kpi4 .tile-value { font-size: 26px; }
}
@media (max-width: 540px) {
  .tiles.kpi4 { grid-template-columns: 1fr !important; }
}
@media (max-width: 768px) {
  :root { --header-h: auto; }
  .topbar {
    padding: calc(6px + env(safe-area-inset-top, 0px)) 12px 6px;
    gap: 8px; flex-wrap: wrap; height: auto;
  }
  .brand-sub { display: none; }
  .nav {
    order: 3; width: 100%; padding: 4px 0 6px;
    display: flex; gap: 6px; overflow-x: auto;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .nav button {
    flex: 0 0 auto; padding: 6px 12px; font-size: 12.5px;
    border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  }
  .nav button[aria-current="page"] {
    background: var(--accent-wash); color: var(--accent-ink);
    border-color: var(--accent); font-weight: 600;
  }
  .top-actions { margin-left: auto; }
  #btn-pdf span, #btn-email span { display: none; }
  .user-chip .user-meta { display: none; }
  .filters { position: static; padding: 8px 12px; gap: 8px; }
  .filter-group { width: 100%; justify-content: space-between; }
  .segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .segmented button { padding: 0 8px; font-size: 12px; }
  .tiles.kpi7 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  .tiles.kpi7 .tile { padding: 10px 8px; }
  .tiles.kpi7 .tile.hero { grid-column: span 2 !important; }
  .tiles.kpi7 .tile-value { font-size: 20px; }
  .tiles.kpi7 .tile.hero .tile-value { font-size: 26px; }
  .tiles.kpi7 .tile-spark svg { width: 54px; }
  .tiles.kpi4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  .tiles.kpi4 .tile { padding: 10px 12px; }
  .tiles.kpi4 .tile-value { font-size: 22px; }
  main { padding: 10px 10px 32px; }
  .exec-head h1 { font-size: 18px; }
  .table-wrap, .card-body:has(table) {
    overflow-x: auto; -webkit-overflow-scrolling: touch; position: relative;
  }
  table { min-width: 480px; }
  .table-wrap th:first-child,
  .table-wrap td:first-child,
  .card-body:has(table) th:first-child,
  .card-body:has(table) td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
    box-shadow: 2px 0 4px rgba(11, 11, 11, 0.05);
  }
  .table-wrap th:first-child,
  .card-body:has(table) th:first-child {
    z-index: 3;
    background: var(--surface-2);
  }
}
/* На широком экране всё помещается без прокрутки: строки делят оставшуюся высоту */
@media (min-width: 1281px) and (min-height: 700px) {
  #page-overview.active { height: calc(100vh - var(--chrome-h, 110px) - 22px); }
  #page-overview .exec { height: 100%; display: flex; flex-direction: column; }
  #page-overview .exec-row { flex: 1 1 0; min-height: 0; }
  #page-overview .exec-row.r1 { flex-grow: 1.15; }
  #page-overview .exec-row > .card { min-height: 0; overflow: hidden; }
  #page-overview .card-body { min-height: 0; }
  #page-overview .chart-box { height: auto !important; flex: 1 1 0; min-height: 0; }
  #page-overview .signals { overflow-y: auto; min-height: 0; flex: 1 1 0; padding-right: 2px; }
  #page-overview .signal { padding: 8px 10px; }
  #page-overview .kv { overflow-y: auto; }
  body:has(#page-overview.active) main { padding-top: 14px; padding-bottom: 0; }
  body:has(#page-overview.active) .footer { display: none; }
}

/* ---------- Страница входа ---------- */
.login-body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 15% -10%, var(--accent-wash), transparent 60%),
    radial-gradient(900px 420px at 110% 110%, #eef6f1, transparent 60%),
    var(--page);
}
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(11, 11, 11, 0.06), 0 2px 6px rgba(11, 11, 11, 0.04);
  padding: 28px 28px 22px;
}
.login-brand { font-size: 20px; }
.login-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.login-card h1 { font-size: 20px; margin: 26px 0 6px; letter-spacing: -0.01em; }
.login-lead { color: var(--ink-2); margin: 0 0 18px; }
.login-steps { list-style: none; display: flex; gap: 8px; margin: 0 0 18px; padding: 0; }
.login-steps li { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding-top: 8px; border-top: 3px solid var(--grid); }
.login-steps li span { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.login-steps li.active { color: var(--ink); border-top-color: var(--accent); }
.login-steps li.active span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.login-steps li.done { color: var(--ink-2); border-top-color: var(--good); }
.login-steps li.done span { background: var(--good); border-color: var(--good); color: #fff; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form[hidden] { display: none; }
#code::placeholder { letter-spacing: .02em; font-size: 15px; }
.login-form label { font-weight: 600; font-size: 13px; }
.login-form input {
  height: 44px; padding: 0 12px; font-size: 17px; letter-spacing: .02em; font-variant-numeric: tabular-nums;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface);
}
.login-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
#code { letter-spacing: .35em; text-align: center; font-size: 22px; }
.login-form .hint { margin: 0 0 6px; color: var(--muted); font-size: 12.5px; }
.login-form .btn { height: 42px; justify-content: center; font-weight: 600; }
.btn.link { border: none; background: none; color: var(--accent); height: 32px; font-weight: 500; }
.btn.link:hover { background: var(--accent-wash); }
.bot-link { font-weight: 600; text-decoration: none; }
.bot-link:hover { text-decoration: underline; }
.login-go { display: flex; justify-content: center; height: 44px; margin-top: 8px; text-decoration: none; font-weight: 600; }
.login-msg { min-height: 20px; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.login-msg.error { color: var(--critical-text); }
.login-msg.ok { color: var(--good-text); }
.login-foot { color: var(--muted); font-size: 12px; margin-top: 16px; text-align: center; max-width: 420px; }

/* ---------- Тёмная тема: те же оттенки, шаги для тёмной поверхности (эталонная палитра dataviz) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-text: #0ca30c; --critical-text: #e66767;
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --accent-ink: #86b6ef;
  --on-accent: #ffffff;
  --filters-bg: rgba(13, 13, 13, 0.90);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-color: rgba(0, 0, 0, 0.45);
  --good-wash: rgba(12, 163, 12, 0.14); --good-line: rgba(12, 163, 12, 0.35);
  --warning-wash: rgba(250, 178, 25, 0.14); --warning-line: rgba(250, 178, 25, 0.38); --warning-text: #fab219;
  --serious-wash: rgba(236, 131, 90, 0.14); --serious-line: rgba(236, 131, 90, 0.38); --serious-text: #ec835a;
  --critical-wash: rgba(208, 59, 59, 0.16); --critical-line: rgba(230, 103, 103, 0.40);
  --hero-line: rgba(57, 135, 229, 0.35);
}
:root[data-theme="dark"] .login-body {
  background: radial-gradient(1200px 500px at 15% -10%, rgba(57, 135, 229, 0.18), transparent 60%), var(--page);
}
:root[data-theme="dark"] .login-card { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); }
:root[data-theme="dark"] .glossary { background: var(--surface); }
:root[data-theme="dark"] .glossary::backdrop { background: rgba(0, 0, 0, 0.6); }
:root[data-theme="dark"] select, :root[data-theme="dark"] input { background: var(--surface); color: var(--ink); }
.theme-btn svg { display: block; }
.theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-moon { display: none; }

/* ---------- Сигналы нормы и поднавигация ---------- */
.signal-ok {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--good-wash);
  border: 1px solid var(--good-line);
  color: var(--good-text);
  font-weight: 600;
  font-size: 13px;
  line-height: 1.4;
}
.subnav { flex: 0 0 auto; }
.subnav .segmented button { font-size: 13px; height: 32px; padding: 0 14px; }
@media (max-width: 900px) {
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .subnav { width: 100%; }
  .subnav .segmented { width: 100%; display: flex; }
  .subnav .segmented button { flex: 1 1 0; text-align: center; }
}
