/* ==========================================================================
   Цветовые токены темы (светлая — значения по умолчанию в :root)
   Тёмная тема переопределяет те же переменные в [data-theme="dark"].
   Атрибут data-theme на <html> выставляется скриптом (см. theme.js в script.js)
   на основе сохранённого выбора пользователя (авто / светлая / тёмная).
   ========================================================================== */
:root {
    color-scheme: light dark;

    /* Фон страницы (градиент) */
    --bg-start: #eef2ff;
    --bg-end: #e2e8f0;

    /* Текст */
    --text: #0f172a;
    --text-muted: rgba(15, 23, 42, 0.68);
    --text-faint: rgba(15, 23, 42, 0.46);

    /* Поверхности (карточки, секции) */
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --surface-strong: #e9eef7;
    --surface-sunken: #f8fafc;

    /* Границы */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Тени */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.07);
    --shadow-md: 0 10px 26px rgba(15, 23, 42, 0.10);
    --shadow-lg: 0 24px 48px rgba(15, 23, 42, 0.16);

    /* Акцентный цвет */
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.12);

    /* Кнопки */
    --btn-bg: #eef2f7;
    --btn-bg-hover: #e2e8f0;
    --btn-text: #0f172a;
    --btn-primary-bg: var(--accent);
    --btn-primary-bg-hover: var(--accent-hover);
    --btn-primary-text: #ffffff;
    --btn-danger-bg: #dc2626;
    --btn-danger-bg-hover: #b91c1c;
    --btn-danger-text: #ffffff;

    /* Поля форм */
    --input-bg: #f8fafc;
    --input-border: #cbd5e1;
    --input-focus: var(--accent);

    /* Уведомления */
    --notice-error-bg: #fee2e2;
    --notice-error-text: #991b1b;
    --notice-success-bg: #dcfce7;
    --notice-success-text: #166534;

    /* Статусы */
    --status-active-bg: #dcfce7;
    --status-active-text: #15803d;
    --status-inactive-bg: #fee2e2;
    --status-inactive-text: #b91c1c;

    /* Таблицы */
    --table-head-bg: #f1f5f9;
    --table-border: #e2e8f0;

    /* Навигация / верхние панели */
    --nav-bg: #ffffff;
    --nav-border: #e2e8f0;
    --nav-hover: #f1f5f9;

    /* Редактор кода */
    --code-bg: #f8fafc;
    --code-border: #e2e8f0;
    --code-text: #1e293b;
    --code-comment: #8a97ab;
    --code-string: #2f9e44;
    --code-keyword: #9c36b5;
    --code-number: #e8590c;
    --code-function: #1971c2;
    --code-constant: #e67700;
    --code-operator: #0c8599;

    /* Просмотр логов */
    --log-bg: #f8fafc;
    --log-border: #e2e8f0;
    --log-text: #1e293b;

    /* Подложка для иконок (чтобы были видны на любом фоне) */
    --icon-chip: rgba(15, 23, 42, 0.06);

    /* Скроллбар */
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-track: transparent;

    /* Типографика */
    --font-size-title: 22px;
    --font-size-subtitle: 16px;
    --font-size-large: 18px;
    --font-size: 14px;
    --font-size-btn: 13px;
    --icon-size: 16px;
    --icon-small-size: 12px;
}

