/* ============================================================================
   LabNexa — core design system
   1. Tokens          6. Buttons        11. Badges & status   16. Print
   2. Base/reset      7. Panels         12. Tabs
   3. App shell       8. Forms          13. Feedback
   4. Sidebar nav     9. Tables         14. Data display
   5. Topbar         10. Overlays       15. Responsive
   ============================================================================ */

/* ---------- 0. Typefaces ------------------------------------------------- */
/* Self-hosted, not linked from Google: the app's CSP allows `font-src 'self'
   data:` only, and an on-premise laboratory should not need the internet to
   render its own UI. Variable files — one download covers 400 to 700. */
@font-face {
    font-family: "Plex Sans";
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url("fonts/plex-sans-latin-400-700.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                   U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC,
                   U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "Plex Sans";
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url("fonts/plex-sans-latin-ext-400-700.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
                   U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
                   U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: "Plex Mono";
    font-style: normal; font-weight: 400; font-display: swap;
    src: url("fonts/plex-mono-latin-400.woff2") format("woff2");
}
@font-face {
    font-family: "Plex Mono";
    font-style: normal; font-weight: 600; font-display: swap;
    src: url("fonts/plex-mono-latin-600.woff2") format("woff2");
}

/* ---------- 1. Tokens ---------------------------------------------------- */
:root {
    color-scheme: light;

    /* Brand ramp */
    --brand-50:  #eef6ff;
    --brand-100: #dbeafe;
    --brand-200: #bcd9f7;
    --brand-300: #8dbdef;
    --brand-400: #559ce2;
    --brand-500: #2a7ccc;
    --brand-600: #1459a6;
    --brand-700: #10488a;
    --brand-800: #0d3a6f;
    --brand-900: #0b2f5a;

    /* Accent (clinical teal) */
    --accent-50:  #e6f7f7;
    --accent-300: #6fd3d4;
    --accent-500: #12959c;
    --accent-600: #0d8b91;
    --accent-700: #0a6f75;

    /* Neutral ramp */
    --n-0:   #ffffff;
    --n-25:  #fbfcfe;
    --n-50:  #f4f7fa;
    --n-100: #eef1f6;
    --n-200: #e2e8f0;
    --n-300: #cbd5e1;
    --n-400: #94a3b8;
    /* Secondary text sits on this step, in the app (--muted) and on the landing
       page. At #6b7a8d it measured 4.38:1 on white and 3.87:1 on --surface-3,
       under the 4.5 floor for text this size. */
    --n-500: #5f6d7c;
    --n-600: #4e5c6e;
    --n-700: #384657;
    --n-800: #26313f;
    --n-900: #172331;

    /* Semantic pairs */
    --success-bg: #e4f6ee; --success-fg: #0f7050; --success: #16845b;
    --warning-bg: #fff3dd; --warning-fg: #8f5b09; --warning: #d88510;
    --danger-bg:  #ffe9ec; --danger-fg:  #ad2d40; --danger:  #c43b4d;
    --info-bg:    #e7f1fd; --info-fg:    #10488a;

    /* Roles */
    --bg:        var(--n-50);
    --surface:   var(--n-0);
    --surface-2: var(--n-25);
    --surface-3: var(--n-100);
    --line:      var(--n-200);
    --line-soft: var(--n-100);
    --text:      var(--n-900);
    --text-2:    var(--n-700);
    --muted:     var(--n-500);
    --primary:   var(--brand-600);
    --primary-hover: var(--brand-700);
    --on-primary: #ffffff;
    /* Brand-tinted surface. The --brand-* ramp is fixed across themes, so it
       must never be used as a background on its own: in dark mode that paints a
       light patch onto a dark page. These two follow the theme. */
    --wash:   #eef6ff;
    --wash-2: #dbeafe;
    --logo-tile: #eef6ff;   /* stays light in both themes: lab logos are dark ink */
    --focus:     var(--brand-500);

    /* Back-compat aliases — older rules and ~100 inline styles reference these */
    --blue:   var(--brand-600);
    --ink:    var(--n-900);
    --border: var(--n-200);

    /* Sidebar */
    --sidebar-bg:     #0c2c4e;
    --sidebar-bg-2:   #0a2440;
    --sidebar-fg:     #cbdcee;
    --sidebar-fg-dim: #7f9cba;
    --sidebar-hover:  rgba(255, 255, 255, .08);
    --sidebar-sel:    rgba(93, 173, 240, .18);

    /* Type */
    --font-ui: "Plex Sans", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    --font-mono: "Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;

    /* Geometry */
    --r-xs: 4px; --r-sm: 6px; --r-md: 9px; --r-lg: 13px; --r-xl: 18px; --r-pill: 999px;
    --sidebar-w: 258px;
    --topbar-h: 62px;
    --shell-max: 1560px;

    /* Elevation */
    --sh-1: 0 1px 2px rgba(16, 34, 54, .05), 0 1px 3px rgba(16, 34, 54, .05);
    --sh-2: 0 2px 4px rgba(16, 34, 54, .04), 0 6px 16px rgba(16, 34, 54, .06);
    --sh-3: 0 8px 20px rgba(16, 34, 54, .09), 0 2px 6px rgba(16, 34, 54, .05);
    --sh-4: 0 24px 60px rgba(11, 32, 56, .22);

    /* Motion */
    --t-fast: 120ms cubic-bezier(.4, 0, .2, 1);
    --t-med:  200ms cubic-bezier(.4, 0, .2, 1);
}

/* Dark palette — defined once, applied for both "system dark" and explicit opt-in. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg:        #0f1721;
        --surface:   #16202c;
        --surface-2: #1a2532;
        --surface-3: #202d3c;
        --line:      #2a3849;
        --line-soft: #223040;
        --text:      #e7edf5;
        --text-2:    #c2ceda;
        --muted:     #8b9bad;
        --primary:   var(--brand-400);
        --primary-hover: var(--brand-300);
        --on-primary: #08213c;
        --wash:   #16283c;
        --wash-2: #1d3550;
        --focus:     var(--brand-300);
        --blue:      var(--brand-300);
        --ink:       #e7edf5;
        --border:    #2a3849;
        --success-bg: #10352a; --success-fg: #6bd7ac;
        --warning-bg: #3a2c11; --warning-fg: #f0be6b;
        --danger-bg:  #3a1a20; --danger-fg:  #f3a3ae;
        --info-bg:    #14283f; --info-fg:    #9cc9f5;
        --sidebar-bg:   #0b1824;
        --sidebar-bg-2: #091320;
        --sh-1: 0 1px 2px rgba(0, 0, 0, .3);
        --sh-2: 0 2px 6px rgba(0, 0, 0, .32);
        --sh-3: 0 10px 26px rgba(0, 0, 0, .4);
        --sh-4: 0 24px 60px rgba(0, 0, 0, .55);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg:        #0f1721;
    --surface:   #16202c;
    --surface-2: #1a2532;
    --surface-3: #202d3c;
    --line:      #2a3849;
    --line-soft: #223040;
    --text:      #e7edf5;
    --text-2:    #c2ceda;
    --muted:     #8b9bad;
    --primary:   var(--brand-400);
    --primary-hover: var(--brand-300);
    --on-primary: #08213c;
    --wash:   #16283c;
    --wash-2: #1d3550;
    --focus:     var(--brand-300);
    --blue:      var(--brand-300);
    --ink:       #e7edf5;
    --border:    #2a3849;
    --success-bg: #10352a; --success-fg: #6bd7ac;
    --warning-bg: #3a2c11; --warning-fg: #f0be6b;
    --danger-bg:  #3a1a20; --danger-fg:  #f3a3ae;
    --info-bg:    #14283f; --info-fg:    #9cc9f5;
    --sidebar-bg:   #0b1824;
    --sidebar-bg-2: #091320;
    --sh-1: 0 1px 2px rgba(0, 0, 0, .3);
    --sh-2: 0 2px 6px rgba(0, 0, 0, .32);
    --sh-3: 0 10px 26px rgba(0, 0, 0, .4);
    --sh-4: 0 24px 60px rgba(0, 0, 0, .55);
}

/* ---------- 2. Base ------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.55;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv05" 1, "ss03" 1;   /* single-storey l, disambiguated 1/l/I */
}

h1, h2, h3, h4 { line-height: 1.22; letter-spacing: -.018em; margin: 0; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p  { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
small { font-size: 12px; }
b, strong { font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* Anything a technologist reads as an identifier or compares column-to-column
   gets the mono face and lining, equal-width digits: accession numbers,
   barcodes, MR numbers, money, result values. */
.mono, .accession-bars, .report-barcode + small, code, kbd, samp {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
}
td, th, .stat-card strong, .owner-kpi strong, .command-card strong,
.dashboard-kpi strong, .billing-amount, .receipt-amount strong,
.invoice-totals, .tally b { font-variant-numeric: tabular-nums; }

a { color: var(--primary); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--primary-hover); }

img, svg, video { max-width: 100%; }
img, svg { vertical-align: middle; }

/* Reboot bits the app used to inherit from Bootstrap. Bootstrap is no longer
   loaded: nothing in the markup used its grid or utilities, and its .btn,
   .badge, .alert, .table, .progress and .modal-backdrop rules collided by name
   with this design system. */
button, input, select, textarea, optgroup { font-family: inherit; }
button { font-size: inherit; line-height: inherit; }
ul, ol { padding-left: 22px; margin: 0 0 10px; }
ul:last-child, ol:last-child { margin-bottom: 0; }
fieldset { min-width: 0; padding: 0; margin: 0; border: 0; }
legend { padding: 0; font-size: inherit; }
caption { padding: 8px 0; color: var(--muted); text-align: left; }
code, pre, kbd, samp { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
sub, sup { position: relative; font-size: .75em; line-height: 0; vertical-align: baseline; }
sup { top: -.5em; }
sub { bottom: -.25em; }
[hidden] { display: none !important; }

/* Blazor EditForm validation — previously unstyled, so invalid fields and their
   messages were indistinguishable from valid ones. */
.validation-message, .validation-errors li { color: var(--danger-fg); font-size: 12px; }
.validation-errors { list-style: none; padding: 0; margin: 0 0 12px; }
.invalid:not(.valid) { border-color: var(--danger); }
.invalid:not(.valid):focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent); }

::selection { background: var(--brand-200); color: var(--brand-900); }

/* One consistent, always-visible focus ring. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.muted { color: var(--muted); }
.text-danger { color: var(--danger-fg); }

/* `.sub` is the secondary line under a primary value — MR number under a patient
   name, barcode under a sample type. It replaced 47 copies of
   style="display:block;color:var(--muted)" scattered through the pages. */
.sub { display: block; margin-top: 2px; color: var(--muted); }
.block { display: block; }

/* Small layout utilities, named so the intent survives. Each replaced a literal
   that appeared in several pages; data-driven values (bar widths, chart heights)
   stay inline because they are computed per row. */
.btn-block  { width: 100%; margin-top: 12px; }
.stack-sm   { margin-top: 12px; }
.stack-none { margin: 0 0 4px; }
.chip-row   { display: flex; gap: 4px; flex-wrap: wrap; }
.stack-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.stack-item:last-child { border-bottom: 0; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- 3. App shell ------------------------------------------------- */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
}

.app-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

.app-shell {
    flex: 1;
    width: 100%;
    max-width: var(--shell-max);
    margin: 0 auto;
    padding: 24px 28px 56px;
    min-width: 0;
}

.app-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    border-top: 1px solid var(--line);
    padding: 14px 28px;
    color: var(--muted);
    font-size: 12px;
    background: var(--surface);
}
.app-footer span { opacity: .45; }

.skip-link {
    position: absolute; left: 10px; top: -60px; z-index: 200;
    padding: 10px 16px; border-radius: var(--r-md);
    background: var(--primary); color: var(--on-primary); font-weight: 650;
    transition: top var(--t-fast);
}
.skip-link:focus { top: 10px; color: var(--on-primary); }

/* ---------- 4. Sidebar navigation ---------------------------------------- */
.app-sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-fg);
    border-right: 1px solid rgba(255, 255, 255, .07);
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    flex: 0 0 auto;
    height: var(--topbar-h);
    padding: 0 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    color: #fff;
    overflow: hidden;
}
.sidebar-brand:hover { color: #fff; }
.sidebar-brand img {
    width: 34px; height: 34px; flex: 0 0 34px;
    object-fit: contain; padding: 3px;
    background: #fff; border-radius: var(--r-md);
}
.sidebar-brand > span { display: grid; min-width: 0; }
.sidebar-brand b {
    font-size: 15px; font-weight: 700; letter-spacing: -.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-brand small {
    font-size: 9.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
    color: var(--sidebar-fg-dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 10px 18px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .2) transparent;
}
.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .16); border-radius: var(--r-pill);
}

