/* ==========================================================================
   vipien admin — базовые стили.

   Ничего внешнего: системные шрифты, никаких @import, никаких CDN.
   Тема — prefers-color-scheme, с ручным переопределением [data-theme].

   Палитра тёплая, спокойная: кремовый фон, тёплый тёмно-серый текст,
   терракотовый акцент. Статусы приглушённые — панель смотрят ночью, когда
   что-то сломалось, и кислотные цвета в этот момент только мешают.

   Шрифт — Futura, проприетарная: скачать её нельзя, поэтому подключаем
   стеком. На macOS возьмётся настоящая Futura, на остальных системах —
   близкие геометрические гротески. У Futura маленькая x-height, поэтому
   базовый кегль 16px и увеличенный межстрочный интервал; цифры в таблицах
   и логи — моноширинным, там геометрический гротеск читается плохо.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --font-ui: "Futura", "Futura PT", "Avenir Next", "Avenir", "Century Gothic",
             "Questrial", "Jost", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "DejaVu Sans Mono", "Liberation Mono", monospace;

  --radius: 14px;
  --radius-sm: 10px;
  --gap: 20px;
  --maxw: 1240px;

  /* ---- светлая тема (по умолчанию) ---- */
  --bg: #F5F4EF;
  --bg-elev: #FAF9F5;
  --bg-sunken: #EFEDE5;
  --bg-hover: #EDEAE0;
  --fg: #1F1E1D;
  --fg-muted: #5C5851;          /* 6,9:1 на --bg-elev */
  --fg-faint: #767068;          /* 4,8:1 на --bg-elev */
  --border: #E4E1D8;
  --border-strong: #CFC9BC;

  --accent: #D97757;            /* терракота: линии графиков, активные рамки, тумблеры */
  --accent-ink: #B4512B;        /* тот же цвет для текста и ссылок: 4,8:1 на карточке */
  --accent-fg: #FFFFFF;
  --accent-soft: #F3E7E0;
  /* кнопка отдельной парой: чистая терракота с белым даёт всего 3,1:1 */
  --btn-bg: #B4512B;            /* 5,1:1 с белым */
  --btn-bg-hover: #9C4524;      /* 6,4:1 */
  --btn-fg: #FFFFFF;
  /* декоративные «лампы» светофора: не несут текста, поэтому теплее и светлее */
  --lamp-green: #5C9173;
  --lamp-yellow: #C99A34;
  --lamp-red: #C4593A;

  --green: #3F6F53;
  --green-soft: #E6EDE6;
  --yellow: #85661F;
  --yellow-soft: #F4EEDC;
  --red: #A8442A;
  --red-soft: #F6E6DF;
  --gray-soft: #EAE7DE;

  --focus: #B4512B;
  --shadow: none;
  --shadow-lg: 0 12px 40px rgba(31, 30, 29, .16);

  /* палитра серий графиков: приглушённая и различимая между собой —
     терракота, приглушённая бирюза, олива, янтарь, слива */
  --chart-1: #C4623F;
  --chart-2: #4E7C8A;
  --chart-3: #6E7F52;
  --chart-4: #A67C3D;
  --chart-5: #7A6A8C;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1F1E1D;
    --bg-elev: #262624;
    --bg-sunken: #2C2B28;
    --bg-hover: #33322E;
    --fg: #F0EEE8;
    --fg-muted: #B5AFA4;
    --fg-faint: #9A948B;
    --border: #383630;
    --border-strong: #4E4B44;

    --accent: #D97757;
    --accent-ink: #E4906F;      /* на угольном фоне светлее — 6,2:1 */
    --accent-fg: #1F1E1D;
    --accent-soft: #35291F;
    --btn-bg: #E4906F;          /* 6,6:1 с тёмным текстом */
    --btn-bg-hover: #EFA184;
    --btn-fg: #241F1C;
    --lamp-green: #8FBFA1;
    --lamp-yellow: #D6B571;
    --lamp-red: #E4917A;

    --green: #8FBFA1;
    --green-soft: #25302A;
    --yellow: #D6B571;
    --yellow-soft: #322A1C;
    --red: #E4917A;
    --red-soft: #33241F;
    --gray-soft: #2F2D28;

    --focus: #E4906F;
    --shadow: none;
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);

    --chart-1: #E2906F;
    --chart-2: #7FB3C0;
    --chart-3: #A3BE86;
    --chart-4: #D9B572;
    --chart-5: #B39CC7;
  }
}