/* Тёмная тема — явный выбор пользователя */
:root[data-theme="dark"] {
    --bg-start: #0f172a;
    --bg-end: #020617;

    --text: #f1f5f9;
    --text-muted: rgba(226, 232, 240, 0.75);
    --text-faint: rgba(226, 232, 240, 0.5);

    --surface: #1e293b;
    --surface-hover: #334155;
    --surface-strong: #1e293b;
    --surface-sunken: #0f172a;

    --border: #334155;
    --border-strong: #475569;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.38);
    --shadow-lg: 0 26px 54px rgba(0, 0, 0, 0.5);

    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft: rgba(59, 130, 246, 0.2);

    --btn-bg: #334155;
    --btn-bg-hover: #475569;
    --btn-text: #f1f5f9;
    --btn-primary-bg: #2563eb;
    --btn-primary-bg-hover: #3b82f6;
    --btn-primary-text: #ffffff;
    --btn-danger-bg: #991b1b;
    --btn-danger-bg-hover: #b91c1c;
    --btn-danger-text: #ffffff;

    --input-bg: #0f172a;
    --input-border: #475569;
    --input-focus: #60a5fa;

    --notice-error-bg: #7f1d1d;
    --notice-error-text: #fecaca;
    --notice-success-bg: #14532d;
    --notice-success-text: #bbf7d0;

    --status-active-bg: #166534;
    --status-active-text: #dcfce7;
    --status-inactive-bg: #7f1d1d;
    --status-inactive-text: #fee2e2;

    --table-head-bg: #1e293b;
    --table-border: #334155;

    --nav-bg: #111c30;
    --nav-border: #334155;
    --nav-hover: #1e293b;

    --code-bg: #0b1220;
    --code-border: #334155;
    --code-text: #dbeafe;
    --code-comment: #8492a6;
    --code-string: #a5d6a7;
    --code-keyword: #c792ea;
    --code-number: #f78c6c;
    --code-function: #82aaff;
    --code-constant: #ffcb6b;
    --code-operator: #89ddff;

    --log-bg: #020617;
    --log-border: #334155;
    --log-text: #d1d5db;

    --icon-chip: rgba(255, 255, 255, 0.09);

    --scrollbar-thumb: #475569;
    --scrollbar-track: transparent;
}

/* Резерв на случай отключённого JavaScript: следуем системной теме устройства */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg-start: #0f172a;
        --bg-end: #020617;
        --text: #f1f5f9;
        --text-muted: rgba(226, 232, 240, 0.75);
        --text-faint: rgba(226, 232, 240, 0.5);
        --surface: #1e293b;
        --surface-hover: #334155;
        --surface-strong: #1e293b;
        --surface-sunken: #0f172a;
        --border: #334155;
        --border-strong: #475569;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
        --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.38);
        --shadow-lg: 0 26px 54px rgba(0, 0, 0, 0.5);
        --accent: #3b82f6;
        --accent-hover: #60a5fa;
        --accent-soft: rgba(59, 130, 246, 0.2);
        --btn-bg: #334155;
        --btn-bg-hover: #475569;
        --btn-text: #f1f5f9;
        --btn-primary-bg: #2563eb;
        --btn-primary-bg-hover: #3b82f6;
        --btn-danger-bg: #991b1b;
        --btn-danger-bg-hover: #b91c1c;
        --input-bg: #0f172a;
        --input-border: #475569;
        --input-focus: #60a5fa;
        --notice-error-bg: #7f1d1d;
        --notice-error-text: #fecaca;
        --notice-success-bg: #14532d;
        --notice-success-text: #bbf7d0;
        --status-active-bg: #166534;
        --status-active-text: #dcfce7;
        --status-inactive-bg: #7f1d1d;
        --status-inactive-text: #fee2e2;
        --table-head-bg: #1e293b;
        --table-border: #334155;
        --nav-bg: #111c30;
        --nav-border: #334155;
        --nav-hover: #1e293b;
        --code-bg: #0b1220;
        --code-border: #334155;
        --code-text: #dbeafe;
        --code-comment: #8492a6;
        --code-string: #a5d6a7;
        --code-keyword: #c792ea;
        --code-number: #f78c6c;
        --code-function: #82aaff;
        --code-constant: #ffcb6b;
        --code-operator: #89ddff;
        --log-bg: #020617;
        --log-border: #334155;
        --log-text: #d1d5db;
        --icon-chip: rgba(255, 255, 255, 0.09);
        --scrollbar-thumb: #475569;
    }
}

