/*
   Панель управления АС информирования граждан: оформление консоли.

   Файл автономен и подключается вместо main.css: в _console_base.html (рассылка,
   отчёты, комментарии, эфиры) и на странице входа registration/login.html.
   main.css остаётся для дашборда руководства, страниц smi_pitch_* и broadcast.html.

   Часть разделов (панель, таблицы отчётов, комментарии, тулбар, дерево каналов)
   стилизует те же имена классов, что генерирует main.js строками
   (.panel, .table-report, .comment-* и т.д.). Так отчёты и панель комментариев
   получили новый вид без правок JS.
*/

@font-face { font-family: "Montserrat"; src: url("../fonts/Montserrat/Montserrat-Regular.ttf") format("truetype");  font-weight: 400; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("../fonts/Montserrat/Montserrat-Medium.ttf") format("truetype");   font-weight: 500; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("../fonts/Montserrat/Montserrat-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("../fonts/Montserrat/Montserrat-Bold.ttf") format("truetype");     font-weight: 700; font-display: swap; }

/* Токены: цвета, радиусы, тени, размеры каркаса.
   Палитра снята с фирменного сайта cint19.ru (template_styles.css :root).
   Тёмная тема переопределяет те же переменные под [data-theme="dark"]. */

:root {
  --brand:        #005A9F;
  --brand-deep:   #00457A;
  --brand-soft:   rgba(0, 90, 159, 0.10);
  --brand-line:   rgba(0, 90, 159, 0.28);
  --accent:       #E76238;
  --accent-soft:  rgba(231, 98, 56, 0.12);
  --graphite:     #333333;
  --grey:         #4F4F4F;
  --mist:         #E7EFF1;

  --ok:           #007400;
  --ok-soft:      rgba(0, 116, 0, 0.10);
  --err:          #D10000;
  --err-soft:     rgba(209, 0, 0, 0.10);
  --warn:         #B26A00;

  --bg:           #F4F6F8;
  --surface:      #FFFFFF;
  --surface-2:    #F8FAFB;
  --surface-sunk: #EFF3F6;
  --text:         #20262B;
  --muted:        #66727C;
  --faint:        #98A4AE;
  --line:         rgba(12, 47, 77, 0.12);
  --line-soft:    rgba(12, 47, 77, 0.07);

  --rail-bg:      #2C3237;
  --rail-text:    rgba(255, 255, 255, 0.72);
  --rail-hover:   rgba(255, 255, 255, 0.09);
  --rail-line:    rgba(255, 255, 255, 0.10);

  --input-bg:     #FFFFFF;
  --input-line:   rgba(12, 47, 77, 0.18);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(16, 40, 66, 0.06), 0 1px 3px rgba(16, 40, 66, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 40, 66, 0.08), 0 1px 3px rgba(16, 40, 66, 0.05);
  --shadow-lg: 0 18px 44px rgba(16, 40, 66, 0.16);

  --rail-w: 232px;
  --head-h: 64px;
  --tabbar-h: 60px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: light;
}

[data-theme="dark"] {
  --brand:        #4C9FE0;
  --brand-deep:   #2E86C9;
  --brand-soft:   rgba(76, 159, 224, 0.16);
  --brand-line:   rgba(76, 159, 224, 0.36);
  --accent:       #F0784F;
  --accent-soft:  rgba(240, 120, 79, 0.16);

  --ok:           #4CAF50;
  --ok-soft:      rgba(76, 175, 80, 0.14);
  --err:          #FF6B6B;
  --err-soft:     rgba(255, 107, 107, 0.14);
  --warn:         #E0A030;

  --bg:           #0F1317;
  --surface:      #171D23;
  --surface-2:    #1C232A;
  --surface-sunk: #12171C;
  --text:         #E7ECF0;
  --muted:        #9AA7B2;
  --faint:        #6F7C87;
  --line:         rgba(255, 255, 255, 0.10);
  --line-soft:    rgba(255, 255, 255, 0.06);

  --rail-bg:      #12171C;
  --rail-text:    rgba(255, 255, 255, 0.70);
  --rail-hover:   rgba(255, 255, 255, 0.07);
  --rail-line:    rgba(255, 255, 255, 0.08);

  --input-bg:     #12171C;
  --input-line:   rgba(255, 255, 255, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6);

  color-scheme: dark;
}

/* База */

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body.console {
  overflow: hidden;              /* страница не скроллится, прокрутка внутри панелей */
  background: var(--bg);
  color: var(--text);
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Bootstrap рисует бордеры, <hr> и разделители своими переменными. Без их
   переопределения в тёмной теме остаются светлые рамки. Особенно заметно
   в модалках, которые собирает main.js с классами .border и .border-bottom. */
body.console {
  --bs-border-color: var(--line);
  --bs-border-color-translucent: var(--line);
  --bs-body-color: var(--text);
  --bs-body-bg: var(--bg);
  --bs-emphasis-color: var(--text);
  --bs-secondary-color: var(--muted);
  --bs-secondary-bg: var(--surface-sunk);
  --bs-tertiary-bg: var(--surface-sunk);
  --bs-heading-color: var(--text);
}

.console hr,
.console .dropdown-divider {
  border: 0;
  border-top: 1px solid var(--line);
  opacity: 1;
  margin: 12px 0;
}

.console .border,
.console .border-top,
.console .border-bottom,
.console .border-start,
.console .border-end { border-color: var(--line) !important; }

.console .rounded,
.console .rounded-3 { border-radius: var(--r-sm) !important; }

.console a { color: var(--brand); text-decoration: none; }
.console a:hover { color: var(--brand-deep); text-decoration: underline; }
.console .text-muted { color: var(--muted) !important; }
.console h1, .console h2, .console h3, .console h4, .console h5, .console h6 { font-weight: 600; margin: 0; }

.console ::selection { background: var(--brand-soft); }

/* Тонкие скроллбары в тон: ::-webkit-scrollbar для Chrome/Safari, scrollbar-* для Firefox */
.console *::-webkit-scrollbar { width: 10px; height: 10px; }
.console *::-webkit-scrollbar-track { background: transparent; }
.console *::-webkit-scrollbar-thumb {
  background: var(--line);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}
.console *::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }
.console * { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* Каркас: левый рейл навигации и рабочая область, высота ровно в экран (100dvh) */

.console-shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100dvh;
}

/* Рейл: тёмная левая колонка с логотипом, разделами и пользователем */

.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--rail-bg);
  color: var(--rail-text);
  border-right: 1px solid var(--rail-line);
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--rail-line);
}

