/* Theme colors */
.theme-purple {
    --theme-primary: #a855f7;
    --theme-primary-light: #c084fc;
    --theme-primary-rgb: 168, 85, 247;
    --primary-rgb: 168, 85, 247;
}

.theme-blue {
    --theme-primary: #3b82f6;
    --theme-primary-light: #60a5fa;
    --theme-primary-rgb: 59, 130, 246;
    --primary-rgb: 59, 130, 246;
}

.theme-green {
    --theme-primary: #22c55e;
    --theme-primary-light: #4ade80;
    --theme-primary-rgb: 34, 197, 94;
    --primary-rgb: 34, 197, 94;
}

.theme-red {
    --theme-primary: #ef4444;
    --theme-primary-light: #f87171;
    --theme-primary-rgb: 239, 68, 68;
    --primary-rgb: 239, 68, 68;
}

.theme-orange {
    --theme-primary: #f97316;
    --theme-primary-light: #fb923c;
    --theme-primary-rgb: 249, 115, 22;
    --primary-rgb: 249, 115, 22;
}

.theme-pink {
    --theme-primary: #ec4899;
    --theme-primary-light: #f472b6;
    --theme-primary-rgb: 236, 72, 153;
    --primary-rgb: 236, 72, 153;
}

.theme-indigo {
    --theme-primary: #6366f1;
    --theme-primary-light: #818cf8;
    --theme-primary-rgb: 99, 102, 241;
    --primary-rgb: 99, 102, 241;
}

.theme-teal {
    --theme-primary: #14b8a6;
    --theme-primary-light: #2dd4bf;
    --theme-primary-rgb: 20, 184, 166;
    --primary-rgb: 20, 184, 166;
}

.theme-yellow {
    --theme-primary: #eab308;
    --theme-primary-light: #facc15;
    --theme-primary-rgb: 234, 179, 8;
    --primary-rgb: 234, 179, 8;
}

.theme-cyan {
    --theme-primary: #06b6d4;
    --theme-primary-light: #22d3ee;
    --theme-primary-rgb: 6, 182, 212;
    --primary-rgb: 6, 182, 212;
}

