:root {
    /* Профессиональная палитра — corporate slate */
    --bg: #e8edf2;
    --bg-subtle: #dce3ea;
    --surface: #f2f5f8;
    --surface-elevated: #ffffff;
    --surface-hover: #e6ebf0;
    --border: #b0bcc8;
    --border-light: #c8d0d9;
    --text: #1a2332;
    --text-muted: #4d5a6a;
    --accent: #2a5898;
    --accent-hover: #204775;
    --accent-soft: #dce8f4;
    --accent-muted: #5a85b8;
    --accent-rgb: 42, 88, 152;
    --ink-rgb: 26, 35, 50;
    --success: #1a6b47;
    --success-soft: #d4e8dc;
    --danger: #a83232;
    --danger-soft: #f0dede;
    --warning: #9a6b00;
    --warning-soft: #fff3d6;
    --highlight: #e9eef5;
    --shadow-sm: 0 1px 3px rgba(var(--ink-rgb), 0.06);
    --shadow-md: 0 4px 14px rgba(var(--ink-rgb), 0.08);
    --radius: 10px;
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: linear-gradient(165deg, #dce3ea 0%, var(--bg) 45%, #eef1f5 100%);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 2rem;
    background: var(--surface-elevated);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    /* Длинное название вытесняет меню на следующую строку, а не наезжает на него. */
    flex-wrap: wrap;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1 1 auto;
    min-width: 0;
}

.logo-img {
    height: 52px;
    width: auto;
    max-width: min(320px, 40vw);
    object-fit: contain;
    flex-shrink: 0;
    background: #ffffff;
    border-radius: 6px;
    padding: 2px 8px;
    border: 1px solid var(--border-light);
}

.logo-text {
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text);
    /* Длинное название переносится, а не наезжает на робота и пункты меню. */
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Анимация lottie с роботом-помощником: в шапке и на странице входа */
.js-lottie {
    flex-shrink: 0;
    align-self: center;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.js-lottie.is-ready {
    opacity: 1;
}

.js-lottie svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* В шапке — сразу после названия «ИИ-помощник …» */
.header-lottie {
    width: 42px;
    height: 42px;
}

.nav {
    display: flex;
    gap: 0.35rem;
    flex: 0 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    transition: color 0.2s, background 0.2s;
    font-weight: 500;
}

.nav-link:hover {
    color: var(--accent);
    background: var(--accent-soft);
}

.nav-link.active {
    color: #ffffff;
    background: var(--accent);
    box-shadow: 0 2px 5px rgba(var(--accent-rgb), 0.22);
}

/* Ниже 1280 px название и переключатели не помещаются в одну строку: переносим
   навигацию под название, иначе она наезжает на текст. */
@media (max-width: 1280px) {
    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.6rem;
        padding: 0.75rem 1.5rem;
    }

    .header-brand {
        flex: 0 0 auto;
        justify-content: center;
        text-align: center;
    }

    .nav {
        justify-content: center;
        width: 100%;
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem 1rem;
        gap: 0.75rem;
    }

    .header-brand {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 0.5rem;
    }

    .logo-img {
        height: 44px;
        max-width: min(280px, 85vw);
    }

    .logo-text {
        font-size: 1.05rem;
        line-height: 1.35;
        max-width: 100%;
    }

    .header-lottie {
        width: 33px;
        height: 33px;
        margin-top: -0.25rem;
    }

    .nav {
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        gap: 0.4rem;
    }

    .nav-link {
        flex: 1 1 calc(33.333% - 0.35rem);
        min-width: 5.5rem;
        padding: 0.5rem 0.5rem;
        font-size: 0.88rem;
        text-align: center;
    }

    .main {
        padding: 1rem;
    }

    .module-header h2 {
        font-size: 1.25rem;
    }

    .module-title-note {
        font-size: 0.85rem;
    }

    .module-header p {
        font-size: 0.92rem;
    }
}

@media (max-width: 380px) {
    .nav-link {
        flex: 1 1 100%;
        min-width: 0;
    }
}

.main { flex: 1; padding: 2rem; max-width: 1400px; margin: 0 auto; width: 100%; }

.footer {
    text-align: center;
    padding: 1rem 3rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-light);
    background: var(--surface-elevated);
    position: relative;
}

.module-header {
    margin-bottom: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.module-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0;
    color: var(--text);
    font-weight: 600;
    line-height: 1.25;
}
.module-header p { color: var(--text-muted); line-height: 1.5; }

/* Пояснение к блоку — сразу после его названия, обычным начертанием. */
.module-title-note {
    font-size: 0.92rem;
    font-weight: 400;
    color: var(--text-muted);
}
.module-header .module-guidance {
    margin: 0;
    padding: 0.5rem 0.7rem;
    font-size: 0.8rem;
    flex: 1 1 340px;
    min-width: 0;
    min-height: 3.6rem;
    display: flex;
    align-items: center;
}
.module-header .module-guidance .guidance-inner {
    display: block;
    min-width: 0;
}

/* Пояснение выровнено по верхнему краю и по высоте с переключателями режимов. */
.module-header-row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.55rem 1rem;
}
.module-header-row > .lawyer-mode-switch,
.module-header-row > .procurement-mode-switch {
    flex: 0 0 auto;
    margin-top: 0;
    align-content: center;
}

/* Предупреждение о чувствительных данных — с новой строки. */
.module-header .module-guidance .privacy-note {
    display: block;
    margin-top: 0.35rem;
    padding-top: 0.35rem;
    border-top: 1px solid var(--border-light);
}

.grid-2 {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.grid-2 > * {
    min-width: 0;
}

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

.card {
    background: var(--surface-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.card h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text);
    font-weight: 600;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    margin-bottom: 1rem;
    transition: border-color 0.2s, background 0.2s;
    background: var(--surface-hover);
}

.upload-zone.dragover {
    border-color: var(--accent-muted);
    background: var(--accent-soft);
}

.upload-zone.is-processing {
    border-color: var(--accent);
    border-style: solid;
    border-width: 3px;
    background: linear-gradient(135deg, #e8eef4 0%, var(--accent-soft) 100%);
    box-shadow:
        0 0 0 4px rgba(var(--accent-rgb), 0.14),
        inset 0 0 0 1px rgba(var(--accent-rgb), 0.1);
    pointer-events: none;
    animation: upload-zone-pulse 1.6s ease-in-out infinite;
    position: relative;
}

.upload-zone.is-processing::after {
    content: '⏳ Обработка файла…';
    display: block;
    margin-top: 0.75rem;
    padding: 0.45rem 0.65rem;
    border-radius: calc(var(--radius) - 2px);
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--accent-muted);
    color: var(--accent-hover);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    box-sizing: border-box;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

@keyframes upload-zone-pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.12); }
    50% { box-shadow: 0 0 0 6px rgba(var(--accent-rgb), 0.2); }
}

