/* =============================================================================
   PLOS THEME SYSTEM
   Dark/Light theme support via CSS custom property overrides.

   The dark theme is the default (values defined in base.html :root).
   This file provides light theme overrides via [data-theme="light"].
   ============================================================================= */

/* -----------------------------------------------------------------------------
   THEME TRANSITION
   Smooth color transitions when toggling between themes.
   Applied to all elements so backgrounds, text, and borders animate.
   ----------------------------------------------------------------------------- */
html[data-theme] *,
html[data-theme] *::before,
html[data-theme] *::after {
    transition:
        background-color 0.25s ease,
        border-color 0.25s ease,
        color 0.25s ease,
        box-shadow 0.25s ease;
}

/* Disable transitions on page load to prevent flash-of-animation.
   The 'no-transitions' class is removed after the first paint by theme-toggle.js */
html.no-transitions *,
html.no-transitions *::before,
html.no-transitions *::after {
    transition: none !important;
}

/* -----------------------------------------------------------------------------
   LIGHT THEME OVERRIDES
   ----------------------------------------------------------------------------- */
[data-theme="light"] {
    /* === CANVAS === */
    --bg-canvas: #f5f5f7;
    --bg-void: #eeeef0;

    /* === SURFACE LAYERS (light mode) === */
    --surface-lowest: #ffffff;
    --surface-low: #f5f5f7;
    --surface-container: #eeeef0;
    --surface-high: #e8e8ea;
    --surface-highest: #dedede;
    --surface-bright: #f9f9f9;

    /* === GLASS LAYERS (light translucency on white bg) === */
    --glass-subtle: rgba(255, 255, 255, 0.60);
    --glass-light: rgba(255, 255, 255, 0.70);
    --glass-medium: rgba(255, 255, 255, 0.80);
    --glass-strong: rgba(255, 255, 255, 0.90);
    --glass-hover: rgba(0, 0, 0, 0.05);

    /* === FIXED LIFE AREA COLORS (slightly deeper for light bg) === */
    --area-health: #059669;
    --area-health-soft: rgba(5, 150, 105, 0.12);
    --area-finance: #2563EB;
    --area-finance-soft: rgba(37, 99, 235, 0.10);
    --area-productivity: #0891D8;
    --area-productivity-soft: rgba(8, 145, 216, 0.10);
    --area-learning: #7C3AED;
    --area-learning-soft: rgba(124, 58, 237, 0.10);
    --area-relationships: #EA580C;
    --area-relationships-soft: rgba(234, 88, 12, 0.10);

    /* === BORDERS === */
    --border-glass: rgba(0, 0, 0, 0.10);
    --border-glass-strong: rgba(0, 0, 0, 0.15);
    --border-focus: rgba(79, 138, 255, 0.5);

    /* === ACCENT COLORS (slightly deepened for light bg contrast) === */
    --accent-blue: #2563EB;
    --accent-cyan: #0891D8;
    --accent-teal: #14B8A6;
    --accent-green: #059669;
    --accent-orange: #EA6010;
    --accent-amber: #D97706;
    --accent-purple: #8B5CF6;

    /* === SEMANTIC COLORS === */
    --color-success: #059669;
    --color-warning: #D97706;
    --color-error: #DC2626;
    --color-info: #0891D8;

    /* Soft versions for badges */
    --color-success-soft: rgba(5, 150, 105, 0.12);
    --color-warning-soft: rgba(217, 119, 6, 0.12);
    --color-error-soft: rgba(220, 38, 38, 0.12);
    --color-info-soft: rgba(8, 145, 216, 0.12);

    /* === TEXT HIERARCHY === */
    --text-primary: #1a1a1a;
    --text-secondary: #374151;
    --text-tertiary: #4b5563;
    --text-muted: #4b5563;
    --text-subtle: #6b7280;
    --text-disabled: #717171;

    /* === SHADOWS (softer, lighter) === */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.10);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12);

    /* === BACKWARD-COMPATIBLE ALIASES === */
    --color-text: var(--text-primary);
    --color-text-secondary: var(--text-secondary);
    --color-text-muted: var(--text-muted);
    --color-muted: var(--text-muted);
    --color-primary: var(--accent-blue);
    --color-primary-light: rgba(37, 99, 235, 0.10);
    --color-primary-dark: #1d4ed8;
    --color-surface: var(--glass-medium);
    --color-bg-card: var(--glass-medium);
    --color-border: var(--border-glass);
    --color-danger: var(--color-error);
    --color-error-dark: #b91c1c;
    --color-success-light: rgba(5, 150, 105, 0.10);
    --color-warning-light: rgba(217, 119, 6, 0.10);
    --color-whatsapp-light: rgba(37, 211, 102, 0.10);
    --color-telegram-light: rgba(0, 136, 204, 0.10);

    /* Gray scale for light mode */
    --color-gray-50: rgba(0, 0, 0, 0.02);
    --color-gray-100: rgba(0, 0, 0, 0.04);
    --color-gray-200: rgba(0, 0, 0, 0.06);
    --color-gray-300: rgba(0, 0, 0, 0.10);
    --color-gray-400: rgba(0, 0, 0, 0.16);
    --color-gray-500: rgba(0, 0, 0, 0.30);
    --color-gray-600: rgba(0, 0, 0, 0.45);
    --color-gray-700: rgba(0, 0, 0, 0.60);
    --color-gray-800: rgba(0, 0, 0, 0.80);

    /* === PLOS-UI.CSS (v3) VARIABLE OVERRIDES === */
    /* These override variables defined in static/css/plos-ui.css */
    --bg-deepest: #f5f5f7;
    --bg-deep: #eeeff1;
    --bg-surface: #ffffff;
    --bg-elevated: #f9fafb;
    --bg-overlay: rgba(0, 0, 0, 0.4);

    --accent-primary: #2563EB;
    --accent-primary-hover: #1d4ed8;
    --accent-primary-glow: rgba(37, 99, 235, 0.15);
    --accent-neon: #0891D8;
    --accent-neon-hover: #0284C7;
    --accent-neon-glow: rgba(8, 145, 216, 0.15);
    --accent-aqua: #14B8A6;
    --accent-aqua-hover: #0D9488;
    --accent-aqua-glow: rgba(20, 184, 166, 0.15);
    --accent-green-hover: #047857;
    --accent-green-glow: rgba(5, 150, 105, 0.15);

    --color-success-subtle: rgba(5, 150, 105, 0.10);
    --color-success-text: #047857;
    --color-warning-subtle: rgba(217, 119, 6, 0.10);
    --color-warning-text: #B45309;
    --color-error-subtle: rgba(220, 38, 38, 0.10);
    --color-error-text: #B91C1C;
    --color-info-subtle: rgba(8, 145, 216, 0.10);
    --color-info-text: #0369A1;

    --border-subtle: rgba(0, 0, 0, 0.12);
    --border-default: rgba(0, 0, 0, 0.10);
    --border-strong: rgba(0, 0, 0, 0.18);

    --channel-whatsapp-subtle: rgba(37, 211, 102, 0.10);
    --channel-telegram-subtle: rgba(0, 136, 204, 0.10);

    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    --glow-primary: 0 0 20px var(--accent-primary-glow);
    --glow-neon: 0 0 20px var(--accent-neon-glow);
    --glow-aqua: 0 0 20px var(--accent-aqua-glow);
    --glow-success: 0 0 20px var(--accent-green-glow);

    /* === MATERIAL DESIGN 3 TOKENS — LIGHT MODE (Stitch Shell) === */
    --md-primary: #0053db;
    --md-on-primary: #ffffff;
    --md-primary-container: #dbe1ff;
    --md-on-primary-container: #00174b;
    --md-primary-fixed: #dbe1ff;
    --md-primary-fixed-dim: #b4c5ff;
    --md-secondary: #cabeff;
    --md-on-secondary: #322569;
    --md-secondary-container: #e6deff;
    --md-on-secondary-container: #1c0b54;
    --md-tertiary: #004d62;
    --md-on-tertiary: #ffffff;
    --md-tertiary-container: #baeaff;
    --md-on-tertiary-container: #001f29;
    --md-surface: #f5f5f7;
    --md-surface-dim: #d6d6d6;
    --md-surface-bright: #f5f5f7;
    --md-surface-container-lowest: #ffffff;
    --md-surface-container-low: #f0f0f0;
    --md-surface-container: #eaeaea;
    --md-surface-container-high: #e4e4e4;
    --md-surface-container-highest: #dedede;
    --md-on-surface: #1a1a1a;
    --md-on-surface-variant: #434655;
    --md-outline: #8d90a0;
    --md-outline-variant: #c3c6d7;
    --md-error: #ba1a1a;
    --md-error-container: #ffdad6;
    --md-on-error: #ffffff;
    --md-inverse-surface: #303030;
    --md-inverse-on-surface: #e2e2e2;
    --md-inverse-primary: #b4c5ff;
    --md-surface-tint: #0053db;

    /* === GAMIFICATION ACCENT (Stitch Shell) === */
    --accent-violet: #7C3AED;

    /* Light mode obsidian shadow is softer */
    --obsidian-shadow: 0 8px 24px rgba(0, 0, 0, 0.10);
}

