/* MTWG — уральский стиль: малахит, медь, сусальное золото, берёста.
   Две темы: тёмная (по умолчанию) и светлая «берёста». Тема задаётся атрибутом
   <html data-theme="dark|light">, его выставляет /assets/js/theme.js до первой отрисовки. */

/* ----- Тёмная тема (базовая) ----- */
:root {
  --malachite-950: #041611;
  --malachite-900: #06201a;
  --malachite-800: #0b2e26;
  --malachite-700: #124a3e;
  --malachite-500: #1f7a63;
  --malachite-300: #5fbf9f;
  --copper-600: #9a5d2b;
  --copper-400: #c8844a;
  --copper-300: #e0a062;
  --gold: #d9b25f;

  --bg: var(--malachite-900);
  --bg-glow:
    radial-gradient(1200px 600px at 10% -10%, rgba(31, 122, 99, 0.35), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(200, 132, 74, 0.18), transparent 55%);

  --text: #f2ead8;
  --text-muted: #a9bdb2;
  --text-on-primary: #fff8ec;
  --text-danger: #ffd3cc;
  --text-warn: #f7e2b3;
  --text-code: #e9f5ef;
  --text-event-error: #ffb4a8;
  --accent-text: var(--gold);
  --link: var(--gold);
  --link-hover: var(--copper-300);
  --brand-mark: var(--malachite-300);

  --surface: linear-gradient(180deg, rgba(18, 74, 62, 0.55), rgba(11, 46, 38, 0.72));
  --surface-solid: var(--malachite-800);
  --surface-sunken: rgba(4, 22, 17, 0.55);
  --surface-input: rgba(4, 22, 17, 0.75);
  --surface-header: rgba(4, 22, 17, 0.88);
  --surface-th: rgba(4, 22, 17, 0.5);
  --surface-btn: rgba(4, 22, 17, 0.6);
  --surface-btn-hover: rgba(31, 122, 99, 0.35);
  --surface-row-hover: rgba(31, 122, 99, 0.18);
  --surface-item: rgba(10, 36, 30, 0.45);
  --surface-code: rgba(2, 10, 8, 0.8);
  --surface-menu-item: var(--malachite-900);

  --line: rgba(217, 178, 95, 0.22);
  --line-soft: rgba(217, 178, 95, 0.12);
  --line-strong: rgba(217, 178, 95, 0.5);
  --line-input: rgba(217, 178, 95, 0.28);
  --line-card-inner: rgba(217, 178, 95, 0.12);
  --gold-tint: rgba(217, 178, 95, 0.12);
  --focus: var(--gold);
  --focus-ring: rgba(217, 178, 95, 0.18);
  --backdrop: rgba(2, 10, 8, 0.7);

  /* Цвета кнопок подобраны так, чтобы белый текст держал 4.5:1 на всём градиенте */
  --primary-from: #9a5d2b;
  --primary-to: #7f4a22;
  --primary-hover-from: #a5622f;
  --primary-hover-to: #8c5126;
  --primary-border: rgba(224, 160, 98, 0.7);
  --primary-shadow: rgba(154, 93, 43, 0.35);
  --primary-shadow-hover: rgba(200, 132, 74, 0.45);

  --ok: #6fd3a6;
  --warn: #e8b65a;
  --danger: #ec7f72;
  --ok-line: rgba(111, 211, 166, 0.6);
  --warn-line: rgba(232, 182, 90, 0.5);
  --danger-line: rgba(224, 105, 91, 0.6);
  --warn-bg: rgba(232, 182, 90, 0.08);
  --danger-bg: rgba(224, 105, 91, 0.2);
  --danger-bg-soft: rgba(224, 105, 91, 0.08);
  --copper-text: var(--copper-300);

  --meter-track: rgba(217, 178, 95, 0.12);
  --meter-fill: var(--malachite-300);
  --ornament: var(--copper-400);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 30px 60px rgba(0, 0, 0, 0.6);
  --ease: 180ms ease;
  --font-head: 'Philosopher', 'Georgia', serif;
  --font-body: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;

  color-scheme: dark;
}