.card.is-file-processing {
    border-color: var(--accent);
    box-shadow:
        0 0 0 3px rgba(var(--accent-rgb), 0.14),
        var(--shadow-md);
}

.card.is-file-processing > h3::after {
    content: ' — обработка…';
    color: var(--accent);
    font-weight: 600;
    font-size: 0.85em;
}

body.app-file-processing {
    cursor: wait;
}

body.app-file-processing .upload-zone.is-processing * {
    cursor: wait;
}

.file-processing-banner {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding: 0.9rem 1.25rem;
    margin: -2rem -2rem 1.5rem;
    width: calc(100% + 4rem);
    max-width: calc(100% + 4rem);
    box-sizing: border-box;
    background: linear-gradient(90deg, var(--accent-hover) 0%, var(--accent) 55%, var(--accent-muted) 100%);
    color: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    animation: banner-glow 2s ease-in-out infinite;
}

@media (max-width: 900px) {
    .file-processing-banner {
        margin: -2rem -1rem 1.25rem;
        width: calc(100% + 2rem);
        max-width: calc(100% + 2rem);
        font-size: 0.92rem;
    }
}

.file-processing-banner__spinner {
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
    margin-top: 0.15rem;
    border: 3px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: status-spin 0.7s linear infinite;
}

.file-processing-banner__text {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

@keyframes banner-glow {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.08); }
}

.upload-zone p { margin-bottom: 0.5rem; font-size: 0.9rem; color: var(--text); }
.hint { font-size: 0.8rem !important; color: var(--text-muted) !important; line-height: 1.45; }

.file-name { display: block; margin-top: 0.5rem; font-size: 0.85rem; color: var(--success); }

.upload-block { margin-bottom: 0.5rem; }
.upload-block .btn-delete { margin-top: 0.25rem; }
.download-link {
    display: inline-block;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.download-link:hover { color: var(--accent-hover); text-decoration: underline; }

.osv-textarea {
    width: 100%;
    min-height: 200px;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-elevated);
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    line-height: 1.4;
    resize: vertical;
    margin-bottom: 0.75rem;
}
.osv-textarea:focus {
    outline: none;
    border-color: var(--accent-muted);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.fact-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.fact-meta { margin-top: 0.5rem; }

.sheet-link-block { margin-bottom: 0.75rem; }
.sheet-open-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    justify-content: center;
    text-decoration: none;
}
.subsection-title {
    font-size: 0.9rem;
    margin: 1rem 0 0.5rem;
    color: var(--text-muted);
    font-weight: 600;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s, box-shadow 0.2s, color 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 2px 5px rgba(var(--accent-rgb), 0.18);
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 3px 8px rgba(var(--accent-rgb), 0.24);
}
.btn-secondary {
    background: var(--surface-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: var(--accent-soft);
    border-color: var(--accent-muted);
    color: var(--accent);
}
.btn-secondary.sheet-open-btn {
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border-light);
}
.btn-secondary.sheet-open-btn:hover {
    background: var(--bg-subtle);
    border-color: var(--border);
    color: var(--text);
}
.btn-danger {
    background: var(--danger);
    color: #ffffff;
}
.btn-danger:hover { filter: brightness(0.92); }
.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    box-shadow: none;
    filter: none;
}
.btn:disabled:hover { filter: none; }
.btn-sm { font-size: 0.8rem; padding: 0.35rem 0.75rem; margin-top: 0.75rem; }
.btn-icon {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0 0.25rem;
}

.progress {
    height: 8px;
    background: var(--border-light);
    border-radius: 4px;
    overflow: hidden;
    margin: 0.65rem 0;
    border: 1px solid var(--accent-muted);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-hover), var(--accent-muted));
    width: 0%;
    transition: width 0.3s;
}

.progress.active {
    box-shadow: 0 0 6px rgba(var(--accent-rgb), 0.22);
}

.progress.active .progress-bar {
    width: 45%;
    animation: progress-slide 1.2s ease-in-out infinite;
}

@keyframes progress-slide {
    0% { margin-left: 0; }
    50% { margin-left: 40%; }
    100% { margin-left: 65%; }
}

.progress.hidden, .hidden { display: none !important; }

