/* Theme layer. Day is the default and needs no overrides; night overrides tokens and the few surface classes
   that hard-code light colours. Bootstrap's own components follow via data-bs-theme="dark" (set by theme.js). */
html {
    transition: background-color .2s ease;
}

body {
    background-color: var(--surface-page, #e1e6e9);
}

:root[data-aria-mode="night"] {
    color-scheme: dark;
    --surface-page: #0a1627;
    --surface-card: #11233a;
    --surface-card-border: #284462;
}

/* Surfaces */
:root[data-aria-mode="night"] .bg-color-white,
:root[data-aria-mode="night"] .bg-white {
    background-color: var(--surface-card) !important;
}

:root[data-aria-mode="night"] .border,
:root[data-aria-mode="night"] .list-group-item {
    border-color: var(--surface-card-border) !important;
}

/* Brand blues are too dark to read as text on a dark surface, so use the pastel tints instead. */
:root[data-aria-mode="night"] .color-primary,
:root[data-aria-mode="night"] .color-primary-dark {
    color: var(--primary-pastel-pale) !important;
}

:root[data-aria-mode="night"] .color-gray-dark {
    color: #b4bcc2 !important;
}

/* Outline buttons and KPI tiles hard-code a white fill. Only the resting state is changed; their hover rules
   (coloured fill, white text) already work on a dark page. */
:root[data-aria-mode="night"] [class*="button-"][class*="-outline"]:not(:hover),
:root[data-aria-mode="night"] .button-white:not(:hover) {
    background-color: var(--surface-card) !important;
}

:root[data-aria-mode="night"] .button-primary-outline:not(:hover),
:root[data-aria-mode="night"] .button-white:not(:hover) {
    color: var(--primary-pastel-pale);
}

:root[data-aria-mode="night"] .button-error-dark-outline:not(:hover) {
    color: var(--error-light);
}

/* Grey utility fills are used for nested panels (card > panel > row), so each tier gets its own step of
   lightness. Text stays light, so these must be dark fills. */
:root[data-aria-mode="night"] {
    --surface-raised: #172d48;
    --surface-raised-2: #213b5a;
}

:root[data-aria-mode="night"] .bg-color-gray-light {
    background-color: var(--surface-raised) !important;
}

:root[data-aria-mode="night"] .bg-color-gray-medium {
    background-color: var(--surface-raised) !important;
}

:root[data-aria-mode="night"] .bg-color-gray,
:root[data-aria-mode="night"] .bg-color-gray-medium .bg-color-gray-light {
    background-color: var(--surface-raised-2) !important;
}

:root[data-aria-mode="night"] .bd-color-primary,
:root[data-aria-mode="night"] .bd-color-primary-faded {
    border-color: #4f6a82 !important;
}

/* Pastel fills stay light in night mode, so give their text a dark colour instead of the inherited light one */
:root[data-aria-mode="night"] [class*="bg-color-"][class*="-pastel"],
:root[data-aria-mode="night"] .bg-color-secondary-light,
:root[data-aria-mode="night"] .bg-color-success-light {
    color: #10202e;
}

:root[data-aria-mode="night"] .button-primary-dark-outline:not(:hover) {
    color: var(--primary-pastel-pale);
}

:root[data-aria-mode="night"] .text-secondary {
    color: #aab3ba !important;
}

:root[data-aria-mode="night"] .nav-tabs .nav-link.active {
    color: var(--primary-pastel-pale) !important;
}

/* Keep the page legible when images/logos assume a light backdrop */
:root[data-aria-mode="night"] img:not(.logo):not(.brand-logo) {
    filter: brightness(.9);
}

/* Calmer night colours.
   The palette is tuned for a white page: the same fully saturated greens, blues, pinks, reds and mustards look much
   louder as large fills on a dark one. Solid fills (status bars, task circles, tile blocks, the red status box, the
   header and footer) are mixed toward the card surface, which keeps each hue but takes most of the intensity out
   (50-70% of the original; the red status box stays strongest because it is a safety signal). White icons and text on
   them gain contrast because the fills are darker. Only fills are changed: the colour variables are also used for text
   and borders, which stay as they were so they keep passing AA.
   Each percentage is the slider's 50 (the standard look): Stronger (--aria-up, 0-1) moves it to 100 (the original
   colour), Softer (--aria-down, 0-1) takes a few points off so fills stay visible. theme.js sets both. */
:root[data-aria-mode="night"] {
    --calm-success: color-mix(in srgb, var(--success) calc(52% + (100% - 52%) * var(--aria-up, 0) - 8% * var(--aria-down, 0)), var(--surface-card));
    --calm-secondary: color-mix(in srgb, var(--secondary-dark) calc(52% + (100% - 52%) * var(--aria-up, 0) - 8% * var(--aria-down, 0)), var(--surface-card));
    --calm-error-soft: color-mix(in srgb, color-mix(in srgb, var(--error-dark) 50%, #fff) calc(52% + (100% - 52%) * var(--aria-up, 0) - 8% * var(--aria-down, 0)), var(--surface-card));
    --calm-error: color-mix(in srgb, var(--error-dark) calc(70% + (100% - 70%) * var(--aria-up, 0) - 8% * var(--aria-down, 0)), var(--surface-card));
    --calm-primary: color-mix(in srgb, var(--primary) calc(55% + (100% - 55%) * var(--aria-up, 0) - 8% * var(--aria-down, 0)), var(--surface-card));
    --calm-gray: color-mix(in srgb, #8b8b8b calc(50% + (100% - 50%) * var(--aria-up, 0) - 8% * var(--aria-down, 0)), var(--surface-card));
    --calm-pastel: color-mix(in srgb, var(--primary-pastel) calc(50% + (100% - 50%) * var(--aria-up, 0) - 8% * var(--aria-down, 0)), var(--surface-card));
}

:root[data-aria-mode="night"] .bg-color-success-faded,
:root[data-aria-mode="night"] .bg-color-success,
:root[data-aria-mode="night"] .button-success-faded,
:root[data-aria-mode="night"] .button-success {
    background-color: var(--calm-success) !important;
}

:root[data-aria-mode="night"] .bg-color-secondary-dark,
:root[data-aria-mode="night"] .button-secondary-dark {
    background-color: var(--calm-secondary) !important;
}

:root[data-aria-mode="night"] .bg-color-error-faded,
:root[data-aria-mode="night"] .button-error-faded {
    background-color: var(--calm-error-soft) !important;
}

:root[data-aria-mode="night"] .bg-color-error-dark,
:root[data-aria-mode="night"] .bg-color-error,
:root[data-aria-mode="night"] .button-error-dark,
:root[data-aria-mode="night"] .button-error {
    background-color: var(--calm-error) !important;
}

:root[data-aria-mode="night"] .bg-color-primary,
:root[data-aria-mode="night"] .button-primary {
    background-color: var(--calm-primary) !important;
}

:root[data-aria-mode="night"] .bg-color-gray-dark,
:root[data-aria-mode="night"] .button-gray-dark {
    background-color: var(--calm-gray) !important;
}

/* The light-blue chips and banners on the details page (URN, referral source, buttons) are `button-primary-pastel`: a pale
   fill with white text, which was 2.54:1 and very bright on a dark page. The calmer fill makes the white text pass (about 6:1). */
:root[data-aria-mode="night"] .button-primary-pastel:not(:hover) {
    background-color: var(--calm-pastel) !important;
    border-color: var(--calm-pastel) !important;
    color: var(--white);
}

/* Header and footer gradient (the --primary-dark to --primary gradient shared by the app header and the footer) */
:root[data-aria-mode="night"] .bg-primary-secondary-gradient {
    background: linear-gradient(25deg, color-mix(in srgb, var(--primary-dark) 60%, var(--surface-card)) 27%, var(--calm-primary) 67%);
}

/* Outline buttons and tiles fill with the full colour on hover: use the calm fills, so a hover is not a flash of the
   brightest colour on the page */
:root[data-aria-mode="night"] .button-success-faded-outline:hover,
:root[data-aria-mode="night"] .button-success-outline:hover {
    background-color: var(--calm-success) !important;
}

:root[data-aria-mode="night"] .button-secondary-dark-outline:hover {
    background-color: var(--calm-secondary) !important;
}

:root[data-aria-mode="night"] .button-error-faded-outline:hover {
    background-color: var(--calm-error-soft) !important;
}

:root[data-aria-mode="night"] .button-error-dark-outline:hover,
:root[data-aria-mode="night"] .button-error-outline:hover {
    background-color: var(--calm-error) !important;
}

:root[data-aria-mode="night"] .button-primary-outline:hover {
    background-color: var(--calm-primary) !important;
}

/* Tile text takes its colour from the tile's button class: the full-strength mustard (90% saturated), green and pink
   were the loudest text on the page. Softer, less saturated tones of the same hues still pass AA (all above 6:1 on the
   card). The error one was the brightest red-pink. */
:root[data-aria-mode="night"] .button-secondary-dark-outline:not(:hover) {
    color: #cbb673;
}

:root[data-aria-mode="night"] .button-success-faded-outline:not(:hover),
:root[data-aria-mode="night"] .button-success-outline:not(:hover) {
    color: #93c09d;
}

:root[data-aria-mode="night"] .button-error-faded-outline:not(:hover) {
    color: #cfa2a6;
}

:root[data-aria-mode="night"] .button-gray-dark-outline:not(:hover) {
    color: #aeb6bc;
}

:root[data-aria-mode="night"] .button-error-dark-outline:not(:hover) {
    color: #e0888c;
}

/* The warning triangle in the red status box was var(--error-dark) on the dark card (about 1.5:1, barely visible): a lighter
   red so it reads, without the full-strength fill */
:root[data-aria-mode="night"] .color-error-dark {
    color: #d4797f !important;
}

/* Raised sections in night mode.
   In light mode the sections of the encounter list (totals tiles, search and sort bar, situational dashboard, filter
   chip, patient status box, "Go to record") are separated by drop shadows on a white card. A dark navy shadow is invisible
   on a dark card, and they all sat on the same surface (#11233a), so nothing separated them. Dark interfaces show
   elevation with a lighter surface instead: each of these is one step lighter than the card (--surface-raised), with a
   fine light top edge and a soft dark shadow for the larger ones. Light mode is unchanged. */
:root[data-aria-mode="night"] {
    --night-lift: inset 0 1px 0 rgba(255, 255, 255, .05), 0 2px 8px rgba(0, 0, 0, .45);
    --night-lift-small: inset 0 1px 0 rgba(255, 255, 255, .05);
}

/* `--primary-light` (#0085b3) is 3.8:1 on the card and 3.3:1 on a raised surface, so text in it (the search box, links) fails AA
   in night mode; the softer blue already used for the URN link is about 5.2:1 */
:root[data-aria-mode="night"] .color-primary-light {
    color: #4caaca !important;
}

@media (prefers-reduced-motion: reduce) {
    html {
        transition: none;
    }
}

/* My profile in night mode: header and cards sit on the raised surface like the list's sections */
:root[data-aria-mode="night"] .profile-header,
:root[data-aria-mode="night"] .profile-card {
    background-color: var(--surface-raised);
    border-color: var(--surface-card-border);
    box-shadow: var(--night-lift-small);
}

:root[data-aria-mode="night"] .profile-avatar {
    background-color: color-mix(in srgb, var(--primary) 70%, var(--surface-card));
}

:root[data-aria-mode="night"] .profile-pill {
    background-color: color-mix(in srgb, var(--primary-pastel-pale) 12%, transparent);
    border-color: color-mix(in srgb, var(--primary-pastel-pale) 35%, transparent);
    color: #cfe5f5;
}

:root[data-aria-mode="night"] .profile-missing {
    color: var(--error-light);
}

:root[data-aria-mode="night"] .theme-switch-row,
:root[data-aria-mode="night"] .theme-group,
:root[data-aria-mode="night"] .theme-current .theme-preview {
    border-color: var(--surface-card-border);
}

:root[data-aria-mode="night"] .theme-switch-track {
    background-color: var(--surface-card-border);
}

:root[data-aria-mode="night"] .theme-switch[aria-checked="true"] .theme-switch-track,
:root[data-aria-mode="night"] .theme-card-badge {
    background-color: var(--primary-pastel);
}

:root[data-aria-mode="night"] .theme-card-badge {
    box-shadow: 0 0 0 2px var(--surface-raised);
    color: #0d1820;
}

:root[data-aria-mode="night"] .theme-card-thumb {
    box-shadow: 0 0 0 1px var(--surface-card-border);
}

:root[data-aria-mode="night"] .theme-card:hover .theme-card-thumb {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-pastel) 55%, transparent);
}

:root[data-aria-mode="night"] .theme-card:has(input:checked) .theme-card-thumb {
    box-shadow: 0 0 0 3px var(--primary-pastel);
}

:root[data-aria-mode="night"] .profile-card .theme-card:has(input:checked),
:root[data-aria-mode="night"] .theme-pick-hint {
    color: #fff;
}

:root[data-aria-mode="night"] .theme-group > summary:hover {
    background-color: color-mix(in srgb, var(--primary-pastel) 8%, transparent);
}

:root[data-aria-mode="night"] .theme-group-on {
    background-color: color-mix(in srgb, var(--primary-pastel) 16%, transparent);
    color: #fff;
}

/* About in night mode: the user grid hairlines follow the card border */
:root[data-aria-mode="night"] .about-users th,
:root[data-aria-mode="night"] .about-users td {
    border-bottom-color: var(--surface-card-border);
}

/* Seasonal decorations in the side margins (see each theme's stylesheet): how much of its full size a decoration keeps
   between 1300px and 1699px. The page is 1140px wide up to 1399px and 1320px from 1400px, so the margin is about 80-130px,
   then 40-90px, then 90-190px; the steps follow that. At 1700px and up the decorations are full size. */
:root {
    --decor-scale: 1;
}

@media (min-width: 1300px) and (max-width: 1399.98px) {
    :root { --decor-scale: .45; }
}

@media (min-width: 1400px) and (max-width: 1499.98px) {
    :root { --decor-scale: .3; }
}

@media (min-width: 1500px) and (max-width: 1599.98px) {
    :root { --decor-scale: .5; }
}

@media (min-width: 1600px) and (max-width: 1699.98px) {
    :root { --decor-scale: .75; }
}

/* Login menu dropdown on the dark surface */
:root[data-aria-mode="night"] .login-menu .dropdown-menu {
    --bs-dropdown-bg: var(--surface-raised, var(--surface-card));
    --bs-dropdown-link-color: #e3e8ec;
    --bs-dropdown-link-hover-color: #fff;
    --bs-dropdown-link-hover-bg: rgba(255, 255, 255, .08);
    --bs-dropdown-divider-bg: var(--surface-card-border);
    border-color: var(--surface-card-border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}

:root[data-aria-mode="night"] .login-menu .dropdown-menu > li:last-child .dropdown-item {
    color: #e59aa0;
}

/* Themes with a character cursor (wand, ball, medal) set it on the whole page, so over the message history there was nothing to
   show where a click-and-drag would start. Over the history text the cursor is the text cursor, so the starting point is clear
   when copying a link or a message. Buttons and links inside keep their own cursors. */
:root[data-aria-theme] .message-history-content,
:root[data-aria-theme] .messaging-history-row {
    cursor: text;
}

:root[data-aria-theme] .message-history-content :is(a, button, [type="button"]) {
    cursor: pointer;
}


/* ---- ARIA components in night mode ---- */

/* Header, footer and the nav overlay use the flat brand navy */
:root[data-aria-mode="night"] {
    --brand-bar: #1a2c4a;
    --label-muted: #9fb2c8;
}

/* Page title colour: the brand blue is unreadable on dark */
:root[data-aria-mode="night"] h1.color-primary {
    color: var(--primary-pastel-pale) !important;
}

/* Manage Users */
:root[data-aria-mode="night"] .manage-role-row {
    border-top-color: var(--surface-card-border);
}

:root[data-aria-mode="night"] .manage-role-dept {
    color: color-mix(in srgb, var(--primary-pastel) 85%, white);
    background-color: color-mix(in srgb, var(--primary-pastel) 16%, transparent);
}

:root[data-aria-mode="night"] .manage-role-remove:not(:hover) {
    color: #e59aa0;
    border-color: #b8656d !important;
}

/* Logged-out card */
:root[data-aria-mode="night"] .logged-out-card {
    background-color: var(--surface-card);
    border-color: var(--surface-card-border);
    box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
}

:root[data-aria-mode="night"] .logged-out-title {
    color: #e3e8ec;
}

:root[data-aria-mode="night"] .logged-out-icon {
    color: #8fd99a;
}

:root[data-aria-mode="night"] .logged-out-icon.signing-in-icon {
    color: #9cc9ec;
}

:root[data-aria-mode="night"] .logged-out-action {
    background-color: color-mix(in srgb, var(--primary) 55%, var(--surface-card)) !important;
    border-color: color-mix(in srgb, var(--primary) 55%, var(--surface-card)) !important;
}

/* Support page */
:root[data-aria-mode="night"] .rf-step-card,
:root[data-aria-mode="night"] .rf-accordion-summary,
:root[data-aria-mode="night"] .rf-accordion-body {
    background-color: var(--surface-card);
    border-color: var(--surface-card-border);
}

:root[data-aria-mode="night"] .rf-accordion {
    border-color: var(--surface-card-border);
}

:root[data-aria-mode="night"] .rf-accordion-summary,
:root[data-aria-mode="night"] .rf-accordion-body strong {
    color: var(--primary-pastel-pale);
}

/* The pastel notices keep their light fill, so their text must be dark */
:root[data-aria-mode="night"] .rf-clinical-alert,
:root[data-aria-mode="night"] .rf-clinical-alert *,
:root[data-aria-mode="night"] .rf-known-issues-banner,
:root[data-aria-mode="night"] .rf-known-issues-banner * {
    color: #3b0d12;
}

:root[data-aria-mode="night"] .rf-known-issue-card {
    background-color: var(--surface-card);
}

/* ---- rules naming the sport and fandom themes (from VirtualED) ---- */

/* Add New Patient form: the pastel and mustard fills are calmer in night mode, so the text goes back to white */
:root[data-aria-mode="night"] .button-primary-pastel.form-action:not(:hover) {
    color: #fff;
}

:root[data-aria-mode="night"] .button-secondary-dark.form-action {
    color: #fff !important;
}

:root[data-aria-mode="night"] .form-floating > label.text-secondary {
    color: #aab3ba !important;
}

:root[data-aria-mode="night"] .button-primary-pastel.form-pill:not(:hover) {
    color: #fff;
}

/* the brand blue is too dim for the small field icons on a dark card */
:root[data-aria-mode="night"] .form-icon {
    color: var(--primary-pastel-pale);
}

/* Totals tiles in night mode (tinted from each tile's --accent) */
:root[data-aria-mode="night"] #PersistentWidgets .encounter-tile .tile-icon {
    color: color-mix(in srgb, #fff calc(100% * var(--aria-solid, 0)), color-mix(in srgb, var(--accent) 55%, #cfd6dc)) !important;
    background: color-mix(in srgb, color-mix(in srgb, var(--accent) 72%, #000) calc(100% * var(--aria-solid, 0)), color-mix(in srgb, var(--accent) min(26%, calc(16% * var(--aria-tint, 1))), #11233a)) !important;
}

:root[data-aria-mode="night"] #PersistentWidgets .encounter-tile .tile-value,
:root[data-aria-mode="night"] #PersistentWidgets .tile-workflow .tile-status {
    color: color-mix(in srgb, var(--accent) calc(22% * (1 - 0.8 * var(--aria-up, 0))), #d5dce1) !important;
}

/* Search, sort and filter chips in night mode */
:root[data-aria-mode="night"] #ManageSearchBar #search_id {
    border-color: color-mix(in srgb, var(--primary-pastel) 40%, transparent) !important;
    background: var(--surface-raised);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
}

:root[data-aria-mode="night"] #ManageSearchBar #search_id:focus-within {
    border-color: var(--primary-pastel) !important;
    box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--primary-pastel) 22%, transparent);
}

:root[data-aria-mode="night"] #ManageSearchBar .sort-group .btn:not(.sort-active):not(.sort-reset),
:root[data-aria-mode="night"] #ManageSearchBar .manage-duplicates-toggle:not(.is-active) {
    background: var(--surface-raised) !important;
    border-color: color-mix(in srgb, var(--primary-pastel) 40%, transparent) !important;
}