/* ----- Светлая тема «берёста» ----- */
:root[data-theme='light'] {
  --bg: #f4eee0;
  --bg-glow:
    radial-gradient(1200px 600px at 10% -10%, rgba(31, 122, 99, 0.12), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(200, 132, 74, 0.14), transparent 55%);

  --text: #17302a;
  --text-muted: #55685f;
  --text-on-primary: #fffaf0;
  --text-danger: #8e2a20;
  --text-warn: #6b4a10;
  --text-code: #17302a;
  --text-event-error: #a63a2e;
  --accent-text: #8a5f14;
  --link: #1f6f58;
  --link-hover: #155444;
  --brand-mark: #1f7a63;

  --surface: linear-gradient(180deg, #fffdf6, #f8f2e4);
  --surface-solid: #fffdf6;
  --surface-sunken: #f3ecd9;
  --surface-input: #fffdf8;
  --surface-header: rgba(255, 253, 246, 0.92);
  --surface-th: #efe6d0;
  --surface-btn: rgba(255, 253, 246, 0.85);
  --surface-btn-hover: rgba(31, 122, 99, 0.1);
  --surface-row-hover: rgba(31, 122, 99, 0.08);
  --surface-item: rgba(255, 253, 246, 0.75);
  --surface-code: #f1ead8;
  --surface-menu-item: #fffdf6;

  --line: rgba(154, 93, 43, 0.28);
  --line-soft: rgba(154, 93, 43, 0.16);
  --line-strong: rgba(154, 93, 43, 0.55);
  --line-input: rgba(154, 93, 43, 0.35);
  --line-card-inner: rgba(154, 93, 43, 0.14);
  --gold-tint: rgba(138, 95, 20, 0.12);
  --focus: #1f6f58;
  --focus-ring: rgba(31, 122, 99, 0.2);
  --backdrop: rgba(40, 30, 10, 0.35);

  --primary-from: #9e5a26;
  --primary-to: #8a4a1c;
  --primary-hover-from: #a25c28;
  --primary-hover-to: #8f4e1f;
  --primary-border: rgba(138, 74, 28, 0.6);
  --primary-shadow: rgba(138, 74, 28, 0.25);
  --primary-shadow-hover: rgba(138, 74, 28, 0.35);

  --ok: #17784f;
  --warn: #8f5e00;
  --danger: #b3372b;
  --ok-line: rgba(23, 120, 79, 0.45);
  --warn-line: rgba(143, 94, 0, 0.4);
  --danger-line: rgba(179, 55, 43, 0.45);
  --warn-bg: rgba(232, 182, 90, 0.18);
  --danger-bg: rgba(179, 55, 43, 0.12);
  --danger-bg-soft: rgba(179, 55, 43, 0.07);
  --copper-text: #8a4a1c;

  --meter-track: rgba(138, 95, 20, 0.14);
  --meter-fill: var(--malachite-500);
  --ornament: #9a5d2b;

  --shadow: 0 10px 28px rgba(64, 40, 12, 0.1);
  --shadow-lg: 0 24px 48px rgba(64, 40, 12, 0.2);

  color-scheme: light;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image:
    var(--bg-glow),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Cpath d='M24 4l20 20-20 20L4 24z' fill='none' stroke='%23808040' stroke-opacity='0.06'/%3E%3C/svg%3E");
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  transition: background-color 240ms ease, color 240ms ease;
}

h1, h2, h3 { font-family: var(--font-head); font-weight: 700; margin: 0 0 0.5rem; letter-spacing: 0.01em; line-height: 1.2; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { font-size: clamp(1.25rem, 3vw, 1.5rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--link); text-decoration: none; transition: color var(--ease); }
a:hover { color: var(--link-hover); text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; font-size: 0.85rem; word-break: break-all; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 0; background: var(--primary-from); color: var(--text-on-primary); padding: 0.5rem 1rem; z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }

/* ----- Шапка и навигация ----- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 2.5rem);
  background: var(--surface-header);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-family: var(--font-head); font-size: 1.25rem; color: var(--accent-text); font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--brand-mark); font-size: 1.1rem; }
.site-nav { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.site-nav .who { color: var(--text-muted); font-size: 0.9rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Переключатель темы: одна кнопка, иконка луны или солнца зависит от текущей темы. */
.theme-toggle { width: 38px; min-width: 38px; min-height: 38px; padding: 0; color: var(--accent-text); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme='light'] .theme-toggle .icon-sun { display: block; }
:root[data-theme='light'] .theme-toggle .icon-moon { display: none; }

.ornament {
  height: 14px;
  background-color: var(--ornament);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='14'%3E%3Cpath d='M0 7 L7 0 L14 7 L21 0 L28 7 L21 14 L14 7 L7 14 Z' fill='none' stroke='%23000' stroke-width='1' stroke-opacity='0.55'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='14'%3E%3Cpath d='M0 7 L7 0 L14 7 L21 0 L28 7 L21 14 L14 7 L7 14 Z' fill='none' stroke='%23000' stroke-width='1' stroke-opacity='0.55'/%3E%3C/svg%3E");
  -webkit-mask-repeat: repeat-x;
  mask-repeat: repeat-x;
  -webkit-mask-size: 28px 14px;
  mask-size: 28px 14px;
  opacity: 0.9;
}

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /* Строки не растягиваются на высоту экрана: иначе содержимое карточек расползается */
  align-content: start;
  gap: 1rem;
}
/* minmax(0, 1fr) не даёт широким таблицам и вкладкам раздвигать страницу */
.container > *, .panel > *, .grid-2 > *, .card > * { min-width: 0; }

.site-footer {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

/* ----- Карточки и блоки ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 2.5vw, 1.5rem);
  box-shadow: var(--shadow);
  position: relative;
}
.card::before {
  content: '';
  position: absolute; inset: 6px;
  border: 1px dashed var(--line-card-inner);
  border-radius: calc(var(--radius) - 6px);
  pointer-events: none;
}
.hero h1 { margin-bottom: 0.25rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.section-head h2 { margin: 0; }
.empty { padding: 1.5rem; text-align: center; color: var(--text-muted); border: 1px dashed var(--line); border-radius: var(--radius-sm); }

.grid-2 { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

.stats { display: grid; gap: 0.75rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat {
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  transition: transform var(--ease), border-color var(--ease);
}
.stat:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.stat .label { color: var(--text-muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat .value { font-family: var(--font-head); font-size: 1.6rem; color: var(--accent-text); font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--text-muted); font-size: 0.82rem; }

/* ----- Кнопки ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 42px; padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-btn);
  color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.95rem;
  cursor: pointer;
  transition: background-color var(--ease), border-color var(--ease), transform 150ms ease, box-shadow var(--ease), color var(--ease);
  user-select: none;
}
.btn:hover { background: var(--surface-btn-hover); border-color: var(--line-strong); text-decoration: none; }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(180deg, var(--primary-from), var(--primary-to));
  border-color: var(--primary-border);
  color: var(--text-on-primary);
  box-shadow: 0 4px 14px var(--primary-shadow);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--primary-hover-from), var(--primary-hover-to)); box-shadow: 0 6px 18px var(--primary-shadow-hover); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: var(--danger-line); color: var(--text-danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-small { min-height: 34px; padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* ----- Формы ----- */
.form-grid { display: grid; gap: 0.9rem 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .form-grid .full { grid-column: 1 / -1; } }
.field { display: grid; gap: 0.35rem; }
.field label, .field > span { font-size: 0.88rem; color: var(--text-muted); font-weight: 600; }
.field .hint { font-size: 0.8rem; color: var(--text-muted); }
input[type='text'], input[type='email'], input[type='password'], input[type='number'], input[type='date'], input[type='url'], input[type='tel'], input[type='search'], input:not([type]), select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-input);
  background: var(--surface-input);
  color: var(--text);
  color-scheme: inherit;
  font: inherit;
  transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9rem; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus-ring); outline: none; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }
