/* Оформление админки (ADM-11). Цвета, радиусы и типографика повторяют packages/tokens
   (primitives.json, semantic.dark.json, semantic.light.json, foundation.json) числами: админка —
   отдельный модуль Go без сборки, импортировать сгенерированный CSS ей нечем.

   Одного цвета в наборе нет — «предупреждение». color.orange (#F49A4E) читается на тёмном, но на
   белом даёт 2,2:1, поэтому в светлой теме он затемнён до 4,6:1 — так же, как text.secondary и
   text.danger по ТЗ 8.7.

   Скриптов на страницах нет вовсе, поэтому всё состояние — в разметке: тему держит cookie,
   «Сейчас» обновляется через meta refresh. */

:root {
  color-scheme: dark light;

  --bg: #000000;
  --card: #191919;
  --raised: #262626;
  --text: #f2f2f2;
  --muted: #a3a3a3;
  --border: #333333;
  --subtle: rgba(255, 255, 255, 0.1);

  --ok: #34c374;
  --warn: #f49a4e;
  --crit: #f26b66;
  --ok-bg: rgba(52, 195, 116, 0.16);
  --warn-bg: rgba(244, 154, 78, 0.16);
  --crit-bg: rgba(242, 107, 102, 0.16);

  --chart: #ffe1a9;
  --chart-fill: rgba(255, 225, 169, 0.16);
  --grid: rgba(255, 255, 255, 0.12);
  --track: rgba(255, 255, 255, 0.12);

  --radius-s: 12px;
  --radius-m: 16px;
  --radius-l: 20px;
  --radius-full: 999px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f2f2f2;
    --card: #ffffff;
    --raised: #f2f2f2;
    --text: #191919;
    --muted: #6b6b6b;
    --border: #e4e4e4;
    --subtle: rgba(0, 0, 0, 0.1);

    --ok: #099f48;
    --warn: #9a5200;
    --crit: #d63e3c;
    --ok-bg: rgba(9, 159, 72, 0.1);
    --warn-bg: rgba(154, 82, 0, 0.1);
    --crit-bg: rgba(214, 62, 60, 0.1);

    --chart: #191919;
    --chart-fill: rgba(25, 25, 25, 0.08);
    --grid: rgba(0, 0, 0, 0.12);
    --track: rgba(0, 0, 0, 0.1);
  }
}

