* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* DARK is the default theme (low-vision accessibility). Toggle sets data-theme="light". */
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --bg: #0f172a;
    --surface: #1e293b;
    --border: #334155;
    --text: #f8fafc;
    --text-muted: #cbd5e1;
    --success: #34d399;
    --warning: #fbbf24;
    --error: #f87171;
    --kp: #fbbf24;                 /* key-point highlight (amber) */
    --left-w: 300px;
    --right-w: 260px;
}
:root[data-theme="light"] {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --kp: #b45309;
}

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--border);
}
.app {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: var(--left-w) 6px 1fr var(--right-w);
    background: var(--border);
}

/* STATIC PATIENT HEADER */
.patient-header {
    position: relative;                       /* anchor for the pinned count */
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.4rem; padding: 0.9rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--text); flex-shrink: 0; text-align: center;
}
.ph-id { display: flex; align-items: center; justify-content: center; gap: 1rem; min-width: 0; }
.ph-name { font-size: 1.7rem; font-weight: 700; line-height: 1.15; color: var(--text); }
.ph-meta {
    font-size: 0.95rem; color: var(--text-muted); margin-top: 0.25rem;
    display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: center;
}
.ph-dot { opacity: 0.6; }
/* all header info centered in one column */
.ph-right { position: static; transform: none; }
.ph-count {
    font-size: 0.8rem; font-weight: 600; white-space: nowrap; color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, transparent);
    border: 1px solid var(--primary); padding: 0.3rem 0.7rem; border-radius: 1rem;
}

/* CATEGORY TABS + SORT + SEARCH BAR */
.topbar-rubella { justify-content: center; text-align: center; border-bottom: 1px solid var(--border); padding: 0.5rem 0.75rem;
    background: color-mix(in srgb, var(--warning) 8%, var(--surface)); }
.rubella-tab { display: block; margin: 0 auto; padding: 0.5rem 1.4rem; border: 1.5px solid var(--warning); border-radius: 1rem;
    background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning);
    font-size: 0.95rem; font-weight: 800; letter-spacing: 0.03em; text-align: center; cursor: pointer; transition: all 0.15s; }
