/*
  Стили админ-панели oChat.

  Раскладка, размеры и компоненты повторяют панель Транскрибатора
  (transcribe_stats.loonix.dev/styles.css) намеренно: две панели открывают
  в соседних вкладках, и одинаковая геометрия означает, что рука тянется
  к кнопке без чтения. Расходиться им незачем.

  Отличается только шапка. Синий #42B5F0 → #3BA9DD — фирменный цвет oChat
  (иконка приложения, заставка); у него ровно одна роль — сказать «это oChat».
  Здесь она уместна: спутать две открытые панели дороже, чем лишний градиент.
  Акцент интерфейса (кнопки, ссылки) остаётся системным синим — как в приложении,
  где фирменный цвет тоже НЕ является акцентом.
*/

:root {
    --accent: #007aff;
    --accent-pressed: #0051c7;
    --danger: #ff3b30;
    --danger-pressed: #d60d06;
    --success: #1a7f37;
    --warning: #ff9500;
    --ink: #333;
    --ink-secondary: #636366;
    --ink-tertiary: #8e8e93;
    --canvas: #f4f4f9;
    --surface: #ffffff;
    --divider: #e5e5ea;
    --brand-top: #42B5F0;
    --brand-bottom: #3BA9DD;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--canvas);
    color: var(--ink);
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 20px auto;
    padding: 0 20px;
}

/* ===== Шапка ===== */

header {
    background: linear-gradient(180deg, var(--brand-top) 0%, var(--brand-bottom) 100%);
    color: white;
    padding: 12px 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header .container {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

header h1 {
    color: white;
    font-size: 1.3em;
    margin: 0;
    flex-shrink: 0;
}

header nav {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

nav a {
    color: white;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 13px;
    opacity: 0.85;
    background: rgba(255, 255, 255, 0.12);
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
}

nav a:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.24);
    text-decoration: none;
}

nav a.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.32);
}

h1, h2 {
    margin-top: 25px;
    color: var(--ink);
}

h2 {
    font-size: 1.25em;
}

/* Переключатель окружения. Оранжевый на staging — чтобы «я думал, это тест»
   было видно раньше, чем палец дойдёт до кнопки удаления. */
.env-switcher {
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    padding: 2px;
    flex-shrink: 0;
}

.env-switcher button {
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    transition: all 0.15s;
}

.env-switcher button:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.env-switcher button.active {
    background: rgba(255, 255, 255, 0.28);
    color: white;
    cursor: default;
}

.env-switcher button.env-staging.active {
    background: var(--warning);
    color: white;
}

/* ===== Кнопки ===== */

button, .btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    font-family: inherit;
}

button:hover, .btn:hover {
    background-color: var(--accent-pressed);
}

button:disabled {
    background-color: #ccc;
    cursor: default;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

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

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

.btn-secondary {
    background-color: var(--ink-tertiary);
}

.btn-secondary:hover {
    background-color: #6e6e73;
}

.btn-success {
    background-color: #28a745;
}

.btn-success:hover {
    background-color: #218838;
}

.logout-btn {
    background-color: var(--danger);
}

.logout-btn:hover {
    background-color: var(--danger-pressed);
}

/* Кнопки фоновых задач: отдельный цвет, потому что это не «сохранить»,
   а «сделать что-то на сервере прямо сейчас». */
.trigger-btn {
    background-color: #5856d6;
    font-size: 13px;
}

.trigger-btn:hover {
    background-color: #4745ac;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--divider);
    background: white;
    color: var(--ink);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 15px;
    transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
    background: #f2f2f7;
    border-color: #d1d1d6;
}

.icon-btn.danger:hover {
    background: #ffeded;
    border-color: var(--danger);
    color: var(--danger);
}

/* ===== Вход ===== */

.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    text-align: center;
    width: 360px;
}

.login-box h2 {
    margin-top: 0;
}

.login-box .login-hint {
    color: var(--ink-tertiary);
    font-size: 0.85em;
    margin-top: 18px;
    line-height: 1.5;
}

/* Выбор окружения на экране входа: до входа шапки ещё нет,
   а ключи у prod и staging разные. */
.login-env {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 14px;
}

