:root {
    --primary: #0d9488;
    --primary-hover: #0f766e;
    --accent-soft: #e6f7f5;
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-subtle: #f1f5f9;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --btn-sec-bg: #f1f5f9;
    --btn-sec-hover: #e2e8f0;
    --danger-bg: #fef2f2;
    --danger-text: #dc2626;
    --danger-border: #fecaca;
}

body.theme-dark {
    --primary: #14b8a6;
    --primary-hover: #2dd4bf;
    --accent-soft: rgba(20, 184, 166, 0.16);
    --bg: #0b1220;
    --surface: #111a2e;
    --surface-subtle: #16223b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #243352;
    --input-bg: #0f172a;
    --input-border: #334155;
    --btn-sec-bg: #1e2d4a;
    --btn-sec-hover: #283b5e;
    --danger-bg: rgba(244, 63, 94, 0.14);
    --danger-text: #fda4af;
    --danger-border: rgba(244, 63, 94, 0.35);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Аккуратные стрелки у выпадающих списков */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 36px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px 14px;
    cursor: pointer;
}

body.theme-dark select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

/* Уведомления без системных alert() */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
}

.toast-item {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.2);
}

.toast-item.toast-error {
    border-left-color: #e11d48;
}

/* Фирменный векторный логотип «3Д-диагностика» */
.brand-full-logo {
    height: 38px;
    width: auto;
    max-width: 150px;
    display: block;
    flex-shrink: 0;
}

.auth-brand-logo {
    height: 58px;
    max-width: 220px;
    margin: 0 auto;
}

.brand-logo-text path {
    fill: var(--text);
    transition: fill 0.2s ease;
}

.brand-logo-mark .logo-part-head {
    fill: var(--primary);
    transition: fill 0.2s ease;
}

.brand-logo-mark .logo-part-orbit {
    fill: var(--primary);
    opacity: 0.78;
    transition: fill 0.2s ease, opacity 0.2s ease;
}

body.theme-dark .brand-logo-mark .logo-part-orbit {
    opacity: 0.92;
}

/* Логотип лаборатории (вспомогательный) */
.lab-logo-svg {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: block;
}

.auth-lab-logo {
    width: 52px;
    height: 52px;
}

/* Авторизация */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px 16px;
    background: radial-gradient(circle at 50% 12%, #ffffff 0%, var(--bg) 80%);
}

body.theme-dark .auth-wrapper {
    background: radial-gradient(circle at 50% 12%, #15223a 0%, var(--bg) 80%);
}

.auth-card {
    position: relative;
    background: var(--surface);
    padding: 38px 30px 28px;
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 40px -15px rgba(15, 23, 42, 0.08), 0 0 0 1px var(--border);
    border: none;
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

body.theme-dark .auth-card {
    box-shadow: 0 24px 50px -15px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border);
}

.auth-theme-btn {
    position: absolute;
    top: 18px;
    right: 18px;
    height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.auth-theme-btn:hover {
    background: var(--btn-sec-hover);
    color: var(--text);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.logo.auth-logo,
.auth-logo {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-top: 4px;
    margin-bottom: 12px;
    gap: 0;
}

.auth-brand-logo {
    height: 52px;
    width: auto;
    max-width: 230px;
    display: block;
    margin: 0 auto;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 13.5px;
    line-height: 1.45;
    margin-bottom: 22px;
    padding: 0 6px;
}

.legal-note {
    margin-top: 18px;
    text-align: center;
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.45;
}

.auth-tabs {
    display: flex;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    padding: 4px;
    border-radius: 12px;
    margin-bottom: 22px;
    align-items: center;
    gap: 4px;
}

.auth-tab {
    flex: 1;
    height: 36px;
    padding: 0 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 9px;
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text-muted);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.auth-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.07);
}

.auth-card .form-group {
    margin-bottom: 14px;
}

.auth-card .form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.auth-card .form-group input {
    height: 42px;
    padding: 0 14px;
    border-radius: 10px;
    font-size: 14px;
    border: 1px solid var(--input-border);
    background-color: var(--input-bg);
}

.auth-card .btn-primary {
    height: 44px;
    font-size: 14.5px;
    font-weight: 600;
    border-radius: 10px;
    margin-top: 8px;
    box-shadow: 0 4px 14px rgba(13, 148, 136, 0.22);
}

.auth-card .btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 18px rgba(13, 148, 136, 0.32);
    transform: translateY(-1px);
}

