/* static/css/style.css — SMDG: medical UI tokens, glass surfaces, mobile-first */
:root {
    /* Основные цвета */
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --primary-light: #6ea8fe;
    --secondary: #6c757d;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #0dcaf0;

    /* Фоны */
    --bg-primary: #f5f7fc;
    --bg-secondary: #ffffff;
    --bg-sidebar: #1a1a2e;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-glass: rgba(255, 255, 255, 0.1);

    /* Текст */
    --text-primary: #1a1a2e;
    --text-secondary: #6c757d;
    --text-light: #ffffff;

    /** Заголовки страниц (бренд) — одинаковый цвет и в светлой теме используется для тёмного режима */
    --brand-page-title: #1a1a2e;

    /* Тени */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 12px 36px rgba(0, 0, 0, 0.16);

    /* Скругления */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    /* Анимации */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.35s ease;

    /* Совместимость со старыми правилами */
    --primary-color: var(--primary);
    --secondary-color: var(--text-primary);
    --success-color: var(--success);
    --warning-color: var(--warning);
    --danger-color: var(--danger);
    --light-color: var(--bg-secondary);
    --dark-color: #212529;
    --smdg-touch-min: 2.75rem;
    --smdg-space-interactive: 0.5rem;
    --smdg-font-min: 1rem;
    --smdg-radius: var(--radius-md);
    --smdg-header-h: 3.5rem;
}

[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --bg-card: rgba(30, 30, 50, 0.85);
    --light-color: #243044;
    --dark-color: #e9ecef;
}

html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

/* Touch-friendly */
button,
a.btn-primary,
a.btn-secondary,
a.btn-admin,
a.btn-info,
[role="button"],
.tab-btn,
.hamburger,
.file-picker__button {
    min-height: var(--smdg-touch-min);
    min-width: 2.75rem;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background:
        radial-gradient(1200px 600px at 80% -10%, rgba(13, 110, 253, 0.12), transparent 55%),
        radial-gradient(900px 500px at -10% 90%, rgba(110, 168, 254, 0.1), transparent 50%),
        linear-gradient(165deg, var(--bg-primary) 0%, #e8eef8 45%, #dce5f5 100%);
    min-height: 100vh;
}

body.page-index {
    background:
        radial-gradient(ellipse 100% 80% at 50% -20%, rgba(13, 110, 253, 0.22), transparent 52%),
        radial-gradient(ellipse 80% 60% at 100% 60%, rgba(118, 75, 162, 0.08), transparent 45%),
        linear-gradient(155deg, #1e3a5f 0%, #2c5282 35%, #4a6fa5 70%, #7b9cc4 100%);
}

body:not(.page-index) {
    background: var(--bg-primary);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Glass card utility + sections */
.card-glossy,
.section {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: var(--shadow-lg);
    transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}

.section:not(.danger):hover {
    box-shadow: var(--shadow-xl);
}

.card-glossy:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
}

[data-theme="dark"] .section,
[data-theme="dark"] .card-glossy {
    border-color: rgba(255, 255, 255, 0.08);
}

/* Header (legacy + index) */
header:not(.site-header) {
    text-align: center;
    margin-bottom: 30px;
    padding: 24px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: var(--shadow-md);
}

h1 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.125rem;
}

.page-index header:not(.site-header) h1 {
    color: var(--text-primary);
}

.page-index #authForm header {
    background: rgba(255, 255, 255, 0.92);
}

/* Status messages */
.status {
    padding: 16px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 25px;
    text-align: center;
    font-weight: 600;
    font-size: 1.05em;
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: var(--shadow-sm);
}

.status.ok {
    background: rgba(209, 236, 241, 0.95);
    color: #0c5460;
    border-color: rgba(23, 162, 184, 0.35);
}

[data-theme="dark"] .status.ok {
    background: rgba(25, 135, 84, 0.2);
    color: #75c687;
    border-color: rgba(25, 135, 84, 0.35);
}

