:root {
    --bg: #f7f7f7;
    --card-bg: #ffffff;
    --text: #1a1a1a;
    --muted: #666666;
    --border: #e0e0e0;
    --accent: #2f2f2f;
    --error: #b00020;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
                 Arial, "Noto Sans", sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

.container {
    margin: 0 auto;
    padding: 48px 24px;
}
.container-narrow { max-width: 720px; }
.container-wide   { max-width: 1400px; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px 28px;
}

.card h1 {
    margin: 0 0 16px 0;
    font-size: 1.4rem;
    font-weight: 600;
}

.muted { color: var(--muted); }

.error {
    color: var(--error);
    background: #fdecea;
    border: 1px solid #f5c2c7;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 0 0 16px 0;
}

form { margin-top: 16px; }

label {
    display: block;
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 4px;
}

input[type="email"] {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 16px;
    font-family: inherit;
}

input[type="email"]:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
}

button:hover { opacity: 0.9; }

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

/* Навигация сверху. Ширина подстраивается под контейнер страницы. */
.topnav {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 24px 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.topnav .brand {
    font-weight: 600;
    text-decoration: none;
}
.topnav .spacer { flex: 1; }
.topnav a { font-size: 0.95rem; }

/* Два явных класса ширины — см. .container-narrow / .container-wide выше. */

/* Textarea */
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    margin-bottom: 16px;
    resize: vertical;
    background: #fff;
    color: var(--text);
}
textarea:focus { outline: none; border-color: var(--accent); }
textarea[disabled] { background: #f2f2f2; color: #aaa; }

/* Переключатель типа сценария */
fieldset.type-picker {
    border: none;
    padding: 0;
    margin: 0 0 16px 0;
}
fieldset.type-picker legend {
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 6px;
}
.radio {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 0.95rem;
    cursor: pointer;
}
.radio input { accent-color: var(--accent); }

/* Сценарий */
.topic-title {
    font-size: 1.25rem;
    line-height: 1.3;
    margin-bottom: 4px;
}
.script-blocks .block {
    border-left: 3px solid var(--border);
    padding: 8px 14px;
    margin: 16px 0;
}
.script-blocks h3 {
    margin: 0 0 6px 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
}
.script-blocks h3 .tc {
    font-weight: 400;
    font-size: 0.85rem;
    margin-left: 8px;
}
.script-blocks p { margin: 0; }

.actions { margin: 20px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.actions.secondary { margin-top: 24px; }
.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 1rem;
    text-decoration: none;
}
.btn:hover { opacity: 0.9; }
.copy-btn.small {
    background: #fff;
    color: var(--accent);
    border: 1px solid var(--border);
    padding: 4px 10px;
    font-size: 0.85rem;
    border-radius: 6px;
    cursor: pointer;
}
.copy-btn.copied { background: #e6f4ea; border-color: #b7e0c3; color: #1e6e34; }

.hidden-copy {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}

/* Публикационный набор */
details.publishing-set {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    margin: 20px 0;
}
details.publishing-set summary {
    cursor: pointer;
    font-weight: 500;
}
.pub-block { margin-top: 12px; }
.pub-block h4 { margin: 0 0 6px 0; font-size: 0.95rem; }
.pub-row {
    display: grid;
    grid-template-columns: 90px 1fr auto;
    gap: 8px 12px;
    align-items: start;
    margin-bottom: 8px;
    font-size: 0.95rem;
}
.pub-label { color: var(--muted); font-size: 0.85rem; padding-top: 5px; }
.pub-value { word-break: break-word; }

/* Окно правок (disabled в Phase 1) */
.edits { margin-top: 24px; }
.edits h3 { font-size: 0.95rem; font-weight: 500; margin-bottom: 6px; }

/* История */
.history-group { margin-bottom: 20px; }
.history-group h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 8px;
}
.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.history-list li {
    border-bottom: 1px solid var(--border);
}
.history-list li:last-child { border-bottom: none; }
.history-list a {
    display: block;
    padding: 10px 0;
    text-decoration: none;
    color: var(--text);
}
.history-list a:hover { background: #fafafa; }
.history-topic { display: block; font-size: 0.95rem; }
.history-meta { display: block; font-size: 0.8rem; margin-top: 2px; }

/* Админка и воронки — ширина через класс .container-wide на <main>. */

.admin-block {
    margin: 28px 0;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}
.admin-block:first-of-type { border-top: none; padding-top: 0; }
.admin-block h2 {
    font-size: 1.05rem;
    margin: 0 0 12px 0;
}
.admin-block h3 {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--muted);
    margin: 16px 0 8px 0;
}

.filter-bar { margin: 0 0 10px 0; font-size: 0.9rem; }
.filter-bar a.active { color: var(--text); font-weight: 600; text-decoration: none; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.admin-table th, .admin-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}
.admin-table th {
    font-weight: 500;
    color: var(--muted);
    background: #fafafa;
}
.admin-table td.nowrap, .admin-table th.nowrap { white-space: nowrap; }
.admin-table tr:hover td { background: #fafafa; }

/* Glossary-таблица: фиксированный layout + per-column ширины через <colgroup>.
   Длинные слова ломаются корректно, определение получает основную ширину. */
.glossary-table {
    table-layout: fixed;
}
.glossary-table th, .glossary-table td {
    word-wrap: break-word;
    overflow-wrap: break-word;
    vertical-align: top;
}

/* Горизонтальный скролл на узких экранах. */
.table-scroll {
    overflow-x: auto;
    margin: 0 -4px;
}

.kv-list { list-style: none; padding: 0; margin: 0 0 12px 0; }
.kv-list li { padding: 4px 0; font-size: 0.95rem; }

.metrics-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}
@media (max-width: 640px) {
    .metrics-columns { grid-template-columns: 1fr; }
}

.funnel-summary .funnel-row { padding: 2px 0; font-size: 0.95rem; }

/* Воронки — карточки */
.funnel-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin: 12px 0 24px;
}
@media (min-width: 720px) {
    .funnel-grid { grid-template-columns: 1fr 1fr; }
}

