/* ===============================================
   NSE Data Tools - Advanced Theming System
   =============================================== */

/* Theme Switching Transitions */
* {
    transition: background-color var(--transition-normal),
                color var(--transition-normal),
                border-color var(--transition-normal),
                box-shadow var(--transition-normal) !important;
}

/* ===============================================
   LIGHT THEME (Default)
   =============================================== */
:root,
[data-theme="light"] {
    /* Primary Color Palette */
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --primary-300: #93c5fd;
    --primary-400: #60a5fa;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-700: #1d4ed8;
    --primary-800: #1e40af;
    --primary-900: #1e3a8a;

    /* Secondary Colors */
    --secondary-color: #64748b;
    --accent-color: #f59e0b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #06b6d4;

    /* Market Specific Colors */
    --bull-color: #16a34a;
    --bear-color: #dc2626;
    --neutral-color: #6b7280;
    --volume-color: #8b5cf6;

    /* Background Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-quaternary: #e2e8f0;
    --bg-dark: #0f172a;
    --bg-card: #ffffff;
    --bg-overlay: rgba(15, 23, 42, 0.1);
    --bg-modal: rgba(0, 0, 0, 0.5);

    /* Text Colors */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --text-inverse: #ffffff;
    --text-on-primary: #ffffff;

    /* Border Colors */
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    --border-dark: #cbd5e1;
    --border-focus: #3b82f6;

    /* Shadow Definitions */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

    /* Chart Colors */
    --chart-primary: #3b82f6;
    --chart-secondary: #10b981;
    --chart-tertiary: #f59e0b;
    --chart-quaternary: #ef4444;
    --chart-grid: #e5e7eb;
    --chart-text: #6b7280;
}

/* ===============================================
   DARK THEME
   =============================================== */
[data-theme="dark"] {
    /* Primary Colors (Adjusted for dark theme) */
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --primary-50: #1e293b;
    --primary-100: #334155;
    --primary-200: #475569;
    --primary-300: #64748b;
    --primary-400: #94a3b8;
    --primary-500: #cbd5e1;
    --primary-600: #e2e8f0;
    --primary-700: #f1f5f9;
    --primary-800: #f8fafc;
    --primary-900: #ffffff;

    /* Background Colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-quaternary: #475569;
    --bg-card: #1e293b;
    --bg-overlay: rgba(255, 255, 255, 0.1);
    --bg-modal: rgba(0, 0, 0, 0.8);

    /* Text Colors */
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --text-inverse: #0f172a;
    --text-on-primary: #ffffff;

    /* Border Colors */
    --border-color: #334155;
    --border-light: #475569;
    --border-dark: #64748b;

    /* Enhanced Dark Theme Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.6);

    /* Chart Colors for Dark Theme */
    --chart-primary: #60a5fa;
    --chart-secondary: #34d399;
    --chart-tertiary: #fbbf24;
    --chart-quaternary: #f87171;
    --chart-grid: #374151;
    --chart-text: #9ca3af;
}

/* ===============================================
   HIGH CONTRAST THEME
   =============================================== */
[data-theme="high-contrast"] {
    --primary-color: #0066cc;
    --primary-dark: #004499;
    --primary-light: #3388dd;

    --bg-primary: #ffffff;
    --bg-secondary: #f0f0f0;
    --bg-tertiary: #e0e0e0;
    --bg-card: #ffffff;

    --text-primary: #000000;
    --text-secondary: #333333;
    --text-muted: #666666;

    --border-color: #000000;
    --border-light: #333333;
    --border-dark: #000000;

    --bull-color: #00aa00;
    --bear-color: #dd0000;
    --neutral-color: #666666;

    /* High contrast shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.5);
}

/* ===============================================
   PROFESSIONAL THEME (Alternative)
   =============================================== */
[data-theme="professional"] {
    --primary-color: #1f2937;
    --primary-dark: #111827;
    --primary-light: #374151;

    --secondary-color: #6b7280;
    --accent-color: #d97706;

    --bg-primary: #f9fafb;
    --bg-secondary: #f3f4f6;
    --bg-tertiary: #e5e7eb;
    --bg-card: #ffffff;

    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;

    --border-color: #d1d5db;
    --border-light: #e5e7eb;
    --border-dark: #9ca3af;

    --bull-color: #065f46;
    --bear-color: #991b1b;
    --neutral-color: #6b7280;
}

/* ===============================================
   DYNAMIC THEME VARIABLES
   =============================================== */
.theme-transition {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Theme-specific component overrides */
[data-theme="dark"] .metric-card {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-tertiary));
    border-color: var(--border-color);
}