.api-key {
    background: rgba(255, 243, 205, 0.95);
    border: 1px solid rgba(255, 193, 7, 0.45);
    padding: 15px;
    border-radius: var(--radius-md);
    text-align: center;
    margin: 20px 0;
    font-family: ui-monospace, 'Courier New', monospace;
    font-size: 1.1em;
    font-weight: bold;
}

/* Sections */
.section {
    padding: 26px 28px;
    margin: 24px 0;
}

.section h2 {
    color: var(--text-primary);
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid rgba(13, 110, 253, 0.25);
    font-weight: 600;
    font-size: clamp(1.15rem, 2.5vw, 1.35rem);
}

.page-index .section {
    background: rgba(255, 255, 255, 0.9);
}

/* Forms */
form {
    margin: 20px 0;
}

input[type="file"],
input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    margin: 10px 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-sm);
    font-size: var(--smdg-font-min);
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

[data-theme="dark"] input[type="text"] {
    background: rgba(22, 33, 62, 0.85);
    border-color: rgba(255, 255, 255, 0.12);
}

.auth-tabs {
    display: flex;
    margin: 20px 0;
    border-bottom: 2px solid rgba(0, 0, 0, 0.06);
    gap: 4px;
}

[data-theme="dark"] .auth-tabs {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

.tab-btn {
    flex: 1;
    padding: 14px 12px;
    background: transparent;
    border: none;
    font-size: var(--smdg-font-min);
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
    color: var(--text-secondary);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-btn:hover {
    background: rgba(13, 110, 253, 0.06);
    color: var(--primary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom: 3px solid var(--primary);
    font-weight: 700;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"] {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: var(--radius-sm);
    font-size: var(--smdg-font-min);
    min-height: 2.75rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

[data-theme="dark"] .form-group input[type="text"],
[data-theme="dark"] .form-group input[type="password"],
[data-theme="dark"] .form-group input[type="email"] {
    background: rgba(22, 33, 62, 0.85);
    border-color: rgba(255, 255, 255, 0.12);
}

/*
 * Авторизация: подпись «Пароль» и плейсхолдеры — как «Логин» (до правки −webkit-fill заливало всё белым).
 * Введённые точки пароля — по-прежнему белые.
 */
[data-theme="dark"] #authForm .form-group label {
    color: var(--text-primary);
}

[data-theme="dark"] #authForm .form-group input::placeholder {
    color: var(--text-secondary);
    opacity: 1;
    -webkit-text-fill-color: var(--text-secondary);
}

[data-theme="dark"] #authForm .form-group input[type="password"] {
    color: #ffffff;
    caret-color: #ffffff;
}

[data-theme="dark"] #authForm .form-group input[type="password"]:not(:placeholder-shown) {
    -webkit-text-fill-color: #ffffff;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.2);
}

.form-group.checkbox-group {
    display: flex;
    align-items: center;
}

.form-group.checkbox-group input {
    width: auto;
    margin-right: 10px;
}

.field-hint {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: var(--text-secondary);
}

.password-strength {
    margin-top: 6px;
    height: 4px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 2px;
    overflow: hidden;
}

.strength-bar {
    height: 100%;
    width: 0;
    transition: width 0.3s, background-color 0.3s;
}

.form-actions {
    margin-top: 28px;
}

.form-actions button {
    width: 100%;
}

.form-footer {
    margin-top: 18px;
    text-align: center;
    font-size: 14px;
}

.form-footer a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.form-footer a:hover {
    text-decoration: underline;
}

/* Base button + variants */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
    border: none;
    text-decoration: none;
    line-height: 1.3;
}

.btn-primary,
.btn-secondary,
.btn-admin,
.btn-info,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 22px;
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--smdg-font-min);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
    text-align: center;
    width: 100%;
    margin: 10px 0;
    line-height: 1.3;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--text-light);
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.35);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(13, 110, 253, 0.45);
}

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

