/**
 * Social Content Engine - Theme System
 * Supports: light, dark, auto (system preference)
 *
 * Usage:
 * - Add data-theme="light|dark|auto" to <html> element
 * - CSS variables adapt automatically
 */

/* ============================================
   Light Theme Variables
   ============================================ */
:root[data-theme="light"],
:root:not([data-theme]) {
    /* Primary colors */
    --primary: #0A66C2;
    --primary-dark: #004182;
    --primary-light: #378FE9;
    --primary-hover: #004182;

    /* Secondary colors */
    --secondary: #057642;
    --secondary-light: #0a9d5a;
    --accent: #F5C75D;
    --danger: #dc3545;
    --warning: #ffc107;
    --success: #057642;

    /* Background colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f3f2ef;
    --bg-tertiary: #e9e5df;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-header: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.5);
    --bg-hover: rgba(0, 0, 0, 0.05);
    --bg-active: rgba(10, 102, 194, 0.1);

    /* Text colors */
    --text-primary: #191919;
    --text-secondary: #666666;
    --text-muted: #8c8c8c;
    --text-inverse: #ffffff;
    --text-link: #0A66C2;
    --text-link-hover: #004182;

    /* Border colors */
    --border-color: #e0e0e0;
    --border-light: #f0f0f0;
    --border-focus: #0A66C2;

    /* Shadow */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #0A66C2 0%, #004182 100%);
    --gradient-bg: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);

    /* Input */
    --input-bg: #ffffff;
    --input-border: #c0c0c0;
    --input-focus-border: #0A66C2;
    --input-placeholder: #8c8c8c;

    /* Scrollbar */
    --scrollbar-bg: #f0f0f0;
    --scrollbar-thumb: #c0c0c0;
    --scrollbar-thumb-hover: #a0a0a0;
}

/* ============================================
   Dark Theme Variables
   ============================================ */
:root[data-theme="dark"] {
    /* Primary colors */
    --primary: #70B5F9;
    --primary-dark: #378FE9;
    --primary-light: #9ECBFF;
    --primary-hover: #378FE9;

    /* Secondary colors */
    --secondary: #4CD964;
    --secondary-light: #6BE078;
    --accent: #F5C75D;
    --danger: #ff6b6b;
    --warning: #ffc107;
    --success: #4CD964;

    /* Background colors */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #1f3460;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-sidebar: rgba(22, 33, 62, 0.95);
    --bg-header: rgba(26, 26, 46, 0.95);
    --bg-overlay: rgba(0, 0, 0, 0.7);
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-active: rgba(112, 181, 249, 0.15);

    /* Text colors */
    --text-primary: #ffffff;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --text-inverse: #191919;
    --text-link: #70B5F9;
    --text-link-hover: #9ECBFF;

    /* Border colors */
    --border-color: rgba(255, 255, 255, 0.1);
    --border-light: rgba(255, 255, 255, 0.05);
    --border-focus: #70B5F9;

    /* Shadow */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #70B5F9 0%, #378FE9 100%);
    --gradient-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);

    /* Input */
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.1);
    --input-focus-border: #70B5F9;
    --input-placeholder: #718096;

    /* Scrollbar */
    --scrollbar-bg: rgba(255, 255, 255, 0.05);
    --scrollbar-thumb: rgba(255, 255, 255, 0.2);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.3);
}

/* ============================================
   Auto Theme (follows system preference)
   ============================================ */
@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
        /* Primary colors */
        --primary: #70B5F9;
        --primary-dark: #378FE9;
        --primary-light: #9ECBFF;
        --primary-hover: #378FE9;

        /* Secondary colors */
        --secondary: #4CD964;
        --secondary-light: #6BE078;
        --accent: #F5C75D;
        --danger: #ff6b6b;
        --warning: #ffc107;
        --success: #4CD964;

        /* Background colors */
        --bg-primary: #1a1a2e;
        --bg-secondary: #16213e;
        --bg-tertiary: #1f3460;
        --bg-card: rgba(255, 255, 255, 0.03);
        --bg-sidebar: rgba(22, 33, 62, 0.95);
        --bg-header: rgba(26, 26, 46, 0.95);
        --bg-overlay: rgba(0, 0, 0, 0.7);
        --bg-hover: rgba(255, 255, 255, 0.05);
        --bg-active: rgba(112, 181, 249, 0.15);

        /* Text colors */
        --text-primary: #ffffff;
        --text-secondary: #a0aec0;
        --text-muted: #718096;
        --text-inverse: #191919;
        --text-link: #70B5F9;
        --text-link-hover: #9ECBFF;

        /* Border colors */
        --border-color: rgba(255, 255, 255, 0.1);
        --border-light: rgba(255, 255, 255, 0.05);
        --border-focus: #70B5F9;

        /* Shadow */
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);

        /* Gradients */
        --gradient-primary: linear-gradient(135deg, #70B5F9 0%, #378FE9 100%);
        --gradient-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);

        /* Input */
        --input-bg: rgba(255, 255, 255, 0.05);
        --input-border: rgba(255, 255, 255, 0.1);
        --input-focus-border: #70B5F9;
        --input-placeholder: #718096;

        /* Scrollbar */
        --scrollbar-bg: rgba(255, 255, 255, 0.05);
        --scrollbar-thumb: rgba(255, 255, 255, 0.2);
        --scrollbar-thumb-hover: rgba(255, 255, 255, 0.3);
    }
}