/* ==========================================================================
   Базовые сбросы и общие стили страницы
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box; /* padding и border не увеличивают заданный размер */
}

html {
    -webkit-text-size-adjust: 100%; /* отключает автоувеличение текста на iOS при повороте экрана */
}

body {
    margin: 0; /* убирает отступы по умолчанию */
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; /* системный шрифт */
    background: linear-gradient(135deg, var(--bg-start), var(--bg-end)); /* градиентный фон темы */
    color: var(--text);
    transition: background-color 0.25s ease, color 0.25s ease; /* плавная смена темы */
}

/* Плавный переход цветов при переключении темы для основных элементов интерфейса */
.contact-card,
.btn,
.admin-section,
.auth-card,
input,
select,
textarea,
table,
th,
td,
.user-navigation a,
.notice,
.status,
.code-editor,
.code-highlight,
.log-view,
.updater-card,
.theme-option,
.account-actions,
.user-navigation {
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

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

/* Тонкий скроллбар, учитывающий тему (поддерживающие браузеры) */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

/* Единый стиль фокуса с клавиатуры */
a:focus-visible,
button:focus-visible,
.theme-option:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}

/* Центральный блок с ограничением ширины */
.container {
    max-width: 960px; /* максимальная ширина контента */
    margin: auto; /* центрирование по горизонтали */
    justify-content: center; /* выравнивание содержимого по центру */
    padding: clamp(20px, 6vw, 44px) clamp(14px, 4vw, 20px); /* адаптивные отступы */
}

/* Шапка страницы (аватар + имя) */
.header {
    text-align: center; /* выравнивание текста по центру */
    margin-bottom: clamp(30px, 6vw, 50px); /* отступ снизу от шапки */
}

.header h1 {
    font-size: clamp(24px, 5vw, 32px); /* адаптивный размер заголовка */
}

/* Круглый блок с аватаром */
.avatar {
    width: clamp(88px, 24vw, 120px); /* ширина аватара адаптируется под экран */
    height: clamp(88px, 24vw, 120px); /* высота аватара */
    border-radius: 50%; /* делает блок круглым */
    background: var(--surface-strong); /* фон темы */
    box-shadow: var(--shadow-md), inset 0 0 0 1px var(--border);
    margin: auto; /* центрирование по горизонтали */
    margin-bottom: 20px; /* отступ снизу */
    display: flex; /* flex-контейнер для центрирования содержимого */
    align-items: center; /* выравнивание по вертикали */
    justify-content: center; /* выравнивание по горизонтали */
    font-size: clamp(32px, 8vw, 40px); /* размер эмодзи внутри */
    transition: transform 0.3s, box-shadow 0.3s; /* плавная анимация при наведении */
}
.avatar:hover {
    transform: scale(1.06); /* лёгкое увеличение аватара при наведении */
    box-shadow: var(--shadow-lg), inset 0 0 0 1px var(--border);
}

h1 {
    margin: 10px 0; /* отступы сверху и снизу заголовка */
}

/* Подзаголовок под именем */
.subtitle {
    color: var(--text-muted); /* приглушённый цвет текста темы */
}

/* Сетка карточек */
.cards {
    display: flex; /* располагает карточки в ряд */
    flex-wrap: wrap; /* переносит карточки на новую строку если не хватает места */
    gap: 12px; /* отступ между карточками */
    justify-content: center; /* центрирует карточки */
    margin-top: 10px; /* отступ сверху */
}

