/* =====================================================================
   Devops MediCore — "Floor Lines" design system
   Every patient and every charge travels a coloured line through the
   hospital; the interface draws that line. Line colours mean WHERE
   (department), never status. Status has its own set, always with an
   icon and a word.
   ===================================================================== */

:root {
  /* ground & ink */
  --floor: #F4F6F7;
  --floor-2: #E9EEF0;
  --surface: #FFFFFF;
  --surface-2: #FAFBFC;
  --ink: #14212B;
  --ink-2: #3A4A55;
  --ink-3: #56666F;
  --hair: #D5DCE0;
  --hair-2: #B9C3C9;
  --select: #CFE0F7;

  /* department lines (wayfinding only) */
  --line-frontdesk: #2E5BBA;
  --line-clinical: #1F7A5A;
  --line-inpatient: #7A4CC2;
  --line-pharmacy: #C76E1C;
  --line-diagnostics: #C2185B;
  --line-finance: #0F5E6E;
  --line-supply: #94661A;
  --line-admin: #4A5864;
  --line: var(--line-clinical);           /* overridden per page/section */

  /* status semantics (never used as rails) */
  --ok: #067647;     --ok-bg: #DCFAE6;
  --warn: #93370D;   --warn-bg: #FEF0C7;
  --crit: #B42318;   --crit-bg: #FEE4E2;
  --info: #175CD3;   --info-bg: #D1E9FF;
  --muted-bg: #EEF2F4;

  --focus: #1849A9;
  --ai: #14212B;     --ai-bg: #EEF2F4;

  /* type */
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --fs-xs: 0.75rem; --fs-sm: 0.8125rem; --fs: 0.9375rem; --fs-md: 1.0625rem; --fs-lg: 1.375rem; --fs-xl: 1.75rem;

  /* geometry */
  --r: 4px; --r-lg: 6px;
  --rail-w: 252px; --top-h: 56px;
  --pad: 20px;
  --shadow-pop: 0 8px 24px -6px rgba(20, 33, 43, .18), 0 2px 6px -2px rgba(20, 33, 43, .12);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --floor: #0E1519; --floor-2: #121B20; --surface: #152027; --surface-2: #19252D;
    --ink: #E6EDF0; --ink-2: #B8C5CC; --ink-3: #93A3AC; --hair: #26343C; --hair-2: #37464F; --select: #1E3A5F;
    --line-frontdesk: #7FA2EC; --line-clinical: #4FC398; --line-inpatient: #B597EE; --line-pharmacy: #F0A45C;
    --line-diagnostics: #F07AAA; --line-finance: #5FC3D6; --line-supply: #D9AE5E; --line-admin: #9AAAB6;
    --ok: #75E0A7; --ok-bg: #0B3B26; --warn: #FEC84B; --warn-bg: #3F2A08; --crit: #FDA29B; --crit-bg: #4A1410;
    --info: #84CAFF; --info-bg: #0B2B52; --muted-bg: #1C2930; --focus: #84CAFF; --ai: #E6EDF0; --ai-bg: #1C2930;
    --shadow-pop: 0 10px 30px -6px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --floor: #0E1519; --floor-2: #121B20; --surface: #152027; --surface-2: #19252D;
  --ink: #E6EDF0; --ink-2: #B8C5CC; --ink-3: #93A3AC; --hair: #26343C; --hair-2: #37464F; --select: #1E3A5F;
  --line-frontdesk: #7FA2EC; --line-clinical: #4FC398; --line-inpatient: #B597EE; --line-pharmacy: #F0A45C;
  --line-diagnostics: #F07AAA; --line-finance: #5FC3D6; --line-supply: #D9AE5E; --line-admin: #9AAAB6;
  --ok: #75E0A7; --ok-bg: #0B3B26; --warn: #FEC84B; --warn-bg: #3F2A08; --crit: #FDA29B; --crit-bg: #4A1410;
  --info: #84CAFF; --info-bg: #0B2B52; --muted-bg: #1C2930; --focus: #84CAFF; --ai: #E6EDF0; --ai-bg: #1C2930;
  --shadow-pop: 0 10px 30px -6px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

[data-line="frontdesk"]   { --line: var(--line-frontdesk); }
[data-line="clinical"]    { --line: var(--line-clinical); }
[data-line="inpatient"]   { --line: var(--line-inpatient); }
[data-line="pharmacy"]    { --line: var(--line-pharmacy); }
[data-line="diagnostics"] { --line: var(--line-diagnostics); }
[data-line="finance"]     { --line: var(--line-finance); }
[data-line="supply"]      { --line: var(--line-supply); }
[data-line="admin"]       { --line: var(--line-admin); }

/* ---------- base & browser surfaces ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--floor); color: var(--ink);
  font: 400 var(--fs)/1.5 var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
::selection { background: var(--select); color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
a { color: inherit; text-decoration-color: var(--hair-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 700; text-wrap: balance; }
h1 { font-size: var(--fs-lg); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-md); }
h3 { font-size: var(--fs); }
p { margin: 0 0 .75em; max-width: 72ch; }
hr { border: 0; border-top: 1px solid var(--hair); margin: 16px 0; }
input, select, textarea, button { font: inherit; color: inherit; caret-color: var(--focus); }
* { scrollbar-width: thin; scrollbar-color: var(--hair-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--hair-2); border-radius: 10px; border: 3px solid var(--floor); }
::-webkit-scrollbar-track { background: transparent; }
.mono, .id { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.right { text-align: end; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 18px; height: 18px; stroke-width: 1.75; flex: none; vertical-align: -3px; }
.icon-sm { width: 15px; height: 15px; }
[hidden] { display: none !important; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) 1fr; grid-template-rows: var(--top-h) 1fr; min-height: 100dvh; }
.shell.rail-collapsed { --rail-w: 68px; }

.topbar {
  grid-column: 1 / -1; position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--hair);
}
.brand { display: flex; align-items: center; gap: 10px; width: calc(var(--rail-w) - 16px); min-width: 0; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-name { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand-name b { font-size: 15px; letter-spacing: -0.01em; }
.brand-name span { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-collapsed .brand-name { display: none; }

.search {
  flex: 1; max-width: 640px; position: relative; display: flex; align-items: center;
  background: var(--floor); border: 1px solid var(--hair); border-radius: var(--r); height: 38px; padding: 0 10px; gap: 8px;
}
.search:focus-within { border-color: var(--focus); background: var(--surface); }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; height: 100%; }
.search kbd { font: 500 11px var(--mono); color: var(--ink-3); border: 1px solid var(--hair); border-radius: 3px; padding: 1px 5px; }
.search-results {
  position: absolute; inset-inline: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--hair);
  border-radius: var(--r-lg); box-shadow: var(--shadow-pop); max-height: 70vh; overflow: auto; z-index: 60;
}
.search-results a { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 12px; padding: 10px 14px; text-decoration: none; border-bottom: 1px solid var(--hair); }
.search-results a:last-child { border-bottom: 0; }
.search-results a[aria-selected="true"], .search-results a:hover { background: var(--floor); }
.search-results .id { font-size: var(--fs-sm); font-weight: 700; }

.top-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 4px; }
.top-btn {
  position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r);
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--ink-2);
}
.top-btn:hover { background: var(--floor); color: var(--ink); }
.top-btn .dot { position: absolute; top: 7px; inset-inline-end: 7px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--crit); color: #fff; font: 700 10px/16px var(--font); }
.top-btn.ai { color: var(--ai); }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: var(--r); background: none; border: 1px solid transparent; cursor: pointer; }
.user-chip:hover { background: var(--floor); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--floor-2); color: var(--ink-2); font: 700 12px var(--font); }
.user-chip .who { display: flex; flex-direction: column; line-height: 1.1; text-align: start; }
.user-chip .who small { color: var(--ink-3); font-size: 11px; }

/* ---------- the line rail (navigation as floor lines) ---------- */
.rail {
  grid-row: 2; position: sticky; top: var(--top-h); height: calc(100dvh - var(--top-h)); overflow-y: auto; overflow-x: hidden;
  background: var(--floor-2); border-inline-end: 1px solid var(--hair); padding: 12px 0 24px;
}
.line-group { position: relative; padding: 6px 0 10px; }
.line-group > .line-title {
  display: flex; align-items: center; gap: 10px; padding-block: 6px; padding-inline: 18px 16px;
  font-size: var(--fs-xs); font-weight: 700; color: var(--ink-2); letter-spacing: .02em;
}
.line-group > .line-title .swatch { width: 14px; height: 4px; border-radius: 2px; background: var(--line); flex: none; }
/* the line itself: one continuous 4px rail through every station of the group */
.line-group ul { list-style: none; margin: 0; padding: 0; position: relative; }
.line-group ul::before {
  content: ""; position: absolute; inset-inline-start: 22px; top: 14px; bottom: 14px; width: 4px; border-radius: 2px; background: var(--line);
}
.station {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 34px; padding-block: 4px; padding-inline: 40px 12px;
  text-decoration: none; color: var(--ink-2); font-size: var(--fs-sm);
}
.station::before { /* station node */
  content: ""; position: absolute; inset-inline-start: 17px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%;
  background: var(--floor-2); border: 3px solid var(--line); transition: transform .25s var(--ease-out), background .2s;
}
.station:hover { color: var(--ink); background: color-mix(in srgb, var(--line) 7%, transparent); }
.station:hover::before { transform: scale(1.12); }
.station[aria-current="page"] { color: var(--ink); font-weight: 700; background: color-mix(in srgb, var(--line) 11%, transparent); }
.station[aria-current="page"]::before { background: var(--line); }
.station .count { margin-inline-start: auto; font: 700 11px var(--mono); color: var(--ink-3); }
.station .icon { display: none; }
.rail-collapsed .line-title span, .rail-collapsed .station span, .rail-collapsed .station .count { display: none; }
.rail-collapsed .station { padding-inline-start: 0; justify-content: center; min-height: 40px; }
.rail-collapsed .station::before { display: none; }
.rail-collapsed .station .icon { display: block; color: var(--line); }
.rail-collapsed .line-group ul::before { inset-inline-start: 0; }
.rail-foot { margin: 12px 16px 0; padding-top: 12px; border-top: 1px solid var(--hair); display: flex; gap: 6px; }

/* ---------- content ---------- */
.main { grid-row: 2; min-width: 0; padding: 0 0 48px; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; padding: 20px var(--pad) 16px;
  border-bottom: 1px solid var(--hair); background: var(--surface); position: relative;
}
.page-head::after { /* the active line runs under every page header */
  content: ""; position: absolute; inset-inline: 0; bottom: -1px; height: 3px; background: var(--line);
}
.page-head .crumbs { width: 100%; font-size: var(--fs-xs); color: var(--ink-3); display: flex; gap: 6px; align-items: center; }
.page-head .crumbs a { text-decoration: none; }
.page-head .title-block { flex: 1; min-width: 240px; }
.page-head .title-block p { margin: 4px 0 0; color: var(--ink-3); font-size: var(--fs-sm); }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.content { padding: 20px var(--pad); display: grid; gap: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.stack { display: grid; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; min-width: 0; }
.panel, .content > *, .split > *, .grid-2 > *, .grid-3 > * { min-width: 0; }
.spacer { flex: 1; }

/* panels: hairline-bounded surfaces, never nested */
.panel { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-lg); min-width: 0; }
.panel > header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--hair); }
.panel > header h2, .panel > header h3 { font-size: var(--fs); }
.panel > header .spacer { flex: 1; }
.panel > .body { padding: 16px; }
.panel > .body.flush { padding: 0; }
.panel > footer { padding: 10px 16px; border-top: 1px solid var(--hair); display: flex; gap: 8px; align-items: center; }
.section-title { display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); margin: 4px 0 8px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--hair); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: var(--r); border: 1px solid var(--hair-2); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: var(--fs-sm); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--floor); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--line)); border-color: transparent; }
.btn-line { --btn-line: color-mix(in srgb, var(--line) 78%, #000); background: var(--btn-line); border-color: var(--btn-line); color: #fff; }
:root[data-theme="dark"] .btn-line { --btn-line: var(--line); color: #0E1519; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-line { --btn-line: var(--line); color: #0E1519; } }
.btn-line:hover { background: color-mix(in srgb, var(--btn-line) 88%, #000); }
.btn-danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 45%, var(--hair)); }
.btn-danger:hover { background: var(--crit-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--floor); border-color: transparent; }
.btn-ai { color: var(--ai); border-color: color-mix(in srgb, var(--ai) 40%, var(--hair)); background: var(--surface); }
.btn-ai:hover { background: var(--ai-bg); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-xs); }
.btn-lg { height: 46px; padding: 0 20px; font-size: var(--fs); }
.btn-icon { width: 36px; padding: 0; }
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink-3); border-top-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- forms ---------- */
.field { display: grid; gap: 5px; min-width: 0; }
.field > label, .label { font-size: var(--fs-xs); font-weight: 700; color: var(--ink-2); }
.field .hint { font-size: var(--fs-xs); color: var(--ink-3); }
.field .error, .field-validation-error { font-size: var(--fs-xs); color: var(--crit); }
.input, .field input:not([type=checkbox]):not([type=radio]):not([type=file]), .field select, .field textarea, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--hair-2); border-radius: var(--r); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.field textarea, textarea.input { height: auto; min-height: 88px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 0; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
.input::placeholder, .field input::placeholder, .field textarea::placeholder { color: var(--ink-3); opacity: .8; }
.input-validation-error { border-color: var(--crit) !important; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-sm); }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
fieldset { border: 0; padding: 0; margin: 0; }
.validation-summary-errors { color: var(--crit); background: var(--crit-bg); border-radius: var(--r); padding: 10px 14px; font-size: var(--fs-sm); }
.validation-summary-errors ul { margin: 0; padding-inline-start: 18px; }
.validation-summary-valid { display: none; }

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--hair-2); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg a, .seg button, .seg label { padding: 0 12px; height: 32px; display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; font-size: var(--fs-sm); text-decoration: none; cursor: pointer; border-inline-end: 1px solid var(--hair); }
.seg > :last-child { border-inline-end: 0; }
.seg [aria-current="true"], .seg .active, .seg input:checked + span { background: var(--ink); color: var(--surface); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data th {
  text-align: start; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-2); padding: 9px 12px;
  border-bottom: 1px solid var(--ink); position: sticky; top: 0; background: var(--surface); white-space: nowrap;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--hair); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.is-selected { background: var(--select); }
