/* Doctors Lab – SOM (Send Out Manager)
   Components are KinetiqPortal's / KinetiqRCM's (same --dlp-* tokens, same markup classes) so the
   products read as one family. SOM is dark mode only: the dark token set is the only one, and the
   layout always renders data-theme="dark". */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root,
[data-theme="dark"] {
    color-scheme: dark;
    --dlp-bg: linear-gradient(135deg, #1a1d23 0%, #2c3340 100%);
    --dlp-surface: #252a33;
    --dlp-surface-2: #2a303a;
    --dlp-surface-3: #2e3540;
    --dlp-text: #e8eaed;
    --dlp-text-muted: #b0b8c4;
    --dlp-heading: #f0f2f5;
    --dlp-border: #3d4450;
    --dlp-border-soft: #454d5c;
    --dlp-primary: #5ba3f0;
    --dlp-primary-hover: #7bb6f5;
    --dlp-nav-hover-bg: #323843;
    --dlp-input-bg: #1e2229;
    --dlp-input-border: #4a5160;
    --dlp-shadow: rgba(0, 0, 0, 0.45);
    --dlp-badge-bg: #1e3a54;
    --dlp-badge-text: #9ec9ef;
    --dlp-table-header: #2f3540;
    --dlp-table-row: #252a33;
    --dlp-modal-overlay: rgba(0, 0, 0, 0.65);
    --dlp-tab-bg: #323843;
    --dlp-tab-active-bg: #1e3a54;
    --dlp-tab-active-text: #9ec9ef;
    --dlp-locked-bg: #323843;
    /* The light values are unreadable on a dark surface, and a status colour that cannot be read
       is worse than none: it looks deliberate. */
    --dlp-ok-bg: #1d3a28;
    --dlp-ok-text: #86d6a0;
    --dlp-warn-bg: #3d3320;
    --dlp-warn-text: #e8c86a;
}

/* ---- layout and components (from KinetiqRCM / KinetiqPortal) ---- */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--dlp-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--dlp-text);
    line-height: 1.6;
}

/* --- header ---
   position/z-index so the menus opening out of it paint over the page rather than under it. */
header {
    background: var(--dlp-surface);
    box-shadow: 0 2px 10px var(--dlp-shadow);
    position: relative;
    z-index: 10;
}

.header-container {
    max-width: 1600px; margin: 0 auto; padding: 0.9rem 1.5rem;
    display: flex; justify-content: space-between; align-items: center;
    gap: 1.5rem; flex-wrap: wrap;
}

.brand { display: inline-flex; align-items: center; text-decoration: none; min-width: 0; }
/* Only one of the pair is ever shown, chosen by the theme the document is in. */
.logo-dark-only { display: none; }
[data-theme="dark"] .logo-light-only { display: none; }
/* Each one is restored to its own display rather than a shared one. A single
   `display: inline-block` here un-centred the sign-in logo, which is centred by `margin: 0 auto`
   — and auto margins do nothing to an inline-block. */
[data-theme="dark"] .logo.logo-dark-only { display: inline-block; }
[data-theme="dark"] .login-logo.logo-dark-only { display: block; }
.logo { max-height: 52px; width: auto; }

/* Sits between the logo and the menu and says what the product is. Two centred lines so it keeps
   the bar's height rather than stretching it. */
.brand-tagline {
    color: var(--dlp-text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    letter-spacing: 0.02em;
    padding-left: 1rem;
    margin-left: 0.25rem;
    border-left: 1px solid var(--dlp-border);
    white-space: nowrap;
}

.header-user { display: flex; align-items: center; gap: 0.6rem; flex-wrap: nowrap; margin-left: auto; }
.welcome-text { color: var(--dlp-text-muted); font-weight: 500; }
.inline-form { display: inline; margin: 0; }

.location-badge {
    background: var(--dlp-badge-bg); color: var(--dlp-badge-text);
    padding: 0.35rem 0.75rem; border-radius: 999px;
    font-size: 0.85rem; font-weight: 500;
}

/* --- header buttons and account menu (ported from KinetiqPortal) --- */
.header-btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    height: 2.25rem; padding: 0 0.9rem; box-sizing: border-box; white-space: nowrap;
}
.header-btn-icon {
    width: 1.05rem; height: 1.05rem; flex-shrink: 0;
    fill: none; stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
}
.header-logout-form { margin: 0; }

.account-menu { position: relative; }
.account-menu-toggle {
    background: none; border: none; cursor: pointer; font: inherit;
    padding: 0.35rem 0.5rem; border-radius: 5px; color: var(--dlp-text-muted); font-weight: 500;
}
.account-menu:hover .account-menu-toggle,
.account-menu:focus-within .account-menu-toggle { background: var(--dlp-nav-hover-bg); }
.account-menu-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 0.35rem);
    min-width: 12rem;
    background: var(--dlp-surface);
    border: 1px solid var(--dlp-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--dlp-shadow);
    z-index: 1000;
    padding: 0.35rem 0;
    display: none;
}
/* The Portal toggles this with a click handler; here it opens on hover and stays open for the
   keyboard, which is the same rule the nav groups use and needs no script. */