/* Одна карточка (контакт или VPN-клиент) */
.contact-card {
    background: var(--surface); /* фон карточки по теме */
    padding: 16px; /* внутренние отступы */
    border-radius: 14px; /* скруглённые углы */
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    flex: 1 1 160px; /* гибкая ширина — адаптируется под экран */
    max-width: 200px; /* верхний предел ширины на широких экранах */
    display: flex; /* flex-контейнер */
    flex-direction: column; /* элементы идут сверху вниз */
    align-items: center; /* выравнивание по центру */
    text-align: center; /* текст по центру */
    transition: transform 0.2s, background-color 0.2s, box-shadow 0.2s; /* плавная анимация при наведении */
}
.contact-card:hover {
    transform: translateY(-2px) scale(1.02); /* лёгкое увеличение карточки */
    background: var(--surface-hover); /* фон при наведении */
    box-shadow: var(--shadow-md);
}

/* Название карточки (например "Telegram") */
.contact-name {
    font-weight: 600; /* жирный текст */
    margin-bottom: 8px; /* отступ снизу */
    font-size: var(--font-size-large); /* размер шрифта */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex-wrap: wrap;
}

/* Маленькая иконка рядом с текстом (с подложкой — видна на любой теме) */
.icon {
    width: var(--icon-size); /* ширина иконки */
    height: var(--icon-size); /* высота иконки */
    margin-right: 6px; /* отступ справа от иконки */
    vertical-align: baseline; /* выравнивание по базовой линии текста */
    background: var(--icon-chip); /* подложка под иконку */
    border-radius: 6px; /* скруглённые углы подложки */
    object-fit: contain;
}