table.data td.num, table.data th.num { text-align: end; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; border-top: 1px solid var(--ink); border-bottom: 0; }
table.data a.rowlink { text-decoration: none; font-weight: 600; }
table.data a.rowlink:hover { text-decoration: underline; }
table.data .actions { text-align: end; white-space: nowrap; }

/* ---------- chips: status (icon + word) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap; background: var(--muted-bg); color: var(--ink-2);
}
.chip .icon { width: 13px; height: 13px; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.crit { background: var(--crit-bg); color: var(--crit); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.ai { background: var(--ai-bg); color: var(--ai); }
.chip.outline { background: transparent; border: 1px solid var(--hair-2); }
.tag-line { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-2); }
.tag-line::before { content: ""; width: 12px; height: 4px; border-radius: 2px; background: var(--line); }

/* flags (allergy / VIP / restricted) */
.flag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: var(--r); font-size: var(--fs-xs); font-weight: 700; }
.flag.allergy { background: var(--crit); color: #fff; }
.flag.nka { background: var(--muted-bg); color: var(--ink-2); }
.flag.vip { background: var(--ink); color: var(--surface); }

/* ---------- alerts ---------- */
.alert { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 14px; border-radius: var(--r-lg); font-size: var(--fs-sm); border: 1px solid transparent; align-items: flex-start; }
.alert .icon { margin-top: 1px; }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.crit { background: var(--crit-bg); color: var(--crit); border-color: color-mix(in srgb, var(--crit) 35%, transparent); }
.alert b { color: inherit; }
.alert .grow { flex: 1 1 200px; min-width: 0; }

/* ---------- patient banner: identifier as headline ---------- */
.patient-banner { background: var(--surface); border-bottom: 1px solid var(--hair); padding: 16px var(--pad) 0; position: relative; }
.pb-top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-start; }
.pb-photo { width: 56px; height: 56px; border-radius: var(--r-lg); background: var(--floor-2); display: grid; place-items: center; overflow: hidden; flex: none; font-weight: 700; color: var(--ink-3); }
.pb-photo img { width: 100%; height: 100%; object-fit: cover; }
.pb-id .mrn { font: 700 26px/1 var(--mono); letter-spacing: -0.01em; }
.pb-id .name { font-size: var(--fs-md); font-weight: 700; margin-top: 4px; }
.pb-id .meta { color: var(--ink-3); font-size: var(--fs-sm); margin-top: 2px; }
.pb-facts { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: var(--fs-sm); }
.pb-facts dt { font-size: var(--fs-xs); color: var(--ink-3); }
.pb-facts dd { margin: 0; font-weight: 600; }
.pb-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-inline-start: auto; }
.pb-tabs { display: flex; gap: 2px; margin-top: 14px; overflow-x: auto; }
.pb-tabs a { padding: 10px 14px; text-decoration: none; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-3); border-bottom: 3px solid transparent; white-space: nowrap; }
.pb-tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--line); }
.pb-tabs a:hover { color: var(--ink); }

