/* =====================================================
   DARK MODE GLOBAL - PAPO REDAÇÃO
   Suporte completo a dark mode em todo o site
   Detecta preferência do sistema e permite toggle manual
   ===================================================== */

/* =====================================================
   DETECÇÃO AUTOMÁTICA (prefers-color-scheme)
   ===================================================== */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        /* Dark Mode - Cores de Fundo */
        --surface: #1e293b;
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        
        /* Dark Mode - Cores de Texto */
        --text-main: #f1f5f9;
        --text-light: #cbd5e1;
        --text-lighter: #94a3b8;
        --text-inverse: #0f172a;
        
        /* Dark Mode - Bordas */
        --border: #334155;
        --border-medium: #475569;
        --border-hover: #64748b;
        
        /* Dark Mode - Sombras */
        --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
        --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
        --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.6);
        --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
        
        /* Dark Mode - Gradientes de Fundo */
        --gradient-bg: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
        --gradient-button: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
        
        /* Dark Mode - Glassmorphism */
        --glass-bg: rgba(30, 41, 59, 0.8);
        --glass-border: rgba(255, 255, 255, 0.1);
        --glass-light: rgba(255, 255, 255, 0.05);
    }
    
    body:not([data-theme="light"]) {
        background: var(--gradient-bg);
        color: var(--text-main);
    }
    
    body:not([data-theme="light"]) .register-container,
    body:not([data-theme="light"]) .card,
    body:not([data-theme="light"]) .form-content {
        background: var(--surface);
        border-color: var(--border);
    }
    
    body:not([data-theme="light"]) input,
    body:not([data-theme="light"]) select,
    body:not([data-theme="light"]) textarea {
        background: var(--bg-secondary);
        color: var(--text-main);
        border-color: var(--border);
    }
    
    body:not([data-theme="light"]) input:focus,
    body:not([data-theme="light"]) select:focus,
    body:not([data-theme="light"]) textarea:focus {
        border-color: var(--primary);
        background: var(--bg-tertiary);
    }
}

/* =====================================================
   TOGGLE MANUAL (data-theme="dark")
   ===================================================== */
[data-theme="dark"] {
    /* Dark Mode - Cores de Fundo */
    --surface: #1e293b;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    
    /* Dark Mode - Cores de Texto */
    --text-main: #f1f5f9;
    --text-light: #cbd5e1;
    --text-lighter: #94a3b8;
    --text-inverse: #0f172a;
    
    /* Dark Mode - Bordas */
    --border: #334155;
    --border-medium: #475569;
    --border-hover: #64748b;
    
    /* Dark Mode - Sombras */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.6);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    
    /* Dark Mode - Gradientes */
    --gradient-bg: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
    --gradient-button: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    
    /* Dark Mode - Glassmorphism */
    --glass-bg: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-light: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] body {
    background: var(--gradient-bg);
    color: var(--text-main);
}

[data-theme="dark"] .register-container,
[data-theme="dark"] .card,
[data-theme="dark"] .form-content,
[data-theme="dark"] .hero-section,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .plan-card {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-main);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--bg-secondary);
    color: var(--text-main);
    border-color: var(--border);
}

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
    border-color: var(--primary);
    background: var(--bg-tertiary);
}

[data-theme="dark"] .btn-prev {
    background: var(--bg-tertiary);
    color: var(--text-main);
}

[data-theme="dark"] .btn-prev:hover {
    background: var(--border-medium);
}

[data-theme="dark"] .header {
    background: var(--gradient-button);
}

[data-theme="dark"] .login-link {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .login-link:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* =====================================================
   FORÇAR LIGHT MODE (data-theme="light")
   ===================================================== */
[data-theme="light"] {
    --surface: #ffffff;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-main: #0f172a;
    --text-light: #475569;
    --text-lighter: #64748b;
    --border: #e2e8f0;
    --border-medium: #cbd5e1;
}

/* =====================================================
   TRANSIÇÕES SUAVES PARA MUDANÇA DE TEMA
   ===================================================== */
body,
.register-container,
.card,
input,
select,
textarea,
button,
.header,
.login-link {
    transition: background-color 0.3s ease, 
                color 0.3s ease, 
                border-color 0.3s ease,
                box-shadow 0.3s ease;
}

/* =====================================================
   SWITCH TOGGLE DARK MODE
   ===================================================== */
.theme-toggle {
    position: relative;
    width: 52px;
    height: 28px;
    min-width: 52px;
    min-height: 28px;
    border-radius: 14px;
    background: rgba(93, 173, 226, 0.3);
    border: 1px solid rgba(93, 173, 226, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 2px;
    transition: background 1.2s cubic-bezier(0.4, 0, 0.2, 1), 
                border-color 1.2s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 0 8px;
    overflow: hidden;
}

.theme-toggle::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(93, 173, 226, 0.1), rgba(147, 197, 253, 0.1));
    opacity: 0;
    transition: opacity 1.2s ease;
    pointer-events: none;
}

.theme-toggle:hover {
    background: rgba(93, 173, 226, 0.4);
    border-color: rgba(93, 173, 226, 0.6);
    box-shadow: 0 0 0 2px rgba(93, 173, 226, 0.2);
}

.theme-toggle:hover::after {
    opacity: 1;
}

.theme-toggle:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--cyan-bright);
    outline-offset: 2px;
}

