/*
 * NurseCharts clinical display contrast compatibility layer
 * --------------------------------------------------------
 * Date: 2026-11-16
 * Purpose: Readable submitted records and previews with the EXISTING light/dark
 *          theme. This file deliberately changes presentation only.
 *
 * The global theme.css applies a dark background to Bootstrap .card with
 * !important. Legacy clinical views have explicit light-theme text colors on
 * their value/label elements. In dark mode this creates dark text on dark
 * cards, particularly in the MAR. Other clinical views intentionally keep
 * white paper-style surfaces; those need dark inherited text even when the
 * application's body text is light.
 *
 * Keep all rules screen-only: printed clinical records/PDFs retain their
 * existing print-specific colors and layout. Do not override urgency/status
 * colors (vital alerts, completion badges, warning chips, etc.).
 */

@media screen {
    /* Dark Bootstrap cards: match the legibility already implemented in the
       submitted ISP Goal form, without altering clinical value semantics. */
    html[data-theme="dark"] .card :is(
        .info-value, .info-val, .field-value, .field-value-pre,
        .preview-value, .detail-value, .nc-field-value
    ):not(.vital-value-warning):not(.text-danger):not(.text-warning):not(.text-success) {
        color: #f8fafc !important;
    }

    html[data-theme="dark"] .card :is(
        .info-label, .info-lbl, .field-label, .preview-label,
        .detail-label, .nc-field-label
    ) {
        color: #cbd5e1 !important;
    }

    /* Keep blank / unavailable values visibly distinct from real readings.
       Don't change any stored values, validation or clinical warning classes. */
    html[data-theme="dark"] .card :is(
        .info-value, .info-val, .field-value, .preview-value,
        .nc-field-value
    ).empty,
    html[data-theme="dark"] .card .nc-field-empty {
        color: #cbd5e1 !important;
    }

    /* Table text in dark Bootstrap cards: Bootstrap 5 uses --bs-table-color,
       not merely the inherited color of the <table>. Avoid contextual tables
       that explicitly communicate a clinical state by their background. */
    html[data-theme="dark"] .card .table:not(.table-light):not(.table-primary):not(.table-secondary):not(.table-success):not(.table-danger):not(.table-warning):not(.table-info) {
        --bs-table-color: #f8fafc;
        --bs-table-bg: transparent;
        --bs-table-border-color: #475569;
        color: #f8fafc !important;
    }

    /* Bootstrap contextual table headers remain pale even in dark mode. The
       existing theme.css had applied muted LIGHT lettering to these light
       headers with !important. Restore readable ink without changing the
       clinical color coding of the header or any body-level status rows. */
    html[data-theme="dark"] .table thead.table-light th,
    html[data-theme="dark"] .table thead.table-secondary th,
    html[data-theme="dark"] .nc-agency-theme .table thead th {
        color: #334155 !important;
    }
    html[data-theme="dark"] .table thead.table-success th {
        color: #14532d !important;
    }

    /* MAR: its header and clinical information cards turn dark via theme.css.
       The built-in info-value style otherwise stays #111827 (near black). */
    html[data-theme="dark"] :is(.mar-view-page, .mar-preview-page) .card.mar-card .info-value {
        color: #f8fafc !important;
    }
    html[data-theme="dark"] :is(.mar-view-page, .mar-preview-page) .card.mar-card .info-label {
        color: #cbd5e1 !important;
    }

    /* MAR's classic grid has deliberately pale/green header cells, so those
       headings must remain dark while the surrounding dark card stays light. */
    html[data-theme="dark"] :is(.mar-view-page, .mar-preview-page) .mar-grid-table thead th {
        color: #334155 !important;
    }

    /* These surfaces are intentionally paper-white in the existing views.
       The app's dark BODY text must not bleed through as white-on-white.
       We don't recolor their banners, alerts, response chips or badges. */
    html[data-theme="dark"] :is(
        .poc-card, .snv-card, .nc-section, .preview-wrapper,
        .emar-card, .eisp-card, .io-panel, .oasis-form-card,
        .oasis-page-header, .oasis-progress-panel, .oasis-paper
    ) {
        color: #1e293b;
    }

    /* Neutral text on white clinical/paper surfaces needs readable slate
       gray rather than the global dark-mode text-muted (#adb5bd). */
    html[data-theme="dark"] :is(
        .poc-card, .snv-card, .nc-section, .preview-wrapper,
        .emar-card, .eisp-card, .io-panel, .oasis-form-card,
        .oasis-page-header, .oasis-progress-panel, .oasis-paper
    ) .text-muted {
        color: #52647a !important;
    }

    /* Bootstrap tables inside paper-white records must use dark table text;
       the global .table rule was otherwise forcing white on light paper. */
    html[data-theme="dark"] :is(
        .poc-card, .snv-card, .nc-section, .preview-wrapper,
        .emar-card, .eisp-card, .io-panel, .oasis-form-card,
        .oasis-page-header, .oasis-progress-panel, .oasis-paper
    ) .table:not(.table-dark) {
        --bs-table-color: #1e293b;
        --bs-table-bg: transparent;
        color: #1e293b !important;
    }

    /* Preserve muted-but-readable dark ink in the explicit table headings on
       white surfaces; leave intentionally colored clinical status cells alone. */
    html[data-theme="dark"] :is(
        .poc-card, .snv-card, .nc-section, .preview-wrapper,
        .emar-card, .eisp-card, .io-panel, .oasis-form-card, .oasis-paper
    ) .table thead th:not(.text-white):not(.text-light) {
        color: #42526a !important;
    }
}