.funnel-card {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
    background: #fff;
}
.funnel-card h3 { margin: 0 0 2px 0; font-size: 1.02rem; }
.funnel-card-active {
    border: 2px solid #d18c3a;
    padding: 15px 17px;
}
.funnel-card .badge {
    position: absolute;
    top: 10px;
    right: 12px;
    background: #d18c3a;
    color: #fff;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    padding: 2px 6px;
    border-radius: 4px;
}
.funnel-card .small { font-size: 0.82rem; }
.funnel-dl { margin: 8px 0 12px 0; }
.funnel-dl dt { font-size: 0.78rem; color: var(--muted); margin-top: 6px; }
.funnel-dl dd { margin: 0; font-size: 0.92rem; }

.funnel-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.funnel-actions form.inline { display: inline; margin: 0; }
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 6px 10px;
    font-size: 0.85rem;
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    display: inline-block;
}
.btn-ghost:hover { background: #fafafa; }
.btn-ghost.danger { color: #b00020; border-color: #f5c2c7; }

.archive-block {
    margin-top: 24px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
}
.archive-block summary { cursor: pointer; font-weight: 500; }
.archive-list { list-style: none; padding: 0; margin: 10px 0 0 0; }
.archive-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}
.archive-list li:last-child { border-bottom: none; }

/* Форма воронки */
.funnel-form .form-row { margin-bottom: 16px; }
.funnel-form label,
.funnel-form .label-text {
    display: block;
    font-size: 0.9rem;
    color: var(--text);
    margin-bottom: 4px;
    font-weight: 500;
}
.funnel-form input[type="text"], .funnel-form textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
}
.funnel-form input.invalid, .funnel-form textarea.invalid {
    border-color: #b00020;
}
.funnel-form .helper {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 4px;
}
.funnel-form .error {
    font-size: 0.85rem;
    color: #b00020;
    margin-top: 4px;
}
.funnel-form .radio { font-weight: normal; margin-right: 12px; }
.funnel-form .checkbox {
    display: inline-flex;
    gap: 6px;
    font-weight: normal;
    align-items: center;
}

.success {
    color: #1e6e34;
    background: #e6f4ea;
    border: 1px solid #b7e0c3;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 0 0 16px 0;
}