.rail-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
}
.rail-mark svg { width: 15px; height: 16px; display: block; }

.rail-brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.rail-brand-text b { font-size: 12.5px; font-weight: 600; color: #fff; letter-spacing: 0.1px; }
.rail-brand-text small { font-size: 11px; color: rgba(255, 255, 255, 0.5); }

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.rail-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--rail-text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.rail-item i { font-size: 16px; flex: 0 0 18px; opacity: 0.9; }
.rail-item > span:not(.rail-dot) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item > .rail-dot { flex: 0 0 7px; }

/* Цвет задаём с запасом по специфичности: иначе общее правило
   `.console a { color: var(--brand) }` красит пункты рейла в ссылочный синий. */
.rail-item:hover,
.console a.rail-item:hover { background: var(--rail-hover); color: #fff; text-decoration: none; }
.console a.rail-item { color: var(--rail-text); text-decoration: none; }
.console a.rail-item.is-active { color: #fff; }

.rail-item.is-active {
  background: var(--brand);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.rail-item.is-active i { opacity: 1; }

.rail-item-hint { font-size: 11px !important; opacity: 0.45; flex: 0 0 auto !important; }

.rail-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(231, 98, 56, 0.2);
}

.rail-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border-top: 1px solid var(--rail-line);
}

.rail-item--external span { flex: 0 1 auto; }

.rail-user {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 6px;
  padding: 8px 10px 4px;
  border-top: 1px solid var(--rail-line);
}
.rail-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.rail-user-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.85);
}
.rail-exit {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  color: var(--rail-text);
  font-size: 14px;
}
.rail-exit:hover { background: var(--rail-hover); color: #fff; text-decoration: none; }

/* Рабочая область: шапка раздела, сообщения Django и тело раздела */

.console-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--head-h);
  padding: 12px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.section-head-titles { flex: 1; min-width: 0; }
