/* === Стили === */

:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --radius: 8px;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

.hidden { display: none !important; }

/* === Экран входа === */
.login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-card {
    background: var(--bg-secondary);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
    width: 380px;
}

.login-logo { font-size: 64px; margin-bottom: 16px; }
.login-card h1 { font-size: 1.8em; margin-bottom: 8px; }
.login-card p { color: var(--text-secondary); margin-bottom: 24px; }
.login-card input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    cursor: pointer;
    font-weight: 600;
}
.login-card button:hover { background: var(--accent-hover); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* === Шапка === */
.header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon { font-size: 24px; }

.header-title {
    font-size: 1.1em;
    white-space: nowrap;
}

/* Навигация по центру */
.nav-center {
    display: flex;
    justify-content: center;
    gap: 4px;
    overflow-x: auto;
}

.nav-btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    transition: all 0.2s;
}
.nav-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-btn.active { background: var(--accent); color: white; }
/* Роли пользователей */
.editor-only, .admin-only { display: none !important; }
body.role-admin .admin-only { display: block !important; }
body.role-admin .editor-only { display: block !important; }
body.role-editor .editor-only { display: block !important; }
body.role-admin .nav-btn.admin-only,
body.role-admin .nav-btn.editor-only,
body.role-editor .nav-btn.editor-only { display: inline-flex !important; }

/* Правая часть шапки */
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-stats {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-pill {
    font-size: 13px;
    padding: 3px 10px;
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    white-space: nowrap;
    border: 1px solid var(--border);
}
.stat-pill.stat-expired {
    background: #fef2f2;
    color: var(--danger);
    border-color: #fecaca;
}
[data-theme="dark"] .stat-pill.stat-expired {
    background: #451a1a;
    border-color: #7f1d1d;
}

.notification-bell {
    position: relative;
    cursor: pointer;
    font-size: 1.2em;
    padding: 4px 8px;
}

.badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 700;
}

/* Меню пользователя */
.user-menu { position: relative; }

.user-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.user-btn:hover { background: var(--border); }

.user-avatar { font-size: 16px; }

.user-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.user-menu.open .user-arrow { transform: rotate(180deg); }

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 180px;
    z-index: 200;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.dropdown-item:hover { background: var(--bg-tertiary); }
.dropdown-item.danger { color: var(--danger); }

/* Панель уведомлений */
.notification-panel {
    position: fixed;
    top: 56px;
    right: 24px;
    width: 380px;
    max-height: 80vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 200;
    overflow-y: auto;
}

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

.notification-list { padding: 8px; }

.notif-panel-empty { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.notif-panel-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: default;
    transition: background 0.15s;
}
.notif-panel-item:hover { background: var(--bg-tertiary); }
.notif-panel-item.read { opacity: 0.5; }
.notif-panel-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.notif-panel-text { flex: 1; min-width: 0; }
.notif-panel-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-panel-time { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.notif-panel-message { font-size: 12px; color: var(--text-secondary); margin-top: 4px; line-height: 1.4; }

/* Справка */
.help-bell {
    position: relative;
    cursor: pointer;
    font-size: 1.2em;
    padding: 4px 8px;
}
.help-panel {
    position: fixed;
    top: 56px;
    right: 24px;
    width: 500px;
    max-height: 80vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 200;
    overflow-y: auto;
}
.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.help-header h3 { margin: 0; }
.help-content {
    padding: 16px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}
.help-content h2 { font-size: 18px; margin: 16px 0 8px; }
.help-content h3 { font-size: 16px; margin: 12px 0 6px; }
.help-content h4 { font-size: 14px; margin: 8px 0 4px; }

/* Профиль */
.profile-form { display: flex; flex-direction: column; gap: 16px; }
.profile-form label { display: block; margin-bottom: 10px; font-size: 14px; color: var(--text-secondary); }
.profile-form input[type="text"],
.profile-form input[type="email"] { width: 100%; max-width: 400px; }
.notif-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.notif-toggle input[type="checkbox"] { width: 16px; height: 16px; }
.notif-toggle span { font-size: 14px; color: var(--text-primary); }
.profile-notif-settings { display: flex; flex-direction: column; gap: 12px; }

/* SMTP */
#smtp-settings label { display: block; margin-bottom: 10px; font-size: 14px; color: var(--text-secondary); }
#smtp-settings input[type="text"],
#smtp-settings input[type="email"],
#smtp-settings input[type="password"],
#smtp-settings input[type="number"] { width: 100%; max-width: 400px; }
.smtp-actions { display: flex; gap: 8px; margin-top: 8px; }
.smtp-test-result { margin-top: 8px; font-size: 13px; }

.notification-item {
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 4px;
    cursor: pointer;
    transition: background 0.2s;
}
.notification-item:hover { background: var(--bg-tertiary); }
.notification-item.unread { border-left: 3px solid var(--accent); }
.notification-item .title { font-weight: 600; font-size: 14px; }
.notification-item .message { font-size: 13px; color: var(--text-secondary); }
.notification-item .time { font-size: 11px; color: var(--text-muted); }

.small-btn {
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    cursor: pointer;
    color: var(--text-primary);
}

/* Основной контент */
.main-content {
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Чат */
.chat-container {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
    height: calc(100vh - 200px);
}

.chat-sidebar {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.chat-sidebar h3 { margin-bottom: 12px; font-size: 14px; }
.chat-sidebar label { font-size: 12px; color: var(--text-secondary); display: block; margin-top: 8px; }
.chat-sidebar select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    margin-top: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.alpha-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.alpha-slider input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 3px;
    outline: none;
}

.alpha-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-primary);
}

