/*
 * Дизайн-система веб-интерфейса «Контроль закупок ЛП» (SA §10.1, NFR-UX-002).
 * Ширина от 1366 px; Chrome, Edge, Яндекс Браузер, Firefox. Шрифты — системные (CSP font-src 'self').
 * Разделы: токены, база, вход, оболочка, кнопки и формы, состояния, бейджи, таблицы, фильтры, пагинация,
 * вкладки, шкала этапов, окна и панели, загрузка файлов, шапка (поиск, колокольчик), профиль, уведомления, печать.
 */

:root {
    --color-primary: #1d4f91;
    --color-primary-hover: #163d70;
    --color-primary-soft: #e7eef8;
    --color-text: #1b2430;
    --color-text-muted: #5b6676;
    --color-border: #d5dbe3;
    --color-border-strong: #b9c2cf;
    --color-bg: #f3f5f8;
    --color-surface: #ffffff;
    --color-surface-alt: #f8f9fb;
    --color-success: #1e7d4f;
    --color-success-soft: #e3f4ea;
    --color-warning: #8a5a00;
    --color-warning-soft: #fff3d6;
    --color-danger: #b42318;
    --color-danger-soft: #fde8e6;
    --color-info: #1e5aa8;
    --color-info-soft: #e5effb;
    --color-neutral: #4a5565;
    --color-neutral-soft: #eceff3;
    --color-critical: #7a0916;
    --color-focus: #2f80ed;
    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.18);
    --header-height: 56px;
    --nav-width: 232px;
    --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ── База ── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 14px;
}

