/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark theme (default) */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-card: #161b22;
    --bg-hover: #1f2937;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #8b949e;  /* U14: >=4.5:1 к bg-primary — контраст AA */
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --accent-bg: rgba(88, 166, 255, 0.1);
    --on-accent: #0d1117;  /* U14: тёмный текст на accent = 7.5:1 против светлого 2.3:1 */
    --border-color: #30363d;
    --border-light: #21262d;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.6);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-doc: Georgia, 'Times New Roman', serif;
}

body.theme-light {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #eaeef2;
    --bg-card: #ffffff;
    --bg-hover: #f0f3f6;
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-muted: #57606a;  /* U14: приглушённый на белом */
    --accent: #0969da;
    --accent-hover: #0550ae;
    --accent-bg: rgba(9, 105, 218, 0.08);
    --on-accent: #ffffff;
    --border-color: #d0d7de;
    --border-light: #e8ecf0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.15);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition), color var(--transition);
}

.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 16px;
}

a {
    text-decoration: none;
    color: inherit;
}

/* ===== HEADER ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: box-shadow var(--transition), background-color var(--transition);
}

.header.scrolled {
    box-shadow: var(--shadow-md);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.logo-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #58a6ff, #a371f7);
    color: #fff;
    font-weight: 800;
    font-size: 19px;
    box-shadow: 0 2px 10px rgba(88, 166, 255, .35);
    flex-shrink: 0;
}

.nav {
    display: none;
    gap: 4px;
}

.nav-link {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
}

.nav-link.active {
    color: var(--accent);
    background-color: var(--accent-bg);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
    transform: scale(1.05);
}

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

body.theme-light .theme-toggle .icon-sun { display: block; }
body.theme-light .theme-toggle .icon-moon { display: none; }

/* ===== SEARCH SECTION ===== */
.search-section {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 24px 0 20px;
    margin-bottom: 28px;
}

.search-container {
    margin-bottom: 16px;
}

.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 0 8px 0 16px;
    transition: all var(--transition);
    gap: 8px;
}

.search-bar:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}
.search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 14px 8px;
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
    font-family: var(--font-ui);
}

.btn-search-clear {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    padding: 6px 9px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition);
}

.btn-search-clear:hover {
    color: #f85149;
    background: rgba(248, 81, 73, 0.12);
}

body.theme-light .btn-search-clear:hover {
    color: #cf222e;
    background: rgba(207, 34, 46, 0.1);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.btn-search {
    padding: 10px 24px;
    background: linear-gradient(135deg, var(--accent), #388bfd);
    color: var(--on-accent);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-search:hover {
    background: linear-gradient(135deg, var(--accent-hover), var(--accent));
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-search:active {
    transform: translateY(0);
}

/* ===== FILTERS ===== */
.filters-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.filters-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 4px;
}

.filter-btn {
    padding: 6px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

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

.filter-btn.active {
    background: var(--accent-bg);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

/* ===== STATUS BAR ===== */
.status-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

.status-bar.visible {
    display: flex;
}

.status-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.status-count {
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* ===== DOCUMENTS GRID ===== */
.documents-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 32px;
}

.doc-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.doc-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--accent);
    transform: scaleY(0);
    transition: transform var(--transition);
}

.doc-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.doc-card:hover::before {
    transform: scaleY(1);
}

.doc-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.doc-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.35;
    flex: 1;
}

.doc-card-header:hover .doc-card-title {
    color: var(--accent);
}

.doc-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.doc-number, .doc-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 3px 10px;
    border-radius: var(--radius-sm);
}

.doc-category-badge, .doc-status-badge {
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500;
}

.doc-category-badge {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent);
}

.doc-status-badge {
    background: rgba(63, 185, 80, 0.1);
    color: #3fb950;
}

/* U16: бейджи статусов — семантический цвет */
.doc-status-badge.st-invalid,
.doc-status-badge.st-expired {
    background: rgba(248, 81, 73, 0.12);
    color: #f85149;
}
.doc-status-badge.st-draft {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}
body.theme-light .doc-status-badge.st-invalid,
body.theme-light .doc-status-badge.st-expired {
    background: rgba(207, 34, 46, 0.1);
    color: #cf222e;
}