:root[data-aria-mode="night"] #ManageSearchBar .sort-group .btn.sort-active {
    color: color-mix(in srgb, var(--tertiary) 55%, #d9dfe4) !important;
    background: color-mix(in srgb, var(--tertiary) 6%, var(--surface-raised)) !important;
    border-color: color-mix(in srgb, var(--tertiary) 28%, transparent) !important;
    box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--tertiary) 55%, transparent);
}

:root[data-aria-mode="night"] #ManageSearchBar .sort-group .btn.sort-active:hover,
:root[data-aria-mode="night"] #ManageSearchBar .sort-group .btn.sort-active.show {
    background: color-mix(in srgb, var(--tertiary) 12%, var(--surface-raised)) !important;
}

:root[data-aria-mode="night"] #ManageSearchBar .sort-reset {
    color: color-mix(in srgb, var(--tertiary) 55%, #d9dfe4);
    background: transparent;
    border-color: color-mix(in srgb, var(--tertiary) 28%, transparent);
}

:root[data-aria-mode="night"] #ManageSearchBar .sort-reset:hover {
    background: color-mix(in srgb, var(--tertiary) 12%, transparent);
}

:root[data-aria-mode="night"] #ManageSearchBar .manage-duplicates-toggle.is-active {
    color: #fff !important;
    background: color-mix(in srgb, var(--primary-pastel) 16%, var(--surface-card)) !important;
    border-color: var(--primary-pastel) !important;
}