.section-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.section-subtitle {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.section-subtitle:empty { display: none; }

.head-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.head-back {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s var(--ease);
}
.head-back:hover { background: var(--surface-sunk); }
.head-back[hidden] { display: none; }

.section-messages { padding: 12px 22px 0; }
.section-messages .alert { margin-bottom: 8px; border-radius: var(--r-sm); }

.section-body {
  flex: 1;
  min-height: 0;
  padding: 18px 22px 22px;
  overflow: hidden;              /* скроллят внутренние панели */
}

/* Сетка колонок раздела */
.cols {
  display: grid;
  gap: 16px;
  height: 100%;
  min-height: 0;
}
.cols--5-7  { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
.cols--4-8  { grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); }
/* Оглавление отчётов - узкий список, а не половина экрана: фиксируем ширину,
   чтобы всё место доставалось таблице. */
.cols--list { grid-template-columns: 272px minmax(0, 1fr); }
.cols--3-3-6 { grid-template-columns: minmax(0, 3fr) minmax(0, 3fr) minmax(0, 6fr); }
.cols--1 { grid-template-columns: minmax(0, 1fr); }

/* Нижняя таб-панель: на десктопе скрыта, показывается в мобильном режиме (см. «Адаптив») */

.tabbar { display: none; }

/* Стек экранов. На десктопе панели стоят рядом, и контроллер стека из console.js
   ничего не делает. На мобильном каждый [data-pane] становится экраном на весь
   вьюпорт, с переходом и кнопкой «назад».
   display: contents убирает сам контейнер из раскладки, и панели становятся
   прямыми колонками сетки .cols. */

[data-stack] { display: contents; }

/* Панель-экран: и на десктопе (колонка сетки), и на мобиле (экран стека)
   должна быть флекс-колонкой с min-height:0, иначе .panel не растянется. */
[data-pane] { display: flex; flex-direction: column; min-height: 0; }

/* Компоненты */

/* Панель-карточка: шапка фиксирована, тело прокручивается */

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
  flex: 0 0 auto;
}
.panel-header h6 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-body {
  padding: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Отчёты рисуются как <div class="panel"><div class="panel-body"> внутри
   #report-result, там панель не должна тянуться на всю высоту. */
#report-result { height: 100%; min-height: 0; overflow-y: auto; }
#report-result > .panel { height: auto; min-height: 100%; }

/* Скролл-блок (используется в шаблонах и main.js) */

.scroll-block { overflow-y: auto; min-height: 0; }

/* Кнопки Bootstrap в цветах консоли */

.console .btn {
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 0.45rem 0.9rem;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.console .btn-sm { font-size: 12.5px; padding: 0.3rem 0.65rem; border-radius: 7px; }

.console .btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.console .btn-primary:hover,
.console .btn-primary:focus { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }

.console .btn-outline-primary { color: var(--brand); border-color: var(--brand-line); background: transparent; }
.console .btn-outline-primary:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

.console .btn-outline-secondary { color: var(--muted); border-color: var(--line); background: transparent; }
.console .btn-outline-secondary:hover { background: var(--surface-sunk); border-color: var(--faint); color: var(--text); }

.console .btn-outline-danger { color: var(--err); border-color: var(--err-soft); }
.console .btn-outline-danger:hover { background: var(--err-soft); border-color: var(--err); color: var(--err); }

.console .btn-danger { background: var(--err); border-color: var(--err); color: #fff; }
.console .btn-success { background: var(--ok); border-color: var(--ok); color: #fff; }
.console .btn-secondary { background: var(--surface-sunk); border-color: var(--line); color: var(--text); }
.console .btn-outline-warning { color: var(--accent); border-color: var(--accent-soft); }
.console .btn-outline-warning:hover,
.console .btn-outline-warning.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.console .btn-check:checked + .btn,
.console .btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.console .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; box-shadow: none; }

/* Формы */

.console .form-control,
.console .form-select {
  padding: 0.5rem 0.7rem;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background-color: var(--input-bg);
  border: 1px solid var(--input-line);
  border-radius: var(--r-sm);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.console .form-control-sm, .console .form-select-sm { padding: 0.32rem 0.55rem; font-size: 12.5px; border-radius: 7px; }

.console .form-control::placeholder { color: var(--faint); }

.console .form-control:focus,
.console .form-select:focus {
  background-color: var(--input-bg);
  color: var(--text);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  outline: none;
}

.console .form-label { font-size: 12.5px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.console .form-text { font-size: 11.5px; color: var(--faint); }

.console .form-check-input { border-color: var(--input-line); background-color: var(--input-bg); }
.console .form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.console .form-check-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.console .form-check-label { font-size: 13px; }

/* Стрелка select у Bootstrap тёмная SVG, в тёмной теме подставляем светлую */
[data-theme="dark"] .console .form-select,
[data-theme="dark"] .form-select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%239AA7B2' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
/* color-scheme переключает встроенный календарь браузера под тему */
.console input[type="date"], .console input[type="datetime-local"] { color-scheme: light; }
[data-theme="dark"] .console input[type="date"],
[data-theme="dark"] .console input[type="datetime-local"] { color-scheme: dark; }

/* Бейджи и алерты: вместо ярких заливок Bootstrap мягкий фон и цветной текст */

.console .badge { font-weight: 500; font-size: 10.5px; padding: 0.3em 0.6em; border-radius: 6px; letter-spacing: 0.2px; }
.console .badge.bg-secondary { background: var(--surface-sunk) !important; color: var(--muted) !important; }
.console .badge.bg-success   { background: var(--ok-soft) !important;  color: var(--ok) !important; }
.console .badge.bg-danger    { background: var(--err-soft) !important; color: var(--err) !important; }
.console .badge.bg-warning   { background: var(--accent-soft) !important; color: var(--accent) !important; }
.console .badge.bg-info      { background: var(--brand-soft) !important; color: var(--brand) !important; }

.console .alert { border-radius: var(--r-sm); border: 1px solid transparent; font-size: 13px; padding: 0.7rem 0.9rem; }
.console .alert-danger  { background: var(--err-soft);  border-color: var(--err-soft);  color: var(--err); }
.console .alert-success { background: var(--ok-soft);   border-color: var(--ok-soft);   color: var(--ok); }
.console .alert-info    { background: var(--brand-soft);border-color: var(--brand-soft);color: var(--brand); }
.console .alert-warning { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }

/* Таблицы отчётов (разметка приходит из main.js). Шапка липкая (position: sticky) при прокрутке */

.table-report {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  color: var(--text);
}

.table-report thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}

.table-report td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.table-report th:last-child, .table-report td:last-child { text-align: right; }
.table-report tbody tr { transition: background 0.12s var(--ease); }
.table-report tbody tr:hover { background: var(--surface-sunk); }
.table-report tbody tr:last-child td { border-bottom: 0; }

.table-responsive { border-radius: var(--r-sm); }

/* Навигация по отчётам */

.report-nav-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.report-nav-spacer { flex: 1; min-width: 8px; }

.report-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease);
}
.report-nav-btn:hover { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); text-decoration: none; }
.report-nav-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.report-nav-btn--outline { border-style: dashed; color: var(--muted); }
.report-nav-btn--outline:hover { border-style: solid; }

/* Вертикальный список отчётов: читается как оглавление, а не как россыпь кнопок */
.report-nav-col { display: flex; flex-direction: column; gap: 3px; }
.report-nav-col .report-nav-btn {
  width: 100%;
  justify-content: flex-start;
  border-radius: var(--r-sm);
  border-color: transparent;
  background: transparent;
  padding: 9px 12px;
  font-size: 13px;
}
.report-nav-col .report-nav-btn:hover { background: var(--brand-soft); border-color: transparent; }
.report-nav-col .report-nav-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.report-nav-col .report-nav-btn i { font-size: 15px; width: 18px; text-align: center; opacity: 0.75; }
.report-nav-col .report-nav-btn.active i { opacity: 1; }
.report-nav-col .report-nav-divider {
  margin: 8px 4px 4px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}

/* Панель комментариев (разметка из main.js) */

.comment-panel-list, .comment-admin-list { min-height: 0; }

.comment-select-item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.14s var(--ease), background 0.14s var(--ease);
}
.comment-select-item + .comment-select-item { margin-top: 6px; }
.comment-select-item:hover { border-color: var(--brand-line); background: var(--surface-2); }
.comment-select-item.active { border-color: var(--brand); background: var(--brand-soft); }