input[readonly] { opacity: 0.75; cursor: not-allowed; }
input[aria-invalid='true'] { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg-soft); }
input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--primary-from); }
.check { display: flex; align-items: center; gap: 0.5rem; color: var(--text); font-size: 0.95rem; min-height: 42px; }
.field-error { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; margin: 0; }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin-top: 0.5rem; }
.form-status { font-size: 0.9rem; color: var(--text-muted); margin: 0; }
.form-status.ok { color: var(--ok); }
.form-status.err { color: var(--danger); }

/* ----- Бейджи и таблицы ----- */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 700;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-active { color: var(--ok); }
.badge-disabled { color: var(--text-muted); }
.badge-expired { color: var(--warn); }
.badge-limit { color: var(--copper-text); }
.badge-up { color: var(--ok); }
.badge-down { color: var(--danger); }
.badge-warn { color: var(--warn); }

.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { color: var(--accent-text); font-family: var(--font-head); font-weight: 700; font-size: 0.9rem; background: var(--surface-th); }
tbody tr { transition: background-color var(--ease); }
tbody tr:hover { background: var(--surface-row-hover); }
td .actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

@media (max-width: 719px) {
  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(--line); border-radius: var(--radius-sm); margin: 0.6rem; padding: 0.4rem 0; background: var(--surface-sunken); }
  table.responsive td { border: 0; padding: 0.35rem 0.8rem; display: grid; grid-template-columns: 110px 1fr; gap: 0.5rem; }
  table.responsive td::before { content: attr(data-label); color: var(--text-muted); font-size: 0.8rem; font-weight: 600; }
  table.responsive td.no-label { display: block; }
  table.responsive td.no-label::before { content: none; }
}