.btn-secondary {
    background: linear-gradient(135deg, #5c636a, #495057);
    color: var(--text-light);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    opacity: 0.98;
}

.btn-admin {
    background: linear-gradient(135deg, #343a40, #212529);
    color: var(--text-light);
    box-shadow: var(--shadow-sm);
}

.btn-admin:hover {
    transform: translateY(-2px);
}

.btn-info {
    background: linear-gradient(135deg, var(--success), #146c43);
    color: var(--text-light);
    box-shadow: 0 2px 8px rgba(25, 135, 84, 0.3);
}

.btn-info:hover {
    transform: translateY(-2px);
}

.btn-warning {
    background: linear-gradient(135deg, var(--warning), #e0a800);
    color: #212529;
    font-weight: 700;
    border: none;
    padding: 12px 22px;
    border-radius: var(--radius-md);
}

.btn-warning:hover {
    transform: translateY(-2px);
}

.btn-danger {
    background: linear-gradient(135deg, #e54b5c, #c82333);
    color: var(--text-light);
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.btn-danger:hover {
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #146c43);
    color: white;
    border: none;
    padding: 12px 22px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    width: 100%;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    box-shadow: 0 2px 8px rgba(25, 135, 84, 0.3);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(25, 135, 84, 0.4);
}

.btn-outline-primary {
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    color: var(--primary);
    background: transparent;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-fast);
}

.btn-outline-primary:hover {
    background: rgba(13, 110, 253, 0.1);
    transform: translateY(-1px);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.user-info span {
    font-weight: 700;
    color: var(--primary);
}

/* Modal 2FA */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(26, 26, 46, 0.55);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 10% auto;
    padding: 28px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: var(--shadow-xl);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .modal-content {
    background: #1e2a45;
    border-color: rgba(255, 255, 255, 0.08);
}

.close {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-secondary);
}

.close:hover {
    color: var(--text-primary);
}

.otp-secret {
    background: rgba(0, 0, 0, 0.04);
    padding: 15px;
    border-radius: var(--radius-sm);
    margin: 15px 0;
    word-break: break-all;
    display: flex;
    align-items: center;
    gap: 10px;
}

.otp-secret code {
    flex: 1;
    font-family: ui-monospace, monospace;
    font-size: 14px;
}

.qr-code {
    text-align: center;
    margin: 20px 0;
}

.qr-code img {
    max-width: 200px;
    height: auto;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-sm);
}

.btn-small {
    padding: 8px 14px;
    font-size: var(--smdg-font-min);
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn-small:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

@media (max-width: 600px) {
    .modal-content {
        margin: 5% auto;
        width: 95%;
        padding: 20px;
    }

    .otp-secret {
        flex-direction: column;
    }

    .user-info {
        flex-direction: column;
        align-items: flex-end;
    }
}

/* File list — modern file “card” row */
.file-list {
    margin-top: 20px;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.5);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.file-list.admin {
    max-height: 500px;
}

.file-item {
    padding: 16px 18px;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    transition: background var(--transition-fast);
}

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

.file-item:hover {
    background: rgba(13, 110, 253, 0.04);
}

[data-theme="dark"] .file-item {
    background: rgba(22, 33, 62, 0.5);
}

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

.file-name {
    font-weight: 700;
    color: var(--text-primary);
    word-break: break-word;
}

.file-size {
    color: var(--text-secondary);
    font-size: 0.92em;
    margin-top: 4px;
}

/* Navigation */
.nav-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    margin: 30px 0;
}

/* Footer */
footer {
    margin-top: 36px;
    padding-top: 22px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    color: var(--text-secondary);
    font-size: 0.95em;
}

footer ul {
    list-style: none;
    padding-left: 20px;
}

footer li {
    margin: 6px 0;
    position: relative;
}

footer li:before {
    content: "•";
    color: var(--primary);
    position: absolute;
    left: -18px;
}

body.page-index #mainApp > footer {
    color: rgba(255, 255, 255, 0.92);
    border-top-color: rgba(255, 255, 255, 0.28);
}

body.page-index #mainApp > footer strong {
    color: #fff;
    font-weight: 600;
}

body.page-index #mainApp > footer li:before {
    color: rgba(255, 255, 255, 0.75);
}

/* Alerts */
.warning {
    background: rgba(255, 193, 7, 0.12);
    border-left: 4px solid var(--warning);
}

.danger {
    background: rgba(220, 53, 69, 0.1);
    border-left: 4px solid var(--danger);
}

.info {
    background: rgba(13, 202, 240, 0.1);
    border-left: 4px solid #17a2b8;
}

.back-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.back-link:hover {
    text-decoration: underline;
}

.controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* Stats */
.stats-container {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    padding: 22px;
    border-radius: var(--radius-lg);
    margin: 20px 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: var(--shadow-md);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary) 0%, #4a6cf7 50%, #7b68ee 100%);
    color: white;
    padding: 20px;
    border-radius: var(--radius-md);
    text-align: center;
    box-shadow: var(--shadow-md);
}

