/* Shared portal theme. Light styles and print output remain unchanged. */
.portal-theme-toggle {
    border: 0; background: transparent; color: #ddd; padding: 15px;
    font: inherit; line-height: 20px; cursor: pointer;
}
.portal-theme-toggle:hover, .portal-theme-toggle:focus-visible { color: #fff; background: #333; }
.portal-theme-toggle:focus-visible { outline: 2px solid #8cc7ff; outline-offset: -3px; }
.portal-theme-toggle[aria-pressed="true"] { color: #b6dbff; background: #253b51; }

@media screen {
    html[data-portal-theme="dark"] {
        color-scheme: dark;
        --portal-ink: #e2e9f2; --portal-muted: #a6b5c6; --portal-blue: #9bccff;
        --portal-blue-dark: #b9ddff; --portal-pale: #203044; --portal-border: #435268;
        --portal-surface: #1c2634; --portal-shadow: 0 8px 28px rgba(0,0,0,.2);
        --forms-ink: #e2e9f2; --forms-muted: #a6b5c6; --forms-blue: #9bccff;
        --forms-blue-dark: #b9ddff; --forms-teal: #8adbd0; --forms-line: #435268;
        --forms-soft: #243244; --forms-page: #121b27; --forms-white: #1c2634; --forms-error: #ffaaa7;
        --ref-ink: #e2e9f2; --ref-muted: #a6b5c6; --ref-blue: #9bccff;
        --ref-blue-dark: #b9ddff; --ref-teal: #8adbd0; --ref-line: #435268;
        --ref-soft: #243244; --ref-info: #203c3b; --ref-warning: #44371f; --ref-error: #ffaaa7;
    }
    html[data-portal-theme="dark"] body { background: #121b27 !important; color: #e2e9f2 !important; }
    html[data-portal-theme="dark"] :is(h1,h2,h3,h4,h5,h6,label,legend) { color: #e2e9f2; }
    html[data-portal-theme="dark"] a { color: #9bccff; }
    html[data-portal-theme="dark"] a:hover { color: #cbe5ff; }
    html[data-portal-theme="dark"] :is(.text-muted,.episode-muted,.episode-kicker,.portal-menu-separator,.client-level) { color: #a6b5c6 !important; }
    html[data-portal-theme="dark"] :is(main,.login-container,.form-section,.portal-card,.portal-menu,.portal-notice,
        .episode-panel,.episode-card,.episode-hero,.episode-section,.episode-tool,.episode-note,.episode-chart-wrap,
        .episode-consent-card,.client-information-group,.client-session-summary,.supervisor-card,
        .assessment-section,.assessment-card,.assessment-heading,.accounts-card,.note-editor,.referral-card,
        .client-form-card,.client-form-hero,.panel,.panel-body,.well,.modal-content,.dropdown-menu) {
        background-color: #1c2634 !important; color: #e2e9f2 !important; border-color: #435268 !important;
    }
    html[data-portal-theme="dark"] :is(fieldset,.episode-detail,.episode-callout,.episode-session-create,.episode-session-actions,
        .episode-inline-action,.supervisor-empty,.panel-heading,.panel-footer,.list-group-item) {
        background-color: #243244 !important; color: #e2e9f2; border-color: #435268 !important;
    }
    html[data-portal-theme="dark"] :is(table,td,th,.devices-grid td,.devices-grid th) { border-color: #435268 !important; }
    html[data-portal-theme="dark"] :is(td,.episode-session-main-row td,.episode-session-actions-row td) {
        background-color: #1c2634 !important; color: #e2e9f2 !important;
    }
    html[data-portal-theme="dark"] :is(th,.episode-list thead th) { background-color: #26364b !important; color: #edf3fa !important; }
    html[data-portal-theme="dark"] tr:nth-child(even) td { background-color: #202d3d !important; }
    html[data-portal-theme="dark"] :is(.table-hover tbody tr:hover td,.episode-list tr:hover td) { background-color: #2d4056 !important; }
    html[data-portal-theme="dark"] :is(.episode-session-main-row.is-inactive td,.episode-session-actions-row.is-inactive td) {
        background-color: #242b35 !important; color: #a8b1bd !important;
    }
    html[data-portal-theme="dark"] .episode-session-actions-row.is-latest-past-week:not(.is-inactive) td { background-color: #234237 !important; }
    html[data-portal-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="hidden"]),
    html[data-portal-theme="dark"] :is(select,textarea,[contenteditable="true"]) {
        background-color: #121c29 !important; color: #edf3fa !important; border-color: #64758a !important;
    }
    html[data-portal-theme="dark"] :is(input,textarea)::placeholder { color: #a2b1c3; opacity: 1; }
    html[data-portal-theme="dark"] :is(input,select,textarea):disabled { color: #a6b5c6 !important; background-color: #283342 !important; }
    html[data-portal-theme="dark"] :is(input[type="checkbox"],input[type="radio"]) { accent-color: #8abfff; }
    html[data-portal-theme="dark"] :is(input,select,textarea,button,a,summary):focus-visible { outline: 2px solid #8cc7ff; outline-offset: 2px; }
    html[data-portal-theme="dark"] :is(.btn-default,.btn-secondary,.btn-light,input[type="submit"],input[type="button"],.episode-action,.episode-session-link) {
        background: #29425e !important; color: #edf3fa !important; border-color: #6682a2 !important; text-shadow: none;
    }
    html[data-portal-theme="dark"] :is(.btn-primary,.btn-success) { color: #fff !important; }
    html[data-portal-theme="dark"] :is(.alert-info,.episode-callout,.episode-badge,.episode-status-pill) {
        background: #213c56 !important; color: #c4e2ff !important; border-color: #527ca2 !important;
    }
    html[data-portal-theme="dark"] :is(.alert-success,.mfa-success,.is-complete) { color: #a5e4bc !important; }
    html[data-portal-theme="dark"] .is-complete { background-color: #213d2d !important; border-color: #4b815e !important; }
    html[data-portal-theme="dark"] :is(.is-neutral,.is-view) { background-color: #26364b !important; color: #c4d7ec !important; border-color: #526a86 !important; }
    html[data-portal-theme="dark"] .alert-success { background: #213d2d !important; border-color: #4b815e !important; }
    html[data-portal-theme="dark"] :is(.alert-warning,.episode-warning,.is-pending) { color: #ffe2a1 !important; }
    html[data-portal-theme="dark"] .is-pending { background-color: #44371f !important; border-color: #aa8447 !important; }
    html[data-portal-theme="dark"] :is(.alert-warning,.episode-warning) { background: #44371f !important; border-color: #aa8447 !important; }
    html[data-portal-theme="dark"] :is(.alert-danger,.error-message,.field-error,.episode-score-alert,.text-danger,[style*="color:Red"],[style*="color: red"]) {
        color: #ffaaa7 !important;
    }
    html[data-portal-theme="dark"] .alert-danger { background: #472829 !important; border-color: #a66060 !important; }
    html[data-portal-theme="dark"] .episode-score-alert { background-color: #472829 !important; }
    html[data-portal-theme="dark"] :is(.navbar,.navbar-default,.navbar-inverse) { background: #192332 !important; border-color: #435268 !important; }
    html[data-portal-theme="dark"] :is(.navbar a,.navbar .portal-theme-toggle) { color: #d4e1ef !important; }
    html[data-portal-theme="dark"] :is(.dropdown-menu a,.portal-menu a) { color: #9bccff !important; }
    html[data-portal-theme="dark"] .episode-chart text { fill: #c3d1e2 !important; }
    html[data-portal-theme="dark"] :is(pre,code) { background-color: #142031; color: #cfe0f4; }
    html[data-portal-theme="dark"] hr { border-color: #435268; }

    /* Dashboard caseload cards and the secondary navigation strip. */
    html[data-portal-theme="dark"] :is(.portal-nav,.portal-menu ul,.slot-summary-column) {
        background: #1c2634 !important; color: #e2e9f2 !important; border-color: #435268 !important;
    }
    html[data-portal-theme="dark"] .slot-summary-list li { border-color: #435268; }
    html[data-portal-theme="dark"] :is(.portal-menu a:hover,.portal-menu a:focus) { background: #30455d !important; border-color: #6682a2 !important; }

    /* Mid-tone section bars sit between the page and content panel shades. */
    html[data-portal-theme="dark"] :is(.slot-summary-column > h2,.client-information-group > h2:first-child,
        .episode-consent-card > h2,.episode-detail-page .episode-section > h2:first-child) {
        background: #7b93ae !important; color: #0b1b2c !important; border-color: #607e9b !important;
    }
    html[data-portal-theme="dark"] :is(.client-information-group,.episode-consent-card,
        .episode-detail-page .episode-section,.episode-detail-page .episode-tool) {
        background-color: #243244 !important;
    }
    html[data-portal-theme="dark"] .client-information-group .episode-detail {
        background: transparent !important; border: 0 !important; box-shadow: none !important;
    }
    html[data-portal-theme="dark"] .client-information-group .episode-detail strong { color: #c1d1e2 !important; }

    /* Expandable headings and their open contents use the same dark surfaces. */
    html[data-portal-theme="dark"] .episode-disclosure {
        background: #243244 !important; color: #e2e9f2 !important; border-color: #52677f !important;
    }
    html[data-portal-theme="dark"] .episode-disclosure > summary { color: #c6e1ff !important; }
    html[data-portal-theme="dark"] :is(.episode-disclosure .episode-note,.episode-disclosure .episode-subsection) {
        background: #1c2634 !important; color: #e2e9f2 !important; border-color: #435268 !important;
    }

    /* Override only the plot canvas/grid, retaining the clinical series colours. */
    html[data-portal-theme="dark"] .episode-chart { background: #162232 !important; border-color: #435268 !important; }
    html[data-portal-theme="dark"] .episode-chart > rect { fill: #162232 !important; }
    html[data-portal-theme="dark"] .episode-chart line[stroke="#dce4ee"] { stroke: #435268 !important; }
    html[data-portal-theme="dark"] .episode-chart text { fill: #cbd8e8 !important; }

    /* Shade each complete session/week together, not each individual table row. */
    html[data-portal-theme="dark"] .episode-list :is(.episode-session-main-row,.episode-session-actions-row) td {
        background-color: #182330 !important; box-shadow: none;
    }
    html[data-portal-theme="dark"] .episode-list .episode-session-actions {
        background: transparent !important;
    }
    html[data-portal-theme="dark"] .episode-list :is(.episode-session-main-row,.episode-session-actions-row).is-alternate-week td {
        background-color: #28394d !important;
    }
    html[data-portal-theme="dark"] .episode-list :is(.episode-session-main-row,.episode-session-actions-row).is-inactive td {
        background-color: #242b35 !important; color: #a8b1bd !important;
    }
    html[data-portal-theme="dark"] .episode-list .episode-session-main-row.is-latest-past-week:not(.is-inactive) td {
        background-color: #1c4032 !important;
    }
    html[data-portal-theme="dark"] .episode-list .episode-session-actions-row.is-latest-past-week:not(.is-inactive) td {
        background-color: #345d49 !important;
    }
    html[data-portal-theme="dark"] .episode-session-week-marker { color: #a2e0b6 !important; }

    /* Supervisor group cards, date panels and attendance controls. */
    html[data-portal-theme="dark"] :is(.supervisor-group,.supervisor-attendance) {
        background: #243244 !important; color: #e2e9f2 !important; border-color: #52677f !important;
    }
    html[data-portal-theme="dark"] .supervisor-member {
        background: #28394d !important; color: #e2e9f2 !important; border-color: #52677f !important;
    }
    html[data-portal-theme="dark"] .supervisor-attendance > .supervisor-date-card {
        background: #1c2634 !important; color: #e2e9f2 !important; border-color: #52677f !important;
    }
    html[data-portal-theme="dark"] .supervisor-attendee {
        background: #28394d !important; color: #e2e9f2 !important;
    }
    html[data-portal-theme="dark"] :is(.supervisor-group-heading h2,.supervisor-section-heading h2,.supervisor-date-card h3) {
        color: #d7e6f7 !important;
    }
    html[data-portal-theme="dark"] :is(.supervisor-member span,.supervisor-group-heading p,.supervisor-section-heading > span) {
        color: #b5c6d9 !important;
    }
    html[data-portal-theme="dark"] .supervisor-status {
        background: #234237 !important; color: #b9ebcb !important; border-color: #598367 !important;
    }
    html[data-portal-theme="dark"] .episode-card[href*="view=assessor"] {
        background-color: #243244 !important;
    }
    html[data-portal-theme="dark"] .episode-card[href*="view=assessor"]:is(:hover,:focus-visible) {
        background-color: #2d4056 !important;
    }
}