/* Base theme colors and variables */
:root {
    /* Light theme (default) */
    --primary: var(--theme-primary, #a855f7);
    --primary-light: var(--theme-primary-light, #c084fc);
    --primary-rgb: var(--theme-primary-rgb, 168, 85, 247);

    /* Direct color variables for theme colors */
    --purple: #a855f7;
    --blue: #3b82f6;
    --green: #22c55e;
    --red: #ef4444;
    --orange: #f97316;
    --pink: #ec4899;
    --indigo: #6366f1;
    --teal: #14b8a6;
    --yellow: #eab308;
    --cyan: #06b6d4;

    /* Theme-aware overlay variables for light mode */
    --overlay-subtle: rgba(255, 255, 255, 0.25);
    --overlay-light: rgba(255, 255, 255, 0.35);
    --overlay-medium: rgba(255, 255, 255, 0.8);
    --overlay-heavy: rgba(255, 255, 255, 0.9);
    --overlay-ultra: rgba(255, 255, 255, 0.95);
    --overlay-solid: rgba(255, 255, 255, 0.98);

    --background: #ffffff;
    --surface: #f8fafc;
    --surface-accent: #f1f5f9;
    --surface-hover: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --border-darker: #cbd5e1;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --max-width: 1200px;
    --header-height: 64px;
    --transition-base: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --app-backdrop: radial-gradient(circle at 15% 10%, rgba(var(--primary-rgb), 0.12), transparent 50%), radial-gradient(circle at 85% 5%, rgba(var(--primary-rgb), 0.08), transparent 45%), radial-gradient(circle at 50% 90%, rgba(var(--primary-rgb), 0.06), transparent 40%), linear-gradient(180deg, rgba(var(--primary-rgb), 0.04) 0%, rgba(var(--primary-rgb), 0.01) 50%, transparent 100%);
    --surface-card: rgba(255, 255, 255, 0.98);
    --surface-card-border: rgba(15, 23, 42, 0.05);
    --surface-hero: linear-gradient(135deg, rgba(var(--primary-rgb, 168, 85, 247), 0.14), rgba(20, 184, 166, 0.08));
    --surface-hero-border: rgba(var(--primary-rgb, 168, 85, 247), 0.25);
    --surface-hero-glow: 0 35px 70px -45px rgba(var(--primary-rgb, 168, 85, 247), 0.4);
    --chip-bg: rgba(15, 23, 42, 0.04);
    --chip-border: rgba(15, 23, 42, 0.08);
    --chip-active-border: rgba(var(--primary-rgb, 168, 85, 247), 0.25);
    --tag-pill-bg: rgba(15, 23, 42, 0.04);
    --tag-pill-border: rgba(15, 23, 42, 0.08);
    --tag-pill-hover: rgba(var(--primary-rgb, 168, 85, 247), 0.12);

    /* T001: Color Palette Tokens */
    /* Primary - Theme-aware colors (references active theme) */
    --color-primary-50: #faf5ff;
    --color-primary-100: #f3e8ff;
    --color-primary-200: #e9d5ff;
    --color-primary-300: #d8b4fe;
    --color-primary-400: var(--theme-primary-light, #c084fc);
    --color-primary-500: var(--theme-primary, #a855f7);
    --color-primary-600: var(--theme-primary, #9333ea);
    --color-primary-700: var(--theme-primary, #7e22ce);
    --color-primary-800: #6b21a8;
    --color-primary-900: #581c87;

    /* Accent - Teal (3 shades) */
    --color-accent-teal-400: #2dd4bf;
    --color-accent-teal-500: #14b8a6;
    --color-accent-teal-600: #0d9488;

    /* Accent - Amber (3 shades) */
    --color-accent-amber-400: #fbbf24;
    --color-accent-amber-500: #f59e0b;
    --color-accent-amber-600: #d97706;

    /* Semantic colors */
    --color-text-primary: #1f2937;
    --color-text-secondary: #6b7280;
    --color-text-tertiary: #9ca3af;
    --color-bg-elevated: #ffffff;
    --color-bg-base: #f9fafb;
    --color-border-subtle: #e5e7eb;
    --color-border-medium: #d1d5db;

    /* T002: Shadow Elevation System */
    --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);
    --shadow-colored: 0 10px 15px -3px rgba(var(--primary-rgb, 168, 85, 247), 0.2);

    /* T003: Gradient Definitions */
    --gradient-primary: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-primary-500) 100%);
    --gradient-accent: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-accent-teal-500) 100%);
    --gradient-subtle: linear-gradient(180deg, rgba(var(--primary-rgb, 168, 85, 247), 0.05) 0%, transparent 100%);
    --gradient-hero: radial-gradient(circle at 0% 0%, rgba(var(--primary-rgb, 168, 85, 247), 0.3), transparent 55%), linear-gradient(135deg, rgba(20, 184, 166, 0.3), rgba(var(--primary-rgb, 168, 85, 247), 0.45));

    /* T004: Typography Scale Tokens */
    /* Font sizes */
    --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --text-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
    --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    --text-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
    --text-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
    --text-2xl: clamp(1.5rem, 1.3rem + 1vw, 1.875rem);
    --text-3xl: clamp(1.875rem, 1.6rem + 1.375vw, 2.25rem);
    --text-4xl: clamp(2.25rem, 1.9rem + 1.75vw, 3rem);
    --text-5xl: clamp(3rem, 2.5rem + 2.5vw, 3.75rem);

    /* Font weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Line heights */
    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    /* T005: Animation Tokens */
    /* Easing functions */
    --ease-in-out-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);

    /* Durations */
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 350ms;
}

/* Dark theme */
[data-theme="dark"] {
    --background: #0f172a;
    --surface: #1e293b;
    --surface-accent: #334155;
    --surface-hover: #475569;
    --text: #f8fafc;
    --text-secondary: #cbd5e1;
    --border: #475569;
    --border-darker: #64748b;

    /* Theme-aware overlay variables for dark mode */
    --overlay-subtle: rgba(15, 23, 42, 0.25);
    --overlay-light: rgba(15, 23, 42, 0.35);
    --overlay-medium: rgba(15, 23, 42, 0.8);
    --overlay-heavy: rgba(15, 23, 42, 0.9);
    --overlay-ultra: rgba(15, 23, 42, 0.95);
    --overlay-solid: rgba(15, 23, 42, 0.98);

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);

    /* T006: Dark Theme Overrides */
    --color-text-primary: #f9fafb;
    --color-text-secondary: #d1d5db;
    --color-text-tertiary: #9ca3af;
    --color-bg-elevated: #1f2937;
    --color-bg-base: #111827;
    --color-border-subtle: #374151;
    --color-border-medium: #4b5563;
    --surface-card: rgba(15, 23, 42, 0.85);
    --surface-card-border: rgba(148, 163, 184, 0.25);
    --surface-hero: linear-gradient(135deg, rgba(var(--primary-rgb, 168, 85, 247), 0.28), rgba(14, 165, 233, 0.25));
    --surface-hero-border: rgba(var(--primary-rgb, 168, 85, 247), 0.55);
    --surface-hero-glow: 0 50px 90px -35px rgba(var(--primary-rgb, 168, 85, 247), 0.8);
    --chip-bg: rgba(148, 163, 184, 0.15);
    --chip-border: rgba(148, 163, 184, 0.35);
    --chip-active-border: rgba(var(--primary-rgb, 168, 85, 247), 0.65);
    --tag-pill-bg: rgba(148, 163, 184, 0.12);
    --tag-pill-border: rgba(148, 163, 184, 0.3);
    --tag-pill-hover: rgba(var(--primary-rgb, 168, 85, 247), 0.3);
    --app-backdrop: radial-gradient(circle at 15% 10%, rgba(var(--primary-rgb), 0.20), transparent 50%), radial-gradient(circle at 85% 5%, rgba(var(--primary-rgb), 0.15), transparent 45%), radial-gradient(circle at 50% 90%, rgba(var(--primary-rgb), 0.12), transparent 40%), linear-gradient(180deg, rgba(var(--primary-rgb), 0.08) 0%, rgba(var(--primary-rgb), 0.03) 50%, transparent 100%);

    /* Adjust shadows for dark mode */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --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.3);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    --shadow-colored: 0 10px 15px -3px rgba(var(--primary-rgb, 168, 85, 247), 0.4);
}

