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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== ШАПКА - УВЕЛИЧЕНА НА 50% ===== */
.header {
    background-color: #6c757d;
    color: white;
    padding: 7.5px 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    flex-shrink: 0;
    position: relative;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-header-instruction {
    background-color: #17a2b8;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
}

.btn-header-instruction:hover {
    background-color: #138496;
}

.header h1 {
    font-size: 1.275rem;
    font-weight: 500;
}

.btn-back {
    background-color: #5a6268;
    color: white;
    border: none;
    padding: 6px 15px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 1.125rem;
    transition: background-color 0.2s;
}

.btn-back:hover {
    background-color: #495057;
}

.btn-settings {
    background-color: #5a6268;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.btn-settings:hover {
    background-color: #495057;
    transform: rotate(45deg);
}

/* ===== ИНСТРУКЦИЯ ПОЛЬЗОВАТЕЛЯ ===== */
.user-instruction-modal {
    position: fixed;
    inset: 0;
    z-index: 2250;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.user-instruction-modal[hidden] {
    display: none;
}

.user-instruction-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.user-instruction-dialog {
    position: relative;
    z-index: 1;
    width: min(920px, 100%);
    max-height: calc(100vh - 32px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-instruction-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
    flex-shrink: 0;
}

.user-instruction-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #333;
}

.user-instruction-close {
    border: none;
    background: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #666;
}

.user-instruction-close:hover {
    color: #333;
}

.user-instruction-body {
    padding: 16px 20px;
    overflow: auto;
    color: #333;
    font-size: 0.92rem;
    line-height: 1.55;
}

.user-instruction-body h1,
.user-instruction-body h2,
.user-instruction-body h3,
.user-instruction-body h4 {
    color: #2c3e50;
    margin: 1.1em 0 0.55em;
    line-height: 1.3;
}

.user-instruction-body h1 {
    font-size: 1.35rem;
}

.user-instruction-body h2 {
    font-size: 1.15rem;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 0.35em;
}

.user-instruction-body h3 {
    font-size: 1.02rem;
}

.user-instruction-body h4 {
    font-size: 0.96rem;
}

.user-instruction-body p,
.user-instruction-body ul,
.user-instruction-body ol,
.user-instruction-body blockquote,
.user-instruction-body hr,
.user-instruction-body .user-instruction-table-wrap {
    margin: 0 0 0.85em;
}

.user-instruction-body ul,
.user-instruction-body ol {
    padding-left: 1.35rem;
}

.user-instruction-body li {
    margin-bottom: 0.35em;
}

.user-instruction-body code {
    background: #f1f3f5;
    border-radius: 3px;
    padding: 0.1em 0.35em;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 0.88em;
}

.user-instruction-body blockquote {
    border-left: 3px solid #17a2b8;
    padding: 0.35em 0 0.35em 0.9em;
    color: #495057;
    background: #f8f9fa;
}

.user-instruction-body hr {
    border: none;
    border-top: 1px solid #dee2e6;
}

.user-instruction-table-wrap {
    overflow-x: auto;
}

.user-instruction-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.user-instruction-table th,
.user-instruction-table td {
    border: 1px solid #dee2e6;
    padding: 8px 10px;
    vertical-align: top;
    text-align: left;
}

.user-instruction-table th {
    background: #f8f9fa;
    font-weight: 600;
}

.user-instruction-loading,
.user-instruction-error {
    color: #6c757d;
}

.user-instruction-error {
    color: #c0392b;
}

.user-instruction-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #e9ecef;
    background: #fff;
    flex-shrink: 0;
}

/* ===== НАСТРОЙКИ (config.cfg) ===== */
.app-settings-modal {
    position: fixed;
    inset: 0;
    z-index: 2200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.app-settings-modal[hidden] {
    display: none;
}

.app-settings-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.app-settings-dialog {
    position: relative;
    z-index: 1;
    width: min(680px, 100%);
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}

.app-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #e9ecef;
}

.app-settings-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #333;
    line-height: 1.35;
}

.app-settings-close {
    border: none;
    background: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #666;
}

.app-settings-body {
    padding: 14px 16px 16px;
}

.app-settings-label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: #333;
}

.app-settings-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9rem;
}

.app-settings-path-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.app-settings-path-row .app-settings-input {
    flex: 1 1 auto;
    min-width: 0;
}

.btn-settings-browse {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 0.85rem;
}

.app-settings-hint {
    margin: 6px 0 14px;
    font-size: 0.78rem;
    color: #666;
    line-height: 1.4;
}

.app-settings-subtitle {
    margin: 0 0 8px;
    font-size: 0.88rem;
    color: #333;
}

.app-settings-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 16px 0 4px;
    padding-top: 12px;
    border-top: 1px solid #dee2e6;
}

.app-settings-version-label {
    font-size: 0.88rem;
    color: #6c757d;
}

.app-settings-version {
    font-size: 0.95rem;
    font-weight: 600;
    color: #212529;
    font-family: Consolas, 'Courier New', monospace;
    letter-spacing: 0.02em;
}

.config-folder-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
    max-height: 260px;
    overflow-y: auto;
    padding: 8px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
}

.config-folder-row {
    display: grid;
    grid-template-columns: 76px 1fr;
    gap: 10px;
    align-items: start;
    padding: 6px 4px;
    border-bottom: 1px solid #e9ecef;
}

.config-folder-row:last-child {
    border-bottom: none;
}

.config-folder-name {
    display: inline-block;
    font-weight: 700;
    font-size: 0.75rem;
    color: #0d6efd;
    background: #e7f1ff;
    border-radius: 4px;
    padding: 3px 6px;
    line-height: 1.3;
    word-break: break-all;
}

.config-folder-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.config-folder-desc {
    font-size: 0.76rem;
    color: #495057;
    line-height: 1.35;
}

.config-folder-path {
    font-size: 0.72rem;
    color: #6c757d;
    line-height: 1.3;
    word-break: break-all;
}

.app-settings-browse-hint {
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffeeba;
    border-radius: 4px;
    padding: 6px 8px;
}

.config-folders-empty {
    margin: 0;
    font-size: 0.8rem;
    color: #6c757d;
}

.config-folder-list-upload {
    max-height: 420px;
}

.config-folder-card {
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background: #fff;
    padding: 8px;
}

.config-folder-card + .config-folder-card {
    margin-top: 8px;
}

.config-folder-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
}

.config-folder-actions .btn-secondary {
    font-size: 0.78rem;
    padding: 6px 10px;
}

.settings-upload-intro {
    margin-top: 0;
    margin-bottom: 10px;
}

.settings-data-root-panel {
    margin: 0 0 14px;
    padding: 10px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background: #f8f9fa;
}

.settings-data-root-value {
    display: block;
    margin-top: 4px;
    font-size: 0.78rem;
    color: #333;
    word-break: break-all;
    white-space: pre-wrap;
}

.settings-upload-panel {
    margin: 4px 0 14px;
    padding: 10px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background: #fbfbfc;
}

.settings-upload-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.settings-upload-status {
    margin-top: 8px;
    padding: 7px 9px;
    border-radius: 4px;
    font-size: 0.78rem;
    line-height: 1.35;
}

.settings-upload-status-info {
    color: #084298;
    background: #cfe2ff;
    border: 1px solid #b6d4fe;
}

.settings-upload-status-success {
    color: #0f5132;
    background: #d1e7dd;
    border: 1px solid #badbcc;
}

.settings-upload-status-error {
    color: #842029;
    background: #f8d7da;
    border: 1px solid #f5c2c7;
}

.settings-save-status {
    margin-top: 8px;
    padding: 7px 9px;
    border-radius: 4px;
    font-size: 0.78rem;
    line-height: 1.35;
}

.settings-save-status-info {
    color: #084298;
    background: #cfe2ff;
    border: 1px solid #b6d4fe;
}