.stat-number {
    font-size: 2.5em;
    font-weight: bold;
    margin: 10px 0;
}

.stat-number.healthy {
    color: #90ee90;
}

.stat-number.unhealthy {
    color: #ffb3b3;
}

.stat-label {
    font-size: 0.9em;
    opacity: 0.95;
}

.directories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin: 15px 0;
}

.directory-card {
    background: rgba(13, 110, 253, 0.06);
    padding: 15px;
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary);
    text-align: center;
}

.file-types {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 15px 0;
}

.file-type-badge {
    background: rgba(0, 0, 0, 0.05);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

/* JSON viewer */
.json-viewer {
    background: #1e1e2e;
    color: #d4d4d4;
    padding: 20px;
    border-radius: var(--radius-sm);
    font-family: ui-monospace, 'Courier New', monospace;
    font-size: 0.9em;
    overflow: auto;
    max-height: 500px;
}

.json-key { color: #9cdcfe; }
.json-string { color: #ce9178; }
.json-number { color: #b5cea8; }
.json-boolean { color: #569cd6; }
.json-null { color: #569cd6; }

.danger-zone {
    text-align: center;
    padding: 20px;
}

.warning-text {
    color: #856404;
    margin-top: 10px;
}

[data-theme="dark"] .warning-text {
    color: #f0c674;
}

.download-link {
    background: rgba(25, 135, 84, 0.12);
    border: 1px solid rgba(25, 135, 84, 0.45);
    padding: 16px;
    margin-top: 20px;
    border-radius: var(--radius-md);
    animation: fadeIn 0.5s ease;
}

.download-link input {
    background-color: var(--bg-secondary);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: var(--radius-sm);
}

.download-link button {
    background: var(--success);
    color: white;
    padding: 10px 14px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
}

.download-link button:hover {
    filter: brightness(1.05);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ═══ Sidebar (admin layouts) ═══ */
.sidebar {
    background: var(--bg-sidebar);
    width: 260px;
    min-height: 100vh;
    padding: 24px 16px;
    position: fixed;
    left: 0;
    top: 0;
    transition: width var(--transition-normal), transform var(--transition-normal);
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: rgba(255, 255, 255, 0.72);
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.sidebar-item.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.35);
}

/* ═══ Data tables (shared) ═══ */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th {
    text-align: left;
    padding: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid rgba(0, 0, 0, 0.06);
    background: rgba(0, 0, 0, 0.02);
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.data-table tr {
    transition: background var(--transition-fast);
}

.data-table tr:hover {
    background: rgba(13, 110, 253, 0.04);
}

[data-theme="dark"] .data-table th {
    background: rgba(255, 255, 255, 0.04);
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .data-table td {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

/* Toast (global; main.js appends .toast) */
@keyframes slideInToast {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideInToast 0.3s ease;
    z-index: 10000;
    max-width: min(92vw, 360px);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.info { border-left: 4px solid var(--primary); }

/* Skeleton */
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, #f0f2f5 25%, #e2e6ec 50%, #f0f2f5 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
    min-height: 1rem;
}

[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg, #2a3142 25%, #1e2535 50%, #2a3142 75%);
    background-size: 200% 100%;
}

/* DICOM Viewer Modal */
.dicom-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    background: #000;
    animation: dicomFadeIn 0.3s ease;
}

@keyframes dicomFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.dicom-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    min-height: 44px;
    flex-shrink: 0;
}

.dicom-modal-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #e8eaed;
    font-size: 14px;
    overflow: hidden;
}

.dicom-modal-icon {
    font-size: 16px;
}

.dicom-modal-filename {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 500px;
}

.dicom-modal-expires {
    color: #9aa0a6;
    font-size: 12px;
    white-space: nowrap;
}

.dicom-modal-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.dicom-modal-btn {
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.dicom-modal-btn-close {
    background: var(--danger);
    color: #fff;
}

.dicom-modal-btn-close:hover {
    filter: brightness(1.08);
}

.dicom-modal-body {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.dicom-modal-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #111;
    z-index: 10;
    transition: opacity 0.3s;
}

.dicom-modal-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #333;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: dicomSpin 0.8s linear infinite;
    margin-bottom: 12px;
}

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

.dicom-modal-loading p {
    color: #9aa0a6;
    font-size: 14px;
    margin: 0;
}

.dicom-modal-error {
    color: #f28b82;
    text-align: center;
}

.dicom-modal-error a {
    color: var(--primary-light);
}

.dicom-modal-iframe {
    width: 100%;
    height: 100%;
    border: none;
    transition: opacity 0.3s;
}

/* File picker */
.file-picker {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 10px 0;
}

.file-picker__input,
.file-picker input[type="file"] {
    position: absolute !important;
    left: 0;
    top: 0;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none;
}

.file-picker__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    margin: 0;
    padding: 10px 18px;
    font-size: 15px;
    cursor: pointer;
}

.file-picker__input:focus-visible + .file-picker__button {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.file-picker__name {
    font-size: 14px;
    color: var(--text-secondary);
    word-break: break-all;
}

.file-picker__name.has-file {
    color: var(--text-primary);
    font-weight: 600;
}

/* index: смена темы в шапке (i18n дописывает #language-selector в конец #smdgLangAndMenu) */
.site-header__theme-wrap {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.55rem;
    min-width: 0;
    max-width: 100%;
}

.site-header__lang-menu .site-header__theme-wrap {
    align-items: center;
}

.site-header__theme-label {
    flex-shrink: 0;
}

#smdgLangAndMenu.site-header__lang-menu .site-header__theme-wrap {
    order: 1;
}

#smdgLangAndMenu.site-header__lang-menu #language-selector {
    order: 2;
}

#smdgLangAndMenu.site-header__lang-menu #smdgMenuToggle {
    order: 3;
}

/* Форма входа: блок темы над заголовком */
.auth-theme-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

[data-theme="dark"] .auth-theme-toolbar {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.theme-switch__text {
    display: inline;
}

@media (max-width: 520px) {
    .theme-switch--compact-header .theme-switch__text {
        display: none;
    }

    .theme-switch--compact-header .theme-switch__btn {
        min-width: calc(var(--smdg-touch-min, 44px) - 4px);
        padding-left: 0.45rem;
        padding-right: 0.45rem;
    }
}

@media (max-width: 400px) {
    .site-header__theme-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .site-header__theme-wrap {
        position: relative;
    }
}

@media (max-width: 380px) {
    .auth-theme-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .theme-switch--stretch-sm {
        width: 100%;
        justify-content: stretch;
    }

    .theme-switch--stretch-sm .theme-switch__btn {
        flex: 1 1 0;
        min-width: 0;
        justify-content: center;
    }
}

/* Site header */
.site-header {
    position: relative;
    z-index: 500;
    text-align: left;
    margin-bottom: 1.5rem;
    padding: 1.1rem 1.35rem;
    background: var(--bg-card);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.38);
    box-shadow: var(--shadow-md);
}

body:not(.page-index) .site-header {
    background: rgba(255, 255, 255, 0.95);
}

.site-header__top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: var(--smdg-space-interactive);
}

.site-header__left {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.4rem 1rem;
    min-width: 0;
}

.site-header__left--dashboard .site-header__brand {
    flex: 0 1 auto;
    min-width: min(100%, 14rem);
}

.site-header__title {
    margin: 0;
    font-size: clamp(1.1rem, 2.5vw, 1.75rem);
    line-height: 1.2;
    color: var(--text-primary);
}

.site-header__back {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0.25rem 0.5rem 0.25rem 0;
    white-space: nowrap;
    font-weight: 600;
}

.site-header__trailing {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    flex-shrink: 0;
}

.site-header__lang-menu {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem 0.5rem;
    flex-shrink: 0;
}

.site-header__lang-menu .language-selector {
    margin-left: 0;
    position: relative;
    z-index: 2;
}

.auth-toolbar__label {
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

/* Карточка формы входа / регистрации */
#authForm.auth-panel {
    max-width: 28rem;
    margin-inline: auto;
    padding: 1.35rem 1.5rem 1.75rem;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.42);
    box-shadow: var(--shadow-xl);
}

[data-theme="dark"] #authForm.auth-panel {
    background: var(--bg-card);
    border-color: rgba(255, 255, 255, 0.12);
}