/* Шапка сайта */
.navbar {
    background: var(--surface);
    min-height: 64px;
    padding: 10px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    gap: 16px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.logo {
    font-size: 22px;
    line-height: 1;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.logo-icon,
.logo-text {
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.logo strong {
    color: var(--primary);
    font-weight: 700;
}

.free-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    padding: 0 11px;
    font-size: 11.5px;
    line-height: 1;
    background: var(--accent-soft);
    color: var(--primary);
    border: 1px solid rgba(13, 148, 136, 0.22);
    border-radius: 9999px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

body.theme-dark .free-badge {
    border-color: rgba(20, 184, 166, 0.3);
}

.doctor-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px;
}

/* Статус хранилища и сервера */
.nav-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 38px;
    padding: 0 12px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 12.5px;
    color: var(--text-muted);
    white-space: nowrap;
    user-select: none;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.nav-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 2.5px rgba(16, 185, 129, 0.2);
    flex-shrink: 0;
}

.nav-storage-text {
    color: var(--text-muted);
    font-size: 12.5px;
    line-height: 1;
}

.nav-storage-text strong {
    color: var(--text);
    font-weight: 600;
}

.nav-status-sep {
    color: var(--border);
    font-size: 11px;
    margin: 0 2px;
    opacity: 0.8;
}

.server-status-label {
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1;
}

.server-status-label.server-ok {
    color: var(--primary);
}

/* Карточка профиля доктора */
.nav-doctor-chip {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    height: 38px;
    padding: 0 12px 0 6px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-doctor-chip:hover {
    background: var(--surface-hover);
    border-color: rgba(13, 148, 136, 0.35);
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.06);
}

.nav-doctor-avatar {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--accent-soft);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-doctor-meta {
    display: flex;
    align-items: baseline;
    gap: 6px;
    white-space: nowrap;
}

.doctor-badge {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1;
    background: transparent;
    padding: 0;
}

.nav-doctor-meta small {
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1;
}

.nav-doctor-meta small::before {
    content: "•";
    margin-right: 6px;
    opacity: 0.5;
}

/* Единая группа действий */
.nav-btn-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
}

.nav-action-btn {
    height: 38px;
    padding: 0 13px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    color: var(--text);
    font-size: 13px;
    font-weight: 550;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-action-btn:hover {
    background: var(--surface-hover);
    border-color: var(--input-border);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(15, 23, 42, 0.05);
}

.nav-action-btn.nav-btn-logout {
    color: var(--text-muted);
}

.nav-action-btn.nav-btn-logout:hover {
    color: #e11d48;
    background: rgba(225, 29, 72, 0.06);
    border-color: rgba(225, 29, 72, 0.28);
    box-shadow: 0 3px 8px rgba(225, 29, 72, 0.08);
}

/* Контейнер */
.container {
    max-width: 1150px;
    margin: 30px auto;
    padding: 0 20px;
}

.top-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 16px;
}

.subtitle-count {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

/* Кнопки */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    line-height: 1;
    white-space: nowrap;
    flex-shrink: 0;
    vertical-align: middle;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

.top-controls .btn {
    height: 40px;
    padding: 0 18px;
    font-size: 13.5px;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--btn-sec-bg);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--btn-sec-hover);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: var(--danger-border);
}

.btn-danger:hover:not(:disabled) {
    filter: brightness(0.97);
}

.btn-sm {
    height: 32px;
    padding: 0 11px;
    font-size: 12.5px;
    border-radius: 6px;
}

.btn-block {
    width: 100%;
    height: 40px;
    margin-top: 10px;
}

