/* ==========================================================================
   Viber AI Bot — админка
   Один файл, разбит на секции. Правки безопасно делать точечно:
   всё построено на CSS-переменных из :root.
   ========================================================================== */

/* --- 1. Токены темы ------------------------------------------------------ */
:root {
    --bg:            #f4f5f9;
    --surface:       #ffffff;
    --surface-2:     #f8f9fc;
    --surface-3:     #eef0f6;
    --border:        #e3e6ef;
    --border-strong: #cdd2e1;

    --text:          #1b1f2b;
    --text-muted:    #6b7280;
    --text-faint:    #9aa1b1;

    --accent:        #6d5efc;
    --accent-hover:  #5b4bea;
    --accent-soft:   #eeecff;
    --accent-text:   #ffffff;

    --success:       #16a34a;
    --success-soft:  #e7f7ed;
    --warning:       #d97706;
    --warning-soft:  #fdf3e3;
    --danger:        #dc2626;
    --danger-soft:   #fdecec;

    --sidebar-bg:    #171a24;
    --sidebar-text:  #a7adbd;
    --sidebar-hover: #232735;
    --sidebar-active:#2b2f42;

    --radius:        12px;
    --radius-sm:     8px;
    --radius-lg:     18px;
    --shadow:        0 1px 2px rgba(16, 20, 40, .05), 0 8px 24px -12px rgba(16, 20, 40, .16);
    --shadow-lg:     0 24px 60px -20px rgba(16, 20, 40, .3);

    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:            #0f1117;
        --surface:       #171a22;
        --surface-2:     #1c202a;
        --surface-3:     #232833;
        --border:        #262b36;
        --border-strong: #363c4a;

        --text:          #e7e9ef;
        --text-muted:    #9aa2b4;
        --text-faint:    #6d7488;

        --accent-soft:   #241f4d;

        --success-soft:  #10281a;
        --warning-soft:  #2b2011;
        --danger-soft:   #2c1618;

        --sidebar-bg:    #12141b;
        --sidebar-hover: #1c202a;
        --sidebar-active:#252a38;

        --shadow:        0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
        --shadow-lg:     0 24px 60px -20px rgba(0, 0, 0, .7);
    }
}

/* --- 2. База ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

.icon { flex: none; }

/* --- 3. Каркас: сайдбар + контент --------------------------------------- */
.app {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 20px 14px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 8px 14px;
    color: #fff;
}

/* Список разделов забирает всё свободное место и прокручивается сам:
   шапка и блок пользователя остаются на виду при любой высоте окна. */
.sidebar__nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #3a4052 transparent;
}

.sidebar__nav::-webkit-scrollbar { width: 6px; }
.sidebar__nav::-webkit-scrollbar-thumb { background: #3a4052; border-radius: 6px; }
.sidebar__nav::-webkit-scrollbar-track { background: transparent; }

.sidebar__logo {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #7c6cff, #5b4bea);
    color: #fff;
    box-shadow: 0 6px 16px -6px rgba(109, 94, 252, .9);
}

.sidebar__brand strong { display: block; font-size: 14.5px; line-height: 1.2; }
.sidebar__brand span   { font-size: 11.5px; color: #7d849a; }

.sidebar__group {
    margin: 12px 8px 4px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #626a80;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 7px 10px;
    margin-bottom: 1px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
    transition: background .14s, color .14s;
}

.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }

.nav-item.is-active {
    background: var(--sidebar-active);
    color: #fff;
    box-shadow: inset 2px 0 0 var(--accent);
}

.nav-item__badge {
    margin-left: auto;
    padding: 1px 7px;
    border-radius: 20px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
}

.sidebar__footer {
    flex: none;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid #23262f;
}

.sidebar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    font-size: 13px;
}

.sidebar__avatar {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
    font-size: 12px;
}

