/* Theme System CSS Variables and Dark/Light Mode Support */
:root {
    /* Light Theme (Default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-primary: #e2e8f0;
    --border-secondary: #cbd5e1;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --shadow-primary: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-secondary: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-large: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-primary: #334155;
    --border-secondary: #475569;
    --accent-primary: #60a5fa;
    --accent-hover: #3b82f6;
    --success-color: #34d399;
    --warning-color: #fbbf24;
    --error-color: #f87171;
    --shadow-primary: 0 1px 3px 0 rgb(0 0 0 / 0.3);
    --shadow-secondary: 0 4px 6px -1px rgb(0 0 0 / 0.3);
    --shadow-large: 0 10px 15px -3px rgb(0 0 0 / 0.3);
}

/* Smooth theme transitions */
* {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Base theme applications */
body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Theme Toggle Button */
.theme-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

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

.theme-toggle-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Theme-aware components */
.card, .modal, .dropdown {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    box-shadow: var(--shadow-secondary);
}

.input, .textarea, .select {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
}

.input:focus, .textarea:focus, .select:focus {
    border-color: var(--accent-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border: 1px solid var(--accent-primary);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

/* Popup/Modal theme support */
.popup-overlay {
    background: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .popup-overlay {
    background: rgba(0, 0, 0, 0.7);
}

.popup-content {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    box-shadow: var(--shadow-large);
}

/* Sidebar theme integration */
.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
}

.sidebar-item {
    color: var(--text-secondary);
}

.sidebar-item:hover, .sidebar-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Status indicators */
.status-success { color: var(--success-color); }
.status-warning { color: var(--warning-color); }
.status-error { color: var(--error-color); }

/* Theme persistence flash prevention */
html {
    background-color: #ffffff; /* Default light background */
}

html[data-theme="dark"] {
    background-color: #0f172a; /* Dark background */
}

/* Prevent flash of unstyled content */
body {
    opacity: 0;
    animation: fadeIn 0.1s ease-in forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-primary: #000000;
        --text-secondary: var(--text-primary);
    }
    
    [data-theme="dark"] {
        --border-primary: #ffffff;
        --text-secondary: var(--text-primary);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* Print styles (always light) */
@media print {
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
}