/* -----------------------------------------------------------------------------
   LIGHT THEME: Element-specific overrides
   These target hardcoded colors in base.html that don't use CSS variables.
   ----------------------------------------------------------------------------- */

/* Global header: dark bg -> light bg */
[data-theme="light"] .global-header {
    background: rgba(255, 255, 255, 0.85);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

/* Nav link tooltip */
[data-theme="light"] .header-nav-link::after {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
}

/* Account dropdown: solid dark -> solid light */
[data-theme="light"] .account-dropdown {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.12);
}

/* Modal backdrop */
[data-theme="light"] .modal-backdrop {
    background: rgba(0, 0, 0, 0.4);
}

/* Modal glass */
[data-theme="light"] .modal {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(0, 0, 0, 0.12);
}

/* Footer */
[data-theme="light"] .global-footer {
    background: rgba(255, 255, 255, 0.6);
    border-top-color: rgba(0, 0, 0, 0.08);
}

/* Form inputs: dark bg -> light bg */
[data-theme="light"] .form-input,
[data-theme="light"] .form-select,
[data-theme="light"] .form-textarea {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.12);
    color: var(--text-primary);
}

[data-theme="light"] .form-input:focus,
[data-theme="light"] .form-select:focus,
[data-theme="light"] .form-textarea:focus {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(59, 123, 247, 0.5);
    box-shadow: 0 0 0 3px rgba(59, 123, 247, 0.1);
}