.settings-save-status-success {
    color: #0f5132;
    background: #d1e7dd;
    border: 1px solid #badbcc;
}

.settings-save-status-error {
    color: #842029;
    background: #f8d7da;
    border: 1px solid #f5c2c7;
}

.stats-card-subtitle {
    margin: 0 0 10px;
    font-size: 0.6rem;
    color: #666;
    line-height: 1.35;
}

.stats-upload-hint {
    margin: 0 0 8px;
    font-size: 0.75rem;
    color: #666;
    line-height: 1.35;
}

.stats-upload-status {
    margin: 8px 0 0;
    padding: 7px 9px;
    border-radius: 4px;
    font-size: 0.78rem;
    line-height: 1.35;
}

.stats-upload-status-info {
    color: #084298;
    background: #cfe2ff;
    border: 1px solid #b6d4fe;
}

.stats-upload-status-success {
    color: #0f5132;
    background: #d1e7dd;
    border: 1px solid #badbcc;
}

.stats-upload-status-error {
    color: #842029;
    background: #f8d7da;
    border: 1px solid #f5c2c7;
}

.stat-base-upload {
    font-size: 0.68rem;
    padding: 4px 6px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #fff;
    color: #333;
    cursor: pointer;
    white-space: nowrap;
}

.stat-base-upload:hover {
    background: #f1f3f5;
}

.analiz-upload-hint {
    margin: 0 0 10px;
    font-size: 0.85rem;
    color: #666;
}

.app-settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
}

/* ===== ОСНОВНОЙ КОНТЕНТ - ГЛАВНАЯ СТРАНИЦА ===== */
.main-content {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    height: 100%;
}

/* Сетка меню - прямоугольники, распределены по экрану */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
    height: 100%;
    max-height: calc(100vh - 120px);
}

.menu-card {
    background: white;
    border-radius: 8px;
    padding: 25px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 140px;
    height: 100%;
}

.menu-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}

.card-icon {
    font-size: 4.32rem;
    margin-bottom: 14px;
}

.menu-card h2 {
    color: #333;
    margin-bottom: 10px;
    font-size: 2.04rem;
}

.menu-card p {
    color: #666;
    font-size: 1.68rem;
    line-height: 1.3;
}

.coming-soon {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: #ffc107;
    color: #333;
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: bold;
}

/* ===== СТРАНИЦА АНАЛИЗА ===== */
.analiz-content {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 8px 10px;
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.analiz-container {
    background: white;
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Контейнер с двумя колонками */
.analiz-layout {
    display: flex;
    gap: 15px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Левая колонка: основной контент (уже) */
.analiz-main-content {
    flex: 1 1 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    min-height: 0;
}

/* Правая колонка: незавершенные диалоги */
.unfinished-dialogs {
    flex: 0 0 35%;
    background-color: #e9ecef;
    padding: 12px;
    border-radius: 5px;
    max-height: none;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.unfinished-dialogs h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: #333;
    font-weight: 600;
}

.analiz-container h2 {
    color: #333;
    margin-bottom: 8px;
    font-size: 0.95rem;
    text-align: center;
}

.analiz-container h3 {
    color: #555;
    margin: 5px 0 4px 0;
    font-size: 0.8rem;
}

.dialog-item {
    background: white;
    padding: 8px 12px;
    margin: 6px 0;
    border-radius: 4px;
    transition: background-color 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.dialog-item-info {
    flex: 1;
    min-width: 0;
}

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

.dialog-item-actions .btn-primary,
.dialog-item-actions .dialog-delete-btn {
    padding: 6px 12px;
    font-size: 0.75rem;
}

.dialog-item:hover {
    background-color: #f8f9fa;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.dialog-item-name {
    font-weight: bold;
    color: #333;
    font-size: 0.85rem;
    flex: 1;
    margin-right: 10px;
}

.dialog-item-date {
    font-size: 0.75rem;
    color: #666;
    white-space: nowrap;
}

#dialogs-list {
    flex: 1;
    overflow-y: auto;
}

/* Загрузка и новый диалог - увеличенные размеры */
.upload-section, .new-dialog-section {
    margin: 10px 0;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 5px;
}

.upload-section h3,
.new-dialog-section h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: #333;
}

.upload-section input[type="file"] {
    width: 100%;
    padding: 10px;
    margin: 8px 0;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.9rem;
}

.upload-section .btn-primary,
.new-dialog-section .btn-primary {
    padding: 10px 20px;
    font-size: 0.9rem;
    margin-top: 5px;
}

.new-dialog-section .btn-primary {
    width: 100%;
    margin-top: 12px;
}

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

    .analiz-start-bar {
        align-items: stretch;
    }

    .analiz-start-btn {
        width: 100% !important;
        max-width: 280px;
        margin: 0 auto !important;
    }
}

.analiz-guide {
    margin: 0 0 10px;
    padding: 10px 12px;
    background: #eef5ff;
    border: 1px solid #cfe2ff;
    border-radius: 6px;
}

.analiz-guide-summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    color: #1f3f6d;
    list-style: none;
}

.analiz-guide-summary::-webkit-details-marker {
    display: none;
}

.analiz-guide[open] .analiz-guide-summary {
    margin-bottom: 8px;
}

.analiz-landing {
    flex-shrink: 0;
}

.analiz-setup-card {
    padding: 12px 14px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e3e7eb;
}

.analiz-setup-grid {
    display: grid;
    grid-template-columns: minmax(220px, 36%) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

.analiz-upload-col .btn-primary {
    width: 100%;
    margin-top: 8px;
}

.analiz-status-heading,
.analiz-upload-col h3,
.analiz-start-info h3 {
    font-size: 0.92rem;
    margin: 0 0 8px;
    color: #333;
}

.analiz-upload-result-panel {
    margin-top: 0;
    min-height: 96px;
    max-height: 120px;
    overflow-y: auto;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #d7dee8;
    border-left: 3px solid #007bff;
}

.analiz-upload-placeholder {
    color: #868e96;
    font-size: 0.82rem;
    line-height: 1.4;
}

.analiz-upload-progress .progress-message {
    font-size: 0.8rem;
}

.analiz-upload-progress .progress-file-name {
    font-size: 0.75rem;
}

.analiz-upload-progress .progress-bar {
    height: 14px;
}

.upload-success-compact p {
    margin: 3px 0;
    font-size: 0.8rem;
    line-height: 1.35;
}

.upload-success-compact .upload-success-title {
    font-weight: 700;
    font-size: 0.84rem;
    margin-bottom: 5px;
}

.analiz-start-bar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #dee2e6;
}

.analiz-start-info {
    width: 100%;
}

.analiz-start-info h3 {
    margin-bottom: 6px;
    text-align: center;
}

.analiz-start-info .vnd-name-display {
    margin: 0;
}

.analiz-start-actions {
    display: flex;
    justify-content: center;
    width: 100%;
    padding-top: 4px;
}

.analiz-start-btn {
    min-width: 200px;
    margin: 0 !important;
    width: auto !important;
    padding: 10px 28px !important;
}

body:not(.analysis-active):not(.federal-refs-active) .analiz-container {
    overflow-y: auto;
}

.analiz-guide h3 {
    margin: 0 0 8px;
    font-size: 1rem;
    color: #1f3f6d;
}

.analiz-guide-list {
    margin: 0 0 10px 18px;
    padding: 0;
    color: #333;
    font-size: 0.82rem;
    line-height: 1.45;
}

.analiz-guide-note {
    margin: 0 0 10px;
    font-size: 0.8rem;
    color: #555;
    line-height: 1.4;
}

.analiz-guide-files-btn {
    font-size: 0.78rem;
}

.vnd-name-display {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 10px 0 4px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #d7dee8;
    border-left: 4px solid #007bff;
    border-radius: 4px;
}

