* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: #f4f5f7;
    color: #1f2328;
    line-height: 1.5;
}

header.topbar {
    background: #1f2937;
    color: #fff;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 4px 20px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
}

header.topbar a {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 18px;
}

header.topbar a.nav-link {
    font-weight: 400;
    font-size: 14px;
    opacity: 0.85;
}

header.topbar a.nav-link:hover {
    opacity: 1;
    text-decoration: underline;
}

.topbar-balance {
    margin-left: auto;
    color: #d1d5db;
    font-size: 14px;
    padding: 0 8px;
}

.topbar-user {
    color: #d1d5db;
    font-size: 14px;
}

.topbar-logout-form {
    display: inline-block;
}

.impersonate-banner {
    background: #fff3d6;
    border-bottom: 3px solid #f0b429;
    color: #6b4a00;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    text-align: center;
}

.impersonate-banner form {
    display: inline-block;
    margin: 0;
}

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

h1 {
    font-size: 24px;
    margin: 0 0 16px;
}

h2 {
    font-size: 18px;
    margin: 28px 0 12px;
    border-bottom: 1px solid #dde1e6;
    padding-bottom: 6px;
}

.card {
    background: #fff;
    border: 1px solid #dde1e6;
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 12px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.project-card h3 {
    margin: 0 0 8px;
    font-size: 16px;
}

.project-card h3 a {
    color: #1f5fbf;
    text-decoration: none;
}

.project-card h3 a:hover {
    text-decoration: underline;
}

.project-card .meta {
    font-size: 13px;
    color: #57606a;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #dde1e6;
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid #e7e9ec;
    font-size: 14px;
    vertical-align: top;
}

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

tr:last-child td {
    border-bottom: none;
}

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #e7ecf3;
    color: #33465c;
}

.badge.status-done, .badge.status-ok {
    background: #dcf5e3;
    color: #1a7a37;
}

.badge.status-error {
    background: #fbdcdc;
    color: #a4222a;
}

.badge.status-pending, .badge.status-none {
    background: #eee;
    color: #666;
}

.btn {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 6px;
    background: #1f5fbf;
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    border: none;
    cursor: pointer;
}

.btn:hover {
    background: #174a96;
}