/* ---------- journey rail (signature component) ---------- */
.journey { --n: 9; position: relative; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); padding: 18px 0 6px; }
.journey::before { content: ""; position: absolute; top: 27px; inset-inline: calc(50% / var(--n)); height: 4px; border-radius: 2px; background: var(--hair); }
.journey .progress { position: absolute; top: 27px; inset-inline-start: calc(50% / var(--n)); height: 4px; border-radius: 2px; background: var(--line); width: var(--done, 0%); }
.journey .stop { position: relative; display: grid; justify-items: center; gap: 6px; text-decoration: none; text-align: center; padding: 0 2px; }
.journey .stop i {
  width: 22px; height: 22px; border-radius: 50%; background: var(--surface); border: 4px solid var(--hair-2); position: relative; z-index: 1;
  transition: transform .3s var(--ease-out), background .3s, border-color .3s;
}
.journey .stop span { font-size: 11.5px; font-weight: 600; color: var(--ink-3); line-height: 1.2; }
.journey .stop.done i { background: var(--stop-line, var(--line)); border-color: var(--stop-line, var(--line)); }
.journey .stop.done span { color: var(--ink-2); }
.journey .stop.now i { border-color: var(--stop-line, var(--line)); transform: scale(1.25); background: var(--surface); }
.journey .stop.now i::after { content: ""; position: absolute; inset: -9px; border-radius: 50%; border: 2px solid var(--stop-line, var(--line)); opacity: 0; animation: arrive 2.4s var(--ease-out) infinite; }
.journey .stop.now span { color: var(--ink); font-weight: 700; }
.journey .stop .n { font: 700 var(--fs-lg)/1 var(--mono); color: var(--ink); }
@keyframes arrive { 0% { transform: scale(.6); opacity: .9; } 70%, 100% { transform: scale(1.35); opacity: 0; } }

