:root {
  color-scheme: light;
  --surface-0: #f4f4f1;
  --surface-1: #fcfcfb;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #85847e;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --critical: #c3322f;
  --warning: #a66a00;
  --good: #1b7a4b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --border: #33322f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --series-1: #3987e5;
    --series-2: #d95926;
    --critical: #e66767;
    --warning: #c98500;
    --good: #35a06a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --border: #33322f;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --series-1: #3987e5;
  --series-2: #d95926;
  --critical: #e66767;
  --warning: #c98500;
  --good: #35a06a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: inherit; }

header.top {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

header.top .brand { font-weight: 600; letter-spacing: -0.01em; }
header.top nav { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; }
header.top nav a { text-decoration: none; color: var(--text-secondary); padding: 4px 0; }
header.top nav a.active { color: var(--text-primary); box-shadow: inset 0 -2px 0 var(--series-1); }
header.top .who { color: var(--text-muted); font-size: 13px; }

main { max-width: 1040px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 14px; }

.tiles { display: flex; gap: 12px; flex-wrap: wrap; }
.tile { flex: 1 1 180px; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.tile .label { color: var(--text-muted); font-size: 13px; }
.tile .delta { font-size: 13px; color: var(--text-secondary); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 500; font-size: 13px; }
/* Числа выравниваем вправо, текст — влево: так столбцы цифр сравниваются взглядом. */
th:first-child, td:first-child,
th.text, td.text,
th.name, td.name { text-align: left; }
tbody tr:hover { background: var(--surface-0); }
td.name { color: var(--text-secondary); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 12px; border: 1px solid var(--border); }
.badge.critical { color: var(--critical); border-color: var(--critical); }
.badge.warning { color: var(--warning); border-color: var(--warning); }
.badge.good { color: var(--good); border-color: var(--good); }

.legend { display: flex; gap: 16px; align-items: center; margin-bottom: 8px; font-size: 13px; color: var(--text-secondary); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot.series-1, rect.series-1 { background: var(--series-1); fill: var(--series-1); }
.dot.series-2, rect.series-2 { background: var(--series-2); fill: var(--series-2); }

svg.chart { width: 100%; height: auto; display: block; }
svg.chart .grid { stroke: var(--border); stroke-width: 1; }
svg.chart .axis { fill: var(--text-muted); font-size: 11px; }
svg.chart .axis.weekend { fill: var(--text-secondary); }
svg.chart .value-label { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
svg.chart .hit { fill: transparent; cursor: default; }
svg.chart g.bar:hover rect.seg { stroke: var(--surface-1); stroke-width: 2; }

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  opacity: 0;
  transition: opacity .1s;
  z-index: 10;
  white-space: nowrap;
}
.tooltip.on { opacity: 1; }
.tooltip .t-day { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; gap: 10px; justify-content: space-between; }

.fresh { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-secondary); }
.fresh .item { display: inline-flex; align-items: center; gap: 6px; }
.fresh .mark { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; }
.fresh .mark.bad { background: var(--critical); }
.fresh .mark.stale { background: var(--warning); }

.stale-banner {
  border: 1px solid var(--critical);
  color: var(--critical);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}

form.login { max-width: 320px; margin: 72px auto; }
form.login label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--text-secondary); }
form.login input {
  width: 100%; padding: 9px 10px; margin-top: 4px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary);
}
form.login button {
  width: 100%; padding: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
  border: 0; border-radius: 8px; background: var(--series-1); color: #fff; margin-top: 6px;
}
form.login .error { color: var(--critical); font-size: 13px; margin-bottom: 10px; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .tile .value { font-size: 22px; }
  td.name { max-width: 140px; }

  /* Шапка на телефоне складывается в строки, иначе пункты меню разъезжаются. */
  header.top { gap: 6px 14px; padding: 10px 12px; }
  header.top .brand { flex: 1 1 100%; }
  header.top nav { flex: 1 1 100%; order: 3; gap: 18px; }
  header.top .who { font-size: 12px; }

  /* Широкие таблицы прокручиваются внутри карточки, а не ломают страницу. */
  .card { overflow-x: auto; }
  table { min-width: 520px; }
}