/* Source status badges */
.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    background: #f0f0f0;
    color: #555;
}
.status-badge.status-pending { background: #f0f0f0; color: #555; }
.status-badge.status-uploading,
.status-badge.status-stage1_processing,
.status-badge.status-stage2_processing,
.status-badge.status-rebuilding { background: #fff3cd; color: #856404; }
.status-badge.status-awaiting_review { background: #d1ecf1; color: #0c5460; }
.status-badge.status-ready { background: #d4edda; color: #155724; }
.status-badge.status-error { background: #f8d7da; color: #721c24; }
.status-badge.status-processing,
.status-badge.status-ready_for_processing { background: #d1ecf1; color: #0c5460; }
.status-badge.status-processed { background: #d4edda; color: #155724; }

/* Glossary term per-row approval badges */
.status-badge.glossary-status-pending { background: #fff3cd; color: #856404; }
.status-badge.glossary-status-approved { background: #d4edda; color: #155724; }
.status-badge.glossary-status-rejected { background: #f8d7da; color: #721c24; }

/* Inline edit/regenerate forms inside glossary table */
.term-edit-form, .term-regen-form { display: flex; flex-direction: column; gap: 8px; }
.term-edit-form label, .term-regen-form label { display: flex; flex-direction: column; gap: 4px; }
.term-edit-form input, .term-edit-form textarea, .term-edit-form select,
.term-regen-form textarea { width: 100%; }
.form-actions { display: flex; gap: 8px; }

/* Off-course / fact-check indicators in tables */
.oc-yes, .fc-fail { color: #b85300; font-weight: 600; }
.fc-ok { color: #1e6e34; }
.fc-retry { color: #856404; }

.methodology-block {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.92rem;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin: 8px 0 16px;
}

/* ASCII-гистограмма для retrieval stats. Моноширинный шрифт — для ровных бар'ов. */
.histogram {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin: 8px 0 16px;
    white-space: pre;
    overflow-x: auto;
}

.review-actions {
    margin-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.reject-form-wrapper summary {
    cursor: pointer;
    display: inline-block;
}
.reject-form {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.reject-form .checkboxes-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 10px 0;
}
.reject-form textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
}

/* Warning banner (off-course on script page) */
.banner-warning {
    background: #fff3cd;
    border: 1px solid #ffe69c;
    color: #806000;
    padding: 10px 14px;
    border-radius: 8px;
    margin: 0 0 16px 0;
    font-size: 0.92rem;
}

/* ---- Generation form: indicator + disabled button ---- */
/* !important нужен чтобы перебить базовое правило `button { background: var(--accent) }`
   на той же специфичности — иначе пользователь видит «активную» яркую кнопку. */
button:disabled,
button[disabled] {
    background-color: #d1d5db !important; /* gray-300 */
    color: #6b7280 !important;            /* gray-500 */
    cursor: not-allowed !important;
    opacity: 0.7 !important;
}
button:disabled:hover,
button[disabled]:hover {
    background-color: #d1d5db !important;
    opacity: 0.7 !important;
    transform: none !important;
}

.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 0.95rem;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

.generation-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: stsen-pulse 1.2s ease-in-out infinite;
}

@keyframes stsen-pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50%      { opacity: 1.0; transform: scale(1.0); }
}

/* Phase 2B step 2A hotfix: индикатор фоновой batch-обработки консультаций. */
.spinner-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: stsen-pulse 1.2s ease-in-out infinite;
    margin-right: 8px;
    vertical-align: middle;
}
.processing-running {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
    border-radius: 8px;
    padding: 12px 14px;
    margin: 8px 0 12px 0;
    font-size: 0.95rem;
}

/* Phase 2B step 2Б: speaker badges + per-row left border in consultation
   detail. Контрастный акцент для эксперта и нейтральный серый для клиента —
   глаз сразу видит чьи реплики. */
.speaker-expert {
    background: var(--accent);
    color: #fff;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
}
.speaker-client {
    background: #e5e7eb;
    color: #4b5563;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    display: inline-block;
}
/* Левая цветная полоса у строки реплики — быстрый сканер по списку. */
.consultation-turns tr.turn-expert {
    border-left: 4px solid var(--accent);
}
.consultation-turns tr.turn-client {
    border-left: 4px solid #d1d5db;
}
.consultation-turns tr.turn-expert td:first-child,
.consultation-turns tr.turn-client td:first-child {
    padding-left: 12px;
}
.consultation-turns td.turn-text { white-space: pre-wrap; word-wrap: break-word; }
.card-error {
    background: #fdecea;
    border: 1px solid #f5c2c7;
    border-radius: 8px;
    padding: 12px 14px;
    margin: 12px 0;
}

/* Phase 2B step 3: разделитель между блоками управления и индексацией голоса. */
hr.muted-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0 12px;
}

/* Phase 2C step 1: бейджи типов секций атласа аудитории. */
.status-badge.atlas-section-category { background: #d4edda; color: #155724; }
.status-badge.atlas-section-trigger { background: #d1ecf1; color: #0c5460; }
.status-badge.atlas-section-pain { background: #f8d7da; color: #721c24; }
.status-badge.atlas-section-objection { background: #fff3cd; color: #856404; }
.status-badge.atlas-section-anti_audience { background: #e5e7eb; color: #4b5563; }
.status-badge.atlas-section-language_pattern { background: #ede9fe; color: #5b21b6; }
.status-badge.atlas-section-intro { background: #e0e7ff; color: #1e3a8a; }
.status-badge.atlas-section-summary { background: #fde68a; color: #78350f; }
.status-badge.atlas-section-other { background: #f0f0f0; color: #555; }

.atlas-section-content {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.95rem;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    margin: 8px 0 16px;
}
