/* Coordinated theme switch — suppress per-element stagger, one page-level cross-fade */
html.wh-theme-switching *,
html.wh-theme-switching *::before,
html.wh-theme-switching *::after {
    transition: none !important;
    animation-duration: 0s !important;
}

/* Keep pill switch UI feedback during page theme swap */
html.wh-theme-switching .wh-theme-toggle--pill .wh-theme-toggle__track {
    transition: background 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease !important;
}
html.wh-theme-switching .wh-theme-toggle--pill .wh-theme-toggle__glyph,
html.wh-theme-switching .wh-theme-toggle--pill .wh-theme-toggle__thumb-glyph {
    transition: color 0.22s ease, opacity 0.22s ease !important;
}
html.wh-theme-switching .wh-theme-toggle--pill .wh-theme-toggle__thumb {
    transition:
        left 0.22s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.22s ease,
        box-shadow 0.22s ease !important;
}

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 160ms;
    animation-timing-function: ease-in-out;
}

html.wh-theme-switching {
    transition: opacity 160ms ease-in-out;
}

html.wh-theme-switching.wh-theme-fade-out {
    opacity: 0.92;
}

@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: 0.01ms;
    }

    html.wh-theme-switching {
        transition: none;
    }
}

/* Screen-reader only — must load with theme toggle (head), not late page styles */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Sun / moon pill switch (toolbar + feed settings) */
.wh-theme-toggle--pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 0;
    -webkit-tap-highlight-color: transparent;
}
.wh-theme-toggle--pill:focus {
    outline: none;
}
.wh-theme-toggle--pill:focus-visible .wh-theme-toggle__track {
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(34, 90, 234, 0.45);
}
html[data-theme="dark"] .wh-theme-toggle--pill:focus-visible .wh-theme-toggle__track {
    box-shadow: 0 0 0 2px #15181e, 0 0 0 4px rgba(59, 118, 255, 0.55);
}
.wh-theme-toggle--pill:active .wh-theme-toggle__thumb {
    transform: translateY(-50%) scale(0.94);
}
.wh-theme-toggle--pill.is-dark:active .wh-theme-toggle__thumb {
    transform: translateY(-50%) scale(0.94);
}

.wh-theme-toggle__track {
    --wh-theme-pad: 3px;
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    width: 54px;
    height: 30px;
    padding: var(--wh-theme-pad);
    border-radius: 999px;
    background: linear-gradient(180deg, #f3f4f6 0%, #e5e7eb 100%);
    border: 1px solid #d1d5db;
    box-sizing: border-box;
    overflow: hidden;
    transition: background 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
}
.wh-theme-toggle--pill:hover .wh-theme-toggle__track {
    border-color: #9ca3af;
}
/*
 * Pill visuals follow .is-dark only — NOT html[data-theme].
 * data-theme lags during view-transition / opacity animation; coupling them
 * made the track and thumb fight each other mid-toggle.
 */
.wh-theme-toggle--pill.is-dark .wh-theme-toggle__track {
    background: linear-gradient(180deg, #2a303b 0%, #1a1e26 100%);
    border-color: #3a4252;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
}
.wh-theme-toggle--pill.is-dark:hover .wh-theme-toggle__track {
    border-color: #4b5568;
}

.wh-theme-toggle__slot {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    min-width: 0;
    pointer-events: none;
}

.wh-theme-toggle__glyph {
    display: block;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: #5b6b82;
    opacity: 0.5;
    transition: color 0.22s ease, opacity 0.22s ease, transform 0.22s ease;
    pointer-events: none;
}

/* Inactive-side track icons only (active icon lives on the thumb) */
.wh-theme-toggle--pill:not(.is-dark) .wh-theme-toggle__slot--sun .wh-theme-toggle__glyph {
    opacity: 0;
}
.wh-theme-toggle--pill.is-dark .wh-theme-toggle__slot--moon .wh-theme-toggle__glyph {
    opacity: 0;
}

/* Moon path sits slightly left in the 24×24 viewBox */
.wh-theme-toggle__glyph--moon {
    transform: translateX(0.5px);
}

.wh-theme-toggle--pill.is-dark .wh-theme-toggle__slot--sun .wh-theme-toggle__glyph {
    opacity: 0.55;
    color: #a8b0bf;
}

.wh-theme-toggle__thumb-rail {
    position: absolute;
    inset: var(--wh-theme-pad);
    z-index: 2;
    pointer-events: none;
}

.wh-theme-toggle__thumb {
    position: absolute;
    top: 50%;
    left: calc(25% - 11px);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.12),
        0 0 0 0.5px rgba(15, 23, 42, 0.06);
    transition:
        left 0.22s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.22s ease,
        box-shadow 0.22s ease;
    pointer-events: none;
    transform: translateY(-50%);
    transform-origin: center center;
}
.wh-theme-toggle--pill.is-dark .wh-theme-toggle__thumb {
    left: calc(75% - 11px);
    background: #2b66f0;
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.wh-theme-toggle__thumb-glyph {
    display: none;
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    pointer-events: none;
}

.wh-theme-toggle--pill:not(.is-dark) .wh-theme-toggle__thumb-glyph--sun {
    display: block;
    color: #d97706;
}

.wh-theme-toggle--pill.is-dark .wh-theme-toggle__thumb-glyph--moon {
    display: block;
    color: #fff;
    transform: translateX(0.5px);
}

/* Dropdown row labels/icons — CSS-driven off .is-dark (no JS display races). */
.wh-theme-dropdown-row .wh-theme-icon-sun,
.wh-theme-dropdown-row .wh-theme-toggle-label--to-light,
.wh-theme-toggle:not(.wh-theme-toggle--pill) .wh-theme-icon-sun,
.wh-theme-toggle:not(.wh-theme-toggle--pill) .wh-theme-toggle-label--to-light {
    display: none !important;
}
.wh-theme-dropdown-row.is-dark .wh-theme-icon-moon,
.wh-theme-dropdown-row.is-dark .wh-theme-toggle-label--to-dark,
.wh-theme-toggle:not(.wh-theme-toggle--pill).is-dark .wh-theme-icon-moon,
.wh-theme-toggle:not(.wh-theme-toggle--pill).is-dark .wh-theme-toggle-label--to-dark {
    display: none !important;
}
.wh-theme-dropdown-row.is-dark .wh-theme-icon-sun,
.wh-theme-dropdown-row.is-dark .wh-theme-toggle-label--to-light,
.wh-theme-toggle:not(.wh-theme-toggle--pill).is-dark .wh-theme-icon-sun,
.wh-theme-toggle:not(.wh-theme-toggle--pill).is-dark .wh-theme-toggle-label--to-light {
    display: inline-block !important;
}

/* Header toolbar — align with "See same ads?" chip */
.dashboard-header-actions .wh-theme-toggle--toolbar {
    align-self: center;
    margin: 0;
    min-height: 30px;
}

/* Feed settings menu row */
.fw-ad-visibility__row--theme {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 2px;
    cursor: default;
}
.fw-ad-visibility__row--theme .fw-ad-visibility__text {
    flex: 1;
    min-width: 0;
}
.fw-ad-visibility-menu .wh-theme-toggle--pill:focus-visible .wh-theme-toggle__track {
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.9), 0 0 0 4px rgba(59, 130, 246, 0.55);
}

/* Profile menu row — label + pill switch */
.wh-theme-dropdown-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
}
.wh-theme-dropdown-row__label {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    flex: 1;
}
.wh-theme-dropdown-row .wh-theme-toggle--dropdown {
    flex-shrink: 0;
}