/* ручное переопределение темы кнопкой в шапке — обе стороны, чтобы
   переключатель работал в любую сторону от системной настройки */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F5F4EF; --bg-elev: #FAF9F5; --bg-sunken: #EFEDE5; --bg-hover: #EDEAE0;
  --fg: #1F1E1D; --fg-muted: #5C5851; --fg-faint: #767068;
  --border: #E4E1D8; --border-strong: #CFC9BC;
  --accent: #D97757; --accent-ink: #B4512B; --accent-fg: #FFFFFF; --accent-soft: #F3E7E0;
  --btn-bg: #B4512B; --btn-bg-hover: #9C4524; --btn-fg: #FFFFFF;
  --lamp-green: #5C9173; --lamp-yellow: #C99A34; --lamp-red: #C4593A;
  --green: #3F6F53; --green-soft: #E6EDE6;
  --yellow: #85661F; --yellow-soft: #F4EEDC;
  --red: #A8442A; --red-soft: #F6E6DF; --gray-soft: #EAE7DE;
  --focus: #B4512B; --shadow: none;
  --chart-1: #C4623F; --chart-2: #4E7C8A; --chart-3: #6E7F52; --chart-4: #A67C3D; --chart-5: #7A6A8C;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1F1E1D; --bg-elev: #262624; --bg-sunken: #2C2B28; --bg-hover: #33322E;
  --fg: #F0EEE8; --fg-muted: #B5AFA4; --fg-faint: #9A948B;
  --border: #383630; --border-strong: #4E4B44;
  --accent: #D97757; --accent-ink: #E4906F; --accent-fg: #1F1E1D; --accent-soft: #35291F;
  --btn-bg: #E4906F; --btn-bg-hover: #EFA184; --btn-fg: #241F1C;
  --lamp-green: #8FBFA1; --lamp-yellow: #D6B571; --lamp-red: #E4917A;
  --green: #8FBFA1; --green-soft: #25302A;
  --yellow: #D6B571; --yellow-soft: #322A1C;
  --red: #E4917A; --red-soft: #33241F; --gray-soft: #2F2D28;
  --focus: #E4906F; --shadow: none;
  --chart-1: #E2906F; --chart-2: #7FB3C0; --chart-3: #A3BE86; --chart-4: #D9B572; --chart-5: #B39CC7;
}

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

/* Карточная раскладка таблиц переопределяет display у <tr>/<td> и тем самым
   перебивает браузерное правило для [hidden]. Свёрнутые строки-раскрытия
   из-за этого показывались на узком экране всегда — возвращаем скрытие. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.3; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .9em; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
small { font-size: .86em; }
ul, ol { padding-left: 1.3em; }
li { margin-bottom: .35em; }

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

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--btn-bg); color: var(--btn-fg);
  padding: 12px 18px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- каркас */

