/* ==========================================================================
   Theme Switch — premium light/dark pill toggle, shared by admin & frontend.
   Markup: components/admin/theme-switch.blade.php
           components/frontend/theme-switch.blade.php
   Logic:  public/js/admin/app.js and public/js/frontend/app.js
   Loaded after @vite('resources/css/app.css') so tokens are available.
   ========================================================================== */

.theme-switch {
    --thumb-size: 26px;
    --switch-padding: 3px;
    --thumb-travel: 32px;

    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    width: 64px;
    height: 32px;
    padding: var(--switch-padding);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 9999px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    cursor: pointer;
    overflow: hidden;
    transition: background 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.5s ease,
    box-shadow 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.dark .theme-switch {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-color: rgba(255, 255, 255, 0.08);
}

/* Subtle ambient highlight, swaps side on theme change */
.theme-switch::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 22% 50%, rgba(255, 255, 255, 0.55), transparent 55%);
    opacity: 0.7;
    transition: opacity 0.5s ease, background 0.5s ease;
}

.dark .theme-switch::before {
    background: radial-gradient(circle at 78% 50%, rgba(255, 255, 255, 0.18), transparent 60%);
    opacity: 1;
}

.theme-switch-thumb {
    position: absolute;
    top: var(--switch-padding);
    left: var(--switch-padding);
    width: var(--thumb-size);
    height: var(--thumb-size);
    border-radius: 9999px;
    background: linear-gradient(135deg, #FD5C02 0%, #CA4901 100%);
    box-shadow: 0 2px 8px rgba(253, 92, 2, 0.45),
    0 0 0 1px rgba(0, 0, 0, 0.05);
    transform: translateX(0);
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1),
    background 0.5s ease,
    box-shadow 0.3s ease;
    z-index: 1;
}

.theme-switch[aria-checked="true"] .theme-switch-thumb {
    transform: translateX(var(--thumb-travel));
    background: linear-gradient(135deg, #818cf8 0%, #4f46e5 100%);
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.06);
}

.theme-switch-icon {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--thumb-size);
    height: var(--thumb-size);
    transition: color 0.45s ease, transform 0.45s ease, opacity 0.45s ease;
    pointer-events: none;
}

.theme-switch-icon .material-symbols-outlined {
    font-size: 18px;
    font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

/* Light mode: sun is active (over thumb), moon is muted */
.theme-switch[aria-checked="false"] .theme-switch-icon-sun {
    color: #ffffff;
    transform: scale(1);
}

.theme-switch[aria-checked="false"] .theme-switch-icon-moon {
    color: rgba(120, 113, 108, 0.55);
    transform: scale(0.85);
}

/* Dark mode: moon is active (over thumb), sun is muted */
.theme-switch[aria-checked="true"] .theme-switch-icon-sun {
    color: rgba(203, 213, 225, 0.45);
    transform: scale(0.85);
}

.theme-switch[aria-checked="true"] .theme-switch-icon-moon {
    color: #ffffff;
    transform: scale(1);
}

.theme-switch:hover .theme-switch-thumb {
    box-shadow: 0 4px 16px rgba(253, 92, 2, 0.6),
    0 0 0 1px rgba(0, 0, 0, 0.05);
}

.dark .theme-switch:hover .theme-switch-thumb {
    box-shadow: 0 4px 18px rgba(99, 102, 241, 0.65),
    0 0 0 1px rgba(255, 255, 255, 0.06);
}

.theme-switch:active .theme-switch-thumb {
    transform: translateX(0) scale(0.92);
}

.theme-switch[aria-checked="true"]:active .theme-switch-thumb {
    transform: translateX(var(--thumb-travel)) scale(0.92);
}

.theme-switch:focus-visible {
    outline: 2px solid var(--color-ring);
    outline-offset: 3px;
}

/* Brief global color crossfade on toggle. Class is added by JS for ~400ms. */
.theme-transitioning *,
.theme-transitioning *::before,
.theme-transitioning *::after {
    transition: background-color 0.4s ease,
    border-color 0.4s ease,
    color 0.4s ease,
    fill 0.4s ease,
    stroke 0.4s ease,
    box-shadow 0.4s ease !important;
}

/* Respect users who explicitly request reduced motion */
@media (prefers-reduced-motion: reduce) {
    .theme-switch,
    .theme-switch-thumb,
    .theme-switch-icon,
    .theme-switch::before {
        transition-duration: 0.01ms !important;
    }
    .theme-transitioning *,
    .theme-transitioning *::before,
    .theme-transitioning *::after {
        transition-duration: 0.01ms !important;
    }
}
