/* Solo aplica las vars dark del SO cuando el usuario NO ha forzado "light"
   manualmente. Sin este :not(...) el @media gana sobre :root y aparece un
   tercer estado híbrido (vars dark + estilos light) cuando el SO está en
   dark y el usuario elige light. */
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --primary: #0f172a;
        --primary-fg: #ffffff;

        --body-fg: #e5e7eb;
        --body-bg: #0f172a;
        --body-quiet-color: #94a3b8;
        --body-medium-color: #cbd5e1;
        --body-loud-color: #ffffff;

        --breadcrumbs-link-fg: #a78bfa;
        --breadcrumbs-bg: #111827;

        --link-fg: #9f67ff;
        --link-hover-color: #f472b6;
        --link-selected-fg: #c4b5fd;

        --hairline-color: #314158;
        --border-color: #45556c;

        --error-fg: #f472b6;
        --message-success-bg: #0f5c4d;
        --message-warning-bg: #6f4b00;
        --message-error-bg: #7a1f3a;

        --darkened-bg: #111827;
        --selected-bg: #1e2939;
        --selected-row: #1d293d;

        --close-button-bg: #314158;
        --close-button-hover-bg: #45556c;

        color-scheme: dark;
    }
}

html[data-theme="dark"] {
    --primary: #0f172a;
    --primary-fg: #ffffff;

    --body-fg: #e5e7eb;
    --body-bg: #0f172a;
    --body-quiet-color: #94a3b8;
    --body-medium-color: #cbd5e1;
    --body-loud-color: #ffffff;

    --breadcrumbs-link-fg: #a78bfa;
    --breadcrumbs-bg: #111827;

    --link-fg: #9f67ff;
    --link-hover-color: #f472b6;
    --link-selected-fg: #c4b5fd;

    --hairline-color: #314158;
    --border-color: #45556c;

    --error-fg: #f472b6;
    --message-success-bg: #0f5c4d;
    --message-warning-bg: #6f4b00;
    --message-error-bg: #7a1f3a;

    --darkened-bg: #111827;
    --selected-bg: #1e2939;
    --selected-row: #1d293d;

    --close-button-bg: #314158;
    --close-button-hover-bg: #45556c;

    color-scheme: dark;
}

.theme-toggle {
    cursor: pointer;
    border: none;
    padding: 0;
    background: transparent;
    vertical-align: middle;
    margin-inline-start: 0px;
    margin-top: -0px;
}

.theme-toggle svg {
    vertical-align: middle;
    height: 1rem;
    width: 1.rem;
    display: none;
}

.theme-toggle .visually-hidden {
    display: none;
}

html[data-theme="auto"] .theme-toggle .theme-label-when-auto,
html[data-theme="dark"] .theme-toggle .theme-label-when-dark,
html[data-theme="light"] .theme-toggle .theme-label-when-light,
html[data-theme="auto"] .theme-toggle svg.theme-icon-when-auto,
html[data-theme="dark"] .theme-toggle svg.theme-icon-when-dark,
html[data-theme="light"] .theme-toggle svg.theme-icon-when-light {
    display: block;
}