/* Вспомогательный текст карточки (логин, номер и т.д.) */
.contact-text {
    font-size: var(--font-size); /* размер шрифта */
    color: var(--text-muted); /* приглушённый цвет текста темы */
    margin-bottom: 6px; /* отступ снизу */
    word-break: break-all; /* перенос длинных строк (ссылок, email) */
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

/* Маленькая иконка внутри текста (например, рядом с логином) */
.icon-small {
    width: var(--icon-small-size); /* ширина иконки */
    height: var(--icon-small-size); /* высота иконки */
    margin-right: 6px; /* отступ справа от иконки */
    vertical-align: baseline; /* выравнивание по базовой линии текста */
    background: var(--icon-chip); /* подложка под иконку */
    border-radius: 4px; /* скруглённые углы подложки */
    object-fit: contain;
}

/* Строка с кнопками внутри карточки */
.contact-actions {
    display: flex; /* кнопки в ряд */
    gap: 6px; /* отступ между кнопками */
    flex-wrap: wrap; /* перенос кнопок на новую строку на узких карточках */
    justify-content: center; /* центрирование кнопок */
}

/* Кнопка / ссылка-кнопка */
.btn {
    padding: 7px 12px; /* внутренние отступы */
    font-size: var(--font-size-btn); /* размер текста */
    font-weight: 500;
    border-radius: 8px; /* скруглённые углы */
    border: 1px solid transparent; /* убирает видимую рамку по умолчанию */
    cursor: pointer; /* курсор-рука при наведении */
    text-decoration: none; /* убирает подчёркивание у ссылок */
    color: var(--btn-text); /* цвет текста по теме */
    background: var(--btn-bg); /* фон кнопки по теме */
    box-shadow: var(--shadow-sm);
    transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s, color 0.2s; /* плавная анимация */
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:hover {
    background: var(--btn-bg-hover); /* фон при наведении */
    transform: translateY(-1px); /* лёгкий сдвиг вверх при наведении */
    box-shadow: var(--shadow-md);
}
.btn:active {
    transform: translateY(0); /* убирает сдвиг при нажатии */
}

/* Состояние кнопки после копирования (зелёная) */
.btn-copied {
    background: #22c55e !important; /* зелёный фон (приоритет над другими стилями) */
    color: white !important; /* белый текст */
}

/* Заголовок секции (VPN-клиенты / Контакты) */
.section-title {
    text-align: center; /* по центру */
    margin: 35px 0 5px; /* отступы: сверху, нет по бокам, снизу */
    font-size: var(--font-size-title); /* размер шрифта */
}

/* Сворачиваемая секция */
.collapsible-section {
    margin-top: 35px; /* отступ сверху как у обычного заголовка секции */
}

/* Заголовок сворачиваемой секции */
.collapsible-section > .section-title {
    display: flex; /* выравнивает текст и стрелку */
    align-items: center; /* центрирование по вертикали */
    justify-content: center; /* центрирование по горизонтали */
    gap: 8px; /* отступ между текстом и стрелкой */
    margin-top: 0; /* отступ уже задан секции */
    cursor: pointer; /* показывает, что заголовок кликабельный */
    list-style: none; /* скрывает стандартный маркер */
    user-select: none; /* не выделяет текст при быстром клике */
}

.collapsible-section > .section-title::-webkit-details-marker {
    display: none; /* скрывает стандартный маркер в WebKit-браузерах */
}

.collapsible-section > .section-title::after {
    content: "▾"; /* стрелка состояния */
    font-size: var(--font-size-subtitle); /* размер стрелки */
    color: var(--text-muted);
    transition: transform 0.2s; /* плавный поворот при раскрытии */
}

.collapsible-section.is-open > .section-title::after {
    transform: rotate(180deg); /* поворачивает стрелку при раскрытии */
}

/* Обёртка содержимого сворачиваемой секции (для анимации высоты) */
.collapsible-content {
    overflow: hidden; /* скрывает контент за пределами анимируемой высоты */
    transition: height 0.3s ease; /* плавное изменение высоты */
}

/* Описание под заголовком секции */
.section-description {
    text-align: center; /* по центру */
    max-width: 620px; /* ограничение ширины текста */
    margin: 0 auto 20px; /* центрирование и отступ снизу */
    color: var(--text-muted); /* приглушённый цвет текста темы */
    font-size: var(--font-size-subtitle); /* размер шрифта */
    line-height: 1.4; /* межстрочный интервал */
}

/* Иконка загрузки (не используется, оставлена про запас) */
.download-icon {
    font-size: var(--font-size-large); /* размер иконки */
    margin-bottom: 8px; /* отступ снизу */
}

/* Подвал страницы */
.footer {
    text-align: center; /* по центру */
    margin-top: 40px; /* отступ сверху */
    color: var(--text-faint); /* едва заметный текст темы */
}

/* Две колонки внутри карточки (например v2rayNG и Happ рядом) */
.download-columns {
    display: flex; /* колонки в ряд */
    flex-wrap: wrap; /* перенос колонок на узких экранах */
    gap: 10px; /* отступ между колонками */
    justify-content: center; /* центрирование */
    width: 100%; /* занимает всю ширину карточки */
}

/* Одна колонка с кнопкой скачивания */
.download-column {
    display: flex; /* элементы в колонку */
    flex-direction: column; /* сверху вниз */
    align-items: center; /* по центру */
    gap: 8px; /* отступ между элементами */
    flex: 1 1 110px; /* колонки делят ширину поровну и переносятся при нехватке места */
    min-width: 110px;
}

/* Название файла/приложения над кнопкой */
.download-title {
    font-size: 14px; /* размер шрифта */
    color: var(--text-muted); /* приглушённый цвет текста темы */
    word-break: break-all; /* перенос длинных названий */
    display: flex;
    align-items: center;
    gap: 2px;
}

/* Кнопка скачивания на всю ширину колонки */
.download-column .btn {
    width: 100%; /* на всю ширину колонки */
    box-sizing: border-box; /* padding не увеличивает ширину */
    justify-content: center;
    text-align: center; /* текст по центру */
    white-space: nowrap; /* текст не переносится на новую строку */
}

/* Дополнительная ширина */
.additional-width {
    flex: 1 1 280px; /* гибкая ширина вместо фиксированной */
    max-width: 360px; /* верхний предел на широких экранах */
}

/* ==========================================================================
   Переключатель темы (авто / светлая / тёмная)
   ========================================================================== */
.theme-switcher {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: var(--nav-bg);
    border: 1px solid var(--nav-border);
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
}

.theme-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, transform 0.2s;
}

.theme-option:hover {
    background: var(--nav-hover);
    color: var(--text);
}

.theme-option.is-active {
    background: var(--accent);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

/* ### Навигация и авторизация */
.account-actions {
    position: fixed;
    top: 12px;
    right: 14px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    font-size: 14px;
    max-width: calc(100vw - 16px);
}

.account-actions form {
    margin: 0;
}

.account-username {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: var(--nav-bg);
    border: 1px solid var(--nav-border);
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

.auth-card,
.admin-section {
    max-width: 1000px;
    margin: 24px auto;
    padding: clamp(16px, 4vw, 24px);
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-md);
}

.auth-card {
    max-width: 420px;
}

.form-stack,
.form-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-stack label,
.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-stack input,
.form-grid input,
.form-grid select,
.inline-form input,
.inline-form select {
    box-sizing: border-box;
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text);
    font: inherit;
}

.form-stack input:focus,
.form-grid input:focus,
.form-grid select:focus,
.inline-form input:focus,
.inline-form select:focus {
    outline: 2px solid var(--input-focus);
    outline-offset: 1px;
}

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

.btn.danger {
    background: var(--btn-danger-bg);
    color: var(--btn-danger-text);
}
.btn.danger:hover {
    background: var(--btn-danger-bg-hover);
}

.notice {
    margin: 12px 0;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 14px;
}

.notice.error {
    background: var(--notice-error-bg);
    color: var(--notice-error-text);
}

.notice.success {
    background: var(--notice-success-bg);
    color: var(--notice-success-text);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr)) auto;
    align-items: end;
}