.account-menu:hover .account-menu-dropdown,
.account-menu:focus-within .account-menu-dropdown { display: block; }
.account-menu-dropdown a,
.account-menu-dropdown button {
    display: block; width: 100%; text-align: left;
    padding: 0.55rem 1rem; color: var(--dlp-text); text-decoration: none;
    background: none; border: none; font: inherit; cursor: pointer;
}
.account-menu-dropdown a:hover,
.account-menu-dropdown button:hover { background: var(--dlp-nav-hover-bg); }
.account-menu-dropdown form { margin: 0; }

/* --- main nav ---
   In the top bar beside the logo, as the Portal has it. The Portal's is a flat row because it has
   seven destinations; this one has nineteen, so the same row would fill the bar and push the
   account menu off it. They are folded into the three groups the navigation already declares, and
   each group opens on hover — the look of the item and of the dropdown is the Portal's, taken
   from its account menu.

   flex: 1 1 auto gives the nav the middle of the bar and keeps the user block hard right, which
   is what stops the two drifting into each other as the window narrows. */
.header-nav {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: wrap;
    flex: 1 1 auto;
}
.nav-link {
    color: var(--dlp-heading); text-decoration: none; font-weight: 500;
    padding: 0.5rem 1rem; border-radius: 5px; font-size: 0.9rem; white-space: nowrap;
    display: inline-block;
}
.nav-link:hover { background: var(--dlp-nav-hover-bg); color: var(--dlp-primary); }
.nav-link.active {
    background: var(--dlp-tab-active-bg); color: var(--dlp-tab-active-text); font-weight: 600;
}

.nav-group { position: relative; }
.nav-group-toggle {
    font: inherit; font-size: 0.9rem; font-weight: 500;
    color: var(--dlp-heading); background: none; border: none; cursor: pointer;
    padding: 0.5rem 1rem; border-radius: 5px; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 0.35rem;
}
.nav-group-toggle::after {
    content: "▾";
    font-size: 0.7em;
    opacity: 0.7;
}
.nav-group:hover .nav-group-toggle,
.nav-group:focus-within .nav-group-toggle { background: var(--dlp-nav-hover-bg); color: var(--dlp-primary); }
.nav-group.active .nav-group-toggle {
    background: var(--dlp-tab-active-bg); color: var(--dlp-tab-active-text); font-weight: 600;
}

.nav-dropdown {
    position: absolute;
    left: 0;
    top: 100%;
    min-width: 16rem;
    background: var(--dlp-surface);
    border: 1px solid var(--dlp-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--dlp-shadow);
    z-index: 1000;
    padding: 0.35rem 0;
    display: none;
}
/* Hover opens it; focus-within keeps it open for the keyboard, and makes a tap work on a
   touchscreen, where hover never fires at all. */
.nav-group:hover .nav-dropdown,
.nav-group:focus-within .nav-dropdown { display: block; }
.nav-dropdown a {
    display: block;
    padding: 0.55rem 1rem;
    color: var(--dlp-text);
    text-decoration: none;
    font-size: 0.9rem;
    white-space: nowrap;
}
.nav-dropdown a:hover { background: var(--dlp-nav-hover-bg); color: var(--dlp-primary); }
.nav-dropdown a.active { color: var(--dlp-tab-active-text); font-weight: 600; }
/* A section with no controller behind it yet goes to a placeholder. Dimming it says so before
   the click rather than after. */
.nav-dropdown a.pending { color: var(--dlp-text-muted); }
.nav-dropdown a.pending::after { content: " · planned"; font-size: 0.8em; opacity: 0.7; }

/* --- page --- */
main { flex: 1; padding: 2rem 0; }
.page-container { max-width: 1600px; margin: 0 auto; padding: 0 1.5rem; }

.page-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.page-header h1 { color: var(--dlp-heading); font-size: 1.7rem; margin: 0; }
.page-header .lede { color: var(--dlp-text-muted); margin: 0.35rem 0 0; max-width: 70ch; }
.page-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.section-title {
    color: var(--dlp-heading); font-size: 1.1rem; font-weight: 600;
    margin: 1.75rem 0 0.85rem; padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--dlp-border-soft);
}