.rubella-tab:hover { background: color-mix(in srgb, var(--warning) 24%, transparent); }
.rubella-tab.active { background: var(--warning); color: #1c1917; }
.topbar-tools { justify-content: center; border-bottom: 1px solid var(--border); padding: 0.6rem 0.75rem; }
.topbar-tools .cat-tab { flex: 0 0 auto; font-size: 1rem; padding: 0.55rem 1.1rem; font-weight: 600; }
/* category row: sort + tabs centered together, not spread to the edges */
.topbar-cats { justify-content: center; }
.topbar-cats .category-tabs { flex: 0 1 auto; justify-content: center; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.75rem; padding: 0.4rem 0.75rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
    flex-shrink: 0; flex-wrap: wrap;
}
.category-tabs { display: flex; flex-wrap: wrap; gap: 0.3rem; min-width: 0; }
.cat-tab {
    padding: 0.28rem 0.6rem; border: 1px solid var(--border);
    background: var(--bg); color: var(--text-muted);
    border-radius: 1rem; font-size: 0.76rem; font-weight: 500;
    cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.cat-tab:hover { border-color: var(--primary); color: var(--primary); }
.cat-tab.active {
    background: var(--primary); color: #fff; border-color: var(--primary);
}
.cat-tab .tab-count { opacity: 0.7; font-size: 0.7rem; margin-left: 0.25rem; }
.topbar-controls { display: flex; gap: 0.4rem; align-items: center; flex-shrink: 0; }
.topbar-controls .compact-select { flex: 0 0 auto; }
.topbar-controls .search-box { width: 220px; }

/* Slim count strip atop the document list */
.sidebar-list-head {
    padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.sidebar-list-head .list-meta { font-size: 0.72rem; color: var(--text-muted); }

/* SIDEBARS */
.sidebar-left, .sidebar-right {
    background: var(--surface);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sidebar-right { border-left: 1px solid var(--border); overflow-y: auto; }

/* Sidebar resize handle */
.sidebar-resizer {
    background: var(--border);
    cursor: col-resize;
    transition: background 0.15s;
}
.sidebar-resizer:hover, .sidebar-resizer.active { background: var(--primary); }

.sidebar-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.sidebar-header h2 { font-size: 1rem; font-weight: 600; }

/* Compact left toolbar (replaces the old radio stacks) */
.sidebar-toolbar {
    padding: 0.6rem 0.7rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toolbar-row { display: flex; gap: 0.4rem; }
.compact-select {
    flex: 1;
    min-width: 0;
    padding: 0.4rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--surface);
    font-size: 0.8rem;
    color: var(--text);
    cursor: pointer;
}
.compact-select:focus { outline: none; border-color: var(--primary); }

.search-box {
    width: 100%;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.85rem;
}
.search-box:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}
.list-meta { font-size: 0.7rem; color: var(--text-muted); }

/* Document list */
.document-list-sidebar { flex: 1; overflow-y: auto; }

.doc-item {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}
.doc-item:hover { background: var(--bg); border-left-color: var(--primary); }
.doc-item.active { background: var(--primary); color: #fff; border-left-color: var(--primary-dark); }

.doc-item-title {
    font-size: 0.8rem; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-item-sub {
    font-size: 0.72rem; opacity: 0.8;
    display: flex; gap: 0.4rem; align-items: center; margin-top: 0.15rem;
}
.doc-item.active .doc-item-sub { opacity: 0.95; }

/* Date source badges */
.badge {
    display: inline-block;
    font-size: 0.62rem;
    padding: 0.05rem 0.3rem;
    border-radius: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge.inherited { background: #fef3c7; color: #92400e; }
.badge.unknown   { background: #fee2e2; color: #991b1b; }
.badge.manual    { background: #dbeafe; color: #1e40af; }
.badge.low       { background: #f1f5f9; color: #475569; }
.doc-item.active .badge { background: rgba(255,255,255,0.25); color: #fff; }

/* MAIN CONTENT */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1px 1fr;
    background: var(--border);
    overflow: hidden;
}
.pane-divider {
    cursor: col-resize; background: var(--border);
    width: 1px; user-select: none; transition: background 0.2s;
}
.pane-divider:hover, .pane-divider.active { background: var(--primary); }

.pane {
    background: var(--surface);
    display: flex; flex-direction: column; overflow: hidden;
}
.pane-header {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
}
.pane-header h3 { font-size: 0.9rem; font-weight: 600; white-space: nowrap; }
.controls { display: flex; gap: 0.35rem; align-items: center; }
.control-btn {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 0.375rem; padding: 0.3rem 0.5rem; cursor: pointer;
    font-size: 0.85rem; min-width: 30px; transition: all 0.15s;
}
.control-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.zoom-level { min-width: 42px; text-align: center; font-size: 0.75rem; color: var(--text-muted); }
.page-indicator { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }

.pane-body {
    flex: 1; overflow: auto; padding: 1rem;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.pane-left .pane-body { background: #f0f0f0; }
.placeholder { color: var(--text-muted); font-size: 0.9rem; text-align: center; }

.image-container {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; cursor: grab;
}
.image-container.grabbing { cursor: grabbing; }
.image-container img {
    max-width: 100%; max-height: 100%; object-fit: contain;
    transform-origin: center center; user-select: none; -webkit-user-drag: none;
}

.text-content {
    width: 100%; height: 100%;
    font-size: 0.88rem; line-height: 1.55;
    white-space: pre-wrap; word-wrap: break-word;
    align-self: flex-start;
}

.pane-footer {
    padding: 0.55rem 1rem; border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 0.6rem; justify-content: center;
}
.nav-btn {
    padding: 0.4rem 0.85rem; background: var(--primary); color: #fff;
    border: none; border-radius: 0.375rem; cursor: pointer; font-size: 0.8rem; font-weight: 500;
}
.nav-btn:hover { background: var(--primary-dark); }
.nav-btn:disabled { background: var(--border); cursor: not-allowed; }
.page-status { font-size: 0.8rem; color: var(--text-muted); flex: 1; text-align: center; }

/* RIGHT SIDEBAR sections */
.sidebar-section { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); }
.sidebar-section h3 {
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.6rem;
}

.info-block { font-size: 0.85rem; }
.info-row {
    display: grid; grid-template-columns: 70px 1fr; gap: 0.5rem;
    margin-bottom: 0.45rem; align-items: baseline;
}
.info-row .label { font-weight: 500; color: var(--text-muted); font-size: 0.8rem; }
.info-row .value { color: var(--text); word-break: break-word; }
.value.unknown { color: var(--error); font-style: italic; }

/* Manual date editor */
.date-edit {
    margin-top: 0.6rem; padding-top: 0.6rem; border-top: 1px dashed var(--border);
    display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center;
}
.date-edit-input {
    flex: 1 1 130px; min-width: 0;
    padding: 0.35rem 0.45rem; border: 1px solid var(--border);
    border-radius: 0.3rem; font-size: 0.8rem;
}
.date-edit-input:focus { outline: none; border-color: var(--primary); }
.mini-btn {
    padding: 0.35rem 0.6rem; border: 1px solid var(--primary);
    background: var(--primary); color: #fff; border-radius: 0.3rem;
    font-size: 0.75rem; cursor: pointer;
}
.mini-btn.ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.mini-btn:hover { filter: brightness(0.95); }
.date-edit-msg { flex-basis: 100%; font-size: 0.72rem; min-height: 0.9rem; }
.date-edit-msg.ok { color: var(--success); }
.date-edit-msg.err { color: var(--error); }

.multidate-hint { font-size: 0.72rem; color: var(--text-muted); line-height: 1.4; margin: 0 0 0.5rem; }
.multidate-list { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.multidate-chip {
    font-size: 0.74rem; font-weight: 600; color: var(--warning);
    background: color-mix(in srgb, var(--warning) 14%, var(--surface));
    border: 1px solid var(--warning); border-radius: 999px; padding: 0.15rem 0.55rem;
}

.labs-list, .icd-list { display: flex; flex-direction: column; gap: 0.5rem; }
.lab-item {
    background: var(--bg); padding: 0.55rem; border-radius: 0.375rem;
    font-size: 0.82rem; border-left: 3px solid var(--success);
}
.lab-name { font-weight: 500; }
.lab-value { color: var(--success); font-weight: 600; }
.lab-unit { color: var(--text-muted); font-size: 0.78rem; }

.icd-item {
    background: var(--bg); padding: 0.6rem; border-radius: 0.375rem;
    border-left: 3px solid var(--warning); font-size: 0.82rem;
}
.icd-code { font-weight: 600; margin-bottom: 0.2rem; }
.icd-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.35rem; }
.icd-description { color: var(--text-muted); font-size: 0.78rem; margin-bottom: 0.2rem; }
.icd-group-tag { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; margin-bottom: 0.15rem; }
.icd-relation { color: var(--warning); font-size: 0.72rem; font-style: italic; }
.icd-table {
    display: inline-block; background: #fff; padding: 0.15rem 0.35rem;
    border-radius: 0.2rem; font-weight: 500; margin-top: 0.2rem; font-size: 0.68rem;
}

.loading { text-align: center; color: var(--text-muted); padding: 2rem 1rem; }

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@media (max-width: 1024px) {
    .app { grid-template-columns: 1fr; }
    .sidebar-resizer, .sidebar-right { display: none; }
    .main-content { grid-template-columns: 1fr; }
}

/* Review banner + OCR confidence (v2 pipeline) */
.review-banner {
    margin: 0.5rem 0.9rem; padding: 0.5rem 0.7rem;
    border-radius: 6px; font-size: 0.78rem; line-height: 1.35;
}
.review-banner.flagged {
    background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
}
.review-banner.clean {
    background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0;
}
.review-banner .conf {
    display: inline-block; margin-left: 0.5rem; opacity: 0.8; font-weight: 600;
}
.icd-era {
    float: right; font-size: 0.65rem; font-weight: 600;
    background: var(--primary); color: #fff;
    padding: 0.05rem 0.4rem; border-radius: 0.7rem;
}

/* Transcript view toggle + visual reconstruction */
.view-toggle { display: inline-flex; gap: 2px; margin-left: auto; }
.vt-btn {
    font-size: 0.7rem; padding: 0.2rem 0.55rem; border: 1px solid var(--border);
    background: var(--bg); color: var(--text-muted); cursor: pointer;
}
.vt-btn:first-child { border-radius: 4px 0 0 4px; }
.vt-btn:last-child { border-radius: 0 4px 4px 0; }
.vt-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.enriched-text { white-space: pre-wrap; font: inherit; margin: 0 0 1rem; }
.enriched-visuals { border-top: 2px dashed var(--border); padding-top: 0.6rem; }
.ev-label {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-muted); margin-bottom: 0.5rem; font-weight: 600;
}
.vis-figure { margin: 0 0 1rem; text-align: left; }
.vis-figure img {
    /* never upscale past the crop's real pixels; bound tall crops so a snapshot
       stays "within the page" instead of dominating the pane */
    max-width: 100%; width: auto; height: auto; max-height: 55vh;
    border: 1px solid var(--border); border-radius: 4px; background: #fff;
}
.vis-figure figcaption {
    font-size: 0.72rem; color: var(--text-muted); margin-top: 0.3rem;
    text-align: left; line-height: 1.4;
}
.vis-table { overflow-x: auto; margin: 0 0 1rem; }
.vis-table table { border-collapse: collapse; width: 100%; font-size: 0.78rem; }
.vis-table th, .vis-table td {
    border: 1px solid var(--border); padding: 0.3rem 0.5rem; text-align: left;
}
.vis-table th { background: var(--bg); font-weight: 600; }
.visual-mode { display: block; }

/* ---- utility ---- */
.hidden { display: none !important; }

/* ---- topbar: sort pinned left, search stays right ---- */
.topbar > .compact-select { flex: 0 0 auto; margin-right: 0.5rem; }
.category-tabs { flex: 1 1 auto; }
.icd-tab { flex: 0 0 auto; border-style: dashed; }
.icd-tab.active { background: var(--primary); color: #fff; border-style: solid; }

/* ---- ICD summary panel (scaffold) ---- */
.icd-panel { flex: 1 1 auto; overflow: auto; padding: 1rem 1.25rem; background: var(--bg); }
.icd-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.icd-panel-head h2 { font-size: 1.05rem; margin: 0; }
.icd-sub { font-weight: 400; font-size: 0.78rem; color: var(--muted); margin-left: 0.4rem; }
.icd-note { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.75rem; }
.icd-table { border-collapse: collapse; width: 100%; font-size: 0.85rem; background: var(--surface); }
.icd-table th, .icd-table td {
    border: 1px solid var(--border); padding: 0.4rem 0.6rem; text-align: left; vertical-align: top;
}
.icd-table th { background: var(--bg); font-weight: 600; position: sticky; top: 0; }
.icd-table .icd-matched { color: var(--muted); font-style: italic; }
.icd-table .icd-count { text-align: right; font-variant-numeric: tabular-nums; }
.icd-group { margin-bottom: 1.4rem; border-left: 3px solid var(--border); padding-left: 0.7rem; }
.icd-group-title {
    font-size: 0.92rem; margin: 0 0 0.25rem; padding-bottom: 0.2rem;
    border-bottom: 2px solid var(--border);
}
.icd-group-relation { font-size: 0.8rem; color: var(--muted); margin: 0 0 0.5rem; line-height: 1.4; }

/* ---- search row (moved below the category section) ---- */
.search-row {
    padding: 0.4rem 0.75rem; background: var(--surface);
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.search-row .search-box { width: 100%; box-sizing: border-box; }
.search-row-main { display: flex; gap: 0.4rem; align-items: center; }
.search-row-main .search-box { flex: 1; }
.search-row-main .mini-btn { flex: 0 0 auto; white-space: nowrap; }
.mini-btn.active-filters { background: var(--primary); color: #fff; border-color: var(--primary); }
.search-filters {
    display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center;
    margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px dashed var(--border);
}
.sf-field { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.7rem; color: var(--text-muted); }
.sf-field input, .sf-field select { font-size: 0.8rem; }
.sf-checkbox { display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; color: var(--text-muted); cursor: pointer; }

/* ---- DICOM series stack viewer ---- */
.stack-ctrl {
    position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
    background: rgba(20,22,28,.82); color: #e8eaf0; padding: 7px 12px;
    border-radius: 10px; backdrop-filter: blur(6px); max-width: 92%; z-index: 5;
    box-shadow: 0 2px 12px rgba(0,0,0,.35);
}
.stack-ctrl button {
    background: #2a2e3a; color: #e8eaf0; border: 1px solid #3a3f4d;
    border-radius: 6px; width: 30px; height: 30px; font-size: 18px; cursor: pointer; line-height: 1;
}
.stack-ctrl button:hover { background: #363b49; }
.stack-ctrl input[type=range] { width: 180px; accent-color: #5b8dff; cursor: pointer; }
.stack-counter { font-size: 13px; font-variant-numeric: tabular-nums; min-width: 58px; text-align: center; }
.stack-marker {
    width: auto !important; padding: 0 10px; font-size: 12px; font-weight: 600;
    background: #7a2e0b !important; border-color: #b5541f !important; color: #ffd9c2 !important;
}
.stack-marker:hover { background: #96380e !important; }
.stack-marker.active { background: #e0670f !important; color: #1a1205 !important; box-shadow: 0 0 0 2px #ffb066; }
.stack-caption {
    position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
    background: rgba(122,46,11,.94); color: #ffe6d5; padding: 8px 14px; border-radius: 8px;
    font-size: 13px; font-weight: 600; max-width: 80%; text-align: center; z-index: 6;
    border: 1px solid #e0670f; box-shadow: 0 2px 14px rgba(0,0,0,.4);
}

/* ---- Pastena second-opinion banner (loud) ---- */
.pastena-banner {
    display: flex; align-items: center; gap: 12px;
    margin: 0 0 8px 0; padding: 10px 14px;
    background: linear-gradient(90deg, #7a2e0b, #b8460f);
    border-left: 5px solid #ffb066; border-radius: 6px;
    color: #fff5ec; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.pastena-banner .pb-badge {
    flex: 0 0 auto; font-size: 11px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; background: #ffb066; color: #1a1205;
    padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.pastena-banner .pb-text { font-size: 14px; line-height: 1.35; }

/* ---- Finding overlay (circle + arrow) on the marked slice ---- */
.stack-frame { position: relative; display: inline-block; line-height: 0; }
.stack-roi { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.stack-roi .roi-ring { fill: none; stroke: #ffb066; stroke-width: .5; opacity: .95;
    filter: drop-shadow(0 0 2px rgba(0,0,0,.9)); animation: roiPulse 1.6s ease-in-out infinite; }
.stack-roi .roi-arrow { stroke: #ffb066; stroke-width: .6; filter: drop-shadow(0 0 2px rgba(0,0,0,.9)); }
.stack-roi .roi-head { fill: #ffb066; }
@keyframes roiPulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

/* ---- Play + overlay-toggle buttons in the control bar ---- */
#stackPlay { min-width: 30px; font-size: 12px; }
#stackPlay.active { background: #e0670f !important; color: #1a1205 !important; }
.stack-roi-toggle {
    background: #3a2a12 !important; color: #ffce9c !important;
    border: 1px solid #7a2e0b !important; font-size: 12px;
}
.stack-roi-toggle.active { background: #e0670f !important; color: #1a1205 !important; }

/* Frame must carry the size constraints so the image + overlay fit the pane. */
.stack-frame { max-width: 100%; max-height: 100%; transform-origin: center center; }
.stack-frame img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---- Trends page ---- */
.trends-tab { text-decoration: none; display: inline-flex; align-items: center; }
.trends-back { color: #9db4e0; text-decoration: none; font-size: 13px; }
.trends-back:hover { color: #fff; }
.trends-intro { padding: 10px 18px 0; max-width: 1100px; }
.trends-intro p { font-size: 13px; line-height: 1.5; color: #93a0b4; }
.trends-intro em { color: #cdd6e4; font-style: normal; }
.trends-intro strong { color: #ffce9c; }
.trends-status { padding: 20px 18px; color: #93a0b4; }
.trends-grid { padding: 6px 18px 40px; }
.tr-group { font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
    color: #8ea2c6; margin: 18px 0 8px; border-bottom: 1px solid #2a3040; padding-bottom: 4px; }
.tr-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.tr-card { background: #1c2130; border: 1px solid #2a3040; border-radius: 8px; padding: 10px 8px 4px; }
.tr-card figcaption { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
    padding: 0 6px 4px; font-size: 13px; }
.tr-metric { font-weight: 700; color: #e6ecf5; }
.tr-ref { font-size: 11px; color: #7fd6a0; }
.tr-n { margin-left: auto; font-size: 11px; color: #7c8aa0; font-variant-numeric: tabular-nums; }
.tr-svg { width: 100%; height: auto; display: block; }
.tr-band { fill: rgba(88, 200, 130, .12); }
.tr-grid { stroke: #2a3040; stroke-width: 1; }
.tr-xlabel, .tr-ylabel { fill: #6f7d92; font-size: 9px; text-anchor: middle; }
.tr-ylabel { text-anchor: start; }
.tr-line { fill: none; stroke: #5b8dff; stroke-width: 1.8; }
.tr-dot { fill: #9db4e0; stroke: #1c2130; stroke-width: 1.5; cursor: pointer; transition: r .1s, fill .1s; }
.tr-dot:hover { fill: #ffce9c; r: 6; }

/* ==========================================================================
   RIGHT-SIDEBAR TOOLS  (ICD / Labs / Calendar / Providers)
   Tabbed panel that replaces the old separate pages. See app.js "RIGHT-SIDEBAR
   TOOLS". The 4th grid column widens while a tool is open so charts/calendar fit.
   ========================================================================== */
.app.tools-wide { grid-template-columns: var(--left-w) 6px 1fr 460px; }

/* Tab strip pinned to the top of the right column */
.right-tabs {
    position: sticky; top: 0; z-index: 6;
    display: flex; gap: 4px; flex-wrap: wrap;
    padding: 0.5rem 0.6rem; background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.rt-tab {
    padding: 0.35rem 0.75rem; border: 1px solid var(--border);
    background: var(--surface); color: var(--text-muted);
    border-radius: 999px; font-size: 0.85rem; font-weight: 600;
    cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.rt-tab:hover { border-color: var(--primary); color: var(--primary); }
.rt-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.tool-panel { padding: 0.75rem 0.85rem 2rem; }
.tool-loading, .tool-empty { color: var(--text-muted); font-size: 0.82rem; padding: 1.4rem 0.2rem; text-align: center; }
.tool-empty.small { padding: 0.6rem 0; text-align: left; }

/* Shared tool chrome */
.tp-head h2 { font-size: 1.05rem; font-weight: 700; margin: 0 0 0.2rem; }
.tp-sub { font-size: 0.74rem; line-height: 1.45; color: var(--text-muted); margin: 0 0 0.9rem; }
.tp-group { margin-bottom: 1.1rem; }
.tp-group-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
    padding-left: 8px; border-left: 3px solid var(--border); margin-bottom: 0.35rem;
}
.tp-group-title { font-size: 0.9rem; font-weight: 700; color: var(--text); }
.tp-group-n { font-size: 0.7rem; color: var(--text-muted); }
.tp-group-rel { font-size: 0.72rem; color: var(--text-muted); font-style: italic; margin: 0 0 0.5rem 8px; }

/* Document chips — clicking loads the doc in the viewer, tool stays open */
.tp-docrow { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tp-docchip {
    font-size: 0.68rem; padding: 2px 8px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    cursor: pointer; white-space: nowrap; transition: all 0.12s;
}
.tp-docchip:hover { border-color: var(--primary); color: var(--primary); }

/* ---- ICD ---- */
.icdx-code {
    border: 1px solid var(--border); border-left-width: 3px; border-radius: 8px;
    padding: 8px 10px; margin-bottom: 8px; background: var(--surface);
}
.icdx-code-head { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; }
.icdx-code-head strong { font-size: 0.85rem; }
.icdx-count { margin-left: auto; font-size: 0.68rem; color: var(--text-muted); }
.icdx-desc { font-size: 0.74rem; color: var(--text-muted); line-height: 1.4; margin-top: 2px; }
.icdx-matched { color: var(--text); }

/* ---- Labs ---- */
.labs-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 0.6rem; }
.ls-chip { font-size: 0.72rem; padding: 4px 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.ls-chip b { font-size: 0.85rem; }
.ls-chip.bad { border-color: #dc2626; color: #dc2626; }
.ls-chip.warn { border-color: #d97706; color: #b45309; }
.ls-flags { font-size: 0.72rem; color: #b91c1c; margin-bottom: 0.9rem; line-height: 1.4; }
.lab-metric { border-bottom: 1px solid var(--border); padding: 0.55rem 0; }
.lab-metric:last-child { border-bottom: none; }
.lm-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.lm-name { font-size: 0.82rem; font-weight: 600; }
.lm-latest { font-size: 0.78rem; color: var(--text); font-weight: 600; margin-left: auto; }
.lm-meta { font-size: 0.68rem; color: var(--text-muted); margin: 2px 0 4px; }
.lm-ref { margin-left: 4px; }
.tp-svg { width: 100%; height: auto; display: block; }
/* tr-badge lived only in the old trends page; define it globally for the panel */
.tr-badge { font-size: 0.62rem; padding: 1px 6px; border-radius: 8px; font-weight: 600; }
.tr-badge.ok { background: #16a34a22; color: #16a34a; }
.tr-badge.oor { background: #dc262622; color: #dc2626; }
.tr-badge.stale { background: #d9770622; color: #d97706; }

/* ---- Calendar ---- */
.calx-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 0.5rem; }
.calx-btn {
    padding: 2px 9px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--text); cursor: pointer; font-size: 0.9rem;
}
.calx-btn:hover { border-color: var(--primary); color: var(--primary); }
.calx-sel { font-size: 0.75rem; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); }
.calx-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.calx-dow { font-size: 0.6rem; text-transform: uppercase; color: var(--text-muted); text-align: center; padding-bottom: 2px; }
.calx-day {
    min-height: 42px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface);
    padding: 3px 4px; display: flex; flex-direction: column; gap: 2px; position: relative;
}
.calx-day.pad { background: transparent; border-color: transparent; }
.calx-day.has { cursor: pointer; background: rgba(37,99,235,0.10); border-color: rgba(37,99,235,0.35); }
.calx-day.has:hover { border-color: var(--primary); background: rgba(37,99,235,0.20); }
.calx-day.sel { border-color: var(--primary); border-width: 2px; }
.calx-day.bday::after { content: '🎂'; position: absolute; top: 2px; right: 3px; font-size: 9px; }
.calx-dnum { font-size: 0.62rem; color: var(--text-muted); }
.calx-day.has .calx-dnum { color: var(--text); font-weight: 700; }
.calx-dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: auto; }
.calx-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.calx-dot.ref { width: 5px; height: 5px; background: transparent !important; border: 1.4px solid; opacity: 0.8; }
.calx-detail { margin-top: 0.8rem; }
.calx-detail-h { font-size: 0.8rem; font-weight: 700; margin-bottom: 0.4rem; }
.calx-ev {
    display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
    padding: 6px 4px; border: none; border-bottom: 1px solid var(--border);
    background: transparent; cursor: pointer;
}
.calx-ev:last-child { border-bottom: none; }
.calx-ev:hover .calx-ev-title { color: var(--primary); }
.calx-ev-cat { font-size: 0.6rem; padding: 1px 6px; border-radius: 999px; color: #fff; white-space: nowrap; }
.calx-ev-title { font-size: 0.74rem; color: var(--text); flex: 1; line-height: 1.3; }
.calx-ev-date { font-size: 0.66rem; color: var(--text-muted); white-space: nowrap; }

/* ---- Providers ---- */
.prov-pills { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 0.8rem; }
.prov-pill {
    padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px;
    background: var(--surface); color: var(--text-muted); cursor: pointer; font-size: 0.72rem;
}
.prov-pill:hover { border-color: var(--primary); color: var(--primary); }
.prov-pill.active { border-color: var(--primary); color: var(--primary); font-weight: 700; }
.prov-pill-n { opacity: 0.7; }
.prov-card2 { border: 1px solid var(--border); border-radius: 9px; background: var(--surface); padding: 9px 11px; margin-bottom: 8px; }
.pc2-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pc2-name { font-size: 0.85rem; font-weight: 700; }
.pc2-badge { font-size: 0.66rem; color: var(--text-muted); white-space: nowrap; }
.pc2-role { font-size: 0.74rem; color: var(--text-muted); line-height: 1.4; margin-top: 2px; }
.prov-none { font-size: 0.7rem; color: var(--text-muted); font-style: italic; margin-top: 6px; }

/* ---- My Notes / Sign Off ---- */
.notes-textarea {
    width: 100%; min-height: 260px; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; background: var(--bg); color: var(--text); font-size: 0.84rem;
    line-height: 1.5; font-family: inherit; resize: vertical;
}
.notes-textarea:focus { outline: none; border-color: var(--primary); }
.notes-status { font-size: 0.7rem; color: var(--text-muted); margin-top: 6px; min-height: 1em; }
.signoff-notes-summary { border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
    padding: 10px 13px; margin-bottom: 16px; }
.signoff-notes-summary h4 { margin: 0 0 8px; font-size: 0.72rem; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--text-muted); }
.signoff-note { font-size: 0.78rem; color: var(--text); line-height: 1.5; margin: 4px 0; }
.signoff-opts label { display: flex; align-items: flex-start; gap: 8px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; margin: 0 0 6px;
    cursor: pointer; font-size: 0.8rem; color: var(--text); }
.signoff-opts input { width: auto; margin-top: 2px; }
.signoff-label { display: block; font-size: 0.72rem; color: var(--text-muted); margin: 11px 0 4px; }
.signoff-form input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
    background: var(--bg); color: var(--text); font-size: 0.82rem; }
.signoff-submit { margin-top: 14px; padding: 10px 18px; border: 0; border-radius: 8px;
    background: var(--success); color: #fff; font-weight: 700; font-size: 0.86rem; cursor: pointer; }
.signoff-submit:hover { opacity: 0.9; }
.signoff-submit:disabled { opacity: 0.6; cursor: default; }
.signoff-ok { display: none; background: color-mix(in srgb, var(--success) 16%, var(--surface));
    color: var(--success); border: 1px solid var(--success); border-radius: 8px; padding: 10px 13px;
    margin-top: 12px; font-size: 0.82rem; }


/* ============ DARK THEME: accessibility additions (2026-07-08) ============ */
/* Fix hardcoded light chips so they stay readable on the dark surface. */
:root:not([data-theme="light"]) .badge.low { background:#334155; color:#e2e8f0; }
:root:not([data-theme="light"]) .icd-table { background:#334155; color:#f1f5f9; }
:root:not([data-theme="light"]) .badge.unknown { background:#7f1d1d; color:#fecaca; }
:root:not([data-theme="light"]) .badge.manual  { background:#1e3a8a; color:#bfdbfe; }

/* Key-point highlight: make important spans pop (esp. on dark). Use <mark> or .kp */
mark, .kp {
    background: color-mix(in srgb, var(--kp) 26%, transparent);
    color: var(--text);
    font-weight: 650;
    padding: 0 .28em; border-radius: 3px;
    box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.kp-strong { color: var(--kp); font-weight: 750; }

/* Floating theme toggle — present on every page */
.theme-toggle {
    position: fixed; right: 14px; bottom: 14px; z-index: 9999;
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); box-shadow: 0 2px 10px rgba(0,0,0,.4);
    font-size: 1.2rem; cursor: pointer; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { border-color: var(--primary); }


/* ICD era color-coding (8=amber/oldest, 9=violet, 10=emerald/newest) */
.icd-era-8  { background:#b45309 !important; color:#fff; }
.icd-era-9  { background:#7c3aed !important; color:#fff; }
.icd-era-10 { background:#059669 !important; color:#fff; }
.icd-legend { display:flex; align-items:center; gap:6px; margin-top:6px; flex-wrap:wrap; }
.icd-legend .icd-era { float:none; }
.icd-legend em { color:var(--text-muted); font-size:.7rem; font-style:italic; }

/* Image pane: dark backdrop in dark mode so scanned white pages pop (lightbox feel) */
:root:not([data-theme="light"]) .pane-left .pane-body { background:#0b1220; }


/* --- center the two nav rows: override .topbar's space-between (source-order + specificity) --- */
nav.topbar-tools, nav.topbar-cats { justify-content: center; }
nav.topbar-tools .cat-tab { flex: 0 0 auto; }
nav.topbar-cats .category-tabs { flex: 0 1 auto; justify-content: center; }
nav.topbar-cats > .compact-select { flex: 0 0 auto; }

/* --- in-app view overlay: Clinical / CRS embedded (one window) --- */
.app { position: relative; }
.view-overlay { position: absolute; inset: 0; z-index: 30; background: var(--bg);
    display: flex; flex-direction: column; }
.view-overlay.hidden { display: none; }
.view-bar { display: flex; align-items: center; gap: 12px; padding: 6px 12px;
    background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.view-back { border: 1px solid var(--border); background: var(--bg); color: var(--text);
    border-radius: 999px; padding: 4px 12px; font-size: 0.8rem; cursor: pointer; }
.view-back:hover { border-color: var(--primary); color: var(--primary); }
.view-title { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.view-frame { flex: 1 1 auto; width: 100%; border: 0; background: var(--bg); }
/* embedded page hides its own header/back-link so the overlay bar is the only chrome */
.embedded .patient-header, .embedded .trends-back { display: none !important; }

/* --- auth corner (settings / logout) --- */
.auth-corner{position:absolute;top:8px;right:12px;z-index:40;display:flex;gap:12px}
.auth-corner a{font-size:.72rem;color:#fff;opacity:.85;text-decoration:none;background:rgba(255,255,255,.15);padding:3px 10px;border-radius:999px}
.auth-corner a:hover{opacity:1}
.auth-corner a.attest-link{font-weight:700;opacity:1;background:var(--warning);color:#1c1917;padding:5px 14px;font-size:.78rem;
  box-shadow:0 0 0 2px color-mix(in srgb, var(--warning) 40%, transparent)}
.auth-corner a.attest-link:hover{background:color-mix(in srgb, var(--warning) 85%, #000)}
.attest-badge{display:inline-block;background:#7f1d1d;color:#fecaca;border-radius:999px;padding:0 6px;margin-left:4px;font-weight:800}
