/* 100xSolutions Calculator - Theme System */

/* Dark Theme */
[data-theme="dark"] {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-elevated: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border: #334155;
    --border-light: #475569;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

/* Blue Theme */
[data-theme="blue"] {
    --primary-color: #1e40af;
    --primary-hover: #1e3a8a;
    --secondary-color: #64748b;
    --background: #f0f9ff;
    --surface: #ffffff;
    --surface-elevated: #e0f2fe;
    --text-primary: #0c4a6e;
    --text-secondary: #0369a1;
    --text-muted: #0284c7;
    --border: #bae6fd;
    --border-light: #7dd3fc;
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
}

/* Green Theme */
[data-theme="green"] {
    --primary-color: #047857;
    --primary-hover: #065f46;
    --secondary-color: #64748b;
    --background: #f0fdf4;
    --surface: #ffffff;
    --surface-elevated: #dcfce7;
    --text-primary: #064e3b;
    --text-secondary: #047857;
    --text-muted: #059669;
    --border: #bbf7d0;
    --border-light: #86efac;
    --success: #10b981;
    --warning: #d97706;
    --error: #dc2626;
}

/* Purple Theme */
[data-theme="purple"] {
    --primary-color: #7c3aed;
    --primary-hover: #6d28d9;
    --secondary-color: #64748b;
    --background: #faf5ff;
    --surface: #ffffff;
    --surface-elevated: #f3e8ff;
    --text-primary: #581c87;
    --text-secondary: #7c3aed;
    --text-muted: #8b5cf6;
    --border: #e9d5ff;
    --border-light: #c4b5fd;
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
}

/* Orange Theme */
[data-theme="orange"] {
    --primary-color: #ea580c;
    --primary-hover: #dc2626;
    --secondary-color: #64748b;
    --background: #fff7ed;
    --surface: #ffffff;
    --surface-elevated: #fed7aa;
    --text-primary: #9a3412;
    --text-secondary: #ea580c;
    --text-muted: #f97316;
    --border: #fed7aa;
    --border-light: #fdba74;
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
}

/* Theme Toggle Animation */
.theme-transition {
    transition: all 0.3s ease;
}

/* System Theme Detection */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --primary-color: #3b82f6;
        --primary-hover: #2563eb;
        --secondary-color: #64748b;
        --background: #0f172a;
        --surface: #1e293b;
        --surface-elevated: #334155;
        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted: #94a3b8;
        --border: #334155;
        --border-light: #475569;
        --success: #10b981;
        --warning: #f59e0b;
        --error: #ef4444;
        --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
        --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    }
}

/* High Contrast Theme */
[data-theme="high-contrast"] {
    --primary-color: #000000;
    --primary-hover: #333333;
    --secondary-color: #666666;
    --background: #ffffff;
    --surface: #ffffff;
    --surface-elevated: #f0f0f0;
    --text-primary: #000000;
    --text-secondary: #333333;
    --text-muted: #666666;
    --border: #000000;
    --border-light: #cccccc;
    --success: #008000;
    --warning: #ff8c00;
    --error: #ff0000;
    --shadow: 0 2px 4px 0 rgb(0 0 0 / 0.5);
    --shadow-lg: 0 4px 8px 0 rgb(0 0 0 / 0.5);
}

/* Custom Theme (user-defined) */
[data-theme="custom"] {
    /* These will be set dynamically via JavaScript */
    --primary-color: var(--custom-primary, #2563eb);
    --primary-hover: var(--custom-primary-hover, #1d4ed8);
    --secondary-color: var(--custom-secondary, #64748b);
    --background: var(--custom-background, #f8fafc);
    --surface: var(--custom-surface, #ffffff);
    --surface-elevated: var(--custom-surface-elevated, #f1f5f9);
    --text-primary: var(--custom-text-primary, #1e293b);
    --text-secondary: var(--custom-text-secondary, #64748b);
    --text-muted: var(--custom-text-muted, #94a3b8);
    --border: var(--custom-border, #e2e8f0);
    --border-light: var(--custom-border-light, #f1f5f9);
}

/* Theme Selector Dropdown */
.theme-selector {
    position: relative;
}

.theme-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    margin-top: 0.25rem;
    min-width: 200px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

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

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: background 0.2s ease;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.theme-option:hover {
    background: var(--surface-elevated);
}

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

.theme-color-preview {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
}

.theme-color-preview.light {
    background: linear-gradient(45deg, #f8fafc 25%, #ffffff 25%, #ffffff 50%, #f8fafc 50%, #f8fafc 75%, #ffffff 75%, #ffffff);
}

.theme-color-preview.dark {
    background: linear-gradient(45deg, #0f172a 25%, #1e293b 25%, #1e293b 50%, #0f172a 50%, #0f172a 75%, #1e293b 75%, #1e293b);
}

.theme-color-preview.blue {
    background: #1e40af;
}

.theme-color-preview.green {
    background: #047857;
}

.theme-color-preview.purple {
    background: #7c3aed;
}

.theme-color-preview.orange {
    background: #ea580c;
}

.theme-color-preview.high-contrast {
    background: #000000;
    border-color: #ffffff;
}

.theme-color-preview.custom {
    background: var(--custom-primary, #2563eb);
}

/* Theme Customization Panel */
.theme-customizer {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    margin-top: 1rem;
    display: none;
}

.theme-customizer.open {
    display: block;
}

.custom-color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.color-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.color-input-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.color-input {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.color-input input[type="color"] {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    cursor: pointer;
    background: none;
    padding: 0;
}

.color-input input[type="text"] {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    background: var(--surface-elevated);
    color: var(--text-primary);
    font-family: monospace;
    font-size: 0.875rem;
}

.theme-customizer-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* Smooth transitions for theme changes */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Theme persistence indicator */
.theme-indicator {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    padding: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 100;
}

.theme-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

/* Theme preview in header */
.theme-preview {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid var(--border);
    margin-right: 0.5rem;
}

/* Mobile theme selector */
@media (max-width: 768px) {
    .theme-dropdown {
        right: 0;
        left: auto;
        min-width: 150px;
    }
    
    .theme-customizer {
        padding: 1rem;
    }
    
    .custom-color-grid {
        grid-template-columns: 1fr;
    }
    
    .theme-customizer-actions {
        flex-direction: column;
    }
    
    .theme-indicator {
        bottom: 5rem;
        left: 0.5rem;
        right: 0.5rem;
        text-align: center;
    }
}

/* Accessibility improvements for themes */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}

@media (prefers-contrast: high) {
    :root {
        --border: #000000;
        --shadow: 0 2px 4px 0 rgb(0 0 0 / 0.5);
        --shadow-lg: 0 4px 8px 0 rgb(0 0 0 / 0.5);
    }
}

/* Print theme overrides */
@media print {
    :root {
        --background: #ffffff;
        --surface: #ffffff;
        --surface-elevated: #ffffff;
        --text-primary: #000000;
        --text-secondary: #000000;
        --text-muted: #666666;
        --border: #000000;
        --border-light: #cccccc;
    }
    
    [data-theme="dark"],
    [data-theme="high-contrast"] {
        --background: #ffffff;
        --surface: #ffffff;
        --surface-elevated: #ffffff;
        --text-primary: #000000;
        --text-secondary: #000000;
        --text-muted: #666666;
        --border: #000000;
        --border-light: #cccccc;
    }
}

/* Theme loading state */
.theme-loading {
    opacity: 0.5;
    pointer-events: none;
}

.theme-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--border);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