.table-wrap {
    overflow-x: auto;
    border-radius: 10px;
}

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

th,
td {
    padding: 10px;
    border-bottom: 1px solid var(--table-border);
    text-align: left;
    vertical-align: top;
}

thead {
    background: var(--table-head-bg);
}

.inline-form,
.user-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.inline-form input {
    width: 140px;
}

.inline-form select {
    max-width: 145px;
}

.user-actions form {
    margin: 0;
}

.status {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 999px;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 600;
}

.status.active {
    background: var(--status-active-bg);
    color: var(--status-active-text);
}

.status.inactive {
    background: var(--status-inactive-bg);
    color: var(--status-inactive-text);
}

@media (max-width: 1000px) {
    .form-grid {
        grid-template-columns: repeat(2, minmax(140px, 1fr));
    }
}

@media (max-width: 800px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .container {
        padding-top: 24px;
    }
}


/* ### Панель настроек администратора */
.settings-button {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    font-weight: 600;
}
.settings-button:hover {
    background: var(--btn-primary-bg-hover);
}

.settings-tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 18px auto 26px;
}

.settings-tabs a {
    background: var(--btn-bg);
}

.updater-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.updater-card {
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-sunken);
    box-shadow: var(--shadow-sm);
}

.updater-card h3 {
    margin-top: 0;
}

.config-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.config-form textarea {
    box-sizing: border-box;
    width: 100%;
    min-height: 420px;
    resize: vertical;
    padding: 12px;
    border: 1px solid var(--input-border);
    border-radius: 10px;
    background: var(--code-bg);
    color: var(--code-text);
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
    tab-size: 4;
    white-space: pre;
    overflow: auto;
}

