/* ============================================================================
   Orbita Admin — Data-RBAC. Фирстиль «Орбита» (редизайн, navy-first, как в
   R7-плагине): светлый холст, белые карточки, акцент navy #252563, зелёный
   успех, шрифты IBM Plex Sans/Mono. Мягкие тени, спокойная типографика.
   Шрифты с CDN + системный фолбэк для офлайна (см. index.html).
   ============================================================================ */

:root {
  /* Холст и поверхности (светлые). Имена navy-* сохранены как токены-слоты:
     чем меньше номер, тем «глубже» слой (холст -> инсеты). */
  --navy-950: #f4f6fb;   /* холст страницы */
  --navy-900: #ffffff;   /* карточки/панели (белый) */
  --navy-850: #f7f8fc;   /* очень светлая заливка (код, треки, верх карточек) */
  --navy-800: #eef1f7;   /* инсет-чип / тултип */
  --navy-700: #dfe3ee;   /* трек тумблера (выкл), ползунок скролла */

  /* Линии (тонкие, на светлом) */
  --line: #edeff5;
  --line-strong: #e0e3ec;

  /* Текст (тёмный navy на светлом) */
  --text: #1b2036;
  --text-dim: #5b6172;
  --text-faint: #8a90a2;

  /* Акцент «Орбита» = navy. Имена crimson-* сохранены как слоты акцента. */
  --crimson: #252563;         /* основной акцент (кнопки, активные состояния) */
  --crimson-bright: #3a3a86;  /* акцентный текст / ссылки / hover */
  --crimson-soft: #e7e8f4;    /* мягкая заливка: hover строки, активные пилюли, focus */
  --crimson-line: #c9cbe6;    /* акцентная граница на светлом */
  --indigo: #5b5bd6;

  --ok: #1f9d57;
  --ok-soft: #e4f5ec;
  --warn: #b7791f;
  --danger: #d1435b;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-1: 0 1px 2px rgba(27, 32, 54, 0.06);
  --shadow-2: 0 6px 20px rgba(27, 32, 54, 0.08);
  --shadow-pop: 0 18px 50px rgba(27, 32, 54, 0.16);

  --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-wordmark: "Arial Narrow", "Roboto Condensed", "Helvetica Neue", sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font: 14px/1.55 var(--font-body);
  background-color: var(--navy-950);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--crimson); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--indigo); }
/* Навигация в топбаре — это меню, а не текстовые ссылки: без подчёркивания. */
.topbar nav a { text-decoration: none; }

::selection { background: var(--crimson-soft); color: var(--text); }

/* Скроллбары в тон (светлые) */
* { scrollbar-width: thin; scrollbar-color: var(--navy-700) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--navy-700); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ---- Boot / центрированные экраны (логин, ошибки, нет прав) ---- */
.boot {
  display: flex; align-items: center; justify-content: center;
  min-height: 70vh; color: var(--text-dim); position: relative; z-index: 1;
}
.center-screen {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; min-height: 78vh; padding: 24px;
}
.center-screen h2 {
  font-family: var(--font-display); font-weight: 700; font-size: 26px;
  margin: 0; letter-spacing: 0.2px;
}
.center-screen .muted { max-width: 440px; }

/* ============================== Layout ============================== */
.app { position: relative; z-index: 1; min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 24px; height: 64px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-1);
  position: sticky; top: 0; z-index: 20;
}

/* Wordmark «ORBITA» узкими капсами + орбитальная точка над i; «Admin» серифом. */
.topbar .brand {
  display: inline-flex; align-items: center; gap: 12px;
  position: relative;
}
.topbar .brand .brand-logo {
  height: 26px; width: auto; display: block;
  /* Официальный логотип тёмно-синий на прозрачном - на светлом топбаре как есть. */
  opacity: 0.95;
}
.topbar .brand .brand-sub {
  font-family: var(--font-display); font-weight: 400; font-style: italic;
  font-size: 16px; letter-spacing: 0; text-transform: none; color: var(--text-dim);
  padding-left: 12px; border-left: 1px solid var(--line-strong);
}

.topbar nav { display: flex; gap: 2px; margin-left: 14px; }
.topbar nav a {
  position: relative;
  padding: 9px 15px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 600; font-size: 13.5px;
  transition: color 0.16s ease, background 0.16s ease;
}
.topbar nav a:hover { background: rgba(37, 37, 99, 0.05); color: var(--text); }
.topbar nav a.active { color: var(--crimson); background: var(--crimson-soft); }
.topbar nav a.active::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--crimson), var(--crimson-bright));
  border-radius: 2px;
}
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--text-dim); font-size: 13px; }
.topbar .user b { color: var(--text); font-weight: 600; }

.content {
  position: relative; z-index: 1;
  padding: 32px 24px 64px; max-width: 1440px; width: 100%; margin: 0 auto;
}
/* Единые правила ширины (задаются централизованно в app.js по маршруту, а не
   каждой страницей - иначе класс «протекал» между страницами через общий .content,
   и ширина зависела от истории переходов). Два разумных уровня:
   - по умолчанию 1440px: списки, дашборды, конструктор - вмещает самую широкую
     таблицу (отчёты ~1335px) без горизонтального скролла;
   - .is-narrow 1120px: страницы-формы редактирования (политика, права роли), где
     широкая колонка только разносила бы поля формы и кнопки шапки по краям.
   Прежний режим rb-wide-page (max-width:none, во всю ширину) убран. */
.content.is-narrow { max-width: 1120px; }

/* Появление содержимого страницы (стаггер). */
.content > * { animation: rise 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) both; }
.content > *:nth-child(2) { animation-delay: 0.05s; }
.content > *:nth-child(3) { animation-delay: 0.1s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .content > * { animation: none; } }

/* ---- Page header ---- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.page-head h1 {
  font-family: var(--font-display); font-weight: 700; font-size: 27px;
  letter-spacing: 0.2px; margin: 0; line-height: 1.15;
}
.page-head .spacer { flex: 1; }

/* Под-навигация раздела «Телеметрия»: таб-бар (Обзор/Метрики/Логи) с подчёркиванием
   активного - заменяет заголовок страницы и кнопку «Назад». Активный таб несёт вес
   заголовка (крупный, полным цветом), остальные приглушены. Визуально отличается от
   фильтра диапазона (range-tabs - бордюрные пилюли справа). */
.tele-tabs { display: inline-flex; align-items: baseline; gap: 20px; }
.tele-tab {
  position: relative;
  font-family: var(--font-display); font-weight: 700; font-size: 21px; letter-spacing: 0.2px;
  color: var(--text-faint); text-decoration: none;
  padding-bottom: 4px; transition: color 0.16s ease;
}
.tele-tab:hover { color: var(--text-dim); }
.tele-tab.active { color: var(--text); }
.tele-tab.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: linear-gradient(90deg, var(--crimson), var(--crimson-bright));
  border-radius: 2px;
}
.muted { color: var(--text-dim); }

