:root {
  --bg: #f6f7f8;
  --surface: #fff;
  --text: #1c2126;
  --muted: #5d6771;
  --border: #d9dee3;
  --accent: #1f5f8b;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --error: #b3261e;
  --ok-bg: #e4f3e8;
  --halo: rgba(31, 95, 139, .15);
  --final: #173f5f;
  --missing-bg: #fdecea;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, "Segoe UI", sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }

.dev-banner { background: var(--warn-bg); color: var(--warn-text); text-align: center; font-size: .85rem; padding: 4px; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar a + a { margin-left: 16px; }
.topbar { display: flex; align-items: center; flex-wrap: wrap; }
.user { margin-left: auto; color: var(--muted); }
.logout { display: inline; }
button.link { background: none; border: 0; padding: 0 0 0 8px; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; }
.login { max-width: 360px; margin: 32px auto; }
.edit-link { font-size: .85rem; font-weight: 400; margin-left: 8px; }
dialog.edit-card { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); border: 1px solid var(--border); border-radius: 6px; padding: 16px; }
dialog.edit-card::backdrop { background: rgba(0, 0, 0, .4); }
dialog.edit-card button.secondary { margin-left: 8px; }
.field-history { display: inline; font-weight: 400; }
.field-history summary { display: inline; cursor: pointer; list-style: none; }
.field-history summary::-webkit-details-marker { display: none; }
.field-history ol { margin: 4px 0 8px; padding-left: 18px; }
.field-history small { display: block; color: var(--muted); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: .9rem; margin: 0; }

.button, button { display: inline-block; background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 6px; padding: 8px 14px; font: inherit; text-decoration: none; cursor: pointer; }
.button.secondary { background: var(--surface); color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.search { display: flex; gap: 8px; margin-bottom: 12px; }
.search input[type=search] { flex: 1; min-width: 0; }

/* The list scrolls inside its frame, so both scrollbars stay on screen; the header and the number stay in place. */
.table-wrap { overflow: auto; max-height: calc(100vh - 140px); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.table-wrap thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); }
.table-wrap tbody td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.table-wrap thead th:first-child { left: 0; z-index: 3; }
.table-wrap tbody tr:hover td { background: #f0f4f8; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: .95rem; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
th a.sort { color: inherit; text-decoration: none; }
th a.sort:hover { color: var(--text); text-decoration: underline; }
th[aria-sort] a.sort { color: var(--text); }
tr:last-child td { border-bottom: 0; }

.flag { background: var(--warn-bg); color: var(--warn-text); padding: 2px 6px; border-radius: 4px; font-size: .85rem; white-space: nowrap; }
.warning { background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 6px; }
.empty { color: var(--muted); padding: 24px 0; }
.pager { display: flex; gap: 12px; padding: 12px 0; align-items: center; }

.message { padding: 10px 12px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }
.message.success { background: var(--ok-bg); }
.message.error { color: var(--error); border-color: var(--error); }

section { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 14px; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.grid section { margin-bottom: 0; }
.grid { margin-bottom: 12px; }
dl { margin: 0; }
dt { color: var(--muted); font-size: .85rem; }
dd { margin: 0 0 8px; overflow-wrap: anywhere; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

.timeline { margin: 0; padding-left: 18px; }
.timeline > li { margin-bottom: 12px; }
.timeline .muted { display: block; }
.timeline p { margin: 4px 0; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field small { display: block; color: var(--muted); margin-top: 4px; }
input, select, textarea { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff; color: var(--text); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--error); background: var(--missing-bg); }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--error); font-size: .9rem; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lifecycle { display: flex; list-style: none; margin: 4px 0 10px; padding: 4px 0 2px; overflow-x: auto; }
.lifecycle .stage { flex: 1 1 0; min-width: 104px; position: relative; text-align: center; padding-top: 46px; font-size: .85rem; color: var(--text); }
.lifecycle .stage::before { content: ""; position: absolute; top: 19px; left: -50%; right: 50%; border-top: 2px solid var(--border); z-index: 0; }
.lifecycle .stage:first-child::before { display: none; }
.lifecycle .done::before, .lifecycle .current::before, .lifecycle .final::before { border-top-color: var(--accent); }
.lifecycle .marker { position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 1; display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; box-sizing: border-box; border-radius: 50%; border: 2px solid var(--border); background: var(--surface); color: var(--muted); }
.lifecycle .icon { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.lifecycle .done .marker { background: var(--accent); border-color: var(--accent); color: #fff; }
.lifecycle .current .marker { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 4px var(--halo); }
.lifecycle .current .name, .lifecycle .final .name { font-weight: 700; }
.lifecycle .final .marker { background: var(--final); border-color: var(--final); color: #fff; box-shadow: 0 0 0 4px var(--halo); }
.lifecycle .upcoming { color: var(--muted); }
.lifecycle .upcoming .marker { background: var(--bg); }
.lifecycle .skipped .marker { border-style: dashed; border-color: var(--muted); }
.lifecycle .skipped, .lifecycle .na { color: var(--muted); }
.lifecycle .na .marker { border-style: dashed; border-color: var(--border); background: var(--bg); opacity: .75; }
.lifecycle .note { display: block; font-size: .75rem; font-weight: 400; color: var(--muted); }
.lifecycle .current .note { color: var(--accent); font-weight: 600; }
.stage-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
form.inline { display: inline; margin: 0; }
.missing { background: var(--missing-bg); border-radius: 4px; padding: 0 4px; }
dd.missing::after { content: "Липсва"; margin-left: 6px; color: var(--error); font-size: .85rem; }
.missing-box a { font-weight: 600; }
[data-missing] { background: var(--missing-bg); border-color: var(--error); }
@media (max-width: 700px) {
  .table-wrap { overflow: visible; max-height: none; }
  .table-wrap thead th, .table-wrap tbody td:first-child { position: static; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: auto; }
  .table-wrap thead tr { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 8px 10px; }
  .table-wrap thead th { padding: 0; border: 0; }
  .table-wrap tbody tr { border-bottom: 1px solid var(--border); padding: 8px 10px; }
  .table-wrap tbody td { border: 0; padding: 2px 0; }
  .table-wrap tbody td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85rem; }
}
.deadline { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: .85rem; white-space: nowrap; border: 1px solid transparent; }
.deadline.ok { background: #e4f3e8; color: #1e6b34; border-color: #9fd3ae; }
.deadline.approaching { background: #fff0db; color: #8a4b00; border-color: #f2b56b; }
.deadline.overdue { background: #fde7e5; color: #a32019; border-color: #f0a29b; }
.deadline.far_overdue { background: #b3261e; color: #fff; }
.deadline.closed { background: var(--bg); color: var(--muted); border-color: var(--border); }
.deadline.missing-start { background: var(--missing-bg); color: var(--error); }
.deadline-line { margin: 6px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.chip { padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; font-size: .85rem; color: var(--text); }
.chip.active { border-color: var(--accent); background: var(--accent); color: #fff; }
.chip-overdue:not(.active) { border-color: #f0a29b; }
.chip-approaching:not(.active) { border-color: #f2b56b; }
.legend { font-size: .8rem; }
.search select { flex: 0 0 auto; width: auto; max-width: 45%; font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
/* Like the list: the board scrolls inside its frame, so the side scrollbar is always on screen. */
.board { display: grid; grid-template-columns: repeat(6, minmax(180px, 1fr)); gap: 10px; overflow: auto; max-height: calc(100vh - 170px); padding-bottom: 8px; }
.board-column { margin: 0; padding: 0 10px 10px; background: var(--bg); }
.board-column h2 { font-size: 1rem; margin: 0 -10px 8px; padding: 10px; position: sticky; top: 0; z-index: 1; background: var(--bg); border-bottom: 1px solid var(--border); }
.board-card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.board-card p { margin: 0 0 4px; }
.board-number { font-weight: 600; }
.board-moves { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.button.small, button.small { font-size: .8rem; padding: 3px 8px; }
@media (max-width: 700px) { .board { grid-template-columns: repeat(6, 82vw); } }
/* Bands: each fact of a card has its own tint; the colours carry no status (status colours are green, orange, red). */
.band { border: 1px solid var(--border); border-left-width: 4px; border-radius: 6px; padding: 8px 12px; margin: 0 0 10px; }
.band legend, .band-title { font-weight: 700; font-size: .9rem; padding: 0 4px; margin: 0 0 4px; }
.band .form-grid { margin-bottom: 4px; }
.band-notified { background: #eef4fb; border-left-color: #5b8fc7; }
.band-waybill { background: #f4f4f6; border-left-color: #8a8f99; }
.band-receipt { background: #eef7f7; border-left-color: #3f9a9a; }
.band-supplier { background: #f3f0f9; border-left-color: #8467b8; }
.band-deadline { background: #eef1f5; border-left-color: var(--final); }
dialog.edit-card:has(.band) { width: min(760px, calc(100vw - 32px)); }
.note { color: var(--muted); background: var(--bg); border: 1px dashed var(--border); padding: 8px 12px; border-radius: 6px; }
.tag { background: var(--bg); color: var(--muted); border: 1px solid var(--border); padding: 1px 6px; border-radius: 4px; font-size: .8rem; white-space: nowrap; }
.grid .wide { grid-column: 1 / -1; }
.bands { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 8px; }
.bands .band { margin: 0; }
/* In a band the inputs line up even when one label runs to two lines. */
.band .field label { min-height: 3em; display: flex; align-items: flex-end; }
/* UX-1: the list and the board use the width of the screen up to 1600 px; the case page stays narrow for reading. */
main.wide { max-width: 1600px; }
/* UX-A13-01: a radio button or a tick box sits right before its own text, and the whole row is clickable. */
input[type=radio], input[type=checkbox] { width: auto; flex: none; margin: .2em 0 0; accent-color: var(--accent); }
fieldset.choice-group { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.choice-group legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.field label.choice, .field label.check { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-weight: 400; cursor: pointer; }
.field label.choice { padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.field label.choice:has(input:checked) { border-color: var(--accent); background: #eef4fb; font-weight: 600; }
.field label.choice:has(input:focus-visible), .field label.check:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.has-error label.choice { border-color: var(--error); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
dialog.edit-card .form-actions { position: sticky; bottom: -16px; background: var(--surface); padding: 10px 0 2px; border-top: 1px solid var(--border); }
dialog.edit-card .form-actions button.secondary { margin-left: 0; }
.message.error ul { margin: 4px 0 0; padding-left: 18px; }
.message.error p { margin: 0; }
/* UX-A13-02/03: one column in the order of the work; inputs that do not apply are hidden, the server still checks all. */
.notice-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; max-width: 640px; margin-bottom: 16px; }
.notice-form .pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 12px; }
.notice-form .field, .notice-form .pair > * { min-width: 0; }
button.secondary { background: var(--surface); color: var(--accent); }
/* A part with an error always stays visible, so the employee can see and fix what the server refused. */
.notice-form:has(select[name=message] option:checked:not([value=""])) .manual-only:not(:has(.has-error)) { display: none; }
.notice-form:not(:has(select[name=message] option:checked:not([value=""]))) .email-only:not(:has(.has-error)) { display: none; }
.notice-form:not(:has(input[name=performer][value=OTHER]:checked)) .other-only:not(:has(.has-error)) { display: none; }
/* Without :has() every input shows; that is the safe side. */
@supports selector(:has(*)) { .notice-form .before-only:not(.shown), .notice-form .reopen-only:not(.shown) { display: none; } }
.date-echo:empty { display: none; }
.case-number { white-space: nowrap; font-weight: 600; }
.table-wrap td .flag, .table-wrap td .tag { display: inline-block; margin-top: 2px; white-space: normal; font-size: .78rem; }
.table-wrap td:first-child .flag, .table-wrap td:first-child .tag { display: block; width: max-content; max-width: 14em; }
details.legend { color: var(--muted); margin: 0 0 8px; }
details.legend summary { cursor: pointer; width: max-content; }
.board-card { padding: 6px 8px; }
.board-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; }
.board-who { font-size: .9rem; overflow-wrap: anywhere; }
.board-worker { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
/* A5: next action and last worker under the stage in the list. */
.list-next { display: block; font-weight: 600; font-size: var(--text-3); }
.list-worker { display: block; color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
.board-moves { margin-top: 4px; }
.board-head .deadline { font-size: .72rem; padding: 0 6px; }
.board-moves .button.small, .board-moves button.small { font-size: .75rem; padding: 2px 6px; }

/* ===== Visual system v2 (docs/UX_UI_STANDARD.md, sections 8-10): tokens, application shell, Case Detail. ===== */
:root {
  /* Colour tokens: one semantic palette; the old names point to the new values so every page follows. */
  --sidebar: #17243d; --sidebar-text: #e6ebf3; --sidebar-muted: #9fb0c8; --sidebar-active: #1d4ed8;
  --bg: #f6f8fb; --surface: #fff; --text: #172334; --muted: #5b6b80; --border: #dfe6ef; --border-strong: #c9d3e0;
  --accent: #1d4ed8; --accent-hover: #1e40af; --accent-bg: #eff6ff;
  --success: #15803d; --success-bg: #ecfdf3; --success-line: #abefc6;
  --warning: #92400e; --warning-bg: #fffbeb; --warning-line: #f5c46b;
  --danger: #b42318; --danger-bg: #fef3f2; --danger-line: #fecdca;
  --info: #1d4ed8; --info-bg: #eff6ff;
  --error: #b42318; --missing-bg: #fef3f2; --ok-bg: #ecfdf3; --warn-bg: #fffbeb; --warn-text: #92400e;
  --halo: rgba(29, 78, 216, .18); --final: #17243d; --focus: #1d4ed8;
  /* Space, radius, type. */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --radius: 10px; --radius-sm: 8px;
  --text-1: 15px; --text-2: 14px; --text-3: 13px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
body { font: var(--text-1)/1.5 system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 50; background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm); }
.skip-link:focus { left: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Buttons: primary / secondary / tertiary / destructive, one height and radius. ---------- */
.button, button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--accent); background: var(--accent); color: #fff; font: 600 var(--text-2)/1.3 inherit; font-family: inherit; text-decoration: none; cursor: pointer; }
.button:hover, button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button:active, button:active { transform: translateY(1px); }
button:disabled, .button[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.button.secondary, button.secondary { background: var(--surface); color: var(--accent); border-color: var(--border-strong); }
.button.secondary:hover, button.secondary:hover { background: var(--accent-bg); border-color: var(--accent); }
.button.tertiary { background: transparent; border-color: transparent; color: var(--accent); padding-inline: 8px; }
.button.tertiary:hover { background: var(--accent-bg); }
button.destructive { background: var(--surface); color: var(--danger); border-color: var(--danger-line); }
button.destructive:hover { background: var(--danger-bg); border-color: var(--danger); }
.button.small-40 { min-height: 36px; padding: 6px 12px; }
.button.small, button.small { min-height: 0; padding: 3px 8px; font-size: .8rem; }
button.link { min-height: 0; background: none; border: 0; color: var(--accent); padding: 0 0 0 8px; font-weight: 400; text-decoration: underline; }
input:not([type=radio]):not([type=checkbox]), select { min-height: 40px; }
input, select, textarea { border-color: var(--border-strong); border-radius: var(--radius-sm); }

/* ---------- Application shell: dark sidebar, light top bar, workspace. ---------- */
body.has-shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--s4); background: var(--sidebar); color: var(--sidebar-text); padding: var(--s4) var(--s3); overflow-y: auto; }
.sidebar a { color: inherit; text-decoration: none; }
.sidebar :focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; color: #fff; padding: 6px 8px 12px; }
.sidebar .brand .nav-icon { color: #60a5fa; }
.nav-icon, .ic { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.nav-list a { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border-radius: var(--radius-sm); color: var(--sidebar-text); font-weight: 500; }
.nav-list a:hover { background: rgba(255, 255, 255, .08); }
.nav-list a[aria-current="page"] { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-user { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, .12); padding: var(--s3) 8px 0; display: grid; gap: 6px; }
.nav-user .user { margin: 0; color: var(--sidebar-text); display: grid; }
.user-name { font-weight: 600; }
.user-role { color: var(--sidebar-muted); font-size: var(--text-3); }
.nav-user .logout { display: block; }
.nav-logout { min-height: 36px; width: 100%; justify-content: flex-start; background: transparent; border-color: rgba(255, 255, 255, .18); color: var(--sidebar-text); font-weight: 500; }
.nav-logout:hover { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .3); }
.workspace { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s3); min-height: 56px; padding: 0 var(--s6); background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar a + a { margin-left: 0; }
.breadcrumb { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: var(--text-2); color: var(--muted); }
.breadcrumb a { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; }
.breadcrumb a:hover { color: var(--accent); text-decoration: underline; }
.breadcrumb [aria-current] { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--border-strong); }
.dev-banner { margin-left: auto; background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-line); border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; text-align: left; }
body.no-shell .topbar { justify-content: flex-end; }
main { width: 100%; max-width: 1180px; margin: 0 auto; padding: var(--s5) var(--s6) var(--s6); }
main.wide { max-width: 1680px; }
main.case-page { max-width: 1520px; }
.message { border-radius: var(--radius-sm); margin: 0 0 var(--s3); }
.message.success { border-color: var(--success-line); color: var(--success); background: var(--success-bg); }
section { border-radius: var(--radius); }
@media (max-width: 1023px) {
  body.has-shell { display: block; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 4px var(--s3); padding: 8px var(--s4); }
  .sidebar .brand { padding: 4px 4px; font-size: 16px; }
  .nav-list { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav-list a { min-height: 40px; padding: 0 10px; gap: 8px; }
  .nav-user { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; align-items: center; gap: 8px; }
  .user-role { display: none; }
  .nav-logout { width: auto; }
  .topbar { position: static; padding: 0 var(--s4); min-height: 48px; }
  main { padding: var(--s4); }
}
@media (max-width: 600px) {
  .nav-user .user { display: none; }
  .nav-list a span, .nav-logout span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .nav-user { margin-left: 0; }
  .nav-list a { padding: 0 11px; }
  .nav-list a[aria-current="page"] span { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  .dev-banner { display: none; }
}

/* ---------- Chips: compact status with a sign; colour supports the text, never replaces it. ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: var(--text-3); font-weight: 600; line-height: 1.5; white-space: nowrap; vertical-align: middle; text-decoration: none; }
.chip-stage { background: var(--accent-bg); border-color: #bfd3fb; color: var(--accent); font-size: 14px; padding: 4px 12px; }
.chip-ok { background: var(--success-bg); border-color: var(--success-line); color: var(--success); }
.chip-warn { background: var(--warning-bg); border-color: var(--warning-line); color: var(--warning); }
.chip-danger { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.chip-neutral { background: var(--bg); color: var(--muted); font-weight: 500; }
.chip-customer { background: var(--accent-bg); border-color: #bfd3fb; color: var(--accent); }
.chip-supplier { background: #f4f0fb; border-color: #d9cdf1; color: #5b3f9a; }
.status { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid var(--border); background: var(--bg); }
.count { display: inline-block; min-width: 1.7em; padding: 0 6px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: 12px; font-weight: 600; text-align: center; color: var(--muted); line-height: 1.6; }
.deadline { border-radius: 999px; padding: 1px 10px; font-weight: 600; font-size: var(--text-3); }
.muted { color: var(--muted); font-size: var(--text-2); margin: 0; }
.muted-inline { color: var(--muted); font-size: var(--text-3); }
.note { color: var(--muted); background: var(--bg); border: 1px dashed var(--border-strong); padding: 8px 12px; border-radius: var(--radius-sm); font-size: var(--text-2); margin: 0; }
.empty-state { color: var(--muted); background: var(--bg); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: var(--s3) var(--s4); margin: 0; font-size: var(--text-2); }

/* ---------- Case Detail: header ---------- */
.case-header { margin: 0 0 var(--s4); }
.case-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2) var(--s3); }
.case-header h1 { font-size: 26px; font-weight: 650; letter-spacing: -.01em; margin: 0; line-height: 1.25; }
.header-link { margin-left: auto; }
.case-meta { display: flex; flex-wrap: wrap; gap: 2px 0; margin: var(--s2) 0 0; font-size: var(--text-2); }
.case-meta > span:not(:last-child)::after { content: "|"; color: var(--border-strong); margin: 0 12px; }
.meta-label { color: var(--muted); }
.indicators { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s6); margin: var(--s3) 0 0; }
.indicators > div { display: flex; align-items: baseline; gap: 8px; }
.indicators dt { color: var(--muted); font-size: var(--text-3); }
.indicators dd { margin: 0; font-size: var(--text-2); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s4) var(--s5); margin: 0; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2) var(--s3); flex-wrap: wrap; margin: 0 0 var(--s3); }
.card-head h2 { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 650; margin: 0; }
.card-head h2 .ic { color: var(--muted); }
.card-head .muted { font-size: var(--text-3); }
.edit-link { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-3); font-weight: 500; margin: 0; }
.group { border-top: 1px solid var(--border); padding-top: var(--s3); margin-top: var(--s3); }
.card-head + .group { border-top: 0; padding-top: 0; margin-top: 0; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s2); }
.group-head h3 { font-size: var(--text-1); font-weight: 650; margin: 0; }
.group p { margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: minmax(96px, 38%) minmax(0, 1fr); gap: 6px var(--s3); margin: 0; font-size: var(--text-2); }
.kv dt { color: var(--muted); font-size: var(--text-2); margin: 0; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
/* UAT DEF-02: a row with its own edit keeps the value left and the edit right, like a card head. */
.kv dd.kv-with-action { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2); }
#external .kv + .card-head { margin-top: var(--s4); }
.kv-grid { grid-template-columns: minmax(110px, 22%) minmax(0, 1fr); }
dd.missing, dt.missing { background: none; padding: 0; }
dd.missing { color: var(--warning); font-weight: 600; }
dd.missing::after { content: none; }
dt.missing { color: var(--warning); }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.description { margin-top: var(--s3); border-top: 1px solid var(--border); padding-top: var(--s2); font-size: var(--text-2); }
.kv-label { color: var(--muted); margin: 0 0 4px; }
.gap { margin: var(--s2) 0 0; font-size: var(--text-3); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.gap a { font-weight: 600; }
.field-history summary { font-size: 12px; opacity: .75; }
details.more > summary, details.inline-form > summary, details.danger-zone > summary { cursor: pointer; color: var(--accent); font-size: var(--text-3); font-weight: 600; padding: 4px 0; }
details.danger-zone > summary { color: var(--danger); font-weight: 500; }
details.more { margin-top: var(--s2); }
details.data-card > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: var(--text-2); }
details.data-card[open] > summary { margin-bottom: var(--s3); }

/* ---------- Stepper ---------- */
.lifecycle-panel { padding: var(--s3) var(--s4) var(--s2); margin-bottom: var(--s4); }
.lifecycle { display: flex; list-style: none; margin: 0; padding: 4px 0 0; overflow-x: auto; overflow-y: hidden; }
.lifecycle .stage { flex: 1 1 0; min-width: 104px; position: relative; text-align: center; padding-top: 42px; font-size: var(--text-3); color: var(--text); line-height: 1.35; }
.lifecycle .stage::before { content: ""; position: absolute; top: 17px; left: -50%; right: 50%; border-top: 2px solid var(--border); z-index: 0; }
.lifecycle .stage:first-child::before { display: none; }
.lifecycle .done::before, .lifecycle .current::before, .lifecycle .final::before { border-top-color: var(--success); }
.lifecycle .marker { position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 1; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface); color: var(--muted); }
.lifecycle .icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lifecycle .done .marker { background: var(--success); border-color: var(--success); color: #fff; }
.lifecycle .current .marker { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 0 0 4px var(--halo); }
.lifecycle .final .marker { background: var(--success); border-color: var(--success); color: #fff; box-shadow: 0 0 0 4px rgba(21, 128, 61, .18); }
.lifecycle .name { display: block; font-weight: 500; }
.lifecycle .current .name, .lifecycle .final .name { font-weight: 700; }
.lifecycle .date { display: block; color: var(--muted); font-size: 12px; }
.lifecycle .upcoming { color: var(--muted); }
.lifecycle .na, .lifecycle .skipped { color: var(--muted); }
.lifecycle .na .marker, .lifecycle .skipped .marker { border-style: dashed; background: var(--bg); }
.lifecycle .stage-note { display: block; font-size: 12px; color: var(--muted); font-style: italic; }

/* ---------- Next action panel ---------- */
.next-panel { background: none; border: 0; padding: 0; margin: 0 0 var(--s3); display: grid; gap: var(--s2); box-shadow: none; }
.next-panel:not(:has(.next)) { display: none; }
.next { display: flex; align-items: center; gap: var(--s4); border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius); padding: var(--s3) var(--s5); background: var(--surface); }
.next-icon { flex: none; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; font-weight: 700; }
.next-body { flex: 1; min-width: 0; }
.next-label { margin: 0; font-size: var(--text-3); font-weight: 700; letter-spacing: .02em; }
.next-title { margin: 2px 0 2px; font-size: 18px; font-weight: 650; line-height: 1.35; }
.next-why { margin: 0; color: var(--muted); font-size: var(--text-2); }
.next .actions { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: flex-end; flex: none; max-width: 46%; }
.next-action { background: var(--warning-bg); border-color: var(--warning-line); border-left-color: #d97706; }
.next-action .next-icon { color: #b45309; background: #fef3c7; }
.next-action .next-label { color: var(--warning); }
.next-options { background: var(--accent-bg); border-color: #bfd3fb; border-left-color: var(--accent); align-items: flex-start; }
.next-options .next-icon { color: var(--accent); background: #dbeafe; }
.next-options .next-label { color: var(--accent); }
.next-blocker { background: var(--danger-bg); border-color: var(--danger-line); border-left-color: var(--danger); padding-block: var(--s2); }
.next-blocker .next-icon { color: var(--danger); background: #fee4e2; width: 30px; height: 30px; }
.next-blocker .next-label { color: var(--danger); }
.next-warning { background: var(--warning-bg); border-color: var(--warning-line); border-left-color: var(--warning-line); padding-block: var(--s2); }
.next-warning .next-icon { color: var(--warning); background: #fef3c7; width: 30px; height: 30px; }
.next-warning .next-label { color: var(--warning); }
.next-success { background: var(--success-bg); border-color: var(--success-line); border-left-color: var(--success); padding-block: var(--s2); }
.next-success .next-icon { color: #fff; background: var(--success); width: 30px; height: 30px; }
.next-success .next-label { color: var(--success); }
.next-success .next-title { font-size: var(--text-1); font-weight: 400; }
.option-list { list-style: none; margin: var(--s2) 0 0; padding: 0; display: grid; gap: var(--s2); }
.option-list li { display: flex; align-items: center; flex-wrap: wrap; gap: 4px var(--s3); }
.option-list .button, .option-list form { flex: none; }
.gap-list { margin: 2px 0 4px; padding-left: 18px; font-size: var(--text-2); }
.link-button { font-weight: 600; }

/* ---------- Section tabs ---------- */
.section-tabs { display: flex; gap: var(--s1) var(--s4); border-bottom: 1px solid var(--border); margin: 0 0 var(--s4); overflow-x: auto; }
.section-tabs a { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 6px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: var(--text-2); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.section-tabs a:hover { color: var(--text); }
.section-tabs a.active, .section-tabs a[aria-current="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Content grid ---------- */
.case-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); align-items: start; }
.case-main, .case-context { display: grid; gap: var(--s4); min-width: 0; align-content: start; }
@media (min-width: 1024px) {
  .case-layout { grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: var(--s5); }
}
.case-layout [id], .next-panel, .case-header { scroll-margin-top: 72px; }

/* Decision card */
.decision-chip { font-size: var(--text-2); }
.empty-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: var(--text-2); }
.history-line { font-size: var(--text-2); color: var(--muted); }
.history-line strong { color: var(--text); }
.record-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.record { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s2) var(--s4); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s2) var(--s3); background: #fbfcfe; }
.record-main { flex: 1 1 320px; min-width: 0; font-size: var(--text-2); }
.record-main p { margin: 0 0 2px; }
.record-action { flex: 0 1 260px; display: grid; gap: 4px; align-content: start; }
.checks { list-style: none; margin: 0 0 var(--s2); padding: 0; }
.checks li { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: 7px 0; border-bottom: 1px solid var(--border); font-size: var(--text-2); }
.checks li:last-child { border-bottom: 0; }

/* Processing rows */
table.rows { width: 100%; border-collapse: collapse; font-size: var(--text-2); }
table.rows th, table.rows td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.rows th { color: var(--text); font-weight: 500; white-space: normal; }
table.rows tr:last-child th, table.rows tr:last-child td { border-bottom: 0; }
table.rows td:nth-child(3) { white-space: nowrap; }
.muted-cell { color: var(--muted); font-size: var(--text-3); }
.stage-control { border-top: 1px solid var(--border); margin-top: var(--s3); padding-top: var(--s3); }
.stage-control h3 { font-size: var(--text-1); margin: 0 0 4px; }
.stage-control .actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }

/* Correspondence */
.mail-list { list-style: none; margin: 0; padding: 0; }
.mail-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px var(--s3); align-items: start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.mail-row:last-child { border-bottom: 0; }
.mail-row p { margin: 0; }
.mail-subject { font-size: var(--text-2); overflow-wrap: anywhere; }
.mail-date { color: var(--muted); font-size: var(--text-3); white-space: nowrap; }
.mail-files { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: var(--text-3); margin-top: 2px !important; }
.mail-files .ic { color: var(--muted); }

/* History */
.history { list-style: none; margin: 0; padding: 0; }
.history > li { border-bottom: 1px solid var(--border); }
.history > li:last-child { border-bottom: 0; }
/* The whole row opens and closes the event; the chevron shows the state (native details/summary). */
details.event > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 14px 128px minmax(0, 1fr); column-gap: var(--s3); padding: 8px 6px 8px 4px; margin: 0 -6px 0 -4px; border-radius: var(--radius-sm); font-size: var(--text-2); }
details.event > summary::-webkit-details-marker { display: none; }
details.event > summary .chev { grid-row: span 2; color: var(--muted); line-height: 1.45; }
details.event > summary .chev::before { content: "▸"; }
details.event[open] > summary .chev::before { content: "▾"; }
details.event > summary time { color: var(--muted); font-variant-numeric: tabular-nums; grid-row: span 2; }
details.event > summary .event-text { grid-column: 3; color: var(--muted); font-size: var(--text-3); overflow-wrap: anywhere; }
details.event > summary:hover { background: var(--bg); }
details.event > summary:hover strong, details.event > summary:hover .chev { color: var(--accent); }
.event-details { margin: 0 0 var(--s2) 166px; padding: var(--s2) var(--s3); background: var(--bg); border-radius: var(--radius-sm); font-size: var(--text-3); }
.event-details p, .event-details ul { margin: 2px 0; }

/* Dialogs */
dialog.edit-card { border: 1px solid var(--border); border-radius: 12px; padding: var(--s5) var(--s6); box-shadow: 0 20px 40px rgba(16, 24, 40, .18); }
dialog.edit-card h2 { font-size: 19px; }

@media (max-width: 700px) {
  .case-header h1 { font-size: 22px; }
  .header-link { margin-left: 0; }
  .case-meta > span:not(:last-child)::after { margin: 0 8px; }
  .indicators { gap: 4px var(--s4); }
  .card { padding: var(--s3) var(--s4); }
  .next { flex-wrap: wrap; padding: var(--s3) var(--s4); align-items: flex-start; }
  .next-icon { display: none; }
  .next .actions { max-width: none; width: 100%; justify-content: stretch; }
  .next .actions .button, .next .actions button, .next .actions form { flex: 1 1 100%; }
  .next .actions form button { width: 100%; }
  .next-title { font-size: 16px; }
  .kv-grid { grid-template-columns: minmax(0, 1fr); }
  .kv-grid dd { margin-bottom: 4px; }
  table.rows, table.rows tbody, table.rows tr, table.rows th, table.rows td { display: block; width: auto; }
  table.rows tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  table.rows th, table.rows td { border: 0; padding: 1px 0; }
  .mail-row { grid-template-columns: minmax(0, 1fr); }
  details.event > summary { grid-template-columns: 14px minmax(0, 1fr); }
  details.event > summary .chev { grid-row: span 3; }
  details.event > summary time { grid-row: auto; }
  details.event > summary .event-text { grid-column: 2; }
  .event-details { margin-left: 26px; }
}

/* Н1, Н3, Н4, Н5 (PO, 10.11.2026): display only. */
.lifecycle .stage-supplier { display: block; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.new-mail { display: inline-flex; vertical-align: middle; color: var(--accent); }
.mail-dir { display: inline-flex; vertical-align: -2px; margin-right: 4px; color: var(--muted); }
.mail-dir.out { color: var(--accent); }
.chip .ic, .button .ic { flex: none; }
.chip .ic { margin-right: 4px; vertical-align: -2px; }

/* A2.2 payment decision (payments app). The text always names the state; the colour only helps (spec 3.1). */
.payment-state { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s3) var(--s4); background: var(--bg); margin-bottom: var(--s3); }
.payment-state p { margin: 0 0 4px; }
.payment-state.payment-to_customer { background: var(--danger-bg); border-color: var(--danger-line); }
.payment-state.payment-from_customer { background: var(--success-bg); border-color: var(--success-line); }
.payment-label { font-size: var(--text-3); font-weight: 700; color: var(--muted); }
.payment-summary { font-size: 17px; }
.payment-pending p { margin: 0 0 4px; }
.notice-body { font-size: var(--text-2); overflow-wrap: anywhere; margin: var(--s2) 0; }
.nav-count { margin-left: auto; min-width: 22px; padding: 0 6px; border-radius: 999px; background: #f59e0b; color: #17243d; font-size: 12px; font-weight: 700; text-align: center; line-height: 20px; }
.approval-actions .inline-actions { margin: var(--s2) 0; }
.approval-actions details.inline-form { margin-top: var(--s2); }
.approval-actions details.inline-form form { margin-top: var(--s2); max-width: 520px; }
/* REQ-23: actions next to a file in the „Файлове“ card. */
.record-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s1) var(--s2); }
.record-actions details.inline-form[open] { flex-basis: 100%; }
.record-actions details.inline-form form { display: grid; gap: var(--s1); margin-top: var(--s1); max-width: 420px; }
#files > details.inline-form { margin-bottom: var(--s3); }
#files input[type=file] { max-width: 100%; }

.nav-password { display: block; font-size: 13px; color: var(--muted, inherit); margin: 4px 0; }