/* --- buttons --- */
.logout-btn, .btn {
    border: none; padding: 0.5rem 1.25rem; border-radius: 5px; cursor: pointer;
    font-size: 0.95rem; font-weight: 500; text-decoration: none; display: inline-block;
    font-family: inherit;
}
.logout-btn { background: #dc3545; color: #fff; }
.logout-btn:hover { background: #c82333; }
.btn-primary { background: var(--dlp-primary); color: #fff; }
.btn-primary:hover { background: var(--dlp-primary-hover); }
.btn-outline { background: var(--dlp-surface); color: var(--dlp-primary); border: 1px solid var(--dlp-primary); }
.btn-outline:hover { background: var(--dlp-nav-hover-bg); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* --- cards --- */
.dashboard-cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem; margin-top: 1rem;
}
.dashboard-card {
    background: var(--dlp-surface-2); border: 1px solid var(--dlp-border);
    border-radius: 8px; padding: 1.15rem 1.25rem; text-decoration: none; display: block;
    color: inherit;
}
a.dashboard-card:hover { border-color: var(--dlp-primary); background: var(--dlp-surface-3); }
.dashboard-card h3 { color: var(--dlp-heading); margin: 0 0 0.4rem; font-size: 1rem; }
.dashboard-card p { margin: 0; }

/* --- panels and alerts --- */
.info-panel {
    margin: 1rem 0 1.5rem; padding: 1rem 1.25rem;
    background: var(--dlp-surface); border: 1px solid var(--dlp-border); border-radius: 6px;
}
.info-panel.accent { border-left: 3px solid var(--dlp-primary); }
.info-panel p { margin: 0.35rem 0; }

.alert-error {
    background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb;
    border-radius: 6px; padding: 0.75rem 1rem; margin-bottom: 1rem;
}
[data-theme="dark"] .alert-error { background: #3a1e20; color: #f5a3a9; border-color: #5c2a2e; }

.status-badge {
    display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px;
    font-size: 0.78rem; font-weight: 600;
    background: var(--dlp-badge-bg); color: var(--dlp-badge-text);
}
.status-badge-warning { background: var(--dlp-warn-bg); color: var(--dlp-warn-text); }
[data-theme="dark"] .status-badge-warning { background: #3a3119; color: #fcd34d; }

/* --- forms --- */
.form-group { margin-bottom: 0.9rem; }
.form-label { display: block; margin-bottom: 0.3rem; font-weight: 500; color: var(--dlp-heading); font-size: 0.9rem; }
/* .form-input's own metrics and focus ring live with the other fields, further down, so there is
   one definition of what a field looks like rather than two that drift. */
.form-actions { margin-top: 1.15rem; }
.field-error { color: #dc3545; font-size: 0.85rem; display: block; margin-top: 0.25rem; }
[data-theme="dark"] .field-error { color: #f87171; }

/* --- login --- */
.login-wrap { display: flex; justify-content: center; align-items: flex-start; padding: 3rem 0; }
/* The Portal's .login-container, to the pixel. */
.login-card {
    background: var(--dlp-surface);
    border-radius: 10px; box-shadow: 0 5px 20px var(--dlp-shadow);
    padding: 2.5rem; width: 100%; max-width: 480px;
    color: var(--dlp-text);
}
.login-logo { display: block; max-width: 260px; width: 100%; height: auto; margin: 0 auto 0.35rem; }
.login-sub { text-align: center; color: var(--dlp-text-muted); font-size: 1.05rem; margin: 0 0 1.5rem; }
/* The environment is the one thing worth saying on a sign-in page: which server am I on. */
.login-environment { text-align: center; margin-top: 1.5rem; }
.environment-badge {
    display: inline-block;
    background: var(--dlp-badge-bg);
    color: var(--dlp-badge-text);
    border-radius: 999px;
    padding: 0.5rem 1.25rem;
    font-size: 1.05rem;
    font-weight: 600;
}

.login-note {
    margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--dlp-border);
    font-size: 0.83rem; color: var(--dlp-text-muted);
}

/* --- footer --- */
footer { border-top: 1px solid var(--dlp-border); background: var(--dlp-surface); padding: 1rem 0; }
.footer-inner { display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap; font-size: 0.85rem; color: var(--dlp-text-muted); text-align: center; }

/* --- content links ---
   RCM had no anchor rule at all, so every link in a table or a panel rendered browser-default
   blue — unreadable on a dark surface and the single loudest difference between one of these
   pages and a Portal page. The Portal's own rule and token are used here, applied in both themes
   rather than only in dark: default blue is the absence of a choice rather than a choice, and the
   two products sitting side by side is the thing being fixed. Underlining stays dark-only, as it
   is there. Buttons and navigation keep their own colours. */
.data-table a:not(.btn),
.card a:not(.btn),
.content-card a:not(.btn),
.info-panel a:not(.btn),
.entry a:not(.btn),
.form-section a:not(.btn),
footer a:not(.btn) { color: var(--dlp-primary); }

.data-table a:not(.btn):hover,
.card a:not(.btn):hover,
.content-card a:not(.btn):hover,
.info-panel a:not(.btn):hover,
.entry a:not(.btn):hover,
.form-section a:not(.btn):hover,
footer a:not(.btn):hover { color: var(--dlp-primary-hover); }

[data-theme="dark"] .data-table a:not(.btn),
[data-theme="dark"] table a:not(.btn),
[data-theme="dark"] .card a:not(.btn),
[data-theme="dark"] .content-card a:not(.btn) { text-decoration: underline; }

[data-theme="dark"] a.btn { text-decoration: none; }

/* --- utility --- */
.muted { color: var(--dlp-text-muted); }
.small { font-size: 0.875rem; }
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: var(--dlp-surface-2); border: 1px solid var(--dlp-border);
    border-radius: 3px; padding: 0.08em 0.35em; font-size: 0.86em;
}

@media (max-width: 1100px) {
    /* The first thing to give up room when the bar tightens: the menu and the account are both
       more use than a subtitle. */
    .brand-tagline { display: none; }
}

@media (max-width: 860px) {
    /* The bar runs out of room, so the nav drops onto its own line under the logo and the groups
       become stacked sections: an absolutely positioned dropdown has nowhere to go on a narrow
       screen. They stay open once tapped. */
    .header-nav {
        flex: 1 0 100%;
        order: 3;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        border-top: 1px solid var(--dlp-border);
        margin-top: 0.5rem;
        padding-top: 0.35rem;
    }
    .nav-group-toggle { width: 100%; text-align: left; justify-content: space-between; }
    .nav-dropdown {
        position: static;
        min-width: 0;
        border: none;
        border-left: 2px solid var(--dlp-border);
        border-radius: 0;
        box-shadow: none;
        margin: 0 0 0.35rem 1rem;
        padding: 0;
    }
    .nav-dropdown a { white-space: normal; }
}

@media (max-width: 640px) {
    .header-container, .page-container { padding-left: 1rem; padding-right: 1rem; }
    .logo { max-height: 40px; }
    .page-header-stats { width: 100%; justify-content: flex-start; }
}

/* --- reference data --- */
.pager {
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem; flex-wrap: wrap; margin-top: 0.9rem;
}
.pager-links { display: inline-flex; gap: 0.6rem; align-items: center; }

.dashboard-card .stat {
    display: block; font-size: 1.7rem; font-weight: 700; color: var(--dlp-heading);
    font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 0.2rem;
}
.dashboard-card .stat-label { display: block; font-size: 0.82rem; color: var(--dlp-text-muted); }

.import-log {
    margin: 0.6rem 0 0; padding: 0.6rem 0.8rem; border-radius: 5px;
    background: var(--dlp-surface-2); border: 1px solid var(--dlp-border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem; white-space: pre-wrap; overflow-x: auto;
}

.status-badge-ok { background: var(--dlp-ok-bg); color: var(--dlp-ok-text); }
[data-theme="dark"] .status-badge-ok { background: #16301f; color: #4ade80; }

/* --- tables (ported from KinetiqPortal) ---
   The base rules were missing entirely, which is why rows had no definition: no cell borders, no
   header band and no hover. Ported verbatim so a table reads the same in both products. The Portal
   stripes alternate rows in dark mode only — in light mode the border and the hover do the work —
   and that is kept rather than "improved", because the two applications sitting side by side with
   different table rhythms is the thing being fixed. */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--dlp-surface);
    color: var(--dlp-text);
}
.data-table th,
.data-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--dlp-border);
    font-size: 0.925rem;
    vertical-align: middle;
}
.data-table-compact th,
.data-table-compact td { padding: 0.4rem 0.65rem; }
.data-table th {
    background: var(--dlp-table-header);
    font-weight: 600;
    color: var(--dlp-heading);
}
.data-table thead th { border-bottom: 1px solid var(--dlp-border); }
/* Backgrounds go on the cells, not the row: a td background would otherwise paint over it. */
.data-table tbody tr:hover > td { background: var(--dlp-nav-hover-bg); }
.data-table tbody tr.row-stat > td { background: #fde8e8; }
.data-table tbody tr.row-stat:hover > td { background: #fad4d4; }
[data-theme="dark"] .data-table tbody tr:nth-child(even):not(.row-stat) > td { background: var(--dlp-surface-3); }
[data-theme="dark"] .data-table tbody tr:hover:not(.row-stat) > td { background: var(--dlp-nav-hover-bg); }
[data-theme="dark"] .data-table tbody tr.row-stat > td { background: #4a2328; }
[data-theme="dark"] .data-table tbody tr.row-stat:hover > td { background: #5d2b31; }

/* --- sortable headings (ported from KinetiqPortal) ---
   The arrow is on the heading and the whole label is the link, so the target is the width of the
   column rather than a glyph. Sorting is done by the server; see SortSpec for why. */
.data-table th.sortable { white-space: nowrap; }
.data-table th.sortable a {
    color: inherit;
    text-decoration: none;
    display: inline-block;
}
.data-table th.sortable a::after {
    content: "\2195";
    margin-left: 0.35rem;
    opacity: 0.35;
    font-size: 0.8em;
}
.data-table th.sortable.sort-asc a::after { content: "\25B2"; opacity: 0.9; }
.data-table th.sortable.sort-desc a::after { content: "\25BC"; opacity: 0.9; }
.data-table th.sortable a:hover,
.data-table th.sortable a:focus-visible { color: var(--dlp-primary); }
.data-table th.sortable.num a { float: right; }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* --- status tabs (ported from KinetiqPortal) --- */
.page-tabs {
    display: flex; flex-wrap: wrap; gap: 0.35rem;
    margin: 1rem 0 0.9rem; border-bottom: 1px solid var(--dlp-border);
}
.page-tab {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.5rem 0.85rem; border: 1px solid transparent; border-bottom: none;
    border-radius: 6px 6px 0 0; color: var(--dlp-text-muted);
    text-decoration: none; font-weight: 500; font-size: 0.9rem;
}
.page-tab:hover { color: var(--dlp-primary); background: var(--dlp-nav-hover-bg); }
.page-tab.active {
    color: var(--dlp-heading); background: var(--dlp-surface);
    border-color: var(--dlp-border); box-shadow: inset 0 -2px 0 var(--dlp-primary);
}
.page-tab-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 1.35rem; height: 1.35rem; padding: 0 0.35rem; border-radius: 999px;
    background: var(--dlp-primary); color: #fff; font-size: 0.72rem; font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.page-tab.active .page-tab-count { background: var(--dlp-primary); }

/* a right-aligned count column still needs room from the label beside it */
.data-table th.num, .data-table td.num { padding-left: 1.25rem; }

/* --- census day grid --- */
.day-grid th.day, .day-grid td.day {
    width: 1.5rem; min-width: 1.5rem; text-align: center;
    padding-left: 0.1rem; padding-right: 0.1rem; font-size: 0.75rem;
}
.day-grid td.glyph { font-weight: 600; color: var(--dlp-heading); }
.day-grid td.glyph.parta { background: var(--dlp-badge-bg); color: var(--dlp-badge-text); }
.day-grid td.glyph.unmapped { background: var(--dlp-warn-bg); color: var(--dlp-warn-text); }
[data-theme="dark"] .day-grid td.glyph.unmapped { background: #3a3119; color: #fcd34d; }
.map-form { align-items: center; gap: 0.4rem; margin: 0; }

/* Raw HL7 on the message page. Segment separators are rendered as line breaks, so the block is
   as wide as the longest segment — the pipes have to stay aligned to be readable at all. */
.raw-message {
    margin: 0;
    padding: 0.9rem 1rem;
    overflow-x: auto;
    font-family: var(--dlp-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: 0.78rem;
    line-height: 1.55;
    white-space: pre;
    tab-size: 4;
    background: var(--dlp-surface-sunken, var(--dlp-surface));
    border: 1px solid var(--dlp-border);
    border-radius: var(--dlp-radius-sm, 4px);
    color: var(--dlp-text);
}

/* Money columns line up only with tabular figures; a ledger that does not line up cannot be
   scanned, which is most of what anyone does with one. */
.money { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.money:has(> span) { text-align: right; }
.ledger-table tfoot th { border-top: 2px solid var(--dlp-border); font-weight: 600; }
.ledger-table tr.reversed td:not(:last-child) { text-decoration: line-through; opacity: 0.6; }

/* ---------------------------------------------------------------------------
   Panels, pills and forms used by the ledger, integrations, audit and census
   pages. These grew up with those pages and were being referenced before they
   were defined, which is why several sections rendered as bare markup.
   --------------------------------------------------------------------------- */

/* The Portal's page panel is .content-card: a soft shadow and a 10px radius, no border. Both
   names resolve to it so a view written against either reads the same. */
.card,
.content-card {
    background: var(--dlp-surface);
    border-radius: 10px;
    box-shadow: 0 5px 20px var(--dlp-shadow);
    padding: 1.25rem 1.5rem;
    margin: 0 0 1.25rem;
    color: var(--dlp-text);
}
.card > .table-wrap { margin-top: 0.75rem; }
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.4rem;
}
.card-header h2 { color: var(--dlp-heading); font-size: 1.1rem; margin: 0; }
.card-header-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
    gap: 1.25rem;
    align-items: start;
}
.card-grid > .card { margin: 0; }

/* A <details class="card"> keeps a destructive or occasional form out of the way without
   hiding that it exists. */
details.card > summary { cursor: pointer; list-style: revert; }
details.card > summary .inline-heading {
    display: inline;
    color: var(--dlp-heading);
    font-size: 1.1rem;
}
details.card > summary + * { margin-top: 0.85rem; }

.page-header-stats { display: flex; gap: 1.5rem; align-items: flex-start; }
.page-header-stats .stat { display: block; text-align: right; }
.stat-value {
    display: block;
    color: var(--dlp-heading);
    font-size: 1.45rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.page-header-stats .stat-label { display: block; font-size: 0.8rem; color: var(--dlp-text-muted); }

.info-panel.warn {
    border-left: 3px solid var(--dlp-warn-text);
    background: var(--dlp-warn-bg);
    color: var(--dlp-warn-text);
}
.info-panel.warn .muted { color: inherit; opacity: 0.85; }
.alert-warning {
    background: var(--dlp-warn-bg);
    color: var(--dlp-warn-text);
    border-radius: 4px;
    padding: 0.7rem 0.9rem;
    margin: 0 0 1rem;
}
.dashboard-card.flag { border-color: var(--dlp-warn-text); }

.pill {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    background: var(--dlp-badge-bg);
    color: var(--dlp-badge-text);
    white-space: nowrap;
}
.pill-ok { background: var(--dlp-ok-bg); color: var(--dlp-ok-text); }
.pill-warn { background: var(--dlp-warn-bg); color: var(--dlp-warn-text); }
.warn-text { color: var(--dlp-warn-text); font-weight: 600; }
.nowrap { white-space: nowrap; }

/* --- inputs (ported from KinetiqPortal) ---
   One set of metrics and one focus ring for every field, so a search box on a work queue and one
   on a form are the same control. The ring is the Portal's: a tinted halo rather than a browser
   outline, which is what made RCM's fields look unfinished next to it. */
.input,
.search-input,
.form-input,
.filter-form input[type="text"],
.filter-form input[type="search"],
.filter-form input[type="date"],
.filter-form select {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--dlp-input-border);
    border-radius: 5px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--dlp-input-bg);
    color: var(--dlp-text);
}
.input:focus,
.search-input:focus,
.form-input:focus,
.filter-form input:focus,
.filter-form select:focus {
    outline: none;
    border-color: var(--dlp-primary);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}
.search-input { margin-bottom: 0.75rem; }
.input-sm { width: auto; min-width: 10rem; padding: 0.4rem 0.6rem; font-size: 0.9rem; }

/* --- filter and search bars (ported from KinetiqPortal: .filter-form) --- */
.filter-bar,
.filter-form,
.ref-search,
.map-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem 1rem;
    margin: 0.75rem 0 1rem;
}
.filter-bar > label,
.filter-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
    color: var(--dlp-heading);
}
.filter-bar .input,
.filter-form input[type="text"],
.filter-form select { min-width: 10rem; }
/* A free-text box needs room for what people actually type into it; a select does not. */
.filter-bar input[type="text"],
.filter-bar input[type="search"],
.ref-search .form-input { min-width: 16rem; }
.input-search { min-width: 22rem; max-width: 100%; }
/* A bar is a row of controls, so its fields size to their content rather than filling the row. */
.filter-bar .input,
.filter-bar .input-sm,
.ref-search .form-input,
.map-form .input,
.map-form .input-sm,
.map-form .form-input { width: auto; }
/* The inline confirm row on a payer mapping sits in a table cell, so its fields stay small. */
.map-form .form-input,
.map-form .input,
.map-form .input-sm { min-width: 9rem; padding: 0.3rem 0.5rem; font-size: 0.85rem; }
.ref-search .form-input { max-width: 26rem; }

/* Labels carry their own field, so the grid lays out label-and-input pairs rather than needing a
   wrapper element around each one. */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 0.75rem 1rem;
    align-items: end;
    margin: 0.85rem 0 0;
}
.form-grid > label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--dlp-heading);
    font-weight: 500;
}
.form-grid-wide { grid-column: 1 / -1; }

/* An inner block within a panel: the Portal's .form-section. */
.entry,
.form-section {
    border: 1px solid var(--dlp-border);
    border-radius: 10px;
    padding: 0.85rem 1rem;
    margin: 0 0 1rem;
    background: var(--dlp-surface-3);
    color: var(--dlp-text);
}
.entry-header { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; }
.entry-header strong { color: var(--dlp-heading); }
.entry .table-wrap { margin-top: 0.5rem; }

/* A corrected cell must never pass for one that is on the printed page. */
.day-grid td.glyph.corrected { outline: 2px dashed var(--dlp-warn-text); outline-offset: -2px; }
.day-grid td.glyph.selected { box-shadow: inset 0 0 0 2px var(--dlp-primary); }
.day-grid td.glyph a { color: inherit; text-decoration: none; display: block; }
.day-grid td.glyph a:hover { text-decoration: underline; }

/* ===========================================================================
   SOM
   =========================================================================== */

/* The Doctors Lab mark is red and blue on transparent; on a dark surface it needs a light plate. */
.logo-plate {
    display: inline-flex; align-items: center; background: #fff; border-radius: 8px;
    padding: 0.45rem 0.8rem; box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}
.logo-plate img { display: block; height: 30px; width: auto; }
.login-card .logo-plate { padding: 0.8rem 1.2rem; margin: 0 auto 0.6rem; }
.login-card .logo-plate img { height: 40px; }
.login-logo-wrap { text-align: center; }
.brand-tagline { border-left-color: var(--dlp-border-soft); }

.nav-link .nav-count {
    display: inline-flex; align-items: center; justify-content: center; min-width: 1.3rem; height: 1.3rem;
    padding: 0 0.35rem; margin-left: 0.35rem; border-radius: 999px; background: #e8412c; color: #fff;
    font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.nav-link .nav-count:empty, .nav-link .nav-count[data-zero] { display: none; }

.alert-ok {
    background: var(--dlp-ok-bg); color: var(--dlp-ok-text); border: 1px solid #2a5a3a;
    border-radius: 6px; padding: 0.75rem 1rem; margin-bottom: 1rem;
}
.btn-danger { background: #b4232f; color: #fff; }
.btn-danger:hover { background: #cf2f3c; }
.btn-ghost { background: transparent; color: var(--dlp-text-muted); border: 1px solid var(--dlp-border); }
.btn-ghost:hover { color: var(--dlp-text); background: var(--dlp-nav-hover-bg); }
.btn[disabled], .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-lg { padding: 0.7rem 1.6rem; font-size: 1.02rem; font-weight: 600; }
button.link { background: none; border: none; color: var(--dlp-primary); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

.queue-patients { display: flex; flex-direction: column; gap: 0.15rem; }
.queue-patients .pt { white-space: nowrap; }
.queue-patients .dob { color: var(--dlp-text-muted); font-size: 0.85em; margin-left: 0.35rem; }
.row-actions { display: flex; gap: 0.4rem; justify-content: flex-end; flex-wrap: nowrap; }
.age-old { color: #fbbf24; font-weight: 600; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--dlp-text-muted); }
.empty-state .big { font-size: 2.4rem; margin-bottom: 0.4rem; }

dialog.modal {
    margin: auto; /* the * reset above removes the browser's centring */
    border: 1px solid var(--dlp-border); border-radius: 10px; background: var(--dlp-surface); color: var(--dlp-text);
    padding: 1.4rem 1.6rem; width: min(520px, 92vw); box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
dialog.modal::backdrop { background: var(--dlp-modal-overlay); }
dialog.modal h3 { color: var(--dlp-heading); margin-bottom: 0.6rem; }
dialog.modal .modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.1rem; }
textarea.form-input { min-height: 5rem; resize: vertical; }

/* --- fax workspace --- */
.fax-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.fax-head h1 { color: var(--dlp-heading); font-size: 1.5rem; }
.fax-head .meta { color: var(--dlp-text-muted); font-size: 0.92rem; }
.fax-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(420px, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 1150px) { .fax-layout { grid-template-columns: 1fr; } }

.viewer { position: sticky; top: 1rem; }
.thumbs { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.5rem; margin-bottom: 0.6rem; }
.thumb {
    position: relative; flex: 0 0 auto; width: 92px; border: 2px solid var(--dlp-border); border-radius: 6px;
    background: var(--dlp-surface-2); cursor: pointer; padding: 3px; user-select: none;
}
.thumb img { display: block; width: 100%; height: auto; border-radius: 3px; background: #fff; }
.thumb .num { position: absolute; top: 4px; left: 6px; font-size: 0.72rem; font-weight: 700; background: rgba(0,0,0,0.65); color: #fff; border-radius: 4px; padding: 0 0.3rem; }
.thumb .tag { position: absolute; bottom: 5px; left: 5px; right: 5px; text-align: center; font-size: 0.66rem; font-weight: 700; border-radius: 4px; padding: 1px 0; }
.thumb input[type=checkbox] { position: absolute; top: 5px; right: 5px; width: 17px; height: 17px; accent-color: var(--dlp-primary); }
.thumb.current { border-color: var(--dlp-primary); box-shadow: 0 0 0 2px rgba(91,163,240,0.35); }
.thumb.selected { border-color: #4ade80; }
.thumb.cover img, .thumb.discarded img { opacity: 0.35; }
.thumb.cover .tag { background: #4b5563; color: #e5e7eb; }
.thumb.attached img { opacity: 0.45; }
.thumb.attached .tag { background: #166534; color: #dcfce7; }
.thumb.discarded .tag { background: #7f1d1d; color: #fee2e2; }
.thumb .grp { position: absolute; bottom: 5px; right: 5px; font-size: 0.66rem; font-weight: 700; background: var(--dlp-badge-bg); color: var(--dlp-badge-text); border-radius: 4px; padding: 0 0.3rem; }
.page-stage { background: #0f1115; border: 1px solid var(--dlp-border); border-radius: 8px; padding: 0.6rem; text-align: center; max-height: calc(100vh - 220px); overflow: auto; }
.page-stage img { max-width: 100%; height: auto; background: #fff; border-radius: 2px; box-shadow: 0 2px 12px rgba(0,0,0,0.5); }
.page-stage.zoom img { max-width: none; width: 160%; }
.viewer-tools { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.viewer-tools .group { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }

.step { border: 1px solid var(--dlp-border); border-radius: 10px; background: var(--dlp-surface); padding: 1rem 1.15rem; margin-bottom: 1rem; box-shadow: 0 3px 14px var(--dlp-shadow); }
.step h2 { display: flex; align-items: center; gap: 0.55rem; color: var(--dlp-heading); font-size: 1.05rem; margin-bottom: 0.7rem; }
.step h2 .n { display: inline-flex; align-items: center; justify-content: center; width: 1.6rem; height: 1.6rem; border-radius: 999px; background: var(--dlp-primary); color: #fff; font-size: 0.85rem; }
.step.disabled { opacity: 0.55; pointer-events: none; }
.seg { display: inline-flex; border: 1px solid var(--dlp-border); border-radius: 7px; overflow: hidden; margin-bottom: 0.75rem; }
.seg button { background: transparent; border: none; color: var(--dlp-text-muted); padding: 0.45rem 1rem; cursor: pointer; font: inherit; font-weight: 500; }
.seg button.on { background: var(--dlp-tab-active-bg); color: var(--dlp-tab-active-text); }
.find-grid { display: grid; grid-template-columns: 1.2fr 1fr 0.9fr 0.9fr; gap: 0.5rem; align-items: end; }
.find-grid label, .acc-row label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--dlp-text-muted); }
.find-grid .form-input, .acc-row .form-input { padding: 0.5rem 0.65rem; font-size: 0.95rem; }
.acc-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.acc-row label { flex: 1; }
.ocr-hint { font-size: 0.85rem; color: var(--dlp-text-muted); margin: -0.2rem 0 0.65rem; }
.ocr-hint .chip { display: inline-block; background: var(--dlp-badge-bg); color: var(--dlp-badge-text); border-radius: 999px; padding: 0.1rem 0.6rem; margin: 0.15rem 0.25rem 0 0; cursor: pointer; border: none; font: inherit; font-size: 0.82rem; }
.ocr-hint .chip:hover { filter: brightness(1.2); }
.results { margin-top: 0.75rem; max-height: 330px; overflow: auto; border: 1px solid var(--dlp-border); border-radius: 7px; }
.results:empty { display: none; }
.results table { width: 100%; border-collapse: collapse; }
.results td, .results th { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--dlp-border); font-size: 0.88rem; text-align: left; }
.results th { background: var(--dlp-table-header); color: var(--dlp-heading); position: sticky; top: 0; }
.results tr.pick { cursor: pointer; }
.results tr.pick:hover td { background: var(--dlp-nav-hover-bg); }
.results tr.chosen td { background: var(--dlp-tab-active-bg); }
.results .none { padding: 0.8rem; color: var(--dlp-text-muted); }
.match { color: var(--dlp-ok-text); font-weight: 600; }
.mismatch { color: #f87171; font-weight: 600; }

.req-card { border: 1px solid var(--dlp-border-soft); border-radius: 8px; padding: 0.75rem 0.9rem; background: var(--dlp-surface-3); margin-bottom: 0.75rem; }
.req-card .title { font-size: 1.05rem; color: var(--dlp-heading); font-weight: 600; }
.req-card .sub { color: var(--dlp-text-muted); font-size: 0.88rem; }
.check-banner { border-radius: 6px; padding: 0.55rem 0.8rem; margin-bottom: 0.7rem; font-size: 0.9rem; }
.check-banner.ok { background: var(--dlp-ok-bg); color: var(--dlp-ok-text); }
.check-banner.bad { background: #3a1e20; color: #fca5a5; border: 1px solid #5c2a2e; }
.check-banner.warn { background: var(--dlp-warn-bg); color: var(--dlp-warn-text); }
.panel-list { list-style: none; border: 1px solid var(--dlp-border); border-radius: 7px; overflow: hidden; }
.panel-list li { display: flex; align-items: center; gap: 0.65rem; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--dlp-border); }
.panel-list li:last-child { border-bottom: none; }
.panel-list li.closed { color: var(--dlp-text-muted); }
.panel-list li.suggested { background: rgba(74,222,128,0.07); }
.panel-list input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--dlp-primary); }
.panel-list .pname { flex: 1; }
.panel-list .pcode { color: var(--dlp-text-muted); font-size: 0.82rem; margin-left: 0.35rem; }
.panel-list .ptag { font-size: 0.72rem; font-weight: 600; border-radius: 999px; padding: 0.05rem 0.5rem; background: var(--dlp-badge-bg); color: var(--dlp-badge-text); white-space: nowrap; }
.panel-list .ptag.sugg { background: #14532d; color: #bbf7d0; }
.attach-bar { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-top: 0.9rem; flex-wrap: wrap; }
.attach-summary { font-size: 0.9rem; color: var(--dlp-text-muted); }
.done-list { list-style: none; margin-top: 0.4rem; }
.done-list li { padding: 0.35rem 0; border-bottom: 1px dashed var(--dlp-border); font-size: 0.9rem; }
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -0.15rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- admin --- */
.admin-tabs { display: flex; gap: 0.3rem; flex-wrap: wrap; border-bottom: 1px solid var(--dlp-border); margin-bottom: 1.1rem; }
.admin-tabs a { padding: 0.55rem 0.95rem; color: var(--dlp-text-muted); text-decoration: none; border-radius: 6px 6px 0 0; font-weight: 500; font-size: 0.92rem; }
.admin-tabs a:hover { color: var(--dlp-primary); background: var(--dlp-nav-hover-bg); }
.admin-tabs a.active { color: var(--dlp-heading); background: var(--dlp-surface); box-shadow: inset 0 -2px 0 var(--dlp-primary); }
.form-grid > label.check, label.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 500; }
label.check input { width: 17px; height: 17px; accent-color: var(--dlp-primary); }
.help { font-size: 0.82rem; color: var(--dlp-text-muted); font-weight: 400; }
.secret-state { font-size: 0.8rem; color: var(--dlp-ok-text); font-weight: 500; }
.copy-field { display: flex; gap: 0.4rem; }
.copy-field input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; }
.log-detail { max-width: 46rem; white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.75rem; color: var(--dlp-text-muted); }
.lvl-Error { color: #f87171; font-weight: 600; }
.lvl-Warning { color: #fbbf24; font-weight: 600; }
.users-table input.form-input, .users-table select.form-input { padding: 0.35rem 0.5rem; font-size: 0.88rem; }
.users-table input.ini { width: 5.5rem; text-transform: uppercase; }
footer .brand-line { color: var(--dlp-text-muted); }