/* ----- Диалоги и уведомления ----- */
dialog.dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow-lg);
}
dialog.dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
dialog.dialog[open] { animation: pop 180ms ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.dialog-body { padding: 1.25rem; display: grid; gap: 1rem; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 0.6rem; flex-wrap: wrap; }
.dialog-head h2 { margin: 0; }
.iface-preview { border-top: 1px solid var(--line); padding-top: 1rem; display: grid; gap: 0.75rem; min-width: 0; }
.iface-preview h3 { margin: 0; }

/* ----- Состояние роутера ----- */
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 0.75rem 1rem; margin-bottom: 0.75rem; }
.card-head h2 { margin-bottom: 0.25rem; }
.card-head > div { min-width: 0; flex: 1 1 260px; }
.card-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.card-actions select { min-width: min(14rem, 100%); }
#st-body h3 { margin: 1rem 0 0.5rem; font-size: 1rem; }
.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.check-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 0.25rem 0.75rem; align-items: center;
  padding: 0.65rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-item);
}
.check-item.level-error { border-color: var(--danger-line); }
.check-item.level-warn { border-color: var(--line-strong); }
.check-item > div { min-width: 0; overflow-wrap: anywhere; }
.check-item > .btn { justify-self: end; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.6rem 1rem; margin: 0; }
.kv dt { color: var(--text-muted); font-size: 0.8rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.rule-list { margin: 0; padding-left: 1.25rem; display: grid; gap: 0.25rem; font-size: 0.9rem; overflow-wrap: anywhere; }
@media (max-width: 719px) {
  .check-item { grid-template-columns: minmax(0, 1fr); }
  .check-item > .btn { justify-self: start; }
}
pre.config {
  margin: 0; padding: 0.9rem; border-radius: var(--radius-sm);
  background: var(--surface-code); border: 1px solid var(--line);
  white-space: pre-wrap; word-break: break-all; font-size: 0.85rem; color: var(--text-code);
  max-height: 320px; overflow: auto;
}

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: 0.5rem; z-index: 50; max-width: min(380px, calc(100vw - 2rem)); }
.toast {
  padding: 0.75rem 1rem; border-radius: var(--radius-sm);
  background: var(--surface-solid); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text);
  animation: pop 180ms ease;
}
.toast.ok { border-color: var(--ok-line); }
.toast.err { border-color: var(--danger-line); color: var(--text-danger); }

/* ----- Вкладки ----- */
.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; }
.tab {
  flex: 0 0 auto; min-height: 40px; padding: 0.45rem 0.9rem; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--text-muted); font: inherit; font-weight: 600; cursor: pointer;
  transition: all var(--ease);
}
.tab:hover { color: var(--text); border-color: var(--line-strong); }
.tab[aria-selected='true'] { background: linear-gradient(180deg, var(--primary-from), var(--primary-to)); color: var(--text-on-primary); border-color: transparent; }
.panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.panel[hidden] { display: none; }