.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 20px 14px 26px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 11px;
  font-weight: 600; font-size: 1.1rem; letter-spacing: .01em;
  padding: 4px 12px 20px;
  color: var(--fg); text-decoration: none;
}
.brand .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--fg-faint); flex: none; }
.brand .dot[data-status="green"]  { background: var(--green); }
.brand .dot[data-status="yellow"] { background: var(--yellow); }
.brand .dot[data-status="red"]    { background: var(--red); }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: var(--radius-sm);
  color: var(--fg); text-decoration: none; font-size: .97rem;
}
.nav a:hover { background: var(--bg-hover); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav .ico { width: 20px; text-align: center; flex: none; font-size: 1rem; opacity: .85; }

.sidebar-foot { margin-top: auto; padding: 18px 12px 0; color: var(--fg-muted); font-size: .85rem; }
.sidebar-foot .logout-form { margin: 12px 0 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 16px 28px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.2rem; }
.topbar .spacer { margin-left: auto; }
.topbar-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-tools select, .topbar-tools input {
  width: auto; min-width: 120px; min-height: 36px; padding: 5px 12px; font-size: .9rem;
}
/* Скрытый чекбокс тумблера — не поле ввода: min-width из правила выше делал
   его шире дорожки, и на телефоне страница ездила вбок на пару пикселей. */
.topbar-tools .switch input { min-width: 0; width: 46px; padding: 0; }
.switch-text { font-size: .86rem; }

.burger { display: none; }

.content { padding: 28px; max-width: var(--maxw); width: 100%; }

/* ------------------------------------------------------------- элементы */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card + .card { margin-top: var(--gap); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { margin-left: auto; }
.card-sub { color: var(--fg-muted); font-size: .92rem; margin: -6px 0 16px; max-width: 76ch; }

.grid { display: grid; gap: var(--gap); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

.kpi {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
}
.kpi .label { color: var(--fg-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; }
.kpi .value {
  font-size: 1.75rem; font-weight: 600; line-height: 1.2; margin-top: 8px;
  letter-spacing: -.01em; word-break: break-word; font-variant-numeric: tabular-nums;
}
.kpi .hint { color: var(--fg-muted); font-size: .87rem; margin-top: 6px; }

/* кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: .93rem; font-weight: 500;
  padding: 9px 16px; min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--fg);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--btn-bg); border-color: var(--btn-bg); color: var(--btn-fg); }
.btn-primary:hover { background: var(--btn-bg-hover); border-color: var(--btn-bg-hover); color: var(--btn-fg); }
.btn-danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn-danger:hover { background: var(--red-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: .87rem; }
.btn-block { width: 100%; }
/* нажатое состояние переключателей периода видно, а не только озвучено */
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }

/* формы */
label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: 7px; }
.field { margin-bottom: 18px; }
.field .help, .help { color: var(--fg-muted); font-size: .86rem; margin-top: 7px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"],
input[type="date"], input[type="datetime-local"], select, textarea {
  width: 100%; font: inherit; font-size: .95rem;
  padding: 10px 13px; min-height: 42px;
  color: var(--fg); background: var(--bg-elev);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
input:hover, select:hover, textarea:hover { border-color: var(--fg-faint); }
/* место под системную стрелку: иначе длинный вариант наезжает на неё */
select { padding-right: 34px; }
textarea { min-height: 140px; font-family: var(--font-mono); font-size: .85rem; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--fg-faint); }
input:disabled, select:disabled, textarea:disabled { background: var(--bg-sunken); color: var(--fg-muted); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent-ink); }
input[type="number"], input[type="date"], input[type="datetime-local"] { font-variant-numeric: tabular-nums; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; margin: 0 0 18px; }
legend { font-size: .9rem; font-weight: 600; padding: 0 8px; }
.inline-label { display: flex; align-items: center; gap: 10px; font-weight: 400; margin: 0; }
.form-grid { display: grid; gap: 0 20px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

/* переключатель */
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; margin: 0; }
.switch input { position: absolute; opacity: 0; width: 46px; height: 27px; margin: 0; cursor: pointer; }
.switch .track {
  width: 46px; height: 27px; border-radius: 14px; flex: none;
  background: var(--border-strong); position: relative; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%; background: #fff;
  transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(19px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

/* бейджи и индикаторы состояния */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 11px; border-radius: 999px;
  font-size: .8rem; font-weight: 500; white-space: nowrap;
  background: var(--gray-soft); color: var(--fg-muted);
}
.badge.green  { background: var(--green-soft);  color: var(--green); }
.badge.yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge.red    { background: var(--red-soft);    color: var(--red); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }

/* режим маршрутизации пира. full-tunnel — это «весь трафик устройства идёт
   за границу»: он должен читаться с одного взгляда, поэтому единственный
   залитый бейдж в таблице. Пара --btn-bg/--btn-fg даёт 5,1:1. */
.badge.mode-full {
  background: var(--btn-bg); color: var(--btn-fg); font-weight: 600;
  letter-spacing: .01em;
}
.badge.mode-selective { background: var(--gray-soft); color: var(--fg-muted); }

.light { display: inline-block; width: .72em; height: .72em; border-radius: 50%; background: var(--fg-faint); }
.light.green { background: var(--green); }
.light.yellow { background: var(--yellow); }
.light.red { background: var(--red); }

/* светофор состояния: приглушённые тона, форма и подпись несут смысл
   наравне с цветом — так его читают и при дальтонизме */
.traffic-light {
  display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap;
  border-radius: var(--radius); padding: 24px;
  border: 1px solid var(--border); background: var(--bg-elev);
}
.traffic-light.green  { background: var(--green-soft);  border-color: var(--green); }
.traffic-light.yellow { background: var(--yellow-soft); border-color: var(--yellow); }
.traffic-light.red    { background: var(--red-soft);    border-color: var(--red); }
.traffic-light .lamp {
  width: 40px; height: 40px; border-radius: 50%; flex: none; margin-top: 2px;
  background: var(--fg-faint); box-shadow: inset 0 0 0 6px rgba(255, 255, 255, .22);
}
/* «часть проверок не выполнилась» — отдельное состояние, а не зелёное и не
   поломка: серая рамка пунктиром и полая лампа, чтобы не читалось как «ок» */
.traffic-light.unknown { background: var(--bg-sunken); border-color: var(--border-strong); border-style: dashed; }
.traffic-light.unknown .lamp {
  background: transparent;
  box-shadow: inset 0 0 0 6px var(--border-strong);
}
.traffic-light.green .lamp  { background: var(--lamp-green); }
.traffic-light.yellow .lamp { background: var(--lamp-yellow); }
.traffic-light.red .lamp    { background: var(--lamp-red); }
.traffic-light .tl-title { font-size: 1.22rem; font-weight: 600; margin: 0 0 4px; }
.traffic-light .tl-text { margin: 0; color: var(--fg); max-width: 82ch; }
.traffic-light .tl-note { margin: 8px 0 0; color: var(--fg-muted); font-size: .92rem; max-width: 82ch; }

/* список проверок здоровья */
.checks { list-style: none; margin: 0; padding: 0; }
.checks li {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px; align-items: start;
  padding: 14px 2px; border-bottom: 1px solid var(--border);
}
.checks li:last-child { border-bottom: 0; }
.checks li:first-child { padding-top: 4px; }
.checks .light { margin-top: .42em; }
.checks .c-title { font-weight: 500; }
.checks .c-detail { color: var(--fg-muted); font-size: .9rem; }
.checks .c-hint { color: var(--fg-muted); font-size: .85rem; margin-top: 5px; }
.checks .c-value {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--fg-muted); font-size: .82rem; text-align: right;
}

/* таблицы */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-elev); color: var(--fg-muted);
  font-size: .74rem; font-weight: 500; text-transform: uppercase; letter-spacing: .06em;
  /* заголовки переносятся: иначе широкая таблица уезжает за экран и кнопки
     действий оказываются за горизонтальной прокруткой */
  white-space: normal;
  border-bottom-color: var(--border-strong);
}
table.data tbody tr:hover { background: var(--bg-hover); }
table.data .num { text-align: right; font-family: var(--font-mono); font-size: .85em; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* nowrap нужен цифрам, а не шапке: «Трафик (приём / отдача)» одной строкой
   раздувал колонку на 200 px и выталкивал «Состояние» под кнопки действий */
table.data thead th.num { white-space: normal; }
/* длинные значения переносятся, а не раздвигают таблицу за край карточки */
table.data td { overflow-wrap: break-word; }
/* колонка действий прижата к правому краю. Прилипание — страховка на случай
   прокрутки; в обычной ширине таблица помещается целиком и ничего не
   перекрывает (ниже 1200 px таблица вообще превращается в карточки) */
table.data .actions {
  white-space: nowrap; text-align: right; width: 1%;
  position: sticky; right: 0; background: var(--bg-elev);
  box-shadow: -8px 0 8px -8px rgba(31, 30, 29, .18);
}
table.data tbody tr:hover .actions { background: var(--bg-hover); }
table.data .actions .btn + .btn { margin-left: 6px; }
table.data .mono { font-family: var(--font-mono); font-size: .85em; }
table.data tfoot th, table.data tfoot td { font-weight: 600; border-top: 1px solid var(--border-strong); }
.empty { padding: 32px; text-align: center; color: var(--fg-muted); }

/* логи */
.logview {
  font-family: var(--font-mono); font-size: .82rem; line-height: 1.6;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow-x: auto; max-height: 62vh; overflow-y: auto;
}
.logview table { width: 100%; border-collapse: collapse; }
.logview td { padding: 4px 10px; vertical-align: top; white-space: pre-wrap; word-break: break-word; }
.logview td.ts { white-space: nowrap; color: var(--fg-muted); width: 1%; }
.logview td.src { white-space: nowrap; color: var(--accent-ink); width: 1%; }
.logview td.lvl { white-space: nowrap; width: 1%; font-weight: 700; }
.logview tr[data-level="error"] td.lvl, .logview tr[data-level="critical"] td.lvl { color: var(--red); }
.logview tr[data-level="warning"] td.lvl { color: var(--yellow); }
.logview tr[data-level="info"] td.lvl { color: var(--green); }
.logview tr[data-level="debug"] td.lvl { color: var(--fg-faint); }
.logview tr[data-level="error"], .logview tr[data-level="critical"] { background: var(--red-soft); }
.logview tr[data-level="warning"] { background: var(--yellow-soft); }
.logview mark { background: var(--accent-soft); color: var(--fg); font-weight: 700; border-radius: 3px; padding: 0 2px; }

/* графики */
.chart-box { position: relative; height: 270px; }
.chart-box.tall { height: 330px; }
.chart-box canvas { max-width: 100%; }

/* заметки */
.note {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  padding: 16px 18px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 0 0 var(--gap);
}
.note.warn { border-color: var(--yellow); background: var(--yellow-soft); }
.note.danger { border-color: var(--red); background: var(--red-soft); }
.note p:last-child { margin-bottom: 0; }
.note h3 { margin-top: 0; }

.kbd, code:not(pre code) {
  font-family: var(--font-mono); font-size: .84em;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px;
}
pre {
  font-family: var(--font-mono); font-size: .82rem; line-height: 1.6;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px; overflow-x: auto; margin: 0 0 14px;
}

details.sig { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0; margin-bottom: 10px; background: var(--bg-elev); }
details.sig > summary { padding: 13px 16px; cursor: pointer; font-weight: 500; list-style-position: inside; }
details.sig > summary:hover { background: var(--bg-hover); }
details.sig[open] > summary { border-bottom: 1px solid var(--border); }
details.sig > div { padding: 14px 16px 4px; }

/* модальные окна */
dialog.modal {
  width: min(720px, calc(100vw - 28px));
  max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-elev); color: var(--fg); box-shadow: var(--shadow-lg);
  overflow: auto;
}
dialog.modal::backdrop { background: rgba(31, 30, 29, .55); }
.modal-head {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-elev); z-index: 2;
}
.modal-head h2 { margin: 0; font-size: 1.12rem; }
.modal-head .spacer { margin-left: auto; }
.modal-body { padding: 24px; }
.modal-foot {
  display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; align-items: center;
  padding: 18px 24px; border-top: 1px solid var(--border);
  position: sticky; bottom: 0; background: var(--bg-elev);
}

