/* Страница статистики — самодостаточная: свои базовые правила, без /styles.css.
   Причина: страница отдаётся заказчику на отдельном домене (585g.aimap.agency),
   где nginx проксирует ТОЛЬКО /stats/ — общий стиль интерфейса туда не доезжает.
   Базовые токены и элементы скопированы из styles.css 14.09.2026. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16191d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2f6fed;
  --pass: #128a4d;
  --pass-bg: #e6f5ec;
  --fail: #c02626;
  --fail-bg: #fdecec;
  --partial: #9a6700;
  --partial-bg: #fdf3e0;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --panel: #1c2027;
    --ink: #e8eaed;
    --muted: #9aa3ad;
    --line: #2c323a;
    --accent: #6ea0ff;
    --pass: #57d08c;
    --pass-bg: #17321f;
    --fail: #ff8a8a;
    --fail-bg: #3a1c1c;
    --partial: #e2b258;
    --partial-bg: #372a13;
  }
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 650; color: var(--ink); text-decoration: none; }
.breadcrumbs { flex: 1; color: var(--muted); font-size: 14px; }
.breadcrumbs a { color: var(--accent); text-decoration: none; }
.breadcrumbs > *:not(:first-child)::before { content: " / "; color: var(--line); }

.view { padding: 24px; max-width: 1400px; margin: 0 auto; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }


.field { display: flex; flex-direction: column; gap: 4px; }
/* Адрес вебхука длинный — поле тянется на всю свободную ширину строки. */
.field.grow { flex: 1 1 420px; min-width: 320px; }
.field label { font-size: 12px; color: var(--muted); }

/* ⚠️ Тип поля нужно ДОБАВЛЯТЬ в этот список. Всё, чего здесь нет, браузер
   рисует по умолчанию, и оно выбивается из остального интерфейса: так до
   09.09.2026 выглядели числовые поля таймаута у проверки сценариев. */
select,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
textarea {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  min-width: 180px;
}

/* Числовое поле в 180px рядом с подписью «Попыток доставки» выглядит пустым:
   ширину задаём по содержимому, а не по общему минимуму. */
input[type="number"] { min-width: 0; width: 110px; }

button {
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 7px 13px;
  font: inherit;
  cursor: pointer;
  background: var(--panel);
  color: var(--ink);
}

button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg); }
tr:last-child td { border-bottom: none; }


dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 20px;
  min-width: 340px;
}

dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
dialog input { width: 100%; }


/* ---- страница ---- */
:root {
  --series-closed: #2a78d6;
  --series-handed: #eb6834;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-closed: #3987e5;
    --series-handed: #d95926;
  }
}

.field > span { font-size: 12px; color: var(--muted); }
.field[hidden] { display: none; }
.table-wrap { overflow-x: auto; }
.block td.tag { white-space: nowrap; color: var(--muted); font-size: 13px; }
.block td.label { min-width: 160px; }
.field small { margin-top: 4px; max-width: 420px; }
input[type="date"] {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
}

.view { overflow-x: hidden; }
.filters { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; margin-bottom: 16px; }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); margin-bottom: 20px; }
.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.tile .label { font-size: 13px; color: var(--muted); }
.tile .value { font-size: 28px; font-weight: 650; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); margin-bottom: 20px; }
.block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.block h2 { font-size: 15px; margin: 0 0 10px; }
.block table { border-radius: 0; }
.block th, .block td { padding: 7px 8px; font-size: 14px; }
.block th { font-size: 12px; text-transform: none; letter-spacing: 0; }
.block th { color: var(--muted); font-weight: 500; }
.block td.num, .block th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.block tr:last-child td { border-bottom: none; }
.block .note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }

.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; min-width: 320px; }
.chart .bar { transition: opacity .15s; }
.chart .bar:hover { opacity: .8; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .tip {
  position: absolute;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  white-space: nowrap;
}
.chart-wrap { position: relative; }

.definitions { font-size: 13px; color: var(--muted); }
.definitions dt { font-weight: 600; color: var(--ink); margin-top: 8px; }
.definitions dd { margin: 2px 0 0; }

.error { color: var(--fail); }
#channel-names .row { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; }
#channel-names code { min-width: 120px; }

.topbar { flex-wrap: wrap; }

/* ---- вход ---- */
.login {
  max-width: 360px;
  margin: 60px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.login h1 { font-size: 18px; margin-bottom: 14px; }
.login .field { margin-bottom: 12px; }
.login input { width: 100%; min-width: 0; }
.login .actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.who { color: var(--muted); font-size: 13px; }