.vnd-name-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
}

.vnd-name-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: #212529;
    line-height: 1.35;
    word-break: break-word;
}

.vnd-name-text.is-empty {
    font-weight: 500;
    color: #868e96;
    font-style: italic;
}

.analiz-screen-hint {
    margin: 0 0 12px;
    padding: 10px 12px;
    background: #f8f9fa;
    border: 1px solid #e3e7eb;
    border-radius: 4px;
    font-size: 0.8rem;
    line-height: 1.45;
    color: #495057;
}

.analiz-modal {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.analiz-modal[hidden] {
    display: none;
}

.analiz-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.analiz-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}

.analiz-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #e9ecef;
}

.analiz-modal-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #333;
}

.analiz-modal-close {
    border: none;
    background: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #666;
}

.analiz-modal-close:hover {
    color: #333;
}

.analiz-modal-body {
    padding: 14px 16px 16px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #333;
}

.analiz-modal-body ul {
    margin: 10px 0;
    padding-left: 20px;
}

.analiz-modal-body li {
    margin: 6px 0;
}

.analiz-modal-footer-note {
    margin: 12px 0 0;
    padding: 10px 12px;
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #6d5a00;
}

/* ===== КНОПКИ ===== */
.btn-primary {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 6px 15px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-primary:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background-color 0.2s;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-success {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: background-color 0.2s;
}

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

.btn-success:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ===== ЧАТ - ПОЛНОЭКРАННЫЙ РЕЖИМ ===== */
.chat-container {
    display: none;
    flex-direction: column;
    flex: 1 1 0;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    overflow: hidden;
    min-height: 0;
    max-height: calc(100vh - 60px);
}

/* Заголовок чата */
.chat-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px 12px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
}

.chat-header h3 {
    margin: 0;
    color: #333;
    font-size: 0.85rem;
}

.clarification-banner {
    font-size: 0.75rem;
    color: #0c5460;
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    border-radius: 4px;
    padding: 6px 8px;
    line-height: 1.35;
}

.clarification-banner[hidden] {
    display: none;
}

.chat-header-buttons {
    display: none;
}

/* Окно сообщений - С ПРОКРУТКОЙ */
.chat-messages {
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    background-color: #f8f9fa;
    min-height: 0;
    height: 0; /* Важно для работы flex + overflow */
}

/* Стилизация скроллбара */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #e9ecef;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #adb5bd;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #6c757d;
}

.message {
    margin: 4px 0;
    padding: 8px 10px;
    border-radius: 6px;
    max-width: 85%;
    font-size: 0.8rem;
}

.message.user {
    background-color: #007bff;
    color: white;
    margin-left: auto;
    text-align: right;
}

.message.assistant {
    background-color: white;
    color: #333;
    border: 1px solid #ddd;
}

.message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.4;
}

/* Поле ввода */
.chat-input-container {
    display: flex;
    gap: 6px;
    padding: 8px;
    background-color: white;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

.chat-input-container textarea {
    flex: 1;
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.8rem;
    font-family: inherit;
    resize: none;
    max-height: 50px;
}

/* ===== КНОПКИ ВНИЗУ ПОД ЧАТОМ ===== */
.chat-footer-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 8px;
    background-color: #f8f9fa;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

/* ===== РЕЗУЛЬТАТЫ ЗАГРУЗКИ ===== */
.upload-result {
    margin-top: 10px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 5px;
    border-left: 3px solid #007bff;
    max-height: none;
    overflow-y: visible;
}

.upload-result h4 {
    color: #333;
    margin-bottom: 8px;
    font-size: 1rem;
}

.upload-success p, .upload-error p {
    margin: 5px 0;
    line-height: 1.5;
    font-size: 0.85rem;
}

/* Прогресс-бар */
.progress-container {
    width: 100%;
}

.progress-info {
    margin-bottom: 10px;
}

.progress-message {
    color: #333;
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.progress-file-name {
    color: #666;
    font-size: 0.8rem;
    margin: 0;
}

.progress-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.progress-bar {
    flex: 1;
    height: 20px;
    background-color: #e9ecef;
    border-radius: 10px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff 0%, #0056b3 100%);
    border-radius: 7px;
    transition: width 0.3s ease;
}

.progress-percent {
    color: #333;
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 40px;
    text-align: right;
}

.progress-steps {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    margin-top: 10px;
}

.progress-step {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    border-radius: 4px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    opacity: 0.5;
}

.progress-step.active {
    background-color: #e7f3ff;
    border-color: #007bff;
    opacity: 1;
}

.progress-step.completed {
    background-color: #d4edda;
    border-color: #28a745;
    opacity: 1;
}

.step-icon {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.step-text {
    font-size: 0.7rem;
    color: #666;
    text-align: center;
}

.progress-step.active .step-text {
    color: #007bff;
    font-weight: 600;
}

.progress-step.completed .step-text {
    color: #28a745;
}

/* ===== СТАТИСТИКА ===== */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.stat-card {
    background: #f8f9fa;
    padding: 8px;
    border-radius: 5px;
    border-left: 3px solid #007bff;
}

.stat-card h4 {
    color: #333;
    margin-bottom: 4px;
    font-size: 0.75rem;
}

.stat-card p {
    color: #666;
    margin: 2px 0;
    font-size: 0.7rem;
}

.stat-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: bold;
    margin-top: 3px;
}

.stat-status.ready {
    background-color: #28a745;
    color: white;
}

.stat-status.not-ready {
    background-color: #dc3545;
    color: white;
}

.stats-in-card {
    margin-top: 2px;
    text-align: left;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

#card-stats {
    cursor: default;
    justify-content: flex-start;
    align-items: stretch;
    padding: 10px 12px 8px;
    overflow: hidden;
    min-height: 0;
    text-align: center;
    gap: 2px;
}

#card-stats .stats-edit-switch {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    gap: 5px;
}

#card-stats .stats-edit-label {
    font-size: 0.62rem;
}

#card-stats .stats-edit-slider {
    width: 30px;
    height: 16px;
}

#card-stats .stats-edit-slider::before {
    width: 12px;
    height: 12px;
}

#card-stats .stats-edit-input:checked + .stats-edit-slider::before {
    transform: translateX(14px);
}

#card-stats .card-icon {
    font-size: 2rem;
    margin-bottom: 2px;
    flex-shrink: 0;
}

#card-stats h2 {
    font-size: 1.05rem;
    margin-bottom: 4px;
    text-align: center;
    width: 100%;
    color: #333;
    flex-shrink: 0;
}

#card-stats .stats-card-subtitle {
    font-size: 1.12rem;
    line-height: 1.3;
    margin: 0 0 8px;
    color: #666;
}

.stats-edit-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

.stats-edit-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: #555;
    white-space: nowrap;
}

.stats-edit-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.stats-edit-slider {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    background: #ced4da;
    border-radius: 20px;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.stats-edit-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    top: 2px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.stats-edit-input:checked + .stats-edit-slider {
    background: #007bff;
}

.stats-edit-input:checked + .stats-edit-slider::before {
    transform: translateX(16px);
}

.stat-item-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    flex-wrap: nowrap;
    min-width: 0;
}

#card-stats .stat-base-reset,
#card-stats .stat-base-recreate {
    padding: 2px 6px;
    border: 1px solid #ced4da;
    border-radius: 3px;
    background: #f8f9fa;
    color: #333;
    font-size: 0.62rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background-color 0.2s, border-color 0.2s, opacity 0.2s;
}

.stat-base-reset:hover:not(:disabled),
.stat-base-recreate:hover:not(:disabled) {
    background: #e9ecef;
    border-color: #adb5bd;
}

.stat-base-reset:disabled,
.stat-base-recreate:disabled,
#card-stats .recreate-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#card-stats .recreate-btn {
    flex-shrink: 0;
    margin-top: 4px;
    padding: 5px 10px;
    font-size: 0.72rem;
}