.status {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
    min-height: 1.25rem;
    line-height: 1.45;
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.status.loading {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem 0.9rem;
    background: #eef2f7;
    border: 1px solid var(--border-light);
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    animation: status-loading-pulse 2s ease-in-out infinite;
    min-width: 0;
}

@keyframes status-loading-pulse {
    0%, 100% { background: #eef2f7; }
    50% { background: #e4eaf0; }
}

.status.loading::before {
    content: '';
    flex-shrink: 0;
    width: 1.15rem;
    height: 1.15rem;
    margin-top: 0.1rem;
    border: 3px solid var(--accent-muted);
    border-top-color: var(--accent-hover);
    border-radius: 50%;
    animation: status-spin 0.65s linear infinite;
}

@keyframes status-spin {
    to { transform: rotate(360deg); }
}

.status.error {
    color: var(--danger);
    font-weight: 500;
    background: rgba(168, 50, 50, 0.07);
    border-color: rgba(168, 50, 50, 0.22);
}

.status.ok {
    color: var(--success);
    font-weight: 600;
    background: rgba(26, 107, 71, 0.08);
    border-color: rgba(26, 107, 71, 0.22);
}

.chat-section {
    display: flex;
    flex-direction: column;
    min-height: 500px;
    box-shadow: var(--shadow-md);
}
.chat-section h3 {
    margin-bottom: 1rem;
    color: var(--text);
    font-weight: 600;
}

.chat-messages {
    position: relative;
    flex: 1;
    overflow-y: auto;
    max-height: 420px;
    padding: 1rem;
    background: var(--surface-hover);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.message {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    line-height: 1.5;
    white-space: normal;
}

.message.message-text {
    white-space: pre-wrap;
}

.message.user {
    background: var(--accent);
    color: #ffffff;
    margin-left: 2rem;
    box-shadow: 0 2px 6px rgba(var(--accent-rgb), 0.18);
}

.message.bot {
    background: var(--surface-elevated);
    margin-right: 2rem;
    border: 1px solid var(--border-light);
    color: var(--text);
}

.message.bot ul,
.message.bot ol,
.message.bot .message-text ul,
.message.bot .message-text ol,
.message.bot .audit-block-body ul,
.message.bot .audit-block-body ol {
    margin: 0.35rem 0 0.35rem 1.25rem;
    padding: 0 0 0 1.25rem;
}
.message.bot ul,
.message.bot .message-text ul,
.message.bot .audit-block-body ul {
    list-style-type: disc;
    list-style-position: outside;
}
.message.bot ol,
.message.bot .message-text ol,
.message.bot .audit-block-body ol {
    list-style-type: decimal;
    list-style-position: outside;
}

/* Нумерованные ответы чата: только нативные маркеры — ровная колонка, включая последний пункт */
.message.bot .message-text ol.chat-numbered,
.message.bot ol.chat-numbered {
    list-style-type: decimal !important;
    list-style-position: outside !important;
    margin: 0.4rem 0 0.4rem 0.15rem !important;
    padding: 0 0 0 1.6rem !important;
    counter-reset: none;
}
.message.bot .message-text ol.chat-numbered > li,
.message.bot ol.chat-numbered > li {
    display: list-item !important;
    list-style: decimal outside !important;
    margin: 0.25rem 0;
    padding: 0;
    min-height: 0;
}
.message.bot .message-text ol.chat-numbered > li::before,
.message.bot .message-text ol.chat-numbered > li::after,
.message.bot ol.chat-numbered > li::before,
.message.bot ol.chat-numbered > li::after {
    content: none !important;
    display: none !important;
}
.message.bot .message-text ol.chat-numbered .chat-num-body,
.message.bot ol.chat-numbered .chat-num-body {
    display: inline;
}

.message.bot ul li,
.message.bot ol:not(.chat-numbered) li,
.message.bot .message-text ul li,
.message.bot .message-text ol:not(.chat-numbered) li,
.message.bot .audit-block-body li {
    display: list-item;
    margin: 0.15rem 0;
}
.message.bot ul.chat-examples {
    list-style-type: disc;
    list-style-position: outside;
    padding-left: 1.35rem;
}
.message.bot ul.chat-examples li {
    display: list-item;
    margin: 0.35rem 0;
}

.message.bot .chat-disclaimer {
    margin: 0.75rem 0 0;
    font-size: 0.9rem;
}

/* Компактные блоки загрузки («Торги», «Закупки») */
.compact-upload-sidebar .card:not(.history-card) {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    overflow-x: hidden;
    min-width: 0;
}

.compact-upload-sidebar .card:not(.history-card) h3 {
    margin-bottom: 0.5rem;
    font-size: 0.92rem;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.compact-upload-sidebar .upload-zone {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem 0.5rem;
    padding: 0.5rem 0.65rem;
    margin-bottom: 0.5rem;
    min-width: 0;
    box-sizing: border-box;
}

.compact-upload-sidebar .upload-zone p {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    font-size: 0.78rem;
    line-height: 1.3;
}

.compact-upload-sidebar .upload-zone .btn {
    flex: 0 0 auto;
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
    line-height: 1.25;
}

.compact-upload-sidebar .upload-zone.is-processing::after {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    margin-top: 0.35rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.78rem;
}

.compact-upload-sidebar .progress {
    height: 5px;
    margin: 0.35rem 0;
}

.compact-upload-sidebar .status {
    margin-top: 0.35rem;
    min-height: 1rem;
    padding: 0.25rem 0.4rem;
    font-size: 0.78rem;
    line-height: 1.35;
}

.compact-upload-sidebar .status.loading {
    gap: 0.4rem;
    padding: 0.4rem 0.55rem;
    font-size: 0.8rem;
}

.compact-upload-sidebar .status.loading::before {
    width: 0.9rem;
    height: 0.9rem;
    border-width: 2px;
}

.compact-upload-sidebar .file-list {
    margin: 0.35rem 0 0;
}

.compact-upload-sidebar .file-list li {
    padding: 0.3rem 0.45rem;
    margin-bottom: 0.2rem;
    font-size: 0.78rem;
    line-height: 1.35;
}

.compact-upload-sidebar .file-list li small.muted {
    font-size: 0.72rem;
}

.compact-upload-sidebar .file-list .btn-icon {
    font-size: 1.05rem;
    line-height: 1;
}

.chat-form.procurement-check-form,
.chat-form.lawyer-check-form {
    justify-content: flex-start;
}

.chat-form.procurement-check-form .procurement-chat-input,
.chat-form.lawyer-check-form .lawyer-chat-input {
    display: none;
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chat-form input[type="text"] {
    flex: 1;
    min-width: 200px;
    padding: 0.65rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-elevated);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-form input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-muted);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-form select {
    padding: 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-elevated);
    color: var(--text);
}

.history-list { list-style: none; }
.history-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.85rem;
}
.history-list li:last-child { border-bottom: none; }
.history-list time { color: var(--text-muted); font-size: 0.75rem; }
.history-query { margin-top: 0.25rem; color: var(--text); }
.economist-history-link {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    font: inherit;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}
.economist-history-link:hover {
    color: var(--accent);
    text-decoration: underline;
}
.economist-history-link:focus-visible {
    outline: 3px solid rgba(var(--accent-rgb), 0.28);
    outline-offset: 3px;
    border-radius: 3px;
}
.economist-message-group {
    border-radius: var(--radius);
    transition: background 0.3s, box-shadow 0.3s;
}
.economist-message-highlight {
    background: var(--accent-soft);
    box-shadow: 0 0 0 5px var(--accent-soft);
}
.history-link { color: var(--accent); text-decoration: none; font-weight: 500; }
.history-link:hover { color: var(--accent-hover); text-decoration: underline; }
.muted { color: var(--text-muted); }

/* Единые состояния рабочих модулей */
.module-guidance,
.module-progress-summary {
    margin-bottom: 0.75rem;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface-hover);
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.45;
}

.module-guidance .privacy-note {
    display: block;
    margin-top: 0.45rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--border-light);
    color: var(--danger);
    font-weight: 600;
}

.module-progress-summary {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    background: var(--surface-elevated);
    box-shadow: var(--shadow-sm);
}

.module-progress-summary strong { color: var(--text); }
.module-progress-summary.is-ready {
    background: var(--success-soft);
    border-color: rgba(26, 107, 71, 0.3);
}
.module-progress-summary.is-ready strong { color: var(--success); }

.module-empty-state {
    display: flex;
    min-height: 180px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 1.5rem;
    color: var(--text-muted);
    text-align: center;
}
.module-empty-state strong { color: var(--text); font-size: 1rem; }

.module-action-hint {
    min-height: 1.1rem;
    margin-top: 0.45rem;
    color: var(--text-muted);
    font-size: 0.78rem;
}
.module-action-hint.is-ready { color: var(--success); }
.module-action-hint.is-loading { color: var(--accent-hover); font-weight: 600; }
.module-action-hint.is-loading::before {
    content: '';
    display: inline-block;
    width: 0.8rem;
    height: 0.8rem;
    margin-right: 0.45rem;
    vertical-align: -0.08rem;
    border: 2px solid var(--accent-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: status-spin 0.7s linear infinite;
}

.module-history-link {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}
.module-history-link:hover { color: var(--accent); text-decoration: underline; }
.module-history-link:focus-visible {
    outline: 3px solid rgba(var(--accent-rgb), 0.28);
    outline-offset: 3px;
    border-radius: 3px;
}
.module-message-group {
    border-radius: var(--radius);
    transition: background 0.3s, box-shadow 0.3s;
}
.module-message-highlight {
    background: var(--accent-soft);
    box-shadow: 0 0 0 5px var(--accent-soft);
}

.selected-file-meta {
    margin-top: 0.75rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface-hover);
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
}
.selected-file-meta strong { color: var(--text); }

.anon-report p { margin: 0.25rem 0; }
.anon-report .anon-file { margin-bottom: 0.5rem; }
.anon-report .anon-summary { margin-bottom: 0.75rem; }
.anon-report .anon-type {
    margin: 0.5rem 0 0.75rem;
    padding: 0.6rem 0.8rem;
    background: var(--surface-hover);
    border-radius: 0.5rem;
}
.anon-report .anon-type h4 {
    margin: 0 0 0.35rem;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text);
}
.anon-report .anon-type .anon-type-count {
    color: var(--accent);
    font-weight: 700;
}
.anon-report .anon-type ul { list-style: none; margin: 0; padding: 0; }
.anon-report .anon-type li {
    font-size: 0.9rem;
    padding: 0.15rem 0;
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
    word-break: break-word;
}
.anon-report .anon-type code {
    color: var(--accent);
    font-weight: 600;
    white-space: nowrap;
}