:root[data-theme="light"] {
  --bg: #f2f2f2;
  --card: #ffffff;
  --raised: #f2f2f2;
  --text: #191919;
  --muted: #6b6b6b;
  --border: #e4e4e4;
  --subtle: rgba(0, 0, 0, 0.1);

  --ok: #099f48;
  --warn: #9a5200;
  --crit: #d63e3c;
  --ok-bg: rgba(9, 159, 72, 0.1);
  --warn-bg: rgba(154, 82, 0, 0.1);
  --crit-bg: rgba(214, 62, 60, 0.1);

  --chart: #191919;
  --chart-fill: rgba(25, 25, 25, 0.08);
  --grid: rgba(0, 0, 0, 0.12);
  --track: rgba(0, 0, 0, 0.1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 500 16px/1.4 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 26px;
  line-height: 30px;
  font-weight: 600;
}

h2 {
  font-size: 20px;
  line-height: 24px;
  font-weight: 600;
}

h3 {
  font-size: 14px;
  line-height: 18px;
  font-weight: 600;
  color: var(--muted);
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 5;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  text-decoration: none;
}

/* Шапка */

.top {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.top-row {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  white-space: nowrap;
}

.brand img {
  width: 24px;
  height: 24px;
  border-radius: 6px;
}

.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar {
  display: none;
}

.nav a {
  padding: 9px 14px;
  border-radius: var(--radius-full);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.nav a:hover {
  color: var(--text);
  background: var(--raised);
}

.nav a.current {
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 8px 13px;
}

.top-right {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

.theme {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}

button {
  font: inherit;
  cursor: pointer;
}

.theme button,
.ghost {
  min-height: 32px;
  padding: 6px 12px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.theme button:hover,
.ghost:hover {
  color: var(--text);
}

.theme button.current {
  background: var(--raised);
  color: var(--text);
}

.ghost {
  border: 1px solid var(--border);
  background: var(--card);
}

/* Содержимое */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

.periods {
  display: flex;
  gap: 4px;
  padding: 2px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}

.periods a {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.periods a.current {
  background: var(--raised);
  color: var(--text);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-items: start;
  gap: 12px;
}

.cards.wide {
  grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 16px;
  min-width: 0;
}

.cards + .cards,
.cards + .card,
.card + .cards,
.card + .card {
  margin-top: 12px;
}

.card header {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}

.note + .note,
.pairs + .note,
.scroll + .note {
  margin-top: 10px;
}

.more {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.more:hover {
  color: var(--text);
  text-decoration: underline;
}

/* Полоса состояния */

.banner {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  background: var(--card);
}

.banner-title {
  margin: 0;
  font-size: 20px;
  line-height: 24px;
  font-weight: 600;
}

.banner.level-ok {
  background: var(--ok-bg);
  border-color: transparent;
}

.banner.level-warn {
  background: var(--warn-bg);
  border-color: transparent;
}

.banner.level-crit {
  background: var(--crit-bg);
  border-color: transparent;
}

/* Пары «подпись — число» */

.pairs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  margin: 0;
}

.pairs > div {
  min-width: 0;
}

.pairs dt {
  color: var(--muted);
  font-size: 13px;
  line-height: 18px;
}

.pairs dd {
  margin: 2px 0 0;
  font-size: 26px;
  line-height: 30px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.pairs dd.small {
  font-size: 18px;
  line-height: 24px;
}

.pairs dd.none {
  color: var(--muted);
  font-size: 16px;
  font-weight: 500;
}

/* Таблицы */

.scroll {
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

caption {
  text-align: left;
  color: var(--muted);
  font-size: 13px;
  padding-bottom: 8px;
}

th,
td {
  text-align: left;
  padding: 8px 14px 8px 0;
  border-bottom: 1px solid var(--subtle);
  white-space: nowrap;
}

tr > :last-child {
  padding-right: 0;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

td.name,
th.name {
  white-space: normal;
  min-width: 170px;
}

td.right,
th.right {
  text-align: right;
}

td.dim {
  color: var(--muted);
}

/* Светофор */

.state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.state::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.state.level-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.state.level-warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.state.level-crit {
  background: var(--crit-bg);
  color: var(--crit);
}

.state.level-unknown {
  background: var(--raised);
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

ul.note {
  margin: 0;
  padding-left: 20px;
}

/* Полоски и графики */

.bar {
  display: block;
  width: 100%;
  height: 6px;
  min-width: 80px;
}

.bar .track {
  fill: var(--track);
}

.bar .fill {
  fill: var(--chart);
}

td.bar-cell {
  width: 30%;
  min-width: 110px;
  padding-right: 12px;
}

figure {
  margin: 0;
}

/* Графиков на экране «Нагрузка» одиннадцать: в две колонки страница перестаёт быть лентой. */
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px 16px;
}

figcaption {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.chart {
  display: block;
  width: 100%;
  height: auto;
  background: var(--raised);
  border-radius: var(--radius-m);
}

.chart .grid {
  stroke: var(--grid);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart .area {
  fill: var(--chart-fill);
}

.chart .line {
  fill: none;
  stroke: var(--chart);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.chart text {
  fill: var(--muted);
  font: 500 11px/1 Inter, system-ui, sans-serif;
}

/* Пустой график — не ноль, а отсутствие данных: вместо линии надпись той же высоты. */
p.chart.empty {
  display: grid;
  place-items: center;
  min-height: 110px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* Вход */

body.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.auth form {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: 24px;
}

.auth h1 {
  font-size: 20px;
  line-height: 24px;
}

.auth label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.auth input {
  font: inherit;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--raised);
  color: var(--text);
}

.auth button[type="submit"] {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius-s);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
}

.error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-s);
  background: var(--crit-bg);
  color: var(--crit);
  font-size: 14px;
}

/* Подвал */

footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px 32px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

footer a {
  color: inherit;
}

@media (max-width: 640px) {
  .top-row {
    padding: 8px 12px;
  }

  .brand {
    font-size: 14px;
  }

  /* На телефоне в первой строке должны уместиться значок, темы и «Выйти»: название убираем —
     оно есть в заголовке вкладки. */
  .brand-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .nav {
    order: 3;
    flex-basis: 100%;
  }

  main {
    padding: 16px 12px 32px;
  }

  .scroll {
    margin: 0 -12px;
    padding: 0 12px;
  }

  .card {
    padding: 14px;
    border-radius: var(--radius-m);
  }

  .cards.wide {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 22px;
    line-height: 26px;
  }

  .pairs dd {
    font-size: 22px;
    line-height: 26px;
  }

  /* Подписи шкалы заданы в единицах viewBox и ужимаются вместе с графиком: на телефоне они
     становятся нечитаемыми. Числа при этом никуда не деваются — они под графиком. */
  .chart text {
    display: none;
  }
}