[data-theme="dark"] .metric-card:hover {
    background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-quaternary));
    box-shadow: var(--shadow-xl);
}

[data-theme="dark"] .index-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .index-card::before {
    background: linear-gradient(90deg, var(--primary-color), var(--primary-light));
}

/* ===============================================
   THEME-SPECIFIC SCROLLBARS
   =============================================== */
[data-theme="light"] ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

[data-theme="light"] ::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: var(--border-dark);
    border-radius: 4px;
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--border-color);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ===============================================
   THEME-SPECIFIC FOCUS STYLES
   =============================================== */
[data-theme="light"] *:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

[data-theme="dark"] *:focus {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}

[data-theme="high-contrast"] *:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* ===============================================
   THEME-SPECIFIC ANIMATIONS
   =============================================== */
[data-theme="dark"] .pulse-animation {
    animation: dark-pulse 2s infinite;
}

[data-theme="light"] .pulse-animation {
    animation: light-pulse 2s infinite;
}

@keyframes dark-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }
}

@keyframes light-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(37, 99, 235, 0);
    }
}

/* ===============================================
   THEME UTILITIES
   =============================================== */
.theme-surface {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.theme-surface-secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.theme-surface-tertiary {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.theme-text-primary {
    color: var(--text-primary);
}

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

.theme-text-muted {
    color: var(--text-muted);
}

.theme-border {
    border-color: var(--border-color);
}

.theme-shadow {
    box-shadow: var(--shadow-md);
}

.theme-shadow-lg {
    box-shadow: var(--shadow-lg);
}

/* ===============================================
   MARKET DATA THEME COLORS
   =============================================== */
.bull-bg {
    background-color: rgba(22, 163, 74, 0.1);
    color: var(--bull-color);
}

.bear-bg {
    background-color: rgba(220, 38, 38, 0.1);
    color: var(--bear-color);
}

.neutral-bg {
    background-color: rgba(107, 114, 128, 0.1);
    color: var(--neutral-color);
}

[data-theme="dark"] .bull-bg {
    background-color: rgba(34, 197, 94, 0.2);
}

[data-theme="dark"] .bear-bg {
    background-color: rgba(239, 68, 68, 0.2);
}

[data-theme="dark"] .neutral-bg {
    background-color: rgba(156, 163, 175, 0.2);
}

/* ===============================================
   PRINT THEME OVERRIDES
   =============================================== */
@media print {
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }

    .theme-surface,
    .theme-surface-secondary,
    .theme-surface-tertiary {
        border: 1px solid #ccc !important;
    }

    .bull-bg { color: #006600 !important; }
    .bear-bg { color: #cc0000 !important; }
    .neutral-bg { color: #666666 !important; }
}

/* ===============================================
   REDUCED MOTION SUPPORT
   =============================================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .pulse-animation,
    .shimmer,
    .loading-shimmer {
        animation: none !important;
    }
}

/* ===============================================
   COLOR SCHEME PREFERENCE DETECTION
   =============================================== */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

@media (prefers-color-scheme: light) {
    :root {
        color-scheme: light;
    }
}

/* ===============================================
   THEME SWITCHING JAVASCRIPT HELPERS
   =============================================== */
.theme-switching {
    pointer-events: none;
}

.theme-switching * {
    transition: none !important;
}

/* Theme loading state */
.theme-loading {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.theme-loaded {
    opacity: 1;
}

/* ===============================================
   ACCESSIBILITY ENHANCEMENTS
   =============================================== */
@media (prefers-contrast: high) {
    :root {
        --border-color: var(--text-primary);
        --border-light: var(--text-secondary);
    }

    .metric-card,
    .index-card,
    .theme-surface {
        border-width: 2px;
    }
}

/* Focus visible for keyboard navigation */
.focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast theme for accessibility */
[data-theme="high-contrast"] .focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 3px;
}

/* ===============================================
   CUSTOM PROPERTIES FOR DYNAMIC THEMING
   =============================================== */
:root {
    --theme-transition-duration: 300ms;
    --theme-transition-easing: cubic-bezier(0.4, 0, 0.2, 1);
    --theme-border-radius: 8px;
    --theme-shadow-color: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --theme-shadow-color: rgba(0, 0, 0, 0.3);
}

/* Theme-aware components */
.adaptive-shadow {
    box-shadow: 0 4px 6px var(--theme-shadow-color);
}

.adaptive-border {
    border-radius: var(--theme-border-radius);
    border: 1px solid var(--border-color);
}

.adaptive-transition {
    transition: all var(--theme-transition-duration) var(--theme-transition-easing);
}