.nav-menu-search {
    display: grid; grid-template-columns: 18px minmax(0, 1fr) 24px; align-items: center; gap: 6px;
    margin: 2px 7px 12px; padding: 7px 8px;
    border: 1px solid rgba(255, 255, 255, .14); border-radius: var(--r-md);
    background: rgba(255, 255, 255, .07); color: var(--sidebar-fg-dim);
    transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
.nav-menu-search:focus-within { border-color: var(--accent-300); background: rgba(255, 255, 255, .1); box-shadow: 0 0 0 3px rgba(93, 173, 240, .12); }
.nav-menu-search > span { font-size: 18px; line-height: 1; transform: rotate(-15deg); }
.nav-menu-search input { min-width: 0; height: auto; padding: 0; border: 0; outline: 0; background: transparent; color: #fff; font-size: 12.5px; box-shadow: none; }
.nav-menu-search input::placeholder { color: var(--sidebar-fg-dim); opacity: 1; }
.nav-menu-search input::-webkit-search-cancel-button { display: none; }
.nav-menu-search button { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--sidebar-fg-dim); font-size: 18px; line-height: 1; cursor: pointer; }
.nav-menu-search button:hover { background: var(--sidebar-hover); color: #fff; }
.nav-menu-search:not(:has(button)) { grid-template-columns: 18px minmax(0, 1fr); }
.nav-search-empty { margin: 16px 9px; padding: 14px 10px; border: 1px dashed rgba(255, 255, 255, .15); border-radius: var(--r-md); color: var(--sidebar-fg-dim); text-align: center; font-size: 12px; }
.nav-section { margin-bottom: 2px; }
.nav-section > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px 7px;
    color: var(--sidebar-fg-dim);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .13em;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: var(--r-sm);
    list-style: none;
    user-select: none;
    transition: color var(--t-fast), background var(--t-fast);
}
.nav-section > summary::-webkit-details-marker { display: none; }
.nav-section > summary:hover { color: #fff; background: var(--sidebar-hover); }
.nav-section > summary::after {
    content: "";
    margin-left: auto;
    width: 6px; height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    transition: transform var(--t-med);
}
.nav-section[open] > summary::after { transform: translateY(1px) rotate(225deg); }

.nav-list { display: grid; gap: 1px; padding: 2px 0 8px; }
.nav-list a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--r-md);
    color: var(--sidebar-fg);
    font-size: 13.5px;
    line-height: 1.3;
    transition: background var(--t-fast), color var(--t-fast);
}
.nav-list a > i {
    flex: 0 0 20px;
    display: grid; place-items: center;
    width: 20px; height: 20px;
    font-style: normal; font-size: 14px;
    color: var(--sidebar-fg-dim);
    transition: color var(--t-fast), transform var(--t-fast);
}
.nav-list a > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-list a:hover { background: var(--sidebar-hover); color: #fff; }
.nav-list a:hover > i { color: var(--accent-300); transform: scale(1.08); }
.nav-list a.active {
    background: linear-gradient(90deg, var(--sidebar-sel), transparent 88%);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07);
}
.nav-list a.active > i { color: var(--accent-300); }
/* Active marker: a rail with a soft halo, so the eye finds the current page
   before it reads any label. */