:root[data-aria-mode="night"] #SelectedFilters > div {
    border: 1px solid var(--surface-card-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3) !important;
}

:root[data-aria-mode="night"] #SelectedFilters .tags-hover:focus-visible {
    outline-color: var(--primary-pastel);
}

/* Situational dashboard in night mode */
:root[data-aria-mode="night"] #FilterWidgets .accordion {
    border-color: color-mix(in srgb, var(--primary-pastel) 22%, transparent) !important;
}

:root[data-aria-mode="night"] #FilterWidgets .accordion-button {
    color: var(--primary-pastel-pale) !important;
}

:root[data-aria-mode="night"] #FilterWidgets .accordion-button:hover {
    background: color-mix(in srgb, var(--primary-pastel) 8%, transparent) !important;
}

:root[data-aria-mode="night"] #filterItemsId .sd-card {
    --accent: var(--primary-pastel);
    background: color-mix(in srgb, var(--primary-pastel) 4%, var(--surface-card));
    border-color: color-mix(in srgb, var(--primary-pastel) 20%, transparent) !important;
}

:root[data-aria-mode="night"] #filterItemsId .sd-card.sd-alert {
    --accent: #f08a96;
}

:root[data-aria-mode="night"] #filterItemsId .sd-card.sd-role {
    --accent: #7fd18a;
}