.btn-active-tool {
    background: var(--accent-soft);
    color: var(--primary-hover);
    border-color: var(--primary);
}

/* Фильтры */
.filters-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filters-row input {
    flex: 2 1 240px;
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
}

.filters-row select {
    flex: 1 1 160px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 13.5px;
    background-color: var(--surface);
    color: var(--text);
}

/* Таблица */
.table-card {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05);
    overflow-x: auto;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th, td {
    height: 76px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

th {
    height: 46px;
    background: var(--surface-subtle);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    white-space: nowrap;
}

tbody tr {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--surface-subtle);
}

.patient-name-link {
    color: var(--text);
    font-weight: 700;
    border-bottom: 1px dashed transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
}

tbody tr:hover .patient-name-link {
    color: var(--primary-hover);
    border-bottom-color: var(--primary-hover);
}

.patient-sub {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 230px;
}

.scans-pill {
    display: inline-flex;
    align-items: center;
    background: var(--accent-soft);
    color: var(--primary-hover);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    margin-left: 6px;
    white-space: nowrap;
    line-height: 1.2;
}

.tag-badge {
    display: inline-flex;
    align-items: center;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 6px;
    margin-left: 6px;
}

.note-preview {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.35;
    max-width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.actions-cell {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    height: 76px;
    white-space: nowrap;
    cursor: default;
}

/* Пагинация */
.pagination-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
    margin-top: 18px;
}

.pagination-info {
    font-size: 13.5px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 16px;
    overflow-y: auto;
}

.modal-top {
    z-index: 200;
}

.modal-content {
    background: var(--surface);
    color: var(--text);
    padding: 24px;
    border-radius: 12px;
    width: 100%;
    max-width: 520px;
    position: relative;
    max-height: 92vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.modal-confirm {
    max-width: 420px;
}

.modal-wide {
    max-width: 720px;
}

.section-sub-title {
    font-size: 15px;
    margin-bottom: 8px;
}

.account-block {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.audit-list {
    max-height: 180px;
    overflow-y: auto;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.audit-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--border);
}

.audit-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.share-url-box {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.share-url-box input {
    flex: 1;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--input-border);
    border-radius: 7px;
    font-size: 12.5px;
    background: var(--input-bg);
    color: var(--text);
}

.share-status-note {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

.card-top-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 32px;
    gap: 10px;
    flex-wrap: wrap;
}

.close-btn {
    position: absolute;
    right: 18px;
    top: 14px;
    width: 32px;
    height: 32px;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    background: transparent;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.form-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

.form-group {
    margin: 12px 0;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--input-bg);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--surface);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.16);
}

.file-drop-area {
    border: 1.5px dashed var(--input-border);
    padding: 14px;
    text-align: center;
    border-radius: 8px;
    background: var(--surface-subtle);
}

.file-drop-area p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.patient-meta {
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    margin: 12px 0;
    line-height: 1.6;
}

.scans-section {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 15px;
}

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

.scans-header h3 {
    font-size: 16px;
}

.add-scan-box {
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    padding: 14px;
    border-radius: 8px;
    margin-bottom: 14px;
}

.scans-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.scan-card-block {
    border: 1px solid var(--border);
    padding: 14px;
    border-radius: 10px;
    background: var(--surface-subtle);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.scan-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.scan-item-info strong {
    font-size: 14px;
}

.scan-item-info small {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 3px;
}

.scan-assets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
}

.asset-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.asset-box-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
}

.asset-box-meta {
    font-size: 11.5px;
    color: var(--text-muted);
}

.asset-box-btns {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.modal-footer-btns {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    gap: 10px;
}

/* Вьюер — без дёрганья при масштабировании */
.viewer-window {
    max-width: 1360px;
    width: 96vw;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

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

.viewer-header h3 {
    font-size: 18px;
    color: var(--text);
}

.viewer-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.viewer-scan-select {
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    font-size: 12.5px;
    background-color: var(--input-bg);
    color: var(--text);
    max-width: 240px;
}

.viewer-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--text);
    flex-wrap: wrap;
    min-height: 54px;
}