.nav-list a.active::before {
    content: "";
    position: absolute; left: -10px; top: 50%; margin-top: -10px;
    width: 3px; height: 20px;
    background: var(--accent-300);
    border-radius: 0 var(--r-xs) var(--r-xs) 0;
    box-shadow: 0 0 10px 1px color-mix(in srgb, var(--accent-300) 55%, transparent);
}
.nav-list a:focus-visible { outline-offset: -2px; }

.sidebar-foot {
    flex: 0 0 auto;
    padding: 10px;
    border-top: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-lab {
    display: grid;
    gap: 7px;
    padding: 10px 11px;
    border-radius: var(--r-md);
    background: rgba(255, 255, 255, .05);
}
.sidebar-lab small {
    color: var(--sidebar-fg-dim);
    font-size: 9.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
}
.sidebar-lab select {
    background: rgba(255, 255, 255, .08);
    border-color: rgba(255, 255, 255, .18);
    color: #fff;
    padding: 7px 9px;
    font-size: 12.5px;
}
.sidebar-lab select option { color: var(--n-900); background: #fff; }
.sidebar-lab-name { color: #fff; font-size: 13px; }
.sidebar-lab .btn {
    width: 100%;
    background: rgba(255, 255, 255, .1);
    border-color: rgba(255, 255, 255, .2);
    color: #fff;
}
.sidebar-lab .btn:hover { background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .3); color: #fff; }

/* Mobile drawer plumbing — CSS-only so navigation never depends on a live circuit. */
.nav-toggle { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.nav-scrim { display: none; }

/* ---------- 5. Topbar ---------------------------------------------------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 14px;
    height: var(--topbar-h);
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
@supports (backdrop-filter: blur(4px)) {
    .topbar {
        background: color-mix(in srgb, var(--surface) 86%, transparent);
        backdrop-filter: saturate(1.4) blur(10px);
    }
}

.nav-toggle-label {
    display: none;
    place-items: center;
    width: 38px; height: 38px;
    border-radius: var(--r-md);
    color: var(--text-2);
    font-size: 18px;
    cursor: pointer;
    transition: background var(--t-fast);
}
.nav-toggle-label:hover { background: var(--surface-3); }

.topbar-context { display: grid; min-width: 0; }
.topbar-context b { font-size: 13.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-context small { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.top-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.language-switcher { margin: 0; }
.language-switcher label { margin: 0; }
.language-switcher select {
    width: auto;
    min-width: 82px;
    height: 38px;
    padding: 0 30px 0 10px;
    border-radius: var(--r-md);
    background-color: var(--surface);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 650;
}

html[dir="rtl"] body {
    font-family: "Noto Nastaliq Urdu", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
    line-height: 1.65;
}
html[dir="rtl"] .app-sidebar { border-right: 0; border-left: 1px solid rgba(255,255,255,.07); }
html[dir="rtl"] .top-actions { margin-left: 0; margin-right: auto; }
html[dir="rtl"] .nav-section > summary::after { margin-left: 0; margin-right: auto; }
html[dir="rtl"] .nav-list a.active {
    background: linear-gradient(270deg, var(--sidebar-sel), transparent 88%);
}
html[dir="rtl"] .nav-list a.active::before {
    left: auto; right: -10px;
    border-radius: var(--r-xs) 0 0 var(--r-xs);
}
html[dir="rtl"] .skip-link { left: auto; right: 10px; }
html[dir="rtl"] input,
html[dir="rtl"] textarea { text-align: start; }
html[dir="rtl"] input[type="email"],
html[dir="rtl"] input[type="tel"],
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[type="date"],
html[dir="rtl"] input[type="datetime-local"],
html[dir="rtl"] code,
html[dir="rtl"] .ltr { direction: ltr; text-align: left; unicode-bidi: isolate; }
html[dir="rtl"] td,
html[dir="rtl"] .user-chip b,
html[dir="rtl"] .topbar-context,
html[dir="rtl"] .sidebar-lab-name { unicode-bidi: plaintext; }

.quick-create {
    display: inline-flex; align-items: center; gap: 6px;
    height: 38px; padding: 0 15px;
    border-radius: var(--r-md);
    background: var(--primary);
    color: var(--on-primary) !important;
    font-size: 13px; font-weight: 600;
    box-shadow: var(--sh-1);
    white-space: nowrap;
    transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.quick-create:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--sh-2); }

.icon-btn {
    display: grid; place-items: center;
    width: 38px; height: 38px; flex: 0 0 38px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--text-2);
    font: inherit; font-size: 15px;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--wash); border-color: var(--brand-300); color: var(--primary); }

/* One button, two glyphs: show the appearance the click will switch *to*. */
.theme-toggle > span { grid-area: 1 / 1; line-height: 1; }
.theme-icon-light { display: none; }
.theme-icon-dark  { display: block; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-icon-light { display: block; }
    :root:not([data-theme="light"]) .theme-icon-dark  { display: none; }
}
:root[data-theme="dark"] .theme-icon-light { display: block; }
:root[data-theme="dark"] .theme-icon-dark  { display: none; }
:root[data-theme="light"] .theme-icon-light { display: none; }
:root[data-theme="light"] .theme-icon-dark  { display: block; }
.theme-toggle .sr-only { grid-area: auto; }

.user-chip {
    display: flex; align-items: center; gap: 9px;
    padding: 4px 12px 4px 4px;
    border-radius: var(--r-pill);
    border: 1px solid var(--line);
    background: var(--surface);
    font-size: 12px;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.user-chip:hover { border-color: var(--brand-300); background: var(--wash); }
.user-chip > span:last-child { display: grid; line-height: 1.25; }
.user-chip b { font-size: 12.5px; color: var(--text); }
.user-chip small { color: var(--muted); font-size: 11px; }

.avatar {
    display: grid; place-items: center;
    width: 32px; height: 32px; flex: 0 0 32px;
    border-radius: 50%;
    background: linear-gradient(140deg, var(--brand-500), var(--brand-700));
    color: #fff;
    font-size: 12px; font-weight: 700;
}

.logout-btn {
    display: grid; place-items: center;
    width: 38px; height: 38px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--muted);
    font-size: 17px;
    cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}
.logout-btn:hover { background: var(--danger-bg); color: var(--danger-fg); }

/* ---------- 6. Page heading & buttons ------------------------------------ */
.page-heading {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin: 0 0 22px;
    padding: 22px 26px;
    border-radius: var(--r-xl);
    background:
        radial-gradient(1200px 320px at 88% -60%, rgba(111, 211, 212, .34), transparent 62%),
        linear-gradient(116deg, var(--brand-800) 0%, var(--brand-600) 58%, var(--accent-600) 130%);
    box-shadow: var(--sh-3), inset 0 1px 0 rgba(255, 255, 255, .14);
    color: #fff;
}
/* A faint graph-paper grid — the surface a lab result is plotted on. Sits under
   the content and is masked away to the right so it never fights the text. */
.page-heading::before {
    content: "";
    position: absolute; inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
    background-size: 34px 34px;
    -webkit-mask-image: linear-gradient(105deg, #000 12%, transparent 62%);
    mask-image: linear-gradient(105deg, #000 12%, transparent 62%);
    pointer-events: none;
}
.page-heading::after {
    content: "";
    position: absolute; right: -60px; top: -110px;
    width: 224px; height: 224px;
    border: 38px solid rgba(255, 255, 255, .06);
    border-radius: 50%;
    pointer-events: none;
}
.page-heading > * { position: relative; z-index: 1; }
.page-heading h1 { color: #fff; font-size: 25px; }
.page-heading p { margin: 5px 0 0; color: rgba(232, 243, 255, .84); font-size: 13px; max-width: 78ch; }
.page-heading .eyebrow,
.page-heading .platform-eyebrow,
.page-heading .advanced-eyebrow {
    display: block;
    margin-bottom: 5px;
    color: var(--accent-300);
    font-size: 10px; font-weight: 800; letter-spacing: .15em; text-transform: uppercase;
}
.page-heading .badge { background: rgba(255, 255, 255, .16); color: #fff; }
.page-heading .btn {
    min-height: 38px;
    border-color: rgba(255, 255, 255, .32);
    background: rgba(255, 255, 255, .12);
    color: #fff;
}
.page-heading .btn:hover { background: rgba(255, 255, 255, .22); border-color: rgba(255, 255, 255, .5); color: #fff; }
.page-heading .btn-primary,
.page-heading a.btn-primary {
    background: #fff;
    border-color: #fff;
    color: var(--brand-700) !important;
}
.page-heading .btn-primary:hover { background: var(--brand-50); border-color: var(--brand-50); color: var(--brand-800) !important; }
.page-heading input,
.page-heading select {
    background: rgba(255, 255, 255, .95);
    border-color: rgba(255, 255, 255, .4);
    color: var(--n-900);
    min-height: 38px;
}

.actions { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 8px 15px;
    border: 1px solid var(--n-300);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--text-2);
    font: inherit;
    font-size: 13px;
    font-weight: 550;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
}
.btn:hover { border-color: var(--brand-400); background: var(--wash); color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn:disabled:hover { border-color: var(--n-300); background: var(--surface); color: var(--text-2); }

.btn-primary, .btn.btn-primary {
    /* A one-stop highlight along the top edge reads as a raised surface without
       looking like a gradient button. */
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--primary) 88%, #fff) 0%, var(--primary) 55%);
    border-color: var(--primary);
    color: var(--on-primary) !important;
    font-weight: 600;
    box-shadow: var(--sh-1), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.btn-primary:hover, .btn.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--on-primary) !important;
    box-shadow: var(--sh-2), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.btn-primary:active, .btn.btn-primary:active { box-shadow: inset 0 2px 4px rgba(0, 0, 0, .18); }

.btn-success, .btn.btn-success {
    background: var(--success); border-color: var(--success); color: #fff !important; font-weight: 600;
}
.btn-success:hover { background: #0f6c4a; border-color: #0f6c4a; color: #fff !important; }

.btn-warning, .btn.btn-warning {
    background: var(--warning-bg); border-color: #f0cd8e; color: var(--warning-fg);
    font-weight: 600;
}
.btn-warning:hover { background: var(--warning); border-color: var(--warning); color: #fff; }

.btn-danger, .btn.btn-danger {
    background: var(--danger-bg); border-color: #f3c3ca; color: var(--danger-fg);
    font-weight: 600;
}
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.btn-sm, .btn.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 12px; border-radius: var(--r-sm); }

/* ---------- 7. Panels ---------------------------------------------------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-1);
    margin-bottom: 18px;
    overflow: hidden;
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
}
.panel-header h2 { font-size: 15.5px; }
.panel-header small { display: block; color: var(--muted); margin-top: 4px; }
.panel-header .advanced-eyebrow,
.panel-header .platform-eyebrow {
    display: block; margin-bottom: 4px;
    color: var(--accent-600); font-size: 10px; font-weight: 800;
    letter-spacing: .14em; text-transform: uppercase;
}
.panel-body { padding: 20px; }
.panel-body > p.muted { line-height: 1.6; }

/* Accent rails for panels that call out a state, replacing inline
   `border-left:4px solid #hex` so the colours track the theme. */
.panel-accent-info    { border-left: 4px solid var(--primary); }
.panel-accent-warning { border-left: 4px solid var(--warning); }
.panel-accent-danger  { border-left: 4px solid var(--danger); }
.panel-accent-success { border-left: 4px solid var(--success); }

.section-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap; margin: 22px 0 12px;
}
.section-toolbar h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- 8. Forms ----------------------------------------------------- */
input, select, textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid var(--n-300);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    outline: none;
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
input::placeholder, textarea::placeholder { color: var(--n-400); }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--n-400); }
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
    outline: none;
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--muted); cursor: not-allowed; }
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }

/* Controls that must never be stretched by the width:100% rule above. */
input[type="checkbox"], input[type="radio"] {
    width: 16px; height: 16px; min-height: 0; flex: 0 0 auto;
    padding: 0; accent-color: var(--primary); cursor: pointer;
}
input[type="file"] { padding: 7px 10px; }
input[type="color"] { padding: 3px; height: 38px; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.required::after { content: " *"; color: var(--danger); }
.required-dot { color: var(--danger); margin-left: 3px; }
.field-guidance { display: block; color: var(--muted); font-weight: 400; margin-top: 5px; line-height: 1.4; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid > div { min-width: 0; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }

.form-actions {
    display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap;
    margin: 22px -20px -20px;
    padding: 15px 20px;
    border-top: 1px solid var(--line);
    background: var(--surface-2);
}

/* Filter bars size themselves. The old fixed grid
   (minmax(240px,1fr) 180px 180px auto) assumed search-first ordering, so any
   page that led with a date field gave the widest slot to a date picker and
   squeezed the search box and the button. Flex lets the search box take the
   slack whatever order the controls appear in, and `align-items: end` keeps
   controls aligned on the input row when some of them carry a label. */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
    margin-bottom: 18px;
}
.filters > * { flex: 0 1 auto; min-width: 0; }
.filters > div { min-width: 150px; }
.filters > input, .filters > select { width: auto; min-width: 160px; }
.filters .search-box { flex: 1 1 260px; min-width: 200px; }
.filters .search-box input { width: 100%; }
.filters > .btn, .filters > .badge { flex: 0 0 auto; }
.filters label { margin-bottom: 5px; }
.filters .booking-date-field { margin-bottom: 0; }

.booking-tests-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.booking-tests-actions .badge { margin-right: 3px; }

.search-box { position: relative; }
.search-box input { padding-left: 36px; }
.search-box::before {
    content: "⌕";
    position: absolute; left: 12px; top: 50%; translate: 0 -55%;
    color: var(--n-400); font-size: 18px; pointer-events: none;
}

.status-switch {
    display: flex; align-items: center; gap: 10px;
    min-height: 38px; padding: 8px 13px;
    border: 1px solid var(--n-300); border-radius: var(--r-sm);
    background: var(--surface); cursor: pointer; font-weight: 400;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.status-switch:hover { border-color: var(--brand-400); background: var(--wash); }
.status-switch span { font-weight: 600; color: var(--text); }

.permission-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.permission-option {
    display: flex; gap: 10px; align-items: flex-start;
    border: 1px solid var(--line); border-radius: var(--r-md);
    padding: 12px; font-weight: 400; cursor: pointer;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.permission-option:hover { border-color: var(--brand-300); background: var(--wash); }
.permission-option:has(input:checked) { border-color: var(--primary); background: var(--wash); }
.permission-option input { margin-top: 2px; }
.permission-option small { display: block; color: var(--muted); margin-top: 3px; font-weight: 400; }

.check {
    display: inline-flex; align-items: center; gap: 6px;
    margin: 0 8px 8px 0; padding: 5px 9px;
    border: 1px solid var(--line); border-radius: var(--r-sm);
    background: var(--surface-2); font-size: 12px; font-weight: 500; cursor: pointer;
}
.check input { margin: 0; }

.password-input-wrap { position: relative; }
.password-input-wrap input { padding-right: 46px; }
.password-toggle {
    position: absolute; right: 4px; top: 50%; translate: 0 -50%;
    display: grid; place-items: center;
    width: 34px; height: 34px; padding: 7px;
    border: 0; border-radius: var(--r-sm);
    background: transparent; color: var(--muted); cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}
.password-toggle:hover { background: var(--surface-3); color: var(--primary); }
.password-toggle svg {
    width: 20px; height: 20px; fill: none; stroke: currentColor;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.remember-login {
    display: flex !important; align-items: center; gap: 9px;
    margin: 0; font-weight: 500; cursor: pointer;
}
.remember-login span { color: var(--text-2); font-size: 13px; }

/* Type-ahead select */
.smart-select { position: relative; }
.smart-select-backdrop { position: fixed; inset: 0; border: 0; background: transparent; z-index: 29; }
.smart-options {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 31;
    max-height: 288px; overflow: auto;
    padding: 5px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--sh-3);
}
.smart-options button {
    display: block; width: 100%; padding: 9px 10px;
    border: 0; border-radius: var(--r-sm);
    background: transparent; color: var(--text);
    font: inherit; font-size: 13px; text-align: left; cursor: pointer;
    transition: background var(--t-fast);
}
.smart-options button:hover { background: var(--wash); color: var(--primary); }
.smart-options small { display: block; color: var(--muted); margin-top: 3px; }
.smart-options > span { display: block; padding: 14px; color: var(--muted); font-size: 12px; }
.smart-options .smart-options-close {
    color: var(--muted); font-size: 12px; text-align: right;
    border-bottom: 1px solid var(--line-soft); border-radius: 0;
}

.logo-upload {
    display: flex; align-items: center; gap: 16px;
    padding: 14px;
    border: 1px dashed var(--n-300); border-radius: var(--r-md);
    background: var(--surface-2);
}
.logo-upload img {
    width: 74px; height: 74px; object-fit: contain; padding: 5px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.logo-upload small { display: block; color: var(--muted); margin-top: 7px; }

.formula-builder {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px;
    margin: 7px 0; padding: 9px;
    border: 1px solid var(--brand-200); border-radius: var(--r-sm);
    background: var(--wash);
}
.formula-builder input, .formula-builder select { min-height: 32px; font-size: 12px; }

/* ---------- 9. Tables ---------------------------------------------------- */
.table-wrap {
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: thin;
    scrollbar-color: var(--n-300) transparent;
}
.table-wrap::-webkit-scrollbar { height: 9px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--n-300); border-radius: var(--r-pill); }
.table-wrap::-webkit-scrollbar-track { background: transparent; }

.patients-grid-footer, .standard-grid-footer {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    min-height: 64px; padding: 12px 16px;
    border-top: 1px solid var(--line); background: var(--surface-2);
}
.patients-grid-summary, .standard-grid-summary { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.patients-grid-summary b, .standard-grid-summary b { color: var(--text); }
.patients-grid-summary span::before, .standard-grid-summary span::before { content: "·"; margin-right: 8px; }
.patients-grid-controls, .patients-pagination, .standard-grid-controls, .standard-pagination { display: flex; align-items: center; gap: 9px; }
.patients-grid-controls label, .standard-grid-controls label { display: flex; align-items: center; gap: 8px; margin: 0; white-space: nowrap; }
.patients-grid-controls select, .standard-grid-controls select {
    width: 86px; min-width: 86px; min-height: 36px;
    padding: 5px 30px 5px 12px;
    color: var(--text); background-color: var(--surface);
}
.patients-pagination > span, .standard-pagination > span { min-width: 92px; text-align: center; color: var(--muted); font-size: 12px; }

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }

/* Header stays put while a long worklist scrolls. */
th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 11px 15px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    /* --text-2 rather than --muted: at 10px uppercase the muted grey measured
       4.27:1 on the header fill, just under the 4.5:1 floor. */
    color: var(--text-2);
    font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
}
.grid-sort-button {
    display: inline-flex; align-items: center; gap: 6px;
    margin: -5px -7px; padding: 5px 7px; border: 0; border-radius: var(--r-sm);
    background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit;
    cursor: pointer; white-space: nowrap;
}
.grid-sort-button:hover { background: var(--surface-3); color: var(--primary); }
.grid-sort-button span { min-width: 10px; color: var(--muted); font-size: 9px; text-align: center; }

td { padding: 12px 15px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr { transition: background var(--t-fast), box-shadow var(--t-fast); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--primary); }
tbody tr:last-child td { border-bottom: 0; }
td small { color: var(--muted); }

.table-link { font-weight: 600; color: var(--primary); font-family: var(--font-mono); font-size: 12.5px; }
.table-link:hover { text-decoration: underline; text-underline-offset: 2px; }

.money-positive { color: var(--success-fg); font-weight: 650; }
.money-due { color: var(--danger-fg); font-weight: 700; }
.negative { color: var(--danger-fg); }

/* ---------- 10. Overlays ------------------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    display: grid; place-items: center;
    padding: 24px;
    background: rgba(10, 26, 43, .55);
    backdrop-filter: blur(3px);
}
.modal-card {
    width: min(1050px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    box-shadow: var(--sh-4);
}
.modal-card > .panel { margin: 0; border: 0; box-shadow: none; border-radius: inherit; }

/* ---------- 11. Badges & status ------------------------------------------ */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px 4px 8px;
    border-radius: var(--r-pill);
    background: var(--surface-3);
    color: var(--text-2);
    font-size: 11px; font-weight: 600; line-height: 1.4;
    white-space: nowrap;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 14%, transparent);
}
/* A status dot as well as a colour: state stays legible for anyone who cannot
   separate the four hues, and reads faster at a glance in a dense worklist. */
.badge::before {
    content: "";
    width: 6px; height: 6px; flex: 0 0 6px;
    border-radius: 50%;
    background: currentColor;
}
.badge-blue  { background: var(--info-bg);    color: var(--info-fg); }
.badge-green { background: var(--success-bg); color: var(--success-fg); }
.badge-amber { background: var(--warning-bg); color: var(--warning-fg); }
.badge-red   { background: var(--danger-bg);  color: var(--danger-fg); }
/* Counter-style badges carry a number, not a state — no dot. */
.tabs .badge::before, .page-heading .badge::before { display: none; }

/* ---------- 12. Tabs ----------------------------------------------------- */
.tabs {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: thin;
    margin-bottom: 18px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--sh-1);
}
.tabs a, .tabs button {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    border: 0; border-radius: var(--r-md);
    background: transparent;
    color: var(--muted);
    font: inherit; font-size: 13px; font-weight: 550;
    white-space: nowrap; cursor: pointer;
    transition: background var(--t-fast), color var(--t-fast);
}
.tabs a:hover, .tabs button:hover { background: var(--surface-3); color: var(--text); }
.tabs a.active, .tabs button.active {
    background: var(--primary);
    color: var(--on-primary);
    font-weight: 650;
    box-shadow: var(--sh-1);
}
.tabs a.active .badge, .tabs button.active .badge { background: rgba(255, 255, 255, .2); color: #fff; }

/* ---------- 13. Feedback ------------------------------------------------- */
.alert {
    display: flex; gap: 10px;
    padding: 12px 15px;
    margin-bottom: 16px;
    border: 1px solid transparent;
    border-left-width: 3px;
    border-radius: var(--r-md);
    background: var(--info-bg);
    border-color: color-mix(in srgb, var(--info-fg) 22%, transparent);
    border-left-color: var(--info-fg);
    color: var(--info-fg);
    font-size: 13px;
    line-height: 1.5;
}
.alert-danger {
    background: var(--danger-bg);
    border-color: color-mix(in srgb, var(--danger-fg) 22%, transparent);
    border-left-color: var(--danger-fg);
    color: var(--danger-fg);
}
.alert-success {
    background: var(--success-bg);
    border-color: color-mix(in srgb, var(--success-fg) 22%, transparent);
    border-left-color: var(--success-fg);
    color: var(--success-fg);
}
.alert-warning {
    background: var(--warning-bg);
    border-color: color-mix(in srgb, var(--warning-fg) 22%, transparent);
    border-left-color: var(--warning-fg);
    color: var(--warning-fg);
}

.empty {
    display: grid; justify-items: center; gap: 4px;
    padding: 48px 20px;
    color: var(--muted);
    text-align: center;
}
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.empty h2 { margin-bottom: 6px; }

.app-error-panel { max-width: 700px; margin: 40px auto; }
.app-error-panel h2 { margin: 0 0 8px; color: var(--text); }

#blazor-error-ui {
    position: fixed; bottom: 0; left: 0; width: 100%; z-index: 1000;
    display: none;
    padding: .7rem 1.25rem;
    background: var(--warning-bg);
    color: var(--warning-fg);
    border-top: 1px solid color-mix(in srgb, var(--warning-fg) 30%, transparent);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .12);
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
#blazor-error-ui .reload { text-decoration: underline; cursor: pointer; }

/* ---------- 14. Data display --------------------------------------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    position: relative;
    overflow: hidden;
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-1);
    min-width: 0;
    transition: box-shadow var(--t-med), transform var(--t-med), border-color var(--t-med);
}
/* Hairline accent that fills in on hover — movement without the card jumping. */
.stat-card::after {
    content: "";
    position: absolute; inset: auto 0 0 0; height: 2px;
    background: linear-gradient(90deg, var(--brand-500), var(--accent-500));
    transform: scaleX(0);
    transform-origin: left;
    transition: transform var(--t-med);
}
.stat-card:hover { box-shadow: var(--sh-2); transform: translateY(-2px); border-color: var(--brand-200); }
.stat-card:hover::after { transform: scaleX(1); }
.stat-card:hover .stat-icon { background: var(--primary); color: var(--on-primary); }
.stat-card > div { min-width: 0; }
.stat-card small {
    color: var(--muted); font-weight: 600; font-size: 11px;
    letter-spacing: .04em; text-transform: uppercase;
}
.stat-card strong {
    display: block; margin-top: 6px;
    font-size: 27px; font-weight: 650; letter-spacing: -.03em;
    font-variant-numeric: tabular-nums;
}
.stat-icon {
    display: grid; place-items: center;
    width: 44px; height: 44px; flex: 0 0 44px;
    border-radius: var(--r-lg);
    background: var(--wash);
    color: var(--primary);
    font-size: 19px;
    transition: background var(--t-med), color var(--t-med);
}
/* Inline SVG icons render at 17px for the sidebar; scale them up in a stat tile. */
.stat-icon svg { width: 21px; height: 21px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.progress-row {
    display: grid; grid-template-columns: 130px minmax(0, 1fr) 36px;
    gap: 12px; align-items: center; margin: 14px 0; font-size: 12px;
}
.progress { height: 8px; background: var(--surface-3); border-radius: var(--r-pill); overflow: hidden; }
.progress > span {
    display: block; height: 100%;
    background: linear-gradient(90deg, var(--brand-500), var(--accent-500));
    border-radius: var(--r-pill);
    transition: width var(--t-med);
}

.patient-summary { display: flex; gap: 26px; align-items: center; flex-wrap: wrap; }
.patient-summary .avatar { width: 54px; height: 54px; flex-basis: 54px; font-size: 18px; }

.meta { display: flex; gap: 26px; flex-wrap: wrap; }
.meta div { font-size: 11.5px; color: var(--muted); }
.meta b { display: block; color: var(--text); margin-top: 3px; font-size: 13px; }

.client-contact { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.client-contact a {
    padding: 8px 13px; border-radius: var(--r-md);
    background: var(--wash); color: var(--primary); font-weight: 600; font-size: 13px;
    transition: background var(--t-fast);
}
.client-contact a:hover { background: var(--wash-2); }
.client-history .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 22px 0; }
.profile-grid > div {
    display: grid; gap: 4px; padding: 15px;
    border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2);
}
.profile-grid span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }

.lab-profile-card { max-width: 900px; }
.lab-profile-hero {
    display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
    padding-bottom: 22px; border-bottom: 1px solid var(--line);
}
.lab-profile-hero .logo-tile {
    display: grid; place-items: center;
    width: 108px; height: 108px; flex: 0 0 108px;
    border-radius: var(--r-xl); background: var(--logo-tile);
}
.lab-profile-hero img { width: 88px; height: 88px; object-fit: contain; }
.lab-profile-hero h2 { margin: 0 0 5px; font-size: 26px; }
.lab-profile-hero p { margin: 0; color: var(--muted); }

/* ---------- 15. Responsive ----------------------------------------------- */
@media (max-width: 1200px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .span-3 { grid-column: span 2; }
    .permission-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1024px) {
    :root { --sidebar-w: 224px; }
    .app-shell { padding: 20px 20px 48px; }
    .filters { grid-template-columns: minmax(0, 1fr) 1fr; }
}

/* Below 900px the sidebar becomes an off-canvas drawer driven by #nav-toggle. */
@media (max-width: 900px) {
    .app-layout { grid-template-columns: minmax(0, 1fr); }

    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(var(--sidebar-w), 84vw);
        transform: translateX(-102%);
        transition: transform var(--t-med);
        box-shadow: var(--sh-4);
        z-index: 60;
    }
    .nav-toggle:checked ~ .app-layout .app-sidebar { transform: none; }

    .nav-scrim {
        display: block;
        position: fixed; inset: 0; z-index: 50;
        background: rgba(10, 26, 43, .5);
        opacity: 0; visibility: hidden;
        transition: opacity var(--t-med), visibility var(--t-med);
    }
    .nav-toggle:checked ~ .app-layout .nav-scrim { opacity: 1; visibility: visible; }

    .nav-toggle-label { display: grid; }

    .app-shell { padding: 18px 15px 48px; }
    .app-footer { padding: 14px 15px; }
    .topbar { padding: 0 14px; gap: 10px; }
    .topbar-context { display: none; }
    .user-chip > span:last-child { display: none; }
    .user-chip { padding: 4px; }

    .page-heading { padding: 20px; border-radius: var(--r-lg); }
    .page-heading h1 { font-size: 21px; }
    .page-heading::after { display: none; }

    .form-grid, .permission-grid, .filters, .profile-grid { grid-template-columns: minmax(0, 1fr); }
    .span-2, .span-3 { grid-column: span 1; }
    .client-history .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .logo-upload { flex-direction: column; align-items: flex-start; }
    .progress-row { grid-template-columns: 100px minmax(0, 1fr) 32px; }
}