/* QR */
.qr-box { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.qr-box img, .qr-box .qr-placeholder {
  width: 240px; height: 240px; flex: none;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px;
}
.qr-box .qr-placeholder { display: flex; align-items: center; justify-content: center; text-align: center; color: #4a4741; font-size: .82rem; }

/* уведомления */
.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  display: flex; flex-direction: column; gap: 10px; max-width: min(420px, calc(100vw - 36px));
}
.toast {
  background: var(--bg-elev); border: 1px solid var(--border-strong); border-left-width: 3px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 13px 16px; font-size: .9rem;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.info { border-left-color: var(--accent); }

/* страница входа */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 32px; }
.login-card .brand { justify-content: center; font-size: 1.3rem; padding-top: 0; }
.form-error {
  border: 1px solid var(--red); background: var(--red-soft); color: var(--red);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 18px; font-size: .9rem;
}
.otp-input { font-family: var(--font-mono); letter-spacing: .4em; text-align: center; font-size: 1.15rem; }

/* полоска-индикатор загрузки */
.busy-bar {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: var(--accent); z-index: 80; transition: width .2s ease-out; opacity: 0;
}
.busy-bar.on { width: 70%; opacity: 1; }

.pager { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.pager .info { color: var(--fg-muted); font-size: .88rem; }

.filters { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.filters .field { margin-bottom: 0; }

.bar-list { list-style: none; margin: 0; padding: 0; }
.bar-list li { padding: 10px 0; border-bottom: 1px solid var(--border); margin: 0; }
.bar-list li:last-child { border-bottom: 0; }
.bar-list .bl-head { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; }
.bar-list .bl-head .v { font-family: var(--font-mono); font-size: .85em; font-variant-numeric: tabular-nums; color: var(--fg-muted); }
.bar-list .bar { height: 6px; border-radius: 3px; background: var(--bg-sunken); margin-top: 7px; overflow: hidden; }
.bar-list .bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.mock-flag {
  background: var(--yellow-soft); color: var(--yellow);
  border: 1px solid var(--yellow); border-radius: 999px;
  padding: 5px 12px; font-size: .8rem; font-weight: 500;
}

/* ------------------------------------------------------------ адаптив */

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 272px; z-index: 50;
    transform: translateX(-100%); transition: transform .18s ease-out;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .burger { display: inline-flex; }
  .scrim { position: fixed; inset: 0; background: rgba(31, 30, 29, .45); z-index: 40; }
  .content { padding: 18px; }
  .topbar { padding: 12px 18px; }
  .card { padding: 20px; }
}

@media (max-width: 640px) {
  .kpi .value { font-size: 1.5rem; }
  .chart-box { height: 230px; }
  .traffic-light { padding: 18px; gap: 16px; }
  .traffic-light .lamp { width: 32px; height: 32px; }
  .modal-body { padding: 18px; }
  .modal-foot { flex-direction: column-reverse; align-items: stretch; padding: 16px 18px; }
  .modal-foot .btn { width: 100%; }
  .modal-foot .inline-label { margin-bottom: 6px; }
  .qr-box img, .qr-box .qr-placeholder { width: 100%; height: auto; aspect-ratio: 1; }

  /* таблицы превращаются в карточки: с телефона чинят VPN, а не листают вбок */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 12px; padding: 10px 14px; background: var(--bg-elev);
  }
  table.responsive td { border: 0; padding: 6px 0; display: flex; gap: 14px; justify-content: space-between; align-items: baseline; }
  table.responsive td::before {
    content: attr(data-label); color: var(--fg-muted); font-size: .76rem;
    text-transform: uppercase; letter-spacing: .07em; flex: none;
  }
  table.responsive td.actions { justify-content: flex-start; flex-wrap: wrap; text-align: left; gap: 8px; position: static; box-shadow: none; }
  table.responsive td.actions::before { width: 100%; }
  .checks li { grid-template-columns: auto minmax(0, 1fr); }
  .checks .c-value { grid-column: 2; text-align: left; }
}

/* Широкие таблицы (клиенты) требуют около 620 px только на содержимое.
   Боковое меню занимает 248 px и прячется лишь на 900 px, поэтому в полосе
   примерно 900–975 px места не хватает: там липкая колонка действий наезжала
   на «Состояние», и значение обрезалось на «не подк…». Ниже 1000 px
   переходим на тот же карточный вид, что и на телефоне: строка читается
   целиком, кнопки прижаты к низу карточки, ничего не перекрыто.
   Правила повторяют блок 640 px — раньше срабатывают только для .wide. */
@media (max-width: 1000px) {
  table.responsive.wide thead { display: none; }
  table.responsive.wide,
  table.responsive.wide tbody,
  table.responsive.wide tr,
  table.responsive.wide td { display: block; width: 100%; }
  table.responsive.wide tr {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 12px; padding: 10px 14px; background: var(--bg-elev);
  }
  table.responsive.wide tr:hover { background: var(--bg-elev); }
  table.responsive.wide td {
    border: 0; padding: 6px 0; display: flex; gap: 14px;
    justify-content: space-between; align-items: baseline; text-align: right;
  }
  table.responsive.wide td::before {
    content: attr(data-label); color: var(--fg-muted); font-size: .76rem;
    text-transform: uppercase; letter-spacing: .07em; flex: none; text-align: left;
  }
  table.responsive.wide td.empty { display: block; text-align: center; }
  table.responsive.wide td.empty::before { content: none; }
  table.responsive.wide td.actions {
    justify-content: flex-start; flex-wrap: wrap; text-align: left; gap: 8px;
    position: static; box-shadow: none; width: auto;
    margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--border);
  }
  table.responsive.wide td.actions::before { width: 100%; }
  table.responsive.wide td.actions .btn + .btn { margin-left: 0; }
  /* раскрытие строки приклеено к своей карточке, а не висит отдельной */
  table.responsive.wide tr.row-detail { padding: 0; border: 0; margin: -8px 0 12px; }
  table.responsive.wide tr.row-detail > td { display: block; text-align: left; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
  table.responsive.wide tr.row-detail > td::before { content: none; }
  /* «▸ имя» держатся вместе у правого края, а не расползаются по строке */
  table.responsive.wide td .row-toggle { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  .sidebar, .topbar-tools, .btn, .toasts { display: none !important; }
  .app { display: block; }
  .card { break-inside: avoid; }
}

/* ==========================================================================
   «Сначала главное, детали за кликом».

   Три размера раскрытия — от самого лёгкого к самому тяжёлому:
     details.more     — строчная ссылка «Подробнее» внутри карточки;
     details.section  — целый раздел страницы, свёрнутый в одну строку;
     tr.row-detail    — раскрытие строки таблицы под ней.
   Стиль общий с details.sig: рамка, тот же радиус, никаких новых цветов.
   ========================================================================== */

details.more { margin: 0 0 12px; }
details.more:last-child { margin-bottom: 0; }
details.more > summary {
  display: inline-flex; align-items: baseline; gap: 7px;
  cursor: pointer; color: var(--accent-ink);
  font-size: .88rem; padding: 2px 0;
  list-style: none;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::marker { content: ""; }
details.more > summary::before { content: "▸"; font-size: .78em; line-height: 1; }
details.more[open] > summary::before { content: "▾"; }
details.more > summary:hover { text-decoration: underline; }
details.more > .more-body {
  padding: 8px 0 2px; color: var(--fg-muted); font-size: .88rem; max-width: 76ch;
}
details.more > .more-body > :last-child { margin-bottom: 0; }
details.more > .more-body h3 { color: var(--fg); font-size: .95rem; margin: 14px 0 6px; }
details.more > .more-body h3:first-child { margin-top: 0; }

/* Раздел-аккордеон: выглядит как карточка, но свёрнут до заголовка. */
details.section {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius);
}
details.section + details.section,
details.section + .card, .card + details.section,
.note + details.section, details.section + .note { margin-top: var(--gap); }
details.section > summary {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding: 18px 24px; cursor: pointer; border-radius: var(--radius);
  list-style: none;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::marker { content: ""; }
details.section > summary:hover { background: var(--bg-hover); }
details.section[open] > summary { border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
details.section > summary .s-title { font-size: 1.2rem; font-weight: 600; letter-spacing: -.01em; }
details.section > summary .s-title::before { content: "▸ "; color: var(--fg-faint); font-size: .8em; }
details.section[open] > summary .s-title::before { content: "▾ "; }
details.section > summary .s-sub { color: var(--fg-muted); font-size: .88rem; }
details.section > summary .spacer { margin-left: auto; }
details.section > .section-body { padding: 22px 24px 24px; }
details.section > .section-body > :last-child { margin-bottom: 0; }

/* Панель фильтров: главное в строку, редкое — за «Ещё фильтры». */
.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: var(--gap);
}
.toolbar .field { margin-bottom: 0; }
.toolbar .field label { margin-bottom: 3px; font-size: .8rem; color: var(--fg-muted); }
.toolbar select, .toolbar input { min-width: 150px; width: auto; }
.toolbar .grow { flex: 1 1 200px; }
.toolbar .grow input { width: 100%; }
.toolbar .spacer { margin-left: auto; }

/* Раскрытие строки таблицы: редкие поля пира, аудита, статистики. */
.row-toggle {
  border: 0; background: none; color: var(--fg-muted); font: inherit;
  cursor: pointer; padding: 0 6px 0 0; line-height: 1;
}
.row-toggle::before { content: "▸"; display: inline-block; font-size: .8em; }
.row-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
tr.row-detail > td { background: var(--bg-sunken); padding: 12px 10px 16px; }
tr.row-detail .kv {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px 24px; margin: 0;
}
tr.row-detail .kv > div { min-width: 0; }
tr.row-detail .kv dt, tr.row-detail .kv .k {
  color: var(--fg-muted); font-size: .74rem;
  text-transform: uppercase; letter-spacing: .06em;
}
tr.row-detail .kv dd, tr.row-detail .kv .v { margin: 0; font-size: .9rem; word-break: break-word; }

/* Строка-итог под светофором: «зелёных N, проверено тогда-то». */
.line-sum {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  color: var(--fg-muted); font-size: .88rem;
}

@media (max-width: 640px) {
  details.section > summary { padding: 16px 18px; }
  details.section > .section-body { padding: 18px; }
  .toolbar select, .toolbar input { min-width: 0; width: 100%; }
  .toolbar .field { width: 100%; }
  table.responsive tr.row-detail { padding: 0; border: 0; margin: -8px 0 12px; }
  table.responsive tr.row-detail > td { display: block; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
  table.responsive tr.row-detail > td::before { content: none; }
}

/* Скрытые по умолчанию колонки-уточнения (приём/отдача в Статистике).
   Именно скрытые, а не удалённые: сортировка и выгрузка видят их всегда. */
table.hide-extra .col-extra { display: none !important; }

/* Селекты в шапке карточки — по содержимому, а не во всю строку:
   иначе два фильтра рядом разъезжаются на две строки во всю ширину. */
.card-head select, .card-head input, details.section > summary select {
  width: auto; min-width: 140px; min-height: 34px; padding: 4px 30px 4px 12px; font-size: .88rem;
}

/* На телефоне четыре карточки-цифры в один столбец отодвигают главное —
   список поломок — на второй экран. Ставим их по две. */
@media (max-width: 640px) {
  .grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .grid.cols-4 .kpi { padding: 14px 14px 16px; }
  .grid.cols-4 .kpi .label { font-size: .72rem; letter-spacing: .05em; }
  .grid.cols-4 .kpi .value { font-size: 1.3rem; margin-top: 4px; }
  .grid.cols-4 .kpi .hint { font-size: .8rem; }
}

/* Стрелка раскрытия держится вплотную к значению ячейки. */
.nowrap-name { display: inline-flex; align-items: baseline; gap: 2px; }

@media (max-width: 640px) {
  /* На узком экране заголовок раздела переносится, и прижатый вправо бейдж
     повисает посреди строки — выравниваем его по левому краю. */
  details.section > summary .spacer { display: none; }
  details.section > summary { gap: 4px 10px; }
}

/* На ноутбуке 1024 четыре карточки-цифры вставали «три плюс одна сиротой».
   Между телефоном и широким экраном раскладываем их сеткой 2×2. */
@media (min-width: 641px) and (max-width: 1150px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