/* Убираем второй «ящик» у заголовка внутри карточки авторизации */
#authForm.auth-panel > header:not(.site-header) {
    margin-top: 0;
    margin-bottom: 1.25rem;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
}

.theme-switch {
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0;
    padding: 3px;
    background: rgba(13, 110, 253, 0.08);
    border: 1px solid rgba(13, 110, 253, 0.22);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .theme-switch {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.14);
}

.theme-switch__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 2.5rem;
    padding: 0.4rem 0.7rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: calc(var(--radius-md) - 3px);
    cursor: pointer;
    transition:
        background var(--transition-fast),
        color var(--transition-fast),
        box-shadow var(--transition-fast);
    white-space: nowrap;
}

.theme-switch__btn:hover {
    color: var(--text-primary);
    background: rgba(13, 110, 253, 0.12);
}

.theme-switch__btn.is-active {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.35);
}

.theme-switch__btn.is-active:hover {
    color: #fff;
    filter: brightness(1.04);
}

.theme-switch__glyph {
    font-size: 1rem;
    line-height: 1;
}

@media (max-width: 1023.98px) {
    .site-header__lang-menu {
        gap: 0.25rem 0.4rem;
    }

    body.page-index .site-header__top {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    body.page-index .site-header__left {
        width: 100%;
    }

    body.page-index .site-header__trailing {
        margin-left: 0;
        width: 100%;
        max-width: 100%;
        justify-content: flex-start;
        align-items: center;
    }

    body.page-index .user-info.user-info--header {
        margin-top: 0;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    body.page-index .site-header__lang-menu {
        justify-content: flex-start;
    }
}

.site-header__brand h1 {
    font-size: clamp(1.25rem, 4vw, 2.5rem);
    text-align: left;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.page-index .site-header__brand h1,
.page-index .site-header__title {
    color: var(--text-primary);
}

/*
 * В тёмной теме основные заголовки (SMDG, панель администратора, пользователи, DLQ …)
 * остаются цвета светлой темы (#1a1a2e — var(--brand-page-title)).
 */
[data-theme="dark"] .site-header .site-header__brand h1,
[data-theme="dark"] .site-header h1.site-header__title {
    color: var(--brand-page-title);
}

/*
 * Заголовок карточки входа: меньше, чем общий h1 страницы.
 * В тёмной теме — светлый текст (brand-page-title на тёмном карточном фоне нечитаем).
 */
#authForm.auth-panel header:not(.site-header) h1 {
    font-size: clamp(1.05rem, 3.2vw, 1.4rem);
    line-height: 1.35;
    margin-bottom: 0.35rem;
}

[data-theme="dark"] #authForm.auth-panel header h1,
[data-theme="dark"] #authForm.auth-panel header h1 span {
    color: var(--text-primary);
}

.page-index .site-header {
    background: rgba(255, 255, 255, 0.94);
}

.site-header__brand .subtitle {
    font-size: clamp(0.95rem, 2.5vw, 1.2rem);
    color: var(--text-secondary);
}

.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    width: var(--smdg-touch-min);
    height: var(--smdg-touch-min);
    padding: 0;
    margin: 0;
    background: rgba(13, 110, 253, 0.08);
    border: 1px solid rgba(13, 110, 253, 0.25);
    border-radius: var(--smdg-radius);
    cursor: pointer;
    flex-shrink: 0;
    z-index: 2;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.hamburger:hover {
    background: rgba(13, 110, 253, 0.14);
}

.hamburger span {
    display: block;
    width: 1.35rem;
    height: 0.15rem;
    background: var(--text-primary);
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.hamburger.is-active span:nth-child(1) {
    transform: translateY(0.5rem) rotate(45deg);
}

.hamburger.is-active span:nth-child(2) {
    opacity: 0;
}

.hamburger.is-active span:nth-child(3) {
    transform: translateY(-0.5rem) rotate(-45deg);
}

.main-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    margin: 0;
    padding: 0;
    border: none;
}

.main-nav__link {
    min-height: var(--smdg-touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--smdg-radius);
    text-decoration: none;
    width: 100%;
    max-width: 100%;
}

.nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 46, 0.45);
    backdrop-filter: blur(2px);
    z-index: 998;
    border: none;
    padding: 0;
    cursor: pointer;
}