/* --- 4. Шапка страницы и контейнер -------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 28px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.topbar__title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.topbar__title span { font-size: 12.5px; color: var(--text-muted); }
.topbar__actions { display: flex; gap: 8px; margin-left: auto; }

.page { padding: 24px 28px 48px; }

.grid { display: grid; gap: 16px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

@media (max-width: 1180px) {
    .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid--sidebar, .grid--3 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    /* Меню разворачивается целиком: страница и так прокручивается. */
    .sidebar__nav { overflow: visible; }
    .grid--2 { grid-template-columns: minmax(0, 1fr); }
    .page, .topbar { padding-left: 16px; padding-right: 16px; }
}

/* --- 5. Карточки --------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
}

.card__header h2 { display: flex; align-items: center; gap: 9px; }
.card__header .muted { font-size: 12.5px; }
.card__header-actions { display: flex; gap: 8px; margin-left: auto; }

.card__body   { padding: 18px; }
.card__body--flush { padding: 0; }
.card__footer { padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

.card__icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--accent-soft);
    color: var(--accent);
}

/* --- 6. Статистика ------------------------------------------------------- */
.stat {
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat__label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted); }
.stat__value { margin-top: 6px; font-size: 28px; font-weight: 680; letter-spacing: -.02em; }
.stat__hint  { font-size: 12px; color: var(--text-faint); }

/* --- 7. Кнопки ----------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    font-size: 13.5px;
    cursor: pointer;
    white-space: nowrap;
    transition: background .14s, border-color .14s, color .14s, transform .06s;
}

.btn:hover     { background: var(--surface-3); text-decoration: none; }
.btn:active    { transform: translateY(1px); }
.btn:disabled  { opacity: .55; cursor: not-allowed; transform: none; }

.btn--primary  { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn--ghost    { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }

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

.btn--sm  { padding: 5px 10px; font-size: 12.5px; }
.btn--icon { padding: 6px; }
.btn--block { width: 100%; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* --- 8. Формы ------------------------------------------------------------ */
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }

.field__label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 560;
}

.field__help { margin-top: 6px; font-size: 12px; color: var(--text-muted); }

.input, .textarea, .select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13.5px;
    transition: border-color .14s, box-shadow .14s;
}

.input:focus, .textarea:focus, .select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.textarea--code { font-family: var(--mono); font-size: 12.5px; }

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.input-group { display: flex; gap: 8px; align-items: center; }
.input-group .input { flex: 1; }

/* Переключатель */
.switch { display: flex; align-items: flex-start; gap: 11px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch__track {
    position: relative;
    flex: none;
    width: 38px;
    height: 22px;
    margin-top: 1px;
    border-radius: 20px;
    background: var(--border-strong);
    transition: background .16s;
}

.switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    transition: transform .16s;
}

.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--accent-soft); }

.switch__text strong { display: block; font-size: 13px; font-weight: 560; }
.switch__text span   { font-size: 12px; color: var(--text-muted); }

/* Ползунок score */
.range { display: flex; align-items: center; gap: 12px; }

.range input[type="range"] {
    flex: 1;
    height: 4px;
    border-radius: 4px;
    background: var(--surface-3);
    appearance: none;
    cursor: pointer;
}

.range input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 3px solid var(--surface);
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

.range input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: 3px solid var(--surface);
    border-radius: 50%;
    background: var(--accent);
}

.range__value {
    min-width: 54px;
    padding: 3px 8px;
    border-radius: 6px;
    background: var(--surface-3);
    font-family: var(--mono);
    font-size: 12.5px;
    text-align: center;
}

/* --- 9. Таблицы ---------------------------------------------------------- */
.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.table th {
    padding: 10px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
}

.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.nowrap, .table th.nowrap { white-space: nowrap; }
.table td.actions { text-align: right; white-space: nowrap; }

/* --- 10. Бейджи и метки -------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 20px;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 560;
    white-space: nowrap;
}

.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--accent  { background: var(--accent-soft);  color: var(--accent); }
.badge--mono    { font-family: var(--mono); letter-spacing: .02em; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pre-wrap { white-space: pre-wrap; word-break: break-word; }

/* Score */
.score {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 9px;
    border-radius: 20px;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
}

.score-high { background: var(--success-soft); color: var(--success); }
.score-mid  { background: var(--warning-soft); color: var(--warning); }
.score-low  { background: var(--surface-3);    color: var(--text-faint); }