/* Slider interno do switch - Modo Light padrão (sol à esquerda) */
.theme-toggle-slider {
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3),
                0 0 0 0 rgba(255, 215, 0, 0.4);
    transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1),
                background 1.2s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(0);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    z-index: 1;
}

/* Animação de pulse ao clicar */
.theme-toggle:active .theme-toggle-slider {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15),
                0 0 0 8px rgba(93, 173, 226, 0.2);
    transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.5s ease;
}

/* Ícone do sol/lua no slider - Modo Light (sol à esquerda) */
.theme-toggle-slider::before {
    content: '☀️';
    display: block;
    line-height: 1;
    transition: opacity 0.8s ease 0.4s,
                transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: rotate(0deg) scale(1);
    opacity: 1;
}

/* Estado dark - slider move para direita e muda para lua */
[data-theme="dark"] .theme-toggle {
    background: rgba(93, 173, 226, 0.5);
    border-color: rgba(93, 173, 226, 0.7);
    box-shadow: 0 0 0 0 rgba(93, 173, 226, 0.3),
                inset 0 0 20px rgba(93, 173, 226, 0.1);
}

[data-theme="dark"] .theme-toggle:hover {
    box-shadow: 0 0 0 2px rgba(93, 173, 226, 0.3),
                inset 0 0 20px rgba(93, 173, 226, 0.15);
}

/* Slider move para direita no modo dark */
[data-theme="dark"] .theme-toggle-slider {
    transform: translateX(24px) !important;
    background: linear-gradient(135deg, #4a5568, #2d3748) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4),
                0 0 0 0 rgba(147, 197, 253, 0.3) !important;
}

/* Muda para lua no modo dark */
[data-theme="dark"] .theme-toggle-slider::before {
    content: '🌙' !important;
    transform: rotate(-15deg) scale(1.1) !important;
    transition: opacity 0.8s ease 0.4s,
                transform 1.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

[data-theme="dark"] .theme-toggle:active .theme-toggle-slider {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4),
                0 0 0 8px rgba(147, 197, 253, 0.2) !important;
}

/* Modo light - slider à esquerda com sol */
[data-theme="light"] .theme-toggle-slider,
html:not([data-theme="dark"]) .theme-toggle-slider {
    transform: translateX(0) !important;
    background: linear-gradient(135deg, #ffd700, #ffed4e) !important;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3),
                0 0 0 0 rgba(255, 215, 0, 0.4) !important;
}

[data-theme="light"] .theme-toggle-slider::before,
html:not([data-theme="dark"]) .theme-toggle-slider::before {
    content: '☀️' !important;
    transform: rotate(0deg) scale(1) !important;
}

/* Animação de transição suave ao mudar tema */
@keyframes themeTransition {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

.theme-toggle.animating {
    animation: themeTransition 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-toggle.animating .theme-toggle-slider {
    animation: themeTransition 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Atualizar aria-checked baseado no tema */
[data-theme="dark"] .theme-toggle[aria-checked="false"],
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle[aria-checked="false"] {
        /* Mantido para compatibilidade */
    }
}

/* Botão no menu mobile */
.theme-toggle-mobile {
    width: 100%;
    justify-content: flex-start;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin: 0.25rem 0;
    height: 44px;
    min-height: 44px;
    position: relative;
}

.theme-toggle-mobile .theme-toggle-slider {
    position: absolute;
    left: 1rem;
    transform: translateX(0);
    margin-right: 0;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
}

.theme-toggle-mobile:hover {
    background: rgba(93, 173, 226, 0.15);
}

/* Estado dark no mobile */
[data-theme="dark"] .theme-toggle-mobile .theme-toggle-slider {
    transform: translateX(24px) !important;
    background: linear-gradient(135deg, #4a5568, #2d3748) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4) !important;
}

[data-theme="dark"] .theme-toggle-mobile .theme-toggle-slider::before {
    content: '🌙' !important;
    transform: rotate(-15deg) scale(1.1) !important;
}

/* Estado light no mobile */
[data-theme="light"] .theme-toggle-mobile .theme-toggle-slider,
html:not([data-theme="dark"]) .theme-toggle-mobile .theme-toggle-slider {
    transform: translateX(0) !important;
    background: linear-gradient(135deg, #ffd700, #ffed4e) !important;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3) !important;
}

[data-theme="light"] .theme-toggle-mobile .theme-toggle-slider::before,
html:not([data-theme="dark"]) .theme-toggle-mobile .theme-toggle-slider::before {
    content: '☀️' !important;
    transform: rotate(0deg) scale(1) !important;
}

/* Mobile: ajustar tamanho */
@media (max-width: 768px) {
    .theme-toggle:not(.theme-toggle-mobile) {
        width: 48px;
        height: 26px;
        min-width: 48px;
        min-height: 26px;
    }
    
    .theme-toggle:not(.theme-toggle-mobile) .theme-toggle-slider {
        width: 20px;
        height: 20px;
    }
    
    [data-theme="dark"] .theme-toggle:not(.theme-toggle-mobile) .theme-toggle-slider {
        transform: translateX(22px) !important;
    }
    
    [data-theme="light"] .theme-toggle:not(.theme-toggle-mobile) .theme-toggle-slider,
    html:not([data-theme="dark"]) .theme-toggle:not(.theme-toggle-mobile) .theme-toggle-slider {
        transform: translateX(0) !important;
    }
}