body.smdg-nav-open {
    overflow: hidden;
    touch-action: none;
}

@media (max-width: 1023.98px) {
    .hamburger {
        display: flex;
    }

    .main-nav {
        position: fixed;
        top: 0;
        left: 0;
        width: min(20rem, 88vw);
        height: 100vh;
        height: 100dvh;
        margin: 0;
        padding: 5rem 1.25rem 1.5rem;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(12px);
        box-shadow: 0.35rem 0 1.75rem rgba(0, 0, 0, 0.18);
        flex-direction: column;
        z-index: 999;
        overflow-y: auto;
        border-top: none;
        transform: translateX(-100%);
        transition: transform 0.28s ease;
    }

    [data-theme="dark"] .main-nav {
        background: rgba(22, 33, 62, 0.98);
    }

    .main-nav.is-open {
        transform: translateX(0);
    }

    .main-nav__link {
        width: 100%;
    }

    .nav-backdrop[hidden] {
        display: none !important;
    }
}

@media (min-width: 1024px) {
    .hamburger {
        display: none;
    }

    .nav-backdrop {
        display: none !important;
    }

    .site-header__left .main-nav {
        display: inline-flex;
        align-items: center;
    }

    .main-nav__link {
        width: auto;
    }
}

.nav-links {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin: 1.5rem 0;
}

