/* Platform-wide contrast guard for light UI surfaces.
   The resolved data-theme value also covers the "auto + light system" path. */

/* Keep the fallback deliberately low-specificity and close to the actual
   light surface. A card may contain a dark custom header, so a blanket
   descendant rewrite would corrupt legitimate white heading copy. */
:where(html[data-theme="light"], html[data-user-theme="light"]) :where(
    .modal-content,
    .dropdown-menu,
    .offcanvas,
    .card,
    .list-group-item,
    .accordion-item,
    .toast,
    .popover,
    .swal2-popup,
    .table,
    .dp-card,
    .dp-panel
):where(:not(.bg-dark):not(.text-bg-dark):not(.navbar-custom):not(.site-footer):not(.weather-modal-shell)) > :is(
    .text-muted,
    .text-secondary,
    .form-text,
    .help-text,
    .hint-text,
    .meta-text,
    .soft-muted
),
:where(html[data-theme="light"], html[data-user-theme="light"]) :where(
    .modal-content,
    .dropdown-menu,
    .offcanvas,
    .card,
    .list-group-item,
    .accordion-item,
    .toast,
    .popover,
    .swal2-popup,
    .dp-card,
    .dp-panel
) :where(
    .card-body,
    .modal-body,
    .offcanvas-body,
    .accordion-body,
    .toast-body,
    .popover-body
) > :is(
    .text-muted,
    .text-secondary,
    .form-text,
    .help-text,
    .hint-text,
    .meta-text,
    .soft-muted
) {
    color: #52647a !important;
    opacity: 1 !important;
}

:where(html[data-theme="light"], html[data-user-theme="light"]) :where(
    .modal-content,
    .dropdown-menu,
    .offcanvas,
    .card,
    .list-group-item,
    .accordion-item,
    .toast,
    .popover,
    .swal2-popup,
    .table,
    .dp-card,
    .dp-panel
):where(:not(.bg-dark):not(.text-bg-dark):not(.navbar-custom):not(.site-footer):not(.weather-modal-shell)) > :is(
    .text-light,
    .text-white
):where(:not(.btn):not(.badge):not(.alert):not(.progress-bar):not(.text-bg-primary):not(.text-bg-secondary):not(.text-bg-success):not(.text-bg-danger):not(.text-bg-warning):not(.text-bg-info):not(.text-bg-dark)),
:where(html[data-theme="light"], html[data-user-theme="light"]) :where(
    .modal-content,
    .dropdown-menu,
    .offcanvas,
    .card,
    .list-group-item,
    .accordion-item,
    .toast,
    .popover,
    .swal2-popup,
    .dp-card,
    .dp-panel
) :where(
    .card-body,
    .modal-body,
    .offcanvas-body,
    .accordion-body,
    .toast-body,
    .popover-body
) > :is(
    .text-light,
    .text-white
):where(:not(.btn):not(.badge):not(.alert):not(.progress-bar):not(.text-bg-primary):not(.text-bg-secondary):not(.text-bg-success):not(.text-bg-danger):not(.text-bg-warning):not(.text-bg-info):not(.text-bg-dark)) {
    color: #23313b !important;
}

:where(html[data-theme="light"], html[data-user-theme="light"]) :where(
    .modal-content,
    .dropdown-menu,
    .offcanvas,
    .card,
    .list-group-item,
    .accordion-item,
    .toast,
    .popover,
    .swal2-popup,
    .table,
    .dp-card,
    .dp-panel
):where(:not(.bg-dark):not(.text-bg-dark):not(.navbar-custom):not(.site-footer):not(.weather-modal-shell)) :where(
    .badge,
    .btn,
    .alert,
    .progress-bar,
    .text-bg-primary,
    .text-bg-secondary,
    .text-bg-success,
    .text-bg-danger,
    .text-bg-warning,
    .text-bg-info,
    .text-bg-dark
) :is(.text-light, .text-white) {
    color: inherit !important;
}

/* `text-bg-*` helpers define both sides of the colour pair, so their nested
   utility copy should follow the foreground already chosen by Bootstrap. */
:is(html[data-theme="light"], html[data-user-theme="light"]) :is(
    .text-bg-primary,
    .text-bg-secondary,
    .text-bg-success,
    .text-bg-danger,
    .text-bg-warning,
    .text-bg-info,
    .text-bg-dark
) :is(.text-light, .text-white) {
    color: inherit !important;
}

/* Same-node utility collisions such as `bg-white text-white` are not covered
   by descendant selectors above. Keep the light surface and repair the ink. */
:is(html[data-theme="light"], html[data-user-theme="light"]) :is(
    .bg-white,
    .bg-light,
    .table-light
):is(.text-white, .text-light):not(.btn):not(.badge):not(.alert):not(.text-bg-dark) {
    color: #23313b !important;
}

/* Form copy must remain legible without changing the pastel/minimal control
   surface. Disabled controls keep their state through cursor and background. */
:is(html[data-theme="light"], html[data-user-theme="light"]) :is(
    .form-control,
    .form-select,
    .input-group-text
):not(.text-bg-dark):not(.bg-dark) {
    color: #344054;
}

:is(html[data-theme="light"], html[data-user-theme="light"]) :is(
    .form-control,
    .form-select
)::placeholder {
    color: #667085;
    opacity: 1;
}

:is(html[data-theme="light"], html[data-user-theme="light"]) :is(
    .form-control,
    .form-select
):disabled {
    color: #667085;
    -webkit-text-fill-color: #667085;
    opacity: 1;
}

/* Semantic text outside badges/buttons keeps the pastel background but uses
   a foreground that meets normal-copy contrast on light surfaces. */
:is(html[data-theme="light"], html[data-user-theme="light"]) :is(
    .card,
    .modal-content,
    .list-group-item,
    .accordion-item,
    .dropdown-menu,
    .dp-card,
    .dp-panel
) .text-success:not(.btn):not(.badge):not(.alert) {
    color: #047857 !important;
}

:is(html[data-theme="light"], html[data-user-theme="light"]) :is(
    .card,
    .modal-content,
    .list-group-item,
    .accordion-item,
    .dropdown-menu,
    .dp-card,
    .dp-panel
) .text-warning:not(.btn):not(.badge):not(.alert) {
    color: #92400e !important;
}

:is(html[data-theme="light"], html[data-user-theme="light"]) :is(
    .card,
    .modal-content,
    .list-group-item,
    .accordion-item,
    .dropdown-menu,
    .dp-card,
    .dp-panel
) .text-info:not(.btn):not(.badge):not(.alert) {
    color: #17627d !important;
}

@media (forced-colors: active) {
    :is(.card, .modal-content, .dropdown-menu, .offcanvas, .dp-card, .dp-panel) {
        border: 1px solid CanvasText !important;
    }
}
