/* ==========================================================================
   Общий стиль всех страниц. Образец — страница случая по макету
   docs/design/case.png; остальные макеты лежат там же (main.png, board.png,
   preview.png). Сначала цвета, потом общие детали, потом отдельные страницы.
   ========================================================================== */

/* Цвета. Меняйте их здесь — они действуют на всех страницах. */
:root {
  --ink: #141414;        /* основной текст, чёрные кнопки */
  --muted: #5c5c5c;      /* второстепенный текст */
  --line: #e2e2de;       /* рамки карточек и разделители */
  --border: #c9c9c4;     /* рамки кнопок и полей ввода */
  --dash: #85857f;       /* пунктир: «ещё нет», «добавить» */
  --tint: #f6f6f3;       /* светлая подложка: комментарии, заголовки таблиц */
  --page: #fafaf8;       /* фон страницы */
  --link: #1d5a96;       /* ссылки */
  --done: #0b6b1d;       /* зелёная точка «этап записан» */
  --focus: #b46a00;      /* рамка фокуса с клавиатуры */
  --ok-ink: #0b5a1a; --ok-bg: #d9f0d6;           /* зелёный чип */
  --info-ink: #1d4f8a; --info-bg: #d6e6fb;       /* синий чип и кружок-аватар */
  --warn-ink: #694310; --warn-bg: #fdf0d2; --warn-line: #e8cb91;  /* предупреждение */
  --danger-ink: #8f2626; --danger-bg: #f9dada;   /* ошибка, «просрочено» */
  --neutral-ink: #3d3d3a; --neutral-bg: #e9e9e4; /* серый чип */
  color-scheme: light; font-family: "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--page); line-height: 1.6;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); }
.container { width: min(100% - 32px, 960px); margin: 0 auto; }
main { padding-bottom: 32px; }
a { color: var(--link); text-underline-offset: 3px; overflow-wrap: anywhere; }
a:hover { color: var(--ink); }
a:focus-visible, input:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible,
summary:focus-visible, .board:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1 { font-size: clamp(24px, 3.2vw, 28px); line-height: 1.25; margin: 20px 0 12px; }
h2 { font-size: 20px; line-height: 1.3; }
h3 { font-size: 17px; line-height: 1.3; }
.muted { color: var(--muted); }
nav { display: flex; flex-wrap: wrap; gap: 10px 24px; margin: 24px 0; }
dt { font-weight: 600; margin-top: 16px; }
dd { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
dl { margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.link-like { color: var(--link); }
.case-reason, .attachment-description { white-space: pre-wrap; }
/* Номер телефона не разрывается на две строки. */
.phone-link { white-space: nowrap; overflow-wrap: normal; }

/* Шапка сайта: название слева, разделы справа, текущий раздел — жирным (main.png). */
.site-header { padding: 18px 0 4px; }
.site-header .container { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 24px; }
.brand { font-size: 22px; font-weight: 700; color: var(--ink); text-decoration: none; }
.site-header nav { margin: 0; gap: 4px 22px; }
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover { color: var(--ink); }
.site-header nav a[aria-current] { color: var(--ink); font-weight: 600; }
.notice { margin: 12px 0 0; padding: 6px 14px; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; color: var(--warn-ink); font-size: 14px; }
.message { padding: 10px 16px; border: 1px solid #a8d4a2; background: #eaf6e8; color: var(--ok-ink); border-radius: 10px; }

/* Путь «Главная › …» над шапкой страницы и ссылка «← назад» на формах. */
.path { margin: 20px 0 12px; gap: 2px 8px; align-items: baseline; color: var(--muted); }
.path a { color: var(--muted); text-decoration: none; }
.path a:hover { color: var(--ink); text-decoration: underline; }

/* Карточка — белый блок со скруглёнными углами. */
.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 20px 24px; margin: 0 0 16px; overflow-wrap: anywhere; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card-title { margin: 0 0 10px; font-size: 19px; line-height: 1.3; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 10px; }
.card-head .card-title { margin: 0; }
.empty-state { color: var(--muted); background: var(--tint); border: 1px dashed var(--dash); border-radius: 10px; padding: 12px 16px; margin: 0 0 12px; }

/* Шапка страницы внутри карточки: заголовок и строка сведений слева, кнопки справа. */
.head-top { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 16px; }
.head-main { flex: 1 1 280px; min-width: 0; }
.page-title { margin: 0; font-size: clamp(22px, 3.2vw, 28px); line-height: 1.25; white-space: pre-wrap; }
.page-meta { margin: 6px 0 0; color: var(--muted); }
.page-meta a { color: inherit; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }

/* Кнопки. Главная — чёрная (button, .button-link), обычная — белая с рамкой (.btn). */
input, button, select, textarea { font: inherit; }
button, .button-link { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 18px; background: var(--ink); color: #fff; border: 1px solid var(--ink); border-radius: 10px; cursor: pointer; text-decoration: none; }
a.button-link:hover, button:hover { background: #333; color: #fff; }
.btn, .button-link.secondary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 16px; background: #fff; color: var(--ink); border: 1px solid var(--border); border-radius: 10px; text-decoration: none; }
a.btn, a.button-link.secondary { color: var(--ink); }
.btn:hover, a.button-link.secondary:hover { background: var(--tint); color: var(--ink); }
.btn-icon { width: 44px; padding: 8px; }
.btn-wide { display: flex; width: 100%; min-height: 52px; font-size: 18px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 12px 0; }
.actions.small { gap: 6px 20px; margin-bottom: 0; }

/* Чипы — короткие цветные отметки: статус, «Д+34», «ОМС». */
.chip, .badge { display: inline-block; padding: 1px 10px; border-radius: 20px; font-size: 14px; font-weight: 600; line-height: 1.6; white-space: nowrap; }
.chip-ok { color: var(--ok-ink); background: var(--ok-bg); }
.chip-info { color: var(--info-ink); background: var(--info-bg); }
.chip-neutral, .badge-preliminary, .badge-done { color: var(--neutral-ink); background: var(--neutral-bg); }
.chip-warn, .badge-check { color: var(--warn-ink); background: var(--warn-bg); }
.chip-danger { color: var(--danger-ink); background: var(--danger-bg); }
/* Число рядом с заголовком колонки или группы. */
.count { color: var(--muted); font-weight: 400; font-size: 16px; white-space: nowrap; }

/* Кружок с буквами фамилии и имени (main.png, preview.png). */
.avatar { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 50%; background: var(--info-bg); color: var(--info-ink); font-weight: 600; font-size: 17px; }
.avatar-large { width: 64px; height: 64px; font-size: 21px; }

/* Вкладки: текст с подчёркиванием у выбранной. */
.tabs { margin: 24px 0 20px; gap: 0 28px; flex-wrap: nowrap; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 2px 9px; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; font-size: 18px; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
.tabs a:focus-visible { outline-offset: -3px; }

/* Строки списка внутри карточки, разделённые линией. */
.list-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:first-child { padding-top: 0; }
.list-item:last-child { border-bottom: 0; padding-bottom: 0; }
.list-item h3 { margin: 0 0 4px; }
.list-item p { margin: 4px 0; }
.list-item h3 a, .person-name a { color: var(--ink); text-decoration: none; }
.list-item h3 a:hover, .person-name a:hover { text-decoration: underline; }

/* Поля ввода и формы. */
label { display: block; font-weight: 600; margin-bottom: 8px; }
input, select, textarea { min-width: 0; padding: 10px 14px; background: #fff; color: var(--ink); border: 1px solid var(--border); border-radius: 10px; }
input { flex: 1; }
select { max-width: 100%; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger-ink); }
.patient-form { max-width: 620px; }
.form-field { margin-bottom: 24px; }
.form-field input { display: block; width: 100%; }
.form-field textarea { display: block; width: 100%; resize: vertical; }
.form-field .muted { margin: 0 0 8px; }
.field-error { color: var(--danger-ink); margin: 8px 0; }
.search-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
/* Строка поиска над списком: широкое поле, кнопка «Найти», справа — главная кнопка страницы. */
.search { margin: 0 0 16px; }
.search .search-controls input { min-height: 48px; font-size: 17px; }
.search-count { margin: 0 0 12px; }
.search .btn { min-height: 48px; }
.search-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.search-row .search { flex: 1 1 360px; margin: 0; }
.search-row .button-link { min-height: 48px; }
/* Заголовок страницы сразу под путём «← назад». */
.path + h1 { margin-top: 0; }

/* Предупреждения: возможный дубль пациента, коды МКБ-10 не проверены. */
.duplicate-warning, .catalogue-notice { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 12px; padding: 14px 16px; margin: 0 0 20px; color: var(--warn-ink); }
.duplicate-warning h2 { font-size: 18px; margin: 0 0 6px; }
.duplicate-warning p, .catalogue-notice p { margin: 6px 0; }
.duplicate-warning ul { margin: 6px 0; padding-left: 20px; }

/* Форма пациента (шаг 4б): ФИО тремя полями в строку (на телефоне — друг под другом),
   телефон из кода страны и номера, списки кодов и регионов с поиском, окно «Сохранить пациента?». */
.form-group { min-width: 0; padding: 0; border: 0; }
.form-group legend { padding: 0; margin-bottom: 8px; font-weight: 600; }
.form-note { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; padding: 8px 12px; color: var(--warn-ink); margin: 0 0 12px; }
.name-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
/* Подпись, поле и ошибка каждой части ФИО — на общих строках сетки: поля стоят ровно, даже если подпись переносится. */
.name-row { grid-template-rows: auto auto auto; row-gap: 0; }
.name-part { display: grid; grid-row: span 3; grid-template-rows: subgrid; align-content: start; }
.name-part label { align-self: end; }
.name-part input, .phone-row input { display: block; width: 100%; }
.phone-row { display: grid; grid-template-columns: 8.5em minmax(0, 1fr); gap: 12px; align-items: end; }
.phone-code { display: flex; align-items: center; gap: 6px; }
.phone-plus { font-size: 18px; font-weight: 600; }
.phone-preview { margin: 8px 0 0; }
.patient-form .form-field .phone-preview { margin: 8px 0 0; }
.combo { position: relative; }
.combo-list { position: absolute; left: 0; right: 0; z-index: 10; max-height: 280px; overflow-y: auto; margin: 4px 0 0; padding: 4px 0; list-style: none; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); }
.combo-list[hidden] { display: none; }
.phone-code-part .combo-list { right: auto; min-width: 16em; }
.combo-option { padding: 10px 14px; cursor: pointer; }
.combo-option:hover, .combo-option[aria-selected="true"] { background: var(--tint); }
.combo-own { border-top: 1px solid var(--line); color: var(--link); }
.copy-phone { margin-left: 4px; font-size: 15px; }
.copy-phone[hidden] { display: none; }
dialog.confirm-dialog { width: min(100% - 32px, 460px); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: #fff; color: var(--ink); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); }
dialog.confirm-dialog::backdrop { background: rgba(20, 20, 20, 0.5); }
.confirm-body { padding: 24px; }
.confirm-body h2 { margin: 0 0 12px; font-size: 20px; }
.confirm-summary { margin: 0 0 20px; }
.confirm-summary dt { margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.confirm-summary dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 10px; }
/* Форма приёма (шаг 7б): выбор пациента, дата с кнопками «Сегодня» и «Завтра». */
.appointment-form .search { margin: 0 0 12px; }
.appointment-form .search .search-controls input { flex: 1 1 220px; width: auto; }
.field-title { display: block; font-weight: 600; margin: 0 0 8px; }
.patient-choices { margin: 0; padding: 0; }
.patient-choices-title { margin: 0; }
.person-main { flex: 1 1 auto; min-width: 0; }
.person-main .person-meta { overflow-wrap: anywhere; }
.person .btn { flex: 0 0 auto; white-space: nowrap; }
.person.selected-patient, .person.selected-patient:last-child { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; }
.date-row .btn { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 480px) {
  .appointment-form .person { flex-wrap: wrap; gap: 8px 12px; }
  .appointment-form .person-main { flex: 1 1 150px; }
  .appointment-form .person .btn { margin-left: 60px; }
  .date-row .btn { flex: 1 1 auto; }
}
.date-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.form-field .date-row input { flex: 1 1 180px; width: auto; }
.date-row [hidden] { display: none; }
.confirm-dialog .confirm-body > .muted { margin: 0 0 16px; }
@media (max-width: 560px) {
  .name-row { grid-template-columns: 1fr; grid-template-rows: none; row-gap: 12px; }
  .name-part { grid-row: auto; grid-template-rows: none; }
  .phone-row { grid-template-columns: 7em minmax(0, 1fr); }
  .confirm-actions > * { flex: 1 1 100%; }
}

/* ==========================================================================
   Список пациентов (как «Недавние пациенты» на main.png).
   ========================================================================== */
.person-list { list-style: none; padding-top: 8px; padding-bottom: 8px; }
.person { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person-name { margin: 0; font-size: 17px; font-weight: 600; }
.person-meta { margin: 0; color: var(--muted); }

/* ==========================================================================
   Карточка пациента: шапка как у случая, вкладки, содержимое в карточках.
   ========================================================================== */
.patient-head .head-main { display: flex; align-items: center; gap: 16px; }
.patient-code { color: var(--muted); white-space: nowrap; }
.case-summary .card-title a { color: var(--ink); text-decoration: none; }
.case-summary .card-title a:hover { text-decoration: underline; }
.case-summary p { margin: 4px 0; }
.case-summary .card-title { margin: 8px 0 6px; }
.past-cases summary { cursor: pointer; color: var(--link); }
.past-cases ul { padding-left: 20px; margin-bottom: 0; }
/* Данные пациента: подпись слева, значение справа (как в preview.png). */
.facts { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; }
.facts dt, .facts dd { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line); }
.facts dt { font-weight: 400; color: var(--muted); }
.facts dt:last-of-type, .facts dd:last-of-type { border-bottom: 0; }

/* ==========================================================================
   Доска (board.png, шаг 9): шесть колонок сеткой по три, в колонке —
   карточки случаев. Вся карточка — ссылка на страницу случая.
   ========================================================================== */
.board-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px 24px; margin-top: 8px; }
.board-column h2 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0; font-size: 18px; }
.board-column h2 .count { font-weight: 400; color: var(--muted); }
.column-hint { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
.board-column .empty-state { margin: 0; }
a.board-card { display: block; padding: 14px 18px; margin-bottom: 12px; color: var(--ink); text-decoration: none; }
a.board-card:hover { border-color: var(--border); color: var(--ink); }
a.board-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.board-card h3 { margin: 0; font-size: 17px; }
.board-card-title { margin: 2px 0 8px; color: var(--muted); }
.board-card-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 4px; }
.board-card-foot { margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--line); }
.is-overdue { color: var(--danger-ink); }
@media (max-width: 860px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .board { grid-template-columns: 1fr; } }

/* Поиск и фильтры над доской (шаг 9, часть 2): поле поиска, «Просрочено N», «Сегодня N». */
.board-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 8px; }
.board-filters .board-search { flex: 1 1 360px; margin: 0; }
.board-search .search-controls input { flex: 1 1 200px; }
.board-chips-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0; }
a.filter-chip { min-height: 32px; display: inline-flex; align-items: center; text-decoration: none; border: 2px solid transparent; }
a.filter-chip:hover { border-color: currentColor; }
a.filter-chip.is-on { border-color: currentColor; }
.board-note { margin: 8px 0 12px; }
.board-empty p { margin: 4px 0; }
/* Чипы колонок: видны на телефоне (там доска — один список), а на компьютере — только
   когда выбрана одна колонка, чтобы можно было вернуться ко всем. */
.board-column-chips { display: none; gap: 8px; margin: 8px 0 16px; }
.board-column-chips.is-chosen { display: flex; flex-wrap: wrap; }
.board-column-chips a.chip { min-height: 36px; display: inline-flex; align-items: center; padding: 2px 12px; text-decoration: none; }
.chip-ink { color: #fff; background: var(--ink); }
a.chip-ink:hover { color: #fff; }
.board.is-one-column { grid-template-columns: minmax(0, 1fr); max-width: 560px; }
@media (max-width: 560px) {
  .board-column-chips { display: flex; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .board-note { display: none; }
}

/* Окно предпросмотра (preview.png). На телефоне выезжает снизу. */
dialog.board-preview { width: min(100% - 32px, 520px); max-height: calc(100% - 32px); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: #fff; color: var(--ink); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); }
dialog.board-preview::backdrop { background: rgba(20, 20, 20, 0.5); }
.board-preview-body { padding: 24px 28px; }
.preview-head { display: flex; align-items: center; gap: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.preview-person { flex: 1 1 auto; min-width: 0; }
.preview-name { margin: 0; font-size: 20px; }
.preview-person p { margin: 2px 0 0; }
.preview-head form { align-self: flex-start; margin: 0; }
.preview-close { border-color: transparent; font-size: 18px; }
.preview-case { padding: 14px 0 6px; }
.preview-procedure { margin: 0; font-weight: 600; }
.preview-diagnosis { margin: 2px 0 0; }
.preview-operation { margin: 8px 0 0; align-items: center; }
.preview-rows { margin: 0 0 12px; }
.preview-rows > div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; }
.preview-rows dt { margin: 0; font-weight: 400; color: var(--muted); }
.preview-rows dd { margin: 0; text-align: right; white-space: normal; }
.preview-rows .is-overdue dd { color: var(--danger-ink); }
.preview-hint, .move-hint { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; padding: 8px 12px; color: var(--warn-ink); margin: 0 0 12px; }
.preview-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview-actions .preview-move { grid-column: 1 / -1; }
@media (max-width: 560px) {
  dialog.board-preview { width: 100%; max-width: none; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 90%; }
  dialog.board-preview[open] { animation: preview-up 0.2s ease-out; }
  .board-preview-body { padding: 20px 16px; }
  .preview-actions { grid-template-columns: 1fr; }
}
@keyframes preview-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { dialog.board-preview[open] { animation: none; } }

/* Предложение переместить карточку после записи этапа (D11) и ссылки «Записать этап». */
.move-offer { background: var(--info-bg); border-radius: 12px; padding: 12px 16px; margin: 12px 0 0; color: var(--info-ink); }
.move-offer p { margin: 0 0 8px; }
.schedule-offer { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 12px; padding: 12px 16px; margin: 12px 0 0; color: var(--warn-ink); }
.schedule-offer p { margin: 0 0 8px; }
.schedule-offer .offer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 0; }
.move-offer form, .move-offer .offer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 0; }
.move-hint { margin: 10px 0 0; }

/* ==========================================================================
   Справочник диагнозов: области — свёрнутые группы, диагноз — одна строка,
   подробности открываются по нажатию (<details>, без JavaScript).
   ========================================================================== */
.diagnosis-region { padding: 0; }
.diagnosis-region > summary { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 14px 24px; cursor: pointer; border-radius: 16px; list-style: none; }
.diagnosis-region > summary::-webkit-details-marker, .diagnosis > summary::-webkit-details-marker { display: none; }
.diagnosis-region > summary h2 { margin: 0; font-size: 18px; }
.diagnosis-region > summary h2::before { content: "›"; display: inline-block; width: 18px; color: var(--muted); transition: transform .15s; }
.diagnosis-region[open] > summary h2::before { transform: rotate(90deg); }
.diagnosis-list { padding: 0 24px 14px; }
.diagnosis.list-item { padding: 8px 0; }
.diagnosis > summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; cursor: pointer; list-style: none; border-radius: 8px; }
.diagnosis > summary:hover .diagnosis-name { text-decoration: underline; }
.diagnosis-name { flex: 1 1 260px; font-weight: 600; }
.diagnosis-code { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.diagnosis-details { margin: 6px 0 4px; padding: 8px 14px; background: var(--tint); border-radius: 10px; }
.diagnosis-details p { margin: 2px 0; }
.code { white-space: nowrap; }
.code-missing { font-style: italic; color: var(--muted); font-size: 14px; }
.diagnosis.needs-check { border-left: 4px solid var(--focus); padding-left: 12px; }
.diagnosis-note { color: var(--warn-ink); }
/* Диагнозы случая (шаг 6): «Вне справочника» — серая отметка с пунктиром,
   результаты поиска и раздел «Введены вручную». */
.badge-out { color: var(--neutral-ink); background: var(--tint); border: 1px dashed var(--dash); line-height: 1.45; }
.diagnosis-result h2 { margin: 0 0 4px; font-size: 17px; }
.diagnosis-result.needs-check { border-left: 4px solid var(--focus); padding-left: 12px; }
.diagnosis-chosen { font-size: 18px; }
.manual-cases { margin: 4px 0 0; padding-left: 20px; }
.case-diagnosis-item h3 { font-size: 17px; }
.case-diagnosis-item .diagnosis-code { margin: 6px 0; }
.diagnoses-note { margin: 12px 0 0; font-size: 14px; }

/* ==========================================================================
   Главная (main.png, шаг 11): поиск, четыре плитки, «Дела на сегодня»
   и «Недавние пациенты» рядом, внизу полоса с числом случаев в колонках доски.
   Страница «Дела» использует те же строки дел.
   ========================================================================== */
.home-search { margin-top: 20px; }
/* Плитки: слово всегда написано, цвет только помогает (красная — просрочено, жёлтая — сегодня). */
.home-tiles { list-style: none; margin: 16px 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.sum-tile { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; height: 100%; padding: 12px 16px; border-radius: 12px; color: var(--ink); text-decoration: none; border: 1px solid var(--line); background: #fff; }
.sum-tile:hover { color: var(--ink); border-color: var(--border); }
.sum-tile-overdue { background: var(--danger-bg); color: var(--danger-ink); border-color: transparent; }
.sum-tile-today { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
a.sum-tile-overdue:hover { color: var(--danger-ink); border-color: currentColor; }
a.sum-tile-today:hover { color: var(--warn-ink); border-color: currentColor; }
.sum-tile-label { font-size: 15px; line-height: 1.3; }
.sum-tile-count { font-size: 28px; font-weight: 600; line-height: 1.2; }
@media (max-width: 560px) { .home-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.home-grid .card { margin: 0; }
.home-agenda .card-title, .home-recent .card-title { font-size: 18px; }
/* Строка дела: короткое ФИО и «Д+N», операция или случай, что нужно сделать, одна кнопка. */
.agenda-item p { margin: 0; }
.agenda-who a { color: var(--ink); font-weight: 600; text-decoration: none; }
.agenda-who a:hover { text-decoration: underline; }
.agenda-who .chip { margin-left: 6px; vertical-align: 1px; }
.agenda-due.is-overdue { color: var(--danger-ink); }
.agenda-due.is-today { color: var(--warn-ink); font-weight: 600; }
.agenda-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 8px 0 0; }
.agenda-actions .btn { min-height: 40px; }
.agenda-actions .appointment-status { margin: 0; }
.agenda-overdue { border-color: var(--danger-bg); }
.done-action.is-overdue { color: var(--danger-ink); }
.home-recent .person-list { margin: 0; padding: 0; list-style: none; }
.home-recent .person:first-child { padding-top: 0; }
.home-more { margin: 10px 0 0; font-size: 14px; }
.home-board { margin-top: 16px; }
.board-strip { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.board-strip a { display: flex; flex-direction: column; gap: 2px; height: 100%; padding: 10px 14px; background: var(--tint); border-radius: 10px; color: var(--ink); text-decoration: none; }
.board-strip a:hover { background: var(--neutral-bg); }
.strip-label { font-size: 15px; line-height: 1.3; }
.strip-count { font-size: 24px; font-weight: 600; line-height: 1.2; }

/* ==========================================================================
   Страница случая лечения (docs/design/case.png): шапка, ряд точек
   стандартных этапов и лента карточек этапов.
   ========================================================================== */
.case-page { margin-top: 20px; }
.case-page .path { margin-top: 0; }
.case-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 12px 0 0; color: var(--muted); }
/* Доска в шапке случая (шаг 9): «Колонка: …», красная строка «Следующее: …», кнопки доски. */
.case-column { white-space: nowrap; }
.next-action { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 12px 0 0; padding: 10px 16px; background: var(--tint); border-radius: 12px; }
.next-action.is-overdue { background: var(--danger-bg); color: var(--danger-ink); }
.next-action p { margin: 0; }
.next-action-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.case-board-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px; margin: 10px 0 0; }
.board-history-item { margin: 4px 0; }
.old-board summary { cursor: pointer; color: var(--link); }
/* Строка основного диагноза в шапке случая. */
.case-diagnosis { margin: 10px 0 0; font-size: 17px; }
.case-diagnosis .chip, .case-diagnosis .badge { margin-left: 4px; vertical-align: 1px; }
.case-diagnosis a { color: var(--ink); font-weight: 600; }
.case-diagnosis.muted a { color: var(--link); font-weight: 400; }
.case-diagnosis.muted { font-size: 16px; }
.case-initial { margin: 12px 0 0; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.case-initial strong { font-weight: 600; }
/* Ряд точек: закрашенная — этап записан, пунктирная пустая — ещё нет. */
.stage-dots { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px 4px; text-align: center; }
.stage-dots li, .stage-dots a { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.stage-dots a { width: 100%; color: var(--ink); text-decoration: none; border-radius: 8px; }
.stage-dots a:hover .dot-label { text-decoration: underline; }
.stage-dots .dot { width: 18px; height: 18px; border-radius: 50%; }
.stage-dots .is-done .dot { background: var(--done); }
.stage-dots .is-empty .dot { border: 2px dashed var(--dash); }
.stage-dots .is-empty .dot-label { color: var(--muted); }
.dot-label { font-size: 15px; line-height: 1.3; }
/* Осмотр графика (шаг 10): под пунктирной точкой — плановая дата; просроченный — красная точка и слово. */
.stage-dots .is-overdue .dot { background: var(--danger-ink); }
.stage-dots .is-overdue .dot-label, .stage-dots .is-overdue .dot-note { color: var(--danger-ink); }
.dot-note { font-size: 13px; line-height: 1.2; color: var(--muted); margin-top: -4px; }
/* Карточка «График осмотров»: строка на осмотр, кнопка «Не требуется» выглядит как ссылка. */
.schedule-card { margin-bottom: 16px; }
.checkup-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; }
.checkup-row h3, .checkup-row .checkup-main p { margin: 0; }
.checkup-row .chip { margin-left: 6px; }
.checkup-actions { margin: 0; }
.inline-form { display: inline; margin: 0; }
button.link-button { min-height: 0; padding: 0; background: none; border: 0; border-radius: 0; color: var(--link); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
button.link-button:hover { color: var(--ink); }
/* Лента этапов: от поздних к ранним, слева линия с точками. */
.stage-timeline { list-style: none; margin: 0; padding: 0; }
.stage-timeline > li { position: relative; padding-left: 40px; }
.stage-timeline > li::before { content: ""; position: absolute; left: 4px; top: 22px; width: 18px; height: 18px; border-radius: 50%; background: var(--done); }
.stage-timeline > li::after { content: ""; position: absolute; left: 12px; top: 46px; bottom: -16px; width: 2px; background: var(--line); }
.stage-timeline > li:last-child::after { display: none; }
.stage-card { padding: 0; }
.stage-card > summary { display: block; cursor: pointer; padding: 18px 24px; border-radius: 16px; }
.stage-card > summary::-webkit-details-marker, .file-tile > summary::-webkit-details-marker { display: none; }
.stage-card[open] > summary { padding-bottom: 6px; }
.stage-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 16px; }
.stage-title { margin: 0; font-size: 19px; line-height: 1.3; }
.stage-date { color: var(--muted); white-space: nowrap; }
.stage-summary { display: block; margin-top: 4px; color: var(--muted); }
.stage-card[open] > summary .stage-summary, .stage-card:not([open]) > summary .stage-collapse { display: none; }
.stage-body { padding: 0 24px 18px; }
/* Плитки файлов этапа. Раскрытая плитка занимает всю ширину под остальными. */
.file-tiles { display: flex; flex-wrap: wrap; gap: 12px; margin: 6px 0 12px; }
.file-tile > summary { display: block; cursor: pointer; border-radius: 10px; }
.tile-thumb { display: block; width: 112px; height: 84px; border-radius: 10px; background: var(--tint); border: 1px solid var(--line); object-fit: cover; }
.tile-label { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px; text-align: center; }
.tile-kind { font-weight: 600; font-size: 15px; }
.tile-name { max-width: 100%; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-tile > summary:hover .tile-thumb, .file-tile-add:hover { border-color: var(--dash); }
.tile-open-head { display: none; }
.file-tile[open] { flex: 0 0 100%; order: 1; min-width: 0; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.file-tile[open] .tile-thumb { display: none; }
.file-tile[open] .tile-open-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; }
.file-panel { margin-top: 10px; max-width: 640px; }
.file-panel p { margin: 6px 0; }
.file-panel form { margin-top: 10px; }
.file-panel .form-field { margin-bottom: 8px; }
.file-photo img { display: block; max-width: 100%; max-height: 70vh; border-radius: 10px; }
.file-tile-add { display: flex; align-items: center; justify-content: center; width: 112px; height: 84px; padding: 6px; border: 1px dashed var(--dash); border-radius: 10px; text-align: center; text-decoration: none; font-size: 14px; line-height: 1.3; }
.stage-no-files { margin: 6px 0 0; }
.file-comments-title { font-weight: 600; margin-top: 12px; }
.file-comment { background: var(--tint); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.file-comment-body { white-space: pre-wrap; }
.stage-comment { margin: 8px 0 0; padding: 8px 14px; background: var(--tint); border-radius: 10px; white-space: pre-wrap; }
.stage-comment-who { color: var(--muted); }
.stage-actions { margin: 12px 0 0; font-size: 15px; }
.stage-measures { margin: 12px 0 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; }
.stage-measures-title { margin: 0 0 6px; font-size: 15px; }
.stage-measures-list { margin: 0; }
.stage-measures-list div { margin: 4px 0 0; }
.stage-measures-list dt, .stage-measures-list dd { display: inline; margin: 0; }
.stage-measures-list dt { font-weight: 400; color: var(--muted); }
.stage-measures-list dt::after { content: ": "; }
.stage-measures-sub { margin: 8px 0 4px; color: var(--muted); }
.stage-rom-list { margin: 0; padding-left: 20px; }
.stage-measures-form { margin: 8px 0 12px; }
.stage-measures-form summary { cursor: pointer; font-weight: 600; }
.stage-form-card .muted { margin: 0 0 14px; }
/* Вкладки «Лечение», «Файлы», «История». */
.media-name { margin: 4px 0; }
.operation-video p { margin: 6px 0; }
.operation { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 20px; }
.operation + .operation { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.operation-details h4 { margin: 0 0 8px; }
/* Записи об операциях (шаг 7): карточка «Операции», форма с выбором связи этапа. */
.operation-record h3 { font-size: 17px; }
.operation-record .diagnosis-code { margin: 6px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.operation-text { margin: 6px 0; white-space: pre-wrap; }
.operation-note { margin: 6px 0; padding: 8px 12px; background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; }
.operation-videos-title { margin: 24px 0 4px; font-size: 17px; }
.stage-link-choice { border: 0; padding: 0; min-width: 0; }
.stage-link-choice legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.radio-line { display: flex; align-items: baseline; gap: 10px; font-weight: 400; margin: 0 0 10px; }
.radio-line input { flex: 0 0 auto; width: auto; display: inline; }
.case-operation { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 12px 0 0; color: var(--muted); }
.case-operation a { color: var(--ink); }

/* Приёмы (шаг 7a): строка приёма, кнопки статуса, строка «Следующий приём». */
.appointment-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.appointment-time { font-variant-numeric: tabular-nums; }
.appointment-patient { color: var(--ink); }
.appointment-comment { overflow-wrap: anywhere; }
.appointment-status { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.appointments-head { margin-top: 20px; }
.appointments-head h1 { margin: 0; }
.appointments-unmarked { border-color: var(--warn-line); }
.case-appointment { margin: 8px 0 0; }
.case-appointment a, .next-appointment a { color: var(--ink); font-weight: 600; }
.video-placeholder { aspect-ratio: 16 / 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: #2b2b2b; color: #e9e9e4; border-radius: 10px; text-align: center; padding: 12px; }
.play-icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 50%; background: rgba(255, 255, 255, .15); font-size: 20px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.files-table { width: 100%; min-width: 560px; border-collapse: collapse; }
.files-table th, .files-table td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.files-table th { background: var(--tint); font-size: 14px; color: var(--muted); }
.files-table tr:last-child td { border-bottom: 0; }
.files-table td:nth-child(3) { white-space: nowrap; overflow-wrap: normal; }
/* Просмотр видео этапа. Сообщение об ошибке показывает static/video-check.js. */
.video-box { margin-bottom: 8px; }
.video-player { display: block; width: 100%; aspect-ratio: 16 / 9; background: #2b2b2b; border-radius: 8px; }
.video-player[hidden], .video-error[hidden] { display: none; }
.video-error { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; padding: 10px 12px; color: var(--warn-ink); }
.video-error p { margin: 0 0 8px; }

/* Подвал сайта: ссылка на «Настройки» (шаг 10). */
.site-footer { border-top: 1px solid var(--line); padding: 12px 0 24px; }
.site-footer a { color: var(--muted); }
.settings-form input { max-width: 120px; }

/* ==========================================================================
   Узкие экраны.
   ========================================================================== */
@media (max-width: 640px) {
  .operation { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { padding-bottom: 0; border-bottom: 0; }
}
@media (max-width: 560px) {
  .stage-dots { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .card { padding: 16px; }
  .diagnosis-region { padding: 0; }
  .diagnosis-region > summary { padding: 12px 16px; }
  .diagnosis-list { padding: 0 16px 12px; }
  .search-controls input { flex: 1 1 160px; }
  .tabs { gap: 0 12px; }
  .tabs a { font-size: 16px; }
  .avatar-large { width: 52px; height: 52px; font-size: 18px; }
  .stage-timeline > li { padding-left: 24px; }
  .stage-timeline > li::before { left: 0; top: 20px; width: 14px; height: 14px; }
  .stage-timeline > li::after { left: 6px; top: 40px; }
  .stage-card { padding: 0; }
  .stage-card > summary { padding: 14px 16px; }
  .stage-body { padding: 0 16px 14px; }
  .tile-thumb, .file-tile-add { width: 88px; height: 66px; }
  .file-tile-add { font-size: 13px; }
}
@media (max-width: 360px) {
  .tabs { gap: 0 4px; justify-content: space-between; }
  .tabs a { font-size: 14px; }
}

/* Код привязки Telegram-бота на странице «Настройки» (шаг 12) */
.link-code { font-family: ui-monospace, Consolas, monospace; font-size: 1.5rem; letter-spacing: 0.12em; }

/* Вход (шаг 17): кнопка «Выйти» в шапке и форма входа. */
.logout-link { color: var(--muted); }
.login-card { max-width: 440px; }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 8px 20px; }

/* Метки на видео (шаг 16б): список под проигрывателем; время — кнопка перемотки (video-marks.js). */
.video-marks { margin: 8px 0 12px; }
.video-marks-title { margin: 0 0 4px; }
.video-mark-list { list-style: none; margin: 0 0 8px; padding: 0; }
.video-mark { padding: 4px 0; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.video-mark:last-child { border-bottom: 0; }
.video-mark-time, .video-mark-seek { font-variant-numeric: tabular-nums; font-weight: 600; }
.video-mark-seek { min-height: 32px; padding: 2px 10px; background: #fff; color: var(--link); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