.comment-select-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}
.comment-select-title-main { min-width: 0; overflow: hidden; overflow-wrap: anywhere; }
.comment-select-title .badge { flex: 0 0 auto; align-self: flex-start; max-width: 92px; white-space: nowrap; }
.comment-select-meta { margin-top: 3px; color: var(--muted); font-size: 11.5px; }
.comment-post-preview { display: block; margin-top: 5px; color: var(--text); font-size: 12.5px; line-height: 1.4; overflow-wrap: anywhere; }

.comment-admin-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: 12px;
}
.comment-admin-card + .comment-admin-card { margin-top: 10px; }
.comment-admin-card.hidden-comment { opacity: 0.55; }
.comment-admin-card.ai-hidden-comment { border-left: 3px solid var(--err); opacity: 0.65; }

.comment-admin-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 11.5px;
}
.comment-admin-author { min-width: 0; color: var(--text); font-weight: 600; font-size: 13px; }
.comment-admin-text { margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }

.comment-admin-media { margin-top: 10px; width: min(100%, 360px); }
.comment-admin-media img, .comment-admin-media video {
  display: block;
  width: 100%;
  max-height: 240px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-sunk);
  object-fit: contain;
}

.comment-admin-file {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-sunk);
  color: var(--text);
  padding: 10px;
}
.comment-admin-file:hover { text-decoration: none; border-color: var(--brand); }