/* journey strip on dashboards: live counts that flip in place */
.journey.board .stop { padding-top: 0; gap: 4px; }
.journey.board::before, .journey.board .progress { top: 36px; }
.journey.board .stop i { margin-top: 3px; border-color: var(--stop-line, var(--line)); }
.journey .stop.here span { text-decoration: underline 2px var(--stop-line, var(--line)); text-underline-offset: 4px; color: var(--ink); }
.flip { display: inline-block; animation: flip .5s var(--ease-out); }
@keyframes flip { 0% { transform: translateY(-40%); opacity: 0; filter: blur(2px); } 100% { transform: none; opacity: 1; filter: none; } }

/* ---------- stat line (not hero metrics): compact, ruled ---------- */
.ledger-line { display: flex; flex-wrap: wrap; margin: 0; border-block: 1px solid var(--hair); background: transparent; }
.ledger-line > div { flex: 1 1 140px; padding: 8px 14px; border-inline-end: 1px solid var(--hair); }
.ledger-line > div:last-child { border-inline-end: 0; }
.ledger-line dt { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 600; }
.ledger-line dd { margin: 2px 0 0; font: 700 var(--fs-md) var(--mono); }
.ledger-line dd small { font: 600 11px var(--font); color: var(--ink-3); margin-inline-start: 4px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--hair); overflow-x: auto; }
.tabs a, .tabs button { padding: 10px 14px; border: 0; background: none; text-decoration: none; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-3); border-bottom: 3px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; }
.tabs [aria-selected="true"], .tabs [aria-current="page"] { color: var(--ink); border-bottom-color: var(--line); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 10px 16px; border-bottom: 1px solid var(--hair); display: flex; gap: 12px; align-items: center; }
.list > li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: var(--fs-sm); margin: 0; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; inset-inline-start: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--hair); }
.timeline li { position: relative; padding: 0 0 16px 28px; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: 2px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--line); }

