/* ===================================
   THEME TOGGLE COMPONENT - MINIMAL & SMOOTH
   =================================== */

:root {
    --theme-transition-duration: 0.3s;
    --theme-transition-easing: ease;
    --theme-transition: background-color var(--theme-transition-duration) var(--theme-transition-easing), 
                    color var(--theme-transition-duration) var(--theme-transition-easing), 
                    border-color var(--theme-transition-duration) var(--theme-transition-easing),
                    box-shadow var(--theme-transition-duration) var(--theme-transition-easing);
    --interactive-transition: transform 0.15s ease, opacity 0.2s ease;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    background: none;
    border: none;
    color: #374151;
    cursor: pointer;
    font-size: 1.125rem;
    position: relative;
    
    /* Mobile optimizations */
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: manipulation;
    
    /* Ensure minimum touch target size */
    min-width: 44px;
    min-height: 44px;
    
    /* Better font rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* Optimized transitions */
    transition: var(--theme-transition), var(--interactive-transition);
    
    /* Performance optimizations */
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Enhanced focus styles for better accessibility */
.theme-toggle:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 3px;
    border-radius: 50%;
}

/* Disabled state */
.theme-toggle:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
    transform: translateZ(0);
}

/* Icon centering and sizing */
.theme-toggle .theme-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    width: 1.2em;
    height: 1.2em;
    font-size: inherit;
    transition: transform 0.3s ease;
}

/* Proper sr-only positioning */
.theme-toggle .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;
}

/* Dark theme styles */
[data-theme="dark"] .theme-toggle {
    color: #f9fafb;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .theme-toggle {
        width: 2.75rem;
        height: 2.75rem;
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .theme-toggle {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .theme-toggle:focus-visible {
        outline-width: 3px;
        outline-color: currentColor;
    }
    
    .theme-toggle {
        outline: 1px solid currentColor;
        outline-offset: -1px;
        border-radius: 50%;
    }
}

/* Print styles */
@media print {
    .theme-toggle {
        display: none;
    }
}

/* ===================================
   UNIVERSAL SMOOTH THEME TRANSITIONS
   =================================== */

/* Aplicar transiciones uniformes a TODOS los elementos que pueden cambiar con el tema */
*,
*::before,
*::after {
    transition: var(--theme-transition);
}

/* Elementos interactivos con transiciones adicionales pero manteniendo las del tema */
a, 
button, 
input, 
textarea, 
select, 
[role="button"], 
[tabindex]:not([tabindex="-1"]),
.interactive {
    transition: var(--theme-transition), var(--interactive-transition), filter 0.2s ease;
}

/* ===================================
   PERFORMANCE OPTIMIZATIONS SELECTIVAS
   =================================== */

/* Solo optimizar elementos que realmente necesitan will-change */
a:hover,
button:hover,
[role="button"]:hover {
    will-change: transform, opacity;
}

a:not(:hover),
button:not(:hover),
[role="button"]:not(:hover) {
    will-change: auto;
}

/* GPU acceleration solo para elementos interactivos */
.theme-toggle,
button,
a,
[role="button"] {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ===================================
   REDUCED MOTION SUPPORT
   =================================== */

@media (prefers-reduced-motion: reduce) {
    :root {
        --theme-transition-duration: 0.1s;
        --interactive-transition: none;
    }
    
    /* Mantener transiciones de tema pero más rápidas */
    *,
    *::before,
    *::after {
        transition: var(--theme-transition) !important;
        animation: none !important;
        transform: translateZ(0) !important;
    }
    
    /* Eliminar will-change en modo reducido */
    * {
        will-change: auto !important;
    }
}

/* ===================================
   CONTAIN OPTIMIZATIONS
   =================================== */

/* Contener layout shifts solo en elementos grandes */
body {
}

main,
section,
article,
nav,
header,
footer {
    contain: layout style; /* Se mantiene para los otros elementos si es beneficioso */
}

/* ===================================
   UTILITY CLASSES OPCIONALES
   =================================== */

/* Para elementos que NO deben tener transición de tema */
.no-theme-transition,
.no-theme-transition *,
.no-theme-transition *::before,
.no-theme-transition *::after {
    transition: none !important;
}

/* Para forzar transición más lenta en elementos específicos */
.slow-theme-transition {
    transition-duration: 0.5s !important;
}

/* Para forzar transición más rápida en elementos específicos */
.fast-theme-transition {
    transition-duration: 0.15s !important;
}