/* ==========================================================================
   Chart shell chrome — LIVE on every census/chart load.
   Split out of census-v2.css (2026-08-19 infrastructure audit, P2) so the
   rollback-only v2 BOARD styles (census-v2-board.css, lazy-loaded behind
   ?census=v2) can be deleted without touching this file. Contents, moved
   VERBATIM: host integration / census-page swap (the .census-host base
   display:none that census-a3.css out-orders), the P3 chart rail (.cx2rail*,
   emitted by chart-rail.js), and the altitude cue (.cx2-altitude*).

   TOKEN REALITY: body carries data-theme="terminal"; this file consumes the
   live --term-* bridge palette (Dark Roast values via dr-compat.css).
   NO RAW HEX anywhere in this file — every color resolves through a token.
   ========================================================================== */

/* ---------- host integration: v2 owns the main area while no chart is open ---------- */

/* The mount node lives in the MAIN detail section (never the rail aside) and
   stays inert unless the JS mount succeeded (fail-open = legacy). While no
   patient is selected (census-page) the census page owns the main area:
   the legacy rail is hidden entirely and the empty state / patient header /
   clinical workspace leave the flow — their DOM and wiring keep running
   untouched. Selecting a row removes census-page and the chart renders
   exactly as legacy. */
.census-host {
    display: none; /* inert unless the JS mount succeeded (fail-open = legacy) */
}
.sol-main-layout.census-app-active.census-page .census-host {
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
}

/* The page swap. Section 17 of census-sidebar-terminal.css (the legacy
   sidebar-collapse grid rules) stands down entirely under .census-app-active —
   its :has() specificity would otherwise outrank this rule even through
   !important and pin the page to 64px 1fr whenever a collapsed sidebar state
   is persisted (the 2026-08-06 "census scrunched left" bug). */
.sol-main-layout.census-page {
    grid-template-columns: minmax(0, 1fr) !important;
}
.sol-main-layout.census-page > #censusSidebar,
.sol-main-layout.census-page .sol-patient-detail > #emptyState,
.sol-main-layout.census-page .sol-patient-detail > #patientHeader,
.sol-main-layout.census-page .sol-patient-detail > #clinicalWorkspace {
    display: none;
}
.sol-main-layout.census-page .sol-patient-detail {
    padding: 0; /* the .census-v2 page carries the reference padding itself */
}


/* ==========================================================================
   P3 chart rail (2026-08-03) — the census docked inside the chart
   Port of census-handoff/app/css/shell.css `.cxrail` onto the production
   shell. HANDOFF §6: when a chart is open the census does not vanish, it
   collapses to a 60px rail that lives in the SHELL (main#patientDetailWrapper),
   not in any chart surface — so every future chart surface inherits it free.
   Scoping law (the §6 gotcha that bit the reference once): every rule here is
   scoped to `.census-app-active:not(.census-page)`, i.e. mount-succeeded AND
   a chart is open. It can never bleed into the census page or a flag-OFF page.
   Still no raw hex — every color resolves through a token.
   ========================================================================== */

.cx2rail { display: none; }

/* Chart open: the rail takes the first column and the legacy sidebar stands
   down — the rail IS the patient switcher now (IMPLEMENTATION.md P3: "now,
   and only now, retire the old collapse affordance"). `auto` lets the rail's
   own width transition drive the column, exactly as the reference does.
   !important matches the census-page rule above; Section 17 of
   census-sidebar-terminal.css stands down under .census-app-active (see the
   page-swap comment), so nothing else competes for these tracks. */
.sol-main-layout.census-app-active:not(.census-page) {
    grid-template-columns: auto minmax(0, 1fr) !important;
}
.sol-main-layout.census-app-active:not(.census-page) > #censusSidebar {
    display: none;
}
.sol-main-layout.census-app-active:not(.census-page) > .cx2rail {
    display: flex;
    flex-direction: column;
    /* Polish (2026-09-01, owner): 72px room-chip strip → 184px so the docked
       rail reads room + LAST NAME + day/CC at rest. Hover/pin still widens to
       272px for the full name and foot hint. */
    width: 184px;
    min-height: 0;
    overflow: hidden;
    background: var(--dr-dark-cacao, var(--term-bg-elevated));
    border-right: 1px solid var(--term-border-subtle);
    transition: width .18s cubic-bezier(.4, 0, .2, 1);
    z-index: 40;
}
/* Hover expands; the pin HOLDS it open so hover never collapses the rail out
   from under the doctor mid-reach (HANDOFF §6). */