.viewer-toolbar label {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.presets-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.zoom-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.zoom-label {
    min-width: 44px;
    text-align: center;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.slice-status-pill {
    margin-left: auto;
    color: var(--primary-hover);
    font-weight: 600;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.real-viewer-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 18px;
    align-items: stretch;
}

.real-viewer-layout.single-column {
    grid-template-columns: 1fr;
}

.canvas-panel {
    background: #050911;
    border: 1px solid var(--border);
    border-radius: 12px;
    height: clamp(560px, 72vh, 800px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    overflow: hidden;
    position: relative;
    user-select: none;
    touch-action: none;
    box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.4);
}

.media-stage {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    max-width: 100%;
    transform-origin: center center;
    will-change: transform;
    cursor: grab;
}

.media-stage.is-dragging {
    cursor: grabbing;
}

.media-stage.is-measuring {
    cursor: crosshair;
}

#dicomCanvas {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    background: #000;
    border-radius: 6px;
    image-rendering: pixelated;
    display: block;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

#dicomImageView {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
    display: block;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

.ruler-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.ruler-readout-box {
    font-size: 12.5px;
    color: var(--text-muted);
    background: var(--surface);
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    line-height: 1.45;
}

.fallback-box {
    text-align: center;
    padding: 20px;
    color: #e2e8f0;
    font-size: 14px;
}

.scan-sim {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    border: 2px dashed #64748b;
    background: radial-gradient(circle, #cbd5e1 10%, #334155 45%, #0f172a 75%);
    margin: 16px auto 0;
}

.slice-controls-panel {
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    color: var(--text);
}

.slice-nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.slice-meta {
    font-size: 13px;
    line-height: 1.4;
    color: var(--text);
    overflow: hidden;
}

#currentSliceFile {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 3px;
}

.step-btns {
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-btns .btn {
    flex: 1;
}

.stack-progress-box {
    font-size: 12.5px;
    color: var(--text-muted);
    background: var(--surface);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    line-height: 1.45;
}

.mode-btns-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

/* Оценка и комментарий под снимком */
.viewer-review-box {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.review-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.star-rating {
    display: inline-flex;
    gap: 4px;
}

.star-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: #94a3b8;
    padding: 2px;
}

.star-btn.active {
    color: #f59e0b;
}

.review-form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.review-form-row input {
    flex: 1;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--input-border);
    border-radius: 7px;
    font-size: 13.5px;
    background: var(--input-bg);
    color: var(--text);
}

@media (max-width: 820px) {
    .real-viewer-layout {
        grid-template-columns: 1fr;
    }

    .viewer-header {
        flex-direction: column;
        align-items: stretch;
    }

    .navbar {
        padding: 12px 16px;
        flex-wrap: wrap;
    }
}

/* Адаптация под телефоны (до 768px) */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }

    .toast-container {
        left: 12px;
        right: 12px;
        bottom: 12px;
        max-width: none;
    }

    .navbar {
        padding: 12px 14px;
        min-height: auto;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .logo {
        font-size: 19px;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 8px;
    }

    .brand-full-logo {
        height: 32px;
        max-width: 125px;
    }

    .auth-card {
        padding: 32px 20px 24px;
        border-radius: 16px;
    }

    .auth-theme-btn {
        top: 14px;
        right: 14px;
        height: 29px;
        padding: 0 10px;
        font-size: 11.5px;
    }

    .auth-brand-logo {
        height: 44px;
        max-width: 195px;
    }

    .free-badge {
        height: 24px;
        padding: 0 9px;
        font-size: 11px;
    }

    .doctor-profile {
        width: 100%;
        height: auto;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    .nav-status-pill {
        flex: 1 1 auto;
        justify-content: center;
        height: 36px;
        padding: 0 10px;
        font-size: 11.5px;
    }

    .nav-doctor-chip {
        flex: 1 1 auto;
        justify-content: center;
        height: 36px;
        padding: 0 10px 0 6px;
    }

    .nav-btn-group {
        width: 100%;
        display: flex;
        gap: 6px;
    }

    .nav-action-btn {
        flex: 1;
        height: 36px;
        padding: 0 8px;
        font-size: 12.5px;
    }

    .container {
        margin: 18px auto;
        padding: 0 12px;
    }

    .top-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .top-controls h1 {
        font-size: 20px;
    }

    .top-controls .btn {
        width: 100%;
        height: 42px;
    }

    .filters-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        margin-bottom: 14px;
    }

    .filters-row input,
    .filters-row select {
        width: 100%;
        flex: none;
        height: 42px;
    }

    .table-card {
        background: transparent;
        border: none;
        box-shadow: none;
        overflow: visible;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
        width: 100%;
    }

    thead {
        display: none;
    }

    tbody tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 12px 14px;
        margin-bottom: 12px;
        box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05);
    }

    th,
    td {
        height: auto;
        padding: 5px 0;
        border-bottom: none;
    }

    .patient-sub,
    .note-preview {
        max-width: 100%;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }

    .actions-cell {
        height: auto;
        padding-top: 10px;
        margin-top: 6px;
        border-top: 1px solid var(--border);
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .actions-cell .btn {
        height: 36px;
        padding: 0 12px;
    }

    .actions-cell .btn-primary {
        flex: 1 1 auto;
    }

    .modal {
        padding: 10px;
        align-items: flex-start;
    }

    .modal-content {
        padding: 18px 16px;
        max-height: 94vh;
        border-radius: 10px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .scan-card-top {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-footer-btns {
        flex-direction: column;
        align-items: stretch;
    }

    .modal-footer-btns .btn {
        width: 100%;
    }

    .viewer-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .viewer-controls {
        flex-wrap: wrap;
        gap: 6px;
    }

    .viewer-toolbar {
        gap: 8px;
        padding: 10px;
    }

    .viewer-toolbar label {
        width: 100%;
        justify-content: space-between;
    }

    .canvas-panel {
        height: 310px;
        padding: 8px;
    }

    #dicomCanvas,
    #dicomImageView {
        max-height: 290px;
    }

    .slice-controls-panel {
        padding: 12px;
        gap: 12px;
    }

    .review-form-row {
        flex-direction: column;
        align-items: stretch;
    }

    .review-form-row .btn {
        width: 100%;
    }
}

/* ============================================================
   ПОДВАЛ САЙТА (FOOTER)
   ============================================================ */
.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    margin-top: 60px;
    padding: 44px 0 28px;
    color: var(--text-muted);
    font-size: 13px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

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

.footer-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr 1.3fr;
    gap: 36px;
    margin-bottom: 36px;
}