body {
    margin: 0;
    min-width: 1280px;
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.45;
    color: var(--color-text);
    background: var(--color-bg);
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

h1, h2, h3 {
    margin: 0 0 0.5em;
    line-height: 1.25;
}

code {
    font-family: var(--font-mono);
    font-size: 0.92em;
}

[hidden] {
    display: none !important;
}

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

.hint {
    margin: 0.35rem 0 0;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.nowrap {
    white-space: nowrap;
}

.noscript-banner {
    padding: 0.75rem 1rem;
    text-align: center;
    color: #fff;
    background: var(--color-danger);
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 8px;
    z-index: 1000;
    padding: 0.5rem 0.75rem;
    color: #fff;
    background: var(--color-primary);
    border-radius: var(--radius);
}

.skip-link:focus {
    top: 8px;
}

/* ── Страница входа ── */
.page-login {
    min-height: 100vh;
}

.login-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background: linear-gradient(160deg, #e7eef8 0%, #f3f5f8 55%, #e9f3ee 100%);
}

.login-card {
    width: 420px;
    padding: 2rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-brand {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1.5rem;
}

.login-brand-title {
    font-weight: 600;
}

.login-brand-sub {
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.login-title {
    font-size: 1.35rem;
}

.login-form {
    margin-top: 1rem;
}

.login-hint {
    margin: 1.25rem 0 0;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* ── Оболочка приложения ── */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    gap: 1rem;
    align-items: center;
    height: var(--header-height);
    padding: 0 1rem;
    color: #fff;
    background: var(--color-primary);
    box-shadow: var(--shadow);
}

.app-brand {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
}

.app-brand:hover {
    text-decoration: none;
}

.env-badge {
    padding: 0.15rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-warning);
    background: var(--color-warning-soft);
    border-radius: 999px;
}

.header-search {
    flex: 1 1 auto;
    max-width: 560px;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-left: auto;
}

.user-menu {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.user-menu-link {
    display: flex;
    flex-direction: column;
    color: #fff;
    line-height: 1.15;
    text-align: right;
}

.user-name {
    font-weight: 600;
}

.user-role {
    font-size: 0.8rem;
    opacity: 0.85;
}

.user-menu .btn-ghost {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.4);
}

.user-menu .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.12);
}

.app-header .sidebar-toggle,
.app-header .bell-button {
    color: #fff;
}

.app-header .sidebar-toggle:hover,
.app-header .bell-button:hover {
    background: rgba(255, 255, 255, 0.12);
}

.app-body {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
}

.app-nav {
    position: sticky;
    top: var(--header-height);
    flex: 0 0 var(--nav-width);
    align-self: flex-start;
    width: var(--nav-width);
    height: calc(100vh - var(--header-height));
    padding: 0.75rem 0;
    overflow-y: auto;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
}

.nav-collapsed .app-nav {
    display: none;
}

.nav-group + .nav-group {
    margin-top: 0.5rem;
}

.nav-group-title {
    padding: 0.4rem 1rem 0.2rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    text-transform: uppercase;
}

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

.nav-link {
    display: block;
    padding: 0.4rem 1rem;
    color: var(--color-text);
    border-left: 3px solid transparent;
}

.nav-link:hover {
    text-decoration: none;
    background: var(--color-surface-alt);
}

.nav-link.is-active {
    font-weight: 600;
    color: var(--color-primary);
    background: var(--color-primary-soft);
    border-left-color: var(--color-primary);
}

.nav-link.is-pending {
    color: var(--color-text-muted);
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    padding: 1.25rem 1.5rem 2rem;
    outline: none;
}

.page-header {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.page-title {
    margin: 0;
    font-size: 1.45rem;
}

.page-actions {
    display: flex;
    gap: 0.5rem;
}

.page-loading {
    padding: 2rem;
    color: var(--color-text-muted);
    text-align: center;
}

.page-placeholder {
    max-width: 640px;
    margin: 3rem auto;
    padding: 2rem;
    text-align: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

/* ── Карточки ── */
.card {
    padding: 1.1rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 1.1rem;
}

.card .hint + .btn {
    margin-top: 0.75rem;
}

.props {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.35rem 1rem;
    margin: 0;
}

.props dt {
    color: var(--color-text-muted);
}

.props dd {
    margin: 0;
}

/* ── Кнопки ── */
.btn {
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0.4rem 0.9rem;
    font: inherit;
    font-weight: 500;
    line-height: 1.2;
    color: var(--color-text);
    white-space: nowrap;
    cursor: pointer;
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
}

.btn:hover {
    text-decoration: none;
    background: var(--color-surface-alt);
}

.btn:disabled,
.btn[aria-busy="true"] {
    cursor: not-allowed;
    opacity: 0.6;
}

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

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

.btn-secondary {
    color: var(--color-primary);
    background: var(--color-surface);
    border-color: var(--color-primary);
}

.btn-secondary:hover {
    background: var(--color-primary-soft);
}

.btn-ghost {
    color: var(--color-primary);
    background: transparent;
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--color-primary-soft);
}

.btn-danger {
    color: #fff;
    background: var(--color-danger);
    border-color: var(--color-danger);
}

.btn-danger:hover {
    background: #8f1c13;
}

.btn-sm {
    min-height: 28px;
    padding: 0.2rem 0.6rem;
    font-size: 0.9rem;
}

.btn-block {
    width: 100%;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--color-text-muted);
    cursor: pointer;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* ── Формы ── */
.form-field {
    margin-bottom: 0.9rem;
}

.form-field label,
.filter-label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    align-items: center;
    margin: 0.5rem 0;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 1rem;
}

.form-title {
    margin-top: 1.25rem;
    font-size: 1rem;
}

.form-error,
.field-error {
    margin-top: 0.35rem;
    font-size: 0.9rem;
    color: var(--color-danger);
}

.form fieldset {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.form legend {
    padding: 0 0.35rem;
    font-weight: 600;
}

.input {
    width: 100%;
    min-height: 34px;
    padding: 0.35rem 0.6rem;
    font: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
}

.input:focus {
    border-color: var(--color-focus);
    outline: none;
    box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.2);
}

.input-sm {
    width: auto;
    min-height: 28px;
    padding: 0.15rem 0.45rem;
}

textarea.input {
    resize: vertical;
}

.check {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
    margin: 0.2rem 1rem 0.2rem 0;
    font-weight: 400;
    cursor: pointer;
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.15rem 1rem;
    margin-top: 0.4rem;
}

.inline-field {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
}

.required {
    color: var(--color-danger);
}

/* ── Сообщения и состояния ── */
.alert {
    margin: 0.75rem 0;
    padding: 0.6rem 0.85rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
}

.alert-danger {
    color: var(--color-danger);
    background: var(--color-danger-soft);
    border-color: #f5c2bd;
}

.alert-info {
    color: var(--color-info);
    background: var(--color-info-soft);
    border-color: #c5d8f2;
}

.alert-warning {
    color: var(--color-warning);
    background: var(--color-warning-soft);
    border-color: #f0d590;
}

/* Текст предупреждения о внешнем контуре ИИ: абзацы из warning_text */
.consent-text {
    white-space: pre-line;
}

/* Действия строки контура ИИ (#admin/ai-contours) */
.contour-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    min-width: 12rem;
}