.score-bar { height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.score-bar__fill { height: 100%; border-radius: 4px; background: var(--accent); }

/* --- 11. Уведомления ----------------------------------------------------- */
.flash-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 380px;
}

.flash {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    font-size: 13.5px;
    animation: flash-in .22s ease-out;
}

.flash--success { border-left: 3px solid var(--success); }
.flash--error   { border-left: 3px solid var(--danger); }
.flash button   { margin-left: auto; border: 0; background: none; color: var(--text-faint); cursor: pointer; padding: 0; }

@keyframes flash-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.notice {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--text);
    font-size: 13px;
}

.notice--warning { background: var(--warning-soft); }
.notice--danger  { background: var(--danger-soft); }
.notice svg { color: var(--accent); }

/* --- 12. Пустые состояния и пагинация ------------------------------------ */
.empty { padding: 48px 24px; text-align: center; color: var(--text-muted); }
.empty svg { color: var(--text-faint); margin-bottom: 10px; }
.empty h3 { margin-bottom: 6px; color: var(--text); }

.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 14px; }
.pagination a, .pagination span {
    min-width: 32px;
    padding: 5px 9px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-align: center;
    font-size: 13px;
}
.pagination a:hover { background: var(--surface-3); text-decoration: none; }
.pagination .is-active { background: var(--accent); color: #fff; font-weight: 600; }

/* --- 13. Чат (тестовый и живые переписки) -------------------------------- */
.chat {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 340px;
    max-height: 62vh;
    padding: 20px;
    overflow-y: auto;
    background: var(--surface-2);
}

.bubble-row { display: flex; gap: 10px; align-items: flex-end; }
.bubble-row--user { flex-direction: row-reverse; }

.bubble {
    max-width: min(560px, 78%);
    padding: 10px 14px;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 13.5px;
    line-height: 1.55;
}

/* Переносы строк из сообщения сохраняем здесь, иначе отступы разметки
   шаблона попали бы в текст пузыря. */
.bubble__text { white-space: pre-wrap; word-break: break-word; }

.bubble--user      { background: var(--accent); border-color: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.bubble--assistant { border-bottom-left-radius: 5px; }
.bubble--system    { max-width: 100%; background: var(--warning-soft); border-color: transparent; color: var(--warning); font-size: 12.5px; }

.bubble__meta { margin-top: 6px; font-size: 11px; opacity: .75; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.bubble img { max-width: 240px; border-radius: 10px; display: block; margin-top: 8px; }

.bubble-avatar {
    display: grid;
    place-items: center;
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 650;
}

.chat-form { display: flex; gap: 10px; align-items: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); }
.chat-form .textarea { min-height: 44px; max-height: 160px; }

.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--text-faint);
    animation: typing 1.1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }

@keyframes typing { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* --- 13b. Переключатель отправителя в тестовом чате ---------------------- */
.sender-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px 0;
    flex-wrap: wrap;
}

/* Реплика менеджера: та же сторона, что и бот, но заметно отличается. */
.bubble--manager {
    background: var(--warning-soft);
    border-color: color-mix(in srgb, var(--warning) 35%, transparent);
    border-bottom-left-radius: 5px;
}

.bubble--silent {
    background: transparent;
    border-style: dashed;
    color: var(--text-faint);
    font-style: italic;
}

/* Служебная отметка в ленте: что произошло после реплики клиента.
   Намеренно не похожа на реплику — это запись для оператора,
   клиенту она никуда не уходит. */
.chat-event {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 86%;
    margin: 0 auto 10px;
    padding: 6px 13px;
    border: 1px dashed var(--border-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-faint);
    font-size: 12px;
}

.chat-event__dot {
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
}

.chat-event__time { margin-left: auto; white-space: nowrap; }

.chat-event--off .chat-event__dot,
.chat-event--duplicate .chat-event__dot { background: var(--warning); }

.chat-event--error .chat-event__dot,
.chat-event--undelivered .chat-event__dot { background: var(--danger); }

.chat-event--call .chat-event__dot { background: var(--accent); }