.login-env button {
    background: #f2f2f7;
    color: var(--ink-secondary);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 14px;
}

.login-env button:hover {
    background: var(--divider);
}

.login-env button.active {
    background: var(--accent);
    color: white;
}

.login-env button.env-staging.active {
    background: var(--warning);
    color: white;
}

/* ===== Поля ввода ===== */

input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
select,
textarea {
    padding: 10px;
    margin: 5px 0;
    border-radius: 5px;
    border: 1px solid #ccc;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 14px;
    background-color: #fff;
    color: var(--ink);
}

textarea {
    resize: vertical;
}

.full-width {
    width: 100%;
}

.search-input {
    width: 320px;
    max-width: 100%;
}

/* ===== Сводка ===== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.stat-card p {
    margin: 6px 0 0;
    color: var(--ink-secondary);
    font-size: 0.9em;
}

.stat-value {
    font-size: 2em;
    font-weight: bold;
    color: var(--accent);
    line-height: 1.2;
}

.stat-value.stat-warn {
    color: var(--danger);
}

/* Значение, которое не число, а строка (например версия сборки):
   тем же кеглем оно переносится и ломает карточку. */
.stat-value.stat-text {
    font-size: 1.1em;
    word-break: break-all;
}

/* ===== Секции и таблицы ===== */

.data-section {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    margin-bottom: 30px;
}

.data-section > h2:first-child {
    margin-top: 0;
}

.section-hint {
    color: var(--ink-secondary);
    font-size: 0.9em;
    margin-top: 0;
}

.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

th, td {
    padding: 12px 15px;
    border: 1px solid #ddd;
    text-align: left;
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
}

th {
    background-color: #f8f8f8;
    font-weight: 600;
}

tbody tr:hover {
    background-color: #f1f1f1;
}

tr.row-clickable {
    cursor: pointer;
}

/* Таблица «ключ — значение» на карточке человека. */
table.details-table th {
    width: 30%;
    text-align: right;
    padding-right: 20px;
    white-space: normal;
}

table.details-table td {
    white-space: normal;
    max-width: none;
    word-break: break-word;
}

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

a:hover {
    text-decoration: underline;
}

/* ===== Постраничность ===== */

/* Постраничность курсорная, а не по offset: договор отдаёт `nextCursor`.
   Поэтому «Назад» — это стопка пройденных курсоров, а не номер страницы. */
.pagination {
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.pagination button {
    margin: 0;
}

.pagination .page-label {
    color: var(--ink-secondary);
    font-size: 0.9em;
}

/* ===== Состояния: загрузка, пусто, ошибка ===== */

.loader {
    text-align: center;
    padding: 24px;
    font-style: italic;
    color: var(--ink-tertiary);
}

/* Пустое состояние и ошибка сети — то, что увидят первым: бэкенда ещё нет.
   Поэтому у обоих есть заголовок и внятное объяснение, а не одна строка «нет данных». */
.state-box {
    text-align: center;
    padding: 32px 20px;
    border-radius: 10px;
    border: 1px dashed var(--divider);
    color: var(--ink-secondary);
    margin-top: 15px;
}

.state-box .state-icon {
    font-size: 28px;
    line-height: 1;
    margin-bottom: 10px;
}

.state-box .state-title {
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}

.state-box .state-text {
    font-size: 0.9em;
    max-width: 560px;
    margin: 0 auto;
}

.state-box .state-text code {
    background: #f2f2f7;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.92em;
    word-break: break-all;
}

.state-box.state-error {
    border-style: solid;
    border-color: #ffd0cd;
    background-color: #fff6f5;
}

.state-box.state-error .state-title {
    color: var(--danger);
}

.state-box button {
    margin-top: 14px;
}

.error-message {
    color: var(--danger);
    background-color: #ffecec;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
}

.success-message {
    color: var(--success);
    background-color: #e8f5e9;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
}

.controls {
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.controls .spacer {
    margin-left: auto;
}

.muted {
    color: var(--ink-tertiary);
    font-size: 0.85em;
}

.hidden {
    display: none !important;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
    font-size: 0.92em;
}

/* ===== Карточки списка (фича-тоггли) ===== */

.item-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 15px;
}

.item-card {
    background: white;
    border: 1px solid var(--divider);
    border-radius: 10px;
    padding: 18px 20px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: start;
}

.item-card.inactive {
    opacity: 0.55;
}

.item-card-body {
    min-width: 0;
}

.item-card-title {
    font-size: 1.05em;
    font-weight: 600;
    margin: 0 0 6px 0;
    color: #1c1c1e;
}

.item-card-description {
    color: #3c3c43;
    font-size: 0.92em;
    line-height: 1.5;
    margin: 0 0 10px 0;
    white-space: pre-wrap;
}

.item-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.78em;
    color: var(--ink-secondary);
}