/* ============================== Buttons ============================== */
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #f2f4f9;
  color: var(--text);
  padding: 9px 16px; border-radius: var(--radius-sm);
  cursor: pointer; font: inherit; font-weight: 600; letter-spacing: 0.2px;
  transition: transform 0.12s ease, border-color 0.16s ease, background 0.16s ease,
    box-shadow 0.16s ease, color 0.16s ease;
}
.btn:hover { border-color: var(--crimson-line); background: #e9ecf5; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--crimson-soft); border-color: var(--crimson); }

.btn.primary {
  background: linear-gradient(135deg, var(--crimson), var(--crimson-bright));
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px rgba(37, 37, 99, 0.22);
}
.btn.primary:hover { filter: brightness(1.07); box-shadow: 0 10px 26px rgba(37, 37, 99, 0.30); transform: translateY(-1px); }
.btn.primary:active { transform: translateY(0); }

.btn.danger { background: transparent; border-color: rgba(209, 67, 91, 0.4); color: #c8324b; }
.btn.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.btn.ghost { background: transparent; border-color: var(--line-strong); color: var(--text-dim); }
.btn.ghost:hover { background: rgba(37, 37, 99, 0.05); border-color: var(--crimson-line); color: var(--text); }
/* Кнопки добавления «+ …»: пунктирная обводка - привычный сигнал «добавить». */
.btn.rb-add { border-style: dashed; border-color: var(--line-strong); color: var(--text-dim); background: transparent; }
.btn.rb-add:hover { border-style: dashed; border-color: var(--crimson); color: var(--crimson); background: var(--crimson-soft); }

.btn:disabled { opacity: 0.45; cursor: default; transform: none; box-shadow: none; filter: none; }
.btn.sm { padding: 6px 11px; font-size: 13px; }

/* ============================== Cards / tables ============================== */
.card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  color: var(--text-faint); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.9px;
  background: #f6f7fb;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.14s ease; }
tbody tr:hover { background: var(--crimson-soft); }
td b { font-weight: 700; }
td .row-actions { display: flex; gap: 8px; }
.empty { padding: 40px 28px; text-align: center; color: var(--text-dim); }

/* ---- Таблица отчётов: «Название» - единственная растяжимая колонка (забирает
   свободное место), остальные ужаты по содержимому - тот же приём, что в таблице
   политик. На всякий случай узкое окно даёт горизонтальный скролл, а не обрезку. */
.reports-table td, .reports-table th { vertical-align: middle; }
.reports-table .col-name { min-width: 240px; font-weight: 600; }
.reports-table .col-mono,
.reports-table .col-status,
.reports-table .col-date,
.reports-table .col-actions { width: 1%; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* ---- Таблица политик: счётчики allow/deny ---- */
/* Все ячейки строки на одной центральной линии (число-чипы, бейдж, кнопки
   одинаковой высоты) — иначе текст липнет к верху, а бейдж/кнопки «скачут». */
.policies-table td { vertical-align: middle; }
.cnt-cell { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
/* Чип только с числом: смысл несёт цвет (зелёный allow / crimson deny) и title. */
.cnt {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; padding: 2px 9px; border-radius: 999px;
  font-weight: 700; font-size: 13px; line-height: 1.5; white-space: nowrap;
  border: 1px solid var(--line-strong); background: rgba(37, 37, 99, 0.05);
}
.cnt-allow { color: var(--ok); background: var(--ok-soft); border-color: rgba(31, 157, 87, 0.35); }
.cnt-deny { color: var(--danger); background: #fbe7ea; border-color: rgba(209, 67, 91, 0.35); }
.cnt-plain { color: var(--text); }
.cnt-none { color: var(--text-faint); font-weight: 600; }

/* ============================== Badges / chips ============================== */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: rgba(37, 37, 99, 0.05); border: 1px solid var(--line-strong);
  color: var(--text-dim);
}
.badge.ok { color: var(--ok); border-color: rgba(31, 157, 87, 0.35); background: var(--ok-soft); }
.badge.off { color: var(--text-faint); }

/* Лёгкий инлайн-индикатор проблемы в строке (точка + короткий текст). */
.attr-warning {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 10px; font-size: 11px; font-weight: 600;
  color: var(--warn); white-space: nowrap; cursor: default;
  vertical-align: middle;
}
.attr-warning::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--warn); flex: none;
}
/* Удалённая роль серьёзнее отсутствующего атрибута (политика осиротела целиком):
   тот же индикатор, но в crimson. */
.attr-warning.role-warning { color: var(--danger); }
.attr-warning.role-warning::before { background: var(--danger); }

/* Информер на странице списка (предупреждение об удалённых атрибутах и т.п.). */
.notice {
  border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 16px;
  border: 1px solid var(--line-strong); background: #f6f7fb;
  font-size: 13.5px; line-height: 1.5; color: var(--text-dim);
}
.notice.warn { border-left: 3px solid var(--warn); background: #faf4e4; }
.notice-title { font-weight: 700; color: var(--warn); margin-bottom: 6px; }
.notice-list { margin: 8px 0 0; padding-left: 18px; }
.notice-list li { margin: 2px 0; }
.notice.muted-note { color: var(--text-faint); border-left: 3px solid var(--line-strong); }
/* Информер удачного разбора (проверенный файл лицензии): та же карточка, но
   зелёная - иначе «файл проверен» читается как предупреждение. */
.notice.ok-note { border-left: 3px solid var(--ok); background: var(--ok-soft); color: var(--text); }
.notice.ok-note .notice-title { color: var(--ok); }
/* Ряд кнопок внутри информера (проверить -> установить/отменить). */
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.taglist { display: flex; flex-wrap: wrap; gap: 7px; }
.tag {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(91, 91, 214, 0.10);
  border: 1px solid rgba(91, 91, 214, 0.28);
  font-size: 12.5px; font-weight: 500;
}
.tag.deny { background: #fbe7ea; border-color: rgba(209, 67, 91, 0.32); color: var(--danger); }
.tag .x { cursor: pointer; color: var(--text-dim); font-weight: 700; line-height: 1; transition: color 0.14s ease; }
.tag .x:hover { color: var(--crimson-bright); }

/* ============================== Forms ============================== */
.form { display: flex; flex-direction: column; gap: 22px; max-width: 780px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label {
  font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--text-dim);
}
.field .hint { color: var(--text-faint); font-size: 12px; }

/* Секции формы (карточки) + парная сетка allow/deny */
.form-section {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  display: flex; flex-direction: column; gap: 18px;
}
.form-section-title {
  font-family: var(--font-display); font-weight: 700; font-size: 16px;
  margin: 0; color: var(--text); display: flex; align-items: center; gap: 11px;
}
.form-section-title::before {
  content: ""; width: 5px; height: 18px; border-radius: 3px;
  background: linear-gradient(180deg, var(--crimson), var(--crimson-bright));
}
/* align-items:start + одинаковые по высоте подписи/подсказки (у обоих полей пары
   по одной строке hint) -> верх инпутов allow/deny на одной линии, а боксы растут
   ВНИЗ независимо при переносе чипов. Подписи при этом не съезжают. */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 720px) { .field-grid { grid-template-columns: 1fr; } }

input[type="text"], input[type="number"], input[type="search"], input[type="date"], textarea, select {
  background: #ffffff;
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px; font: inherit; width: 100%;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input[type="text"]:focus, input[type="number"]:focus, input[type="search"]:focus, input[type="date"]:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--crimson-line);
  box-shadow: 0 0 0 3px rgba(37, 37, 99, 0.12);
  background: #ffffff;
}
textarea { resize: vertical; min-height: 64px; font-family: var(--font-mono); font-size: 13px; }
input:disabled { opacity: 0.6; cursor: not-allowed; }

/* Компактное поле поиска в шапке раздела (page-head): фикс-ширина, прижато вправо
   спейсером. На узких экранах занимает всю строку. */
.search-box { flex: 0 1 auto; width: min(300px, 100%); }
.search-box input[type="search"] { width: 100%; padding-top: 8px; padding-bottom: 8px; }

/* Контейнер результатов списка при перезагрузке (поиск, пагинация, сортировка):
   не схлопываем содержимое, а приглушаем на время запроса. Так высота страницы
   не скачет и скролл не прыгает вверх. */
.list-body.is-loading { opacity: 0.5; pointer-events: none; transition: opacity 0.15s ease; }

.chips-input {
  display: flex; flex-wrap: wrap; gap: 7px; align-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 7px; background: #ffffff;
  min-height: 44px; /* как у обычного input, чтобы пустые боксы не были ниже */
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.chips-input:focus-within { border-color: var(--crimson-line); box-shadow: 0 0 0 3px rgba(37, 37, 99, 0.12); }
.chips-input input { flex: 1; min-width: 160px; border: none; background: transparent; padding: 4px; }
.chips-input input:focus { box-shadow: none; background: transparent; }
.chips-input .combobox { flex: 1; min-width: 180px; }
.chips-input .combobox > input { border: none; background: transparent; padding: 4px; }
.chips-input .combobox > input:focus { box-shadow: none; }

/* ---- Поисковый комбобокс ---- */
.combobox { position: relative; width: 100%; }
.combobox > input { width: 100%; padding-right: 26px; }
/* Каретка-шеврон: даёт понять, что это выбор из списка, а не просто текстовое поле
   (иначе комбобоксы неотличимы от инпутов). Кликам не мешает. */
.combobox::after {
  content: ""; position: absolute; right: 11px; top: 50%; width: 6px; height: 6px;
  margin-top: -4px; transform: rotate(45deg);
  border-right: 1.5px solid var(--text-faint); border-bottom: 1.5px solid var(--text-faint);
  pointer-events: none;
}
/* В поле-чипсах (теги) комбобокс встроен без рамки - каретка там ни к чему. */
.chips-input .combobox::after { display: none; }
.chips-input .combobox > input { padding-right: 4px; }
.combobox-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  margin: 0; padding: 5px; list-style: none;
  max-height: 300px; overflow-y: auto;
  background: #ffffff;
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
  animation: pop 0.14s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.combobox-list[hidden] { display: none; }
.combobox-option {
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
  border-left: 2px solid transparent; transition: background 0.1s ease;
}
.combobox-option.is-active, .combobox-option:hover {
  background: rgba(37, 37, 99, 0.08); border-left-color: var(--crimson);
}
.combobox-option-label { font-weight: 600; font-size: 13.5px; color: var(--text); }
.combobox-option-value { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.combobox-option-desc {
  font-size: 11.5px; color: var(--text-dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Заголовок-разделитель группы (имя домена) в списке таблиц. */
.combobox-group {
  position: sticky; top: -5px;
  padding: 7px 10px 5px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.7px; text-transform: uppercase;
  color: var(--crimson-bright);
  background: #ffffff;
}
.combobox-group + .combobox-option { border-top: none; }
.combobox-group:not(:first-child) { margin-top: 3px; border-top: 1px solid var(--line); }
.mono.dim { color: var(--text-faint); font-size: 12px; }

/* ---- selectMenu: кастомный <select> (кнопка + меню combobox-list) ---- */
/* Меню рендерится порталом в document.body с position:fixed (см. selectMenu в
   components.js), поэтому стекинг-контекст здесь поднимать не нужно. */
.selectmenu { position: relative; width: 100%; }
.selectmenu-btn {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; background: #ffffff; border: 1px solid var(--line-strong); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 12px; font: inherit; text-align: left;
  cursor: pointer; transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.selectmenu-btn:hover { border-color: var(--crimson-line); }
.selectmenu-btn:focus-visible {
  outline: none; border-color: var(--crimson-line); box-shadow: 0 0 0 3px rgba(37, 37, 99, 0.12);
}
.selectmenu.open .selectmenu-btn { border-color: var(--crimson-line); }
.selectmenu-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Каретка-шеврон (как у combobox); поворачивается вверх при раскрытии. */
.selectmenu-btn::after {
  content: ""; flex: none; width: 6px; height: 6px; margin-left: 4px; position: relative; top: -2px;
  transform: rotate(45deg); transition: transform 0.16s ease;
  border-right: 1.5px solid var(--text-faint); border-bottom: 1.5px solid var(--text-faint);
}
.selectmenu.open .selectmenu-btn::after { transform: rotate(-135deg); top: 1px; }
.selectmenu-option.is-selected { background: rgba(37, 37, 99, 0.06); }
.selectmenu-option.is-selected .combobox-option-label { color: var(--crimson-bright); }

/* ---- Запрещённые колонки: группировка по таблицам ---- */
.denied-columns { display: flex; flex-direction: column; gap: 12px; }
.dc-empty { font-size: 13px; padding: 2px 0; }
.dc-groups { display: flex; flex-direction: column; gap: 10px; }
.dc-group {
  background: #f6f7fb;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.dc-group-head { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }
.dc-group-title { font-weight: 600; color: var(--text); }
.dc-group-sub { font-size: 11.5px; color: var(--text-faint); }
.dc-group-count { font-size: 11px; color: var(--crimson-bright); font-weight: 600; }
.dc-group-head .spacer { flex: 1; }
.dc-group-x {
  appearance: none; border: none; background: transparent; cursor: pointer;
  color: var(--text-faint); font-size: 19px; line-height: 1; padding: 0 4px;
  transition: color 0.14s ease;
}
.dc-group-x:hover { color: var(--crimson-bright); }
.dc-cols { display: flex; flex-wrap: wrap; gap: 7px; }
.dc-col {
  appearance: none; cursor: pointer; font: inherit; font-size: 12.5px;
  padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(37, 37, 99, 0.04);
  color: var(--text-dim);
  transition: border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
}
.dc-col:hover { border-color: var(--crimson-line); color: var(--text); }
.dc-col.is-on { background: var(--crimson-soft); border-color: var(--crimson); color: var(--crimson); }
.dc-col.is-on::before { content: "✕"; margin-right: 6px; font-size: 10px; opacity: 0.85; }

/* ---- Переключатель (toggle switch) ---- */
.switch { display: inline-flex; gap: 12px; align-items: center; cursor: pointer; font-weight: 500; user-select: none; }
/* Нативный чекбокс прячем визуально, но оставляем доступным (источник состояния). */
.switch .switch-input { position: absolute; opacity: 0; width: 0; height: 0; margin: 0; }
.switch-track {
  position: relative; flex: none;
  width: 46px; height: 26px;
  background: var(--navy-700);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  transition: background .18s ease, border-color .18s ease;
}
.switch-thumb {
  position: absolute; top: 50%; left: 3px;
  width: 20px; height: 20px;
  background: var(--text-dim);
  border-radius: 50%;
  transform: translateY(-50%);
  box-shadow: var(--shadow-1);
  transition: left .18s ease, background .18s ease;
}
.switch .switch-input:checked ~ .switch-track {
  background: var(--crimson);
  border-color: var(--crimson-line);
}
.switch .switch-input:checked ~ .switch-track .switch-thumb {
  left: calc(100% - 23px);
  background: #fff;
}
.switch .switch-input:focus-visible ~ .switch-track {
  outline: 2px solid var(--crimson-bright);
  outline-offset: 2px;
}
.switch-text { font-weight: 500; color: var(--text-dim); transition: color .18s ease; }
.switch .switch-input:checked ~ .switch-text { color: var(--text); }
/* Сетка тумблеров прав (API-RBAC): адаптивные колонки. */
.switch-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px 28px; }
.switch-list .switch { width: 100%; }
/* Разворачиваемый снимок политики в аудите. */
.audit-snapshot summary { cursor: pointer; color: var(--text-dim); }
.audit-snapshot pre {
  margin: 8px 0 0; padding: 10px; background: #f6f7fb; border-radius: 8px;
  max-height: 280px; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-word;
}
/* Построчный diff снимка ДО/ПОСЛЕ. */
.diff { margin: 8px 0 0; display: flex; flex-direction: column; gap: 8px; max-width: 520px; }
.diff-field {
  display: grid; grid-template-columns: 180px 1fr; gap: 10px; align-items: start;
  padding: 7px 10px; background: #eef1f7; border-radius: 8px;
}
.diff-field-label {
  font-size: 11px; color: var(--text-faint); text-transform: uppercase;
  letter-spacing: 0.4px; padding-top: 3px;
}
/* min-width:0 — иначе grid-колонка распирается длинным токеном (не сжимается). */
.diff-chips { display: flex; flex-wrap: wrap; gap: 5px; min-width: 0; }
.diff-chip {
  font-family: var(--font-mono); font-size: 12px;
  padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line-strong);
  max-width: 100%; white-space: normal; overflow-wrap: anywhere; word-break: break-word;
}
.diff-chip.added { color: var(--ok); background: var(--ok-soft); border-color: rgba(31, 157, 87, 0.35); }
.diff-chip.removed {
  color: #c8324b; background: rgba(209, 67, 91, 0.12); border-color: rgba(209, 67, 91, 0.4);
  text-decoration: line-through;
}
.diff-scalar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; min-width: 0;
}
.diff-old { color: var(--text-faint); text-decoration: line-through; overflow-wrap: anywhere; }
.diff-arrow { color: var(--text-dim); }
.diff-new { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }

/* ============================== Row filters ============================== */
.rowfilters { display: flex; flex-direction: column; gap: 12px; }
.rowfilter {
  display: grid; grid-template-columns: 240px 1fr auto; gap: 12px; align-items: start;
  background: #f6f7fb;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px;
}
/* min-width:0 — иначе grid-колонка распирается длинным чипом (вёрстку «вело»). */
.rowfilter-col { min-width: 0; }
.rowfilter .col-label {
  font-size: 11px; color: var(--text-faint); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 5px;
}
/* Таблицы предиката стопкой: по чипу на строку. Явный белый бокс с рамкой -
   чтобы список читался как ограниченная область (а не сливался с фоном карточки),
   и был очевиден скролл при большом числе. Зона добавления (.rowfilter-add) - под
   боксом, статична. scrollbar-gutter резервирует место под скроллбар (сигнал скролла). */
.rowfilter-tables {
  display: flex; flex-direction: column; gap: 6px; align-items: stretch;
  max-height: 44vh; overflow-y: auto; scrollbar-gutter: stable;
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 8px;
}
/* Чип во всю ширину колонки: длинное имя обрезаем многоточием, × всегда виден
   (иначе длинные названия распирали колонку 240px). Технический ref — в title. */
.rowfilter-tables .tag { display: flex; width: 100%; max-width: 100%; }
.rowfilter-tables .tag .tag-label {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rowfilter-tables .tag .tag-ref { display: none; }
.rowfilter-tables .tag .x { flex: none; }
/* Пока таблиц нет - не показываем пустой белый бокс (осталась бы зона добавления). */
.rowfilter-tables:empty { display: none; }
.rowfilter-add { margin-top: 8px; }

/* Подсветка проблемной строки + inline-ошибки + автокомплит предиката. */
.rowfilter.has-error { border-color: var(--danger); background: #fdf2f4; }
.predicate-wrap { position: relative; }
/* Предикат бывает многострочным (несколько условий) - даём высоту, чтобы текст не
   обрезался в 2 строки; пользователь может растянуть дальше (resize: vertical). */
.predicate-wrap textarea { min-height: 96px; font-family: var(--font-mono); font-size: 13px; }
textarea.input-error, input.input-error { border-color: var(--danger); }
textarea.input-error:focus, input.input-error:focus { box-shadow: 0 0 0 3px rgba(209, 67, 91, 0.12); }
.predicate-errors { margin-top: 7px; display: flex; flex-direction: column; gap: 3px; }
.predicate-errors[hidden] { display: none; }
.predicate-errors > div { font-size: 12px; color: #c8324b; line-height: 1.35; }
.ac-list .combobox-option-value { text-transform: none; }

/* Выбранный чип над комбобоксом (роль на форме создания). */
.rowfilter-table { margin-bottom: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.rowfilter-table:empty { display: none; }

/* Подсказки предиката - две разные по смыслу группы, разнесены: атрибуты (акцентная
   секция, всегда на виду) и колонки (много - фильтр + счётчик + прокручиваемый бокс). */
.rowfilter-hints { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.hint-group { display: flex; flex-direction: column; gap: 8px; }
.rowfilter-hints .hint-label {
  font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.5px;
}
/* Заголовок группы колонок: подпись+счётчик слева, поле фильтра справа. */
.hint-group-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hint-group-head .hint-label { flex: none; }
.hint-filter { flex: 1 1 200px; max-width: 280px; padding: 7px 10px; font-size: 13px; }
/* Атрибуты - мягкие акцентные чипы (ключевые плейсхолдеры ${user.<attr>}): залитый
   тон + тонкая обводка (без «громкой» сплошной рамки), заметно, но не кричит. */
.hint-attrs { display: flex; flex-wrap: wrap; gap: 6px; }
.hint-attrs .hint-chip {
  border: 1px solid rgba(91, 91, 214, 0.22);
  color: var(--indigo); background: rgba(91, 91, 214, 0.09);
}
.hint-attrs .hint-chip:hover { border-color: var(--indigo); color: #fff; background: var(--indigo); }
/* Колонки - белый прокручиваемый бокс с рамкой (десятки чипов иначе распирают
   карточку и сливаются со светлым фоном), ограниченная высота + gutter под скроллбар. */
.hint-chips {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; align-content: flex-start;
  max-height: 200px; overflow-y: auto; scrollbar-gutter: stable;
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 10px;
}
/* Внутри бокса чипы колонок делаем сплошными (dashed читается «незавершённым»):
   единый язык чипов с атрибутами, отличие только в акцентном цвете. */
.hint-chips .hint-chip { border-style: solid; }
.hint-empty { font-size: 12px; }
.hint-chip {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  border: 1px dashed var(--line-strong); background: #f6f7fb;
  color: var(--text-dim); font-family: var(--font-mono); font-size: 11.5px;
  cursor: pointer; user-select: none; transition: all 0.14s ease;
}
.hint-chip:hover { border-style: solid; border-color: var(--crimson); color: var(--text); background: var(--crimson-soft); }

.form-actions { display: flex; gap: 12px; margin-top: 8px; }
.field-error { color: #c8324b; font-size: 13px; font-weight: 500; }

/* ============================== Toasts ============================== */
.toasts { position: fixed; right: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: #ffffff;
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--crimson);
  border-radius: var(--radius-sm);
  padding: 12px 16px; min-width: 250px; max-width: 440px;
  box-shadow: var(--shadow-pop);
  animation: rise 0.3s ease both;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

code, .mono { font-family: var(--font-mono); }

/* Пагинатор списков. */
.paginator {
  display: flex; align-items: center; gap: 10px;
  margin-top: 14px; padding: 10px 4px 0;
  border-top: 1px solid var(--line);
}
.paginator-info { font-size: 13px; }

/* ============================================================================
   Модальное окно подтверждения (confirmDialog) — замена нативного confirm()
   ============================================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(24, 28, 52, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: overlay-in 0.16s ease both;
}
.modal-overlay.is-closing { animation: overlay-out 0.14s ease forwards; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlay-out { from { opacity: 1; } to { opacity: 0; } }

.modal {
  width: 100%; max-width: 440px;
  background: linear-gradient(180deg, var(--navy-850), var(--navy-900));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  animation: modal-in 0.18s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.modal-overlay.is-closing .modal { animation: none; }
/* Широкая модалка YAML (выгрузка/загрузка отчёта) */
.rb-yaml-modal { max-width: 680px; }
.rb-yaml-modal .modal-body { max-height: 70vh; overflow-y: auto; }
.rb-yaml-modal textarea { background: var(--navy-900); }
/* Обзор таблицы: словарь колонок + примеры строк */
.rb-tov-modal { max-width: 780px; }
.rb-tov-modal .modal-body { max-height: 64vh; overflow: auto; }
.rb-tov-tabs { display: flex; gap: 6px; padding: 12px 20px 0; }
.rb-tov-tab { border: 1px solid var(--line-strong); background: transparent; color: var(--text-dim); font-weight: 600; font-size: 12.5px; padding: 5px 14px; border-radius: var(--radius-sm); cursor: pointer; }
.rb-tov-tab:hover { color: var(--text); }
.rb-tov-tab.is-active { background: var(--crimson-soft); border-color: var(--crimson); color: var(--crimson); }
.rb-tov-body { display: flex; flex-direction: column; gap: 8px; }
.rb-tov-col { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px; }
.rb-tov-col-head { display: flex; align-items: center; gap: 10px; }
.rb-tov-col-head .spacer { flex: 1; }
.rb-tov-name { font-weight: 600; font-size: 13px; }
.rb-tov-type { font-size: 11px; color: var(--text-faint); }
.rb-tov-desc { font-size: 12px; color: var(--text-dim); margin-top: 5px; line-height: 1.45; }
.rb-tov-values { margin-top: 8px; display: flex; flex-direction: column; gap: 2px; max-height: 210px; overflow: auto; border-top: 1px solid var(--line); padding-top: 6px; }
.rb-tov-val { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.rb-tov-valv { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-tov-valc { color: var(--text-faint); flex: 0 0 auto; font-family: var(--font-mono); }
.rb-tov-rows { overflow-x: auto; }
/* Кнопка-действие внутри чипа таблицы */
.tag-action { cursor: pointer; font-size: 11px; color: var(--text-dim); border: 1px solid var(--line-strong); border-radius: 999px; padding: 0 7px; line-height: 1.6; transition: color .12s ease, border-color .12s ease; }
.tag-action:hover { color: var(--crimson-bright); border-color: var(--crimson-line); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal-head { padding: 18px 22px 0; }
.modal-title {
  font-family: var(--font-display);
  font-size: 19px; font-weight: 700; color: var(--text);
  letter-spacing: 0.2px;
}
.modal-body {
  padding: 10px 22px 18px;
  color: var(--text-dim);
  line-height: 1.55; font-size: 14.5px;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: #f6f7fb;
}

@media (max-width: 720px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .user { display: none; }
  .content { padding: 22px 14px 48px; }
  .rowfilter { grid-template-columns: 1fr; }
}

/* ============================================================================
   Телеметрия: KPI-карточки, графики (SVG), срез по пользователям
   ============================================================================ */

.page-head.sub { margin: 28px 0 14px; }
.page-head.sub h2 { font-family: var(--font-display); font-size: 19px; margin: 0; font-weight: 600; }

/* Переключатель диапазона */
.range-tabs { display: flex; gap: 6px; }
.range-tabs .btn.active {
  color: var(--text);
  border-color: var(--crimson-line);
  background: var(--crimson-soft);
}

/* KPI-карточки */
.telemetry-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi-card {
  background: linear-gradient(180deg, var(--navy-850), var(--navy-900));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 16px 18px;
}
.kpi-value { font-family: var(--font-display); font-size: 28px; line-height: 1.1; color: var(--text); }
.kpi-value.tone-err { color: var(--danger); }
.kpi-value.tone-warn { color: var(--warn); }
.kpi-label { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.kpi-sub { font-size: 12px; margin-top: 2px; }

/* Сетка карточек с графиками: на широком экране 2 в ряд (крупнее) */
.chart-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.chart-card { padding: 16px 18px 10px; }
.chart-title { color: var(--text-dim); font-size: 14px; margin-bottom: 8px; }

/* SVG-графики: масштабируются по ширине контейнера */
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { fill: var(--text-faint); font-size: 12px; font-family: var(--font-body); }
.chart-empty { fill: var(--text-faint); font-size: 13px; }
.chart-line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { stroke: var(--navy-900); stroke-width: 1; }

/* Цветовые варианты графиков (из фирстиля) */
.chart-line.v-crimson { stroke: #d1135c; }
.chart-dot.v-crimson { fill: #d1135c; }
.chart-line.v-danger { stroke: var(--danger); }
.chart-dot.v-danger { fill: var(--danger); }
.chart-line.v-warn { stroke: var(--warn); }
.chart-dot.v-warn { fill: var(--warn); }
.chart-bar.v-indigo { fill: var(--indigo); }
.chart-bar.v-crimson { fill: #d1135c; }
.chart-bar.v-ok { fill: var(--ok); }
.chart-bar.v-warn { fill: var(--warn); }
.chart-bar.v-err { fill: var(--danger); }

/* Интерактив: crosshair, фокус-точка, тултип */
.chart-wrap { position: relative; }
.chart-bar { transition: filter 0.08s ease; }
.chart-bar.is-focus { filter: brightness(1.4); }
.chart-guide { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 3 4; pointer-events: none; }
.chart-focus { stroke: var(--navy-900); stroke-width: 2; pointer-events: none; }
.chart-focus.v-crimson { fill: #d1135c; }
.chart-focus.v-danger { fill: var(--danger); }
.chart-focus.v-warn { fill: var(--warn); }
.chart-focus.v-indigo { fill: var(--indigo); }
.chart-tooltip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 10px));
  background: var(--navy-800);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 10px;
  pointer-events: none;
  box-shadow: var(--shadow-2);
  white-space: nowrap;
  z-index: 5;
}
.chart-tooltip .tt-x { color: var(--text-dim); font-size: 11px; }
.chart-tooltip .tt-y { color: var(--text); font-weight: 600; font-size: 15px; line-height: 1.2; }

/* Кликабельные строки таблицы (переход в детализацию) */
tr.row-link { cursor: pointer; }
tr.row-link:hover { background: var(--crimson-soft); }

/* Бейджи статуса запроса (HTTP-код): 4xx предупреждение, 5xx ошибка */
.badge.err { color: var(--danger); border-color: rgba(209, 67, 91, 0.45); background: #fbe7ea; }
.badge.warn { color: var(--warn); border-color: rgba(183, 121, 31, 0.4); background: #f6ecd4; }

/* Сортируемые заголовки таблицы */
th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.th-sort:hover { color: var(--text); }
th.th-sort.active { color: var(--crimson-bright); }
th.th-sort .sort-ind { color: var(--crimson-bright); font-weight: 700; }

/* ============================================================================
   Детализация трейса: дерево спанов с таймлайном и разворачиваемыми деталями
   ============================================================================ */

.trace-tree { padding: 6px 0; }
.span-entry { border-bottom: 1px solid var(--line); }
.span-entry:last-child { border-bottom: none; }

.span-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 7px 10px;
  cursor: pointer;
}
.span-row:hover { background: var(--crimson-soft); }
.span-caret { color: var(--text-faint); font-size: 11px; transition: transform 0.12s ease; flex: none; }
.span-entry.open > .span-row .span-caret { transform: rotate(90deg); }
.span-name { color: var(--text); font-size: 13px; white-space: nowrap; flex: none; }
.span-tag {
  flex: none;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--navy-800);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
}

/* Таймлайн-полоса: занимает свободное место, бар позиционируется отступом+шириной */
.span-bar-track {
  flex: 1 1 auto;
  min-width: 80px;
  height: 8px;
  background: var(--navy-850);
  border-radius: 4px;
  overflow: hidden;
}
.span-bar { height: 100%; border-radius: 4px; min-width: 2px; }
.span-bar.v-ok { background: var(--ok); }
.span-bar.v-indigo { background: var(--indigo); }
.span-bar.v-crimson { background: #d1135c; }
.span-bar.v-warn { background: var(--warn); }
.span-bar.v-err { background: var(--danger); }
.span-bar.v-muted { background: #8a90a2; }

.span-dur { flex: none; color: var(--text-dim); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }

/* Блок деталей спана: скрыт по умолчанию, раскрывается классом .open на entry */
.span-detail { display: none; padding: 8px 16px 14px 38px; background: var(--navy-900); font-size: 12px; }
.span-entry.open > .span-detail { display: block; }
.attr-row { display: flex; gap: 10px; padding: 2px 0; }
.attr-k { color: var(--text-dim); min-width: 130px; flex: none; }
.attr-v { color: var(--text); word-break: break-word; }
.attr-v.err { color: var(--danger); }
.attr-sql { padding: 4px 0; }
.attr-sql .attr-k { margin-bottom: 4px; }
.sql-pre {
  margin: 0;
  padding: 10px 12px;
  background: var(--navy-850);
  border: 1px solid var(--line);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-size: 12px;
  max-height: 280px;
  overflow: auto;
}


/* --- Конструктор отчётов (двухпанельный) --- */
/* Определение (широкая колонка) + живое превью (узкая липкая сбоку). Раньше было
   наоборот - определение задыхалось в 420px. Ниже 1000px всё в одну колонку. */
/* Конструктор капнут (иначе контролы растягиваются с пустотой), превью забирает
   весь остаток ширины - для широких pivot-отчётов это критично. */
.rb-2col { display: grid; grid-template-columns: minmax(340px, 780px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1000px) { .rb-2col { grid-template-columns: 1fr; } }
.rb-rail { display: flex; flex-direction: column; gap: 16px; }
.rb-rail .form-section { margin: 0; }
.rb-rows { display: flex; flex-direction: column; gap: 8px; }
.rb-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rb-row input { min-width: 70px; }
.rb-row input[type="text"] { flex: 1 1 90px; }
.rb-subrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 0 10px; }
/* Метка соединителя (И/ИЛИ) между условиями. */
.rb-and { align-self: flex-start; font-size: 11px; font-weight: 700; letter-spacing: .5px; color: var(--text-faint); padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; }
/* Шаг «Итоги»: ровный вертикальный ритм между «Посчитать» / «Группировать по» / подытоги. */
.rb-summarize { display: flex; flex-direction: column; gap: 14px; }
/* Вертикальный стек полей с ровным ритмом (сортировка+лимит и т.п.). */
.rb-vstack { display: flex; flex-direction: column; gap: 14px; }
/* Переключатель соединителя группы И | ИЛИ. */
.rb-conn { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.rb-conn-btn { border: 1px solid var(--line-strong); background: transparent; color: var(--text-dim); font-weight: 700; font-size: 11px; letter-spacing: .5px; padding: 2px 12px; border-radius: 999px; cursor: pointer; transition: background .12s ease, color .12s ease, border-color .12s ease; }
.rb-conn-btn:hover { color: var(--text); border-color: var(--crimson-line); }
.rb-conn-btn.is-active { background: var(--crimson-soft); border-color: var(--crimson); color: var(--crimson); }
/* Вложенная группа условий = визуальные скобки. */
.rb-cond-groupwrap { display: flex; align-items: flex-start; gap: 8px; }
.rb-cond-group { flex: 1 1 auto; min-width: 0; border: 1px solid var(--line-strong); border-left: 3px solid var(--crimson-line); border-radius: var(--radius-sm); padding: 10px 12px; background: #f6f7fb; display: flex; flex-direction: column; gap: 8px; }
.rb-metric { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rb-metric > .combobox { min-width: 0; }
.rb-metric input[type="text"], .rb-metric input[type="number"] { flex: 1 1 110px; min-width: 0; }
.rb-metric > .x { flex: 0 0 auto; margin-left: auto; }
.rb-metric > .x + .x { margin-left: 0; }
.rb-cf { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.rb-cf-body { display: flex; flex-direction: column; gap: 8px; }
.rb-colname { font-size: 11px; color: var(--text-dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.form-section input[type="color"] { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.rb-preview { position: sticky; top: 76px; background: #ffffff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rb-preview-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--text-dim); }
.rb-preview-body { padding: 8px; overflow-x: auto; max-height: 72vh; }
.preview-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.preview-table th, .preview-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.preview-table th { color: var(--text-dim); text-align: left; font-weight: 600; }
.preview-table .rb-tree-cell { white-space: nowrap; }
/* Над-заголовок группы (R1): так же, как объединённая ячейка ляжет в Р7. */
.preview-table th.rb-th-group { border-bottom: 1px solid var(--line-strong); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.preview-table th[rowspan] { vertical-align: middle; }
.preview-table tr.rb-total { font-weight: 600; }
.preview-table tr.rb-total td { border-top: 1px solid var(--line-strong); }

/* Заблокированная (не отражающая текущий SQL) панель конструктора: видна, но
   неинтерактивна - сохраняет контекст «как было», не намекая, что можно править. */
.rb-disabled { opacity: 0.45; pointer-events: none; user-select: none; }
/* Заголовок секции SQL с бейджем статуса синхронизации рядом с названием. */
.rb-sql-title { display: flex; align-items: center; gap: 10px; }

/* --- Определение запроса: вкладки Конструктор|SQL --- */
.rb-def-head {
  /* top = высота липкого .topbar (64px), иначе шапка паркуется под ним */
  position: sticky; top: 64px; z-index: 3;
  margin: -20px -22px 0; padding: 14px 22px;
  background: rgba(255, 255, 255, 0.97); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
}
.rb-def-head .spacer { flex: 1; }
.rb-def-body { padding-top: 4px; }
.rb-subhead { font-family: var(--font-display); font-weight: 700; font-size: 13px; color: var(--text-dim); margin: 16px 0 8px; letter-spacing: .3px; }
.rb-subhead:first-child { margin-top: 4px; }
.rb-panel-builder[hidden], .rb-panel-sql[hidden] { display: none; }
.rb-panel-builder, .rb-panel-sql { display: flex; flex-direction: column; gap: 20px; }

/* Подсекции конструктора в отдельных блоках-карточках, чтобы не сливались в ленту. */
/* Шаги конструктора - плоские подсекции (заголовок с акцентом + контролы), а не
   серые карточки внутри белой карточки. Разделяются воздухом, а не рамками. */
.rb-group { display: flex; flex-direction: column; gap: 10px; }
.rb-group-title { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 12.5px; letter-spacing: .4px; text-transform: uppercase; color: var(--text-dim); }
.rb-group-title::before { content: ""; width: 4px; height: 13px; border-radius: 2px; background: var(--crimson); flex: 0 0 auto; }
.rb-group-title .spacer, .rb-group-head .spacer { flex: 1; }
.rb-step-remove { border: 0; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 11px; font-weight: 600; letter-spacing: .2px; text-transform: none; padding: 2px 6px; border-radius: var(--radius-sm); }
.rb-step-remove:hover { color: var(--crimson-bright); background: var(--crimson-soft); }
.rb-group-head { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
/* Панель «добавить шаг» */
.rb-addstep { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 2px 2px 4px; }
.rb-addstep[hidden] { display: none; }

/* Вкладки «Конструктор | SQL-запрос»: показываем одну проекцию за раз. Точка на
   вкладке «Конструктор» загорается, когда SQL вне конструктора (панели заморожены). */
.rb-deftabs { display: flex; gap: 6px; margin: 4px 0 14px; }
.rb-deftab { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-strong); background: transparent; color: var(--text-dim); font-family: var(--font-display); font-weight: 700; font-size: 12.5px; letter-spacing: .3px; padding: 6px 16px; border-radius: var(--radius-sm); cursor: pointer; }
.rb-deftab:hover { color: var(--text); }
.rb-deftab.is-active { background: var(--crimson-soft); border-color: var(--crimson); color: var(--crimson); }
.rb-deftab-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--warn); flex: 0 0 auto; }
.rb-deftab-dot[hidden] { display: none; }

/* Вкладки секций (R2): секция = отдельная таблица отчёта (свой лист в Р7).
   Действия (переименовать/порядок/удалить) показываем только у активной вкладки,
   чтобы полоса не превращалась в частокол иконок. */
.rb-sectabs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rb-sectab { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 2px 4px 2px 0; }
.rb-sectab.is-active { background: var(--crimson-soft); border-color: var(--crimson); }
.rb-sectab-label { border: 0; background: transparent; color: var(--text-dim); font-family: var(--font-display); font-weight: 700; font-size: 12.5px; letter-spacing: .3px; padding: 5px 10px; cursor: pointer; }
.rb-sectab-label:hover { color: var(--text); }
.rb-sectab.is-active .rb-sectab-label { color: var(--crimson); }
.rb-sectab-act { border: 0; background: transparent; color: var(--text-faint); font-size: 12px; line-height: 1; padding: 4px 5px; border-radius: var(--radius-sm); cursor: pointer; }
.rb-sectab-act:hover { color: var(--text); background: var(--surface-1); }
.rb-sectab-act:disabled { opacity: .35; cursor: default; }
.rb-sectab-act.rb-sectab-del:hover { color: var(--danger); }
.rb-sectab-input { font-size: 12.5px; padding: 4px 8px; width: 160px; }

.rb-lint-strip { display: flex; align-items: center; gap: 8px; min-height: 22px; font-size: 12px; color: var(--text-dim); }
.rb-lint-strip.is-silent { display: none; }
.rb-lint-strip .dot { width: 8px; height: 8px; border-radius: 999px; background: var(--text-faint); flex: 0 0 auto; }
.rb-lint-strip.is-ok .dot { background: var(--ok); }
.rb-lint-strip.is-ok { color: var(--ok); }
.rb-lint-strip.is-warn .dot { background: var(--warn); }
.rb-lint-strip.is-err .dot { background: var(--danger); }
.rb-lint-strip.is-err { color: var(--danger); }
.predicate-wrap.rb-sql-error textarea { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(209, 67, 91, 0.12); }

@keyframes rbFlash { 0% { box-shadow: 0 0 0 3px var(--crimson-soft); border-color: var(--crimson-bright); } 100% { box-shadow: none; } }
.rb-flash { animation: rbFlash .26s ease-out; }

/* --- Связи (JOIN) конструктором --- */
.rb-join { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
.rb-join-label { min-width: 96px; color: var(--text-dim); }
.rb-join-eq { color: var(--text-faint); padding: 0 2px; }

/* --- Формат чисел: пример --- */
/* Ровная сетка «Колонки и формат»: имя | подпись | формат | выравнивание | ширина. */
.rb-colrow { display: grid; grid-template-columns: 116px minmax(0, 1fr) 190px 150px 72px; gap: 8px 12px; align-items: center; }
.rb-colrow > input { min-width: 0; }
.rb-fmt-cell { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.rb-fmt-row { display: flex; gap: 6px; min-width: 0; }
.rb-fmt-row > .combobox { flex: 1 1 auto; min-width: 0; }
.rb-fmt-row > input { flex: 1 1 80px; min-width: 0; width: auto; }
.rb-fmt-example { font-size: 11px; color: var(--text-faint); }
@media (max-width: 620px) { .rb-colrow { grid-template-columns: 96px minmax(0, 1fr); } }

/* --- Параметры: строка + подсказка про форму значения (IN/BETWEEN) --- */
.rb-param { display: flex; flex-direction: column; gap: 6px; }
.rb-param .hint[hidden] { display: none; }
/* Ровная сетка строки параметра. Фикс-ширины из sized() нейтрализуем: выравнивание
   держит грид (как в «Колонки и формат»), а не разнокалиберные пиксели. */
.rb-param-main { display: grid; grid-template-columns: minmax(0, 1.2fr) 132px minmax(0, 1.4fr) 150px 24px; gap: 8px 12px; align-items: center; }
.rb-param-main > * { width: auto !important; min-width: 0; }
.rb-param-main > .x { justify-self: center; margin: 0; cursor: pointer; color: var(--text-faint); font-weight: 700; font-size: 16px; line-height: 1; }
.rb-param-main > .x:hover { color: var(--danger); }
.rb-param-sub { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding-left: 2px; min-height: 4px; }
.rb-param-sub .hint { margin: 0; }
@media (max-width: 720px) { .rb-param-main { grid-template-columns: 1fr 1fr; } .rb-param-main > .x { justify-self: end; } }

/* --- Закрепление областей --- */
.rb-freeze { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.rb-freeze-item { display: inline-flex; align-items: center; gap: 6px; }

/* --- Печатная шапка: строки титула + чипы плейсхолдеров --- */
.rb-title-line { display: flex; flex-direction: column; gap: 4px; }
.rb-title-chips { display: flex; flex-wrap: wrap; gap: 5px; }
/* Титул в превью: как он ляжет над таблицей в Р7 (первая строка - заголовок). */
.rb-title-block { padding: 4px 0 10px; }
.rb-title-line-main { font-weight: 600; font-size: 13px; }
.rb-title-line-sub { font-size: 12px; color: var(--text-dim); }

/* --- Многоуровневая шапка: конструктор групп --- */
.rb-hg { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 7px; }
.rb-hg-cols { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rb-hg-kids { display: flex; flex-direction: column; gap: 6px; padding-left: 14px; border-left: 2px solid var(--line); }
.rb-hg-sub { background: var(--navy-850); }

/* --- Тестовые параметры: диапазон (BETWEEN) --- */
.rb-pp-range { display: flex; align-items: center; gap: 5px; }
.rb-pp-range > input { flex: 1 1 0; min-width: 0; }

/* --- Условное форматирование: подписи и пример ячейки --- */
/* Подпись «текст»/«заливка» рядом с образцом цвета (не над ним) - иначе строка
   условия выше остальных и ломает выравнивание. */
.rb-color { display: inline-flex; flex-direction: row; align-items: center; gap: 5px; }
.rb-color .hint { font-size: 10px; }
.rb-cf-example { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 22px; padding: 0 6px; border-radius: 5px; border: 1px solid var(--line); font-size: 11px; font-family: var(--font-mono); }

/* --- Тестовые параметры и выполненный SQL над превью --- */
/* Панель тестовых значений параметров: подпись сверху + адаптивная сетка полей,
   которая аккуратно тайлится даже при большом числе параметров. */
.rb-preview-params { padding: 10px 14px 12px; border-bottom: 1px solid var(--line); }
.rb-preview-params[hidden] { display: none; }
.rb-pp-caption { font-family: var(--font-display); font-weight: 700; font-size: 10.5px; letter-spacing: .5px; text-transform: uppercase; color: var(--text-faint); margin-bottom: 8px; }
.rb-pp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 10px; }
.rb-pp { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.rb-pp-label { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rb-pp input, .rb-pp select { width: 100%; height: 33px; box-sizing: border-box; padding: 5px 9px; font-size: 12.5px; }
.rb-executed-sql { margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--navy-900); color: var(--text-dim); font-family: var(--font-mono); font-size: 11.5px; white-space: pre-wrap; overflow-x: auto; max-height: 160px; }
.rb-executed-sql[hidden] { display: none; }

/* --- Прогрессивное раскрытие секций --- */
.rb-optional { display: flex; flex-direction: column; gap: 16px; }
.rb-optional[hidden] { display: none; }
.rb-locked-hint[hidden] { display: none; }

/* --- Ошибка сохранения: подсветка секции --- */
.rb-section-error { outline: 1px solid var(--danger); outline-offset: 2px; border-radius: var(--radius); }

/* --- SQL-редактор: подсветка + гуттер номеров строк --- */
.rb-sql-editor { position: relative; display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--navy-900); }
.rb-sql-editor.rb-sql-error { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(209, 67, 91, 0.12); }
/* Гуттер, слой подсветки и textarea делят одинаковые метрики бокса (шрифт,
   line-height, padding, white-space), иначе слои разъезжаются. */
.rb-sql-gutter, .rb-sql-hl, .rb-sql-input {
  font-family: var(--font-mono, monospace); font-size: 12px; line-height: 1.5;
  margin: 0; border: 0;
}
.rb-sql-gutter {
  flex: 0 0 auto; width: 38px; padding: 10px 8px 10px 0; text-align: right;
  color: var(--text-faint); background: #eef1f7; white-space: pre;
  overflow: hidden; user-select: none;
}
.rb-sql-code { position: relative; flex: 1 1 auto; min-width: 0; }
/* Слой подсветки: под кареткой, не перехватывает события, скроллится из JS. */
.rb-sql-hl {
  position: absolute; inset: 0; min-height: 168px; padding: 10px;
  white-space: pre; overflow: hidden; pointer-events: none;
  color: var(--text); background: transparent;
}
.rb-sql-hl code { font: inherit; }
/* textarea поверх слоя: текст полностью прозрачный (в WebKit нужен и
   -webkit-text-fill-color, иначе остаётся призрачная заливка и вид «затемнения»);
   видна только каретка. Высота задаётся из JS под число строк. */
.rb-sql-input {
  position: relative; width: 100%; min-height: 168px; padding: 10px;
  background: transparent; color: transparent; -webkit-text-fill-color: transparent;
  caret-color: var(--crimson-bright);
  white-space: pre; overflow-x: auto; overflow-y: hidden; outline: none;
}
/* Глобальное textarea:focus накладывает тёмную заливку (rgba .85) — по специфичности
   оно перебивало бы прозрачный фон и «затемняло» слой подсветки под кареткой на фокусе.
   Держим фон прозрачным и без рамки/тени и в фокусе. */
.rb-sql-input, .rb-sql-input:focus {
  background: transparent; box-shadow: none; border: 0;
}
.rb-sql-input::selection { background: rgba(37, 37, 99, 0.18); }
/* Токены подсветки (классы из highlightSQL). */
.rb-sql-hl .tok-kw { color: var(--crimson-bright); font-weight: 600; }
.rb-sql-hl .tok-str { color: #1f9d57; }
.rb-sql-hl .tok-num { color: #b7791f; }

/* --- Панель списка отчётов --- */
/* Панель фильтров внутри карточки: отступы по бокам/сверху выравнивают поля по
   тексту колонок таблицы (у ячеек padding 16px) и дают воздух от края карточки -
   иначе поля прилипали к рамке. Карточку не трогаем (её делят все страницы). */
.rb-list-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 16px 16px 0; margin-bottom: 12px; }
.rb-list-toolbar input[type="search"] { width: 100%; }
.rb-th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.rb-th-sort:hover { color: var(--text); }
.tag.sm { font-size: 11px; padding: 1px 7px; }

/* Плашка «замороженного» конструктора (сложный SQL): дружелюбная, заметная, но не
   тревожная. Появляется над панелями, когда запрос сложнее конструктора. */
.rb-frozen-note {
  margin: 0 0 12px; padding: 10px 14px;
  background: var(--crimson-soft); border: 1px solid var(--crimson-line);
  border-left: 3px solid var(--crimson); border-radius: var(--radius-sm);
  color: var(--text); font-size: 12.5px; line-height: 1.5;
}

/* Свёрнутый блок «Дополнительно» (кросс-таб, подсветка, оформление листа). */
.rb-adv-sections { margin-top: 4px; }
.rb-adv-summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: baseline; gap: 10px;
  padding: 12px 14px; border: 1px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--navy-900); color: var(--text); font-weight: 600; font-size: 14px;
}
.rb-adv-summary::-webkit-details-marker { display: none; }
.rb-adv-summary::before {
  content: "▸"; color: var(--text-faint); font-weight: 400;
  transition: transform .15s ease;
}
.rb-adv-sections[open] > .rb-adv-summary::before { transform: rotate(90deg); }
.rb-adv-summary:hover { border-color: var(--crimson-line); }
.rb-adv-hint { color: var(--text-faint); font-weight: 400; font-size: 12px; }
/* Открытым «Дополнительно» читается как ОДИН блок: шапка + плоские подсекции внутри
   общей рамки, а не три отдельные карточки враздрай. */
.rb-adv-sections[open] { border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--navy-850); }
.rb-adv-sections[open] > .rb-adv-summary { border: 0; border-bottom: 1px solid var(--line-strong); border-radius: var(--radius) var(--radius) 0 0; }
.rb-adv-sections[open] > .form-section { border: 0; box-shadow: none; background: transparent; margin: 0; padding: 18px 20px; }
.rb-adv-sections[open] > .form-section + .form-section { border-top: 1px solid var(--line); }

/* Тумблер с подсказкой под ним (напр. «Подытоги и общий итог»): подсказка
   выровнена под текстом, а не под дорожкой переключателя. */
.rb-toggle-field { display: flex; flex-direction: column; gap: 4px; }
.rb-toggle-field > .hint { padding-left: 52px; }

/* «Печатная шапка»: строки титула + под-опция «Печатать дату» должны дышать друг
   от друга (иначе тумблер приклеен к кнопке «+ строка титула» сверху). */
.rb-printhead { display: flex; flex-direction: column; gap: 12px; }

/* ============================================================================
   Домены данных: список, редактор схемы, примеры/правила, междоменные связи.
   Раздел плотный по природе (витрина -> десятки колонок), поэтому строки
   компактнее общих форм: колонка живёт одной строкой-сеткой, а витрины
   сворачиваются.
   ============================================================================ */

.domains-table .dm-desc {
  max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dm-rail { max-width: 1080px; }
.dm-section-hint { margin-bottom: 12px; }

/* Кнопка-крестик удаления строки (колонка, витрина, пример, правило, связь). */
.dm-x {
  flex: 0 0 auto; width: 26px; height: 26px; padding: 0;
  border: 1px solid transparent; border-radius: 7px; background: none;
  color: var(--text-faint); font-size: 17px; line-height: 1; cursor: pointer;
  transition: color .12s ease, border-color .12s ease, background .12s ease;
}
.dm-x:hover { color: var(--danger); border-color: rgba(209, 67, 91, 0.35); background: #fbe7ea; }

/* --- схема: витрины --- */
.dm-tables { display: flex; flex-direction: column; gap: 10px; }
.dm-table { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--navy-850); }
.dm-table-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.dm-toggle {
  flex: 0 0 auto; width: 24px; height: 24px; padding: 0;
  border: 0; border-radius: 6px; background: none;
  color: var(--text-dim); font-size: 12px; line-height: 1; cursor: pointer;
}
.dm-toggle:hover { color: var(--crimson-bright); background: var(--crimson-soft); }
.dm-table-head .dm-table-name { flex: 0 1 220px; font-weight: 600; }
.dm-table-head .dm-table-title { flex: 1 1 240px; min-width: 0; }
.dm-count { flex: 0 0 auto; font-size: 12px; color: var(--text-faint); white-space: nowrap; }

/* --- схема: колонки --- */
.dm-cols {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border-top: 1px solid var(--line-strong); background: var(--navy-900);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.dm-cols[hidden] { display: none; }
.dm-col {
  display: grid; align-items: center; gap: 6px;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 0.9fr) auto minmax(160px, 1.5fr) auto;
}
.dm-col-head {
  font-size: 11.5px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase;
  color: var(--text-faint); padding: 0 2px;
}
.dm-col input[type="text"] { width: 100%; }
/* Флаг-чип (NULL): состояние читается заливкой, а не мелким чекбоксом. */
.dm-flag {
  padding: 5px 9px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--navy-900); color: var(--text-faint);
  font-family: var(--font-mono); font-size: 11px; cursor: pointer; white-space: nowrap;
  transition: color .12s ease, border-color .12s ease, background .12s ease;
}
.dm-flag:hover { border-color: var(--crimson-line); color: var(--text); }
.dm-flag.is-on { background: var(--crimson-soft); border-color: var(--crimson-line); color: var(--crimson); font-weight: 600; }

/* --- примеры --- */
.dm-examples, .dm-rules { display: flex; flex-direction: column; gap: 10px; }
.dm-example {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--navy-850);
}
.dm-example-head, .dm-example-sql { display: flex; align-items: flex-start; gap: 8px; }
.dm-example-head { align-items: center; }
.dm-example-label {
  flex: 0 0 46px; padding-top: 7px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase;
  color: var(--text-faint);
}
.dm-example-head .dm-example-label { padding-top: 0; }
.dm-example-head input, .dm-example-sql textarea { flex: 1 1 auto; min-width: 0; }

/* --- правила --- */
.dm-rule { display: flex; align-items: center; gap: 8px; }
.dm-rule input { flex: 1 1 auto; min-width: 0; }

/* --- междоменные связи --- */
.dm-rels { display: flex; flex-direction: column; gap: 12px; }
.dm-rel {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--navy-850);
}
.dm-rel-main { display: flex; align-items: flex-end; gap: 10px; }
/* Конец связи: домен -> таблица -> колонка одной группой, подпись над ней. */
.dm-rel-side {
  flex: 1 1 0; min-width: 0;
  display: grid; align-items: center; gap: 6px;
  grid-template-columns: 1fr 1fr 1fr; grid-template-rows: auto auto;
}
.dm-rel-side-label {
  grid-column: 1 / -1;
  font-size: 11.5px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase;
  color: var(--text-faint);
}
.dm-rel-pick > input { font-family: var(--font-mono); font-size: 12.5px; }
.dm-rel-arrow { flex: 0 0 auto; padding-bottom: 7px; color: var(--text-dim); font-size: 17px; }
.dm-rel-main .dm-x { margin-bottom: 3px; }
.dm-rel-meta { display: flex; align-items: center; gap: 8px; }
.dm-rel-meta .dm-rel-type { flex: 0 0 190px; }
.dm-rel-meta input { flex: 1 1 auto; min-width: 0; }
.dm-rel-join { display: flex; align-items: center; gap: 8px; }
.dm-rel-join input { flex: 1 1 auto; min-width: 0; }
.dm-rel-join .dm-example-label { padding-top: 0; }
.dm-rel-warn { color: var(--warn); font-size: 12px; }

/* Узкое окно: сетки распадаются в столбец, иначе поля схлопываются в нечитаемые. */
@media (max-width: 900px) {
  .dm-col { grid-template-columns: 1fr 1fr; }
  .dm-col-head { display: none; }
  .dm-rel-main { flex-direction: column; align-items: stretch; }
  .dm-rel-arrow { padding: 0; text-align: center; transform: rotate(90deg); }
}

/* Описание домена — проза, а не код: моноширинный дефолт textarea мешает её читать.
   SQL примера остаётся моноширинным (см. .dm-example-sql). */
.dm-rail .form-section > .field > textarea { font-family: var(--font-body); font-size: 13.5px; }
.dm-example-sql textarea { font-family: var(--font-mono); font-size: 13px; }

/* Кнопки «+ витрина / + колонка / + пример / + правило / + связь» живут в
   flex-колонках и без этого растягивались бы во всю ширину, читаясь как панель. */
.dm-tables > .btn, .dm-cols > .btn, .dm-examples > .btn,
.dm-rules > .btn, .dm-rels > .btn { align-self: flex-start; }

/* ============================================================================
   ЛОГИ (раздел телеметрии): фильтры + раскрываемый список строк лога
   ============================================================================ */

.log-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.log-filters .search-box { flex: 1 1 220px; }
.selectmenu.log-level-menu { flex: none; width: 180px; }

.log-list { padding: 2px 0; }
.log-entry { border-bottom: 1px solid var(--line); }
.log-entry:last-child { border-bottom: none; }
.log-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 12px; }
.log-row.clickable { cursor: pointer; }
.log-row.clickable:hover { background: var(--crimson-soft); }
.log-time { flex: none; font-size: 12px; font-variant-numeric: tabular-nums; }
.log-svc { flex: none; font-size: 12px; }
/* Сообщение забирает остаток ширины и обрезается многоточием в свёрнутом виде. */
.log-msg { flex: 1 1 auto; min-width: 0; font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-trace { flex: none; font-size: 12px; white-space: nowrap; }

.log-detail { display: none; padding: 6px 14px 12px 14px; background: var(--navy-900); }
.log-entry.open > .log-detail { display: block; }
.log-entry.open > .log-row .log-msg { white-space: normal; overflow: visible; }
.log-body { margin: 0 0 8px; padding: 10px 12px; background: var(--navy-850); border: 1px solid var(--line); border-radius: 8px; white-space: pre-wrap; word-break: break-word; color: var(--text); font-size: 12px; max-height: 240px; overflow: auto; }
.log-attrs { display: flex; flex-direction: column; gap: 2px; }
.log-attr { display: flex; gap: 10px; padding: 2px 0; font-size: 12px; }
.log-attr-k { color: var(--text-dim); min-width: 160px; flex: none; }
.log-attr-v { color: var(--text); word-break: break-word; }

/* ============================================================================
   МЕТРИКИ (обозреватель): список слева + детализация справа
   ============================================================================ */

.metrics-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) { .metrics-layout { grid-template-columns: 1fr; } }

.metrics-list { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 12px; }
.metrics-items { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow-y: auto; }
.metrics-group-title { font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--text-faint); margin: 4px 0 2px; }
.metrics-group { display: flex; flex-direction: column; gap: 2px; }
.metrics-item {
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--font-mono);
  word-break: break-word;
}
.metrics-item:hover { background: var(--navy-850); color: var(--text); }
.metrics-item.active { background: var(--crimson-soft); border-color: var(--line); color: var(--text); }

.metrics-detail { min-width: 0; }
.metric-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; }
.metric-ctl { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.metric-ctl select { max-width: 200px; }

/* ====================== Подсказки стартового экрана ====================== */
/* Строка списка: номер, поле во всю ширину, кнопки порядка и удаления справа.
   Своя раскладка, а не .field: там колонка (подпись над контролом), и строка
   рассыпалась бы по вертикали. */
.suggestion-rows { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; }
.suggestion-row { display: flex; align-items: center; gap: 10px; }
.suggestion-row .num {
  min-width: 20px; text-align: right;
  color: var(--text-faint); font-size: 12px; font-family: var(--font-mono);
}
.suggestion-row input[type="text"] { flex: 1; min-width: 0; }
.suggestion-row .row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.suggestion-empty { padding: 22px 18px; color: var(--text-faint); }
.suggestion-counter { color: var(--text-faint); font-size: 12px; margin: 10px 0 0; }

/* ============================================================================
   ЛИЦЕНЗИИ: плашка безопасного режима, таблица позиций каталога, сводка
   ============================================================================ */

/* Плашка режима живёт НАД .content (см. app.js): она общая для всех разделов и
   не стирается переходом между экранами. Пустой контейнер не занимает места. */
.safe-mode-host {
  position: relative; z-index: 1;
  background: #fbe7ea;
  border-bottom: 1px solid rgba(209, 67, 91, 0.35);
  box-shadow: var(--shadow-1);
}
.safe-mode-host:empty { display: none; border: none; box-shadow: none; }
/* Внутренняя колонка выровнена по ширине страницы, а заливка идёт во всю ширину:
   отказ системы должен читаться как состояние всей панели, а не как информер. */
.safe-mode {
  max-width: 1440px; margin: 0 auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 7px;
  color: var(--text); line-height: 1.55;
}
.safe-mode-title {
  font-family: var(--font-display); font-weight: 700; font-size: 20px;
  letter-spacing: 0.2px; color: var(--danger);
}
.safe-mode-reason { color: var(--text); }
.safe-mode-reason b { font-weight: 600; }
.safe-mode-actions { margin-top: 5px; }

/* Таблица позиций каталога: растяжимые - «Предмет» и «Причина», остальные
   колонки ужаты по содержимому (тот же приём, что в таблице отчётов). */
.licenses-table td, .licenses-table th { vertical-align: middle; }
.licenses-table .col-subject { min-width: 180px; }
.licenses-table .col-reason { min-width: 220px; }
.licenses-table .col-id,
.licenses-table .col-type,
.licenses-table .col-major,
.licenses-table .col-term,
.licenses-table .col-state,
.licenses-table .col-source { width: 1%; white-space: nowrap; }
.licenses-table .col-major { text-align: right; font-variant-numeric: tabular-nums; }
/* Срок на исходе: строка подсвечена целиком, чтобы её было видно в длинном списке. */
.licenses-table tbody tr.is-warn { background: #faf4e4; }
.lic-state { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* Сводка под таблицей: инстансы, сборка, ключ, журнал, часы, каталог. */
.lic-summary {
  margin-top: 16px; padding: 18px 20px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px 24px;
}
.lic-sum-label {
  color: var(--text-faint); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.9px;
}
.lic-sum-value { margin-top: 3px; color: var(--text); word-break: break-word; }
.lic-sum-value.mono { font-size: 12.5px; }
.lic-sum-value.tone-err { color: var(--danger); font-weight: 600; }
.lic-sum-value.tone-warn { color: var(--warn); font-weight: 600; }

/* ============================================================================
   СПУТНИКИ: состав установленного, загрузка пакета, снятие
   ============================================================================ */

/* Растяжимое здесь только имя спутника: остальные колонки короткие и ужимаются
   по содержимому (тот же приём, что в таблице лицензий). */
.satellites-table td, .satellites-table th { vertical-align: middle; }
.satellites-table .col-name { min-width: 200px; }
.satellites-table .col-license,
.satellites-table .col-count,
.satellites-table .col-state,
.satellites-table .col-actions { width: 1%; white-space: nowrap; }
.satellites-table .col-count { text-align: right; font-variant-numeric: tabular-nums; }
.satellites-table .col-actions { text-align: right; }

/* Пояснение под таблицей: где проходит граница между тем, что делает панель, и
   тем, что остаётся ручным шагом на сервере. */
.sat-hint {
  margin-top: 16px; padding: 18px 20px;
  display: flex; flex-direction: column; gap: 8px;
  color: var(--text); line-height: 1.55;
}
.sat-hint-title {
  color: var(--text-faint); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.9px;
}

/* ============================================================================
   СТРОКИ ПОСТАВКИ: пометка происхождения и оверлей поверх домена
   ============================================================================ */

/* Пометка «строка пришла с пакетом». Нейтральный тон намеренно: это не ошибка и
   не предупреждение, а класс строки, от которого зависит набор действий. */
.badge.origin {
  margin-left: 8px; font-weight: 600;
  color: var(--text-dim); background: var(--navy-800); border-color: var(--line-strong);
}
/* Заголовок пояснительного информера: у .notice-title цвет предупреждения, а
   здесь предупреждать не о чем, сообщается устройство. */
.notice.muted-note .notice-title { color: var(--text-dim); }

/* Читаемая ширина колонки с числом в таблице «что объявляет пакет». */
.reports-table .col-count {
  width: 1%; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums;
}
/* Описание домена поставки: обычный абзац, а не поле ввода (править нечего). */
.dm-src-desc { margin-bottom: 12px; color: var(--text-dim); line-height: 1.55; }

/* Оверлей: строка на витрину - имя из поставки, своё название, флаг «скрыть». */
.dm-ov-tables { display: flex; flex-direction: column; gap: 8px; }
.dm-ov-row { display: flex; align-items: center; gap: 10px; }
.dm-ov-row .dm-ov-name { flex: 0 1 220px; font-weight: 600; word-break: break-all; }
.dm-ov-row input[type="text"] { flex: 1 1 240px; min-width: 0; }
.dm-ov-hide {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-dim); font-size: 12.5px; white-space: nowrap; cursor: pointer;
}
/* Скрытой витрине название уже незачем: поле гасим, чтобы это было видно. */
.dm-ov-row input.is-muted { opacity: 0.45; }