/* Color picker specific styles */
.color-picker {
    position: relative;
    display: inline-block;
}

.color-picker-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0.5rem;
    font-size: 1rem;
    background-color: transparent;
    border: none;
    border-radius: 0.875rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-in-out-smooth);
}

.color-picker-button:hover {
    color: var(--color-text-primary);
    transform: translateY(-1px);
    background-color: var(--surface-hover);
}

.color-picker-button.active {
    color: var(--primary);
    background-color: rgba(var(--primary-rgb), 0.1);
}

/* Dark mode color-picker button */
[data-theme="dark"] .color-picker-button {
    background-color: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] .color-picker-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 1);
    box-shadow: none;
}

[data-theme="dark"] .color-picker-button:active {
    background-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .color-picker-button.active {
    background-color: rgba(var(--primary-rgb), 0.2);
    color: var(--primary);
    border-color: transparent;
    box-shadow: none;
}

.color-picker-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: auto;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    display: none;
    z-index: 1000;
    min-width: 200px;
    max-width: calc(100vw - 2rem);
    margin-top: 0.25rem;
}

.color-picker-dropdown.show {
    display: block;
}

.color-option {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-base);
    margin-bottom: 0.25rem;
}

.color-option:last-child {
    margin-bottom: 0;
}

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

.color-option.active {
    background: var(--surface-accent);
    font-weight: 500;
}

.color-preview {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 0.75rem;
    border: 2px solid transparent;
    transition: all var(--transition-base);
}

.color-purple .color-preview { background: var(--purple); }
.color-blue .color-preview { background: var(--blue); }
.color-green .color-preview { background: var(--green); }
.color-red .color-preview { background: var(--red); }
.color-orange .color-preview { background: var(--orange); }
.color-pink .color-preview { background: var(--pink); }
.color-indigo .color-preview { background: var(--indigo); }
.color-teal .color-preview { background: var(--teal); }
.color-yellow .color-preview { background: var(--yellow); }
.color-cyan .color-preview { background: var(--cyan); }

.color-option.active .color-preview {
    border-color: var(--text);
    box-shadow: 0 0 0 2px var(--background);
}

/* Theme toggle styles */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0.5rem;
    font-size: 1rem;
    background-color: transparent;
    border: none;
    border-radius: 0.875rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-in-out-smooth);
}

.theme-toggle:hover {
    color: var(--color-text-primary);
    transform: translateY(-1px);
    background-color: var(--surface-hover);
}

.theme-toggle:active {
    transform: translateY(0);
    background-color: var(--surface-accent);
}

.theme-toggle i {
    font-size: 1rem;
}

/* Dark mode theme toggle */
[data-theme="dark"] .theme-toggle {
    background-color: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] .theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 1);
}

[data-theme="dark"] .theme-toggle:active {
    background-color: rgba(255, 255, 255, 0.15);
}

/* Responsive theme adjustments */
@media (max-width: 768px) {
    .color-picker-dropdown {
        min-width: 150px;
    }

    .color-option {
        padding: 0.75rem 0.5rem;
    }

    .color-preview {
        width: 18px;
        height: 18px;
        margin-right: 0.5rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .color-preview {
        border: 2px solid var(--text);
    }

    .theme-toggle, .color-picker-button {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .color-option,
    .color-preview,
    .theme-toggle,
    .color-picker-button {
        transition: none;
    }
}
