/**
 * GoTrade Global Theme System
 * Supports: light, dark, system (auto) modes
 * Uses CSS custom properties for consistent theming across all workspaces
 */

/* ============================================================================
   LIGHT MODE (Default)
   ============================================================================ */
:root,
[data-theme="light"] {
    /* Backgrounds */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-muted: #e5e7eb;
    --bg-inverse: #111827;
    
    /* Text */
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --text-subtle: #9ca3af;
    --text-inverse: #f9fafb;
    
    /* Borders */
    --border-default: #e5e7eb;
    --border-muted: #d1d5db;
    --border-strong: #9ca3af;
    
    /* Sidebar */
    --sidebar-bg: #fafafa;
    --sidebar-border: #e5e5e5;
    --sidebar-hover: #dbeafe;
    --sidebar-active-bg: #eff6ff;
    --sidebar-active-text: #1d4ed8;
    --sidebar-text: #1e293b;
    --sidebar-text-muted: #64748b;
    --sidebar-group-text: #9ca3af;
    
    /* Navigation */
    --nav-bg: #ffffff;
    --nav-border: #e5e7eb;
    --nav-link: #6b7280;
    --nav-link-hover: #2563eb;
    --nav-link-active: #3b82f6;
    
    /* Accents */
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-primary-light: #dbeafe;
    --accent-success: #10b981;
    --accent-success-light: #d1fae5;
    --accent-warning: #f59e0b;
    --accent-warning-light: #fef3c7;
    --accent-error: #ef4444;
    --accent-error-light: #fee2e2;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* Focus rings */
    --ring-color: rgba(59, 130, 246, 0.5);
}

/* ============================================================================
   DARK MODE
   ============================================================================ */
[data-theme="dark"] {
    /* Backgrounds */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-muted: #475569;
    --bg-inverse: #f1f5f9;
    
    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;
    --text-inverse: #0f172a;
    
    /* Borders */
    --border-default: #334155;
    --border-muted: #475569;
    --border-strong: #64748b;
    
    /* Sidebar */
    --sidebar-bg: #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-hover: #1e3a5f;
    --sidebar-active-bg: #1e3a5f;
    --sidebar-active-text: #60a5fa;
    --sidebar-text: #f1f5f9;
    --sidebar-text-muted: #94a3b8;
    --sidebar-group-text: #64748b;
    
    /* Navigation */
    --nav-bg: #1e293b;
    --nav-border: #334155;
    --nav-link: #94a3b8;
    --nav-link-hover: #60a5fa;
    --nav-link-active: #3b82f6;
    
    /* Accents (slightly adjusted for dark mode contrast) */
    --accent-primary: #3b82f6;
    --accent-primary-hover: #60a5fa;
    --accent-primary-light: #1e3a5f;
    --accent-success: #34d399;
    --accent-success-light: #064e3b;
    --accent-warning: #fbbf24;
    --accent-warning-light: #78350f;
    --accent-error: #f87171;
    --accent-error-light: #7f1d1d;
    
    /* Shadows (more subtle in dark mode) */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    
    /* Focus rings */
    --ring-color: rgba(96, 165, 250, 0.5);
}

/* ============================================================================
   SYSTEM MODE (Respects OS preference)
   ============================================================================ */
@media (prefers-color-scheme: dark) {
    [data-theme="system"] {
        /* Backgrounds */
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --bg-muted: #475569;
        --bg-inverse: #f1f5f9;
        
        /* Text */
        --text-primary: #f1f5f9;
        --text-secondary: #cbd5e1;
        --text-muted: #94a3b8;
        --text-subtle: #64748b;
        --text-inverse: #0f172a;
        
        /* Borders */
        --border-default: #334155;
        --border-muted: #475569;
        --border-strong: #64748b;
        
        /* Sidebar */
        --sidebar-bg: #0f172a;
        --sidebar-border: #1e293b;
        --sidebar-hover: #1e3a5f;
        --sidebar-active-bg: #1e3a5f;
        --sidebar-active-text: #60a5fa;
        --sidebar-text: #f1f5f9;
        --sidebar-text-muted: #94a3b8;
        --sidebar-group-text: #64748b;
        
        /* Navigation */
        --nav-bg: #1e293b;
        --nav-border: #334155;
        --nav-link: #94a3b8;
        --nav-link-hover: #60a5fa;
        --nav-link-active: #3b82f6;
        
        /* Accents */
        --accent-primary: #3b82f6;
        --accent-primary-hover: #60a5fa;
        --accent-primary-light: #1e3a5f;
        --accent-success: #34d399;
        --accent-success-light: #064e3b;
        --accent-warning: #fbbf24;
        --accent-warning-light: #78350f;
        --accent-error: #f87171;
        --accent-error-light: #7f1d1d;
        
        /* Shadows */
        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
        --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
        
        --ring-color: rgba(96, 165, 250, 0.5);
    }
}