.comment-admin-parent {
  margin-top: 8px;
  border-left: 3px solid var(--brand);
  color: var(--muted);
  font-size: 12px;
  padding-left: 9px;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.comment-admin-group + .comment-admin-group { margin-top: 14px; }

/* Ветка ответов: цвет левой линии зависит от глубины вложенности (data-depth) */
.comment-admin-thread {
  position: relative;
  margin-top: 8px;
  padding-left: 14px;
  border-left: 2px solid var(--line);
}
.comment-admin-thread[data-depth="0"] { border-left-color: var(--brand-line); }
.comment-admin-thread[data-depth="1"] { border-left-color: var(--line); }
.comment-admin-thread[data-depth="2"] { border-left-color: var(--line-soft); }
.comment-admin-thread > .comment-admin-card,
.comment-admin-thread > .comment-admin-thread > .comment-admin-card { margin-top: 8px; }
.comment-admin-thread > .comment-admin-card:first-child { margin-top: 0; }

.comment-admin-reply-ref { margin-top: 5px; color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.comment-admin-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* Форма ответа скрыта, пока JS не добавит класс open */
.comment-admin-reply, .comment-admin-channel-reply { display: none; margin-top: 10px; }
.comment-admin-reply.open, .comment-admin-channel-reply.open { display: block; }
.comment-admin-reply textarea, .comment-admin-channel-reply textarea { min-height: 92px; resize: vertical; }

.comment-panel-header-wrap { gap: 12px; align-items: flex-start; }

/* Редактор поста (contenteditable) и панель форматирования. Подсказка в пустом редакторе через ::before */

.fmt-toolbar { display: flex; gap: 3px; flex-wrap: wrap; }

.fmt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.14s var(--ease), border-color 0.14s var(--ease);
}
.fmt-btn:hover { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); }
.fmt-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.fmt-btn mark { background: #FFE066; color: #333; border-radius: 2px; padding: 0 1px; }
.fmt-btn.active mark { background: rgba(255, 255, 255, 0.3); color: #fff; }

.post-editor { cursor: text; line-height: 1.55; }
.post-editor:empty::before { content: attr(data-placeholder); color: var(--faint); pointer-events: none; }
.post-editor h1, .post-editor h2, .post-editor h3,
.post-editor h4, .post-editor h5, .post-editor h6 { font-size: 1.05rem; font-weight: 700; margin: 0.15em 0; line-height: 1.3; }
.post-editor blockquote { border-left: 3px solid var(--brand); padding-left: 10px; margin: 0.25em 0; color: var(--muted); }

/* Список медиафайлов в рассылке */

.bc-media-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-sunk);
  color: var(--text);
  font-size: 12.5px;
}
.bc-media-type {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--brand-soft);
  color: var(--brand);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Дерево каналов на странице рассылки: группы сворачиваются, каналы перетаскиваются между группами */