/* ---------- empty states ---------- */
.empty { display: grid; justify-items: center; text-align: center; gap: 8px; padding: 40px 20px; color: var(--ink-3); min-width: 0; }
.empty svg.illus { width: 120px; height: 48px; }
.empty h3 { color: var(--ink); font-size: var(--fs); }
.empty p { margin: 0 auto; max-width: min(46ch, 100%); font-size: var(--fs-sm); }

/* ---------- AI: drafts, summaries, the dock ---------- */
.ai-draft { border: 1px dashed color-mix(in srgb, var(--ai) 55%, var(--hair)); border-radius: var(--r-lg); background: color-mix(in srgb, var(--ai-bg) 55%, var(--surface)); }
.ai-draft > header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: var(--ai); font-size: var(--fs-xs); font-weight: 700; border-bottom: 1px dashed color-mix(in srgb, var(--ai) 35%, var(--hair)); }
.ai-draft > .body { padding: 12px 14px; font-size: var(--fs-sm); }
.ai-draft > .body ul { margin: 0; padding-inline-start: 18px; }
.ai-summary { font-size: var(--fs-sm); }
.ai-summary ul { margin: 6px 0 0; padding-inline-start: 18px; }
.ai-thinking { display: inline-flex; gap: 4px; align-items: center; color: var(--ai); font-size: var(--fs-xs); font-weight: 700; }
.ai-thinking i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: think 1.2s infinite ease-in-out; }
.ai-thinking i:nth-child(2) { animation-delay: .15s; } .ai-thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes think { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.dock {
  position: fixed; top: var(--top-h); inset-inline-end: 0; bottom: 0; width: min(440px, 100vw); z-index: 50;
  background: var(--surface); border-inline-start: 1px solid var(--hair); box-shadow: var(--shadow-pop);
  display: grid; grid-template-rows: auto auto 1fr auto; transform: translateX(105%); transition: transform .35s var(--ease-out);
}
[dir="rtl"] .dock { transform: translateX(-105%); }
.dock.open { transform: none; }
.dock-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--hair); }
.dock-head h2 { font-size: var(--fs); display: flex; align-items: center; gap: 8px; color: var(--ai); }
.dock-scope { padding: 8px 14px; border-bottom: 1px solid var(--hair); display: flex; gap: 8px; align-items: center; font-size: var(--fs-xs); }
.dock-scope select { height: 30px; font-size: var(--fs-xs); }
.dock-log { overflow-y: auto; padding: 14px; display: grid; gap: 14px; align-content: start; }
.msg { font-size: var(--fs-sm); line-height: 1.55; }
.msg.user { justify-self: end; max-width: 85%; background: var(--floor); border-radius: 10px 10px 2px 10px; padding: 8px 12px; }
.msg.assistant { max-width: 100%; }
.msg.assistant p { margin: 0 0 .6em; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 .6em; padding-inline-start: 18px; }
.msg .cite { display: inline-flex; align-items: center; font: 700 10.5px var(--mono); padding: 0 5px; border-radius: 3px; background: var(--ai-bg); color: var(--ai); text-decoration: none; vertical-align: 1px; }
.msg .sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dock-input { border-top: 1px solid var(--hair); padding: 10px; display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: end; }
.dock-input textarea { resize: none; min-height: 40px; max-height: 160px; border: 1px solid var(--hair-2); border-radius: var(--r); padding: 9px 10px; background: var(--surface); }
.dock-input textarea:focus { outline: 0; border-color: var(--ai); }
.dock-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.dock-suggest button { border: 1px solid var(--hair); background: var(--surface); border-radius: 14px; padding: 4px 10px; font-size: var(--fs-xs); cursor: pointer; color: var(--ink-2); }
.dock-suggest button:hover { border-color: var(--ai); color: var(--ai); }