.anon-scope {
    margin-top: 1rem;
    padding: 0.75rem 0.9rem;
    background: var(--surface-hover);
    border-radius: 0.5rem;
}
.anon-scope h4 {
    margin: 0 0 0.4rem;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text);
}
.anon-scope ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.anon-scope li {
    font-size: 0.9rem;
    padding: 0.15rem 0;
}
.anon-scope .anon-scope-type {
    font-weight: 600;
    color: var(--accent);
}

.anon-mode-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.anon-mode-switch .btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
#doc-mode-note {
    margin: 0 0 0.75rem;
}

.result-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.result-heading h3 { margin: 0; }
.result-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.result-actions .btn-sm { margin-top: 0; }

.history-link.is-active {
    color: var(--accent-hover);
    font-weight: 700;
}

@media (max-width: 640px) {
    .module-guidance,
    .module-progress-summary {
        padding: 0.6rem 0.7rem;
        font-size: 0.8rem;
    }

    .module-empty-state {
        min-height: 140px;
        padding: 1rem;
    }

    .result-heading {
        display: block;
    }

    .result-actions {
        margin-top: 0.75rem;
    }

    .result-actions .btn {
        flex: 1 1 auto;
    }
}

/* Экономист: быстрый старт и понятная обратная связь в чате */
.fact-updated-date {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 400;
}

