: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; }
.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; }
