/* Danel Pulse: one visual system, mobile first (design D1, D2, D4, D5).
   Colors live only in :root; rules use var(--…), transparent, currentColor or inherit.
   Components: .button (.button-light, .button-text), .pill (.pill-pending, .pill-confirmed,
   .pill-conflict, .pill-neutral), .card, details.disclosure, dl.meta, .field, .hint,
   .field-error, fieldset.choices with .choice, .attention, .form-error, .empty,
   table.stack with td[data-label], .summary-grid, .total-card, .document-layout. */

@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("fonts/inter-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116;
}

@font-face {
  font-family: "Inter Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("fonts/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

:root {
  color-scheme: light;

  --color-canvas: #f6f5f4;
  --color-surface: #ffffff;
  --color-hairline: rgba(0,0,0,.08);
  --color-control-border: #8c8781;
  --color-text: rgba(0,0,0,.95);
  --color-text-body: #615d59;
  --color-accent: #0075de;
  --color-on-accent: #ffffff;
  --color-accent-strong: #005bab;
  --color-accent-tint: #e6f3fe;
  --color-midnight: #02093a;
  --color-on-midnight: #ffffff;
  --color-on-midnight-muted: rgba(255,255,255,.72);
  --pill-pending-text: #5c3b00;
  --pill-pending-bg: #ffe3a6;
  --pill-confirmed-text: #003e75;
  --pill-confirmed-bg: #cfe6fb;
  --pill-conflict-text: #8a1c0c;
  --pill-conflict-bg: #fde0db;
  --pill-neutral-text: #4a4743;
  --pill-neutral-bg: #ebe9e6;
  --color-attention-text: #4d3300;
  --color-attention-bg: #fff3d6;
  --color-error-text: #b3261e;
  --shadow-header: 0 1px 3px rgba(0,0,0,.06);

  --font-sans: "Inter Variable", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --radius-control: 8px;
  --radius-card: 12px;
  --radius-pill: 9999px;
  --target: 44px;
  --content-width: 1240px;
  --content-wide: 1440px;
  --gutter: 16px;
  --duration: 200ms;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
/* When Tab reaches a textarea, Chrome reveals only its caret line. The bottom padding keeps the whole
   focused field on screen: 72 px box - 35 px to the caret line bottom + 4 px focus ring < 48 px. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-bottom: 48px; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-canvas);
  color: var(--color-text-body);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  font-weight: 400;
  font-feature-settings: "lnum";
  overflow-wrap: break-word;
}
h1, h2, h3, h4 { color: var(--color-text); margin: 0 0 var(--space-3); }
h1 { font-size: 24px; line-height: 1.2; font-weight: 650; letter-spacing: -0.02em; }
h2 { font-size: 20px; line-height: 1.3; font-weight: 600; letter-spacing: -0.011em; }
h3, h4 { font-size: 16px; line-height: 1.5; font-weight: 600; }
p { margin: 0 0 var(--space-3); max-width: 72ch; }
strong, b { color: var(--color-text); font-weight: 600; }
a { color: var(--color-accent-strong); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
img, iframe { max-width: 100%; }
small, .small { font-size: 14px; line-height: 1.43; }
.caption, .eyebrow { font-size: 12px; line-height: 1.33; font-weight: 600; letter-spacing: 0.01em; color: var(--color-text-body); }
.muted, small { color: var(--color-text-body); }
.money, .num { font-variant-numeric: tabular-nums; }
.money { white-space: nowrap; font-weight: 600; color: var(--color-text); }
.date { white-space: nowrap; }
.hash { font-variant-numeric: tabular-nums; word-break: break-all; }
pre {
  margin: 0 0 var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-control);
  background: var(--color-canvas);
  color: var(--color-text);
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
/* The hidden attribute wins over the display of buttons and fields set below (task 6.4). */
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Focus and motion */
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
a, button, .button, summary, input, select, textarea, .choice, nav a {
  transition: color var(--duration) ease, background-color var(--duration) ease, border-color var(--duration) ease;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Shell (D3, D5). Phone: brand, role and logout in the first row; clinic and
   sections in the second, scrolling inside nav; the demo pill below them.
   From 761 px one row in source order, wrapping only when it does not fit. */
.skip-link {
  position: absolute; left: var(--gutter); top: var(--space-2); z-index: 20;
  display: inline-flex; align-items: center; min-height: var(--target); padding: 10px 16px;
  border-radius: var(--radius-control); background: var(--color-surface); color: var(--color-accent-strong);
  transform: translateY(-200%);
}
.skip-link:focus, .skip-link:focus-visible { transform: none; }
.app-header {
  position: relative; z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-hairline);
  box-shadow: var(--shadow-header);
}
.header-inner {
  max-width: var(--content-width); margin: 0 auto; padding: var(--space-1) var(--gutter) var(--space-2);
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-3);
}
.brand {
  order: 1; flex: 0 0 auto;
  display: inline-flex; align-items: center; min-height: var(--target);
  color: var(--color-text); font-size: 16px; font-weight: 650; letter-spacing: -0.011em; text-decoration: none;
  white-space: nowrap;
}
.header-user { order: 2; flex: 0 0 auto; margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.header-role { font-size: 14px; line-height: 1.43; font-weight: 500; color: var(--color-text); white-space: nowrap; }
.logout button { padding: 10px 12px; }
.header-context { order: 3; flex: 1 0 100%; min-width: 0; display: flex; align-items: center; gap: var(--space-3); }
.header-clinic {
  flex: 0 1 auto; min-width: 0; max-width: 50%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px; line-height: 1.43; color: var(--color-text-body);
}
.header-demo { order: 4; margin: 0 0 var(--space-1); }
.app-header nav {
  flex: 1 1 auto; min-width: 0; padding: var(--space-1);
  display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: thin;
}
.app-header nav a {
  display: inline-flex; align-items: center; flex: 0 0 auto; min-height: var(--target); padding: 0 var(--space-3);
  border-radius: var(--radius-control); color: var(--color-text-body); font-size: 14px; font-weight: 500;
  text-decoration: none; white-space: nowrap;
}
.app-header nav a:hover { background: var(--color-canvas); color: var(--color-text); }
.app-header nav a[aria-current="page"] { background: var(--color-canvas); color: var(--color-text); font-weight: 600; }
main { max-width: var(--content-width); margin: 0 auto; padding: var(--space-4) var(--gutter) var(--space-8); min-width: 0; }
.page-wide .header-inner, .page-wide main, .page-wide .footer-inner { max-width: var(--content-wide); }
.app-footer { border-top: 1px solid var(--color-hairline); }
.footer-inner {
  max-width: var(--content-width); margin: 0 auto; padding: var(--space-5) var(--gutter) var(--space-8);
  font-size: 14px; line-height: 1.43; color: var(--color-text-body);
}
.footer-inner p { margin: 0 0 var(--space-1); }
.page-heading { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-3) var(--space-6); margin: var(--space-2) 0 var(--space-6); }
.page-heading > * { min-width: 0; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

/* Buttons (D4): one filled button per screen; light and text buttons for the rest */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--target); padding: 10px 16px; margin: 0;
  border: 1px solid transparent; border-radius: var(--radius-control);
  background: var(--color-accent); color: var(--color-on-accent);
  font: inherit; font-size: 14px; line-height: 1.43; font-weight: 500;
  text-align: center; text-decoration: none; cursor: pointer;
}
button:hover, .button:hover { background: var(--color-accent-strong); }
.button-light, .secondary { background: var(--color-accent-tint); color: var(--color-accent-strong); }
.button-light:hover, .secondary:hover { background: var(--color-accent-tint); border-color: var(--color-accent-strong); }
.button-text { background: transparent; color: var(--color-accent-strong); }
.button-text:hover { background: var(--color-canvas); }
.button-block { display: flex; width: 100%; }