.group-dropzone { border-radius: var(--r-sm); padding: 2px; transition: background 0.14s var(--ease); }
.group-dropzone.drop-hover { outline: 2px dashed var(--brand); outline-offset: 2px; background: var(--brand-soft); }

.group-header-row { cursor: default; padding: 3px 2px; }
.group-toggle-btn { color: var(--muted); text-decoration: none; background: none; border: 0; }
.group-toggle-btn:hover { color: var(--brand); }
.group-toggle-icon { display: inline-block; width: 1rem; text-align: center; transition: transform 0.15s var(--ease); }
.group-children.collapsed { display: none; }
.group-toggle-icon.collapsed { transform: rotate(-90deg); }

.channel-draggable { cursor: grab; border-radius: 6px; padding: 2px 4px; }
.channel-draggable:hover { background: var(--surface-sunk); }
.channel-draggable.dragging { opacity: 0.55; }

/* Контекстное меню канала */

.channel-ctx-menu {
  position: fixed;
  z-index: 9999;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  /* Меню у нижнего края экрана раньше уезжало за границу: ограничиваем высоту
     и разрешаем прокрутку, а точную позицию правит console.js. */
  max-height: min(70vh, 420px);
  overflow-y: auto;
}
.channel-ctx-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.13s var(--ease);
}
.channel-ctx-item:hover { background: var(--brand-soft); color: var(--brand); }

/* Эфиры: карточка трансляции, у идущей в эфир красная полоса слева */

.event-item {
  border: 1px solid var(--line) !important;
  border-radius: var(--r-md) !important;
  background: var(--surface);
  transition: border-color 0.14s var(--ease), background 0.14s var(--ease);
  cursor: pointer;
}
.event-item:hover { border-color: var(--brand-line) !important; background: var(--surface-2); }
.event-item[data-status="live"] { border-left: 3px solid var(--err) !important; }

/* Модалки и выезжающие панели (offcanvas): уведомления и меню «Ещё» на мобильном */

.console .modal-content,
.modal-content {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.modal-header, .modal-footer { border-color: var(--line-soft); }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-backdrop.show { opacity: 0.45; }
[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%); }

.notifications-offcanvas {
  background: var(--surface);
  color: var(--text);
  border-left: 1px solid var(--line);
}
.notifications-offcanvas .offcanvas-header { border-bottom: 1px solid var(--line-soft); }
.notifications-offcanvas .offcanvas-title { font-size: 15px; font-weight: 600; }
.notifications-offcanvas .accordion-item { background: var(--surface); border-color: var(--line-soft); }
.notifications-offcanvas .accordion-button {
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  box-shadow: none;
}
.notifications-offcanvas .accordion-button:not(.collapsed) { background: var(--brand-soft); color: var(--text); }
.notifications-offcanvas .accordion-body { font-size: 12.5px; color: var(--muted); }

.console .list-group-item { background: var(--surface); color: var(--text); border-color: var(--line-soft); }

.console-more { background: var(--surface); color: var(--text); border-radius: var(--r-lg) var(--r-lg) 0 0; height: auto; }
.console-more .offcanvas-header { border-bottom: 1px solid var(--line-soft); }
.console-more .offcanvas-body { display: flex; flex-direction: column; gap: 4px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

.more-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 12px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.more-item:hover { background: var(--surface-sunk); text-decoration: none; color: var(--text); }
.more-item i { font-size: 17px; color: var(--muted); }
.more-item--exit { color: var(--err); }
.more-item--exit i { color: var(--err); }

/* Индикация загрузки.
   Данных много, запросы идут по 1-2 секунды, и без индикатора интерфейс
   выглядит зависшим. Полоса вверху показывается на время любых fetch-запросов:
   console.js оборачивает fetch и ставит класс is-busy. */

.route-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 10000;
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}
.route-progress.is-busy { opacity: 1; }
.route-progress::before {
  content: "";
  display: block;
  height: 100%;
  width: 40%;
  border-radius: 0 2px 2px 0;
  background: linear-gradient(90deg, transparent, var(--brand) 40%, var(--accent));
  animation: routeSlide 1.1s var(--ease) infinite;
}
@keyframes routeSlide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* Локальный спиннер: подставляется в панели, пока данные не пришли */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 12.5px;
}
.loading-spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spinnerTurn 0.7s linear infinite;
}
@keyframes spinnerTurn { to { transform: rotate(360deg); } }