.stat-item {
    margin: 2px 0;
    padding: 2px 0;
    border-bottom: 1px solid #e9ecef;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-item-content {
    display: flex;
    flex-direction: column;
}

.stat-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
}

#card-stats .stat-status {
    font-size: 0.65rem;
    padding: 2px 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

#card-stats .stat-docs {
    font-size: 0.65rem;
    color: #666;
    margin-top: 1px;
    font-weight: normal;
    text-align: right;
}

#card-stats .stat-base-link {
    font-size: 0.8rem;
}

.recreate-btn {
    margin-top: 10px;
    padding: 8px 16px;
    background-color: #ffc107;
    color: #333;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: background-color 0.3s;
    width: 100%;
}

.recreate-btn:hover {
    background-color: #ffb300;
}

.recreate-btn:active {
    background-color: #ffa000;
}

.stat-base-link {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: #007bff;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.stat-base-link:hover {
    color: #0056b3;
}

.stat-base-link:focus-visible {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.stats-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.stats-modal[hidden] {
    display: none;
}

.stats-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.stats-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(520px, 100%);
    max-height: min(70vh, 520px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.stats-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
}

.stats-modal-header h3 {
    font-size: 1rem;
    color: #333;
}

.stats-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #666;
    cursor: pointer;
    padding: 0 4px;
}

.stats-modal-close:hover {
    color: #333;
}

.stats-modal-body {
    padding: 12px 16px 16px;
    overflow-y: auto;
}

.stats-modal-summary {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 10px;
}

.stats-modal-loading,
.stats-modal-empty,
.stats-modal-error {
    font-size: 0.85rem;
    color: #666;
}

.stats-modal-error {
    color: #dc3545;
}

.stats-doc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.stats-doc-list li {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.8rem;
}

.stats-doc-list li:last-child {
    border-bottom: none;
}

.stats-doc-name {
    color: #333;
    word-break: break-word;
    flex: 1;
}

.stats-doc-chunks {
    color: #666;
    white-space: nowrap;
    font-size: 0.75rem;
}

/* ===== ПОДВАЛ - КОМПАКТНЫЙ ===== */
.footer {
    background-color: #e9ecef;
    padding: 6px 0;
    text-align: center;
    flex-shrink: 0;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 15px;
}

.footer p {
    color: #666;
    font-size: 0.9rem;
}

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 768px) {
    .menu-grid {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, auto);
        gap: 12px;
    }
    
    .menu-card {
        min-height: 120px;
        height: auto;
    }
    
    .header h1 {
        font-size: 1.125rem;
    }
    
    .message {
        max-width: 95%;
    }
    
    .chat-footer-buttons {
        flex-direction: column;
        gap: 5px;
    }
}

/* ===== РЕЖИМ ДИАЛОГА - ПОЛНОЭКРАННЫЙ ===== */
body.dialog-active {
    overflow: hidden;
}

body.dialog-active .footer {
    display: none;
}

body.dialog-active .upload-section,
body.dialog-active .new-dialog-section,
body.dialog-active .analiz-container > h2 {
    display: none !important;
}

/* Контент в режиме диалога */
body.dialog-active .analiz-content {
    height: calc(100vh - 45px);
    max-height: calc(100vh - 45px);
    overflow: hidden;
}

/* Контейнер анализа в режиме диалога */
body.dialog-active .analiz-container {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

/* Чат контейнер в режиме диалога - видимый и занимает всё пространство */
body.dialog-active .analiz-layout {
    display: flex !important;
    gap: 0;
}

body.dialog-active .unfinished-dialogs {
    display: none !important;
}

body.dialog-active .analiz-main-content {
    flex: 1 1 100% !important;
    width: 100% !important;
    display: flex !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

body.dialog-active .chat-container {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0 !important;
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
}

/* Окно сообщений в режиме диалога - фиксированная высота с прокруткой */
body.dialog-active .chat-messages {
    flex: 1 1 0;
    min-height: 100px;
    height: calc(100vh - 250px);
    max-height: calc(100vh - 250px);
    overflow-y: auto !important;
    overflow-x: hidden;
}

/* ===== ДВУХЭТАПНЫЙ АНАЛИЗ ВНД ===== */
.analysis-stage-panel {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 20px;
    overflow: hidden;
}

.stage-header h3 {
    margin: 0 0 6px;
    color: #333;
}

.stage-subtitle {
    margin: 0 0 16px;
    color: #666;
    font-size: 0.95rem;
}

.stage1-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-right: 4px;
}

#stage1-panel .stage-header {
    flex-shrink: 0;
}

#stage1-panel .stage1-top-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}

#stage1-panel .stage-header h3 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.25;
}

#stage1-panel .stage-subtitle {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.3;
}

#stage1-panel .stage1-top-block .analiz-screen-hint {
    margin: 2px 0 0;
    padding: 5px 10px;
    font-size: 0.72rem;
    line-height: 1.35;
    flex-shrink: 0;
}

#stage1-panel.analysis-stage-panel {
    padding: 12px 16px;
}

#stage1-panel .stage1-form {
    gap: 8px;
    overflow: hidden;
    padding-right: 0;
}

#stage1-panel .stage1-form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    gap: 10px 14px;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
}

#stage1-panel .stage1-form-main,
#stage1-panel .stage1-form-side {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

#stage1-panel .stage1-form-side {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 8px 10px;
}

#stage1-panel .stage1-field-side {
    height: 100%;
    display: flex;
    flex-direction: column;
    margin: 0;
}

#stage1-panel .stage1-field {
    flex-shrink: 0;
}

#stage1-panel .stage1-field label,
#stage1-panel .stage1-field-label {
    margin-bottom: 4px;
    font-size: 0.78rem;
}

#stage1-panel .stage1-hint {
    margin: 0 0 4px;
    font-size: 0.68rem;
}

#stage1-panel .stage1-field select {
    max-width: none;
    padding: 5px 8px;
    font-size: 0.78rem;
}

#stage1-panel #stage1-legal {
    min-height: 0;
}

#stage1-panel .stage1-checkbox-group {
    gap: 4px;
    flex: 1;
}

#stage1-panel .stage1-checkbox-option {
    font-size: 0.76rem;
    gap: 6px;
    line-height: 1.3;
}

#stage1-panel .stage1-form-footer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding-top: 4px;
    border-top: 1px solid #e9ecef;
}

#stage1-panel .stage1-form-footer .stage1-note {
    margin: 0;
    padding: 6px 10px;
    font-size: 0.75rem;
}

#stage1-panel .stage1-form-footer .stage1-note:empty {
    display: none;
}

#stage1-panel .stage1-form-actions {
    display: flex;
    justify-content: center;
    width: 100%;
}

#stage1-panel .stage1-form-footer .btn-primary {
    flex-shrink: 0;
    margin: 0;
}

@media (max-width: 900px) {
    #stage1-panel .stage1-form-grid {
        grid-template-columns: 1fr;
    }

    #stage1-panel .stage1-form-side {
        order: 2;
    }
}

.stage1-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: #333;
}

.stage1-field select {
    width: 100%;
    max-width: 640px;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95rem;
    background: #fff;
}

.stage1-field input.create-text-input,
.stage1-field textarea {
    width: 100%;
    max-width: 640px;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95rem;
}

.stage1-field.field-error label {
    color: #a0670a;
}

.stage1-field.field-error input,
.stage1-field.field-error select,
.stage1-field.field-error textarea {
    border-color: #e0a800;
    box-shadow: 0 0 0 2px rgba(224, 168, 0, 0.22);
    background-color: #fffdf5;
}

.stage1-hint {
    margin: 0 0 6px;
    font-size: 0.85rem;
    color: #777;
}