.sol-main-layout.census-app-active:not(.census-page) > .cx2rail:hover,
.sol-main-layout.census-app-active:not(.census-page) > .cx2rail.is-pinned {
    width: 272px;
}

.cx2rail-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 8px 8px;
    border-bottom: 1px solid var(--term-border-subtle);
}
.cx2rail-head .cx2rail-back { flex: 0 0 100%; }

.cx2rail-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 7px;
    font: 600 11px/1 var(--term-font-mono, var(--font-mono, monospace));
    letter-spacing: .08em;
    color: var(--term-fg-secondary);
    background: none;
    border: 1px dashed var(--term-border-strong);
    border-radius: 3px;
    white-space: nowrap;
    cursor: pointer;
}
.cx2rail-back:hover {
    color: var(--dr-amber, var(--term-status-editing));
    border-color: var(--dr-amber, var(--term-status-editing));
    border-style: solid;
}
.cx2rail-back:focus-visible { outline: 2px solid var(--sn-focus-ring, var(--term-accent)); outline-offset: 1px; }
.cx2rail-arrow { font-size: 11px; }

.cx2rail-count {
    padding: 0 2px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .06em;
    color: var(--term-fg-muted);
    white-space: nowrap;
}
.cx2rail-count b { font-size: 13px; color: var(--term-fg-primary); }

.cx2rail-pin {
    margin-left: auto;
    padding: 2px 5px;
    font-size: 10px;
    line-height: 1;
    color: var(--term-fg-secondary);
    background: none;
    border: 1px solid var(--term-border-subtle);
    border-radius: 3px;
    cursor: pointer;
}
.cx2rail-pin:hover { color: var(--term-fg-primary); border-color: var(--term-border-strong); }
.cx2rail-pin[aria-pressed="true"] { color: var(--term-accent); }

.cx2rail-list { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 6px 0; }
.cx2rail-list::-webkit-scrollbar { width: 0; }

.cx2rail-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    white-space: nowrap;
    cursor: pointer;
    /* Derived trajectory tone when the arcs payload supplied one; neutral
       otherwise. The reference's acuity edge is NOT ported — production has
       no proven severity-to-acuity mapping and an invented one is a clinical
       claim (the same honest absence the unit strip states). */
    border-left: 4px solid var(--cx2rail-edge, var(--term-border-subtle));
    /* Row separation (owner 2026-08-21, re-asked 2026-09-01 "basically no
       divider"): hairline lifted 9% → 22% plus a zebra wash on even rows. */
    border-bottom: 1px solid color-mix(in srgb, var(--term-fg-primary) 22%, transparent);
}
.cx2rail-item:nth-child(even) { background: color-mix(in srgb, var(--term-fg-primary) 3%, transparent); }
.cx2rail-item:last-child { border-bottom-color: transparent; }
.cx2rail-item:hover { background: var(--dr-inkwash, color-mix(in srgb, var(--term-fg-primary) 6%, transparent)); }
.cx2rail-item:focus-visible { outline: 2px solid var(--sn-focus-ring, var(--term-accent)); outline-offset: -2px; }
/* Selection is a context, never a decision: neutral inner ring, no state hue. */
.cx2rail-item.is-active {
    background: var(--dr-inkwash, color-mix(in srgb, var(--term-fg-primary) 6%, transparent));
    box-shadow: inset 0 0 0 1px var(--sn-selection-ring, color-mix(in srgb, var(--term-fg-primary) 25%, transparent));
}

.cx2rail-room {
    min-width: 44px;
    text-align: right;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: .02em;
    color: var(--term-fg-primary);
}
.cx2rail-room.is-none { color: var(--term-fg-muted); font-weight: 400; }

.cx2rail-item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }

/* At rest the row shows LAST name + day/CC; the ", First" tail and the
   foot hint are the only hover/pin-revealed pieces now. */
