/* =========================
   THEME SWITCH
   IDENTICAL in bds_backend and bds_frontend (web/css/theme-switch.css) —
   edit one, copy it over, and check the two hashes match.

   The light / dark switch (each app's _theme_switch.php partial), driven by
   web/js/theme.js. A knob that slides between a sun and a moon:
   light = knob left, sun showing; dark = knob right, moon showing.

   Its state is drawn from <html data-bs-theme>, which the <head> sets before
   the first paint, so the switch is right before any script runs.

   Size and colours are variables a host can set, so the switch can match the
   controls beside it: the portal's topbar (web/css/topbar.css) makes it as tall
   as its icon buttons; the portal's sign-in page and the storefront header
   retint it. The knob's size and travel follow from the size variables.
========================= */

.theme-switch {
    --ts-width: 60px;
    --ts-height: 32px;
    --ts-pad: 3px;              /* between the track's inner edge and the knob */
    --ts-border-width: 1px;
    --ts-icon-size: 14px;
    --ts-knob-size: calc(var(--ts-height) - 2 * var(--ts-pad) - 2 * var(--ts-border-width));

    --ts-track: rgba(255, 255, 255, 0.14);
    --ts-track-hover: rgba(255, 255, 255, 0.22);
    --ts-border: rgba(255, 255, 255, 0.22);
    --ts-knob: #ffffff;
    --ts-knob-shadow: 0 1px 3px rgba(15, 23, 42, 0.35);
    --ts-sun: #fde68a;
    --ts-moon: #c7d2fe;
    --ts-focus: #ffffff;

    position: relative;
    flex-shrink: 0;
    width: var(--ts-width);
    height: var(--ts-height);
    padding: 0;
    border: var(--ts-border-width) solid var(--ts-border);
    border-radius: 999px;
    background: var(--ts-track);
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

/* A taller touch target than the drawn pill, without changing its look. */
.theme-switch::before {
    content: '';
    position: absolute;
    inset: -7px -4px;
}

.theme-switch:hover {
    background: var(--ts-track-hover);
}

.theme-switch:focus-visible {
    outline: 2px solid var(--ts-focus);
    outline-offset: 2px;
}

.theme-switch-knob {
    position: absolute;
    top: var(--ts-pad);
    left: var(--ts-pad);
    width: var(--ts-knob-size);
    height: var(--ts-knob-size);
    border-radius: 50%;
    background: var(--ts-knob);
    box-shadow: var(--ts-knob-shadow);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease;
}

.theme-switch-icon {
    position: absolute;
    top: var(--ts-pad);
    width: var(--ts-knob-size);
    height: var(--ts-knob-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--ts-icon-size);
    line-height: 1;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.25s ease;
}

.theme-switch-sun {
    right: var(--ts-pad);
    color: var(--ts-sun);
}

.theme-switch-moon {
    left: var(--ts-pad);
    color: var(--ts-moon);
    opacity: 0;
    transform: scale(0.6) rotate(-30deg);
}

/* The knob's travel: the track's width less its height (the knob and the
   padding either side of it). */
[data-bs-theme="dark"] .theme-switch-knob {
    transform: translateX(calc(var(--ts-width) - var(--ts-height)));
}

[data-bs-theme="dark"] .theme-switch-sun {
    opacity: 0;
    transform: scale(0.6) rotate(30deg);
}

[data-bs-theme="dark"] .theme-switch-moon {
    opacity: 1;
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    .theme-switch,
    .theme-switch-knob,
    .theme-switch-icon {
        transition: none;
    }
}