@media (min-width: 768px) {
    .nav-links {
        grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    }
}

.user-info--header,
#authForm + * .user-info,
#mainApp .user-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--smdg-space-interactive);
    margin-top: 0;
    flex: 1;
    min-width: min(100%, 12rem);
}

.user-info .btn-danger,
.user-info .btn-outline-primary {
    min-height: var(--smdg-touch-min);
    padding: 0.5rem 0.9rem;
    width: auto;
}

@media (max-width: 767.98px) {
    .file-item {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
    }

    .file-actions,
    .file-item .dicom-view-btn {
        width: 100%;
    }

    .file-list {
        max-height: min(50vh, 24rem);
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        min-height: unset;
    }

    .btn:not(.btn-small),
    .btn-primary,
    .btn-secondary {
        padding: 12px 16px;
        font-size: 16px;
    }

    .data-table {
        display: block;
        overflow-x: auto;
    }

    .toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .sidebar {
        width: 200px;
    }
}

.file-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--smdg-space-interactive);
    align-items: center;
    justify-content: flex-end;
}

.btn-small,
.file-item .btn-small {
    min-height: 2.75rem;
    padding: 0.45rem 0.85rem;
    font-size: var(--smdg-font-min);
    width: auto;
}

.file-item a.btn-small,
.file-item .btn-small {
    width: auto;
}