.footer-col h4 {
    color: var(--text);
    font-size: 13.5px;
    font-weight: 650;
    margin-bottom: 14px;
    letter-spacing: -0.01em;
}

.footer-brand-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    color: var(--text);
    margin-bottom: 10px;
}

.footer-brand-title strong {
    font-weight: 700;
}

.footer-badge {
    background: var(--accent-soft);
    color: var(--primary);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 6px;
    border: 1px solid rgba(13, 148, 136, 0.2);
}

.footer-desc {
    line-height: 1.55;
    font-size: 12.5px;
    margin-bottom: 14px;
}

.footer-compliance-tag {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 11.5px;
    color: var(--text);
}

.compliance-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.2);
}

.footer-nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.footer-nav-list li {
    line-height: 1.4;
    font-size: 12.5px;
}

.footer-link-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-muted);
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
    transition: color 0.15s ease;
}

.footer-link-btn:hover {
    color: var(--primary);
    text-decoration: underline;
}

.footer-contact-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.footer-contact-link:hover {
    text-decoration: underline;
}

.footer-nav-label {
    color: var(--text-muted);
    margin-right: 4px;
}

.footer-disclaimer {
    font-size: 12px;
    line-height: 1.55;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 10px;
    color: var(--text-muted);
}

.footer-bottom-bar {
    padding-top: 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
}

.footer-system-state {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
}