.stage1-field-label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: #333;
}

.stage1-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stage1-checkbox-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.9rem;
    color: #333;
    cursor: pointer;
}

.stage1-checkbox-option input {
    margin-top: 3px;
    flex-shrink: 0;
}

.stage1-note {
    padding: 10px 12px;
    border-radius: 6px;
    background: #f0f7ff;
    color: #1a5276;
    font-size: 0.9rem;
}

.stage1-note.warning {
    background: #fff8e6;
    color: #856404;
}

.stage1-note.stage1-note-progress,
.analysis-result.analysis-progress {
    background: #f0f7ff;
    color: #1a5276;
}

.stage1-note .stage1-progress .progress-message,
.analysis-result.analysis-progress .stage1-progress .progress-message {
    margin: 0 0 10px;
    font-weight: 500;
    font-size: 0.95rem;
}

.stage1-note .stage1-progress .progress-bar-wrapper,
.analysis-result.analysis-progress .stage1-progress .progress-bar-wrapper {
    margin-bottom: 0;
}

.stage1-summary {
    padding: 12px 14px;
    margin-bottom: 14px;
    background: #f8f9fa;
    border-left: 4px solid #007bff;
    border-radius: 4px;
    font-size: 0.92rem;
    line-height: 1.5;
}

.stage1-fnd-block {
    margin-top: 4px;
}

.stage1-fnd-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 280px;
    overflow-y: auto;
    padding: 10px 12px;
    background: #f8fbff;
    border: 1px solid #d6e4ff;
    border-radius: 6px;
}

.stage1-fnd-item {
    padding: 10px 12px;
    background: #fff;
    border: 1px solid #e3eaf5;
    border-radius: 6px;
}

.stage1-fnd-item-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.82rem;
}

.stage1-fnd-index {
    font-weight: 600;
    color: #495057;
}

.stage1-fnd-role {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: lowercase;
}

.stage1-fnd-role-primary {
    background: #e7f1ff;
    color: #0d6efd;
}

.stage1-fnd-role-secondary {
    background: #eef2f7;
    color: #495057;
}

.stage1-fnd-type {
    color: #6c757d;
    font-size: 0.78rem;
}

.stage1-fnd-title {
    font-weight: 600;
    color: #212529;
    line-height: 1.4;
}

.stage1-fnd-articles,
.stage1-fnd-reason {
    margin-top: 6px;
    font-size: 0.86rem;
    color: #495057;
    line-height: 1.45;
}

.stage1-fnd-empty,
.stage1-fnd-loading {
    margin: 0;
    font-size: 0.88rem;
    color: #6c757d;
    line-height: 1.45;
}

.analysis-result.analysis-progress {
    white-space: normal;
}

.analysis-result {
    flex: 1;
    min-height: 200px;
    overflow-y: auto;
    padding: 16px;
    background: #fafafa;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    white-space: pre-wrap;
    line-height: 1.55;
    font-size: 0.95rem;
}

.stage-footer-buttons {
    display: flex;
    gap: 10px;
    margin-top: 14px;
    flex-shrink: 0;
}

body.analysis-active {
    overflow: hidden;
}

body.analysis-active .footer {
    display: none;
}

body.analysis-active .analiz-landing,
body.analysis-active .analiz-container > h2,
body.analysis-active .unfinished-dialogs {
    display: none !important;
}

body.analysis-active .analiz-content {
    height: calc(100vh - 45px);
    max-height: calc(100vh - 45px);
    overflow: hidden;
}

body.analysis-active .analiz-container {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

body.analysis-active .analiz-layout {
    display: flex !important;
    gap: 0;
}

body.analysis-active .analiz-main-content {
    flex: 1 1 100% !important;
    width: 100% !important;
    display: flex !important;
    flex-direction: column;
    min-height: 0 !important;
    overflow: hidden !important;
}

body.analysis-active .analysis-stage-panel[style*="flex"],
body.analysis-active #stage1-panel[style*="flex"],
body.analysis-active #stage2-panel[style*="flex"] {
    display: flex !important;
    flex: 1 1 0 !important;
    height: 100% !important;
    max-height: 100% !important;
}

body.analysis-active #new-panel {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    height: 100%;
    max-height: 100%;
}

body.analysis-active .analiz-container {
    display: flex;
    flex-direction: column;
}

body.analysis-active #rework-result-panel {
    flex: 1;
    min-height: 0;
}

/* Режим просмотра результата создания/переработки ВНД */
.create-result-notice {
    display: none;
}

body.create-result-view #create-result-notice {
    display: block;
    flex-shrink: 0;
    margin: 0 0 12px;
    padding: 12px 16px;
    background: #e8f4fd;
    border: 1px solid #b8daff;
    border-radius: 8px;
    color: #1a3a5c;
    font-size: 0.95rem;
    line-height: 1.5;
}

body.create-result-view #create-result-notice p {
    margin: 0;
}

body.create-result-view #create-result-notice p + p {
    margin-top: 8px;
}

body.create-result-view .create-landing,
body.create-result-view #create-shared-prep,
body.create-result-view #new-panel:not(.create-result-visible),
body.create-result-view #rework-step-form,
body.create-result-view .analiz-container > h2 {
    display: none !important;
}

body.create-result-view .analiz-content,
body.create-result-view .analiz-container {
    height: calc(100vh - 45px);
    max-height: calc(100vh - 45px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

body.create-result-view .create-panel.create-result-visible {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    margin: 0;
    height: 100%;
    max-height: 100%;
}

body.create-result-view .create-panel.create-result-visible > h3,
body.create-result-view .create-panel.create-result-visible > .stage-subtitle,
body.create-result-view .create-panel.create-result-visible .create-upload-block,
body.create-result-view .create-panel.create-result-visible .create-text-input,
body.create-result-view #create-shared-prep,
body.create-result-view #rework-progress,
body.create-result-view .create-panel.create-result-visible .create-actions,
body.create-result-view .create-panel.create-result-visible .create-step:not(#new-step-document),
body.create-result-view #new-generate-progress {
    display: none !important;
}

body.create-result-view #new-step-document {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    padding: 12px 16px;
    justify-content: flex-start;
}

body.create-result-view #new-panel.create-result-visible {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    padding: 12px 16px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body.create-result-view #new-step-document > h4:first-of-type {
    flex-shrink: 0;
    margin: 0 0 10px;
}

.new-document-step {
    flex: 1 1 0;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.create-document-preview-actions {
    flex-shrink: 0;
    margin: 0 0 12px;
}

.btn-show-document {
    min-width: 200px;
}

body.create-result-view .create-result-panel {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    margin-top: 0;
}

body.create-result-view .create-result-panel > h4 {
    flex-shrink: 0;
    margin: 0 0 10px;
}

body.create-result-view .create-result-subheading {
    flex-shrink: 0;
    margin: 12px 0 8px;
    font-size: 1rem;
    font-weight: 600;
    color: #495057;
}

body.create-result-view .create-changes-report {
    flex: 1 1 0;
    min-height: 120px;
    max-height: none;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    white-space: pre-wrap;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 12px;
    font-size: 0.9rem;
}

.create-document-body .vnd-self-fill,
.create-result-text .vnd-self-fill,
.analysis-result.create-result-text .vnd-self-fill {
    color: #c0392b;
    font-weight: 700;
}

body.create-result-view .create-result-actions,
body.create-result-view #new-step-document .stage-footer-buttons {
    flex-shrink: 0;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #e9ecef;
}

body.create-result-view #new-step-document .create-result-actions {
    margin-top: auto;
}

.create-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.create-modal[hidden] {
    display: none !important;
}