@media (prefers-color-scheme: light) {
    :root[data-theme="auto"] {
        /* Primary colors */
        --primary: #0A66C2;
        --primary-dark: #004182;
        --primary-light: #378FE9;
        --primary-hover: #004182;

        /* Secondary colors */
        --secondary: #057642;
        --secondary-light: #0a9d5a;
        --accent: #F5C75D;
        --danger: #dc3545;
        --warning: #ffc107;
        --success: #057642;

        /* Background colors */
        --bg-primary: #ffffff;
        --bg-secondary: #f3f2ef;
        --bg-tertiary: #e9e5df;
        --bg-card: #ffffff;
        --bg-sidebar: #ffffff;
        --bg-header: #ffffff;
        --bg-overlay: rgba(0, 0, 0, 0.5);
        --bg-hover: rgba(0, 0, 0, 0.05);
        --bg-active: rgba(10, 102, 194, 0.1);

        /* Text colors */
        --text-primary: #191919;
        --text-secondary: #666666;
        --text-muted: #8c8c8c;
        --text-inverse: #ffffff;
        --text-link: #0A66C2;
        --text-link-hover: #004182;

        /* Border colors */
        --border-color: #e0e0e0;
        --border-light: #f0f0f0;
        --border-focus: #0A66C2;

        /* Shadow */
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
        --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
        --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);

        /* Gradients */
        --gradient-primary: linear-gradient(135deg, #0A66C2 0%, #004182 100%);
        --gradient-bg: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);

        /* Input */
        --input-bg: #ffffff;
        --input-border: #c0c0c0;
        --input-focus-border: #0A66C2;
        --input-placeholder: #8c8c8c;

        /* Scrollbar */
        --scrollbar-bg: #f0f0f0;
        --scrollbar-thumb: #c0c0c0;
        --scrollbar-thumb-hover: #a0a0a0;
    }
}

/* ============================================
   Theme Transition
   ============================================ */
html {
    color-scheme: light dark;
}

html[data-theme="light"] {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
}

/* Smooth transition when theme changes */
html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
    transition: background-color 0.3s ease,
                color 0.3s ease,
                border-color 0.3s ease,
                box-shadow 0.3s ease !important;
}

/* ============================================
   Theme Switcher Component
   ============================================ */
.theme-switcher {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem;
    background: var(--bg-hover);
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

.theme-switcher-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.theme-switcher-btn.active {
    color: var(--primary);
    background: var(--bg-active);
}

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

/* Dropdown version */
.theme-dropdown {
    position: relative;
}

.theme-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}

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

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

.theme-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    min-width: 150px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.theme-dropdown.open .theme-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.theme-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-dropdown-item:first-child {
    border-radius: 7px 7px 0 0;
}

.theme-dropdown-item:last-child {
    border-radius: 0 0 7px 7px;
}

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

.theme-dropdown-item.active {
    background: var(--bg-active);
    color: var(--primary);
}

.theme-dropdown-item svg {
    width: 18px;
    height: 18px;
}

.theme-dropdown-item span {
    flex: 1;
}

.theme-dropdown-item .check-icon {
    width: 16px;
    height: 16px;
    opacity: 0;
}

.theme-dropdown-item.active .check-icon {
    opacity: 1;
}

/* ============================================
   Language Switcher Component
   ============================================ */
.lang-dropdown {
    position: relative;
}

.lang-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.875rem;
}

.lang-dropdown-toggle:hover {
    color: var(--text-primary);
    border-color: var(--border-color);
    background: var(--bg-hover);
}

.lang-dropdown-toggle svg {
    width: 18px;
    height: 18px;
}

.lang-dropdown-toggle .lang-code {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

.lang-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    min-width: 160px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.lang-dropdown.open .lang-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.lang-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.lang-dropdown-item:first-child {
    border-radius: 7px 7px 0 0;
}

.lang-dropdown-item:last-child {
    border-radius: 0 0 7px 7px;
}

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

.lang-dropdown-item.active {
    background: var(--bg-active);
    color: var(--primary);
}

.lang-dropdown-item .lang-flag {
    font-size: 1.1rem;
    line-height: 1;
}

.lang-dropdown-item .lang-name {
    flex: 1;
}

.lang-dropdown-item .lang-code-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.lang-dropdown-item.active .lang-code-badge {
    background: var(--bg-active);
    color: var(--primary);
}

.lang-dropdown-item .check-icon {
    width: 16px;
    height: 16px;
    opacity: 0;
}

.lang-dropdown-item.active .check-icon {
    opacity: 1;
}

/* ============================================
   Scrollbar Styling
   ============================================ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-bg);
    border-radius: 4px;
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
}