.state {
    padding: 1.5rem;
    text-align: center;
    border-radius: var(--radius);
}

.state p {
    margin: 0 0 0.75rem;
}

.state-empty {
    color: var(--color-text-muted);
    background: var(--color-surface);
    border: 1px dashed var(--color-border-strong);
}

.state-error {
    color: var(--color-danger);
    background: var(--color-danger-soft);
}

.toast {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 400;
    min-width: 280px;
    max-width: 440px;
    padding: 0.75rem 1rem;
    color: #fff;
    background: #263445;
    border-left: 4px solid var(--color-info);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    border-left-color: #3cc47c;
}

.toast-warning {
    border-left-color: #f2b84b;
}

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

.toast-title {
    font-weight: 600;
}

.toast-sub {
    margin-top: 0.15rem;
    font-size: 0.9rem;
    opacity: 0.85;
}

.toast-sub:empty {
    display: none;
}

/* ── Бейджи ── */
.badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    border-radius: 999px;
}

.badge-success { color: var(--color-success); background: var(--color-success-soft); }
.badge-warning { color: var(--color-warning); background: var(--color-warning-soft); }
.badge-danger { color: var(--color-danger); background: var(--color-danger-soft); }
.badge-info { color: var(--color-info); background: var(--color-info-soft); }
.badge-neutral { color: var(--color-neutral); background: var(--color-neutral-soft); }

.severity-critical { color: #fff; background: var(--color-critical); }
.severity-error { color: #fff; background: var(--color-danger); }
.severity-warning { color: var(--color-warning); background: var(--color-warning-soft); }
.severity-info { color: var(--color-info); background: var(--color-info-soft); }

.source-badge {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
    padding: 0 0.4rem;
    font-size: 0.75rem;
    white-space: nowrap;
    border: 1px solid currentColor;
    border-radius: var(--radius);
}

.source-success { color: var(--color-success); }
.source-warning { color: var(--color-warning); }
.source-info { color: var(--color-info); }
.source-neutral { color: var(--color-neutral); }

.source-link {
    color: inherit;
}

.field-value {
    font-weight: 500;
}

.money {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.money-negative {
    color: var(--color-danger);
}

.money-delta {
    font-size: 0.9em;
    color: var(--color-success);
}

.money-delta.money-negative {
    color: var(--color-danger);
}

.entity-link {
    font-weight: 500;
}

/* ── Таблицы ── */
.data-table-host {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.data-table-toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--color-border);
}

.column-picker {
    position: relative;
}

.column-picker summary {
    list-style: none;
}

.column-picker-menu {
    position: absolute;
    right: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    min-width: 240px;
    max-height: 360px;
    padding: 0.5rem 0.75rem;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.data-table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.data-table caption {
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    text-align: left;
}

.data-table th,
.data-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--color-border);
}

.data-table thead th {
    position: sticky;
    top: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-surface-alt);
}