.doc-card-snippet {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.doc-card-snippet mark {
    background: rgba(88, 166, 255, 0.2);
    color: var(--accent);
    padding: 1px 2px;
    border-radius: 2px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state svg {
    opacity: 0.4;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.2rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.9rem;
}

/* ===== PAGINATION ===== */
.pagination {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 24px 0;
}

.pagination.visible {
    display: flex;
}

.page-btn {
    min-width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    padding: 0 8px;
}

.page-btn:hover:not(.active):not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}

.page-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-ellipsis {
    color: var(--text-muted);
    padding: 0 4px;
}

/* ===== LOADING SPINNER ===== */
.loading-spinner {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 12px;
    color: var(--text-secondary);
}

.loading-spinner.visible {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-sm {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

/* ===== OVERLAY (Document Viewer) ===== */
.overlay {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    visibility: hidden;
}

.overlay.open {
    pointer-events: auto;
    opacity: 1;
    visibility: visible;
}

.overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.overlay-content {
    position: absolute;
    top: 0;
    right: -100%;
    width: min(920px, 100% - 32px);  /* ширина диалога: учитываем скроллбар */
    height: 100%;
    background: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
    overflow: hidden;
}

.overlay.open .overlay-content {
    right: 0;
}

#docOverlay #closeDocOverlay {
    position: absolute;
    top: 14px;
    right: 16px;
    z-index: 20;
}

.overlay-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.doc-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.4;
}

.doc-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.overlay-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.doc-body-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.doc-body-content {
    padding: 24px;
    font-family: var(--font-doc);
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.doc-body-content mark {
    background: rgba(88, 166, 255, 0.3);
    padding: 1px 3px;
    border-radius: 2px;
}

.find-in-page {
    display: none;
    padding: 8px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.find-in-page.visible {
    display: flex;
}

.find-in-page span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.find-input {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    flex: 0 1 200px;
}

.find-input:focus {
    border-color: var(--accent);
}

.btn-find, .btn-find-nav {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition);
}

.btn-find:hover, .btn-find-nav:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.find-counter {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== RELATED (похожие документы из категории) ===== */
.overlay-actions-row {
    position: relative;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 4px;
}

.related-section {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 30;
    margin-top: 6px;
    padding: 14px 16px;
    max-height: min(46vh, 360px);
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.related-section.open {
    display: block;
}

.related-section h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.related-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.related-item {
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.related-item:hover {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.related-item-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.related-item-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== MODAL (Export) ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.modal.open {
    display: flex;
    pointer-events: auto;
    opacity: 1;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.55);
}

.modal-dialog {
    position: relative;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: min(460px, calc(100% - 32px));
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { transform: translateY(20px) scale(0.97); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.05rem;
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

#exportDocTitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.format-options {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.format-option {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.format-option:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.format-option input[type="radio"] {
    accent-color: var(--accent);
}

.export-status, .export-result {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* U22: на мобиле скрываем .btn-export — дублирует .btn-primary */
.btn-primary {
    background: var(--accent);
    color: var(--on-accent);
    border: none;
    border-radius: 8px;
    padding: 11px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary:hover { filter: brightness(1.1); }

.btn-primary:disabled { opacity: .55; cursor: default; filter: none; }

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 24px;
    background: linear-gradient(135deg, #3fb950, #2ea043);
    color: #0d1117;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all var(--transition);
}

.btn-download:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ===== BUTTON CLOSE ===== */
.btn-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    line-height: 1;
}

.btn-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ===== FOOTER ===== */
.footer {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding: 24px 0;
    background: var(--bg-secondary);
}

.footer-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    text-align: center;
}

.footer p {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ===== RESPONSIVE ===== */
@media (min-width: 640px) {
    .container { padding: 0 24px; }
    .search-bar { padding: 0 12px 0 20px; }
    .documents-grid { grid-template-columns: repeat(2, 1fr); gap: 20px; }
    .doc-card { padding: 24px 28px; }
}

@media (min-width: 960px) {
    .nav { display: flex; }
    .documents-grid { grid-template-columns: repeat(3, 1fr); gap: 24px; }
    .search-bar { padding: 0 16px 0 24px; }
}

@media (min-width: 1280px) {
    .container { max-width: 1320px; padding: 0 32px; }
}

@media (max-width: 639px) {
    .doc-card-header { flex-direction: column; }
    .filter-btn { font-size: 0.75rem; padding: 5px 10px; min-height: 40px; }  /* U24 */
    .tool-input { min-height: 40px; }
    .btn-search, .btn-login { min-height: 40px; }
    .overlay-content { width: calc(100% - 56px); right: -100%; }
    .doc-body-content { padding: 16px; font-size: 0.92rem; }
}

@media (max-width: 959px) {
    .header-inner { flex-wrap: wrap; height: auto; padding: 10px 0; row-gap: 8px; }
    .nav { display: flex; order: 3; width: 100%; overflow-x: auto; }
}

/* Карточки не прѝчутѝѝ под sticky-хедер при лиѝтании */
.doc-card, .results-container { scroll-margin-top: 76px; }

/* Подѝказка под iframe-превью */
.preview-hint { margin: 0 0 8px; font-size: 12px; color: var(--text-muted); }

/* Мобильные фильтры — горизонтальный ѝкролл вмеѝто переноѝа */
@media (max-width: 639px) {
    .filters-bar { flex-wrap: nowrap; overflow-x: auto; }
}

/* Печать: только ѝодержимое открытого документа */
@media print {
    .header, .search-section, .footer, .pagination, .user-box, .theme-toggle,
    .nav, .find-in-page, .loading-spinner, .empty-state, .documents-grid,
    .doc-preview-section, .related-section { display: none !important; }
    body { background: #fff !important; color: #000 !important; }
    .overlay { position: static !important; display: none !important; background: none !important; }
    .overlay.open { display: block !important; }
    .overlay-content {
        position: static !important; width: 100% !important; height: auto !important;
        right: 0 !important; box-shadow: none !important; border: none !important;
    }
    .doc-title, .doc-body-content, .doc-meta, .doc-meta span { color: #000 !important; }
}

/* ===== SCROLLBAR ===== */
.doc-body-scroll::-webkit-scrollbar,
.related-section::-webkit-scrollbar,
.overlay-content::-webkit-scrollbar {
    width: 6px;
}

.doc-body-scroll::-webkit-scrollbar-track,
.related-section::-webkit-scrollbar-track {
    background: transparent;
}

.doc-body-scroll::-webkit-scrollbar-thumb,
.related-section::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.doc-body-scroll::-webkit-scrollbar-thumb:hover,
.related-section::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== TRANSITIONS FOR CARDS ===== */
.documents-grid .doc-card {
    animation: fadeInUp 0.3s ease both;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== SELECTION ===== */
::selection {
    background: var(--accent);
    color: #fff;
}

/* ===== CATEGORY CARDS ===== */
.category-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.category-card:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}
.category-card-name { font-weight: 600; }
.category-card-count { color: var(--text-secondary); font-size: 13px; white-space: nowrap; }

/* ===== Source links (ѝѝылочнаѝ модель ѝтатей) ===== */
.doc-src-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 16px;
    margin-left: 8px;
    flex-shrink: 0;
}
.doc-src-link:hover { text-decoration: underline; }
.doc-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.btn-source {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    color: var(--accent) !important;
    border-color: var(--accent) !important;
}
.doc-ref-note { color: var(--text-secondary); font-style: italic; margin-bottom: 12px; }
.doc-src-big { font-size: 15px; margin-left: 0; display: inline-block; }
.doc-card-src { margin-top: 10px; }
.doc-card-src a {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    color: var(--accent);
    font-size: 12px;
    text-decoration: none;
}
.doc-card-src a:hover { text-decoration: underline; }

/* ===== Предпроѝмотр ѝодержимого иѝточника во вьювере ===== */
.doc-preview-section {
    margin: 18px 24px 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 14px;
}
.doc-preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.doc-preview-head h3 { margin: 0; font-size: 16px; }
.doc-preview-head a { color: var(--accent); font-size: 13px; text-decoration: none; white-space: nowrap; }
.doc-preview-head a:hover { text-decoration: underline; }
.doc-preview-frame {
    width: 100%;
    flex: 1 1 auto;
    height: auto;
    min-height: 320px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: #fff;
}
#docOverlay.preview-open .doc-preview-section {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
#docOverlay.preview-open .doc-body-scroll { display: none; }

/* ===== Режимы вьювера «Текст | Предпросмотр источника» (U15) ===== */
.viewer-tabs { display: flex; gap: 6px; margin-top: 4px; }
.viewer-tabs .filter-btn { padding: 4px 12px; font-size: 0.78rem; }
.overlay-content:focus { outline: none; }

/* ===== Единая surface-панель сообщений (U13) ===== */
.export-error {
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(248, 81, 73, 0.12);
    border-left: 3px solid #f85149;
    border-radius: var(--radius-sm);
    color: #f85149;
    font-size: 0.88rem;
    white-space: pre-wrap;
}
body.theme-light .export-error {
    background: rgba(207, 34, 46, 0.08);
    color: #cf222e;
    border-left-color: #cf222e;
}

/* ===== Skip-link (U25) ===== */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 2000;
    background: var(--accent);
    color: var(--on-accent);
    padding: 10px 18px;
    border-radius: 0 0 8px 0;
    font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ===== Нвторизациѝ: кнопка, чип, карточка пользователѝ ===== */
body.auth-locked .header,
body.auth-locked .search-section,
body.auth-locked main,
body.auth-locked footer { display: none !important; }

.user-box { position: relative; display: flex; align-items: center; margin-left: 12px; }
.btn-login {
    background: var(--accent);
    color: var(--on-accent);
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
}
.btn-login:hover { filter: brightness(1.1); }

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 5px 10px 5px 5px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-card);
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.user-chip:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, .12);
    transform: translateY(-1px);
}
.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #58a6ff 0%, #a371f7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2), 0 2px 8px rgba(88, 166, 255, .35);
}
.user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.user-chevron { font-size: 10px; color: var(--text-secondary); }

.user-card {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 1200;
    min-width: 240px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
    animation: cardIn .15s ease-out;
}
@keyframes cardIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}
.user-card-head { display: flex; align-items: center; gap: 10px; }
.user-card-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #58a6ff 0%, #a371f7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.user-card-name { font-weight: 700; font-size: 15px; word-break: break-all; }
.user-card-role {
    display: inline-block;
    margin-top: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(88, 166, 255, .12);
    color: var(--accent);
}
.user-card-actions {
    display: flex;
    gap: 14px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    align-items: center;
}
.user-card-actions a, .user-card-actions button {
    font-size: 13px;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: none;
    padding: 0;
}
.user-card-actions button { color: #f85149; }

.login-dialog { max-width: 400px; }
.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 4px 0 10px;
}
.auth-logo .logo-badge { color: #fff; }
.auth-body { display: flex; flex-direction: column; gap: 10px; }
.auth-input {
    width: 100%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
}
.auth-input:focus { outline: none; border-color: var(--accent); }
.auth-error { color: #f85149; font-size: 13px; min-height: 16px; }
.auth-submit {
    background: var(--accent);
    color: var(--on-accent);
    border: none;
    border-radius: 8px;
    padding: 11px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.auth-submit:hover { filter: brightness(1.1); }
.auth-hint { font-size: 12px; color: var(--text-secondary); margin: 4px 0 0; text-align: center; }

/* ===== Светлаѝ тема: контраѝт ѝтатуѝов и ошибок ===== */
body.theme-light .doc-status-badge { color: #1a7f37; background: rgba(26, 127, 55, 0.12); }
body.theme-light .user-card-actions button { color: #cf222e; }
body.theme-light .auth-error { color: #cf222e; }
body.theme-light .doc-card-snippet mark { background: rgba(9, 105, 218, 0.15); }

/* ===== Фокуѝ длѝ клавиатуры ===== */
.doc-card:focus-visible, .related-item:focus-visible, .user-chip:focus-visible,
.nav-link:focus-visible, .filter-btn:focus-visible, .page-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Панель периода/сортировки (Fn3) */
.tool-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.tool-input {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
}
.tool-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tool-dash { color: var(--text-muted); }
@media (max-width: 639px) {
    .tool-bar { flex-wrap: nowrap; overflow-x: auto; }
}