.muted {
    color: var(--text-muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

@media (max-width: 800px) {
    .updater-grid {
        grid-template-columns: 1fr;
    }

    .account-actions {
        max-width: calc(100vw - 16px);
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}


/* ### Карточки встроенных скриптов */
.updater-card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.updater-card-heading h3 {
    margin-top: 0;
    margin-bottom: 8px;
}

.updater-state-line {
    margin: 8px 0 16px;
}

.updater-actions,
.editor-toolbar,
.editor-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.updater-actions form {
    margin: 0;
}

.editor-toolbar {
    justify-content: space-between;
    margin-bottom: 16px;
}

/* ### Редактор Python с подсветкой */
.code-editor {
    position: relative;
    overflow: hidden;
    min-height: 420px;
    border: 1px solid var(--code-border);
    border-radius: 12px;
    background: var(--code-bg);
    isolation: isolate;
}

.code-editor textarea,
.code-highlight {
    box-sizing: border-box;
    margin: 0;
    padding: 16px;
    width: 100%;
    min-height: 420px;
    border: 0;
    font-family: Consolas, "Cascadia Code", "Fira Code", monospace;
    font-size: 13px;
    line-height: 1.55;
    tab-size: 4;
    white-space: pre;
    overflow: auto;
    letter-spacing: 0;
}

.code-editor textarea {
    position: relative;
    z-index: 2;
    display: block;
    resize: vertical;
    background: transparent;
    color: transparent;
    caret-color: var(--code-text);
    -webkit-text-fill-color: transparent;
    outline: none;
}

.code-editor textarea::selection {
    background: var(--accent-soft);
    -webkit-text-fill-color: transparent;
}

.code-highlight {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    color: var(--code-text);
}

.code-highlight code {
    display: block;
    min-height: 100%;
}

.code-highlight .tok-comment {
    color: var(--code-comment);
    font-style: italic;
}

.code-highlight .tok-string {
    color: var(--code-string);
}

.code-highlight .tok-keyword {
    color: var(--code-keyword);
}

.code-highlight .tok-number {
    color: var(--code-number);
}

.code-highlight .tok-function {
    color: var(--code-function);
}

.code-highlight .tok-constant {
    color: var(--code-constant);
}

.code-highlight .tok-operator {
    color: var(--code-operator);
}

.log-view {
    box-sizing: border-box;
    width: 100%;
    max-height: 70vh;
    min-height: 280px;
    overflow: auto;
    padding: 16px;
    border: 1px solid var(--log-border);
    border-radius: 12px;
    background: var(--log-bg);
    color: var(--log-text);
    font: 12px/1.55 Consolas, "Cascadia Code", monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (max-width: 640px) {
    .updater-actions .btn {
        width: 100%;
        box-sizing: border-box;
        text-align: center;
        justify-content: center;
    }

    .updater-actions form {
        width: 100%;
    }

    .updater-actions form .btn {
        width: 100%;
    }

    .code-editor textarea,
    .code-highlight {
        font-size: 12px;
        padding: 12px;
    }
}


/* ### Навигация авторизованных пользователей */
.user-navigation {
    position: fixed;
    top: 12px;
    left: 14px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: calc(100vw - 360px);
}

.user-navigation a {
    display: inline-block;
    padding: 7px 11px;
    border: 1px solid var(--nav-border);
    border-radius: 999px;
    background: var(--nav-bg);
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}

.user-navigation a:hover {
    background: var(--nav-hover);
}

/* ### Широкая рабочая область настроек */
body.authenticated .container:has(.settings-tabs) {
    width: calc(100% - 32px);
    max-width: 1800px;
    box-sizing: border-box;
}

body.authenticated .container:has(.settings-tabs) .admin-section {
    max-width: none;
}

body.authenticated .container:has(.settings-tabs) .table-wrap {
    width: 100%;
}

body.authenticated .container:has(.settings-tabs) table {
    min-width: 1100px;
}

@media (max-width: 800px) {
    .user-navigation {
        position: static;
        justify-content: center;
        max-width: 100%;
        padding: 10px 10px 0;
    }

    .account-actions {
        position: static;
        justify-content: center;
        margin: 8px 10px 0;
    }

    body.authenticated .container:has(.settings-tabs) {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .contact-card {
        flex: 1 1 42vw;
    }

    .user-navigation a {
        padding: 6px 9px;
        font-size: 13px;
    }

    .theme-option {
        width: 28px;
        height: 28px;
    }
}