/* ---------- voice dictation ---------- */
.dictation { display: grid; gap: 10px; }
.dict-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mic-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px 0 12px; border-radius: 20px; border: 1px solid var(--hair-2); background: var(--surface); font-weight: 700; font-size: var(--fs-sm); cursor: pointer; }
.mic-btn:hover { border-color: var(--crit); }
.mic-btn .rec { width: 12px; height: 12px; border-radius: 50%; background: var(--crit); }
.dictation.recording .mic-btn { background: var(--crit); color: #fff; border-color: var(--crit); }
.dictation.recording .mic-btn .rec { background: #fff; animation: pulse 1s infinite; border-radius: 2px; }
@keyframes pulse { 50% { opacity: .35; } }
.dict-wave { height: 32px; flex: 1; min-width: 120px; }
.dict-timer { font: 700 var(--fs-sm) var(--mono); min-width: 48px; }
.dict-live { font-size: var(--fs-sm); color: var(--ink-2); min-height: 1.5em; font-style: italic; }
.dict-transcript { width: 100%; min-height: 110px; }
.filled-by-ai { animation: aifill 1.6s var(--ease-out); }
@keyframes aifill { 0% { background: var(--ai-bg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai) 30%, transparent); } 100% { background: var(--surface); box-shadow: none; } }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 80; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--surface); border-radius: var(--r-lg); padding: 12px 14px; box-shadow: var(--shadow-pop); display: grid; grid-template-columns: auto 1fr auto; gap: 10px; font-size: var(--fs-sm); animation: toast-in .35s var(--ease-out); }
.toast.crit { background: var(--crit); color: #fff; }
.toast b { display: block; }
.toast a { color: inherit; }
.toast button { background: none; border: 0; color: inherit; cursor: pointer; opacity: .7; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* ---------- menus, dialogs, drawers ---------- */
.menu { position: relative; }
.menu-pop { position: absolute; top: calc(100% + 6px); inset-inline-end: 0; min-width: 220px; background: var(--surface); border: 1px solid var(--hair); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: 6px; z-index: 70; display: grid; }
.menu-pop a, .menu-pop button { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r); text-decoration: none; font-size: var(--fs-sm); background: none; border: 0; text-align: start; cursor: pointer; width: 100%; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--floor); }
.menu-pop hr { margin: 6px 0; }
dialog.modal { border: 0; padding: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); width: min(560px, calc(100vw - 32px)); max-height: 88dvh; }
dialog.modal::backdrop { background: rgba(14, 21, 25, .45); }
dialog.modal > header { padding: 14px 16px; border-bottom: 1px solid var(--hair); display: flex; align-items: center; gap: 10px; }
dialog.modal > .body { padding: 16px; overflow: auto; }
dialog.modal > footer { padding: 12px 16px; border-top: 1px solid var(--hair); display: flex; justify-content: flex-end; gap: 8px; }
dialog.modal.wide { width: min(900px, calc(100vw - 32px)); }

