/* Prevent theme flashing on page load */
html {
    /* Default to light theme to prevent flash */
    background-color: #fff;
    color: #697a8d;
}

html[data-theme="dark"] {
    background-color: #1a1d29;
    color: #c7d2e7;
}

html[data-theme="blackgold"] {
    background-color: #0f1014;
    color: #e7dcc0;
}

html[data-theme="richgold"] {
    background-color: #fff7e0;
    color: #3b2f1a;
}

/* iOS Style Theme Toggle Switch */
.theme-toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 30px;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

.theme-toggle-switch .switch-track {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #87CEEB 0%, #4A90E2 100%);
    border-radius: 15px;
    transition: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.theme-toggle-switch.dark .switch-track {
    background: linear-gradient(135deg, #2C3E50 0%, #1A1D29 100%);
}

.theme-toggle-switch.richgold .switch-track {
    background: linear-gradient(135deg, #f6d365 0%, #b8890b 100%);
}

.theme-toggle-switch.blackgold .switch-track {
    background: linear-gradient(135deg, #2b2414 0%, #0f1014 100%);
}

.theme-toggle-switch .switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 26px;
    height: 26px;
    background: #fff;
    border-radius: 50%;
    transition: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle-switch.dark .switch-thumb {
    transform: translateX(30px);
    background: #2C3E50;
}

.theme-toggle-switch.richgold .switch-thumb {
    background: #fff7e0;
}

.theme-toggle-switch.blackgold .switch-thumb {
    transform: translateX(30px);
    background: #2b2414;
}

.theme-toggle-switch .switch-icon {
    font-size: 14px;
    transition: all 0.3s ease;
    color: #4A90E2;
}

.theme-toggle-switch.dark .switch-icon {
    color: #F39C12;
}

.theme-toggle-switch.richgold .switch-icon {
    color: #7a5a10;
}

.theme-toggle-switch.blackgold .switch-icon {
    color: #d4af37;
}

/* Hover Effects */
.theme-toggle-switch:hover .switch-track {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(105, 108, 255, 0.1);
}

.theme-toggle-switch.richgold:hover .switch-track {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(201, 162, 39, 0.25);
}

.theme-toggle-switch.blackgold:hover .switch-track {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 0 0 3px rgba(212, 175, 55, 0.3);
}

.theme-toggle-switch:hover .switch-thumb {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.theme-toggle-switch.richgold:hover .switch-thumb {
    box-shadow: 0 4px 12px rgba(201, 162, 39, 0.3);
}

.theme-toggle-switch.blackgold:hover .switch-thumb {
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
}

/* Active State */
.theme-toggle-switch:active .switch-thumb {
    transform: scale(0.95);
}

.theme-toggle-switch.dark:active .switch-thumb {
    transform: translateX(30px) scale(0.95);
}

.theme-toggle-switch.blackgold:active .switch-thumb {
    transform: translateX(30px) scale(0.95);
}

.theme-toggle-switch.richgold:active .switch-thumb {
    transform: scale(0.95);
}

/* Focus State for Accessibility */
.theme-toggle-switch:focus {
    outline: none;
}

.theme-toggle-switch:focus .switch-track {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 3px rgba(105, 108, 255, 0.3);
}

.theme-toggle-switch.richgold:focus .switch-track {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 3px rgba(201, 162, 39, 0.35);
}

.theme-toggle-switch.blackgold:focus .switch-track {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 0 0 3px rgba(212, 175, 55, 0.4);
}

/* Labels */
.theme-toggle-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-toggle-label {
    font-size: 14px;
    color: var(--bs-body-color, #697a8d);
    user-select: none;
    transition: color 0.3s ease;
}

[data-theme="dark"] .theme-toggle-label {
    color: #c7d2e7;
}

[data-theme="blackgold"] .theme-toggle-label {
    color: #e7dcc0;
}

[data-theme="richgold"] .theme-toggle-label {
    color: #3b2f1a;
}

.theme-toggle-label.active {
    color: #696cff;
    font-weight: 500;
}

/* Responsive Design */
@media (max-width: 768px) {
    .theme-toggle-switch {
        width: 50px;
        height: 25px;
    }
    
    .theme-toggle-switch .switch-thumb {
        width: 21px;
        height: 21px;
        top: 2px;
    }
    
    .theme-toggle-switch.dark .switch-thumb {
        transform: translateX(25px);
    }
    
    .theme-toggle-switch.dark:active .switch-thumb {
        transform: translateX(25px) scale(0.95);
    }

    .theme-toggle-switch.blackgold:active .switch-thumb {
        transform: translateX(25px) scale(0.95);
    }
    
    .theme-toggle-switch .switch-icon {
        font-size: 12px;
    }
}

/* Navbar Integration */
.navbar .theme-toggle-container {
    margin: 0 8px;
}

/* Sidebar Integration */
.menu-link .theme-toggle-container {
    width: 100%;
    justify-content: flex-start;
    padding: 0;
}

.menu-link .theme-toggle-container .theme-toggle-label {
    margin-left: 0;
    font-size: 13px;
}

/* Animation for theme change - only when explicitly triggered */
@keyframes themeChange {
    0% { opacity: 0.8; }
    50% { opacity: 1; }
    100% { opacity: 0.8; }
}

.theme-toggle-switch.changing {
    animation: themeChange 0.6s ease-in-out;
}

/* Prevent any animations during page load */
.theme-toggle-switch:not(.changing) {
    animation: none !important;
}

.theme-toggle-switch * {
    animation: none !important;
    transition: none !important;
}

/* Re-enable transitions after page load */
.page-loaded .theme-toggle-switch .switch-track {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-loaded .theme-toggle-switch .switch-thumb {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-loaded .theme-toggle-switch .switch-icon {
    transition: all 0.3s ease;
}
