/* Enhanced Theme Selector Component */

/* Base theme toggle (maintains existing functionality for non-premium users) */
.theme-toggle {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

.theme-toggle:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.theme-toggle .theme-icon {
    font-size: 1.1rem;
    color: var(--text-primary);
    flex-shrink: 0;
}

/* Premium Theme Selector Dropdown */
.premium-theme-selector {
    position: relative;
    display: inline-block;
}

.premium-theme-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 1000;
    min-width: 320px;
    max-width: 400px;
    max-height: 80vh;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 25px var(--shadow-lg);
    padding: 0;
    opacity: 0;
    transform: translateY(-10px);
    visibility: hidden;
    transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.premium-theme-dropdown.show {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}

.premium-theme-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 16px;
    width: 12px;
    height: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-bottom: none;
    border-right: none;
    transform: rotate(45deg);
}

/* Dropdown Header */
.theme-dropdown-header {
    flex-shrink: 0;
    padding: var(--space-3) var(--space-3) var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
}

.theme-dropdown-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.premium-badge {
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px var(--space-2);
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* Scrollable content area */
.theme-dropdown-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
}

/* Custom scrollbar styles */
.theme-dropdown-content::-webkit-scrollbar {
    width: 8px;
}

.theme-dropdown-content::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.theme-dropdown-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-sm);
}

.theme-dropdown-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Standard Theme Options (Light/Dark/System) */
.standard-themes {
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border);
}

.standard-themes .section-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.standard-theme-options {
    display: flex;
    gap: var(--space-2);
}

.theme-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.theme-option:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
    color: var(--text-primary);
}

.theme-option.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    font-weight: 500;
}

/* Premium Theme Collections */
.premium-themes .section-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: var(--space-3);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.theme-collection {
    margin-bottom: var(--space-4);
}

.theme-collection:last-child {
    margin-bottom: 0;
}

.collection-header {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
    text-transform: capitalize;
}

.theme-variants {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-2);
}

.premium-theme-option {
    display: flex;
    align-items: center;
    padding: var(--space-3);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    min-height: 60px;
}

.premium-theme-option:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px var(--shadow);
}

.premium-theme-option.active {
    background: var(--primary-light);
    border: 3px solid var(--primary) !important;
    box-shadow: 0 0 0 2px var(--border-focus);
}

/* Theme Preview Colors */
.theme-preview {
    display: flex;
    gap: 4px;
    margin-right: var(--space-3);
    flex-shrink: 0;
}

.color-swatch {
    width: 16px;
    height: 16px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

/* Theme Info */
.theme-info {
    flex: 1;
    min-width: 0;
}

.theme-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0 0 2px 0;
    text-transform: capitalize;
}

.theme-description {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.3;
}

/* Selection Indicator */
.theme-option-indicator {
    width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    border: 2px solid var(--border);
    margin-left: var(--space-2);
    flex-shrink: 0;
    position: relative;
}


/* Loading State */
.theme-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    color: var(--text-muted);
}

/* Theme toggle tooltip positioning - under selector, right-aligned */
.premium-theme-selector .theme-toggle[data-tooltip]::before,
.nav-control.theme-control .theme-toggle[data-tooltip]::before {
    bottom: auto;
    top: calc(100% + 8px);
    left: auto;
    right: 0;
    transform: none;
    margin-bottom: 0;
    margin-top: 0;
    white-space: nowrap;
    text-align: left;
}

.premium-theme-selector .theme-toggle[data-tooltip]::after,
.nav-control.theme-control .theme-toggle[data-tooltip]::after {
    bottom: auto;
    top: calc(100% + 3px);
    left: auto;
    right: 12px;
    transform: none;
    border-top: none;
    border-bottom: 5px solid var(--bg-tooltip, rgba(0, 0, 0, 0.9));
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
}

.theme-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: var(--space-2);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {

    
    .theme-variants {
        grid-template-columns: 1fr;
    }
    
    .standard-theme-options {
        flex-direction: column;
        gap: var(--space-1);
    }
}

/* Dark theme adjustments */
[data-theme="dark"] .theme-toggle,
[data-theme="system"].system-dark .theme-toggle {
    background: var(--bg-blur);
    border-color: var(--border);
}

[data-theme="dark"] .theme-toggle:hover,
[data-theme="system"].system-dark .theme-toggle:hover {
    background: var(--bg-secondary);
    border-color: var(--primary);
}

/* Premium theme specific adjustments for dark backgrounds */
[data-theme="deep-forest"] .premium-theme-dropdown,
[data-theme="deep-forest"] .premium-theme-dropdown::before {
    background: var(--bg-secondary);
}

[data-theme="deep-forest"] .theme-option,
[data-theme="deep-forest"] .premium-theme-option {
    background: var(--bg-tertiary);
    color: #000000;
}

[data-theme="deep-forest"] .theme-option:hover,
[data-theme="deep-forest"] .premium-theme-option:hover {
    background: var(--bg-primary);
    color: #ffffff;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .premium-theme-dropdown {
        /* Reset all positioning to create true modal */
        position: fixed ;
        top: 50%;
        left: 50%;
        transform: translate(-50%, 0px) scale(0.8);
        right: auto ;
        bottom: auto ;
        /* Modal sizing */
        width: calc(100vw - 32px) ;
        max-width: 400px ;
        max-height: 90vh ;
        /* Modal styling */
        border-radius: var(--radius-lg) ;
        box-shadow: 0 10px 40px var(--shadow-lg) ;
        z-index: 10000 ; /* Above everything including navigation */
        margin: 0 ;
        /* Animation states */
        opacity: 0 ;
        visibility: hidden ;
        transition: all 0.3s ease-in-out ;
    }
    
    .premium-theme-dropdown.show {
        transform: translate(-50%, 0px) scale(1);
    }
    
    .premium-theme-dropdown::before {
        display: none;
    }
    
    .theme-dropdown-content {
        padding: var(--space-4);
        padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px)); /* Safe area for devices with home indicators */
        overflow-y: auto; /* Allow scrolling if content is too tall */
    }
    
    .standard-theme-options {
        flex-direction: column;
        gap: var(--space-3);
    }
    
    .theme-option {
        justify-content: flex-start;
        padding: var(--space-3);
        font-size: 1rem;
    }
    
    .premium-theme-option {
        padding: var(--space-3);
    }
    
    .theme-collection {
        margin-bottom: var(--space-4);
    }
    
    .theme-variants {
        gap: var(--space-3);
    }
}

@media (max-width: 480px) {
    .premium-theme-dropdown {
        max-height: 80vh;
    }
    
    .theme-dropdown-header {
        padding: var(--space-3);
    }
    
    .theme-dropdown-title {
        font-size: 1.1rem;
    }
    
    /* Mobile backdrop for theme selector */
    .theme-selector-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease-in-out;
    }
    
    .theme-selector-backdrop.show {
        opacity: 1;
        visibility: visible;
    }
    
    /* Mobile drag handle for theme selector - hide for centered modal */
    .mobile-theme-handle {
        display: none; /* Not needed for centered modal */
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .premium-theme-dropdown,
    .theme-option,
    .premium-theme-option {
        transition: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .premium-theme-dropdown {
        border: 2px solid currentColor;
    }
    
    .theme-option,
    .premium-theme-option {
        border: 1px solid currentColor;
    }
}