/* Status pill (D4): always with text */
.pill, .badge {
  display: inline-flex; align-items: center; gap: var(--space-1); max-width: 100%;
  padding: 5px 10px; border-radius: var(--radius-pill);
  font-size: 12px; line-height: 1.33; font-weight: 600; letter-spacing: 0.01em;
  background: var(--pill-neutral-bg); color: var(--pill-neutral-text);
}
.pill-pending, .badge { background: var(--pill-pending-bg); color: var(--pill-pending-text); }
.pill-confirmed { background: var(--pill-confirmed-bg); color: var(--pill-confirmed-text); }
.pill-conflict { background: var(--pill-conflict-bg); color: var(--pill-conflict-text); }
.pill-neutral { background: var(--pill-neutral-bg); color: var(--pill-neutral-text); }

/* Cards and disclosures (D4) */
.card, article {
  margin: 0 0 var(--space-4); padding: var(--space-4);
  background: var(--color-surface); border: 1px solid var(--color-hairline); border-radius: var(--radius-card);
}
.card > :last-child, article > :last-child { margin-bottom: 0; }
.card:target, .step:target { border-color: var(--color-accent); }
details { border-bottom: 1px solid var(--color-hairline); padding: var(--space-3) 0; }
summary { cursor: pointer; }
details.disclosure { padding: 0; }
details.disclosure > summary {
  display: flex; align-items: center; gap: var(--space-3); min-height: 56px; padding: var(--space-2) 0;
  list-style: none; color: var(--color-text); font-weight: 600;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after {
  content: ""; flex: 0 0 auto; margin-left: auto; width: 8px; height: 8px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translate(-2px, -2px);
}
details.disclosure[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
details.disclosure > :not(summary) { margin-bottom: var(--space-4); }

/* Facts (D4): label above value on a phone, in a row from 761 px */
dl.meta { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-6); margin: 0 0 var(--space-4); font-size: 14px; line-height: 1.43; }
dl.meta > div { flex: 1 1 100%; min-width: 0; }
dl.meta dt { color: var(--color-text-body); }
dl.meta dd { margin: 0 0 var(--space-2); color: var(--color-text); }

/* Fields (D4) */
form { margin: 0; }
label, .field-label { display: block; margin: var(--space-3) 0; color: var(--color-text); font-size: 14px; line-height: 1.43; font-weight: 500; }
.field { margin: var(--space-4) 0; }
.field > label { margin: 0 0 6px; }
input, select, textarea {
  display: block; width: 100%; max-width: 100%; min-height: var(--target); margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--color-control-border); border-radius: var(--radius-control);
  background: var(--color-surface); color: var(--color-text); font: inherit; font-size: 16px; line-height: 1.5;
}
.field > input, .field > select, .field > textarea { margin-top: 0; }
textarea { min-height: 72px; resize: vertical; }
input[type="radio"], input[type="checkbox"] {
  display: inline-block; width: 20px; height: 20px; min-height: 0; margin: 2px 0 0; padding: 0; flex: 0 0 auto;
  accent-color: var(--color-accent);
}
::placeholder { color: var(--color-text-body); opacity: 1; }
.hint { margin: 6px 0 0; font-size: 14px; line-height: 1.43; color: var(--color-text-body); }
.error, .field-error { color: var(--color-error-text); }
.field-error { margin: 6px 0 0; font-size: 14px; line-height: 1.43; font-weight: 500; }