.cx2rail-name {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--term-fg-primary);
}
.cx2rail-first { display: none; }
.cx2rail:hover .cx2rail-first, .cx2rail.is-pinned .cx2rail-first { display: inline; }
.cx2rail-day {
    display: flex;
    align-items: baseline;
    gap: 7px;
    overflow: hidden;
    font-size: 11.5px;
    font-weight: 500;
    color: var(--term-fg-muted);
}
/* Sub-line pieces (2026-08-21 legibility pass): day stays bright, the
   diagnosis takes the row's DERIVED trajectory tone — the same variable the
   edge stripe carries, so a worsening patient's diagnosis reads scarlet, an
   improving one teal, and an untoned row falls back to secondary instead of
   a wall of one muted color. */
.cx2rail-daynum {
    flex: none;
    font-weight: 700;
    font-size: 11.5px;
    color: var(--term-fg-primary);
}
.cx2rail-cc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--cx2rail-edge, var(--term-fg-secondary));
}
.cx2rail-ownertag {
    flex: none;
    padding: 1px 5px;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--dr-amber, var(--term-status-editing));
    border: 1px solid color-mix(in srgb, var(--dr-amber, var(--term-status-editing)) 45%, transparent);
    border-radius: 3px;
}
/* Derived worsening dot — real truth (worse >= 1 from the v2 tapestry lanes).
   Sits at the trailing edge in both widths. */
.cx2rail-worse {
    flex: none;
    margin-left: auto;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--dr-scarlet, var(--term-status-critical));
    box-shadow: 0 0 5px color-mix(in srgb, var(--dr-scarlet, var(--term-status-critical)) 55%, transparent);
}

/* Ownership fold (2026-08-21): mine on top, other doctors' rooms behind a
   labeled divider — the rail's port of the A3 board OTHER DOCTORS disclosure.
   Collapsed rail shows only the +N chip; label and caret ride the same
   hover/pin reveal as names. Renders only when others exist (admin view). */
.cx2rail-others-head {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-top: 12px;
    padding: 7px 10px 7px 14px;
    background: color-mix(in srgb, var(--term-fg-primary) 4%, transparent);
    border: 0;
    border-top: 1px solid var(--term-border-strong);
    border-bottom: 1px solid color-mix(in srgb, var(--term-fg-primary) 9%, transparent);
    color: var(--term-fg-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}
.cx2rail-others-head:hover { color: var(--term-fg-primary); }
.cx2rail-others-head:focus-visible { outline: 2px solid var(--sn-focus-ring, var(--term-accent)); outline-offset: -2px; }
.cx2rail-others-count { min-width: 44px; text-align: right; font-size: 12px; }
.cx2rail-others-caret { margin-left: auto; }

/* Another doctor's row: same affordances (admins do open these charts), the
   room chip just steps back to muted so the doctor's own rooms stay the
   bright column. */
.cx2rail-item.is-other .cx2rail-room { color: var(--term-fg-muted); font-weight: 500; }

/* Head count reads mine-first: the big number is the doctor's own census,
   the +N tail is other doctors' patients. */
.cx2rail-count-others { color: var(--term-fg-muted); font-weight: 400; }

.cx2rail-foot {
    padding: 8px 10px;
    border-top: 1px solid var(--term-border-subtle);
    font-size: 9px;
    letter-spacing: .04em;
    color: var(--term-fg-muted);
    white-space: nowrap;
    overflow: hidden;
    opacity: 0;
    transition: opacity .12s ease;
}
.cx2rail:hover .cx2rail-foot, .cx2rail.is-pinned .cx2rail-foot { opacity: 1; }

/* ---------- altitude cue (shell law, HANDOFF §1.1) ---------- */

/* The app bar states the working level: CENSUS on the page, CHART · patient in
   a chart. It deliberately carries NO patient count — the header counts were
   removed on 2026-07-23 because the census list is the single source of truth
   for them, and an altitude cue is not a reason to put them back. */
.cx2-altitude {
    display: none;
    font-size: 10.5px;
    letter-spacing: .06em;
    color: var(--term-fg-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.census-shell .cx2-altitude { display: inline-flex; align-items: baseline; gap: 6px; }
.cx2-altitude-level { font-weight: 600; color: var(--term-fg-muted); }