/* Select dropdown options */
[data-theme="light"] .form-select option,
[data-theme="light"] select option {
    background: #ffffff;
    color: #1a1a1a;
}

[data-theme="light"] .form-select option:checked,
[data-theme="light"] select option:checked {
    background: #e5e7eb;
}

/* Mobile menu overlay */
[data-theme="light"] .mobile-nav-overlay.open {
    background: rgba(0, 0, 0, 0.3);
}

/* Mobile nav panel */
[data-theme="light"] .mobile-nav-panel {
    background: #ffffff;
    border-right-color: rgba(0, 0, 0, 0.08);
}

/* Chat widget panel */
[data-theme="light"] .chat-widget-panel {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.12);
}

/* Glass containers with backdrop-filter - add subtle shadow in light mode */
[data-theme="light"] .glass,
[data-theme="light"] .glass-subtle,
[data-theme="light"] .glass-strong,
[data-theme="light"] .card,
[data-theme="light"] .stat-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

/* Selection color */
[data-theme="light"] ::selection {
    background: rgba(59, 123, 247, 0.2);
    color: #1a1a1a;
}

/* Scrollbar (webkit) */
[data-theme="light"] ::-webkit-scrollbar-track {
    background: #f0f0f0;
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

/* Meta theme-color handled by JS */

/* Print styles remain unchanged (already white bg) */

/* -----------------------------------------------------------------------------
   THEME TOGGLE BUTTON STYLES
   ----------------------------------------------------------------------------- */
.theme-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.theme-toggle-btn:hover {
    background: var(--glass-hover);
    color: var(--text-primary);
    border-color: var(--border-glass-strong);
}

.theme-toggle-btn svg {
    width: 18px;
    height: 18px;
}

/* Show/hide the correct icon based on theme */
.theme-toggle-btn .icon-sun {
    display: none;
}

.theme-toggle-btn .icon-moon {
    display: block;
}

[data-theme="light"] .theme-toggle-btn .icon-sun {
    display: block;
}

[data-theme="light"] .theme-toggle-btn .icon-moon {
    display: none;
}

/* Mobile theme toggle in mobile nav */
.mobile-theme-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    width: 100%;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    color: var(--text-secondary);
    transition: background 0.15s ease;
}

.mobile-theme-toggle:hover {
    background: transparent;
}

.mobile-theme-toggle svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Show/hide the correct icon in mobile toggle */
.mobile-theme-toggle .icon-sun {
    display: none;
}

.mobile-theme-toggle .icon-moon {
    display: block;
}

[data-theme="light"] .mobile-theme-toggle .icon-sun {
    display: block;
}

[data-theme="light"] .mobile-theme-toggle .icon-moon {
    display: none;
}

/* Page guide and explanation modal overrides for light */
[data-theme="light"] .page-guide-panel,
[data-theme="light"] .explanation-modal,
[data-theme="light"] .personalization-cta-modal {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.12);
}

/* Toast override for light mode */
[data-theme="light"] .toast-msg {
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
}