:root[data-aria-mode="night"] #filterItemsId .sd-count {
    color: color-mix(in srgb, var(--accent) calc(80% * (1 - 0.8 * var(--aria-up, 0))), #fff) !important;
    background: color-mix(in srgb, var(--accent) min(100%, calc(12% * var(--aria-tint, 1))), var(--surface-card)) !important;
}

:root[data-aria-mode="night"] #filterItemsId .sd-row:hover .sd-count,
:root[data-aria-mode="night"] #filterItemsId .sd-item:hover .sd-count {
    background: color-mix(in srgb, var(--accent) min(100%, calc(22% * var(--aria-tint, 1))), var(--surface-card)) !important;
}

:root[data-aria-mode="night"] #filterItemsId .sd-caption {
    color: #9aa5ae !important;
}

:root[data-aria-mode="night"] #filterItemsId .sd-date {
    border-color: color-mix(in srgb, var(--primary-pastel) 40%, transparent);
}

:root[data-aria-mode="night"] #filterItemsId .sd-date:focus {
    border-color: var(--primary-pastel);
    box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--primary-pastel) 22%, transparent);
}

/* Acute Outreach car rows: the light per-car fills are for day mode; at night each row is a dark tint of the accent */
:root[data-aria-mode="night"] #PersistentWidgets .tile-car {
    background: color-mix(in srgb, var(--accent) min(100%, calc(10% * var(--aria-tint, 1))), var(--surface-card)) !important;
}