/* Decision choices (D4, D7): radio cards; the checked card is tinted */
fieldset { margin: var(--space-4) 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: var(--space-2); color: var(--color-text); font-size: 14px; font-weight: 600; }
.choices { display: grid; gap: var(--space-2); }
.choice {
  display: flex; align-items: flex-start; gap: var(--space-3); min-height: var(--target); margin: 0; padding: var(--space-3);
  border: 1px solid var(--color-control-border); border-radius: var(--radius-control);
  background: var(--color-surface); cursor: pointer;
}
.choice:has(input:checked) { background: var(--color-accent-tint); border-color: var(--color-accent); }
.choice-label { display: block; color: var(--color-text); font-weight: 500; }
.choice-note { display: block; margin-top: 2px; font-size: 14px; line-height: 1.43; font-weight: 400; color: var(--color-text-body); }
/* D7 step 2: the second document only for «Это тот же документ», «Это разные документы» and «Это копия
   другого документа»; a browser without :has() keeps it visible. */
@supports selector(:has(*)) {
  .decision-form:not(:has(input[value="mark_duplicate"]:checked, input[value="mark_distinct"]:checked)) .other-document { display: none; }
}

/* Messages (D4) */
.attention, .notice {
  margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); max-width: none;
  border-radius: var(--radius-card); background: var(--color-attention-bg); color: var(--color-attention-text);
}
.attention ul { margin: var(--space-2) 0 0; padding-left: var(--space-5); }
.attention strong, .notice strong { color: inherit; }
.form-error, .notice.error {
  margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); max-width: none;
  border: 1px solid var(--color-hairline); border-left: 4px solid var(--color-error-text); border-radius: var(--radius-card);
  background: var(--color-surface); color: var(--color-text);
}
.empty { padding: var(--space-6) 0; color: var(--color-text-body); }

/* Tables (D4): plain tables scroll inside their area; table.stack turns rows into cards
   below 761 px and takes each cell label from data-label */
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; line-height: 1.43; }
th, td { padding: var(--space-3); border-bottom: 1px solid var(--color-hairline); vertical-align: top; }
thead th { background: var(--color-canvas); color: var(--color-text); font-weight: 600; }
th.num, td.num { text-align: right; }
td.money, td.date, th.money { white-space: nowrap; }
table.stack, table.stack tbody, table.stack tr, table.stack td, table.stack th { display: block; }
table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
table.stack tr {
  margin: 0 0 var(--space-3); padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-hairline); border-radius: var(--radius-card); background: var(--color-surface);
}
table.stack td, table.stack tbody th { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-2) 0; text-align: right; }
table.stack td::before, table.stack tbody th::before { content: attr(data-label); color: var(--color-text-body); font-weight: 500; text-align: left; }
table.stack tr > :last-child { border-bottom: 0; }