/* ----- Вход ----- */
.login-wrap { min-height: calc(100vh - 170px); display: grid; place-items: center; }
.login-card { width: min(440px, 100%); display: grid; align-content: start; gap: 1rem; }
.code-number {
  display: grid; place-items: center; padding: 1rem; border-radius: var(--radius-sm);
  background: var(--surface-input); border: 1px solid var(--line-strong);
}
.code-number .label { color: var(--text-muted); font-size: 0.85rem; }
.code-number .num-big { font-family: var(--font-head); font-size: 2.6rem; color: var(--accent-text); letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.timer { color: var(--text-muted); font-size: 0.88rem; }
.alert { padding: 0.75rem 0.9rem; border-radius: var(--radius-sm); border: 1px solid var(--warn-line); background: var(--warn-bg); color: var(--text-warn); font-size: 0.92rem; }
.alert.err { border-color: var(--danger-line); background: var(--danger-bg-soft); color: var(--text-danger); }
.code-input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; }

.inline-meta { color: var(--text-muted); font-size: 0.85rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

.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; }
.peer-name { font-weight: 700; color: var(--text); }
.route-pill { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); font-size: 0.8rem; color: var(--text-muted); }
.event { padding: 0.4rem 0; border-bottom: 1px dashed var(--line-soft); }
.event .t { color: var(--text-muted); font-size: 0.78rem; }
.event.warn .m { color: var(--warn); }
.event.error .m { color: var(--text-event-error); }
.router-row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ----- Подключения ----- */
.pd-section { display: grid; gap: 0.6rem; border-top: 1px solid var(--line); padding-top: 1rem; min-width: 0; }
.pd-section h3 { margin: 0; font-size: 1rem; }
.pd-actions { flex-wrap: wrap; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; margin-bottom: 0.75rem; }
.crumb-sep { color: var(--text-muted); }
.crumb-current { font-weight: 600; padding: 0 0.4rem; }
.drill-subtitle { margin: 1.25rem 0 0.5rem; font-size: 1rem; }
.qr-box { display: flex; justify-content: center; align-items: center; min-height: 200px; }
/* QR всегда на белом фоне: сканеры требуют контраста в любой теме. */
.qr-box img { background: #fff; padding: 0.5rem; border-radius: var(--radius-sm); max-width: 100%; height: auto; }
.meter { height: 6px; margin-top: 0.35rem; border-radius: 3px; background: var(--meter-track); border: 1px solid var(--line-soft); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--meter-fill); border-radius: 3px; transition: width 180ms ease; }