:root[data-aria-mode="night"] #PersistentWidgets .tile-car + .tile-car {
    border-top-color: color-mix(in srgb, var(--accent) min(100%, calc(30% * var(--aria-tint, 1))), transparent);
}

:root[data-aria-mode="night"] #PersistentWidgets .tile-car-name {
    color: color-mix(in srgb, var(--accent) calc(22% * (1 - 0.8 * var(--aria-up, 0))), #d5dce1) !important;
}

/* Encounters list rows in night mode */
:root[data-aria-mode="night"] .sl-row {
    --label-muted: #9fb2c8;
}

:root[data-aria-mode="night"] .sl-row .sl-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3) !important;
}

:root[data-aria-mode="night"] .sl-row:hover .sl-card {
    box-shadow: 0 .1rem .6rem color-mix(in srgb, var(--accent) min(100%, calc(35% * var(--aria-tint, 1))), transparent) !important;
}

:root[data-aria-mode="night"] .sl-row .sl-rail {
    background: color-mix(in srgb, var(--accent) min(100%, calc(20% * var(--aria-tint, 1))), var(--surface-card)) !important;
    color: color-mix(in srgb, var(--accent) calc(55% * (1 - 0.8 * var(--aria-up, 0))), #fff);
}

:root[data-aria-mode="night"] .sl-row .sl-rail svg {
    color: color-mix(in srgb, var(--accent) calc(55% * (1 - 0.8 * var(--aria-up, 0))), #fff) !important;
}

:root[data-aria-mode="night"] .sl-row .urn-value {
    color: color-mix(in srgb, var(--primary-light, #0085b3) 70%, #fff);
}

:root[data-aria-mode="night"] .sl-row .sl-action {
    background: var(--surface-card) !important;
}

:root[data-aria-mode="night"] .sl-row .sl-action {
    border-color: color-mix(in srgb, var(--accent) min(100%, calc(60% * var(--aria-tint, 1))), var(--surface-card)) !important;
}

:root[data-aria-mode="night"] .sl-row .sl-action .fs-x-small {
    color: color-mix(in srgb, var(--accent) calc(40% * (1 - 0.8 * var(--aria-up, 0))), #d3d9de);
}

/* "Go to record" (card icon and table button): the status colour class leaves the resting text and icon full-strength
   red on the dark card, so both take the same soft tint as the card label. Hover keeps the existing rules. */
:root[data-aria-mode="night"] .sl-row .sl-action:not(:hover),
:root[data-aria-mode="night"] .encounter-table .et-actions .btn:not(:hover) {
    color: color-mix(in srgb, var(--accent) calc(40% * (1 - 0.8 * var(--aria-up, 0))), #d3d9de) !important;
}

:root[data-aria-mode="night"] .encounter-table .et-actions .btn:not(:hover) {
    border-color: color-mix(in srgb, var(--accent) min(100%, calc(60% * var(--aria-tint, 1))), var(--surface-card)) !important;
}

@media (min-width: 1051px) {
    :root[data-aria-mode="night"] .sl-row .encounter-cell .sl-action {
        background: color-mix(in srgb, var(--accent) min(100%, calc(14% * var(--aria-tint, 1))), var(--surface-card)) !important;
    }

    :root[data-aria-mode="night"] .sl-row .encounter-cell .sl-action:hover {
        background: color-mix(in srgb, var(--accent) min(100%, calc(26% * var(--aria-tint, 1))), var(--surface-card)) !important;
    }
}

:root[data-aria-mode="night"] .sl-row .reason-plan-tooltip {
    border: 1px solid rgba(255, 255, 255, .12);
    border-left: 4px solid color-mix(in srgb, var(--accent) 70%, #fff);
    background: color-mix(in srgb, #fff 7%, var(--surface-card));
    box-shadow: 0 .6rem 1.6rem rgba(0, 0, 0, .55);
}

:root[data-aria-mode="night"] .sl-row .sl-tip-icon {
    background: color-mix(in srgb, var(--accent) min(100%, calc(35% * var(--aria-tint, 1))), var(--surface-card));
    color: color-mix(in srgb, var(--accent) calc(20% * (1 - 0.8 * var(--aria-up, 0))), #f3f5f7);
}

:root[data-aria-mode="night"] .sl-row .sl-rail > svg:first-child {
    background: color-mix(in srgb, var(--accent) min(100%, calc(20% * var(--aria-tint, 1))), var(--surface-card));
}

:root[data-aria-mode="night"] .sl-row .sl-action:hover .fs-x-small {
    color: #fff;
}

:root[data-aria-mode="night"] .sl-row.sl-open .sl-card {
    background: color-mix(in srgb, var(--accent) 7%, #11233a) !important;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3) !important;
}

:root[data-aria-mode="night"] .sl-row .sl-note {
    background: color-mix(in srgb, var(--note-accent) min(100%, calc(6% * var(--aria-tint, 1))), var(--surface-card));
}

:root[data-aria-mode="night"] .sl-row .sl-note-label,
:root[data-aria-mode="night"] .sl-row .sl-task-user {
    color: #aab3ba;
}

:root[data-aria-mode="night"] .sl-row .sl-note.sl-note-empty {
    background: transparent;
    border-color: color-mix(in srgb, #9aa5ad 45%, transparent) !important;
}


/* Table view of the Encounters list (night) */
:root[data-aria-mode="night"] .encounter-table-wrap {
    --label-muted: #9fb2c8;
    border-color: var(--surface-card-border, #284462);
    box-shadow: 0 2px 14px rgba(0,0,0,.35);
}

:root[data-aria-mode="night"] .encounter-table thead th {
    border-bottom-color: color-mix(in srgb, var(--primary-pastel) 22%, transparent);
}

:root[data-aria-mode="night"] .encounter-table tbody td {
    border-bottom-color: color-mix(in srgb, #fff 8%, transparent);
}

:root[data-aria-mode="night"] .encounter-table .et-chip {
    color: color-mix(in srgb, var(--chip) calc(55% * (1 - 0.8 * var(--aria-up, 0))), #fff);
}

:root[data-aria-mode="night"] .encounter-table .et-task-count {
    color: color-mix(in srgb, #fff calc(60% * var(--aria-up, 0)), var(--primary-pastel)); /* lighter as the row tint behind it deepens */
    background: color-mix(in srgb, var(--primary-pastel) 14%, transparent);
}

:root[data-aria-mode="night"] .encounter-table .urn-chip {
    color: #e8edf1;
}

:root[data-aria-mode="night"] .list-view-switch button {
    color: var(--primary-pastel);
    background: var(--surface-card, #11233a);
}

:root[data-aria-mode="night"] .list-view-switch button.is-active {
    color: #fff;
    background: color-mix(in srgb, var(--primary-pastel) 22%, var(--surface-card, #11233a));
    border-color: var(--primary-pastel);
}

/* Encounter details header (night) */
:root[data-aria-mode="night"] #encounterDetailId {
    --label-muted: #9fb2c8;
}

:root[data-aria-mode="night"] #encounterDetailId .encounter-patient-card,
:root[data-aria-mode="night"] #encounterDetailId .encounter-status-card {
    border-color: var(--surface-card-border, #284462);
    box-shadow: 0 2px 14px rgba(0,0,0,.35);
}

:root[data-aria-mode="night"] #encounterDetailId .encounter-name,
:root[data-aria-mode="night"] #encounterDetailId .encounter-urn {
    color: #e8edf1;
}

:root[data-aria-mode="night"] #encounterDetailId .encounter-back-chevron {
    border-color: var(--primary-pastel);
}

:root[data-aria-mode="night"] #encounterDetailId .et-chip {
    color: color-mix(in srgb, var(--chip) calc(55% * (1 - 0.8 * var(--aria-up, 0))), #fff);
}

/* Encounter details: presentation strip (night) */
:root[data-aria-mode="night"] #encounterDetailId .presentation-strip {
    background: color-mix(in srgb, #fff 4%, var(--surface-card, #11233a));
    border-color: var(--surface-card-border, #284462);
}

:root[data-aria-mode="night"] #encounterDetailId .ps-cell + .ps-cell,
:root[data-aria-mode="night"] #encounterDetailId .ps-cell {
    border-color: color-mix(in srgb, #fff 10%, transparent);
}

:root[data-aria-mode="night"] #encounterDetailId .ps-value,
:root[data-aria-mode="night"] #encounterDetailId .ps-referral-pill {
    color: #e8edf1 !important;
}

:root[data-aria-mode="night"] #encounterDetailId .ps-address-link,
:root[data-aria-mode="night"] #encounterDetailId .presentation-strip .phone-link {
    color: #8fc6ea;
}

:root[data-aria-mode="night"] #encounterDetailId .presenting-chevron {
    border-color: #9aa5ae;
}

/* Encounter details: tasks (night) */
:root[data-aria-mode="night"] #encounterDetailId .task-table .list-group-item.task-row:hover,
:root[data-aria-mode="night"] #encounterDetailId .task-table .list-group-item.task-row.is-selected {
    background-color: color-mix(in srgb, var(--primary-pastel) 16%, transparent) !important;
    color: #cfe4f5;
}
:root[data-aria-mode="night"] #encounterDetailId .task-edit-inner > div:first-child:not(.bg-danger) {
    background: color-mix(in srgb, var(--primary-pastel) 14%, transparent) !important;
    color: #cfe4f5;
}
:root[data-aria-mode="night"] #encounterDetailId .task-edit-inner > div:last-child { background: var(--surface-card); }
:root[data-aria-mode="night"] #encounterDetailId .task-table .task-row:focus-visible { outline-color: #9cc9ec; }
:root[data-aria-mode="night"] #encounterDetailId .task-edit .button-primary-pastel-outline { color: #cfe4f5; border-color: var(--primary-pastel) !important; }

/* Encounter details: patient details tab (night) */
:root[data-aria-mode="night"] #encounterDetailId .pd-row { border-bottom-color: var(--surface-card-border); }
:root[data-aria-mode="night"] #encounterDetailId .pd-row-alt { background: color-mix(in srgb, var(--primary-pastel) 7%, transparent); }
:root[data-aria-mode="night"] #encounterDetailId .pd-tab { background: color-mix(in srgb, var(--primary-pastel) 16%, var(--surface-card)); color: #cfe4f5; }
:root[data-aria-mode="night"] #encounterDetailId .pd-row-alt .pd-tab { background: color-mix(in srgb, var(--primary-pastel) 22%, var(--surface-card)); }
:root[data-aria-mode="night"] #encounterDetailId .pd-fact > div:last-child > div:first-child { color: #e4ecf2; }
:root[data-aria-mode="night"] #encounterDetailId .pd-row[role="button"]:hover,
:root[data-aria-mode="night"] #encounterDetailId .pd-section.is-open > .pd-row { background-color: color-mix(in srgb, var(--primary-pastel) 14%, transparent); }
:root[data-aria-mode="night"] #encounterDetailId .pd-section { border-bottom-color: var(--surface-card-border); }
:root[data-aria-mode="night"] #encounterDetailId .pd-editor { border-top-color: var(--surface-card-border); }
:root[data-aria-mode="night"] #encounterDetailId .pd-editor .button-primary-pastel-outline { color: #cfe4f5; border-color: var(--primary-pastel) !important; }

/* Encounter details: tabs card (night) */
:root[data-aria-mode="night"] #encounterDetailId .encounter-tabs-card {
    background: var(--surface-card);
    border-color: var(--surface-card-border) !important;
}
:root[data-aria-mode="night"] #encounterDetailId .encounter-tabs-card > .nav-tabs {
    background: var(--surface-raised); border-bottom-color: var(--surface-card-border);
}
:root[data-aria-mode="night"] #encounterDetailId .encounter-tabs-card .nav-link { color: #9aa5ae !important; }
:root[data-aria-mode="night"] #encounterDetailId .encounter-tabs-card .nav-link.active { color: var(--primary-pastel-pale) !important; border-bottom-color: var(--primary-pastel); }
:root[data-aria-mode="night"] #encounterDetailId .encounter-tabs-card .nav-link:hover:not(.active) {
    border-bottom-color: color-mix(in srgb, var(--primary-pastel) 70%, transparent);
    background-color: color-mix(in srgb, var(--primary-pastel) 10%, transparent);
    color: var(--primary-pastel-pale) !important;
}
:root[data-aria-mode="night"] #encounterDetailId .encounter-tabs-card .nav-link:focus-visible { outline-color: var(--primary-pastel); }

/* Encounter details: messages (night) */
:root[data-aria-mode="night"] #encounterDetailId .msg-card,
:root[data-aria-mode="night"] #encounterDetailId .msg-placeholder,
:root[data-aria-mode="night"] #encounterDetailId .msg-channel { border-color: var(--surface-card-border); }
:root[data-aria-mode="night"] #encounterDetailId .msg-title-left { color: #e4ecf2; }
:root[data-aria-mode="night"] #encounterDetailId .msg-template:hover { background: color-mix(in srgb, var(--primary-pastel) 12%, transparent); }
:root[data-aria-mode="night"] #encounterDetailId .msg-template.is-selected { background: color-mix(in srgb, var(--primary-pastel) 20%, transparent); color: #cfe4f5; }
:root[data-aria-mode="night"] #encounterDetailId .msg-channel.is-on { background: color-mix(in srgb, var(--primary-pastel) 8%, transparent); }
:root[data-aria-mode="night"] #encounterDetailId .msg-channel.is-off { background: color-mix(in srgb, #ffffff 4%, transparent); }
:root[data-aria-mode="night"] #encounterDetailId .msg-channel div.form-control[readonly] { background: var(--surface-raised); }
:root[data-aria-mode="night"] #encounterDetailId .msg-editor .button-primary-pastel-outline,
:root[data-aria-mode="night"] #encounterDetailId .msg-history .button-primary-pastel-outline { color: #cfe4f5; border-color: var(--primary-pastel) !important; }
:root[data-aria-mode="night"] #encounterDetailId .msg-resend { color: #cfe4f5; border-color: var(--primary-pastel);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%23101418' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='M5 10.5l3.2 3.2L15 6.8'/%3E%3C/svg%3E"); }
:root[data-aria-mode="night"] #encounterDetailId .msg-history-head,
:root[data-aria-mode="night"] #encounterDetailId .msg-history hr { border-color: var(--surface-card-border); }

:root[data-aria-mode="night"] .highlight-new {
    background-color: color-mix(in srgb, var(--primary-pastel) 12%, transparent);
    box-shadow: inset 3px 0 0 var(--primary-pastel);
    animation: highlight-new-settle-night 1.5s ease-out;
}
@keyframes highlight-new-settle-night {
    from { background-color: color-mix(in srgb, var(--primary-pastel) 28%, transparent); }
    to   { background-color: color-mix(in srgb, var(--primary-pastel) 12%, transparent); }
}
@media (prefers-reduced-motion: reduce) { :root[data-aria-mode="night"] .highlight-new { animation: none; } }
:root[data-aria-mode="night"] #encounterDetailId .msg-confirm .button-primary-outline { background: var(--surface-card) !important; color: var(--primary-pastel-pale); border-color: var(--primary-pastel) !important; }

/* Workflow task circles (night) */
:root[data-aria-mode="night"] .task-fill-complete { background-color: color-mix(in srgb, var(--success) 60%, #000); }
:root[data-aria-mode="night"] .task-fill-progress { background-color: color-mix(in srgb, var(--secondary-dark) 55%, #000); }
:root[data-aria-mode="night"] .task-fill-none { background-color: color-mix(in srgb, var(--error-dark) 60%, #888); }

:root[data-aria-mode="night"] .encounter-table .et-sort:hover { color: var(--primary-pastel); }
:root[data-aria-mode="night"] .encounter-table th[aria-sort="ascending"],
:root[data-aria-mode="night"] .encounter-table th[aria-sort="descending"] { color: color-mix(in srgb, var(--tertiary) 70%, #fff); }

/* Loading skeletons (night) */
:root[data-aria-mode="night"] .sk { background: color-mix(in srgb, #fff 9%, transparent); }
:root[data-aria-mode="night"] .sk::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.09), transparent); }

/* Encounter details: task list header and pills (night) */
:root[data-aria-mode="night"] #encounterDetailId .task-list-header h3,
:root[data-aria-mode="night"] #encounterDetailId .task-count { color: #e3e8ec; }
:root[data-aria-mode="night"] #encounterDetailId .task-status { background: color-mix(in srgb, var(--pill) 30%, transparent); color: #f1f4f6; }
:root[data-aria-mode="night"] #encounterDetailId .task-filter { border-color: var(--surface-card-border); }
:root[data-aria-mode="night"] #encounterDetailId .encounter-home-button { color: #cfe4f5; border-color: var(--primary-pastel) !important; }
:root[data-aria-mode="night"] #encounterDetailId .task-table .list-group-item.task-row { color: #e3e8ec; }
:root[data-aria-mode="night"] #encounterDetailId .task-table .list-group-item.task-row:hover,
:root[data-aria-mode="night"] #encounterDetailId .task-table .list-group-item.task-row.is-selected { color: #fff; }
:root[data-aria-mode="night"] #encounterDetailId .task-filter-btn.is-active { background-color: #1f5f94; color: #fff; }
/* the metadata block inside the task editor is a Bootstrap .bg-light row (from the metadata component): dark card at night */
:root[data-aria-mode="night"] #encounterDetailId .task-edit-inner .bg-light {
    background-color: color-mix(in srgb, #fff 4%, var(--surface-card)) !important;
}

/* Batch task list: night (VirtualED look) */
:root[data-aria-mode="night"] #encounterDetailId .task-batch > h3 { color: #e3e8ec !important; }
:root[data-aria-mode="night"] #encounterDetailId .task-batch-create:not(:disabled) {
    background-color: var(--primary-pastel) !important; border-color: var(--primary-pastel) !important; color: #101418;
}

/* Tasks / Batch create tabs: night */
:root[data-aria-mode="night"] #encounterDetailId .encounter-task-tab { color: #9aa5ae; }
:root[data-aria-mode="night"] #encounterDetailId .encounter-task-tab.is-active { color: #e3e8ec; }

/* Batch save error: night */
:root[data-aria-mode="night"] #encounterDetailId .task-batch-error {
    background: color-mix(in srgb, #c0392b 16%, var(--surface-card)); border-left-color: #e07a6e; color: #e3e8ec;
}
:root[data-aria-mode="night"] #encounterDetailId .task-batch-error-body > i { color: #f0a198; }
:root[data-aria-mode="night"] #encounterDetailId .task-batch-error-ack { color: #f3c4be; border-color: #e07a6e; }

/* Batch checkboxes: night */
:root[data-aria-mode="night"] #encounterDetailId .task-batch .form-check-input { background-color: transparent; border-color: #6b7782; }
:root[data-aria-mode="night"] #encounterDetailId .task-batch .form-check-input:checked { background-color: var(--primary-pastel); border-color: var(--primary-pastel);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%23101418' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='M5 10.5l3.2 3.2L15 6.8'/%3E%3C/svg%3E"); }

/* the DOB text in the key-facts block moves toward white (not black) as Stronger deepens the tint */
:root[data-aria-mode="night"] .sl-row .patient-grid .fact-dob {
    color: color-mix(in srgb, #fff calc(55% * var(--aria-up, 0)), var(--label-muted, #5d6872));
}