/* Revision page (D11): heading with the saved facts; the summary first (the midnight total card with
   «Скачать XLSX» and «По врачам», two columns from 761 px); one «Обратите внимание» panel; then the
   closed disclosures with counters, whose document table turns into row cards below 761 px. */
.revision-heading { margin: var(--space-1) 0 var(--space-5); }
.revision-heading h1 { margin-bottom: var(--space-2); }
dl.revision-meta { gap: 0 var(--space-5); margin: 0 0 var(--space-2); }
dl.revision-meta > div { display: flex; flex-wrap: wrap; gap: 0 var(--space-2); flex: 0 1 auto; }
dl.revision-meta dd { margin: 0; }
/* The saving time, the revision number and the currency are short: each pair stays on one line. */
dl.revision-meta > div + div { flex-wrap: nowrap; white-space: nowrap; }
.revision-note { margin: 0; font-size: 14px; line-height: 1.43; color: var(--color-text-body); }
.summary-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); margin: 0 0 var(--space-4); }
.summary-grid > * { min-width: 0; margin: 0; }
.total-card { background: var(--color-midnight); border-color: transparent; color: var(--color-on-midnight-muted); }
.total-card h2, .total-card strong, .total-card .total, .total-card a:not(.button) { color: var(--color-on-midnight); }
.total-card small, .total-card .muted, .total-card .caption, .total-card .total-caption, .total-card .total-count { color: var(--color-on-midnight-muted); }
.total-card .button { display: flex; width: 100%; margin-top: var(--space-4); }
.total-caption { margin: 0 0 var(--space-2); font-size: 14px; line-height: 1.43; font-weight: 500; letter-spacing: 0; }
.total { display: block; color: var(--color-text); font-size: 40px; line-height: 1.1; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.total.total-empty { font-size: 24px; line-height: 1.2; letter-spacing: -0.02em; }
.total-pill { margin: var(--space-2) 0 0; }
.total-count { margin: var(--space-2) 0 0; font-size: 14px; line-height: 1.43; }
.doctors-card h2 { margin-bottom: var(--space-1); }
.doctor-list { margin: 0; padding: 0; list-style: none; }
.doctor-list > li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3);
  padding: var(--space-3) 0; border-bottom: 1px solid var(--color-hairline);
}
.doctor-list > li:last-child { border-bottom: 0; padding-bottom: 0; }
.doctor-name { flex: 1 1 8rem; min-width: 0; color: var(--color-text); font-weight: 500; }
.doctor-amount { margin-left: auto; white-space: nowrap; }
.doctor-count { font-size: 14px; line-height: 1.43; color: var(--color-text-body); }
.doctor-amount .money { font-size: 18px; line-height: 1.33; }
.doctor-list .pill { margin-left: auto; }
.doctor-empty { margin: var(--space-2) 0 0; }
.attention > h2 { margin: 0 0 var(--space-1); color: inherit; font-size: 16px; line-height: 1.5; letter-spacing: 0; }
.attention > ul { margin: 0; }
.attention li + li { margin-top: var(--space-1); }
.attention .reasons { margin: var(--space-1) 0 0; }
.attention-link { margin: 0; }
.attention-link a, .row-origin a, .sources-link a { display: inline-flex; align-items: center; min-height: var(--target); }
.revision-details > h2 { margin: var(--space-6) 0 var(--space-3); }
.revision-details > details.disclosure { margin: 0 0 var(--space-3); }
.disclosure-title { flex: 1 1 auto; min-width: 0; }
.document-rows .row-origin { min-width: 0; }
.row-origin p { margin: 0 0 var(--space-1); }
.excluded-list { margin: 0 0 var(--space-4); padding: 0; list-style: none; }
.excluded-list > li { padding: var(--space-3) 0; border-bottom: 1px solid var(--color-hairline); }
.excluded-list p { margin: 0 0 var(--space-1); }
.excluded-list .excluded-reason { color: var(--color-text); font-weight: 600; }

/* Report list (D10): the reviewer's «Сформировать отчёт» is a disclosure in the page heading (the filled
   button while closed; open, it gives way to the form's own button and takes the whole row); the GET
   search; revision cards with the stored total and pills; pages of 20 without a second nav. */