#chat-alpha-val {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    min-width: 24px;
    text-align: center;
}

.alpha-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.chat-main {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: var(--radius);
    max-width: 85%;
}
.message.user {
    background: var(--accent);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.message.assistant {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.msg-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    opacity: 0.7;
}
.message.user .msg-label { color: rgba(255,255,255,0.8); }
.message.assistant .msg-label { color: var(--text-muted); }
.msg-body { line-height: 1.5; }
.message .sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.1);
    font-size: 12px;
    opacity: 0.8;
}

.message.assistant .sources { opacity: 1; }

.thinking-pulse {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}
.thinking-pulse .dots {
    display: inline-flex;
    gap: 4px;
}
.thinking-pulse .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    animation: dot-bounce 1.2s ease-in-out infinite;
}
.thinking-pulse .dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-pulse .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.3; }
    40% { transform: translateY(-8px); opacity: 1; }
}

.sources-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 12px;
}

.sources-table th,
.sources-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.sources-table th {
    font-weight: 600;
    background: rgba(0,0,0,0.05);
}

.sources-table .doc-download-btn {
    padding: 2px 6px;
    font-size: 11px;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.chat-input-area textarea {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: none;
    font-size: 14px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.send-btn {
    padding: 10px 24px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
}
.send-btn:hover { background: var(--accent-hover); }

.stop-btn {
    padding: 10px 24px;
    background: #f59e0b;
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}
.stop-btn:hover { background: #d97706; }

/* Таблица документов */
.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar input, .toolbar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.refresh-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    transition: all 0.2s;
}
.refresh-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.refresh-btn.loading { opacity: 0.6; pointer-events: none; }

.scanner-status {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}
.scanner-status .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
}
.scanner-status .dot.scanning {
    background: #f59e0b;
    animation: pulse 1s infinite;
}
.scanner-status .dot.ok { background: var(--success); }
.scanner-status .scan-new { color: var(--success); font-weight: 600; }
.scanner-status .scan-err { color: #ef4444; font-weight: 600; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Группировка по категориям */
.doc-category {
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.category-header:hover { background: var(--border); }

.category-toggle {
    font-size: 10px;
    transition: transform 0.2s;
    width: 16px;
    text-align: center;
}

.doc-category.collapsed .category-toggle { transform: rotate(-90deg); }
.doc-category.collapsed .category-body { display: none; }

.category-name {
    font-weight: 600;
    font-size: 15px;
    flex: 1;
}

.category-count {
    background: var(--accent);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.category-body { padding: 0; }

.category-body .doc-table {
    margin: 0;
    border-radius: 0;
    border: none;
    width: 100%;
    table-layout: fixed;
}

.category-body .doc-table th,
.category-body .doc-table td {
    padding: 10px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.category-body .doc-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    text-align: left;
}

.category-body .doc-table td {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

/* Колонки таблицы — фиксированные пропорции */
.category-body .doc-table th:nth-child(1),
.category-body .doc-table td:nth-child(1) { width: 40%; }
.category-body .doc-table th:nth-child(2),
.category-body .doc-table td:nth-child(2) { width: 10%; }
.category-body .doc-table th:nth-child(3),
.category-body .doc-table td:nth-child(3) { width: 12%; }
.category-body .doc-table th:nth-child(4),
.category-body .doc-table td:nth-child(4) { width: 12%; }
.category-body .doc-table th:nth-child(5),
.category-body .doc-table td:nth-child(5) { width: 13%; }
.category-body .doc-table th:nth-child(6),
.category-body .doc-table td:nth-child(6) { width: 13%; }

/* Кнопки действий */
.doc-view-btn, .doc-download-btn, .action-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    border: 1px solid var(--border);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.doc-view-btn { border-color: var(--accent); color: var(--accent); }
.doc-view-btn:hover { background: var(--accent); color: white; }
.doc-download-btn { border-color: var(--success); color: var(--success); }
.doc-download-btn:hover { background: var(--success); color: white; }
.action-btn.danger { border-color: var(--danger); color: var(--danger); }
.action-btn.danger:hover { background: var(--danger); color: white; }

/* Сроки */
.expiry-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.filter-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}
.filter-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

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

.expiry-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.expiry-item:hover { border-color: var(--accent); }

.expiry-status { font-size: 24px; }
.expiry-info { flex: 1; }
.expiry-info h4 { margin-bottom: 4px; }
.expiry-info .meta { font-size: 13px; color: var(--text-secondary); }
.expiry-days {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}

/* Загрузка файлов */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.3s, background 0.3s;
}
.upload-area:hover, .upload-area.dragover {
    border-color: var(--accent);
    background: rgba(37, 99, 235, 0.05);
}
.upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-hint { font-size: 13px; color: var(--text-muted); margin-top: 8px; }

.upload-form {
    margin-top: 24px;
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.upload-form label {
    display: block;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

.upload-form input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.progress-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

/* Статистика */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
}

.stat-number {
    font-size: 2.5em;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Настройки */
.settings-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.settings-icon {
    font-size: 18px;
    margin-right: 4px;
}

.scanner-settings .scanner-info {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 6px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.scanner-settings .scanner-info span:first-child {
    min-width: 200px;
    color: var(--text-secondary);
}

.scanner-settings .scanner-info span:last-child {
    font-weight: 600;
    color: var(--text);
}

.scanner-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.danger-btn {
    background: var(--danger);
    color: white;
    border: none;
}

.danger-btn:hover {
    background: #dc2626;
}

.connection-item, .user-item, .doctype-item, .tag-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.item-info { flex: 1; min-width: 200px; }
.item-info .name { font-weight: 600; font-size: 14px; }
.item-info .details { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.item-actions { display: flex; gap: 6px; align-items: center; }

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

/* AI сервисы */
.ai-service-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.ai-service-icon { font-size: 20px; flex-shrink: 0; }
.ai-service-info { flex: 1; min-width: 200px; }
.ai-service-name { font-weight: 600; font-size: 14px; }
.ai-service-details { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.ai-service-status { font-size: 13px; font-weight: 500; white-space: nowrap; }
.loading-text { padding: 12px 16px; color: var(--text-muted); font-size: 13px; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.unknown { background: var(--text-muted); }

/* Кнопки */
.primary-btn {
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
}
.primary-btn:hover { background: var(--accent-hover); }

.test-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    cursor: pointer;
    font-size: 13px;
}
.test-btn:hover { background: var(--bg-tertiary); }

/* Просмотр документа */
.doc-meta p { margin: 4px 0; font-size: 14px; }

.doc-preview {
    max-height: 60vh;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 13px;
    line-height: 1.6;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* Модальное окно */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-content h3 { margin-bottom: 16px; }

.modal-content input, .modal-content select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* Профиль */
.profile-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
}

.profile-tab {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
}
.profile-tab.active { background: var(--accent); color: white; }

.profile-section { display: none; }
.profile-section.active { display: block; }

.profile-section label {
    display: block;
    margin: 12px 0;
    font-size: 14px;
}

.profile-section input[type="text"],
.profile-section input[type="email"] {
    width: 300px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-left: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Адаптив */
@media (max-width: 768px) {
    /* Header */
    .header {
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 8px 12px;
    }
    .header-left { justify-content: center; }
    .header-left h1 { font-size: 16px; }
    .nav-center { justify-content: center; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 2px; padding: 0 4px; }
    .nav-btn { padding: 6px 10px !important; font-size: 12px !important; white-space: nowrap; flex-shrink: 0; }
    .header-right { justify-content: center; }

    /* Chat */
    .chat-container { grid-template-columns: 1fr; }
    .chat-sidebar { display: none; }
    .chat-input-area { flex-direction: column; gap: 8px; }
    .chat-input-area textarea { width: 100%; min-height: 60px; font-size: 14px; }
    .send-btn, .stop-btn { width: 100%; padding: 12px; font-size: 15px; }

    /* Documents — горизонтальный скролл таблицы */
    .doc-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .doc-table { min-width: 600px; font-size: 12px; }
    .doc-table th, .doc-table td { padding: 6px 8px; }
    .category-header { padding: 8px 10px; font-size: 13px; }
    .doc-category { margin-bottom: 4px; }
    .category-body .doc-table th:nth-child(2),
    .category-body .doc-table td:nth-child(2),
    .category-body .doc-table th:nth-child(5),
    .category-body .doc-table td:nth-child(5) { display: none; }

    /* Toolbar */
    .toolbar { flex-direction: column; gap: 6px; }
    .toolbar input, .toolbar select { width: 100%; font-size: 14px; padding: 8px; }
    .toolbar button { width: 100%; }

    /* Dashboard */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px; text-align: center; }
    .stat-card .stat-value { font-size: 22px; }
    .stat-card .stat-label { font-size: 11px; }

    /* Settings */
    .settings-section { padding: 10px; margin-bottom: 8px; }
    .settings-section label { font-size: 13px; margin-bottom: 6px; }
    .settings-section input, .settings-section select { width: 100% !important; font-size: 14px; padding: 10px; }
    .settings-section h3 { font-size: 15px; margin-bottom: 8px; }

    /* Modals */
    .modal-content { margin: 10px; padding: 16px; max-height: 90vh; overflow-y: auto; border-radius: 12px; }
    .modal-content label { font-size: 13px; }
    .modal-content input, .modal-content select { width: 100% !important; font-size: 14px; padding: 10px; margin-bottom: 8px; }
    .modal-actions { flex-direction: column; gap: 8px; }
    .modal-actions button { width: 100%; padding: 12px; }

    /* Notifications */
    .notif-item { flex-direction: column; gap: 6px; padding: 10px 12px; }
    .notif-content { min-width: auto; }
    .notif-actions { flex-direction: row; }

    /* Logs */
    .logs-table { font-size: 11px; }
    .logs-table th, .logs-table td { padding: 5px 6px; }
    .logs-table th:nth-child(3), .logs-table td:nth-child(3),
    .logs-table th:nth-child(5), .logs-table td:nth-child(5) { display: none; }

    /* Profile / Expiry */
    .expiry-item { flex-direction: column; gap: 4px; padding: 8px 0; }

    /* Upload */
    .upload-drop { padding: 20px; font-size: 13px; }

    /* Help panel */
    .help-panel { width: 100%; right: 0; left: 0; }

    /* Tables summary */
    .tab-content { padding: 10px; }
}

/* Логи */
.logs-list { margin-top: 12px; }
.logs-table-wrap { overflow-x: auto; }
.logs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.logs-table th {
    text-align: left;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-secondary);
    white-space: nowrap;
}
.logs-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.logs-table tr:hover { background: var(--bg-tertiary); }
.log-time { white-space: nowrap; color: var(--text-muted); font-size: 12px; }
.log-level { font-weight: 500; white-space: nowrap; }

/* Уведомления */
.expiry-section { margin-bottom: 24px; }
.expiry-section .section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.notifications-page-list { margin-top: 8px; }
.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}
.notif-item:hover { background: var(--bg-tertiary); }
.notif-icon { font-size: 20px; flex-shrink: 0; margin-top: 2px; }
.notif-content { flex: 1; min-width: 200px; }
.notif-title { font-size: 14px; margin-bottom: 2px; }
.notif-message { font-size: 13px; color: var(--text-secondary); margin-bottom: 2px; }
.notif-time { font-size: 11px; color: var(--text-muted); }
.notif-actions { display: flex; gap: 4px; align-items: flex-start; flex-shrink: 0; }
.notif-unread-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 6px;
    vertical-align: middle;
}

/* Folder picker */
.folder-picker {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 500px; max-height: 70vh; overflow-y: auto;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; z-index: 1000;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.fp-header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.fp-path { font-size: 12px; color: var(--text-muted); word-break: break-all; }
.fp-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.fp-item:hover { background: var(--bg-tertiary); border-color: var(--border); }
.fp-readonly { opacity: 0.5; cursor: default; }
.fp-back { color: var(--accent); font-weight: 600; }
.fp-new { color: var(--accent); border: 1px dashed var(--accent); }
.fp-right { margin-left: auto; font-size: 12px; }
.fp-loading, .fp-error { padding: 20px; text-align: center; color: var(--text-muted); }