/* ---------- boards (bed board, queue) ---------- */
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.bed {
  position: relative; display: grid; gap: 2px; padding: 10px 10px 10px 14px; border-radius: var(--r); background: var(--surface);
  border: 1px solid var(--hair); text-decoration: none; min-height: 84px; transition: border-color .2s;
}
.bed:hover { border-color: var(--ink-3); }
.bed .code { font: 700 var(--fs-sm) var(--mono); }
.bed .who { font-size: var(--fs-xs); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bed .sub { font-size: 11px; color: var(--ink-3); }
.bed .state { position: absolute; top: 8px; inset-inline-end: 8px; }
.bed.available { background: var(--surface-2); border-style: dashed; }
.bed.cleaning { background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 6px, var(--floor-2) 6px, var(--floor-2) 12px); }
.bed.blocked { opacity: .6; }

/* queue display (waiting area screens) */
.display-board { min-height: 100dvh; background: #0E1519; color: #E6EDF0; padding: 32px; display: grid; grid-template-rows: auto 1fr auto; gap: 24px; }
.display-board .now { font: 700 clamp(64px, 12vw, 180px)/1 var(--mono); letter-spacing: -0.02em; }

/* ---------- kiosk (large touch, NFR-12) ---------- */
.kiosk { --fs: 1.25rem; font-size: 1.25rem; }
.kiosk .btn { height: 64px; font-size: 1.25rem; padding: 0 28px; }
.kiosk .field input, .kiosk .field select { height: 56px; font-size: 1.2rem; }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 480px); background: var(--surface); }
.auth-art { position: relative; overflow: hidden; background: var(--floor-2); }
.auth-art svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.auth-art .caption { position: absolute; inset-inline-start: 48px; bottom: 48px; max-width: 460px; background: var(--floor-2); padding: 20px 24px 8px; border-radius: var(--r-lg); }
.auth-art .caption h1 { font-size: var(--fs-xl); letter-spacing: -0.02em; margin-bottom: 8px; }
.auth-form { display: grid; align-content: center; gap: 18px; padding: 48px; }
.auth-form .brand { width: auto; }

/* ---------- mobile bottom bar ---------- */
.tabbar { display: none; }
.install-banner { display: none; }
.has-install .main { padding-bottom: calc(190px + env(safe-area-inset-bottom)); }