.filter-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--space-4); align-items: end; }
.filter-form > * { min-width: 0; }
.filter-form button { margin: var(--space-3) 0; }
.page-heading > details.capture { padding: 0; border-bottom: 0; }
.page-heading > details.capture[open] { flex: 1 1 100%; }
details.capture > summary { list-style: none; }
details.capture > summary::-webkit-details-marker { display: none; }
details.capture[open] > summary, details.capture[open] > summary:hover {
  background: var(--color-accent-tint); border-color: var(--color-accent-strong); color: var(--color-accent-strong);
}
.capture-card { margin: var(--space-3) 0 0; }
.saved-reports > h2 { margin-bottom: var(--space-3); }
.report-search { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--space-4); align-items: end; }
.report-search > * { min-width: 0; }
.report-search .actions { margin: var(--space-3) 0; }
.report-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); margin: 0 0 var(--space-4); padding: 0; list-style: none; }
.report-list > li { min-width: 0; }
.report-card {
  display: flex; flex-direction: column; gap: var(--space-2); height: 100%; padding: var(--space-4);
  border: 1px solid var(--color-hairline); border-radius: var(--radius-card); background: var(--color-surface);
  color: var(--color-text); text-decoration: none;
}
.report-card:hover { background: var(--color-canvas); }
.report-card:hover .report-card-title { text-decoration: underline; }
.report-card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-1) var(--space-4); }
.report-card-title { min-width: 0; font-weight: 600; overflow-wrap: break-word; }
.report-card-empty, .report-card-meta { color: var(--color-text-body); font-size: 14px; line-height: 1.43; }
.report-card-pills { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pagination { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-4); }

/* Review queue (D6): GET filters with counters, then one row per document: a link with the date,
   doctor and amount (or the number of versions) and the status pill; the pill goes under the link
   on a phone and to its right from 761 px. */
.queue-filters { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0 0 var(--space-4); padding: 0; list-style: none; }
.queue-filter {
  display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--target); padding: 0 var(--space-4);
  border: 1px solid var(--color-hairline); border-radius: var(--radius-pill); background: var(--color-surface);
  color: var(--color-text); font-size: 14px; line-height: 1.43; font-weight: 500; text-decoration: none; white-space: nowrap;
}
a.queue-filter:hover { border-color: var(--color-control-border); }
.queue-filter.is-current { background: var(--color-accent-tint); border-color: var(--color-accent); color: var(--color-accent-strong); font-weight: 600; }
.count {
  display: inline-flex; justify-content: center; min-width: 24px; padding: 0 var(--space-2); border-radius: var(--radius-pill);
  background: var(--color-canvas); color: var(--color-text); font-size: 12px; line-height: 20px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.queue-filter.is-current .count { background: var(--color-surface); color: var(--color-accent-strong); }
.queue-list {
  margin: 0 0 var(--space-4); padding: 0; list-style: none;
  background: var(--color-surface); border: 1px solid var(--color-hairline); border-radius: var(--radius-card);
}
.queue-row {
  display: grid; grid-template-columns: minmax(0, 1fr); justify-items: start; gap: 0 var(--space-4);
  padding: var(--space-2) var(--space-4) var(--space-3); border-bottom: 1px solid var(--color-hairline);
}
.queue-row:last-child { border-bottom: 0; }
.queue-link {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-4); width: 100%; min-width: 0; min-height: var(--target);
  color: var(--color-text); text-decoration: none;
}
.queue-link:hover .queue-doctor, .queue-link:hover .queue-versions { text-decoration: underline; }
.queue-doctor, .queue-versions { font-weight: 500; }
.queue-amount { white-space: nowrap; font-variant-numeric: tabular-nums; }
.queue-note { grid-column: 1 / -1; margin: var(--space-2) 0 0; font-size: 14px; line-height: 1.43; color: var(--color-text-body); }
.queue-empty {
  margin: 0 0 var(--space-4); padding: var(--space-6) var(--space-4);
  background: var(--color-surface); border: 1px solid var(--color-hairline); border-radius: var(--radius-card);
}
.queue-empty > :last-child { margin-bottom: 0; }
.queue-footnote { font-size: 14px; line-height: 1.43; color: var(--color-text-body); }

/* Document page (D7): one column (heading, original up to 60vh, then the steps); from 1101 px the
   original is the left column and stays pinned under the header while the steps scroll. History and
   recognized text are disclosures with readable lists instead of raw dicts. */
