/* ==========================================================================
   AICC Pathology console, v19 design system
   Brand tokens from aicchealth.com: warm cream paper, pine (#1a3a30), brass (#b8893d),
   Fraunces display, Inter Tight text, JetBrains Mono labels. Fonts and icons are served
   from wwwroot/lib, so the app looks the same on a server with no internet access.
   ========================================================================== */

@font-face { font-family: "Inter Tight"; font-weight: 400; font-style: normal; font-display: swap; src: url("../lib/fonts/inter-tight-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter Tight"; font-weight: 500; font-style: normal; font-display: swap; src: url("../lib/fonts/inter-tight-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter Tight"; font-weight: 600; font-style: normal; font-display: swap; src: url("../lib/fonts/inter-tight-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter Tight"; font-weight: 700; font-style: normal; font-display: swap; src: url("../lib/fonts/inter-tight-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Fraunces"; font-weight: 100 900; font-style: normal; font-display: swap; src: url("../lib/fonts/fraunces-latin-opsz-normal.woff2") format("woff2"); }
@font-face { font-family: "Fraunces"; font-weight: 100 900; font-style: italic; font-display: swap; src: url("../lib/fonts/fraunces-latin-opsz-italic.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-style: normal; font-display: swap; src: url("../lib/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 500; font-style: normal; font-display: swap; src: url("../lib/fonts/jetbrains-mono-latin-500-normal.woff2") format("woff2"); }

/* ---------- Tokens ---------- */
:root {
    color-scheme: light;
    --font: "Inter Tight", "Segoe UI", system-ui, -apple-system, sans-serif;
    --display: "Fraunces", Georgia, "Times New Roman", serif;
    --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

    --bg: #f5f2ec;
    --surface: #fffefb;
    --surface-2: #faf7f1;
    --surface-3: #ede8de;
    --border: #e4ded1;
    --border-strong: #d4cdbe;
    --text: #0f1f1a;
    --text-2: #2a3a34;
    --muted: #6b7771;
    --accent: #1a3a30;
    --accent-strong: #0a1f1a;
    --accent-soft: #e3ebe6;
    --accent-text: #f5f2ec;
    --link: #2d5849;
    --brass: #b8893d;
    --brass-deep: #8c6428;
    --brass-soft: #f4ead6;
    --focus: #b8893d;
    --badge-bg: #8c6428;
    --badge-text: #ffffff;

    --sidebar: #faf7f1;
    --sidebar-2: #ede8de;
    --sidebar-text: #2a3a34;
    --sidebar-muted: #6b7771;
    --sidebar-active: #1a3a30;
    --sidebar-active-text: #f5f2ec;
    --sidebar-border: #e4ded1;

    --ok: #2d5849;       --ok-bg: #e1ebe5;
    --warn: #8c6428;     --warn-bg: #f4ead6;
    --bad: #b8433a;      --bad-bg: #f8e4e1;
    --info: #3f6f82;     --info-bg: #e3edf1;

    --st-queued: #6b7771;     --st-queued-bg: #ece8df;
    --st-processing: #3f6f82; --st-processing-bg: #e3edf1;
    --st-review: #8c6428;     --st-review-bg: #f4ead6;
    --st-approved: #2d5849;   --st-approved-bg: #e1ebe5;
    --st-delivered: #1a3a30;  --st-delivered-bg: #d6e3db;
    --st-failed: #b8433a;     --st-failed-bg: #f8e4e1;
    --st-hold: #a55a27;       --st-hold-bg: #f6e5d6;
    --st-test: #675a84;       --st-test-bg: #ebe7f1;

    --shadow-sm: 0 1px 2px rgba(15, 31, 26, .05);
    --shadow: 0 1px 2px rgba(15, 31, 26, .05), 0 6px 18px rgba(15, 31, 26, .06);
    --shadow-lg: 0 20px 60px rgba(15, 31, 26, .18), 0 4px 12px rgba(15, 31, 26, .06);
    --radius: 4px;
    --radius-sm: 2px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #09160f; --surface: #0e1f19; --surface-2: #122620; --surface-3: #183029;
        --border: #213a31; --border-strong: #2d4b40;
        --text: #eee9df; --text-2: #c7ccc3; --muted: #8e9c95;
        --accent: #d4a85c; --accent-strong: #e2bd77; --accent-soft: #2a2416; --accent-text: #0a1f1a; --link: #d4a85c;
        --brass: #d4a85c; --brass-deep: #e2bd77; --brass-soft: #2a2416; --focus: #d4a85c; --badge-bg: #d4a85c; --badge-text: #0a1f1a;
        --sidebar: #0b1a15; --sidebar-2: #152922; --sidebar-text: #c7ccc3; --sidebar-muted: #7f8e87;
        --sidebar-active: #1a3a30; --sidebar-active-text: #f5f2ec; --sidebar-border: #1b3129;
        --ok: #7fbf9c; --ok-bg: #13291f; --warn: #d4a85c; --warn-bg: #2a2416; --bad: #ec8a80; --bad-bg: #331915; --info: #8fbfd1; --info-bg: #13262d;
        --st-queued: #a7b1ab; --st-queued-bg: #1a2a24; --st-processing: #8fbfd1; --st-processing-bg: #13262d;
        --st-review: #d4a85c; --st-review-bg: #2a2416; --st-approved: #7fbf9c; --st-approved-bg: #13291f;
        --st-delivered: #b5d6c3; --st-delivered-bg: #1a3a30; --st-failed: #ec8a80; --st-failed-bg: #331915;
        --st-hold: #eda36f; --st-hold-bg: #33210f; --st-test: #bcaee0; --st-test-bg: #241f33;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3); --shadow-lg: 0 20px 60px rgba(0, 0, 0, .6);
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #09160f; --surface: #0e1f19; --surface-2: #122620; --surface-3: #183029;
    --border: #213a31; --border-strong: #2d4b40;
    --text: #eee9df; --text-2: #c7ccc3; --muted: #8e9c95;
    --accent: #d4a85c; --accent-strong: #e2bd77; --accent-soft: #2a2416; --accent-text: #0a1f1a; --link: #d4a85c;
    --brass: #d4a85c; --brass-deep: #e2bd77; --brass-soft: #2a2416; --focus: #d4a85c; --badge-bg: #d4a85c; --badge-text: #0a1f1a;
    --sidebar: #0b1a15; --sidebar-2: #152922; --sidebar-text: #c7ccc3; --sidebar-muted: #7f8e87;
    --sidebar-active: #1a3a30; --sidebar-active-text: #f5f2ec; --sidebar-border: #1b3129;
    --ok: #7fbf9c; --ok-bg: #13291f; --warn: #d4a85c; --warn-bg: #2a2416; --bad: #ec8a80; --bad-bg: #331915; --info: #8fbfd1; --info-bg: #13262d;
    --st-queued: #a7b1ab; --st-queued-bg: #1a2a24; --st-processing: #8fbfd1; --st-processing-bg: #13262d;
    --st-review: #d4a85c; --st-review-bg: #2a2416; --st-approved: #7fbf9c; --st-approved-bg: #13291f;
    --st-delivered: #b5d6c3; --st-delivered-bg: #1a3a30; --st-failed: #ec8a80; --st-failed-bg: #331915;
    --st-hold: #eda36f; --st-hold-bg: #33210f; --st-test: #bcaee0; --st-test-bg: #241f33;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4); --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3); --shadow-lg: 0 20px 60px rgba(0, 0, 0, .6);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: var(--font); font-size: 14px; line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; text-wrap: balance; }
h1 { font-family: var(--display); font-weight: 400; font-size: 30px; letter-spacing: -.02em; line-height: 1.1; font-optical-sizing: auto; }
h1 em, .display em { font-style: italic; color: var(--brass-deep); }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
code, kbd, .mono { font-family: var(--mono); font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1:focus, h1:focus-visible { outline: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.grow { flex: 1 1 auto; }
.hidden { display: none !important; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gap-lg { gap: 20px; }
.mt { margin-top: 16px; }
.mt-sm { margin-top: 8px; }
.mb { margin-bottom: 16px; }
.mb-sm { margin-bottom: 8px; }
.list-tools { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.list-tools label.btn { cursor: pointer; }
.wrap-anywhere { overflow-wrap: anywhere; }
.label { font-family: var(--mono); font-size: 10.5px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.display { font-family: var(--display); font-optical-sizing: auto; letter-spacing: -.02em; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    background: var(--sidebar); color: var(--sidebar-text); border-right: 1px solid var(--sidebar-border);
    display: flex; flex-direction: column; padding: 16px 12px 10px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 18px; color: var(--text); text-decoration: none !important; }
.brand-mark { width: 42px; height: 34px; flex: none; display: grid; place-items: center; }
.brand-mark img { width: 42px; height: auto; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-family: var(--display); font-size: 22px; font-weight: 500; letter-spacing: -.01em; color: var(--text); line-height: 1; }
.brand-text small { font-size: 11.5px; color: var(--sidebar-muted); margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.nav-group { font-family: var(--mono); font-size: 10px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; color: var(--sidebar-muted); padding: 16px 10px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
    color: var(--sidebar-text); text-decoration: none !important; font-weight: 500; font-size: 13.5px;
}
.nav-item i { font-size: 15px; width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: var(--sidebar-2); color: var(--text); }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-active-text); box-shadow: inset 3px 0 0 var(--brass); }
.nav-item.active i { opacity: 1; }
.nav-item span { flex: 1; }
.nav-count { font-family: var(--mono); font-size: 10.5px; font-weight: 500; background: var(--badge-bg); color: var(--badge-text); border-radius: 9px; padding: 0 7px; line-height: 18px; font-variant-numeric: tabular-nums; }
.nav-count.warn { background: var(--warn-bg); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.nav-count.bad { background: var(--bad); color: #fff; }
.sidebar-foot { font-family: var(--mono); font-size: 10px; letter-spacing: .04em; color: var(--sidebar-muted); padding: 12px 10px 4px; border-top: 1px solid var(--sidebar-border); margin-top: 12px; }
.scrim { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20; height: 56px; display: flex; align-items: center; gap: 12px;
    padding: 0 24px; background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
/* The menu button: hides the sidebar on wide screens (more room for the case page), opens it as a drawer on phones. */
@media (min-width: 1001px) {
    .shell.nav-collapsed { grid-template-columns: minmax(0, 1fr); }
    .shell.nav-collapsed .sidebar { display: none; }
}
.quick-search { position: relative; flex: 1; max-width: 460px; }
.quick-search i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }
.quick-search input[type=search] { width: 100%; padding-left: 32px; background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar-right form { margin: 0; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 20px; color: var(--text); text-decoration: none !important; }
.user-chip:hover { background: var(--surface-3); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 11.5px; letter-spacing: .02em; }
.user-text { display: flex; flex-direction: column; line-height: 1.15; }
.user-text strong { font-size: 13px; font-weight: 600; }
.user-text small { font-size: 11px; color: var(--muted); }
.content { padding: 22px 24px 48px; width: 100%; max-width: 1480px; }

@media (max-width: 1000px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .18s ease; }
    .nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(5, 12, 18, .45); z-index: 40; }
    .topbar { padding: 0 16px; }
    .content { padding: 16px 16px 40px; }
    .user-text { display: none; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); margin-top: 6px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.crumbs a { color: var(--muted); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-head h2 i { color: var(--muted); }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.grid { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 1150px) { .grid-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

/* Queue strip: the pipeline from import to delivery, one tile per stage */
.pipeline { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 16px; }
.stage { padding: 14px 16px; border-right: 1px solid var(--border); text-decoration: none !important; color: var(--text); position: relative; display: flex; flex-direction: column; gap: 2px; }
.stage:last-child { border-right: 0; }
.stage:hover { background: var(--surface-2); }
.stage .label { display: flex; align-items: center; gap: 6px; }
.stage .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--muted)); }
.stage .value { font-family: var(--display); font-size: 34px; font-weight: 400; font-variant-numeric: lining-nums tabular-nums; letter-spacing: -.02em; line-height: 1.1; margin-top: 2px; }
.stage .hint { font-size: 12px; color: var(--muted); }
.stage.hot .value { color: var(--c); }
@media (max-width: 1100px) { .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); } .stage:nth-child(3) { border-right: 0; } .stage:nth-child(-n+3) { border-bottom: 1px solid var(--border); } }
@media (max-width: 560px) { .pipeline { grid-template-columns: repeat(2, minmax(0, 1fr)); } .stage { border-right: 1px solid var(--border) !important; border-bottom: 1px solid var(--border); } .stage:nth-child(2n) { border-right: 0 !important; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .value { font-family: var(--display); font-size: 26px; font-weight: 400; font-variant-numeric: lining-nums tabular-nums; letter-spacing: -.01em; }
.kpi .hint { font-size: 12px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px; padding: 0 13px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 500; font-size: 13.5px;
    cursor: pointer; white-space: nowrap; text-decoration: none !important; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-brass { background: var(--badge-bg); border-color: var(--badge-bg); color: var(--badge-text); }
.btn-brass:hover { background: var(--brass-deep); border-color: var(--brass-deep); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: var(--accent-text); }
.btn-ok:hover { filter: brightness(1.08); background: var(--ok); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.btn-warn:hover { background: var(--warn-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm); border: 0; background: transparent; color: var(--text-2); cursor: pointer; font-size: 17px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); z-index: 1; }

/* ---------- Forms ---------- */
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=date], input[type=url], select, textarea {
    font: inherit; font-size: 13.5px; color: var(--text); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 6px 10px; min-height: 34px; width: 100%;
    transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: 70px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
input:disabled, select:disabled, textarea:disabled, input[readonly], textarea[readonly] { background: var(--surface-2); color: var(--text-2); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; vertical-align: middle; }
input[type=file] { font: inherit; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span, .field > label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field .help { font-size: 12px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.form-grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid .span-2 { grid-column: auto; } }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.filters .field { flex: 0 1 170px; }
.filters .field.wide { flex: 1 1 240px; }
.validation-message { color: var(--bad); font-size: 12px; }
@media (max-width: 560px) {
    .filters .field { flex: 1 1 calc(50% - 8px); }
    .filters .field.wide { flex-basis: 100%; }
    .page-head { align-items: flex-start; }
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-family: var(--mono); font-weight: 500; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
.table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table tr.selected td { background: var(--accent-soft) !important; }
.table .num, .table td.num { font-variant-numeric: tabular-nums; text-align: right; }
.table td.actions { text-align: right; white-space: nowrap; }
.table .sub { display: block; font-size: 12px; color: var(--muted); }
.table-compact td { padding: 5px 10px; }
.cell-strong { font-weight: 600; }
.acc { font-family: var(--mono); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.table .sub.mono { white-space: nowrap; }

/* ---------- Pills and tags ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; color: var(--c); background: var(--cb); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-queued { --c: var(--st-queued); --cb: var(--st-queued-bg); }
.st-processing { --c: var(--st-processing); --cb: var(--st-processing-bg); }
.st-review { --c: var(--st-review); --cb: var(--st-review-bg); }
.st-approved { --c: var(--st-approved); --cb: var(--st-approved-bg); }
.st-delivered { --c: var(--st-delivered); --cb: var(--st-delivered-bg); }
.st-failed { --c: var(--st-failed); --cb: var(--st-failed-bg); }
.st-hold { --c: var(--st-hold); --cb: var(--st-hold-bg); }
.st-test { --c: var(--st-test); --cb: var(--st-test-bg); }
.st-processing.pill::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 5px; font-size: 11.5px; font-weight: 500; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.tag.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.tag.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.tag.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.load { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: .03em; }
.load-high { background: var(--bad-bg); color: var(--bad); }
.load-medium { background: var(--warn-bg); color: var(--warn); }
.load-low { background: var(--ok-bg); color: var(--ok); }

/* ---------- Alerts, toasts, empty states ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13.5px; border: 1px solid transparent; }
.alert > i { font-size: 16px; line-height: 1.3; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.alert-bad { background: var(--bad-bg); color: var(--bad); }
.alert-info { background: var(--info-bg); color: var(--info); }
.alert .btn { margin-left: auto; }
.alert strong { font-weight: 600; }
.toast-host { position: fixed; right: 20px; top: 68px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--c, var(--accent)); box-shadow: var(--shadow-lg); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; animation: rise .18s ease-out; }
.toast.ok { --c: var(--ok); } .toast.bad { --c: var(--bad); } .toast.warn { --c: var(--warn); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-state i { font-size: 34px; color: var(--border-strong); }
.empty-state h2 { color: var(--text); }
.empty-state .btn { margin-top: 8px; }
.empty-row { text-align: center; color: var(--muted); padding: 28px 12px !important; }
.loading-block { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--muted); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .7s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab { padding: 10px 14px; border: 0; background: none; font: inherit; font-size: 13.5px; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--brass); }
.tab .count { font-size: 11px; background: var(--surface-3); border-radius: 9px; padding: 0 6px; color: var(--text-2); }
.card > .tabs { padding: 0 8px; }

/* ---------- Key/value lists ---------- */
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.case-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; padding: 14px 16px; }
.case-head .label { margin-bottom: 2px; }
.case-head .v { font-weight: 500; overflow-wrap: anywhere; }

/* ---------- Pager ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); flex-wrap: wrap; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(6, 14, 20, .5); z-index: 80; display: grid; place-items: center; padding: 16px; animation: fade .12s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; border: 1px solid var(--border); }
.modal.wide { width: min(900px, 100%); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 12px 12px; }

/* ---------- Bar charts (CSS only) ---------- */
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) minmax(0, 1fr) 48px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: block; height: 10px; background: var(--surface-3); border-radius: 5px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 5px; min-width: 2px; }
.bars.brass .bar-fill { background: var(--brass); }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 6px; }
.spark .col { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; opacity: .85; }
.spark .col:hover { opacity: 1; }
.spark-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ---------- Case page ---------- */
.case-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.section { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.section + .section { margin-top: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.section-head h3 { font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.section-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.item-row { display: grid; gap: 8px; grid-template-columns: 34px minmax(0, 1fr) 34px; align-items: start; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.item-row .n { font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 7px; text-align: center; }
.item-fields { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.item-fields .full { grid-column: 1 / -1; }
.sticky-bar { position: sticky; bottom: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(6px); border-top: 1px solid var(--border); padding: 10px 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 16px -16px -16px; border-radius: 0 0 var(--radius) var(--radius); }
.report-frame { width: 100%; height: 78vh; min-height: 520px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }
.hl7 { font-family: var(--mono); font-size: 12px; line-height: 1.6; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; overflow-x: auto; white-space: pre; margin: 0; max-height: 60vh; }
.hl7 .seg { color: var(--accent-strong); font-weight: 600; }
.hl7 .sep { color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--brass); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 16px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: 12px; color: var(--muted); }
.diff { font-size: 12.5px; }
.diff del { background: var(--bad-bg); color: var(--bad); text-decoration: line-through; }
.diff ins { background: var(--ok-bg); color: var(--ok); text-decoration: none; }
.sig-pad { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: #fff; touch-action: none; width: 100%; max-width: 480px; height: 160px; display: block; }
.sig-img { max-height: 80px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; }
.target-list { display: flex; flex-direction: column; }
.target { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.target:last-child { border-bottom: 0; }
.target .name { flex: 1; min-width: 0; }
.target .canon { font-size: 12px; color: var(--muted); }

/* ---------- Login ---------- */
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--bg); }
.login-brand-panel { background: #1a3a30; color: #f5f2ec; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; position: relative; overflow: hidden; }
.login-brand-panel .lockup { display: flex; align-items: center; gap: 14px; }
.login-brand-panel .lockup .tile { width: 58px; height: 58px; border-radius: 4px; background: #f5f2ec; display: grid; place-items: center; }
.login-brand-panel .lockup .tile img { width: 44px; height: auto; }
.login-brand-panel .lockup strong { font-family: var(--display); font-size: 30px; font-weight: 500; letter-spacing: -.01em; display: block; line-height: 1; }
.login-brand-panel .lockup small { font-size: 13px; color: #c9d3cd; display: block; margin-top: 4px; }
.login-brand-panel .eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: #d4a85c; margin-bottom: 18px; }
.login-brand-panel h2 { font-family: var(--display); font-weight: 350; font-size: clamp(34px, 3.6vw, 52px); line-height: 1.04; letter-spacing: -.025em; max-width: 14ch; }
.login-brand-panel h2 em { font-style: italic; color: #d4a85c; }
.login-brand-panel .fine { font-size: 12.5px; color: #a9b8b0; }
.login-main { display: grid; place-items: center; padding: 32px 16px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 18px; }
.login-card h1 { font-size: 36px; }
.login-card .lede { color: var(--muted); margin-top: -8px; }
.login-foot { font-size: 12.5px; color: var(--muted); }
.dev-help { border: 1px dashed var(--border); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2, transparent); }
.dev-help-title { font-size: 12.5px; font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.dev-help .kv { margin: 0; }
.login-mobile-brand { display: none; align-items: center; gap: 10px; }
.login-mobile-brand img { width: 40px; }
.login-mobile-brand strong { font-family: var(--display); font-size: 24px; font-weight: 500; }
@media (max-width: 860px) {
    .login-shell { grid-template-columns: minmax(0, 1fr); }
    .login-brand-panel { display: none; }
    .login-mobile-brand { display: flex; }
}

/* ---------- Blazor error bar ---------- */
#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000; padding: 10px 20px; background: var(--bad-bg); color: var(--bad); border-top: 1px solid var(--bad); font-size: 13.5px; }
#blazor-error-ui .dismiss { float: right; border: 0; background: none; color: inherit; font-size: 18px; cursor: pointer; line-height: 1; }
#blazor-error-ui .reload { font-weight: 600; margin-left: 8px; }
.blazor-error-boundary { display: none; }

@media print {
    .sidebar, .topbar, .page-actions, .sticky-bar { display: none !important; }
    .shell { display: block; }
}

/* v20.5 code-level reasoning on the case page */
details.mdm { margin-top: 6px; max-width: 360px; }
details.mdm summary { cursor: pointer; color: var(--muted); }
details.mdm .mdm-body { display: grid; gap: 8px; margin-top: 6px; }
details.mdm ul { margin: 2px 0 0; padding-left: 16px; }

/* v20.7 data cleanup */
ul.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
ul.issues li { line-height: 1.45; }
.addr-check { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