/* Кнопка в процессе работы: текст прозрачный, поверх крутится спиннер */
.console .btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.console .btn.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spinnerTurn 0.6s linear infinite;
}

/* Пустые состояния */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
}
.empty i { font-size: 30px; color: var(--faint); }
.empty b { font-size: 14px; font-weight: 600; color: var(--text); }
.empty span { font-size: 12.5px; max-width: 320px; }

/* Форма составления рассылки.
   Редактор должен занимать всё свободное место до кнопки отправки, иначе
   между текстом и кнопкой остаётся пустота. */

.bc-compose { display: flex; flex-direction: column; }
.bc-text-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.bc-text-wrap .post-editor {
  flex: 1;
  min-height: 8rem;
  max-height: none;
  overflow-y: auto;
}

/* Нижняя строка панели с кнопками шага (рассылка, эфиры): счётчик выбранного и переход дальше или назад */

.step-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line-soft);
  background: var(--surface);
  flex: 0 0 auto;
}
.step-count { font-size: 12.5px; color: var(--muted); flex: 1; }
.step-count b { color: var(--text); font-weight: 600; }

/* Страница входа */

body.login-page {
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 24px 16px;
  background:
    radial-gradient(1100px 520px at 50% -10%, var(--brand-soft), transparent 70%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 30px 28px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}

.login-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
}
.login-mark svg { width: 22px; height: 24px; }

.login-title { font-size: 17px; font-weight: 600; text-align: center; line-height: 1.35; }
.login-sub { margin: 5px 0 22px; font-size: 12.5px; color: var(--muted); text-align: center; }

.login-field { margin-bottom: 14px; }
.login-field .form-label { display: block; }
.login-card .form-control { padding: 0.6rem 0.75rem; font-size: 14px; }
.login-card .btn-primary { width: 100%; padding: 0.6rem; font-size: 14px; }

.login-foot { margin-top: 20px; text-align: center; font-size: 11.5px; color: var(--faint); }

.login-theme {
  position: fixed;
  top: 16px;
  right: 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 6px 14px;
  cursor: pointer;
}
.login-theme:hover { color: var(--brand); border-color: var(--brand-line); }

/* Адаптив. До 1200px рейл сворачивается до иконок */

@media (max-width: 1200px) {
  :root { --rail-w: 68px; }
  .rail-brand { justify-content: center; padding: 14px 8px; }
  .rail-brand-text { display: none; }
  .rail-item { justify-content: center; padding: 11px 8px; }
  .rail-item span, .rail-item-hint { display: none; }
  .rail-item i { flex: 0 0 auto; font-size: 17px; }
  .rail-user { flex-direction: column; gap: 6px; padding: 10px 4px 4px; }
  .rail-user-name { display: none; }
  .rail-dot { position: absolute; top: 7px; right: 12px; }
  .section-head, .section-body, .section-messages { padding-left: 16px; padding-right: 16px; }
}

/* Мобильный режим (до 992px): рейла нет, внизу таб-панель, панели работают как стек экранов */