/* MAR's dark-theme Bootstrap cards must not print as black boxes. The ISP
 * Goal view already has its own print override; keep those rules untouched. */
@media print {
    html[data-theme="dark"] :is(.mar-view-page, .mar-preview-page) .card.mar-card {
        background: #fff !important;
        color: #1e293b !important;
    }
    html[data-theme="dark"] :is(.mar-view-page, .mar-preview-page) .card.mar-card .info-value {
        color: #1e293b !important;
    }
    html[data-theme="dark"] :is(.mar-view-page, .mar-preview-page) .card.mar-card .info-label {
        color: #64748b !important;
    }
}

/* ========================================================================== 
   NurseCharts 2026-11-16, follow-up: app-wide, surface-aware contrast
   --------------------------------------------------------------------------
   The original compatibility layer above handled Bootstrap .card values,
   but not the standalone .snv-card or the nurse dashboard's pale sections.
   All theme corrections below are explicitly screen-only; neither clinical
   data nor stored preferences nor server-rendered PDF templates are changed.
   IMPORTANT: text follows the ACTUAL surface (dark panel vs pale/paper panel).
   Never force all descendant text light or all descendant text dark.
   ========================================================================== */
@media screen {
    :root {
        --nc-ink-on-paper: #1e293b;
        --nc-muted-on-paper: #52647a;
        --nc-ink-on-dark: #f8fafc;
        --nc-muted-on-dark: #cbd5e1;
    }

    /* Skilled Nurse Visit /View: these panels are NOT Bootstrap .card, and
       previously had transparent backgrounds plus hard-coded dark field ink.
       Give the entire panel a real surface for each theme. */
    html[data-theme="light"] .snv-card {
        background-color: #ffffff;
        color: #212529;
    }
    html[data-theme="dark"] .snv-card {
        background-color: #171b21 !important;
        border-color: #475569 !important;
        color: var(--nc-ink-on-dark) !important;
    }
    html[data-theme="dark"] .snv-card .field-label {
        color: var(--nc-muted-on-dark) !important;
    }
    html[data-theme="dark"] .snv-card .field-value:not(.vital-value-warning):not(.text-danger):not(.text-warning):not(.text-success) {
        color: var(--nc-ink-on-dark) !important;
    }
    html[data-theme="dark"] .snv-card .section-divider {
        color: #7dd3fc;
        border-bottom-color: #475569;
    }
    /* Red remains red and clinically conspicuous, but is legible on charcoal.
       Don't change values, thresholds, or status words. */
    html[data-theme="dark"] .snv-card :is(.vital-value-warning, .vital-warning-inline) {
        color: #ff9ca5 !important;
    }

    /* Previews and discharge/plan-of-care panels deliberately keep white
       clinical paper surfaces in both themes. They must NEVER inherit the
       light type color from the dark body, including ordinary values which
       don't carry a dedicated field-value class. */
    html[data-theme="dark"] :is(
        .preview-card, .poc-card, .nc-section, .preview-wrapper,
        .emar-card, .eisp-card, .io-panel, .oasis-form-card,
        .oasis-page-header, .oasis-progress-panel, .oasis-paper
    ) {
        color: var(--nc-ink-on-paper) !important;
    }
    html[data-theme="dark"] :is(
        .preview-card, .poc-card, .nc-section, .preview-wrapper,
        .emar-card, .eisp-card, .io-panel, .oasis-form-card,
        .oasis-page-header, .oasis-progress-panel, .oasis-paper
    ) .text-muted {
        color: var(--nc-muted-on-paper) !important;
    }
    html[data-theme="dark"] :is(
        .preview-card, .poc-card, .nc-section, .preview-wrapper,
        .emar-card, .eisp-card, .io-panel, .oasis-form-card,
        .oasis-page-header, .oasis-progress-panel, .oasis-paper
    ) .table:not(.table-dark) {
        --bs-table-color: var(--nc-ink-on-paper);
        color: var(--nc-ink-on-paper) !important;
    }
    html[data-theme="dark"] .preview-card .field-value:not(.vital-value-warning) {
        color: var(--nc-ink-on-paper);
    }

    /* Explicitly pale Bootstrap cards must stay pale. Global theme.css's
       .card background !important otherwise replaces their .bg-light color. */
    html[data-theme="dark"] .card:is(.bg-light, .bg-white, .text-bg-light) {
        background-color: #f8fafc !important;
        color: var(--nc-ink-on-paper) !important;
    }

    /* Light Bootstrap utility surfaces can be embedded in any screen, even
       inside otherwise dark cards. Preserve their light backgrounds while
       restoring readable dark text and secondary labels. */
    html[data-theme="dark"] :is(
        .bg-white, .bg-light, .text-bg-light, .alert-light,
        .modal-body.bg-light
    ) {
        color: var(--nc-ink-on-paper) !important;
    }
    html[data-theme="dark"] :is(
        .bg-white, .bg-light, .text-bg-light, .alert-light,
        .modal-body.bg-light
    ) .text-muted {
        color: var(--nc-muted-on-paper) !important;
    }

    /* Nurse dashboard intentionally retains white/translucent glass cards
       and a pale red Needs Attention panel in either theme. Keep its colored
       status header, chip, icons and action buttons untouched. */
    html[data-theme="dark"] .dash-wrap :is(
        .stat-card, .section-card, .action-card, .nc-incident-report-shortcut,
        .modal-body
    ) {
        color: var(--nc-ink-on-paper) !important;
    }
    html[data-theme="dark"] .dash-wrap :is(
        .stat-card, .section-card, .action-card, .modal-body
    ) .text-muted {
        color: var(--nc-muted-on-paper) !important;
    }
    html[data-theme="dark"] .dash-wrap :is(.stat-sub, .action-sub) {
        color: var(--nc-muted-on-paper) !important;
    }
    /* Needs Attention text was pale (inherited from body) on #fff1f1. */
    html[data-theme="dark"] .dash-wrap .nc-attention {
        color: #262b36 !important;
    }
    html[data-theme="dark"] .dash-wrap .nc-attention .text-muted {
        color: #566176 !important;
    }
    html[data-theme="dark"] .dash-wrap .modal-body .card,
    html[data-theme="dark"] .dash-wrap #quickNotesList .card {
        background-color: #ffffff !important;
        color: var(--nc-ink-on-paper) !important;
    }

    /* Muted draft metadata needs adequate contrast in LIGHT mode too;
       Bootstrap's default muted gray on #fff1f1 is marginal. */
    html[data-theme="light"] .dash-wrap .nc-attention .text-muted {
        color: #566176 !important;
    }

    /* Shared agency workspaces deliberately use a light, blue-tinted canvas
       (including headings/tables). Global theme.css makes any .card dark,
       clashing with this workspace's original light-ink stylesheet.
       Respect the existing agency presentation in both user theme modes. */
    html[data-theme="dark"] .nc-agency-theme .card:not(.bg-primary):not(.bg-dark):not(.bg-success):not(.bg-danger):not(.bg-warning):not(.bg-info),
    html[data-theme="dark"] .nc-agency-theme .nc-surface {
        background: #ffffff !important;
        color: #18355f !important;
    }
    html[data-theme="dark"] .nc-agency-theme .table:not(.table-dark) {
        --bs-table-color: #18355f;
        --bs-table-bg: transparent;
        --bs-table-border-color: #dce8fa;
        color: #18355f !important;
    }
    /* Bootstrap cells have their own --bs-table-color state cascade and
       can remain white even when the parent table has dark readable ink. */
    html[data-theme="dark"] .nc-agency-theme .table:not(.table-dark) tbody td:not(.text-white):not(.text-light) {
        color: #18355f !important;
    }
    html[data-theme="dark"] .nc-agency-theme .table:not(.table-dark) thead th:not(.text-white):not(.text-light) {
        color: #385474 !important;
    }
    html[data-theme="dark"] .nc-agency-theme .table.table-dark :is(th, td) {
        color: #f8fafc !important;
    }
    html[data-theme="dark"] .nc-agency-theme :is(.text-muted, .nc-muted) {
        color: #52647a !important;
    }
    /* Preserve contrast on blue heading strips instead of darkening them. */
    html[data-theme="dark"] .nc-agency-theme .nc-heading-row :is(.nc-muted, .text-muted) {
        color: #f1f5ff !important;
    }
    html[data-theme="dark"] .nc-agency-theme .card-header:not(.bg-primary):not(.bg-dark):not(.bg-info):not(.bg-success):not(.bg-danger):not(.bg-warning) {
        color: #18355f;
    }
}