.data-table tbody tr:hover {
    background: var(--color-surface-alt);
}

.data-table tr.is-clickable {
    cursor: pointer;
}

.data-table tr.is-selected {
    background: var(--color-primary-soft);
}

/* Просроченные строки очередей (SLA-04 в #failures) */
.data-table tr.is-overdue td {
    background: var(--color-danger-soft);
}

/* Строки итогов таблиц показателей, отчётов и главной (WP-19.1) */
.data-table tfoot th,
.data-table tfoot td {
    font-weight: 600;
    background: var(--color-surface-alt);
    border-top: 2px solid var(--color-border-strong);
}

.align-right { text-align: right !important; }
.align-center { text-align: center !important; }

.col-select {
    width: 36px;
}

.th-sort {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    background: none;
    border: 0;
}

.sort-indicator::after {
    content: "↕";
    opacity: 0.35;
}

.sort-ascending::after {
    content: "↑";
    opacity: 1;
}

.sort-descending::after {
    content: "↓";
    opacity: 1;
}

.table-state {
    padding: 1.5rem !important;
    color: var(--color-text-muted);
    text-align: center !important;
}

.table-state-error {
    color: var(--color-danger);
}

.diff-added td:last-child { background: var(--color-success-soft); }
.diff-removed td:nth-child(2) { background: var(--color-danger-soft); }
.diff-changed td:last-child { background: var(--color-warning-soft); }

.diff-value {
    word-break: break-word;
}

/* ── Фильтры ── */
.filter-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: flex-end;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.filter-field {
    min-width: 180px;
}

.filter-search {
    min-width: 280px;
}