.main--economist {
    max-width: none;
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

.main--economist .module-header {
    flex: 0 0 auto;
}

.economist-layout {
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    overflow: hidden;
}

.economist-layout .sidebar {
    align-self: start;
}

.economist-chat {
    height: 100%;
    min-height: 0;
    margin-bottom: 0;
    overflow: hidden;
}

.economist-chat .chat-messages {
    height: 0;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.economist-chat-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.economist-chat-heading h3 {
    margin-bottom: 0.25rem;
}

.economist-welcome-title {
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.economist-examples {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
}

.economist-example {
    width: 100%;
    min-height: 3.25rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface-hover);
    color: var(--accent-hover);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.economist-example-item {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.economist-example-item small {
    display: block;
    margin-top: 0.4rem;
    padding: 0 0.15rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.35;
}

.economist-example:hover {
    background: var(--accent-soft);
    border-color: var(--accent-muted);
}

.economist-example:focus-visible,
.economist-chat-form input:focus-visible,
.economist-chat-form .btn:focus-visible {
    outline: 3px solid rgba(var(--accent-rgb), 0.28);
    outline-offset: 2px;
}

.economist-request-status {
    min-height: 1.35rem;
    margin: -0.25rem 0 0.65rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.4;
}

.economist-request-status.loading {
    opacity: 1;
    pointer-events: auto;
    color: var(--accent-hover);
    font-weight: 600;
}

.economist-request-status.loading::before {
    content: '';
    display: inline-block;
    width: 0.8rem;
    height: 0.8rem;
    margin-right: 0.45rem;
    vertical-align: -0.08rem;
    border: 2px solid var(--accent-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: status-spin 0.7s linear infinite;
}

.economist-request-status.ok { color: var(--success); }
.economist-request-status.error { color: var(--danger); }

.economist-chat-form .btn:disabled {
    background: var(--border);
    color: var(--surface-elevated);
    box-shadow: none;
    cursor: not-allowed;
}

.economist-form-hint {
    margin-top: 0.4rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.economist-compact-examples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.economist-compact-examples > span {
    margin-right: 0.1rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.economist-compact-examples button {
    padding: 0.25rem 0.55rem;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: var(--surface-hover);
    color: var(--accent-hover);
    font: inherit;
    font-size: 0.75rem;
    line-height: 1.25;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.economist-compact-examples button:hover {
    background: var(--accent-soft);
    border-color: var(--accent-muted);
}

.economist-compact-examples button:focus-visible {
    outline: 3px solid rgba(var(--accent-rgb), 0.28);
    outline-offset: 2px;
}

@media (max-width: 700px) {
    .economist-examples {
        grid-template-columns: 1fr;
    }

    .economist-welcome {
        margin-right: 0;
    }

    .economist-chat .chat-messages {
        height: 420px;
        min-height: 420px;
        max-height: 420px;
        overflow-y: auto;
    }

    .economist-chat-form {
        display: grid;
        grid-template-columns: 1fr;
    }

    .economist-chat-form input[type="text"],
    .economist-chat-form .btn {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 900px) {
    .main--economist {
        display: block;
        flex: 0 0 auto;
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .economist-layout {
        min-height: 0;
        overflow: visible;
    }

    .economist-chat {
        height: auto;
        margin-bottom: 1rem;
        overflow: visible;
    }
}

/* Полноэкранный рабочий блок: Юрист, Закупки, Торги, Секретарь */
.main--module-full {
    max-width: none;
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

.main--module-full .module-header {
    flex: 0 0 auto;
}

.module-layout {
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    overflow: hidden;
}

.module-layout .sidebar {
    align-self: start;
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.module-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    margin-bottom: 0;
    overflow: hidden;
}

.module-chat > h3,
.result-heading {
    margin-bottom: 0.5rem;
}

.module-chat .chat-messages,
.module-chat .protocol-output,
.module-chat .result-output {
    height: 0;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
}

@media (max-width: 700px) {
    .module-chat .chat-messages,
    .module-chat .protocol-output,
    .module-chat .result-output {
        height: 420px;
        min-height: 420px;
        max-height: 420px;
        overflow-y: auto;
    }
}

@media (max-width: 900px) {
    .main--module-full {
        display: block;
        flex: 0 0 auto;
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .module-layout {
        min-height: 0;
        overflow: visible;
    }

    .module-layout .sidebar {
        max-height: none;
        overflow-y: visible;
    }

    .module-chat {
        height: auto;
        min-height: 414px;
        margin-bottom: 1rem;
        overflow: visible;
    }

    .economist-chat {
        height: auto;
        min-height: 414px;
        margin-bottom: 1rem;
        overflow: visible;
    }

    /* В потоке страницы область ответов не сжимается и растёт вместе с текстом. */
    .module-chat .chat-messages,
    .module-chat .protocol-output,
    .module-chat .result-output {
        height: auto;
        min-height: 180px;
        flex: 0 0 auto;
        overflow-y: visible;
    }
}

/* На невысоких экранах контент определяет высоту страницы: подвал не перекрывает
   рабочую область, а окно ответов растёт вместе с содержимым. */
@media (max-height: 860px) {
    .main--module-full,
    .main--economist {
        display: block;
        flex: 0 0 auto;
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .module-layout {
        min-height: 0;
        overflow: visible;
    }

    .module-layout .sidebar {
        max-height: none;
        overflow-y: visible;
    }

    .module-chat {
        height: auto;
        min-height: 414px;
        margin-bottom: 1rem;
        overflow: visible;
    }

    .economist-chat {
        height: auto;
        min-height: 414px;
        margin-bottom: 1rem;
        overflow: visible;
    }

    .module-chat .chat-messages,
    .module-chat .protocol-output,
    .module-chat .result-output {
        height: auto;
        min-height: 180px;
        flex: 0 0 auto;
        overflow-y: visible;
    }
}

code {
    font-size: 0.8em;
    background: var(--bg-subtle);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    color: var(--accent-hover);
}

.protocol-output,
.result-output {
    min-height: 400px;
    padding: 1rem;
    background: var(--surface-hover);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    overflow-y: auto;
    line-height: 1.6;
}

.protocol-output h2, .protocol-output h3 { margin: 1rem 0 0.5rem; color: var(--text); }
.protocol-output table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
    font-size: 0.9rem;
    background: var(--surface-elevated);
}
.protocol-output th, .protocol-output td {
    border: 1px solid var(--border);
    padding: 0.5rem;
    text-align: left;
}
.protocol-output th {
    background: var(--accent-soft);
    color: var(--text);
}

.file-list { list-style: none; margin: 1rem 0; }
.file-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    padding: 0.5rem;
    background: var(--surface-hover);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
}
.file-list li > span:first-child {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

mark, .citation-highlight {
    background: var(--highlight);
    padding: 0.1em 0.2em;
    border-radius: 3px;
    color: var(--text);
}

.citations {
    margin-top: 0.75rem;
    font-size: 0.85rem;
}

.citation-list {
    margin: 0.35rem 0 0;
    padding-left: 0;
    list-style: none;
    color: var(--text-muted);
}

.citation-source {
    margin-bottom: 0.2rem;
    line-height: 1.4;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Без кликабельных ссылок на localhost/сайт в ответах и источниках */
.message.bot a,
.citations a {
    color: inherit;
    text-decoration: none;
    pointer-events: none;
    cursor: text;
}

.loading { opacity: 0.7; pointer-events: none; }

.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(var(--ink-rgb), 0.38);
}

.confirm-overlay.hidden { display: none; }

body.confirm-open { overflow: hidden; }

.confirm-dialog {
    width: min(420px, 100%);
    padding: 1.25rem 1.5rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.confirm-message {
    margin-bottom: 1.25rem;
    line-height: 1.45;
    font-size: 1rem;
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Окно возврата в систему после разрыва сессии (см. static/js/auth-modal.js) */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(var(--ink-rgb), 0.38);
}

.auth-overlay.hidden { display: none; }

body.auth-open { overflow: hidden; }

.auth-dialog {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: min(420px, 100%);
    padding: 1.5rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.auth-title {
    margin: 0;
    font-size: 1.15rem;
}

.auth-hint {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.auth-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.auth-actions .login-submit { margin-top: 0; }

.economist-table-wrap {
    overflow-x: auto;
    margin-top: 0.25rem;
}

.economist-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.economist-table th,
.economist-table td {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border-light);
    text-align: left;
    vertical-align: top;
}

.economist-table th {
    background: var(--surface-hover);
    font-weight: 600;
    white-space: nowrap;
}

.economist-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.55);
}

.economist-table td:not(:nth-child(2)) {
    white-space: nowrap;
}

.economist-report {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.economist-object {
    margin: 0 0 0.5rem;
    line-height: 1.4;
}

.economist-section-title {
    margin: 0.85rem 0 0.35rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.economist-report .economist-section-title:first-of-type {
    margin-top: 0.25rem;
}

.economist-table-total {
    font-weight: 600;
    background: var(--surface-hover);
}

.economist-table-total td {
    border-top-width: 2px;
}

.procurement-mode-switch,
.lawyer-mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 1rem;
    max-width: 720px;
    padding: 0.35rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border-light);
    border-radius: calc(var(--radius) + 2px);
    box-shadow: var(--shadow-sm);
}

/* Колонки создаются по числу кнопок — чтобы не оставалось пустой колонки
   под кнопку, которой нет (у «Юриста» третья кнопка «Сбор информации»
   появляется только при включённом KAD-агенте). */
.module-header-row > .lawyer-mode-switch {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
}

/* В «Секретаре» полоса сжимается по содержимому: две кнопки без пустой
   трети, место под третью кнопку не резервируется. */
.module-header > .lawyer-mode-switch {
    width: fit-content;
}

.procurement-mode-btn,
.lawyer-mode-btn {
    min-height: 2.75rem;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    line-height: 1.35;
    text-align: center;
    white-space: normal;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.procurement-mode-btn:hover:not(.active),
.lawyer-mode-btn:hover:not(.active) {
    background: var(--surface-hover);
    border-color: var(--border);
    color: var(--text);
}

.procurement-mode-btn.active,
.lawyer-mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(var(--accent-rgb), 0.35);
}

.procurement-mode-btn.active:hover,
.lawyer-mode-btn.active:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

@media (max-width: 640px) {
    .procurement-mode-switch,
    .lawyer-mode-switch {
        grid-template-columns: 1fr;
        max-width: none;
        width: 100%;
        min-width: 0;
    }

    .module-header-row > .procurement-mode-switch,
    .module-header-row > .lawyer-mode-switch {
        flex: 1 1 auto;
        min-width: 0;
        grid-template-columns: 1fr;
        grid-auto-flow: row;
    }

    .module-header > .lawyer-mode-switch {
        width: 100%;
    }
}

.audit-remarks-heading {
    margin: 1rem 0 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.audit-summary-heading {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.audit-verdict {
    font-weight: 700;
}
.audit-verdict-fail {
    color: var(--danger);
}
.audit-verdict-ok {
    color: var(--success);
}

.audit-block {
    margin: 0.65rem 0;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    border-left-width: 4px;
}

.audit-block-critical {
    background: var(--danger-soft);
    border-left-color: var(--danger);
}

.audit-block-important {
    background: var(--warning-soft);
    border-left-color: var(--warning);
}

.audit-block-title {
    font-weight: 600;
    line-height: 1.45;
    margin-bottom: 0.45rem;
    color: var(--text);
}

.audit-block-critical .audit-block-title {
    color: var(--danger);
}

.audit-block-important .audit-block-title {
    color: var(--warning);
}

.audit-block-body ul,
.audit-block-body ol {
    margin: 0.15rem 0 0 1.25rem;
    padding: 0 0 0 1.25rem;
}
.audit-block-body ul {
    list-style-type: disc;
    list-style-position: outside;
}
.audit-block-body ol {
    list-style-type: decimal;
    list-style-position: outside;
}

.audit-block-body li {
    display: list-item;
    margin: 0.25rem 0;
}

.audit-block-body .muted {
    margin: 0;
    font-style: italic;
}

.parse-result {
    margin-top: 0.75rem;
    padding: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.5;
    background: var(--surface-hover);
    border-radius: var(--radius);
}

/* Настройки: кнопка-шестерёнка и модальное окно */
.settings-gear-icon {
    display: block;
    width: 1.15rem;
    height: 1.15rem;
    background-color: currentColor;
    -webkit-mask: url("../img/cogwheel.png") center / contain no-repeat;
    mask: url("../img/cogwheel.png") center / contain no-repeat;
}
.settings-gear {
    position: absolute;
    top: 50%;
    right: 0.9rem;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.settings-gear:hover {
    background: var(--accent-soft);
    border-color: var(--accent-muted);
    color: var(--accent);
}
.settings-gear:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.settings-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(var(--ink-rgb), 0.45);
}
.settings-overlay[hidden] { display: none; }

.settings-dialog {
    display: flex;
    flex-direction: column;
    width: min(880px, 100%);
    max-height: min(88vh, 860px);
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(var(--ink-rgb), 0.28);
}

.settings-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
}
.settings-head h2 { font-size: 1.1rem; font-weight: 600; }

.settings-close {
    border: none;
    background: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.25rem;
}
.settings-close:hover { color: var(--danger); }

.settings-body {
    padding: 1.1rem 1.25rem;
    overflow-y: auto;
    /* Полоса прокрутки видна всегда: окно настроек прокручивается по высоте. */
    scrollbar-gutter: stable;
}
.settings-section + .settings-section {
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px solid var(--border-light);
}
.settings-section[open] {
    padding-bottom: 1rem;
}

/* Заголовок пункта настроек: раскрывает пункт по клику */
.settings-section-head {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    padding: 0.4rem 0.25rem;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.settings-section-head::-webkit-details-marker {
    display: none;
}
.settings-section-head:hover {
    background: var(--surface-hover);
}
.settings-section-head:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.settings-section[open] > .settings-section-head {
    margin-bottom: 0.6rem;
}

/* Стрелка: повёрнута вниз, когда пункт раскрыт */
.settings-section-head::after {
    content: "";
    flex: 0 0 auto;
    width: 0.4rem;
    height: 0.4rem;
    margin-left: auto;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(45deg) translate(-0.1rem, -0.1rem);
    transition: transform 0.15s ease;
}
.settings-section[open] > .settings-section-head::after {
    transform: rotate(-135deg);
}

.settings-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}
/* Внутри раскрывающего заголовка отступ задаёт сам заголовок */
.settings-section-head h3 {
    margin: 0;
}
/* Маркер пункта настроек — как в перечислении */
.settings-section h3::before {
    content: "";
    flex: 0 0 auto;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.settings-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 0.65rem;
}

.settings-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
}
/* Список моделей прокручивается внутри рамки: до последней модели не нужно
   прокручивать всё окно настроек. */
.settings-models-wrap {
    max-height: min(46vh, 420px);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.settings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.settings-table th,
.settings-table td {
    padding: 0.55rem 0.7rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border-light);
}
.settings-table thead th {
    background: var(--surface-hover);
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}
.settings-table tbody tr:last-child td { border-bottom: none; }
.settings-table tbody tr.is-selected { background: var(--accent-soft); }
.settings-table tbody tr.is-unavailable { color: var(--text-muted); }
.settings-table tbody tr.settings-group th {
    padding: 0.55rem 0.8rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #ffffff;
    background: var(--accent);
    text-align: left;
    border-bottom: 1px solid var(--accent-hover);
}
.settings-col-pick { width: 2.2rem; }
.settings-table td.settings-pick { text-align: center; }
.settings-table input[type="radio"] {
    width: 1.05rem;
    height: 1.05rem;
    accent-color: var(--accent);
    cursor: pointer;
}
.settings-table input[type="radio"]:disabled { cursor: not-allowed; }

/* Управление пользователями (секция в настройках) */
.users-status {
    font-size: 0.8rem;
    color: var(--success);
    background: var(--success-soft);
    border-radius: var(--radius);
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.6rem;
}
.users-status[hidden] { display: none; }
.users-table td { vertical-align: middle; }
.users-login { font-weight: 600; white-space: nowrap; }
.users-self {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-size: 0.68rem;
    font-weight: 600;
}
.users-role { min-width: 9.5rem; }
.users-changed { white-space: nowrap; font-variant-numeric: tabular-nums; }
.users-actions { white-space: nowrap; }
.users-actions .btn { margin: 0 0.35rem 0.35rem 0; }
.users-badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}
.users-badge.is-on { color: var(--success); background: var(--success-soft); }
.users-badge.is-off { color: var(--danger); background: var(--danger-soft); }
.users-badge.is-temp { color: var(--warning); background: var(--warning-soft); }
.users-edit-row td { background: var(--highlight); }
.users-edit {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
}
.users-edit-login { font-weight: 600; }
.users-edit .settings-input { min-width: 11rem; }
/* Поля пароля в строке смены — те же блоки с заголовком, что и в форме
   добавления, поэтому фиксируем ширину обёртки, а не самого поля. */
.users-edit-field { flex: 0 0 11rem; }
.users-form {
    margin-top: 0.85rem;
    padding: 0.8rem 0.9rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface);
}
.users-form-title {
    margin: 0 0 0.6rem;
    font-size: 0.85rem;
    font-weight: 600;
}
.users-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0.6rem;
}
.users-field { display: flex; flex-direction: column; gap: 0.2rem; }
.users-field > span {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
}
.users-field .settings-input { width: 100%; }
.users-field-head {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}
.users-field-head label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
}
/* Кнопка стоит в строке заголовка, поэтому по высоте равна шрифту: тот же
   кегль и та же строка, без рамки — читается как ссылка, а не как кнопка. */
.users-gen {
    padding: 0;
    border: 0;
    background: none;
    font-family: inherit;
    font-size: 0.72rem;
    line-height: normal;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
}
.users-gen:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}
.users-gen:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.users-form-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-top: 0.7rem;
}
.users-check {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
}
.users-hint {
    margin: 0.6rem 0 0;
    font-size: 0.74rem;
    color: var(--text-muted);
    line-height: 1.45;
}

/* Логи пользователей (секция в настройках) */

.user-logs-path {
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--text-muted);
    word-break: break-all;
    cursor: text;
    user-select: all;
}
/* В свёрнутом пункте путь занимает одну строку, чтобы не ломать заголовок */
.settings-section-head .user-logs-path {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
/* Путь к файлу показываем только в раскрытом пункте */
.settings-section:not([open]) .user-logs-path {
    display: none;
}
.user-logs-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin: 0.6rem 0;
}
.user-logs-field { display: inline-flex; }
.user-logs-field .settings-input { min-width: 10rem; }
.user-logs-table td { font-size: 0.8rem; }
.user-logs-ts { white-space: nowrap; }
.user-logs-tokens { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.user-logs-question { max-width: 22rem; overflow-wrap: anywhere; }
.user-logs-error {
    display: block;
    margin-top: 0.2rem;
    color: var(--danger);
    font-size: 0.75rem;
}
.user-logs-code {
    display: inline-block;
    margin-top: 0.25rem;
    padding: 0.1rem 0.35rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm, 4px);
    background: var(--surface-hover);
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.7rem;
    cursor: help;
}
.user-logs-legacy {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-muted);
    font-size: 0.7rem;
}
.user-logs-status {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.75rem;
    white-space: nowrap;
}
.user-logs-status.is-ok {
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent-hover);
}
.user-logs-status.is-error {
    background: rgba(220, 38, 38, 0.12);
    color: var(--danger);
}

.settings-model-name { font-weight: 600; display: block; }
.settings-model-id {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}
.settings-model-note {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}
.settings-model-price { font-weight: 600; white-space: nowrap; }
.settings-model-unavailable {
    display: inline-block;
    margin-top: 0.3rem;
    padding: 0.1rem 0.45rem;
    font-size: 0.72rem;
    border-radius: 999px;
    background: var(--warning-soft);
    color: var(--warning);
}
.settings-model-link {
    display: inline-block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--accent);
}
.settings-model-link:hover { color: var(--accent-hover); text-decoration: underline; }

.settings-input {
    width: 100%;
    padding: 0.55rem 0.7rem;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.settings-input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.settings-error {
    margin-top: 0.7rem;
    padding: 0.5rem 0.7rem;
    font-size: 0.85rem;
    color: var(--danger);
    background: var(--danger-soft);
    border-radius: var(--radius);
}
.settings-error[hidden] { display: none; }

.settings-logo {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    flex-wrap: wrap;
}
.settings-logo-preview {
    flex-shrink: 0;
    min-width: 132px;
    min-height: 60px;
    max-width: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.6rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
}
.settings-logo-preview img[hidden] { display: none; }
.settings-logo-img {
    max-width: 100%;
    max-height: 56px;
    object-fit: contain;
}
.settings-logo-controls {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 200px;
    flex: 1;
}
.settings-logo-name {
    font-size: 0.85rem;
    font-weight: 600;
    word-break: break-all;
}
.settings-logo-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.2rem;
}
.settings-logo-pick { cursor: pointer; }
.settings-logo-pick:focus-within {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.settings-logo-pick input:focus-visible { outline: none; }
.settings-logo-status {
    font-size: 0.78rem;
    color: var(--success);
}
.settings-logo-status.is-error { color: var(--danger); }
.settings-logo-status[hidden] { display: none; }

.settings-foot {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.9rem 1.25rem;
    border-top: 1px solid var(--border-light);
    background: var(--surface);
    border-radius: 0 0 var(--radius) var(--radius);
}
.settings-current {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-muted);
}

@media (max-width: 720px) {
    .settings-overlay { padding: 0; align-items: flex-end; }
    .settings-dialog { max-height: 92vh; border-radius: var(--radius) var(--radius) 0 0; }
    .settings-foot { flex-wrap: wrap; }
    .settings-current { flex: 1 0 100%; order: -1; }
}

/* === Вход по логину и паролю === */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.main--login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}

.login-card {
    width: min(400px, 100%);
    padding: 2rem;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.login-brand .logo-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

/* Робот перед названием «ИИ-помощник …» на странице входа */
.login-lottie {
    width: 44px;
    height: 44px;
}

@media (max-width: 420px) {
    .login-lottie {
        width: 36px;
        height: 36px;
    }
}

.login-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.login-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.login-submit {
    margin-top: 0.25rem;
    padding: 0.65rem 1rem;
    font-size: 0.95rem;
}

.login-hint {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.login-logout {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-light);
    text-align: center;
}

.login-card code {
    display: block;
    margin-top: 0.4rem;
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    word-break: break-all;
    background: var(--highlight);
    border-radius: var(--radius);
}

/* Кнопка выхода в шапке: последний пункт навигации, отделён вертикальной чертой */
.nav-logout {
    margin-left: 0.35rem;
    padding-left: 0.6rem;
    border-left: 1px solid var(--border-light);
}

.nav-logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    /* Иконка вынесена из потока (см. .nav-logout-icon), поэтому высота кнопки
       задаётся строкой текста, как до появления картинки. Справа место под иконку. */
    position: relative;
    padding: 0.5rem 2.4rem 0.5rem 0.9rem;
    font: inherit;
    font-weight: 500;
    white-space: nowrap;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    cursor: pointer;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.nav-logout-btn:hover {
    color: #ffffff;
    background: var(--accent);
    border-color: var(--accent);
}

.nav-logout-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.nav-logout-icon {
    position: absolute;
    right: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.66em;
    height: 1.66em;
    object-fit: contain;
    /* Иконка чёрная, а при наведении фон становится синим — инвертируем в белый. */
    filter: none;
    transition: filter 0.2s;
}

.nav-logout-btn:hover .nav-logout-icon {
    filter: brightness(0) invert(1);
}

.nav-user {
    font-weight: 500;
}

/* На узком экране пункты занимают сетку — кнопка выхода занимает строку целиком */
@media (max-width: 768px) {
    .nav-logout {
        flex: 1 1 100%;
        display: flex;
        justify-content: center;
        margin-left: 0;
        padding-left: 0;
        border-left: none;
    }

    .nav-logout-btn {
        width: 100%;
        justify-content: center;
        font-size: 0.88rem;
    }
}

/* Вкладка «Арбитражные дела»: карточки заданий и состояния сбора КАД */
.arbitr-job {
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    margin-bottom: 0.6rem;
}

.arbitr-intro {
    margin: -0.25rem 0 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.arbitr-form {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.arbitr-form > label:not(.arbitr-checkbox),
.arbitr-field > label {
    margin-top: 0.45rem;
    font-weight: 600;
    font-size: 0.88rem;
}

/* Группа «лейбл — поле — подсказка» в форме сбора информации */
.arbitr-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.arbitr-form .arbitr-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.6rem 0.75rem;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.arbitr-form .arbitr-input::placeholder {
    color: #93a0af;
}

.arbitr-form .arbitr-input:hover {
    border-color: var(--border);
}

.arbitr-form .arbitr-input:focus {
    outline: none;
    border-color: var(--accent-muted);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ИНН — цифры моноширинные, чтобы было видно каждую из 10–12 позиций */
#arbitr-inn {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.08em;
}

/* Счётчик дел: аккуратное поле без браузерных «стрелок» */
.arbitr-form .arbitr-input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

.arbitr-form .arbitr-input[type="number"]::-webkit-outer-spin-button,
.arbitr-form .arbitr-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.arbitr-form .arbitr-run-btn {
    align-self: flex-start;
    margin-top: 0.55rem;
}

/* Живая проверка полей: зелёная — можно искать, красная — поправьте ввод */
.arbitr-field.is-valid .arbitr-input {
    border-color: var(--success);
}

.arbitr-field.is-valid .field-hint {
    color: var(--success);
}

.arbitr-field.is-invalid .arbitr-input {
    border-color: var(--danger);
}

.arbitr-field.is-invalid .field-hint {
    color: var(--danger);
}

.field-hint,
.arbitr-checkbox small {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.35;
}

.arbitr-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin: 0.7rem 0 0.25rem;
    cursor: pointer;
}

.arbitr-checkbox input {
    margin-top: 0.2rem;
    flex: 0 0 auto;
}

.arbitr-checkbox strong {
    display: block;
    font-size: 0.88rem;
}

.arbitr-agents-heading {
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.8rem;
    border-top: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 0.88rem;
}

.arbitr-agents-heading .btn {
    margin-left: auto;
}

.arbitr-job-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.arbitr-badge {
    flex: 0 0 auto;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.78rem;
    background: var(--accent-soft);
    color: var(--text-muted);
}

.arbitr-badge[data-state="running"] { background: var(--warning-soft); color: var(--warning); }
.arbitr-badge[data-state="done"] { background: var(--success-soft); color: var(--success); }
.arbitr-badge[data-state="failed"] { background: var(--danger-soft); color: var(--danger); }

.arbitr-job-meta {
    margin-top: 0.25rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.arbitr-job-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.arbitr-job-actions .btn {
    text-decoration: none;
}

.arbitr-warn,
.arbitr-error {
    margin-top: 0.3rem;
    font-size: 0.82rem;
}

.arbitr-warn { color: var(--warning); }
.arbitr-error { color: var(--danger); }