@media (prefers-color-scheme: light) {
    [data-theme="system"] {
        /* Inherits from :root (light mode defaults) */
    }
}

/* ============================================================================
   THEMED COMPONENT CLASSES
   Apply these to override Tailwind defaults with theme-aware colors
   ============================================================================ */

/* Backgrounds */
.theme-bg-primary { background-color: var(--bg-primary) !important; }
.theme-bg-secondary { background-color: var(--bg-secondary) !important; }
.theme-bg-tertiary { background-color: var(--bg-tertiary) !important; }
.theme-bg-muted { background-color: var(--bg-muted) !important; }

/* Text */
.theme-text-primary { color: var(--text-primary) !important; }
.theme-text-secondary { color: var(--text-secondary) !important; }
.theme-text-muted { color: var(--text-muted) !important; }

/* Borders */
.theme-border { border-color: var(--border-default) !important; }
.theme-border-muted { border-color: var(--border-muted) !important; }

/* Hover states */
.hover\:theme-bg-tertiary:hover { background-color: var(--bg-tertiary) !important; }

/* ============================================================================
   SMOOTH TRANSITIONS
   Only apply to specific elements to avoid flash on page load
   ============================================================================ */
.theme-transition,
.theme-bg-primary,
.theme-bg-secondary,
.theme-text-primary,
.theme-text-secondary {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

/* ============================================================================
   NAVIGATION STYLES (Theme-Aware)
   ============================================================================ */
.nav-primary {
    background-color: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
}

.nav-link {
    color: var(--nav-link);
    transition: color 0.2s ease, border-color 0.2s ease;
}

.nav-link:hover {
    color: var(--nav-link-hover);
}

.nav-link-active {
    color: var(--nav-link-active);
    border-bottom-color: var(--nav-link-active);
}

/* ============================================================================
   SIDEBAR STYLES (Theme-Aware)
   ============================================================================ */
.sidebar-nav {
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
}

.sidebar-group-label {
    color: var(--sidebar-group-text);
}

.sidebar-link {
    color: var(--sidebar-text);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-link:hover {
    background-color: var(--sidebar-hover);
}

.sidebar-link-active {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 500;
}

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

/* ============================================================================
   CARD STYLES (Theme-Aware)
   ============================================================================ */
.card {
    background-color: var(--bg-primary) !important;
    border: 1px solid var(--border-default) !important;
    box-shadow: var(--shadow-sm) !important;
}

.card-elevated {
    box-shadow: var(--shadow-md) !important;
}

/* ============================================================================
   FORM CONTROLS (Theme-Aware)
   ============================================================================ */
.input-themed {
    background-color: var(--bg-primary);
    border-color: var(--border-default);
    color: var(--text-primary);
}

.input-themed:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--ring-color);
}

.input-themed::placeholder {
    color: var(--text-subtle);
}

/* ============================================================================
   DROPDOWN STYLES (Theme-Aware)
   ============================================================================ */
.dropdown-menu-themed {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-lg);
}

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

.dropdown-item-themed:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ============================================================================
   BUTTON VARIANTS (Theme-Aware)
   ============================================================================ */
.btn-primary {
    background-color: var(--accent-primary);
    color: white;
}

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

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

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

/* ============================================================================
   THEME TOGGLE BUTTON
   ============================================================================ */
.theme-toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    color: var(--text-secondary);
    transition: background-color 0.15s ease;
}

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

/* Theme icons visibility */
[data-theme="light"] .theme-icon-light { display: block; }
[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="light"] .theme-icon-system { display: none; }

[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: block; }
[data-theme="dark"] .theme-icon-system { display: none; }

[data-theme="system"] .theme-icon-light { display: none; }
[data-theme="system"] .theme-icon-dark { display: none; }
[data-theme="system"] .theme-icon-system { display: block; }

/* ============================================================================
   BADGE STYLES (Theme-Aware)
   ============================================================================ */
.badge-coming-soon {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-subtle);
    background-color: var(--bg-tertiary);
    border-radius: 9999px;
}

.badge-new {
    background-color: var(--accent-primary-light);
    color: var(--accent-primary);
}

.badge-beta {
    background-color: var(--accent-warning-light);
    color: var(--accent-warning);
}

/* ============================================================================
   SCROLLBAR STYLING (Theme-Aware)
   ============================================================================ */
.themed-scrollbar::-webkit-scrollbar {
    width: 8px;
}

.themed-scrollbar::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.themed-scrollbar::-webkit-scrollbar-thumb {
    background: var(--border-muted);
    border-radius: 4px;
}

.themed-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}