.create-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.create-modal-dialog {
    position: relative;
    background: #fff;
    border-radius: 8px;
    padding: 20px 24px;
    max-width: 420px;
    width: calc(100% - 32px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.create-modal-dialog h3 {
    margin: 0 0 10px;
    font-size: 1.1rem;
    color: #333;
}

.create-modal-text {
    margin: 0 0 18px;
    color: #555;
    line-height: 1.45;
}

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

.create-modal-dialog.create-qa-dialog {
    display: flex;
    flex-direction: column;
    max-width: 720px;
    width: calc(100% - 32px);
    max-height: calc(100vh - 48px);
    padding: 16px 20px;
}

.create-qa-dialog #create-qa-title {
    flex-shrink: 0;
    margin-bottom: 4px;
}

.create-qa-dialog .create-modal-text {
    flex-shrink: 0;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.create-qa-messages {
    display: block;
    flex: 1 1 0;
    min-height: 200px;
    max-height: 50vh;
    margin-bottom: 10px;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
}

.create-qa-input-row {
    flex-shrink: 0;
    padding: 0;
    border-top: none;
}

.create-qa-input-row textarea {
    max-height: 80px;
    font-size: 0.9rem;
}

.create-qa-footer {
    flex-shrink: 0;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e9ecef;
}

body.create-result-view .create-result-actions {
    flex-wrap: wrap;
}

/* ===== ПОМОЩНИК СОЗДАНИЯ ВНД ===== */
.create-landing {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100vh - 140px);
    max-height: calc(100vh - 140px);
    padding: 8px 0 16px;
}

.create-landing h2 {
    margin: 0 0 12px;
    font-size: 1.35rem;
    text-align: center;
}

.create-landing-instruction {
    background: #f0f7ff;
    border: 1px solid #c5ddf5;
    border-radius: 8px;
    padding: 14px 18px;
    margin: 0 0 16px;
    color: #333;
    font-size: 0.9rem;
    line-height: 1.45;
}

.create-landing-instruction p {
    margin: 0 0 8px;
}

.create-landing-instruction p:last-child {
    margin-bottom: 0;
}

.create-landing-instruction ul {
    margin: 0 0 8px;
    padding-left: 1.25rem;
}

.create-landing-instruction li {
    margin-bottom: 4px;
}

.create-landing .create-menu {
    justify-content: center;
    margin-bottom: 0;
}

.create-shared-prep {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.create-shared-prep h3 {
    margin: 0 0 8px;
}

.create-instruction-dialog {
    display: flex;
    flex-direction: column;
    max-width: min(760px, 100%);
    width: calc(100% - 32px);
    max-height: calc(100vh - 48px);
}

.create-instruction-dialog h3 {
    flex-shrink: 0;
}

.create-instruction-dialog .create-modal-actions {
    flex-shrink: 0;
    margin-top: 12px;
}

.create-instruction-body {
    color: #444;
    font-size: 0.92rem;
    line-height: 1.5;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-right: 4px;
}

.create-instruction-body p {
    margin: 0 0 10px;
}

.create-instruction-body h4 {
    margin: 1.1em 0 0.5em;
    font-size: 1rem;
    color: #2c3e50;
}

.create-instruction-body h5 {
    margin: 0.85em 0 0.4em;
    font-size: 0.94rem;
    color: #333;
}

.create-instruction-body ul,
.create-instruction-body ol {
    margin: 0 0 10px;
    padding-left: 1.35rem;
}

.create-instruction-body li {
    margin-bottom: 0.35em;
}

.create-instruction-body blockquote {
    margin: 0 0 12px;
    padding: 0.35em 0 0.35em 0.9em;
    border-left: 3px solid #17a2b8;
    color: #495057;
    background: #f8f9fa;
}

.create-instruction-body code {
    background: #f1f3f5;
    border-radius: 3px;
    padding: 0.1em 0.35em;
    font-size: 0.88em;
}

.create-document-dialog {
    display: flex;
    flex-direction: column;
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    height: calc(100vh - 24px);
    max-height: calc(100vh - 24px);
    padding: 12px 16px;
    overflow: hidden;
}

.create-document-header {
    flex-shrink: 0;
}

.create-document-header h3 {
    margin: 0 0 4px;
}

.create-document-header .create-modal-text {
    margin: 0 0 10px;
    font-size: 0.88rem;
}

.create-document-workspace {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    gap: 14px;
    overflow: hidden;
}

.create-document-panel,
.create-document-qa-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    flex: 1 1 0;
}

.create-document-panel {
    flex: 1.3 1 0;
}

.create-document-qa-panel {
    flex: 0.9 1 0;
    border-left: 1px solid #e9ecef;
    padding-left: 14px;
}

.create-document-panel h4,
.create-document-qa-panel h4 {
    flex-shrink: 0;
    margin: 0 0 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: #495057;
}

.create-document-footer {
    flex-shrink: 0;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e9ecef;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.create-document-body {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.55;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 16px;
    color: #333;
}

.create-document-qa-panel .create-qa-messages {
    flex: 1 1 0;
    min-height: 0;
    max-height: none;
    margin-bottom: 8px;
    overflow-y: auto;
}

.create-document-qa-panel .create-qa-input-row {
    flex-shrink: 0;
}

@media (max-width: 960px) {
    .create-document-workspace {
        flex-direction: column;
    }

    .create-document-qa-panel {
        flex: 0 0 38%;
        border-left: none;
        border-top: 1px solid #e9ecef;
        padding-left: 0;
        padding-top: 12px;
    }
}

.create-explanation {
    margin: 0 0 16px;
    color: #555;
    font-size: 0.95rem;
}

.create-menu {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.create-mode-btn {
    min-width: 200px;
    padding: 12px 18px !important;
    font-size: 0.9rem !important;
}

.create-panel {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Форма «Создать новый» — две колонки на весь экран */
body.create-new-active {
    overflow: hidden;
}

body.create-new-active .footer {
    display: none;
}

body.create-new-active .analiz-content {
    height: calc(100vh - 45px);
    max-height: calc(100vh - 45px);
    max-width: none;
    padding: 8px 12px;
}

body.create-new-active .analiz-container {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
}

body.create-new-active .create-landing {
    display: none;
}

body.create-rework-active {
    overflow: hidden;
}

body.create-rework-active .footer {
    display: none;
}

body.create-rework-active .analiz-content {
    height: calc(100vh - 45px);
    max-height: calc(100vh - 45px);
    max-width: none;
    padding: 8px 12px;
}

body.create-rework-active .analiz-container {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
}

body.create-rework-active #rework-panel {
    flex: 1 1 0;
    display: flex !important;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 10px 14px;
    margin: 0;
}

body.create-rework-active #rework-step-form {
    flex: 1 1 0;
    display: flex !important;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

body.create-new-active #new-panel {
    flex: 1 1 0;
    display: flex !important;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 10px 14px;
    margin: 0;
}

.new-form-step {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.new-form-header {
    flex-shrink: 0;
    margin-bottom: 8px;
}

.new-form-header h3 {
    margin: 0 0 4px;
    font-size: 1rem;
}

.new-form-header .stage-subtitle {
    margin: 0;
    font-size: 0.85rem;
}

.new-form-layout {
    flex: 1 1 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px 24px;
    min-height: 0;
    overflow: hidden;
}

.new-form-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.new-form-column .stage1-field {
    flex-shrink: 0;
}

.new-form-column .stage1-field label {
    font-size: 0.82rem;
    margin-bottom: 4px;
}

.new-form-column .stage1-field input,
.new-form-column .stage1-field select,
.new-form-column .stage1-field textarea,
.new-form-column .create-text-input {
    max-width: none;
    width: 100%;
    margin-bottom: 0;
    padding: 6px 8px;
    font-size: 0.88rem;
}

.new-form-column .stage1-hint {
    font-size: 0.78rem;
    margin-top: 4px;
}

.new-form-footer {
    flex-shrink: 0;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #e9ecef;
    background: var(--bg-color, #fff);
    position: relative;
    z-index: 2;
}

.new-form-footer .create-actions {
    margin-top: 8px;
}

.new-followup-fields {
    flex: 1 1 0;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 4px;
    padding-bottom: 24px;
    scroll-padding-bottom: 24px;
}

.new-followup-fields .stage1-field {
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.followup-nested-field {
    margin-left: 16px;
    padding-left: 12px;
    border-left: 2px solid #dee2e6;
}

.new-followup-fields .stage1-field label {
    font-size: 0.85rem;
}

.new-followup-option {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 4px 0;
    font-size: 0.88rem;
}

.new-followup-option input {
    margin-top: 3px;
}

body.create-new-active #new-step-followup {
    flex: 1 1 0;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#new-followup-error,
#new-analyze-progress-followup {
    flex-shrink: 0;
}

@media (max-width: 900px) {
    body.create-new-active .analiz-content {
        height: auto;
        max-height: none;
        overflow: auto;
    }

    body.create-new-active {
        overflow: auto;
    }

    body.create-new-active .footer {
        display: block;
    }

    .new-form-layout {
        grid-template-columns: 1fr;
        overflow-y: auto;
    }

    .new-form-column {
        overflow: visible;
    }
}

.create-prompt-info {
    margin: 0 0 16px;
    padding: 10px 12px;
    background: #f0f7ff;
    border: 1px solid #cce5ff;
    border-radius: 6px;
    font-size: 0.88rem;
    color: #333;
}

.create-prompt-info summary {
    cursor: pointer;
    font-weight: 600;
    color: #1a5276;
}

.create-prompt-body {
    margin-top: 10px;
    line-height: 1.5;
}

.create-prompt-body p {
    margin: 0 0 8px;
}

.create-upload-block {
    margin-bottom: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
}

.create-upload-block label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}

.create-upload-block input[type="file"] {
    margin-bottom: 8px;
}

.upload-status {
    margin-top: 8px;
    font-size: 0.85rem;
    color: #666;
}

.upload-status.success {
    color: #155724;
}

.upload-status.error {
    color: #721c24;
}

.upload-status.warning {
    color: #856404;
}

.create-analysis-none-option {
    margin: 8px 0 10px;
}

.create-text-input {
    width: 100%;
    max-width: 480px;
    padding: 8px 10px;
    margin-bottom: 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.create-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.create-step textarea {
    width: 100%;
    max-width: 640px;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95rem;
    resize: vertical;
}

.create-result-panel {
    margin-top: 20px;
}

.create-result-panel .analysis-result:not(.create-result-text) {
    max-height: 50vh;
}

/* ===== ПОИСК В ВНД ===== */
.search-content {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    width: 100%;
    overflow: hidden;
}

.search-page-container {
    background: white;
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.search-page-container h2 {
    font-size: 1.2rem;
    color: #333;
    margin-bottom: 12px;
}

.search-container {
    gap: 12px;
}

.search-form {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-form textarea {
    width: 100%;
    resize: vertical;
    min-height: 90px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    font-size: 0.9rem;
}

.search-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.search-actions input {
    width: 90px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.search-status {
    min-height: 20px;
    color: #333;
    font-size: 0.9rem;
}

.search-status.error {
    color: #dc3545;
}

.search-results {
    flex: 1;
    overflow-y: auto;
    max-height: none;
    padding-right: 4px;
}

.search-result-item {
    background: #fff;
    border: 1px solid #e9ecef;
    border-left: 4px solid #007bff;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.search-result-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.search-score {
    color: #666;
    font-size: 0.8rem;
}

.search-result-text {
    color: #222;
    font-size: 0.88rem;
    line-height: 1.45;
    margin-bottom: 6px;
}

.search-result-source {
    color: #666;
    font-size: 0.76rem;
    word-break: break-all;
}

.search-empty {
    color: #666;
    font-size: 0.9rem;
}

/* Диалог «Поиск в ВНД» */
.search-intro {
    color: #555;
    font-size: 0.92rem;
    margin-bottom: 14px;
    line-height: 1.45;
}

.search-setup-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-source-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.search-source-card {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-source-card h3 {
    margin: 0;
    font-size: 1rem;
    color: #333;
}

.search-source-card input[type="file"] {
    font-size: 0.85rem;
}

.search-source-card label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #495057;
}

.search-chat-box.search-chat-inactive {
    opacity: 0.72;
    border-color: #d0d7de;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.search-chat-inactive .search-chat-header {
    background: #f1f3f5;
}

.search-chat-inactive .search-chat-messages {
    background: #eef1f4;
}

.search-chat-inactive .search-chat-input-row {
    background: #e9ecef;
    border-color: #ced4da;
}

.search-chat-inactive .search-chat-input-row textarea:disabled,
.search-chat-inactive .search-chat-input-row .btn-primary:disabled {
    cursor: not-allowed;
    opacity: 0.75;
}

body:not(.search-dialog-active) .search-chat-panel {
    margin-top: 14px;
    min-height: 260px;
}

body:not(.search-dialog-active) .search-page-container {
    display: flex;
    flex-direction: column;
}

.search-chat-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    gap: 10px;
}

.search-chat-box {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    background: #fff;
    border: 2px solid #c5d9f0;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(26, 58, 92, 0.09);
    overflow: hidden;
}

.search-reselect-hint {
    margin: 0 0 6px;
    padding: 5px 10px;
    font-size: 0.78rem;
    color: #868e96;
    background: #f8f9fa;
    border-radius: 4px;
    border-left: 3px solid #ced4da;
    line-height: 1.35;
}

.search-setup-locked .search-source-grid {
    gap: 8px;
    pointer-events: none;
}

.search-setup-locked .search-source-card {
    padding: 8px 10px;
    gap: 5px;
    background: #eef1f4;
    border-color: #dde2e6;
    opacity: 0.7;
}

.search-setup-locked .search-source-card h3 {
    font-size: 0.82rem;
    color: #6c757d;
    margin: 0;
}

.search-setup-locked .stage-subtitle,
.search-setup-locked .stage1-hint {
    display: none;
}

.search-setup-locked label {
    font-size: 0.74rem;
    color: #868e96;
    margin: 0;
}

.search-setup-locked input,
.search-setup-locked select,
.search-setup-locked button {
    font-size: 0.76rem;
    opacity: 0.85;
    cursor: not-allowed;
}

.search-setup-locked .upload-status {
    font-size: 0.74rem;
    max-height: 2.2em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.search-chat-header {
    flex-shrink: 0;
    padding: 10px 12px 8px;
    background: linear-gradient(180deg, #f0f6fc 0%, #fff 100%);
    border-bottom: 1px solid #e3ecf5;
}

.search-doc-title {
    margin: 0;
    font-size: 0.92rem;
    color: #495057;
    font-weight: 600;
}

.search-analysis-title {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: #0c5460;
}

.search-chat-messages {
    flex: 1 1 0;
    min-height: 0;
    border: none;
    border-radius: 0;
    background-color: #f8f9fa;
}

.search-chat-input-row {
    flex-shrink: 0;
    margin: 0 10px 10px;
    padding: 10px 12px;
    gap: 10px;
    background: #e8f2fb;
    border: 2px solid #9ec5eb;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(26, 58, 92, 0.08);
}

.search-chat-input-row textarea {
    max-height: 88px;
    min-height: 44px;
    padding: 10px 12px;
    font-size: 0.9rem;
    line-height: 1.4;
    background: #fff;
    border: 2px solid #7eb3e8;
    border-radius: 6px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

.search-chat-input-row textarea::placeholder {
    color: #6c8fad;
}

.search-chat-input-row textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.18);
}

.search-chat-input-row .btn-primary {
    align-self: flex-end;
    min-width: 108px;
    padding: 10px 14px;
    font-weight: 600;
}

.search-chat-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 10px 0 2px;
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid #e9ecef;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.04);
}

body.search-dialog-active {
    overflow: hidden;
}

body.search-dialog-active .footer {
    display: none;
}

body.search-dialog-active .search-content {
    height: calc(100vh - 45px);
    max-height: calc(100vh - 45px);
    overflow: hidden;
    padding: 10px 16px 12px;
}

body.search-dialog-active .search-page-container {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

body.search-dialog-active .search-page-container > h2,
body.search-dialog-active .search-intro {
    display: none;
}

body.search-dialog-active .search-setup-panel {
    flex-shrink: 0;
}

body.search-dialog-active .search-chat-panel {
    display: flex !important;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

body.search-dialog-active .search-chat-box {
    flex: 1 1 0;
    min-height: 0;
}

body.search-dialog-active .search-chat-messages {
    flex: 1 1 0;
    min-height: 0;
    height: auto;
    max-height: none;
}

body.search-dialog-active .search-chat-footer {
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .search-source-grid {
        grid-template-columns: 1fr;
    }

    body.search-dialog-active .search-setup-locked .search-source-grid {
        grid-template-columns: 1fr 1fr;
    }

    .search-chat-footer {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ===== Панель федеральных ссылок ===== */
.federal-refs-panel {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 24px;
    margin: 20px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.federal-refs-content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.federal-refs-content h3 {
    color: #1a3a5c;
    margin-bottom: 12px;
    font-size: 1.2rem;
}

.federal-refs-subtitle {
    color: #555;
    margin-bottom: 16px;
}

.federal-refs-list {
    list-style: decimal;
    padding-left: 24px;
    margin-bottom: 16px;
    max-height: min(280px, 40vh);
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 80px;
}

.federal-refs-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    flex-shrink: 0;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid #e9ecef;
    position: sticky;
    bottom: 0;
    background: #fff;
    z-index: 2;
}

.federal-refs-actions .btn-primary,
.federal-refs-actions .btn-success,
.federal-refs-actions .btn-secondary,
.federal-refs-actions .btn-danger {
    padding: 10px 18px;
    font-size: 0.85rem;
}

body.federal-refs-active .analiz-landing {
    display: none !important;
}

body.federal-refs-active .analiz-content,
body.federal-refs-active .analiz-container,
body.federal-refs-active .analiz-layout,
body.federal-refs-active .analiz-main-content {
    overflow: auto !important;
    max-height: none !important;
    height: auto !important;
}

body.federal-refs-active .analiz-main-content {
    flex: 1 1 100% !important;
    width: 100% !important;
}

.federal-refs-list li {
    margin-bottom: 10px;
    color: #333;
    line-height: 1.4;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.federal-ref-title {
    flex: 1 1 260px;
}

.federal-ref-variants {
    color: #666;
    font-size: 0.85em;
    font-weight: normal;
}

.federal-ref-status {
    font-size: 0.82rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.federal-ref-status.found {
    background: #d4edda;
    color: #155724;
}

.federal-ref-status.missing {
    background: #f8d7da;
    color: #721c24;
}

.federal-refs-status {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-weight: 500;
    white-space: pre-wrap;
}

.federal-refs-status.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.federal-refs-status.partial {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.federal-refs-status.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.federal-refs-status.info {
    background: #e7f1ff;
    color: #0c5460;
    border: 1px solid #b8daff;
}

.federal-refs-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.federal-refs-buttons .btn-primary,
.federal-refs-buttons .btn-success,
.federal-refs-buttons .btn-secondary,
.federal-refs-buttons .btn-danger {
    padding: 10px 18px;
    font-size: 0.85rem;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background-color: #545b62;
}

/* ===== АУТЕНТИФИКАЦИЯ ===== */
.auth-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-auth {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 0.85rem;
    text-decoration: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s;
}

.btn-auth-login {
    background-color: #28a745;
    color: white;
}

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

.btn-auth-register {
    background-color: #17a2b8;
    color: white;
}

.btn-auth-register:hover {
    background-color: #138496;
}

.btn-auth-logout {
    background-color: #dc3545;
    color: white;
}

.btn-auth-logout:hover {
    background-color: #c82333;
}

.auth-user-label {
    color: #fff;
    font-size: 0.85rem;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-user-link {
    text-decoration: none;
    border-bottom: 1px dotted rgba(255, 255, 255, 0.7);
    cursor: pointer;
}

.auth-user-link:hover {
    color: #fff;
    border-bottom-style: solid;
}

body.auth-page {
    overflow: auto;
}

.auth-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    overflow: auto;
}

.auth-card {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    padding: 28px 24px;
}

.auth-card h2 {
    margin-bottom: 8px;
    font-size: 1.4rem;
    color: #333;
}

.auth-subtitle {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 20px;
    line-height: 1.4;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-form label {
    font-size: 0.85rem;
    color: #444;
    margin-top: 4px;
}

.auth-form input {
    padding: 10px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.95rem;
}

.auth-form input:focus {
    outline: none;
    border-color: #17a2b8;
    box-shadow: 0 0 0 2px rgba(23, 162, 184, 0.15);
}

.auth-hint {
    color: #888;
    font-weight: normal;
    font-size: 0.8rem;
}

.auth-recaptcha-note {
    font-size: 0.75rem;
    color: #888;
    line-height: 1.4;
    margin: 4px 0 0;
}

.auth-recaptcha-note a {
    color: #555;
}

.auth-submit {
    margin-top: 12px;
    width: 100%;
    padding: 10px 16px;
    font-size: 0.95rem;
}

.auth-message {
    padding: 10px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.auth-message-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.auth-message-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.auth-links {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    font-size: 0.85rem;
    color: #666;
}

.auth-links a {
    color: #17a2b8;
    text-decoration: none;
}

.auth-links a:hover {
    text-decoration: underline;
}

/* ===== КАБИНЕТ АДМИНИСТРАТОРА ===== */
body.admin-page {
    overflow: auto;
}

.admin-layout {
    flex: 1;
    display: flex;
    min-height: 0;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.admin-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #dee2e6;
    padding: 20px 12px;
}

.admin-sidebar-title {
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    padding: 0 8px 16px;
}

.admin-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.admin-nav-item {
    text-align: left;
    background: transparent;
    border: none;
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 0.95rem;
    color: #444;
    cursor: pointer;
}

.admin-nav-item:hover {
    background: #f1f3f5;
}

.admin-nav-item.is-active {
    background: #e9ecef;
    color: #212529;
    font-weight: 600;
}

.admin-content {
    flex: 1;
    padding: 24px 28px;
    overflow: auto;
}

.admin-content h2 {
    font-size: 1.4rem;
    color: #333;
    margin-bottom: 8px;
}

.admin-section-lead {
    color: #666;
    font-size: 0.95rem;
    margin-bottom: 20px;
}

.admin-setting-card {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.admin-setting-title {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    cursor: pointer;
}

.admin-setting-desc {
    margin-top: 6px;
    font-size: 0.85rem;
    color: #666;
    line-height: 1.45;
    max-width: 520px;
}

.admin-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.admin-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.admin-switch-slider {
    position: absolute;
    inset: 0;
    background: #ced4da;
    border-radius: 26px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.admin-switch-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.admin-switch input:checked + .admin-switch-slider {
    background: #28a745;
}

.admin-switch input:checked + .admin-switch-slider::before {
    transform: translateX(22px);
}

.admin-switch input:disabled + .admin-switch-slider {
    opacity: 0.6;
    cursor: default;
}

.admin-content .auth-message {
    margin-bottom: 16px;
}

@media (max-width: 720px) {
    .admin-layout {
        flex-direction: column;
    }

    .admin-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #dee2e6;
    }

    .admin-setting-card {
        flex-direction: column;
        align-items: flex-start;
    }
}