@media (max-width: 560px) {
    .stat-grid, .client-history .stat-grid { grid-template-columns: minmax(0, 1fr); }
    .booking-tests-header { align-items: stretch; }
    .booking-tests-actions { justify-content: stretch; }
    .booking-tests-actions .badge { width: 100%; text-align: center; }
    .booking-tests-actions .btn { flex: 1; }
    .form-actions { justify-content: stretch; }
    .form-actions > * { flex: 1; }
    .quick-create span { display: none; }
    .patients-grid-footer, .patients-grid-controls, .standard-grid-footer, .standard-grid-controls { align-items: stretch; flex-direction: column; }
    .patients-grid-controls label, .patients-pagination, .standard-grid-controls label, .standard-pagination { justify-content: space-between; }
}

/* ---------- 16. Print ---------------------------------------------------- */
@page { size: A4 portrait; margin: 8mm 9mm 27mm; }

@media print {
    :root {
        color-scheme: light !important;
        --bg: #ffffff !important;
        --surface: #ffffff !important;
        --surface-2: #ffffff !important;
        --surface-3: #f4f7fa !important;
        --line: #cbd5e1 !important;
        --line-soft: #e2e8f0 !important;
        --text: #111827 !important;
        --text-2: #26313f !important;
        --muted: #5f6d7c !important;
    }

    html, body {
        direction: ltr !important;
        text-align: left;
        width: auto !important; height: auto !important; min-height: 0 !important;
        background: #fff !important; color: #000;
        font-size: 10px;
    }

    .app-sidebar, .topbar, .app-footer, .nav-scrim, .nav-toggle-label,
    .no-print, .actions, .form-actions, .tabs, #blazor-error-ui,
    .standard-report aside, .comparative-report aside { display: none !important; }

    .app-layout { display: block !important; }
    .app-main { display: block !important; min-height: 0 !important; }
    .app-shell, .public-shell, .shared-report-sheet {
        direction: ltr !important;
        padding: 0 !important; margin: 0 !important;
        width: auto !important; max-width: none !important;
        min-height: 0 !important; height: auto !important;
    }

    .panel { border: 0 !important; box-shadow: none !important; margin: 0 !important; background: #fff !important; color: #111827 !important; }
    .panel-body { padding: 0 !important; background: #fff !important; color: #111827 !important; }
    .panel-header { background: #fff !important; color: #111827 !important; }
    .patient-print-summary, .patient-summary, .test-report-block, .dynamic-report-section, .table-wrap, table, thead, tbody, tr, th, td {
        background: #fff !important; color: #111827 !important;
    }
    th, td { border-color: #cbd5e1 !important; }
    a { color: #000 !important; }
    table { font-size: 11px; }
    tbody tr:hover { background: none !important; }

    .print-header {
        display: block !important;
        text-align: center;
        padding: 0 0 5px !important;
        margin: 0 0 5px !important;
        border-bottom: 1px solid #222 !important;
    }
    .print-header > p { margin: 3px 0 0; font-size: 11px; font-weight: 700; }
    .print-logo {
        width: 60px !important; height: 55px !important;
        padding: 0 !important; margin: 0 auto !important;
        background: transparent !important; border-radius: 0 !important;
    }

    .patient-print-summary {
        margin: 0 0 5px !important; padding: 0 0 4px !important;
        border-bottom: 1px solid #222 !important;
    }
    .patient-print-summary .patient-summary {
        display: grid; grid-template-columns: 150px 1fr; gap: 8px; padding: 2px 0 !important;
    }
    .patient-print-summary h2 { font-size: 11px !important; margin: 0 !important; }

    .classic-report-head { grid-template-columns: 65px 1fr auto !important; gap: 8px !important; }
    .classic-report-head h1 { font-size: 16px; margin: 0 0 2px; }
    .report-contact { font-size: 8px; line-height: 1.25; gap: 3px 10px; }
    .report-identifiers { gap: 5px; grid-column: auto; }
    .report-barcode { width: 118px; height: 37px; }
    .report-qr { width: 39px !important; height: 39px !important; }
    .report-code small { font-size: 7px; }

    .legacy-patient-grid .meta {
        display: grid !important; grid-template-columns: repeat(3, 1fr) !important; gap: 2px 10px !important;
    }
    .legacy-patient-grid .meta > div { font-size: 8px; }
    .legacy-patient-grid .meta b { display: block; font-size: 9px; margin-top: 0; }

    .dashboard-grid, .invoice-grid { display: block !important; }
    .invoice-party { border-bottom: 1px solid #333; }

    .standard-report > section.panel, .comparative-report > section.panel { margin: 0 !important; }
    .standard-report .panel-header, .comparative-report .panel-header {
        padding: 3px 0 !important; min-height: 0; border-bottom: 1px solid #222;
    }
    .standard-report .panel-header h2, .comparative-report .panel-header h2 { font-size: 10px; }
    .standard-report .panel-body, .comparative-report .panel-body { padding: 0 !important; }

    .test-report-block { margin: 0 0 5px !important; break-inside: auto !important; page-break-inside: auto !important; }
    .test-report-title { padding: 3px 0 !important; border-bottom: 1px solid #333 !important; font-size: 10px; }
    .test-report-block table { margin: 0; font-size: 8.5px; line-height: 1.15; }
    .test-report-block th { padding: 3px 5px !important; font-size: 7.5px; background: none !important; }
    .test-report-block td { padding: 3px 5px !important; }
    .test-report-block tr { break-inside: avoid; }
    .test-report-block small { font-size: 7.5px; }
    .report-remark, .test-report-block .alert { padding: 3px 5px !important; margin: 2px 0 !important; font-size: 8px; }
    .badge, .status-badge { padding: 1px 5px; font-size: 7px; }

    .report-final-footer {
        position: fixed; left: 0; right: 0; bottom: 0;
        margin: 0 !important; background: #fff; break-inside: avoid;
    }
    .signatory-grid { grid-template-columns: repeat(4, 1fr); gap: 8px !important; }
    .signatory-grid article { min-height: 0 !important; font-size: 7.5px !important; line-height: 1.12; }
    .signatory-grid img { height: 25px !important; }
    .report-disclaimer { font-size: 6.5px !important; margin-top: 3px !important; padding-top: 2px !important; }

    .receipt-sheet { border: 0; box-shadow: none; max-width: none; padding: 20px; }
    .configured-page-break { break-before: page; page-break-before: always; }
}

/* User-friendly Select parameter option builder */
.select-options-editor{margin-top:8px;padding:10px;border:1px solid var(--border);border-radius:10px;background:var(--surface-soft,#f8fafc);min-width:360px}
.select-options-add{display:grid;grid-template-columns:minmax(150px,1fr) auto;gap:7px;align-items:center}
.select-options-error{display:block;margin-top:7px;color:var(--danger,#b42318);font-weight:700}
.select-options-empty{margin-top:8px;padding:10px;text-align:center;color:var(--muted);border:1px dashed var(--border);border-radius:8px}
.select-options-list{display:grid;gap:6px;margin-top:9px}
.select-option-row{display:grid;grid-template-columns:28px minmax(135px,1fr) auto;gap:7px;align-items:center;padding:7px;background:var(--surface);border:1px solid var(--border);border-radius:8px}
.select-option-number{display:grid;place-items:center;width:24px;height:24px;border-radius:50%;background:var(--primary-soft,#e7f1fb);color:var(--primary);font-weight:800}
.select-option-actions{display:flex;align-items:center;gap:5px;white-space:nowrap}
.select-options-preview{display:grid;grid-template-columns:auto minmax(150px,1fr) auto;gap:8px;align-items:center;margin-top:9px;padding-top:9px;border-top:1px solid var(--border)}
.select-options-preview>span{font-size:.78rem;font-weight:800;color:var(--muted)}
@media(max-width:900px){.select-options-editor{min-width:260px}.select-options-add{grid-template-columns:1fr}.select-option-row{grid-template-columns:28px 1fr}.select-option-actions{grid-column:2;flex-wrap:wrap}.select-options-preview{grid-template-columns:1fr}.select-options-preview>span{display:block}}
.reference-range-editor{margin-top:6px;padding:10px;border:1px solid var(--border);border-radius:10px;background:var(--surface-soft,#f8fafc);min-width:300px}
.reference-range-editor>label:not(.check){display:block;margin-top:6px;font-size:.72rem;font-weight:800;color:var(--muted)}
.reference-range-editor input,.reference-range-editor select,.reference-range-editor textarea{width:100%}
.reference-range-editor .range-switch{display:inline-flex;align-items:center;gap:8px;width:auto;margin:9px 0 4px;padding:0;cursor:pointer;color:var(--text);font-size:.75rem;font-weight:750;line-height:1.2}
.reference-range-editor .range-switch input{position:absolute;opacity:0;width:1px!important;height:1px;margin:0;pointer-events:none}
.reference-range-editor .range-switch-track{position:relative;display:inline-block;flex:0 0 34px;width:34px;height:19px;border:1px solid var(--border-strong,var(--border));border-radius:999px;background:var(--surface);transition:.18s ease}
.reference-range-editor .range-switch-track::after{content:"";position:absolute;top:2px;left:2px;width:13px;height:13px;border-radius:50%;background:var(--muted);transition:.18s ease}
.reference-range-editor .range-switch input:checked+.range-switch-track{border-color:var(--brand-600);background:var(--brand-600)}
.reference-range-editor .range-switch input:checked+.range-switch-track::after{left:17px;background:#fff}
.reference-range-editor .range-switch input:focus-visible+.range-switch-track{outline:3px solid color-mix(in srgb,var(--brand-500) 28%,transparent);outline-offset:2px}
.range-value-grid{display:grid;grid-template-columns:1fr 1fr;gap:7px;margin-top:6px}
.range-value-grid label{font-size:.69rem;font-weight:800;color:var(--muted)}
.range-gender-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:7px}
.range-gender-card{padding:8px;border:1px solid var(--border);border-radius:8px;background:var(--surface)}
.range-gender-card strong{font-size:.76rem;color:var(--brand-700)}
.range-advanced{margin-top:9px;border-top:1px solid var(--border);padding-top:8px}
.range-advanced summary{cursor:pointer;font-size:.75rem;font-weight:800;color:var(--brand-700)}
.range-advanced textarea{margin-top:7px}
.range-advanced small{display:block;color:var(--muted);line-height:1.35}
@media(max-width:900px){.reference-range-editor{min-width:250px}.range-gender-grid,.range-value-grid{grid-template-columns:1fr}}
.patient-age-entry{display:grid;grid-template-columns:repeat(3,minmax(72px,1fr));gap:7px}
.patient-age-entry>div{position:relative}
.patient-age-entry input{padding-right:27px;text-align:center}
.patient-age-entry span{position:absolute;right:8px;top:50%;transform:translateY(-50%);font-size:.65rem;font-weight:800;color:var(--muted);pointer-events:none}
@media(max-width:640px){.patient-age-entry{grid-template-columns:1fr}.patient-age-entry input{text-align:left}.patient-age-entry span{font-size:.72rem}}
.age-rule-builder{margin-top:8px}
.age-rule-toolbar{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:9px;border:1px solid var(--border);border-radius:8px;background:var(--surface)}
.age-rule-toolbar>div{display:grid;gap:2px}.age-rule-toolbar strong{font-size:.78rem;color:var(--brand-800)}.age-rule-toolbar small{font-size:.68rem;color:var(--muted);line-height:1.3}
.age-rule-empty{display:grid;gap:3px;margin-top:7px;padding:12px;text-align:center;border:1px dashed var(--border);border-radius:8px;color:var(--muted)}.age-rule-empty b{font-size:.75rem}.age-rule-empty span{font-size:.68rem}
.age-rule-list{display:grid;gap:8px;margin-top:8px}.age-rule-card{padding:9px;border:1px solid var(--border);border-radius:9px;background:var(--surface)}
.age-rule-card-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:7px}.age-rule-card-head strong{font-size:.76rem;color:var(--brand-700)}
.age-rule-grid{display:grid;grid-template-columns:110px 1fr 1fr;gap:7px}.age-rule-grid>div>label{display:block;margin-bottom:3px;font-size:.67rem;font-weight:800;color:var(--muted)}.age-rule-grid label small{font-weight:600}
.age-rule-grid input,.age-rule-grid select{min-height:32px!important;margin:0!important}.age-rule-age>div{display:grid;grid-template-columns:repeat(3,1fr);gap:4px}.age-rule-age input{text-align:center;padding:5px!important}
.age-rule-label{grid-column:1/-1}.age-rule-preview{display:block;margin-top:7px;padding-top:6px;border-top:1px solid var(--border);font-size:.68rem;color:var(--muted)}
@media(max-width:1100px){.age-rule-grid{grid-template-columns:1fr 1fr}.age-rule-label{grid-column:1/-1}}@media(max-width:700px){.age-rule-toolbar{align-items:flex-start;flex-direction:column}.age-rule-grid{grid-template-columns:1fr}.age-rule-label{grid-column:auto}}
.interpretation-rule-builder{margin-top:8px}.interpretation-rule-grid{display:grid;grid-template-columns:1.15fr .8fr 1.15fr .9fr;gap:7px}.interpretation-rule-grid>div>label{display:block;margin-bottom:3px;font-size:.67rem;font-weight:800;color:var(--muted)}.interpretation-rule-grid input,.interpretation-rule-grid select{min-height:32px!important;margin:0!important}.interpretation-rule-note{margin-top:8px;padding:8px 10px;border-radius:7px;background:var(--brand-50);color:var(--brand-800);font-size:.68rem;line-height:1.4}.interpretation-rule-card .age-rule-preview b{color:var(--brand-800)}
@media(max-width:1200px){.interpretation-rule-grid{grid-template-columns:1fr 1fr}}@media(max-width:700px){.interpretation-rule-grid{grid-template-columns:1fr}}