/* ----- ФСБ: карта связей и история по дням ----- */
.fsb-legend { margin: 0 0 0.5rem; }
.fsb-swatch { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 3px; background: var(--danger); vertical-align: -0.1rem; }
.fsb-graph { width: 100%; height: auto; display: block; }
.fsb-graph text { fill: currentColor; font-size: 13px; }
.fsb-graph .fsb-user, .fsb-graph .fsb-ip { fill: var(--gold-tint); stroke: var(--line); stroke-width: 1; }
.fsb-graph .fsb-ip.shared { stroke: var(--danger); stroke-width: 2; }
.fsb-graph .fsb-node { cursor: pointer; }
.fsb-graph .fsb-node:hover rect { stroke: var(--focus); }
.fsb-graph .fsb-edge { fill: none; stroke: var(--gold); opacity: 0.45; }
.fsb-graph .fsb-edge.shared { stroke: var(--danger); opacity: 0.8; }
.fsb-graph .fsb-edge:hover { opacity: 1; }
.fsb-graph .fsb-edge-label { font-size: 11px; fill: var(--text-muted); text-anchor: middle; }
.fsb-timeline { position: relative; display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 8px; }
.fsb-overlay { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.fsb-overlay path { fill: none; stroke: var(--gold); stroke-width: 1.5; opacity: 0.7; }
.fsb-day { flex: 0 0 260px; min-width: 260px; }
.fsb-day h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.fsb-group { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px; margin-bottom: 8px; }
.fsb-group-head { font-weight: 600; padding: 4px 6px; border-radius: 6px; background: var(--gold-tint); word-break: break-all; }
.fsb-group-head.shared { color: var(--danger); }
.fsb-block { border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: 6px; padding: 6px 8px; margin-top: 6px; font-size: 0.85rem; }
.fsb-block.shared { border-left-color: var(--danger); }

/* ----- Кабинет менеджера: группа ----- */
.group-ifaces { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.75rem; margin-bottom: 0.5rem; }
.group-iface { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.75rem; display: grid; gap: 0.35rem; }

/* ----- Вкладки раздела «Мониторинг» отличаются от основных ----- */
.subtabs { margin-bottom: 0.25rem; gap: 0.3rem; }
.subtabs .tab { min-height: 32px; padding: 0.3rem 0.8rem; font-size: 0.88rem; border-radius: var(--radius-sm); }
.subtabs .tab[aria-selected='true'] { background: var(--gold-tint); color: var(--accent-text); border-color: var(--focus); }

/* ===== Адаптация под телефон ===== */
@media (max-width: 719px) {
  .brand { font-size: 1.05rem; }
  .site-header { gap: 0.5rem; padding-top: calc(0.7rem + env(safe-area-inset-top)); }
  .site-nav { gap: 0.5rem; }
  .site-nav .who { max-width: 130px; }
  .site-nav .btn { min-height: 38px; padding: 0.35rem 0.8rem; }

  .tab { min-height: 36px; padding: 0.35rem 0.7rem; font-size: 0.9rem; }

  /* Диалоги выезжают снизу, как шторка; кнопки внизу на всю ширину */
  dialog.dialog {
    position: fixed; inset: auto 0 0 0; margin: 0;
    width: 100%; max-width: 100%; max-height: 92vh;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  dialog.dialog[open] { animation: sheet 220ms ease; }
  @keyframes sheet { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  .dialog-body { padding: 1rem 1rem 1.25rem; }
  .dialog-foot { position: sticky; bottom: 0; background: var(--surface-solid); padding: 0.75rem 0 0; margin-top: 0.25rem; border-top: 1px solid var(--line); }
  .dialog-foot .btn { flex: 1 1 calc(50% - 0.3rem); }
  .dialog-head h2 { font-size: 1.15rem; }

  /* Кнопки в карточках строк — крупнее и на всю ширину */
  .router-row-actions .btn, .card-actions .btn { flex: 1 1 auto; }
  .btn-small { min-height: 40px; padding: 0.45rem 0.85rem; }
  .card-actions { width: 100%; }
  .card-actions select, .card-actions input[type="search"] { min-width: 0; width: 100%; }
  .card-head { flex-direction: column; align-items: stretch; }
  .card-head > div { flex: 0 0 auto; width: 100%; }
  .card-head .btn { width: 100%; }
  .card-head .card-actions .btn { flex: 1 1 calc(50% - 0.25rem); }

  /* Поля и выпадающие списки высотой под палец */
  select, input, textarea { min-height: 44px; }
  textarea { min-height: 88px; }

  /* Уведомления во всю ширину над нижней полосой */
  .toasts { left: 0.75rem; right: 0.75rem; bottom: calc(0.75rem + env(safe-area-inset-bottom)); max-width: none; }

  /* Граф ФСБ: горизонтальная прокрутка, текст остаётся читаемым */
  .fsb-scroll { overflow-x: auto; margin: 0 -0.25rem; padding: 0 0.25rem 0.5rem; }
  .fsb-graph { min-width: 640px; }
  .fsb-legend { font-size: 0.85rem; }

  /* Мобильная навигация: круговое меню разделов. На широком экране скрыто, вкладки вверху остаются. */
  nav.tabs:not(.subtabs) { display: none; }
  #admin-app { padding-bottom: 96px; }
}

@media (max-width: 380px) {
  table.responsive td { grid-template-columns: 90px 1fr; }
  .stats { gap: 0.6rem; }
  .stat { padding: 0.8rem; }
  .stat .value { font-size: 1.35rem; }
}

.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.field-pair .field { min-width: 0; }
.field-pair input[type="date"] { min-width: 0; }
@media (max-width: 380px) { .field-pair { grid-template-columns: minmax(0, 1fr); } }

/* Проверка браузера перед отправкой кода: шахматная сетка, клетки заполняются случайными цветами. */
.pow { display: grid; gap: 0.7rem; margin: 0.25rem 0 0.5rem; }
.pow[hidden] { display: none; }
/* Заголовок «Проверка» — шрифт Ruslan Display, по бокам — ромбовый орнамент. */
.pow-title {
  margin: 0.2rem 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  font-family: 'Ruslan Display', var(--font-head), serif;
  font-weight: 400;
  font-size: 1.6rem;
  line-height: 1.2;
  color: var(--accent-text);
  letter-spacing: 0.02em;
}
.pow-orn {
  flex: 0 0 64px;
  height: 12px;
  background-color: var(--gold);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='12' viewBox='0 0 64 12'%3E%3Cpath d='M0 6H20M44 6H64' stroke='%23000' stroke-width='1.2'/%3E%3Cpath d='M26 1L31 6L26 11L21 6Z M42 1L47 6L42 11L37 6Z' fill='%23000'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='12' viewBox='0 0 64 12'%3E%3Cpath d='M0 6H20M44 6H64' stroke='%23000' stroke-width='1.2'/%3E%3Cpath d='M26 1L31 6L26 11L21 6Z M42 1L47 6L42 11L37 6Z' fill='%23000'/%3E%3C/svg%3E") center / contain no-repeat;
}
/* Двойная рамка в народном стиле. */
.pow-frame {
  padding: 8px;
  border: 2px solid var(--gold);
  border-radius: 6px;
  background: var(--surface-input);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px var(--line-strong);
}
.pow-grid {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 3px;
}
.pow-cell { aspect-ratio: 1; border-radius: 3px; background: var(--gold-tint); transition: background 220ms ease; }
.pow-cell.dark { background: var(--surface-code); }
.pow-cell.light { background: var(--surface-sunken); }
.pow-text { margin: 0; color: var(--text-muted); font-size: 0.9rem; }
.pow-text strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* Состояние роутера на дашборде. */
.router-state { margin-top: 0.6rem; }
.router-kv { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.5rem 0.9rem; }
.router-kv > div { background: var(--surface-sunken); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.5rem 0.65rem; }
.router-kv dt { color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.router-kv dd { margin: 0.15rem 0 0; color: var(--text); font-variant-numeric: tabular-nums; }

/* Фильтры и сортировка роутеров на дашборде. */
.router-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.6rem; margin: 0.6rem 0 0.4rem; }

/* Круговое меню разделов на телефоне. На широком экране скрыто. */
.radial { display: none; }
.radial-scrim { position: fixed; inset: 0; z-index: 40; background: var(--backdrop); }
@media (max-width: 719px) {
  .radial { display: block; position: fixed; right: 16px; bottom: 20px; width: 56px; height: 56px; z-index: 50; }
  .radial-fab {
    position: absolute; left: 0; top: 0; width: 56px; height: 56px; border-radius: 50%;
    border: 0; background: var(--gold); color: var(--malachite-950); font-size: 28px; line-height: 1;
    display: grid; place-items: center; box-shadow: var(--shadow); cursor: pointer;
  }
  .radial-fab span { display: block; transition: transform 220ms ease; }
  .radial.open .radial-fab span { transform: rotate(45deg); }
  .radial-item {
    position: absolute; left: 28px; top: 28px; width: 42px; height: 42px;
    border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface-menu-item); color: var(--text);
    display: grid; place-items: center; cursor: pointer; opacity: 0; transform: translate(-50%, -50%) scale(0.2);
    transition: transform 260ms ease, opacity 200ms ease; transition-delay: calc(var(--i) * 22ms);
  }
  .radial-item svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .radial-item.on { background: var(--primary-from); border-color: var(--primary-from); color: var(--text-on-primary); }
  .radial.open .radial-item { opacity: 1; transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1); }
  .radial-item:focus-visible, .radial-fab:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
  .radial-caption {
    position: absolute; right: 68px; bottom: 16px; margin: 0; white-space: nowrap; padding: 6px 12px;
    border-radius: 999px; background: var(--surface-menu-item); border: 1px solid var(--line); color: var(--text); font-size: 0.85rem;
    transition: opacity 200ms ease;
  }
  .radial.open .radial-caption { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .radial-item, .radial-fab span { transition: none; }
}