.back-link { margin: 0; font-size: 14px; line-height: 1.43; }
.back-link a { display: inline-flex; align-items: center; min-height: var(--target); }
.document-heading { margin-top: 0; margin-bottom: var(--space-4); }
.document-heading h1 { margin-bottom: var(--space-1); }
.document-heading p { margin: 0; }
.document-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
.document-layout > * { min-width: 0; }
.document-original {
  padding: var(--space-4); background: var(--color-surface);
  border: 1px solid var(--color-hairline); border-radius: var(--radius-card);
}
.original-heading { margin: 0 0 var(--space-2); font-size: 14px; line-height: 1.43; font-weight: 600; letter-spacing: 0; }
.original-file + .original-file { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--color-hairline); }
.original-frame > pre { max-height: 60vh; overflow: auto; margin: 0; }
.original-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 var(--space-4); margin: var(--space-1) 0 0; font-size: 14px; line-height: 1.43; }
.original-actions a { display: inline-flex; align-items: center; min-height: var(--target); margin-left: auto; }
/* Receipt facts (D7): source and receipt time of the main version, of a version card and of a previewed file,
   label and value side by side even on a phone. */
dl.receipt-facts { gap: 0 var(--space-4); margin: 0; }
dl.receipt-facts > div { display: flex; flex-wrap: wrap; gap: 0 var(--space-2); flex: 0 1 auto; }
dl.receipt-facts dd { margin: 0; }
.document-heading .document-receipt { margin-top: var(--space-1); }
.candidate-receipt { margin-bottom: var(--space-1); }
.same-file { margin: 0 0 var(--space-1); font-size: 14px; line-height: 1.43; font-weight: 500; }
.original-preview {
  display: block; width: 100%; height: min(60vh, 350px); object-fit: contain;
  border: 1px solid var(--color-hairline); border-radius: var(--radius-control); background: var(--color-canvas);
}
.document-steps > article, .document-steps > details, .document-steps > section { margin: 0 0 var(--space-4); }
/* Case B (D7): every version expanded and equal under «Версии документа (N)»; case A: the other receipts of the
   file are cards inside the closed «Другие получения того же файла (N)». */
.versions > h2 { margin: var(--space-2) 0 var(--space-3); }
.versions > article:last-child { margin-bottom: 0; }
.other-receipts > article:last-child { margin-bottom: var(--space-4); }
.document-steps > :last-child { margin-bottom: 0; }
.candidate-review > section { margin: var(--space-5) 0 0; padding-top: var(--space-4); border-top: 1px solid var(--color-hairline); }
.candidate-review > details.disclosure:first-of-type { margin-top: var(--space-4); border-top: 1px solid var(--color-hairline); }
.candidate-review > details.disclosure:last-child, .candidate-review > details.disclosure:last-child > :last-child { margin-bottom: 0; }
.candidate-review > details.disclosure:last-child { border-bottom: 0; }
/* Steps of a version card (D7, task 5.1): 1 «Поля документа», then 2 «Решение». Step 1 names the problems
   of the saved version over its form; each field may offer the recognized value («Распознано: … —
   перенести», copied by review.js). Saving fields opens the page on step 2 (#decision-<id>), highlighted. */
.step-title { display: flex; align-items: center; gap: var(--space-2); }
.step-number {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 24px; height: 24px;
  border-radius: var(--radius-pill); background: var(--color-accent-tint); color: var(--color-accent-strong);
  font-size: 14px; line-height: 1; font-weight: 600;
}
.problem-list { list-style: none; }
.problem-list li + li { margin-top: var(--space-1); }
.step-summary { margin-bottom: var(--space-2); }
.suggestion { max-width: 100%; margin-top: var(--space-2); padding: 6px 14px; border-radius: var(--radius-pill); text-align: left; }
.step { scroll-margin-top: var(--space-2); }
.candidate-review > .step:target { border-top-width: 2px; }
/* Previous and next documents of the queue filter (D7, task 5.3): GET links that keep ?status=, after the
   history; «Следующий в очереди» stays on the right even without a previous document. */
.document-neighbours { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 var(--space-4); }
.document-neighbours a { display: inline-flex; align-items: center; min-height: var(--target); }
.document-neighbours .neighbour-next { margin-left: auto; }
details.disclosure.panel {
  padding: 0 var(--space-4); background: var(--color-surface);
  border: 1px solid var(--color-hairline); border-radius: var(--radius-card);
}
details.disclosure.panel > h3 { margin-top: var(--space-4); }
.field-list { display: grid; grid-template-columns: minmax(0, 1fr); margin: 0 0 var(--space-3); font-size: 14px; line-height: 1.43; }
.field-list dt { color: var(--color-text-body); }
.field-list dd { margin: 0 0 var(--space-2); color: var(--color-text); }
.word-list { margin: 0; padding-left: var(--space-6); font-size: 14px; line-height: 1.43; color: var(--color-text); }
.word-list li + li { margin-top: var(--space-1); }
.word { font-weight: 500; }
.history-list { margin: 0 0 var(--space-4); padding: 0; list-style: none; }
.history-list > li { padding: var(--space-3) 0; border-bottom: 1px solid var(--color-hairline); }
.history-list > li > p { margin-bottom: var(--space-1); }
.history-list > li > details.disclosure { border-bottom: 0; }
/* Sources, the report row and appointments (D12, task 6.3): a source is a card with its name and one
   state pill on top, its facts as «поле — значение»; diagnostics in disclosures. The report row lists its
   origin with the technical fields labelled; appointment rows are cards below 761 px, their origin cell
   (reason and the disclosure of the row's cells) takes the whole card width. */