/* Подменённое время в тестовом чате — чтобы не спутать его с настоящим. */
#prompt-time.is-faked {
    color: var(--warning);
    font-weight: 600;
}

/* --- 14. Отладочная панель тестового чата -------------------------------- */
.match {
    padding: 11px 13px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.match--used { border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }
.match__head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.match__title { font-weight: 560; font-size: 12.5px; }
.match__text { font-size: 12.5px; color: var(--text-muted); }
.match__text b { color: var(--text); font-weight: 560; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 12.5px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12px; word-break: break-all; }

details.debug { margin-top: 10px; }
details.debug summary { cursor: pointer; font-size: 12.5px; color: var(--text-muted); }
details.debug pre {
    margin: 8px 0 0;
    padding: 12px;
    max-height: 320px;
    overflow: auto;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    font-size: 11.5px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- 15. Вкладки и списки реплик ---------------------------------------- */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-3); border-radius: var(--radius-sm); }
.tabs a {
    padding: 6px 14px;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 540;
}
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.turn {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
    padding: 10px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.turn .textarea { min-height: 62px; background: var(--surface); }

@media (max-width: 700px) { .turn { grid-template-columns: minmax(0, 1fr); } }

/* --- 16. Мелочи ---------------------------------------------------------- */
.copy-field {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-family: var(--mono);
    font-size: 12px;
    word-break: break-all;
}

.checklist { display: flex; flex-direction: column; gap: 2px; }

.checklist__item { display: flex; gap: 11px; align-items: flex-start; padding: 9px 10px; border-radius: var(--radius-sm); }
.checklist__item:hover { background: var(--surface-2); }

.checklist__mark {
    display: grid;
    place-items: center;
    flex: none;
    width: 20px;
    height: 20px;
    margin-top: 1px;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--text-faint);
}

.checklist__item.is-done .checklist__mark { background: var(--success-soft); color: var(--success); }
.checklist__item strong { font-size: 13px; font-weight: 550; }
.checklist__item span { display: block; font-size: 12px; color: var(--text-muted); }

.divider { height: 1px; margin: 16px 0; background: var(--border); border: 0; }

.stack   { display: flex; flex-direction: column; gap: 12px; }
.stack--sm { gap: 8px; }
.row     { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.spacer  { flex: 1; }

.progress { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.progress__fill { height: 100%; background: var(--accent); transition: width .3s; }

/* --- 16b. Массовые действия и правка категории в списке FAQ -------------- */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--accent-soft);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

/* Без этой строки display:flex перебивает атрибут hidden и панель
   видна даже тогда, когда ничего не отмечено. */
.bulk-bar[hidden] { display: none; }

/* Ячейка категории: выглядит как текст, ведёт себя как кнопка. */
.category-edit {
    padding: 2px;
    border: 0;
    border-radius: 6px;
    background: none;
    font: inherit;
    color: inherit;
    cursor: text;
    text-align: left;
}

.category-edit:hover { background: var(--surface-3); }

.category-input,
.category-select { min-width: 170px; padding: 4px 26px 4px 8px; font-size: 12.5px; }

.table input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* --- 16c. Выбор категорий FAQ в настройках ------------------------------- */
.category-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.category-pick {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    font-size: 12.5px;
    cursor: pointer;
}

.category-pick:hover { border-color: var(--accent); }
.category-pick input { accent-color: var(--accent); cursor: pointer; }
.category-pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* --- 16d. Список тегов шаблона сообщения --------------------------------- */
.tag-list { display: flex; flex-direction: column; gap: 4px; }

.tag-list__row {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 10px;
    align-items: baseline;
    font-size: 12.5px;
}

.tag-list__row code { color: var(--accent); }

@media (max-width: 700px) {
    .tag-list__row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}

/* --- 17. Страница входа -------------------------------------------------- */
.auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background:
        radial-gradient(1100px 520px at 12% -8%, color-mix(in srgb, var(--accent) 18%, transparent), transparent),
        var(--bg);
}

.auth__card { width: 100%; max-width: 380px; padding: 30px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.auth__logo { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 16px; border-radius: 13px; background: linear-gradient(135deg, #7c6cff, #5b4bea); color: #fff; }