@media (max-width: 767.98px) {
    .modal-content {
        margin: 0;
        min-height: 100vh;
        min-height: 100dvh;
        max-width: 100%;
        width: 100%;
        border-radius: 0;
        padding: 1.25rem 1rem 2rem;
        overflow-y: auto;
    }

    .modal {
        padding: 0;
        align-items: stretch;
        display: flex;
    }

    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .form-actions button {
        width: 100%;
    }
}

.responsive-data-table {
    width: 100%;
    border-collapse: collapse;
}

.responsive-data-table th,
.responsive-data-table td {
    padding: 0.75rem 0.55rem;
    text-align: left;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.responsive-data-table tbody tr:hover {
    background: rgba(13, 110, 253, 0.04);
}

@media (max-width: 767.98px) {
    .responsive-data-table thead {
        display: none;
    }

    .responsive-data-table tbody tr {
        display: block;
        margin-bottom: 1rem;
        padding: 0.85rem 1rem;
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: var(--smdg-radius);
        background: var(--bg-secondary);
        box-shadow: var(--shadow-sm);
    }

    .responsive-data-table tbody td {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.5rem;
        padding: 0.4rem 0;
        border: none;
    }

    .responsive-data-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        flex: 0 0 38%;
        max-width: 10rem;
    }

    .responsive-data-table .action-buttons {
        width: 100%;
        flex-direction: column;
    }
}

@media (min-width: 768px) and (max-width: 1023.98px) {
    .container {
        max-width: 100%;
        padding: 0.75rem 1.25rem;
    }

    .section {
        padding: 1.25rem 1.35rem;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 75rem;
    }
}

@media (min-width: 90rem) {
    .container {
        max-width: 90rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    h1 {
        font-size: 2rem;
    }

    .nav-links {
        grid-template-columns: 1fr;
    }

    .controls {
        flex-direction: column;
    }
}

/* Админка: блок «Управление пользователями» — две кнопки в ряд одинаковой ширины (как DLQ ↔ User). */
#admin-advanced-wrap .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: stretch;
}

#admin-advanced-wrap .controls > .btn-primary,
#admin-advanced-wrap .controls > .btn-secondary,
#admin-advanced-wrap .controls > a.btn-primary,
#admin-advanced-wrap .controls > a.btn-secondary {
    width: 100%;
    margin: 0;
    box-sizing: border-box;
}

/* «Детальная статистика» и «Обновить»: та же ширина, что у кнопки «Удалить все файлы» (.danger-zone .btn-danger — 100% секции). */
.admin-stats-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    margin-top: 1.25rem;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

.admin-stats-toolbar .btn-info,
.admin-stats-toolbar .btn-secondary {
    width: 100%;
    min-width: 0;
    margin: 0;
    box-sizing: border-box;
}

.controls {
    flex-wrap: wrap;
}

@media (max-width: 767.98px) {
    #admin-advanced-wrap .controls {
        grid-template-columns: 1fr;
    }

    .controls {
        flex-direction: column;
    }

    .controls .btn-primary,
    .controls .btn-secondary,
    .controls .btn-warning,
    .controls a.btn-primary {
        width: 100%;
    }
}

/* Icon buttons (optional) */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.btn-icon:hover {
    background: rgba(13, 110, 253, 0.08);
    border-color: rgba(13, 110, 253, 0.35);
}