.source-card { margin: 0 0 var(--space-4); }
.source-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-4); margin: 0 0 var(--space-3); }
.source-heading > .source-name { flex: 1 1 12rem; min-width: 0; margin: 0; }
.source-part { margin: var(--space-5) 0 var(--space-2); padding-top: var(--space-4); border-top: 1px solid var(--color-hairline); }
.source-heading + .source-part { margin-top: 0; padding-top: 0; border-top: 0; }
.source-card .field-list { margin-bottom: var(--space-3); }
.source-card > details.disclosure, .sheet-snapshot details.disclosure { margin: 0 0 var(--space-3); }
.source-list > .notice { margin-bottom: var(--space-5); }
.row-card h2 { margin-bottom: var(--space-4); }
.row-card .button { margin-top: var(--space-2); }
main > details.disclosure.panel { margin: 0 0 var(--space-4); }
.origin-list { margin: 0; padding-left: var(--space-5); font-size: 14px; line-height: 1.43; color: var(--color-text); }
.origin-list li + li { margin-top: var(--space-1); }
.sheet-snapshot { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--color-hairline); }
.sheet-snapshot > h4 { margin-top: var(--space-5); }
table.stack td.stack-wide { display: block; text-align: left; }
table.stack td.stack-wide::before { display: block; }
.stack-wide .excluded-reason { margin: 0 0 var(--space-1); color: var(--color-text); font-weight: 600; }
.stack-wide details.disclosure { border-bottom: 0; }
.stack-wide details.disclosure > :not(summary) { margin-bottom: var(--space-2); }
/* Settings (ui-managed-settings D13): one card and one form per section, in the page order; a field
   whose source already has data is shown as text with its explanation; each column is a header and
   a letter side by side even on a phone; «ID записи» only for «По колонке с ID записи» (a browser
   without :has() keeps it visible, and the server ignores it for the other way). */
.settings-card > h2 { margin-bottom: var(--space-3); }
.settings-saved { margin: 0 0 var(--space-3); }
.settings-card .form-error > :last-child { margin-bottom: 0; }
dl.settings-state { margin-bottom: var(--space-2); }
.locked-value { margin: 0; color: var(--color-text); font-weight: 500; overflow-wrap: break-word; }
.settings-group { margin: var(--space-5) 0; padding-top: var(--space-4); border-top: 1px solid var(--color-hairline); }
.settings-group:first-of-type { margin-top: var(--space-2); padding-top: 0; border-top: 0; }
.settings-group > legend { font-size: 16px; }
.settings-note { margin: 0 0 var(--space-4); }
.settings-columns > legend { margin-bottom: 0; }
/* «Выбрать файл» under the key field (task 6.4): hidden until settings.js shows it; its status line takes
   no room while empty. */
.key-file { margin: 0 0 var(--space-4); }
.key-file-status:empty { margin: 0; }
.column-pair { margin: var(--space-3) 0; }
.column-pair > legend { margin-bottom: 0; font-weight: 500; }
.column-pair > .hint { margin-top: 0; }
.column-fields { display: grid; grid-template-columns: minmax(0, 1fr) 6rem; gap: 0 var(--space-3); }
.column-fields > .field { margin: var(--space-2) 0; }
@supports selector(:has(*)) {
  .sheets-form:has(input[name="identity_mode"][value="snapshot_rows"]:checked) .column-entry { display: none; }
}
/* Connection state and history (task 6.3, D13): the pill and its text wrap under the card heading; one
   history entry per saved revision, the login and the field names wrap inside the card. */