.filter-label {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.range-inputs {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.filter-actions {
    margin-left: auto;
}

.multi-select {
    position: relative;
}

.multi-select summary {
    cursor: pointer;
    list-style: none;
}

.multi-select-menu {
    position: absolute;
    z-index: 20;
    display: flex;
    flex-direction: column;
    min-width: 240px;
    max-height: 320px;
    padding: 0.5rem 0.75rem;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

/* ── Пагинация ── */
.pagination {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.75rem;
}

.page-nav {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.page-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 0.5rem;
    font: inherit;
    cursor: pointer;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.page-btn.is-current {
    font-weight: 600;
    color: #fff;
    background: var(--color-primary);
    border-color: var(--color-primary);
}

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

.page-gap {
    padding: 0 0.25rem;
    color: var(--color-text-muted);
}

.page-size {
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
    color: var(--color-text-muted);
}

/* ── Вкладки ── */
.tab-list {
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--color-border);
}

.tab {
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
    padding: 0.55rem 0.9rem;
    font: inherit;
    color: var(--color-text-muted);
    white-space: nowrap;
    cursor: pointer;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
}

.tab.is-active {
    font-weight: 600;
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tab-badge {
    padding: 0 0.4rem;
    font-size: 0.75rem;
    background: var(--color-neutral-soft);
    border-radius: 999px;
}

.tab-panel {
    padding: 1rem 0;
    outline: none;
}

/* ── Шкала этапов ── */
.stage-timeline {
    display: flex;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: none;
}

.stage-step {
    position: relative;
    flex: 1 1 0;
    padding: 0 0.5rem;
    text-align: center;
}

.stage-step::before {
    position: absolute;
    top: 14px;
    right: 50%;
    left: -50%;
    height: 2px;
    content: "";
    background: var(--color-border);
}

.stage-step:first-child::before {
    display: none;
}

.stage-marker {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border: 2px solid var(--color-border-strong);
    border-radius: 50%;
}

.stage-label {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.85rem;
}

.stage-date {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.stage-done .stage-marker {
    color: #fff;
    background: var(--color-success);
    border-color: var(--color-success);
}

.stage-done::before,
.stage-current::before {
    background: var(--color-success);
}

.stage-current .stage-marker {
    color: #fff;
    background: var(--color-primary);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px var(--color-primary-soft);
}

.stage-current .stage-label {
    font-weight: 600;
}

.stage-skipped .stage-marker {
    border-style: dashed;
}

/* ── Модальные окна и боковая панель ── */
body.has-modal,
body.has-drawer {
    overflow: hidden;
}

.modal-overlay,
.drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(16, 24, 40, 0.45);
}

.modal-overlay {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 1rem 1rem;
    overflow-y: auto;
}

/* Окно под верхним окном стека (CR-WP-27-4): страницу затемняет только верхний слой */
.modal-overlay.modal-overlay-covered {
    background: transparent;
}

.modal-card {
    width: 520px;
    max-width: 100%;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.modal-card.wide {
    width: 880px;
}

.modal-header,
.drawer-header {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-title,
.drawer-title {
    margin: 0;
    font-size: 1.1rem;
}

.modal-body {
    padding: 1rem 1.1rem 1.1rem;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.confirm-message {
    margin-top: 0;
}

.drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
    outline: none;
}

.drawer-sm { width: 420px; }
.drawer-md { width: 640px; }
.drawer-lg { width: 960px; }

.drawer-body {
    flex: 1 1 auto;
    padding: 1rem 1.1rem;
    overflow-y: auto;
}

/* ── Загрузка файлов ── */
.dropzone {
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    background: var(--color-surface-alt);
    border: 2px dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
    background: var(--color-primary-soft);
    border-color: var(--color-primary);
}

.dropzone.is-disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.dropzone-label {
    font-weight: 600;
}

.dropzone-hint {
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.dropzone-files {
    margin: 0.5rem 0 0;
    padding: 0;
    list-style: none;
}

.dropzone-file {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 0.3rem 0;
}

.file-name {
    flex: 1 1 auto;
    word-break: break-all;
}

.file-size {
    color: var(--color-text-muted);
}

.dropzone-errors {
    color: var(--color-danger);
}

/* ── Шапка: поиск ── */
.search-box {
    position: relative;
}

.search-input {
    color: var(--color-text);
    border-color: transparent;
}

.search-suggest {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    left: 0;
    z-index: 60;
    margin: 0;
    padding: 0.25rem 0;
    overflow: hidden;
    color: var(--color-text);
    list-style: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.search-option {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 0 0.5rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
}

.search-option:hover,
.search-option.is-active {
    background: var(--color-primary-soft);
}

.search-type {
    grid-row: span 2;
    font-size: 0.78rem;
    color: var(--color-text-muted);
}

.search-title {
    font-weight: 500;
}

.search-subtitle {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.search-empty {
    padding: 0.5rem 0.75rem;
    color: var(--color-text-muted);
}

/* ── Шапка: колокольчик ── */
.header-bell {
    position: relative;
}

.bell-button {
    position: relative;
}

.bell-button.is-unavailable {
    opacity: 0.55;
}

.bell-count {
    position: absolute;
    top: 2px;
    right: 0;
    min-width: 18px;
    padding: 0 4px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 18px;
    color: #fff;
    text-align: center;
    background: var(--color-danger);
    border-radius: 999px;
}

.bell-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 60;
    width: 380px;
    padding: 0.5rem 0;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

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

.bell-item {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.5rem 0.85rem;
    border-bottom: 1px solid var(--color-border);
}

.bell-item .badge {
    flex: 0 0 auto;
    min-width: 22px;
    text-align: center;
}

.bell-item-text {
    display: flex;
    flex-direction: column;
}

.bell-item-time {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.bell-empty {
    margin: 0;
    padding: 0.75rem 0.85rem;
    color: var(--color-text-muted);
}

.bell-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.85rem 0.25rem;
}

.bell-all {
    padding: 0.5rem 0.85rem;
    font-weight: 500;
}

/* ── Профиль ── */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.card-wide {
    grid-column: 1 / -1;
}

.permissions {
    margin-top: 0.75rem;
}

.permissions summary {
    color: var(--color-primary);
    cursor: pointer;
}

.permissions ul {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
    columns: 2;
}

.bot-platforms {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.bot-platform {
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.bot-platform-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.bot-platform-actions {
    margin-top: 0.5rem;
}

.bot-code {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--color-primary-soft);
    border-radius: var(--radius);
}

.bot-code-value {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    user-select: all;
}

.bot-code-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.bot-code-timer {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.bot-code-expired {
    background: var(--color-warning-soft);
}

.channel-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
    padding: 0.35rem 0;
}

.channel-row .hint {
    flex-basis: 100%;
    margin: 0;
}

.events-picker summary {
    margin-top: 0.5rem;
    color: var(--color-primary);
    cursor: pointer;
}

/* ── Уведомления ── */
.notification-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.notification-item {
    padding: 0.75rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-border);
    border-radius: var(--radius);
}

.notification-item.is-unread {
    border-left-color: var(--color-primary);
}

.notification-meta {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.notification-title {
    margin: 0.35rem 0 0.25rem;
    font-size: 1rem;
}

.notification-item.is-unread .notification-title {
    font-weight: 700;
}

.notification-body {
    margin: 0;
    white-space: pre-wrap;
}

.notification-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* ── Чат ИИ-ассистента (WP-19.2): лента сообщений, ответ, чипы ссылок ── */
.notification-list[data-thread] {
    margin: 0.75rem 0 1rem;
}

.ai-answer > :first-child {
    margin-top: 0;
}

.ai-answer p,
.ai-answer ul,
.ai-answer ol,
.ai-answer table {
    margin: 0 0 0.5rem;
}

.ai-references {
    flex-wrap: wrap;
}

.ai-ref + .ai-ref {
    margin-left: 0.25rem;
}

/* ── W20 (WP-44): рабочая таблица, ячейки по серьёзности, индикаторы причин, «ДС в работе» ──
 * Только классы: CSP style-src 'self' запрещает атрибут style (SEC-L-06). Критично — отдельный цвет (Р-2.15 п. 4). */
:root {
    --cell-critical-bg: #f9d7dc;
    --cell-critical-border: #7a0916;
    --fail-light-green: #c8f0c0;
    --fail-pink: #f8c8dc;
    --fail-swamp: #8a8a4e;
    --row-ds-in-progress: #f1e8fb;
    --row-ds-in-progress-border: #7b4bb3;
}

.work-table-host .data-table-wrap {
    max-height: calc(100vh - 260px);
    overflow: auto;
}

.data-table.data-table-dense th,
.data-table.data-table-dense td {
    padding: 0.3rem 0.45rem;
    font-size: 0.86rem;
}

.data-table tr.header-groups th {
    top: auto;
    position: static;
    font-size: 0.8rem;
    text-align: center;
    color: var(--color-text);
    background: var(--color-neutral-soft);
    border-right: 1px solid var(--color-border-strong);
}

.data-table .col-sticky {
    position: sticky;
    z-index: 2;
    background: var(--color-surface);
    box-sizing: border-box;
}

.data-table thead .col-sticky {
    z-index: 3;
    background: var(--color-surface-alt);
}

.data-table .col-sticky-1 { left: 0; min-width: 6.5rem; max-width: 6.5rem; }
.data-table .col-sticky-2 { left: 6.5rem; min-width: 9rem; max-width: 9rem; }
.data-table .col-sticky-3 { left: 15.5rem; min-width: 14rem; max-width: 14rem; border-right: 2px solid var(--color-border-strong); }

.wt-value {
    display: inline-block;
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.cell-sev-critical { background: var(--cell-critical-bg) !important; box-shadow: inset 0 0 0 2px var(--cell-critical-border); }
.cell-sev-error { background: var(--color-danger-soft) !important; }
.cell-sev-warning { background: var(--color-warning-soft) !important; }
.cell-sev-info { background: transparent; }
.cell-src-eis .wt-value::after {
    content: " ЕИС";
    font-size: 0.7rem;
    color: var(--color-info);
}

.cell-flag {
    margin-left: 0.25rem;
    padding: 0 0.3rem;
    font-size: 0.8rem;
    line-height: 1.3;
    color: var(--color-text);
    cursor: pointer;
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
}

.cell-flag-critical { color: #fff; background: var(--color-critical); border-color: var(--color-critical); }
.cell-flag-error { color: #fff; background: var(--color-danger); border-color: var(--color-danger); }
.cell-flag-warning { color: var(--color-warning); background: var(--color-warning-soft); border-color: var(--color-warning); }
.cell-flag-info { color: var(--color-info); background: var(--color-info-soft); border-color: var(--color-info); }
.cell-flag-reviewed { color: var(--color-success); background: var(--color-success-soft); border-color: var(--color-success); }

.data-table tr.row-ds-in-progress td {
    background: var(--row-ds-in-progress);
}

.data-table tr.row-ds-in-progress td:first-child {
    box-shadow: inset 4px 0 0 var(--row-ds-in-progress-border);
}

.data-table tr.is-critical td:first-child {
    box-shadow: inset 4px 0 0 var(--color-critical);
}

.badge-ds-in-progress { color: var(--row-ds-in-progress-border); background: var(--row-ds-in-progress); }
.row-ds-in-progress-swatch { background: var(--row-ds-in-progress); border-color: var(--row-ds-in-progress-border); }

.fail-ind {
    display: inline-block;
    width: 0.95rem;
    height: 0.95rem;
    margin-right: 0.15rem;
    padding: 0;
    vertical-align: middle;
    cursor: pointer;
    background: var(--color-neutral-soft);
    border: 1px solid var(--color-border-strong);
    border-radius: 3px;
}

.fail-ind-light_green { background: var(--fail-light-green); }
.fail-ind-pink { background: var(--fail-pink); }
.fail-ind-swamp { background: var(--fail-swamp); }
.fail-ind-inherited { opacity: 0.5; }

.cell-tooltip {
    position: fixed;
    z-index: 1200;
    max-width: 26rem;
    padding: 0.5rem 0.65rem;
    font-size: 0.85rem;
    color: #fff;
    pointer-events: none;
    background: #1b2430;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.cell-tooltip[hidden] {
    display: none;
}

.cell-tooltip-title {
    margin: 0 0 0.25rem;
    font-weight: 600;
}

.cell-tooltip-line {
    margin: 0;
    white-space: pre-wrap;
}

.cell-tooltip-line + .cell-tooltip-title {
    margin-top: 0.45rem;
}

.wt-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
    margin: 0.25rem 0 0.5rem;
    font-size: 0.85rem;
}

.wt-legend-swatch {
    display: inline-block;
    width: 1.1rem;
    height: 0.9rem;
    margin-right: 0.3rem;
    vertical-align: middle;
    border: 1px solid var(--color-border-strong);
    border-radius: 3px;
}

.wt-flag-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.wt-flag-item {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--color-border);
}

.wt-flag-item:last-child {
    border-bottom: 0;
}

.wt-flag-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.4rem;
}

.patient-names {
    margin: 0.25rem 0 0;
    padding-left: 1.2rem;
}

/* ── Печать ── */
@media print {
    body {
        min-width: 0;
        background: #fff;
    }

    .app-header,
    .app-nav,
    .toast,
    .page-actions,
    .filter-panel,
    .pagination,
    .skip-link {
        display: none !important;
    }

    .app-main {
        padding: 0;
    }

    .card,
    .data-table-host {
        border: 0;
        box-shadow: none;
    }
}