.item-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* ===== Плашки ===== */

.tag {
    display: inline-block;
    background: #f2f2f7;
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
    font-size: 0.78em;
    color: var(--ink-secondary);
}

.tag-active {
    background: #e4f7ed;
    color: #1b7f3b;
}

.tag-inactive {
    background: #ffeded;
    color: #b42318;
}

.tag-premium {
    background: #fff4e0;
    color: #9a5b00;
}

.tag-blocked {
    background: #ffeded;
    color: #b42318;
}

.tag-platform-apple {
    background: #eef0f3;
    color: #1d1d1f;
}

.tag-platform-android {
    background: #e6f4ea;
    color: #137333;
}

.tag-platform-all {
    background: #e8f0fe;
    color: #1a73e8;
}

/* ===== Формы ===== */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 15px;
}

.form-grid .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-grid .field.full-row {
    grid-column: 1 / -1;
}

.form-grid label {
    font-size: 0.85em;
    font-weight: 500;
    color: #3c3c43;
}

.form-grid input[type="text"],
.form-grid textarea,
.form-grid select {
    width: 100%;
    margin: 0;
    padding: 9px 12px;
    border-radius: 6px;
    border: 1px solid #d1d1d6;
}

.form-grid textarea {
    min-height: 90px;
}

.form-grid .checkbox-field {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.form-grid .checkbox-field label {
    margin: 0;
    cursor: pointer;
}

.form-grid .hint {
    font-size: 0.75em;
    color: var(--ink-tertiary);
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
}

/* ===== Карточка человека ===== */

.user-headline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.user-headline .user-name {
    font-size: 1.4em;
    font-weight: 600;
    margin: 0;
}

.user-headline .user-id {
    color: var(--ink-tertiary);
    font-size: 0.85em;
}

.danger-zone {
    border: 1px solid #ffd0cd;
    background-color: #fff6f5;
}

.danger-zone h2 {
    color: var(--danger);
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 12px;
}

/* ===== Подтверждение опасных действий ===== */

/* Диалог, а не window.confirm(): в системном окне нельзя показать, КОГО
   затрагивает действие — имя и идентификатор он обрежет или склеит в одну
   строку, а перепутанный человек здесь стоит удалённого аккаунта. */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    width: 480px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    box-sizing: border-box;
}

.modal h3 {
    margin: 0 0 12px;
    font-size: 1.15em;
}

.modal .modal-text {
    font-size: 0.95em;
    color: #3c3c43;
    margin: 0 0 16px;
}

/* Кого именно затрагивает действие. Отдельная плашка, а не строка в тексте:
   её читают, даже когда текст пролистывают. */
.modal .modal-subject {
    background: #f8f8fa;
    border: 1px solid var(--divider);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.modal .modal-subject-name {
    font-weight: 600;
    font-size: 1.02em;
    word-break: break-word;
}

.modal .modal-subject-id {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
    font-size: 0.82em;
    color: var(--ink-secondary);
    word-break: break-all;
    margin-top: 4px;
}

.modal .modal-warning {
    background: #fff6f5;
    border: 1px solid #ffd0cd;
    color: #b42318;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 0.9em;
    margin-bottom: 16px;
}

.modal label {
    display: block;
    font-size: 0.85em;
    font-weight: 500;
    color: #3c3c43;
    margin-bottom: 6px;
}

.modal input[type="text"] {
    width: 100%;
    margin: 0 0 16px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

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

    .search-input {
        width: 100%;
    }
}