.connection-state { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); margin: 0 0 var(--space-3); }
.connection-state > .pill { flex: none; }
.connection-text { min-width: 0; overflow-wrap: break-word; }
.settings-history { margin: 0; padding: 0; list-style: none; }
.settings-history > li { padding: var(--space-3) 0; border-top: 1px solid var(--color-hairline); }
.settings-history > li:first-child { padding-top: 0; border-top: 0; }
.settings-history > li:last-child { padding-bottom: 0; }
.settings-history p { margin: 0; }
.settings-history-author { font-weight: 600; overflow-wrap: break-word; }
.settings-history-fields { color: var(--color-text-body); overflow-wrap: break-word; }
/* Users (ui-managed-settings D14): one card per member, the login wraps inside its card; the own card has no forms. */
.settings-links { margin: 0; }
.user-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); margin: 0 0 var(--space-6); padding: 0; list-style: none; }
.user-list > .card { margin: 0; }
.user-heading { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
.user-heading > h3 { flex: 0 1 auto; min-width: 0; margin: 0; overflow-wrap: break-word; }
.user-card > details.disclosure { border-top: 1px solid var(--color-hairline); }
.user-actions { margin-top: var(--space-4); }
.login-card { max-width: 430px; margin: var(--space-6) auto var(--space-10); }
.login-card form button { margin-top: var(--space-2); }
.status-card { max-width: 560px; margin: var(--space-6) auto var(--space-10); }
.status-message { margin: 0 0 var(--space-5); }
.clinic-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
.clinic-list > .card { margin: 0; }
.clinic-card h2 { margin-bottom: var(--space-4); }

@media (min-width: 761px) {
  .app-header { position: sticky; top: 0; }
  /* Link targets and focused fields scroll in under the sticky header, not behind it (task 5.1).
     The padding is the header height: two rows here (117 px) when the clinic, the sections and the role
     do not fit in one row, which at these widths depends on the clinic name. */
  html { scroll-padding-top: 117px; }
  .header-inner { padding: var(--space-2) var(--space-6); gap: var(--space-1) var(--space-4); }
  .brand, .header-context, .header-demo, .header-user { order: 0; }
  .header-context { flex: 1 1 auto; }
  .header-clinic { max-width: 16rem; padding-left: var(--space-4); border-left: 1px solid var(--color-hairline); }
  .header-demo { margin: 0; }
  main { padding: var(--space-6) var(--space-6) var(--space-10); }
  .footer-inner { padding: var(--space-6) var(--space-6) var(--space-10); }
  .clinic-list { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  h1 { font-size: 28px; }
  .card, article { padding: var(--space-6); }
  dl.meta > div { flex: 0 1 auto; }
  table.stack { display: table; }
  table.stack thead { position: static; width: auto; height: auto; overflow: visible; clip: auto; display: table-header-group; }
  table.stack tbody { display: table-row-group; }
  table.stack tr { display: table-row; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; }
  table.stack td, table.stack th, table.stack tbody th { display: table-cell; padding: var(--space-3); text-align: left; }
  table.stack td.num, table.stack td.money { text-align: right; }
  table.stack td::before, table.stack tbody th::before { content: none; }
  table.stack tr > :last-child { border-bottom: 1px solid var(--color-hairline); }
  table.stack td.stack-wide { display: table-cell; }
  .summary-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .total { font-size: 44px; }
  .total-card .button { display: inline-flex; width: auto; }
  .filter-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr) auto; }
  .report-search { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr); }
  .report-search .actions { grid-column: 1 / -1; }
  .report-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .queue-row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding: var(--space-2) var(--space-6); }
  .queue-row > .pill { justify-self: end; }
  .queue-note { margin-top: 0; padding-bottom: var(--space-2); }
  .queue-link { display: grid; grid-template-columns: 9rem minmax(0, 1fr) 9rem; }
  .queue-link .queue-amount { text-align: right; }
  .queue-versions { grid-column: 1 / -1; }
  .queue-empty { padding: var(--space-6); }
  .document-original, details.disclosure.panel { padding-left: var(--space-6); padding-right: var(--space-6); }
  .document-original { padding-top: var(--space-5); padding-bottom: var(--space-5); }
  .original-preview { height: min(60vh, 480px); }
  .field-list > div { display: grid; grid-template-columns: minmax(0, 14rem) minmax(0, 1fr); gap: 0 var(--space-4); margin: 0 0 var(--space-1); }
  .field-list dd { margin: 0; }
}

@media (min-width: 1101px) {
  /* One header row (69 px), as the pinned original column assumes (top: 88px). */
  html { scroll-padding-top: 69px; }
  /* D10: the search fields and its buttons in one row. */
  .report-search { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr) auto; }
  .report-search .actions { grid-column: auto; flex-wrap: nowrap; }
  .document-layout { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: var(--space-6); align-items: start; }
  .document-original { position: sticky; top: 88px; max-height: calc(100vh - 104px); overflow-y: auto; }
  /* The whole original card fits the first screen under the page heading and stays so when pinned. */
  .document-original .original-preview { height: calc(100vh - 340px); min-height: 360px; }
}

@media (min-width: 1101px) and (max-width: 1117px) {
  /* With the demo label and a clinic name near 16rem the header still takes two rows here (117 px). */
  html:has(.header-demo) { scroll-padding-top: 117px; }
}
