/* Общие элементы: кнопки, поля, таблицы, чипы статуса, баннеры, карточки-показатели, скелетон, полоса .meter.
   Цвета только из tokens.css. Статус всегда со словом и формой значка: не только цвет.
   Движение: только transform и opacity (и цвета при наведении); при reduced motion всё гасится в tokens.css. */
* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0; min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column;
  color: var(--text); background: var(--bg);
  font: 100%/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); }
button, summary, a { touch-action: manipulation; }
h2 { margin: 0 0 6px; font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.lead { margin: 0 0 24px; color: var(--text-2); }
/* заголовок секции */
.hsec { margin: 0 0 12px; font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; }
.sub { color: var(--text-2); font-size: 0.9rem; }
.dim { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* длинные названия точек и районов: переносятся, не распирают сетку; в таблице и чипе режутся многоточием */
.pname { min-width: 0; overflow-wrap: anywhere; }
.cut { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- кнопки ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  font: inherit; font-size: 0.92rem; font-weight: 550; line-height: 1.2; text-decoration: none; cursor: pointer;
  padding: 8px 16px; border: 1px solid var(--stroke-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: transform 160ms var(--ease-out), background-color 150ms ease, color 150ms ease, border-color 150ms ease;
  user-select: none; -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: scale(var(--press)); }
.btn:focus-visible, .tabs button:focus-visible, .field :is(input, select, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.sm { min-height: 32px; padding: 4px 12px; font-size: 0.85rem; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { background: var(--solid-2); }
  .btn.primary:hover:not(:disabled) { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--bg); }
  .btn.danger:hover:not(:disabled) { opacity: 0.9; }
  .btn.ghost:hover:not(:disabled) { background: var(--raised); color: var(--text); }
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
/* кнопка с запросом «в пути»: вместо надписи крутится кружок, ширина кнопки не меняется (надпись остаётся невидимой) */
.btn[aria-busy="true"] { cursor: progress; position: relative; opacity: 1; }
.btn[aria-busy="true"] > .btn-label { visibility: hidden; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 16px; height: 16px; left: calc(50% - 8px); top: calc(50% - 8px);
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* пальцу 44 px: на телефоне высота кнопки больше, поля 16 px, чтобы iPhone не приближал страницу */
@media (pointer: coarse) {
  .btn { min-height: 44px; } .btn.sm { min-height: 44px; }
  input, select, textarea { font-size: 16px !important; }
}

/* ---- вкладки периода (сутки / неделя / месяц / свой): цвет, не поездка ---- */
.tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: var(--radius-sm); background: var(--raised); }
.tabs button {
  font: inherit; font-size: 0.9rem; font-weight: 550; cursor: pointer; min-height: 36px; padding: 4px 14px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text-2);
  transition: background-color 150ms ease, color 150ms ease;
}
.tabs button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--stroke); }
@media (hover: hover) and (pointer: fine) { .tabs button:hover { color: var(--text); } }
@media (pointer: coarse) { .tabs button { min-height: 44px; } }

/* ---- поля ---- */
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > label, .field > .lbl { font-size: 0.85rem; font-weight: 600; color: var(--text-2); }
.field input, .field select, .field textarea, input.in, select.in {
  font: inherit; color: var(--text); background: var(--surface); width: 100%; min-width: 0; min-height: 40px;
  border: 1px solid var(--stroke-2); border-radius: var(--radius-sm); padding: 8px 12px;
  transition: border-color 150ms ease, background-color 150ms ease;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input::placeholder { color: var(--text-3); }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input:disabled, .field select:disabled { opacity: 0.55; cursor: not-allowed; background: var(--raised); }
.field.bad input, .field.bad select { border-color: var(--bad); }
.field .hint { font-size: 0.82rem; color: var(--text-3); }
.field .err { font-size: 0.82rem; color: var(--bad-ink); font-weight: 550; }  /* текст ошибки, не только красная рамка */
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; position: relative; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.check::before { content: ""; position: absolute; inset: -2px -8px; }  /* зона нажатия больше самой галочки */
@media (pointer: coarse) { .check { min-height: 44px; } .check input { width: 22px; height: 22px; } }
select { color-scheme: inherit; }

/* ---- таблица ---- */
.board { background: var(--surface); border: 1px solid var(--stroke); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--stroke); }
th { font-size: 0.72rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
/* ячейка с названием: занимает остаток ширины и режет длинное название многоточием, остальные колонки не ломаются */
td.name { max-width: 0; width: 100%; }
td.name .cut { display: block; font-weight: 550; }
tr.problem td { background: var(--bad-soft); }
@media (hover: hover) and (pointer: fine) { a.row:hover td, tr.link:hover td { background: var(--raised); } }

/* таблица на телефоне: строка становится карточкой, название сверху на всю ширину, у чисел подпись колонки из data-l
   (таблица не листается вбок, название не сжимается до двух букв) */
@media (max-width: 560px) {
  table.tbl-card thead { display: none; }
  table.tbl-card, table.tbl-card tbody { display: block; }
  table.tbl-card tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 10px 12px; border-bottom: 1px solid var(--stroke); }
  table.tbl-card tbody tr:last-child { border-bottom: 0; }
  table.tbl-card td { padding: 0; border: 0; text-align: left; background: none !important; }
  table.tbl-card td.name { flex: 1 0 100%; max-width: 100%; width: auto; min-width: 0; overflow: hidden; }
  table.tbl-card td[data-l]::before { content: attr(data-l) " "; color: var(--text-3); font-size: 0.8rem; font-weight: 500; }
  table.tbl-card tr.problem { background: var(--bad-soft); }
}

/* ---- чипы статуса: слово и значок формы, цвет лишь усиливает ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 0.8rem; font-weight: 650; white-space: nowrap; vertical-align: middle;
  background: var(--raised); color: var(--text-2);
}
.chip::before { content: ""; width: 8px; height: 8px; flex: none; background: currentColor; }
.chip.ok { background: var(--ok-soft); color: var(--ok-ink); }          /* Онлайн: круг */
.chip.ok::before { border-radius: 50%; }
.chip.bad { background: var(--bad-soft); color: var(--bad-ink); }       /* Офлайн: квадрат */
.chip.unk { background: var(--raised); color: var(--text-2); }          /* Неизвестно: пустой круг */
.chip.unk::before { background: transparent; border: 2px solid currentColor; border-radius: 50%; }
.chip.warn { background: var(--warn-soft); color: var(--warn-ink); }    /* упёрлось в CPU: треугольник */
.chip.warn::before { width: 9px; height: 8px; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.chip.test { background: var(--accent-soft); color: var(--accent-ink); } /* шёл тест скорости: точка, дышит одним pulse на весь сайт */
.chip.test::before { border-radius: 50%; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ---- баннеры: слово «внимание» в тексте, а не только цвет ---- */
.banner {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; margin: 0 0 16px;
  border: 1px solid var(--stroke); border-left-width: 4px; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 0.95rem; line-height: 1.4;
}
.banner > :first-child { min-width: 0; overflow-wrap: anywhere; }
.banner.bad { border-left-color: var(--bad); background: var(--bad-soft); }
.banner.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.banner.info { border-left-color: var(--accent); background: var(--accent-soft); }
.banner b { font-weight: 700; }
.flash { min-height: 1.4em; font-size: 0.9rem; color: var(--text-2); }
.flash.ok { color: var(--ok-ink); } .flash.err { color: var(--bad-ink); font-weight: 550; }

/* ---- карточки и показатели ---- */
.card { background: var(--surface); border: 1px solid var(--stroke); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.stack > .banner { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 12px; }
.stat { display: grid; gap: 2px; align-content: start; }
.stat-k { font-size: 0.82rem; font-weight: 600; color: var(--text-2); }
.stat-v { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-v small { font-size: 0.9rem; font-weight: 600; color: var(--text-2); letter-spacing: 0; }
.stat-s { font-size: 0.82rem; color: var(--text-3); }
.stat.bad .stat-v { color: var(--bad-ink); }
.empty { padding: 40px 16px; text-align: center; color: var(--text-2); }
.empty b { display: block; margin-bottom: 4px; color: var(--text); font-weight: 650; }
.empty.err { color: var(--bad-ink); }

/* ---- полоса заполнения: ширина не анимируется, растёт transform: scaleX (240 мс); значение рядом словом ---- */
.meter { display: flex; align-items: center; gap: 10px; min-width: 0; }
.meter-bar { flex: 1 1 auto; min-width: 40px; height: 8px; border-radius: 999px; background: var(--raised); overflow: hidden; }
.meter-bar > i { display: block; height: 100%; width: 100%; border-radius: inherit; background: var(--accent); transform-origin: left center; transition: transform 240ms var(--ease-out), background-color 300ms ease; }
.meter.ok .meter-bar > i { background: var(--ok); }
.meter.warn .meter-bar > i { background: var(--warn); }
.meter.bad .meter-bar > i { background: var(--bad); }
.meter-val { flex: none; font-size: 0.85rem; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 4ch; text-align: right; }
.meter.na .meter-bar > i { transform: scaleX(0); }

/* ---- скелетон: невидим 200 мс, потом дышит ---- */
.skel { display: grid; gap: 14px; animation: sk-in 200ms ease-out 200ms both; }
.sk { background: var(--skel); border-radius: var(--radius); animation: sk-pulse 1.1s ease-in-out 400ms infinite alternate; }
.sk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 12px; }
.sk-card { height: 96px; } .sk-hero { height: 168px; }
.sk-line { height: 16px; width: 58%; border-radius: 8px; } .sk-line.short { width: 34%; }
.sk-rows { display: grid; gap: 8px; } .sk-row { height: 44px; border-radius: 10px; }
.sk-head { height: 24px; width: 180px; max-width: 60%; border-radius: 8px; }
@keyframes sk-in { from { opacity: 0; } }
@keyframes sk-pulse { from { opacity: 1; } to { opacity: 0.45; } }
/* reduced motion: пульса нет, но 200 мс до показа остаются: это проявление, не движение */
@media (prefers-reduced-motion: reduce) { .skel { animation: sk-in 200ms ease-out 200ms both !important; } }
/* контент занимает место скелетона коротким проявлением (только opacity: у липких предков нельзя transform) */
:where(#root > :not(.skel)) { animation: page-in 180ms var(--ease-out); }
@keyframes page-in { from { opacity: 0; } }

/* ---- печать: всегда светлая, без кнопок ---- */
@media print {
  body { background: #fff; color: #000; }
  .btn, .tabs, .no-print { display: none !important; }
  .card, .board { box-shadow: none; }
}

/* ---- график: высота задана заранее (--ch + строка легенды), пустой период держит ту же высоту ---- */
.chart { position: relative; min-height: calc(var(--ch, 200px) + 34px); min-width: 0; }
.chart .u-legend th, .chart .u-legend td { padding: 0; border: 0; text-align: left; text-transform: none; letter-spacing: 0; font-size: inherit; font-weight: 500; white-space: nowrap; color: inherit; }
.chart .u-legend { font-size: 0.8rem; color: var(--text-2); text-align: left; min-height: 26px; }
.chart .u-legend .u-series { padding: 2px 8px 2px 0; }
.chart .u-legend .u-marker { border-radius: 2px; }
.chart .u-legend .u-value { font-variant-numeric: tabular-nums; }
.chart .u-cursor-x, .chart .u-cursor-y { border-color: var(--text-3); }
.chart-empty { position: absolute; inset: 0 0 34px 0; display: none; align-items: center; justify-content: center; text-align: center; padding: 0 16px; color: var(--text-2); pointer-events: none; }

/* ---- окно подтверждения ---- */
.dlg { width: min(420px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--stroke); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.dlg::backdrop { background: rgba(10, 12, 20, 0.45); }
.dlg[open] { animation: dlg-in 200ms var(--ease-out); }
@keyframes dlg-in { from { opacity: 0; transform: scale(0.96); } }
.dlg h3 { margin: 0 0 8px; font-size: 1.1rem; overflow-wrap: anywhere; }
.dlg-body { color: var(--text-2); margin-bottom: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@media (prefers-reduced-motion: reduce) { .dlg[open] { animation: none !important; } }

/* ---- период ---- */
.period { display: grid; gap: 10px; justify-items: start; }
.period-custom { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.period-custom .field { width: 160px; }
.measure { display: grid; gap: 6px; justify-items: start; }