@media (max-width: 991.98px) {
  .console-shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }

  .section-head {
    padding: 10px 14px;
    min-height: 56px;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .section-title { font-size: 16px; }
  .section-body { padding: 12px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); }
  .section-messages { padding: 10px 14px 0; }

  /* Колонки схлопываются, их место занимает стек */
  .cols { display: block; height: 100%; }

  /* Стек: активен только один экран (is-active), остальные ждут за правым краем,
     предыдущие (is-behind) сдвинуты влево. overflow: hidden обязателен, иначе
     скруглённый край соседнего экрана выглядывает справа. */
  [data-stack] { display: block; position: relative; height: 100%; overflow: hidden; }

  [data-stack] [data-pane] {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    transform: translateX(100%);
    transition: transform 0.28s var(--ease);
    will-change: transform;
    background: var(--bg);
  }
  [data-stack] [data-pane].is-active { transform: translateX(0); }
  [data-stack] [data-pane].is-behind { transform: translateX(-28%); }

  /* Анимация включается только после класса stack-ready, чтобы экраны не мигали при загрузке */
  [data-stack]:not(.stack-ready) [data-pane] { transition: none; }

  [data-pane] > .panel { height: 100%; border-radius: var(--r-md); }

  /* Полупрозрачная таб-панель с размытием фона; env(safe-area-inset-bottom) учитывает полоску жестов на iPhone */
  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    align-items: stretch;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(18px) saturate(1.3);
    border-top: 1px solid var(--line);
  }

  .tab {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 10px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .tab i { font-size: 18px; }
  .tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
  .tab:hover, .tab:active,
  .console a.tab:hover { color: var(--brand); text-decoration: none; }
  /* Неактивные вкладки должны быть приглушёнными, иначе правило .console a
     красит весь таб-бар в синий и активный пункт перестаёт читаться. */
  .console a.tab { color: var(--muted); text-decoration: none; }
  .console a.tab.is-active { color: var(--brand); }
  .tab.is-active i { transform: translateY(-1px); }
  .tab-dot {
    position: absolute;
    top: 9px;
    left: calc(50% + 7px);
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
  }

  /* Таблицы отчётов: горизонтальный скролл с липкой первой колонкой */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-report { min-width: 560px; }
  .table-report thead th:first-child,
  .table-report tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    box-shadow: 1px 0 0 var(--line-soft);
  }
  .table-report thead th:first-child { z-index: 3; background: var(--surface-2); }

  .panel-header { padding: 10px 12px; }
  .panel-body { padding: 12px; }

  .modal-dialog { margin: 10px; }
  .modal-content { border-radius: var(--r-lg); }

  /* Крупнее тач-цели */
  .comment-select-item { padding: 12px; }
  .console .btn { padding: 0.55rem 1rem; }
  .console .btn-sm { padding: 0.4rem 0.75rem; }
  .report-nav-btn { padding: 8px 14px; font-size: 13px; }
}

@media (max-width: 575.98px) {
  .section-head { gap: 8px; }
  .head-actions .btn span { display: none; }
  .tab span { font-size: 9.5px; }

  /* Модалки на телефоне.
     Диалог по центру с полями по бокам на 390px выглядит зажатым: текст
     переносится, кнопки ломаются в две строки. Разворачиваем на весь экран,
     шапка и подвал модалки липкие. */

  .console .modal-dialog {
    margin: 0;
    max-width: 100%;
    min-height: 100dvh;
  }
  .console .modal-content {
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .console .modal-header {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 12px 14px;
    background: var(--surface);
  }
  .console .modal-body { padding: 14px; }
  .console .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 3;
    gap: 8px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
  }
  .console .modal-footer > .btn { flex: 1 1 0; margin: 0; }

  /* Строка «Медиафайлы» и подобные подписи с кнопками справа ставим в столбик,
     кнопки на всю ширину, чтобы в них можно было попасть пальцем. */
  .console .modal-body .form-label.d-flex {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
  }
  .console .modal-body .form-label.d-flex > .d-flex { width: 100%; }
  .console .modal-body .form-label.d-flex > .d-flex > .btn,
  .console .modal-body .form-label.d-flex > .d-flex > label.btn { flex: 1 1 0; justify-content: center; }

  /* Редактор поста: на весь доступный экран, раз модалка полноэкранная */
  .console .modal-body .post-editor { min-height: 46vh !important; max-height: none !important; }

  .console .fmt-toolbar { gap: 4px; }
  .console .fmt-btn { min-width: 34px; height: 34px; }
}

/* Если в системе включено «уменьшить движение», анимации и переходы фактически отключаются */
@media (prefers-reduced-motion: reduce) {
  .console *, .console *::before, .console *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
