@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&display=swap");

:root {
    --bg: #070b14;
    --surface: #1d2430;
    --accent: #9a9dff;
    --success: #5fb88a;
    --danger: #d97b7b;
    --warning: #e6c34a;
    --text: #e6e9f0;
    --text-muted: #9aa3b5;
    --font-heading: "IBM Plex Mono", monospace;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    display: flex;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
}

.page {
    flex: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 48px 24px;
}

.server-time {
    color: var(--text-muted);
}

/* Навигация — левый сайдбар */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 24px 16px;
    background: var(--surface);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar a {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    padding: 10px 12px;
    border-radius: 6px;
}

.sidebar a:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.nav-brand {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text) !important;
    margin-bottom: 16px;
    padding: 10px 12px;
}

.nav-active,
.nav-active:hover {
    background: var(--accent);
    color: var(--bg) !important;
}

.sidebar a.nav-sublink {
    padding-left: 28px;
    font-size: 13px;
}

.nav-details {
    display: flex;
    flex-direction: column;
}

.nav-details summary {
    cursor: pointer;
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 14px;
    border-radius: 6px;
}

.nav-details summary:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

/* Тултип при наведении на пункт сайдбара - что раздел делает / какой
   команде-кнопке бота соответствует. Чистый CSS (:hover + ::after), без JS.
   Раскрывается вправо от сайдбара, в область основного контента, где есть
   место (сам сайдбар всего 240px). */
.sidebar a[data-tooltip] {
    position: relative;
}

.sidebar a[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(-4px);
    width: max-content;
    max-width: 280px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    padding: 8px 12px;
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 1.4;
    white-space: normal;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease 0.2s, visibility 0.15s ease 0.2s, transform 0.15s ease 0.2s;
    z-index: 100;
}

.sidebar a[data-tooltip]:hover::after,
.sidebar a[data-tooltip]:focus-visible::after {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
}

/* Формы */
.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 640px;
}

/* Модификатор для форм с более чем двумя колонками в .field-row (например
   кнопка меню: текст + ссылка + чекбокс видимости) - в 640px три колонки
   слишком тесные. */
.form-wide {
    max-width: 860px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.field-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

/* Колонка чекбокса в .field-row - фиксированная ширина, не сжимается и не
   растягивается вместе с соседними текстовыми полями (иначе чекбокс с
   подписью переносится некрасиво на узкий столбец). */
.field-fixed {
    flex: none;
    width: 150px;
}

.field-fixed .field-checkbox-inline {
    margin-left: 0;
    margin-top: 8px;
}

/* Тело секции "Свои кнопки" (список + пустое состояние + форма добавления/
   подтверждение удаления) - единый вертикальный ритм между всеми элементами,
   иначе плейсхолдер "кнопок пока нет" склеивается с полями формы добавления. */
.custom-buttons-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.custom-buttons-actions {
    display: flex;
    gap: 10px;
}

.field-row-inline {
    align-items: center;
}

.field-row-inline input[type="number"] {
    width: 100px;
    flex: none;
}

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

.field-checkbox-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-direction: row;
    white-space: nowrap;
    margin-left: 8px;
}

label {
    font-size: 13px;
    color: var(--text-muted);
}

.field-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

/* Секции формы настроек — карточка-обёртка по образцу .candidate-card,
   паттерн взят с wildbuyers.club (.spec), на наших токенах. */
.form-section {
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 16px;
    background: var(--surface);
}

.form-section:last-of-type {
    margin-bottom: 0;
}

.form-section h3 {
    font-size: 16px;
    margin: 0 0 14px;
}

.form-section > .field + .field,
.form-section > .field-row + .field,
.form-section > .field + .field-row,
.form-section > .field-row + .field-row {
    margin-top: 16px;
}

.badge-pill {
    display: inline-block;
    font-family: var(--font-heading);
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 2px 8px;
    color: var(--accent);
    font-weight: 600;
    margin-left: 8px;
    vertical-align: middle;
}

.badge-pill-large {
    font-size: 18px;
    padding: 4px 14px;
    margin-left: 10px;
}

.stat-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 12px;
}

.stat-row:last-child {
    margin-bottom: 0;
}

.stat-item {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* Сетка сводных карточек статистики (/admin/stats) - отдельные классы, не
   .stat-row/.stat-item (те завязаны на inline-бейдж переменной ширины и
   используются на других страницах - publisher_history/categories/
   publisher_settings - трогать их нельзя). Все карточки одного размера,
   выровнены в CSS grid, а не флекс-ряд с переносом. */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.stat-grid + .stat-grid {
    margin-top: 12px;
}

.stat-tile {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-height: 104px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 16px;
    background: var(--bg);
}

.stat-tile-value {
    font-family: var(--font-heading);
    font-size: 26px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
}

.stat-tile-accent .stat-tile-value {
    color: var(--accent);
}

.stat-tile-label {
    font-size: 12px;
    color: var(--text-muted);
}

input[type="text"],
input[type="number"],
input[type="url"],
select {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    color: var(--text);
    padding: 8px 10px;
    font-size: 14px;
    font-family: var(--font-body);
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
}

input[type="text"]:disabled,
input[type="url"]:disabled,
textarea:disabled {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    cursor: not-allowed;
}

/* Кнопки */
.btn {
    display: inline-block;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-family: var(--font-heading);
    font-weight: 600;
    cursor: pointer;
    width: fit-content;
}

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

.btn-primary:hover {
    opacity: 0.9;
}

.btn-neutral {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text);
}