.empty {
    color: #7c8695;
    font-style: italic;
    padding: 12px 0;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.metric {
    background: #fff;
    border: 1px solid #dde1e6;
    border-radius: 8px;
    padding: 12px 14px;
    text-align: center;
}

.metric .value {
    font-size: 20px;
    font-weight: 700;
}

.metric .label {
    font-size: 12px;
    color: #57606a;
    margin-top: 2px;
}

.badge.status-draft { background:#eef0f2; color:#5a6472; }
.badge.status-in_progress { background:#fff3d6; color:#8a6100; }
.badge.status-archived { background:#e4e7eb; color:#6b7280; }

.actions { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.action-form select { padding: 5px 8px; border: 1px solid #cfd4da; border-radius: 6px; font-size: 13px; width: 100%; background: #fff; }
.action-rename summary { cursor: pointer; font-size: 13px; color: #1f5fbf; user-select: none; }
.action-rename form { margin-top: 8px; display: flex; gap: 6px; }
.action-rename input[type="text"] { flex: 1; padding: 5px 8px; border: 1px solid #cfd4da; border-radius: 6px; font-size: 13px; }

.btn-secondary { background:#eef1f5; color:#2b3440; }
.btn-secondary:hover { background:#e0e5eb; }

.btn-success { background:#4f9e5a; color:#fff; }
.btn-success:hover { background:#438c4e; }
.btn-success:active { background:#387a42; }

.btn-light-blue { background:#dbeeff; color:#0b4a8f; border:1px solid #a9d2f5; }
.btn-light-blue:hover { background:#c7e4ff; }
.btn-light-blue:active { background:#b3daff; }
.btn-icon {
    padding: 6px 8px;
    line-height: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon.is-copied { color: #1a7f37; border-color: #1a7f37; }
.clone-actions { display:flex; flex-direction:column; gap:6px; }
.clone-actions .btn { width:100%; text-align:center; font-size:13px; padding:6px 10px; }

.btn-danger { background:#c53434; color:#fff; }
.btn-danger:hover { background:#a82a2a; }
.btn-danger-light { background:#fbecec; color:#a4222a; }
.btn-danger-light:hover { background:#f5dada; }
.trash-form .btn { width:100%; text-align:center; font-size:13px; padding:6px 10px; }
.actions form { margin:0; }

.create-form fieldset { border:1px solid #dde1e6; border-radius:8px; padding:16px 20px; margin-bottom:18px; background:#fff; }
.create-form legend { font-weight:600; font-size:15px; padding:0 8px; color:#33465c; }
.form-field { margin-bottom:14px; }
.form-field label { display:block; font-size:13px; font-weight:600; color:#333; margin-bottom:5px; }
.form-field input[type="text"], .form-field input[type="number"], .form-field select, .form-field textarea {
    width:100%; padding:8px 10px; border:1px solid #cfd4da; border-radius:6px; font-size:14px; font-family:inherit;
}
.form-field textarea { resize:vertical; }
.create-form details { margin-top:6px; }
.create-form summary { cursor:pointer; font-size:14px; color:#1f5fbf; user-select:none; margin-bottom:10px; }
.create-form > .btn { font-size:15px; padding:10px 22px; }

.static-value { padding:8px 10px; background:#f4f5f7; border:1px solid #e0e3e8; border-radius:6px; font-size:14px; color:#57606a; }
.btn-small { font-size:12px; padding:4px 10px; vertical-align:middle; }

.version-picker { display:flex; align-items:center; gap:10px; margin:16px 0; }
.version-picker select { padding:6px 10px; border:1px solid #cfd4da; border-radius:6px; font-size:14px; background:#fff; min-width:320px; }
.view-metrics { margin:16px 0; }
.metric-note { font-size: 11px; color: #8a8f98; margin-top: 2px; }

.article-body {
    background:#fff;
    border:1px solid #dde1e6;
    border-radius:8px;
    padding:32px 40px;
    margin-top:20px;
    font-family: Georgia, "Times New Roman", serif;
    font-size:17px;
    line-height:1.7;
    color:#222;
}
.article-body h1, .article-body h2, .article-body h3,
.article-body h4, .article-body h5, .article-body h6 {
    font-family: Arial, Helvetica, sans-serif;
    margin-top:1.4em;
    margin-bottom:0.4em;
    color:#111;
}
.article-body a { color:#1a5cb0; }
.article-body a:hover { color:#e05000; }
.edit-block-visual a { cursor: pointer; }
.article-body p { margin:0.8em 0; }
.article-body ul, .article-body ol { padding-left:1.6em; margin:0.6em 0; }
.article-body li { margin:0.3em 0; }
.article-body table { border-collapse:collapse; width:100%; margin:1em 0; }
.article-body td, .article-body th { border:1px solid #ccc; padding:6px 10px; }
.article-body th { background:#f4f4f4; }
.article-body blockquote {
    border-left:4px solid #ccc;
    margin:1em 0;
    padding:4px 16px;
    color:#555;
}
.article-body img { max-width:100%; height:auto; }

/* Врезка внимания (note) — ярко-зелёная заливка, как в Word.
   blockquote.attention-block — тот же блок внимания, проставленный руками
   в редакторе (маркер для экспортёра, см. app/exporters.py).
   blockquote:not([class]) — блок внимания без класса, как его отдаёт модель
   при генерации (легаси-разметка, ~2500 таких блоков в базе). */
.article-body .note,
.article-body blockquote.attention-block,
.article-body blockquote:not([class]) {
    background: #b6f0b6;
    border: 1px solid #7ecb7e;
    border-radius: 6px;
    padding: 14px 18px;
    margin: 1.4em 0;
    color: #1a1a1a;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.55;
}
.article-body .note strong {
    font-weight: 700;
}

/* Комментарий эксперта (expert-comment) — бирюзовая заливка, курсив */
.article-body blockquote.expert-comment {
    background: #b3e6e6;
    border: 1px solid #7fc0c0;
    border-left: 4px solid #3fa3a3;
    border-radius: 6px;
    padding: 14px 18px;
    margin: 1.4em 0;
    color: #123;
    font-family: Arial, Helvetica, sans-serif;
    font-style: italic;
    font-size: 15px;
    line-height: 1.55;
}
.article-body blockquote.expert-comment p {
    margin: 0.4em 0;
}
.article-body blockquote.expert-comment .expert-author {
    text-align: right;
    font-style: normal;
    font-weight: 600;
    margin-top: 0.6em;
}

.export-buttons { display:flex; flex-wrap:wrap; gap:10px; margin:16px 0; }

.rollback-form { display:flex; align-items:center; gap:10px; margin:10px 0; flex-wrap:wrap; }
.rollback-form select { padding:5px 10px; border:1px solid #cfd4da; border-radius:6px; font-size:13px; background:#fff; }
.rollback-form label { font-size:13px; color:#57606a; }

.run-result {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 14px 0;
    font-size: 14px;
    border: 1px solid #cbd5e0;
    background: #eef2f7;
    color: #2b3a4a;
}
.run-result-done { background: #dcf5e3; border-color: #a3e0b8; color: #1a7a37; }
.run-result-no_deficit { background: #eef2f7; border-color: #cbd5e0; color: #33465c; }
.run-result-model_no_changes { background: #fff3d6; border-color: #f0d999; color: #8a6100; }
.run-result-error { background: #fbdcdc; border-color: #f0a9a9; color: #a4222a; }
.run-step-form { display: inline-block; }
.btn-disabled { opacity: 0.6; cursor: not-allowed; }
.row-failed { background: #fbdcdc; }

.job-status {
    margin-top: 6px;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    display: inline-block;
    max-width: 340px;
}
.job-status-queued { background: #eef2f7; color: #5a6472; }
.job-status-processing { background: #fff3d6; color: #8a6100; }
.job-status-done { background: #dcf5e3; color: #1a7a37; }
.job-status-failed { background: #fbdcdc; color: #a4222a; }
.job-status-cancelled { background: #eceef0; color: #6a737d; }
.hint-small { font-size: 12px; color: #8a6100; margin-top: 4px; }

.run-card { border: 1px solid #d8dee4; border-radius: 8px; padding: 14px 16px; margin: 12px 0; background: #fff; }
.run-card-error { border-color: #f0a9a9; background: #fdf5f5; }
.run-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.run-step { font-weight: 600; font-size: 15px; }
.run-status-badge { font-size: 12px; padding: 3px 10px; border-radius: 12px; background: #eef2f7; color: #57606a; }
.run-status-done { background: #dcf5e3; color: #1a7a37; }
.run-status-error { background: #fbdcdc; color: #a4222a; }
.run-status-running { background: #fff3d6; color: #8a6100; }
.run-meta { font-size: 13px; color: #57606a; margin-bottom: 8px; }
.run-error { font-size: 13px; color: #a4222a; background: #fdeaea; padding: 8px 10px; border-radius: 6px; margin: 8px 0; }
.run-details { margin-top: 8px; }
.run-details summary { cursor: pointer; font-size: 13px; color: #0969da; padding: 4px 0; }
.run-pre { background: #f6f8fa; border: 1px solid #e1e4e8; border-radius: 6px; padding: 12px; font-size: 12px; white-space: pre-wrap; word-wrap: break-word; max-height: 400px; overflow-y: auto; margin-top: 6px; }
.subtle { color: #57606a; font-size: 14px; }

.model-select { padding: 4px 8px; border: 1px solid #cfd4da; border-radius: 6px; font-size: 12px; background: #fff; margin-right: 6px; margin-top: 6px; }

.analytics-step { margin: 22px 0; }
.analytics-step h2 { font-size: 16px; margin-bottom: 8px; }
.analytics-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.analytics-table th, .analytics-table td { border: 1px solid #d8dee4; padding: 6px 10px; text-align: left; }
.analytics-table th { background: #f6f8fa; font-weight: 600; }
.analytics-table tr:nth-child(even) { background: #fafbfc; }
.analytics-table tr.row-cheapest { background: #dcf5e3 !important; }
.badge-cheap { font-size: 11px; background: #1a7a37; color: #fff; padding: 2px 7px; border-radius: 10px; margin-left: 4px; }
.badge-few { font-size: 11px; background: #eef2f7; color: #8a6100; padding: 2px 7px; border-radius: 10px; margin-left: 4px; }
.analytics-comment { font-size: 13px; padding: 8px 12px; border-radius: 6px; margin-bottom: 6px; }
.analytics-comment-reliable { background: #dcf5e3; color: #1a5c2c; }
.analytics-comment-insufficient { background: #fff3d6; color: #8a6100; }
.analytics-comment-none { background: #eef2f7; color: #57606a; }
.metric-help { margin: 14px 0; border: 1px solid #d8dee4; border-radius: 8px; padding: 6px 12px; background: #fbfcfd; }
.metric-help summary { cursor: pointer; font-size: 13px; color: #0969da; font-weight: 500; }
.metric-help-body { font-size: 13px; color: #3a444e; margin-top: 8px; }
.metric-help-body p { margin: 8px 0; }
.metric-help-top { background: #f0f6ff; }

.cost-total { background: #f0f6ff; border: 1px solid #cfe0f5; border-radius: 8px; padding: 10px 14px; margin: 12px 0; font-size: 14px; }
.cost-total-sub { color: #57606a; font-size: 13px; margin-left: 6px; }
.step-cost { margin-top: 6px; }
.step-cost summary { cursor: pointer; font-size: 12px; color: #8a6100; }
.step-cost-table { width: 100%; border-collapse: collapse; font-size: 11px; margin-top: 6px; }
.step-cost-table th, .step-cost-table td { border: 1px solid #e1e4e8; padding: 3px 6px; text-align: left; }
.step-cost-table th { background: #f6f8fa; }
.step-cost-row-error { background: #fdf5f5; }

.step-prompt { margin-top: 8px; }
.step-prompt summary { cursor: pointer; color: #666; font-size: 0.9em; user-select: none; }
.prompt-text {
    white-space: pre-wrap;
    word-break: break-word;
    background: #f6f6f6;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    font-family: monospace;
    font-size: 0.85em;
    max-height: 400px;
    overflow-y: auto;
    margin-top: 6px;
}
.prompt-warning { font-size: 0.85em; color: #a4222a; margin: 6px 0 4px; }
.prompt-hint { font-size: 0.8em; color: #666; margin: 4px 0; word-break: break-word; }

.insert-version-block { margin: 12px 0; border: 1px solid #d8dee4; border-radius: 8px; padding: 6px 12px; background: #fbfcfd; }
.insert-version-block summary { display: inline-block; list-style: none; }
.insert-version-block summary::-webkit-details-marker { display: none; }
.insert-version-body { margin-top: 10px; }
.insert-hint { font-size: 13px; color: #57606a; margin-bottom: 8px; }
.insert-textarea { width: 100%; font-family: monospace; font-size: 12px; padding: 8px; border: 1px solid #cfd4da; border-radius: 6px; box-sizing: border-box; margin-bottom: 8px; resize: vertical; }

.step-state { display: flex; gap: 8px; align-items: flex-start; margin-top: 4px; flex-wrap: wrap; }
.step-state-form { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; margin: 0; }
.state-radio { font-size: 12px; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; color: #57606a; white-space: nowrap; }
.state-radio input { margin: 0; }
/* приглушение выключенных шагов */
.step-row-disabled { background: #eef0f2; }
.step-row-disabled td { color: #8a919a; }
.step-row-disabled .state-radio { color: #57606a; }
/* пометка ручных шагов */
.step-row-manual { background: #fff8e6; }
/* пометка выполненных шагов */
.step-row-done { background: #e3f7e8; }
.step-row-done td { color: #2a6b3d; }
.step-row-done .state-radio { color: #57606a; }

.run-pipeline-block { margin: 14px 0; padding: 10px 14px; background: #eef6ff; border: 1px solid #cfe0f5; border-radius: 8px; }
.btn-primary { background: #1a6dd6; color: #fff; border: none; }
.btn-primary:hover { background: #1560bd; }
.run-pipeline-hint { font-size: 12px; color: #57606a; margin-left: 8px; }

.pipeline-plan { margin-bottom: 10px; }
.pipeline-plan-title { font-size: 13px; font-weight: 600; color: #1a5c9e; margin-bottom: 4px; }
.pipeline-plan-list { margin: 4px 0 6px 0; padding-left: 22px; font-size: 13px; color: #2a3a4a; }
.pipeline-plan-list li { margin: 2px 0; }
.pipeline-plan-pos { color: #8a919a; font-size: 12px; }
.pipeline-plan-stop { font-size: 12px; color: #8a6100; background: #fff8e6; padding: 6px 10px; border-radius: 6px; margin-top: 4px; }
.pipeline-plan-empty { font-size: 13px; color: #8a6100; }

.pipeline-overwrite-warning { background: #fde8e8; border: 1px solid #f5aeae; color: #a4222a; font-size: 13px; font-weight: 600; padding: 8px 12px; border-radius: 6px; margin-bottom: 8px; }

.model-save-form { margin: 0; }
.model-label { font-size: 12px; color: #57606a; display: inline-flex; align-items: center; gap: 4px; }

.diff-toggle { margin: 10px 0; }
.diff-legend { font-size: 13px; color: #57606a; margin: 8px 0; }
.diff-changed { background: #fff8e1; border: 1px solid #f0d999; border-radius: 4px; padding: 2px 6px; margin: 4px 0; }
.diff-added { background: #e6ffed; border: 1px solid #a6f4c5; border-radius: 4px; padding: 2px 6px; margin: 4px 0; }
.diff-removed { background: #ffd7d5; border: 1px solid #ff8182; border-radius: 4px; padding: 4px 8px; margin: 4px 0; color: #b42318; font-size: 0.85em; }

.settings-tabs { margin: 12px 0; border-bottom: 1px solid #d0d7de; }
.settings-tabs a { display: inline-block; padding: 8px 16px; text-decoration: none; color: #57606a; }
.settings-tabs a.active { color: #1a5cb0; border-bottom: 2px solid #1a5cb0; font-weight: 600; }

.site-filter { display: inline-block; margin: 0 0 12px 16px; }
.site-filter select { padding: 4px; }

.pin-form { display: inline; float: right; }
.pin-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: #d4a72c; padding: 0 4px; line-height: 1; }
.pin-btn:hover { opacity: 0.7; }
.progress-badge { display: inline-block; font-size: 12px; padding: 1px 6px; border-radius: 3px; }
.progress-done { background: #dafbe1; color: #1a7f37; }
.progress-error { background: #ffebe9; color: #cf222e; }
.progress-running { background: #ddf4ff; color: #0969da; }
.progress-none { background: #f6f8fa; color: #57606a; }
.progress-when { font-size: 11px; color: #57606a; margin-left: 4px; }

.edit-block { position: relative; border: 1px dashed #d0d7de; padding: 8px; margin: 6px 0; }
.edit-block:hover { border-color: #0969da; }
.edit-block-toolbar { position: absolute; top: -10px; right: 4px; background: #fff; padding: 0 4px; }
.btn-tiny { font-size: 11px; padding: 1px 6px; cursor: pointer; }
.edit-block-visual:focus { outline: 2px solid #0969da; }
.edit-block-html { width: 100%; min-height: 80px; font-family: monospace; font-size: 12px; }
.edit-warning { background: #fff8c5; border: 1px solid #d4a72c; padding: 8px; margin: 8px 0; }
.edit-actions-top {
    margin: 0 0 12px;
    padding: 12px 0;
    position: sticky;
    top: 56px;
    z-index: 80;
    background: #f4f5f7;
    box-shadow: 0 4px 8px -4px rgba(0,0,0,.18);
}
.save-status { margin-left: 10px; font-size: 13px; color: #1a8a3a; }
.save-status.is-error { color: #c0392b; }

/* URL ссылки при наведении в режиме правки — как строка статуса браузера */
.link-preview {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 1100;
    max-width: 60vw;
    padding: 4px 8px;
    background: rgba(31, 41, 55, .88);
    color: #fff;
    font-size: 12px;
    border-radius: 0 4px 0 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
}

/* План статьи в режиме ручного редактирования — фиксированная панель слева */
.edit-toc {
    position: fixed;
    left: 20px;
    top: 90px;
    width: 240px;
    max-height: calc(100vh - 164px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid #dfe3e9;
    border-radius: 6px;
    font-size: 13px;
    z-index: 70;
}
.edit-toc-title {
    position: sticky;
    top: 0;
    padding: 8px 12px;
    font-weight: 500;
    color: #1f5fbf;
    background: #fbfcfd;
    border-bottom: 1px solid #dfe3e9;
}
.edit-toc-list { display: flex; flex-direction: column; padding: 4px 12px 12px; }
.edit-toc-item { color: #1a5cb0; text-decoration: none; padding: 3px 0; font-size: 13px; line-height: 1.35; cursor: pointer; }
.edit-toc-item:hover { color: #e05000; text-decoration: underline; }
.edit-toc-l3 { margin-left: 16px; }
.edit-toc-l4 { margin-left: 32px; }
.edit-toc-l5 { margin-left: 48px; }
.edit-toc-l6 { margin-left: 64px; }
.edit-toc-item.is-active { color: #0a3f8f; background: #eaf1fb; border-radius: 4px; }

/* Панели меньше 1500px не оставляют места для оглавления слева от статьи */
@media (max-width: 1500px) {
    .edit-toc { display: none; }
}

.step-limits { white-space: nowrap; font-size: 12px; }
.limit-tokens { color: #24292f; }
.limit-effort { display: inline-block; margin-left: 4px; padding: 0 4px; border-radius: 3px; background: #f6f8fa; color: #57606a; font-size: 11px; }
.limit-effort-override { background: #fff8c5; color: #7d4e00; }

/* Обёртка для широких таблиц — горизонтальная прокрутка вместо display:block
   (display:block на table ломает раскладку строк с формами/details внутри ячеек). */
.table-scroll { overflow-x: auto; }

/* Код кубика мелким серым под именем шага в /article-types/{id} — отдельный
   класс, не .subtle: .subtle уже висит на <tr> архивных шагов той же
   таблицы, переиспользование смешало бы два разных смысла в одном классе. */
.step-cell-code { display: block; font-size: 11px; color: #57606a; margin-top: 2px; }

.view-panels { display: flex; gap: 16px; align-items: stretch; margin: 12px 0; }
.view-panel { flex: 1; min-width: 0; }
.meta-tags td.meta-copy-cell { width: 1%; white-space: nowrap; }
.keys-scroll { max-height: 300px; overflow-y: auto; border: 1px solid #d0d7de; border-radius: 6px; }
.keys-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.keys-table th { position: sticky; top: 0; background: #f6f8fa; z-index: 1; text-align: left; }
.keys-row-ok { background: #dafbe1; }
.keys-row-partial { background: #fff8c5; }
.keys-row-missing { background: #ffebe9; }
.keys-empty { color: #57606a; font-size: 13px; }

.article-body mark { background: #d0d7de; color: inherit; padding: 0 1px; border-radius: 2px; }
.keys-missing { font-size: 12px; color: #57606a; margin: 6px 0 0 0; line-height: 1.5; }
.keys-toggle { margin: 8px 0; font-size: 13px; }

/* ── Мобильные (до 640px) ─────────────────────────────────────────── */
@media (max-width: 640px) {
    header.topbar {
        padding: 10px 12px;
        gap: 4px 12px;
    }
    header.topbar a.nav-link { font-size: 13px; }
    .topbar-balance {
        margin-left: 0;
        width: 100%;
        font-size: 12px;
        padding: 2px 0 0 0;
    }
    main { padding: 0 12px; }

    .table-scroll table { min-width: 640px; }

    .view-panels { flex-direction: column; }
    .keys-scroll { max-height: 240px; }

    /* карточки проектов — в одну колонку */
    .card-grid { grid-template-columns: 1fr; }
}

/* Разделитель между «Избранным» и остальными статьями */
.favorites-divider {
    border: 0;
    border-top: 1px solid #dfe3e9;
    margin: 8px 0 28px;
}

/* Оглавление статьи (план) */
.article-toc { margin: 12px 0 16px; border: 1px solid #dfe3e9; border-radius: 6px; background: #fbfcfd; }
.article-toc summary { cursor: pointer; padding: 8px 12px; font-weight: 500; color: #1f5fbf; user-select: none; }
.article-toc-list { display: flex; flex-direction: column; padding: 4px 12px 12px; }
.article-toc-item { color: #1a5cb0; text-decoration: none; padding: 3px 0; font-size: 14px; line-height: 1.35; }
.article-toc-item:hover { color: #e05000; text-decoration: underline; }
.article-toc-l3 { margin-left: 16px; }
.article-toc-l4 { margin-left: 32px; }
.article-toc-l5 { margin-left: 48px; }
.article-toc-l6 { margin-left: 64px; }
.article-body h1, .article-body h2, .article-body h3,
.article-body h4, .article-body h5, .article-body h6 { scroll-margin-top: 70px; }

/* Кнопка «наверх» */
#back-to-top {
    position: fixed; left: 20px; bottom: 76px; z-index: 90;
    width: 42px; height: 42px; border-radius: 50%;
    border: 1px solid #cfd4dc; background: #fff; color: #1f2733;
    font-size: 20px; line-height: 1; cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,.12);
    display: none;
}
#back-to-top.visible { display: block; }
#back-to-top:hover { background: #eef1f5; }

/* Прежняя версия блока при наведении */
#prev-peek {
    position: absolute; z-index: 500; display: none;
    max-height: 60vh; overflow: auto;
    background: #fff; border: 1px solid #cfd4dc; border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,.14); padding: 8px 12px;
    font-size: 13px; line-height: 1.45; color: #1f2733;
}
#prev-peek .pp-head { font-size: 12px; color: #57606a; margin-bottom: 4px; }
#prev-peek .pp-body { white-space: pre-wrap; }

#prev-peek .pp-body { white-space: normal; }
#prev-peek .pp-body a { pointer-events: none; }
#prev-peek .pp-body p:first-child, #prev-peek .pp-body h2:first-child,
#prev-peek .pp-body h3:first-child, #prev-peek .pp-body h4:first-child { margin-top: 0; }
#prev-peek .pp-body p:last-child { margin-bottom: 0; }
#prev-peek .pp-body table { font-size: 12px; }

/* Пословная подсветка правок между версиями */
.diff-changed ins, #prev-peek ins { text-decoration: none; color: #14663a; font-weight: 700; background: #d7f5e3; border-radius: 2px; padding: 0 1px; }
.diff-changed del, #prev-peek del { color: #b42318; text-decoration: line-through; background: #ffe3e1; border-radius: 2px; padding: 0 1px; }
#prev-peek .pp-body { padding: 0; }

/* Индикатор идущей операции */
.run-live-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    border-radius: 6px;
    background: #eaf4ff;
    border: 1px solid #9dc4ea;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
    padding: 10px 14px;
    min-width: 280px;
    max-width: 360px;
}
.run-live {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0;
    font-size: 14px;
    color: #1f4e8c;
    font-weight: 600;
}
.run-live-dot { width: 9px; height: 9px; border-radius: 50%; background: #2f6fd0; animation: run-live-pulse 1.4s ease-in-out infinite; }
@keyframes run-live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.source-data-block { margin-top: 24px; }
.source-data-block summary { display: inline-block; list-style: none; cursor: pointer; }
.source-data-block summary::-webkit-details-marker { display: none; }
.source-data-body { margin-top: 12px; }

.progress-queued { background: #eef2f7; color: #33465c; }

/* Широкие страницы (таблица шагов) — используем всю ширину экрана */
main.main-wide { max-width: 1600px; }

.project-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 20px;
    align-items: start;
}
.project-main { min-width: 0; }
.project-side {
    position: sticky;
    top: 66px;
    max-height: calc(100vh - 90px);
    margin-top: 12px;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fafafa;
}
.project-side h2 { margin-top: 16px; }
@media (max-width: 1200px) {
    .project-layout { grid-template-columns: 1fr; }
    .project-side { position: static; max-height: none; margin-top: 0; }
}

/* Ширины колонок таблицы шагов: справочные ужимаем, статусу даём место */
.table-scroll table { table-layout: auto; }
.table-scroll thead th:nth-child(1) { width: 44px; }            /* # */
.table-scroll thead th:nth-child(2) { width: 190px; }           /* Название */
.table-scroll thead th:nth-child(3) { width: 90px; }            /* Тип */
.table-scroll thead th:nth-child(4) { width: 64px; }            /* Веб-поиск */
.table-scroll thead th:nth-child(5) { width: 96px; }            /* Лимит */
.table-scroll thead th:nth-child(6) { width: 120px; }           /* Настройка */
.table-scroll thead th:nth-child(7) { width: 150px; }           /* Финансы */

.step-row td { vertical-align: top; font-size: 13px; }
.step-row td:nth-child(3), .step-row td:nth-child(4) { font-size: 12px; color: #57606a; }

/* селект модели не должен распирать колонку */
.model-select { max-width: 240px; }
.model-label { display: block; margin-top: 6px; font-size: 12px; }

/* таблица истории прогонов — компактнее, не распирает ячейку */
.step-cost-table { font-size: 10px; }
.step-cost-table th, .step-cost-table td { padding: 2px 4px; }
.step-cost { max-width: 100%; overflow-x: auto; }

.htmx-indicator { display: none; }
.htmx-indicator.htmx-request { display: block; }
.steps-busy {
    padding: 8px 12px;
    margin-bottom: 10px;
    border-radius: 6px;
    background: #fff6d6;
    border: 1px solid #e0c86a;
    font-weight: 600;
    position: fixed;
    top: 112px;
    right: 20px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.truncated-warning {
    margin-top: 6px;
    padding: 4px 8px;
    border-radius: 4px;
    background: #fff4e5;
    border: 1px solid #e0a458;
    color: #8a5100;
    font-size: 12px;
    font-weight: 600;
}

/* Страница «Расходы» */
.expenses-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    margin: 14px 0;
}
.expenses-filters label { font-size: 12px; color: #57606a; }
.expenses-filters select,
.expenses-filters input { padding: 6px 8px; border: 1px solid #cfd4da; border-radius: 6px; font-size: 13px; }
.expenses-filters input[type="number"] { width: 120px; }

.cost-estimate {
    display: inline-block;
    font-size: 11px;
    color: #8a6100;
    background: #fff3d6;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
}

.cost-none { color: #9aa4b1; }

.expenses-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 0;
    border-bottom: 1px solid #dde1e6;
    padding-bottom: 8px;
}
.expenses-tabs a {
    padding: 6px 12px;
    border-radius: 6px;
    text-decoration: none;
    color: #33465c;
    font-size: 13px;
}
.expenses-tabs a.active {
    background: #1f5fbf;
    color: #fff;
    font-weight: 600;
}

.expenses-pagination {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
}

.edit-block-visual h2, .edit-block-visual h3, .edit-block-visual h4,
.edit-block-visual h5, .edit-block-visual h6 { position: relative; }
.edit-block-visual h2::before, .edit-block-visual h3::before, .edit-block-visual h4::before,
.edit-block-visual h5::before, .edit-block-visual h6::before {
    position: absolute; left: -34px; top: .35em;
    font-size: 11px; font-weight: 600; line-height: 1;
    color: #8a94a6; background: #eef1f5; border: 1px solid #dde1e6;
    border-radius: 4px; padding: 2px 5px;
    user-select: none; pointer-events: none;
}
.edit-block-visual h2::before { content: "H2"; }
.edit-block-visual h3::before { content: "H3"; }
.edit-block-visual h4::before { content: "H4"; }
.edit-block-visual h5::before { content: "H5"; }
.edit-block-visual h6::before { content: "H6"; }

.run-progress-wrap { margin: 8px 0; }
.run-live-panel .run-progress-wrap { margin: 6px 0 0; }
.run-progress { display: flex; gap: 2px; height: 10px; margin: 8px 0; }
.run-progress-seg { flex: 1; border-radius: 2px; background: #c9d1d9; }
.run-progress-seg.is-done { background: #1a7f37; }
.run-progress-seg.is-running { background: #0969da; animation: run-live-pulse 1.4s ease-in-out infinite; }
.run-progress-seg.is-queued { background: #c9d1d9; }
.run-progress-seg.is-failed { background: #cf222e; }
.run-progress-bar { height: 8px; margin: 8px 0; border-radius: 4px; background: #c9d1d9; overflow: hidden; }
.run-progress-fill { height: 100%; background: #1a7f37; }
.run-progress-label { font-size: 12px; color: #656d76; }
.run-live-panel .run-progress-label { color: #1f4e8c; }