/* ---------- utilities ---------- */
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mb-0 { margin-bottom: 0; }
.w-full { width: 100%; }
.text-crit { color: var(--crit); } .text-ok { color: var(--ok); } .text-warn { color: var(--warn); } .text-ai { color: var(--ai); }
.offline-banner { position: fixed; top: var(--top-h); inset-inline: 0; z-index: 45; background: var(--warn-bg); color: var(--warn); text-align: center; font-size: var(--fs-sm); font-weight: 700; padding: 6px; border-bottom: 1px solid var(--hair); }
.skeleton { background: linear-gradient(90deg, var(--floor-2), var(--floor), var(--floor-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--r); min-height: 1em; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  :root { --pad: 16px; }
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; inset-block: var(--top-h) 0; inset-inline-start: 0; width: 280px; z-index: 55; transform: translateX(-102%); transition: transform .3s var(--ease-out); box-shadow: var(--shadow-pop); }
  [dir="rtl"] .rail { transform: translateX(102%); }
  .shell.rail-open .rail { transform: none; }
  .main { grid-column: 1; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .brand { width: auto; }
  .brand-name, .user-chip .who, .search kbd, .top-btn.hide-sm { display: none; }
  .topbar { gap: 4px; padding: 0 8px; min-width: 0; }
  .search { max-width: none; min-width: 0; flex: 1 1 0; }
  .top-btn { width: 34px; }
  .user-chip { padding: 2px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .page-head { padding-top: 14px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset-inline: 0; bottom: 0; z-index: 45;
    background: var(--surface); border-top: 1px solid var(--hair); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a, .tabbar button { display: grid; justify-items: center; gap: 2px; padding: 8px 0 6px; text-decoration: none; font-size: 11px; font-weight: 600; color: var(--ink-3); background: none; border: 0; }
  .tabbar [aria-current="page"] { color: var(--ink); }
  .tabbar [aria-current="page"] .icon { color: var(--line); }
  .tabbar .scan { margin-top: -18px; }
  .tabbar .scan span.ring { width: 52px; height: 52px; border-radius: 50%; background: var(--ink); color: var(--surface); display: grid; place-items: center; box-shadow: var(--shadow-pop); }
  /* tables become stacked rows */
  table.data.stack-sm thead { display: none; }
  table.data.stack-sm tr { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 10px 12px; border-bottom: 1px solid var(--hair); }
  table.data.stack-sm td { border: 0; padding: 2px 0; }
  table.data.stack-sm td::before { content: attr(data-label); display: block; font-size: 10.5px; color: var(--ink-3); font-weight: 700; }
  table.data.stack-sm td.actions { grid-column: 1 / -1; text-align: start; }
  .dock { top: 0; width: 100vw; z-index: 90; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .auth-form { padding: 28px 20px; }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); inset-inline-end: 16px; }
  .journey.compact-sm { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
  .journey.compact-sm .stop:not(.now):not(.prev):not(.next):not(.here) { display: none; }
  .journey.compact-sm .progress { display: none; }
  .journey.compact-sm::before { inset-inline: 12%; }
  .journey.board { grid-template-columns: 1fr; padding: 8px 16px; }
  .journey.board::before { top: 18px; bottom: 18px; inset-inline-start: 26px; inset-inline-end: auto; width: 4px; height: auto; }
  .journey.board .stop { grid-template-columns: 22px 1fr auto; justify-items: start; align-items: center; text-align: start; gap: 12px; padding: 6px 0; }
  .journey.board .stop i { order: 1; margin: 0; } .journey.board .stop span:not(.n) { order: 2; font-size: var(--fs-sm); } .journey.board .stop .n { order: 3; font-size: var(--fs-md); }
  .install-banner:not([hidden]) { display: flex; position: fixed; inset-inline: 12px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 46; background: var(--ink); color: var(--surface); padding: 12px 14px; border-radius: var(--r-lg); gap: 10px; align-items: center; box-shadow: var(--shadow-pop); }
}
@media (display-mode: standalone) {
  .topbar { padding-top: env(safe-area-inset-top); height: calc(var(--top-h) + env(safe-area-inset-top)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- print (documents, wristbands, labels, downtime packs) ---------- */
@media print {
  .topbar, .rail, .tabbar, .dock, .toasts, .page-actions, .no-print, .pb-tabs { display: none !important; }
  .shell { display: block; }
  body { background: #fff; color: #000; }
  .panel { border-color: #999; break-inside: avoid; }
  .page-head::after { background: #000; }
}