.btn-neutral:hover {
    border-color: var(--accent);
}

.btn-danger {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(217, 123, 123, 0.15);
}

.btn-small {
    padding: 6px 14px;
    font-size: 12px;
}

.button-preview {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 8px 0 16px;
}

.button-preview-chip {
    display: inline-block;
    width: fit-content;
    padding: 6px 14px;
    border-radius: 6px;
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text);
    font-size: 13px;
}

.rotation-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* Уведомления */
.alert {
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 14px;
}

.alert ul {
    margin: 0;
    padding-left: 20px;
}

.alert-success {
    background: rgba(95, 184, 138, 0.15);
    border: 1px solid var(--success);
    color: var(--success);
}

.alert-danger {
    background: rgba(217, 123, 123, 0.15);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* Категории */
.rotation-summary {
    margin-bottom: 20px;
    color: var(--text-muted);
    max-width: 640px;
}

.rotation-summary strong {
    color: var(--text);
}

.categories-table {
    width: 100%;
    max-width: 640px;
    border-collapse: collapse;
}

.categories-table th,
.categories-table td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 14px;
}

.categories-table th {
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 12px;
}

.categories-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.06);
}

.history-table {
    width: 100%;
    max-width: 640px;
    border-collapse: collapse;
}

.history-table th,
.history-table td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 14px;
}

.history-table th {
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 12px;
}

.history-table a {
    color: var(--accent);
}

.history-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.06);
}

.toggle-btn {
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-family: var(--font-heading);
    font-weight: 600;
    cursor: pointer;
}

.toggle-on {
    background: rgba(95, 184, 138, 0.15);
    border: 1px solid var(--success);
    color: var(--success);
}

.toggle-off {
    background: rgba(217, 123, 123, 0.15);
    border: 1px solid var(--danger);
    color: var(--danger);
}

/* Промпт-редактор */
textarea {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    color: var(--text);
    padding: 8px 10px;
    font-size: 14px;
    font-family: var(--font-body);
    resize: vertical;
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.field label code {
    background: var(--surface);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--font-heading);
}

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.tab {
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 14px;
}

.tab:hover {
    color: var(--text);
    border-color: var(--accent);
}

.tab-active,
.tab-active:hover {
    color: var(--bg);
    background: var(--accent);
    border-color: var(--accent);
}

/* /publish — категории и кандидаты */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.category-grid .btn {
    width: 100%;
}

.candidate-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 640px;
    margin: 16px 0;
}

.candidate-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 16px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.candidate-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.candidate-info {
    flex: 1;
    min-width: 0; /* обязательно для работы ellipsis внутри flex-контейнера */
}

.candidate-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

/* Экран выбора картинки товара (/publish, только веб) */
.image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    max-width: 640px;
    margin: 16px 0;
}

.image-thumb-btn {
    padding: 4px;
    border-radius: 8px;
    border: 2px solid transparent;
    background: var(--surface);
    cursor: pointer;
}

.image-thumb-btn:hover {
    border-color: var(--accent);
}

.image-thumb-current {
    border-color: var(--accent);
}

.image-thumb {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.candidate-title a {
    color: var(--text);
    font-weight: 600;
}

.candidate-title-list {
    font-size: 16px;
    margin-top: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.candidate-title-list a {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
}

.candidate-meta {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 6px;
    line-height: 1.6;
}

.ai-score-badge {
    font-family: var(--font-heading);
    font-size: 12px;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 2px 8px;
    color: var(--accent);
    font-weight: 600;
}

/* HTMX loading indicator — стандартный паттерн htmx.org/attributes/hx-indicator */
.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}

.search-indicator {
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 14px;
}

.search-dot {
    animation: search-dot-pulse 1.4s infinite;
    animation-fill-mode: both;
}

.search-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.search-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes search-dot-pulse {
    0%, 80%, 100% {
        opacity: 0.2;
    }
    40% {
        opacity: 1;
    }
}

.publish-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.preview-image {
    max-width: 320px;
    width: 100%;
    border-radius: 8px;
    display: block;
    margin-bottom: 12px;
}

.preview-card {
    max-width: 640px;
}

.preview-meta {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 12px;
}

.preview-text {
    white-space: pre-wrap;
    margin-bottom: 12px;
    line-height: 1.5;
}

/* Разделитель между двумя независимыми блоками на одной странице (например
   встроенные кнопки меню vs произвольные кнопки на /admin/menu-buttons) -
   чтобы визуально не читались как одна форма/секция. */
.page-section-divider {
    margin: 40px 0 24px;
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.page-section-intro {
    color: var(--text-muted);
    margin: -8px 0 16px;
}

/* Вводная строка сразу под <h1> страницы (не после divider, поэтому без
   отрицательного margin-top, в отличие от .page-section-intro). */
.page-intro {
    color: var(--text-muted);
    margin: 0 0 24px;
}