.pulse-green-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* Ссылки под карточкой авторизации */
.auth-wrapper {
    flex-direction: column;
    gap: 16px;
}

/* Юридический блок в карточке авторизации */
.auth-legal-box {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.auth-security-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(13, 148, 136, 0.08);
    border: 1px solid rgba(13, 148, 136, 0.22);
    color: var(--primary);
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    line-height: 1.3;
}

body.theme-dark .auth-security-badge {
    background: rgba(45, 212, 191, 0.09);
    border-color: rgba(45, 212, 191, 0.22);
    color: #2dd4bf;
}

.auth-security-badge:hover {
    background: rgba(13, 148, 136, 0.16);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.auth-security-badge .security-shield-icon {
    flex-shrink: 0;
}

.auth-legal-links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 11.5px;
    color: var(--text-muted);
}

.auth-legal-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-muted);
    font-size: 11.5px;
    cursor: pointer;
    transition: color 0.15s ease;
}

.auth-legal-link:hover {
    color: var(--primary);
    text-decoration: underline;
}

.auth-legal-dot {
    opacity: 0.35;
    font-size: 12px;
    user-select: none;
}

/* ============================================================
   ПЛАВАЮЩИЙ БАННЕР COOKIE
   ============================================================ */
.cookie-banner {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    max-width: 480px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.16);
    padding: 18px 20px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.cookie-banner.visible {
    opacity: 1;
    transform: translateY(0);
}

.cookie-banner-inner {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cookie-icon-wrapper {
    font-size: 26px;
    line-height: 1;
}

.cookie-heading {
    font-size: 14px;
    font-weight: 650;
    color: var(--text);
    margin-bottom: 5px;
}

.cookie-text {
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-muted);
    margin: 0;
}

.cookie-more-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font-weight: 550;
    cursor: pointer;
    text-decoration: underline;
}

.cookie-btn-group {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.cookie-btn-group .btn {
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 8px;
}

/* ============================================================
   МОДАЛЬНОЕ ОКНО ПРАВОВОЙ ИНФОРМАЦИИ
   ============================================================ */
.modal-legal {
    max-width: 820px;
    padding: 0;
    display: flex;
    flex-direction: column;
    max-height: 88vh;
    border-radius: 16px;
}

.legal-modal-header {
    padding: 22px 24px 14px;
    border-bottom: 1px solid var(--border);
}

.legal-modal-header h2 {
    font-size: 18px;
    margin-bottom: 14px;
    color: var(--text);
}

.legal-tabs-row {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.legal-tab-btn {
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.legal-tab-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.legal-tab-btn.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.legal-scroll-area {
    padding: 22px 24px;
    overflow-y: auto;
    flex: 1;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
}

.legal-pane {
    display: none;
}

.legal-pane.active {
    display: block;
}

.legal-pane h3 {
    font-size: 16px;
    margin-bottom: 4px;
    color: var(--text);
}

.legal-date {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.legal-pane h4 {
    font-size: 13.5px;
    margin: 18px 0 8px;
    color: var(--text);
}

.legal-pane p {
    margin-bottom: 10px;
    color: var(--text);
}

.legal-pane ul {
    padding-left: 20px;
    margin-bottom: 14px;
}

.legal-pane li {
    margin-bottom: 6px;
}

.legal-table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 12px;
}

.legal-table th,
.legal-table td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.legal-table th {
    background: var(--surface-subtle);
    font-weight: 600;
}

.legal-table code {
    background: var(--surface-subtle);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11.5px;
}

.legal-modal-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    background: var(--surface-subtle);
    border-radius: 0 0 16px 16px;
}

/* Адаптив для футера и cookie на мобильных */
@media (max-width: 900px) {
    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: 24px;
    }
}

@media (max-width: 600px) {
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .cookie-banner {
        left: 12px;
        right: 12px;
        bottom: 12px;
        max-width: none;
    }

    .legal-tabs-row {
        gap: 4px;
    }

    .legal-tab-btn {
        padding: 6px 9px;
        font-size: 11.5px;
    }
}