/**
 * Theme System - Light & Dark Mode
 * Color palette extracted from reference designs
 */

/* ========================================
   CSS VARIABLES - LIGHT THEME (DEFAULT)
   ======================================== */
:root {
    /* Backgrounds */
    --bg-primary: #f0ebe5;
    --bg-secondary: #e8e1d8;
    --bg-surface: #faf7f4;
    --bg-hover: #e0d9d0;
    
    /* Text Colors */
    --text-primary: #2c2c2c;
    --text-secondary: #6b6b6b;
    --text-tertiary: #9ca3af;
    --text-inverse: #ffffff;
    
    /* Borders & Dividers */
    --border-primary: #d9cfc3;
    --border-secondary: #c9bdb1;
    --border-focus: #bc7a5a;
    
    /* Brand & Accent Colors */
    --color-brand: #bc7a5a;
    --color-accent: #bc7a5a;
    --color-accent-hover: #a86b4d;
    
    /* Semantic Colors */
    --color-success: #16a34a;
    --color-success-bg: #f0fdf4;
    --color-warning: #f59e0b;
    --color-warning-bg: #fffbeb;
    --color-error: #dc2626;
    --color-error-bg: #fff5f5;
    --color-info: #3b82f6;
    --color-info-bg: #eff6ff;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 8px 24px rgba(0, 0, 0, 0.15);
    
    /* Focus Ring */
    --focus-ring: 0 0 0 3px rgba(188, 122, 90, 0.15);
    --focus-ring-accent: 0 0 0 3px rgba(188, 122, 90, 0.25);
    
    /* Chart Colors */
    --chart-primary: #bc7a5a;
    --chart-secondary: #d4a08a;
    --chart-grid: rgba(188, 122, 90, 0.08);
    
    /* Opacity Levels */
    --opacity-hover: 0.7;
    --opacity-disabled: 0.5;
}

/* ========================================
   CSS VARIABLES - DARK THEME
   ======================================== */
[data-theme="dark"] {
    /* Backgrounds */
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-surface: #2a2a2a;
    --bg-hover: #3a3a3a;
    
    /* Text Colors */
    --text-primary: #f5f5f5;
    --text-secondary: #b8b8b8;
    --text-tertiary: #8a8a8a;
    --text-inverse: #2c2c2c;
    
    /* Borders & Dividers */
    --border-primary: #3a3a3a;
    --border-secondary: #4a4a4a;
    --border-focus: #ff6b35;
    
    /* Brand & Accent Colors */
    --color-brand: #ff6b35;
    --color-accent: #ff6b35;
    --color-accent-hover: #ff7a47;
    
    /* Semantic Colors */
    --color-success: #22c55e;
    --color-success-bg: #14532d;
    --color-warning: #fbbf24;
    --color-warning-bg: #451a03;
    --color-error: #ef4444;
    --color-error-bg: #7f1d1d;
    --color-info: #60a5fa;
    --color-info-bg: #1e3a8a;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 8px 24px rgba(0, 0, 0, 0.6);
    
    /* Focus Ring */
    --focus-ring: 0 0 0 3px rgba(255, 107, 53, 0.3);
    --focus-ring-accent: 0 0 0 3px rgba(255, 107, 53, 0.4);
    
    /* Chart Colors */
    --chart-primary: #ff6b35;
    --chart-secondary: #ffa07a;
    --chart-grid: rgba(255, 255, 255, 0.05);
    
    /* Opacity Levels */
    --opacity-hover: 0.8;
    --opacity-disabled: 0.4;
}

/* ========================================
   BASE STYLES
   ======================================== */
body {
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ========================================
   CARDS & SURFACES
   ======================================== */
.card,
.table-card,
.stats-card,
.hero-card,
.feature-card,
.login-card {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-primary) !important;
    box-shadow: var(--shadow-sm) !important;
    transition: all 0.2s ease;
}

.card:hover,
.table-card:hover,
.stats-card:hover {
    box-shadow: var(--shadow-md) !important;
}

.card-header {
    background: var(--bg-surface) !important;
    border-bottom: 1px solid var(--border-primary) !important;
    color: var(--text-primary) !important;
}

.card-header h5,
.card-header h6 {
    color: var(--text-primary) !important;
}

/* ========================================
   TYPOGRAPHY
   ======================================== */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary) !important;
}

.text-muted {
    color: var(--text-secondary) !important;
}

.lead {
    color: var(--text-secondary) !important;
}

/* ========================================
   BUTTONS
   ======================================== */
.btn-primary,
.btn-primary-cta,
.btn-login {
    background: var(--color-brand) !important;
    border: none !important;
    color: var(--text-inverse) !important;
}

.btn-primary:hover,
.btn-primary-cta:hover,
.btn-login:hover {
    background: var(--color-accent) !important;
    transform: translateY(-1px);
}

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

.btn-secondary:hover {
    background: var(--bg-hover) !important;
    border-color: var(--border-secondary) !important;
}

.btn-outline-secondary {
    border-color: var(--border-primary) !important;
    color: var(--text-secondary) !important;
    background: transparent !important;
}

.btn-outline-secondary:hover {
    background: var(--bg-hover) !important;
    border-color: var(--border-secondary) !important;
}

.btn-link {
    color: var(--text-secondary) !important;
}

.btn-link:hover {
    color: var(--text-primary) !important;
}

/* ========================================
   FORMS
   ======================================== */
.form-control,
.form-select {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-primary) !important;
    color: var(--text-primary) !important;
    transition: all 0.2s ease;
}

.form-control:focus,
.form-select:focus {
    background: var(--bg-surface) !important;
    border-color: var(--border-focus) !important;
    box-shadow: var(--focus-ring) !important;
    color: var(--text-primary) !important;
}

.form-control::placeholder {
    color: var(--text-tertiary) !important;
}

.form-label {
    color: var(--text-primary) !important;
}

/* Form Switch */
.form-check-input {
    background-color: var(--border-secondary);
    border-color: var(--border-primary);
}

.form-check-input:checked {
    background-color: var(--color-brand) !important;
    border-color: var(--color-brand) !important;
}

.form-check-label {
    color: var(--text-primary) !important;
}

/* ========================================
   TABLES
   ======================================== */
.table {
    color: var(--text-primary) !important;
}

.table thead th {
    background: var(--bg-secondary) !important;
    color: var(--text-secondary) !important;
    border-bottom: 1px solid var(--border-primary) !important;
}

.table tbody tr {
    border-color: var(--border-primary) !important;
}

.table tbody tr:hover {
    background: var(--bg-hover) !important;
}

.table tbody td {
    border-color: var(--border-primary) !important;
    color: var(--text-primary) !important;
}

/* ========================================
   BADGES
   ======================================== */
.badge {
    transition: all 0.2s ease;
}

.badge.bg-primary {
    background: var(--color-brand) !important;
    color: var(--text-inverse) !important;
}

.badge-country,
.badge-device,
.badge-browser {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-primary) !important;
}

/* ========================================
   NAVIGATION
   ======================================== */
.navbar-custom {
    background: var(--bg-surface) !important;
    border-bottom: 1px solid var(--border-primary) !important;
}

.navbar-nav {
    gap: 0.5rem !important;
}

.brand-logo {
    background: var(--color-brand) !important;
}

.brand-text {
    color: var(--text-primary) !important;
}

.nav-link-custom {
    color: var(--text-secondary) !important;
    padding: 0.5rem 1rem !important;
    margin: 0 !important;
}

.nav-link-custom:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

.nav-link-custom.active {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

.nav-link-custom i {
    color: var(--text-secondary) !important;
    margin-right: 0.5rem !important;
}

.nav-link-custom.active i,
.nav-link-custom:hover i {
    color: var(--text-primary) !important;
}

.user-dropdown-toggle {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

.user-avatar {
    background: var(--color-brand) !important;
    color: var(--text-inverse) !important;
}

/* ========================================
   DROPDOWNS
   ======================================== */
.dropdown-menu,
.dropdown-menu-custom {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-primary) !important;
    box-shadow: var(--shadow-md) !important;
}

.dropdown-item,
.dropdown-item-custom {
    color: var(--text-primary) !important;
}

.dropdown-item:hover,
.dropdown-item-custom:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

.dropdown-divider {
    border-color: var(--border-primary) !important;
}

/* ========================================
   ALERTS
   ======================================== */
.alert {
    border: 1px solid var(--border-primary) !important;
}

.alert-success {
    background: var(--color-success-bg) !important;
    color: var(--color-success) !important;
}

.alert-warning {
    background: var(--color-warning-bg) !important;
    color: var(--color-warning) !important;
}

.alert-danger {
    background: var(--color-error-bg) !important;
    color: var(--color-error) !important;
}

.alert-info {
    background: var(--color-info-bg) !important;
    color: var(--color-info) !important;
}

/* ========================================
   MODALS
   ======================================== */
.modal-content {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-primary) !important;
}

.modal-header {
    background: var(--bg-surface) !important;
    border-bottom: 1px solid var(--border-primary) !important;
}

.modal-title {
    color: var(--text-primary) !important;
}

.modal-body {
    color: var(--text-primary) !important;
}

.modal-footer {
    background: var(--bg-surface) !important;
    border-top: 1px solid var(--border-primary) !important;
}

.modal-backdrop.show {
    opacity: 0.5;
}

[data-theme="dark"] .modal-backdrop.show {
    opacity: 0.7;
}

/* Modal close button */
.btn-close {
    opacity: 0.6;
}

.btn-close:hover {
    opacity: 1;
}

/* ========================================
   SPECIAL ELEMENTS
   ======================================== */

/* Logo Container */
.logo-container,
.hero-logo {
    background: var(--color-brand) !important;
    color: var(--text-inverse) !important;
}

/* Stats Icon */
.stats-icon {
    background: var(--color-brand) !important;
    color: var(--text-inverse) !important;
}

/* Dividers */
.divider {
    background: var(--border-primary) !important;
}

/* Code Blocks */
code,
.code-block,
.api-key-display,
.log-entry {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-primary) !important;
    color: var(--text-primary) !important;
}

/* Stat Bubbles */
.stat-bubble {
    background: var(--bg-secondary) !important;
    border-radius: 8px !important;
    transition: all 0.2s ease;
}

.stat-bubble-value {
    color: var(--text-primary) !important;
    margin-bottom: 0.25rem !important;
    font-size: 1.5rem !important;
    font-weight: 600 !important;
}

.stat-bubble-label {
    color: var(--text-secondary) !important;
    font-size: 0.75rem !important;
}

/* Info Sections */
.info-section {
    background: var(--bg-secondary) !important;
}

/* More Options Toggle */
.more-options-toggle {
    color: var(--text-primary) !important;
}

.more-options-toggle:hover {
    color: var(--text-secondary) !important;
}

/* Sort Buttons */
.sort-btn {
    border-color: var(--border-primary) !important;
    color: var(--text-secondary) !important;
    background: transparent !important;
}

.sort-btn.active {
    background: var(--color-brand) !important;
    color: var(--text-inverse) !important;
    border-color: var(--color-brand) !important;
}

.sort-btn:not(.active):hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

/* URL Links */
.url-link,
.short-url-link {
    color: var(--text-primary) !important;
}

.url-link:hover,
.short-url-link:hover {
    color: var(--text-primary) !important;
    opacity: 0.8;
}

/* Copy button visibility in dark mode */
.btn-link {
    color: var(--text-secondary) !important;
}

.btn-link:hover {
    color: var(--text-primary) !important;
}

/* ========================================
   DARK THEME SPECIFIC ADJUSTMENTS
   ======================================== */
[data-theme="dark"] {
    /* Enhance contrast for important elements */
    .btn-primary,
    .btn-primary-cta,
    .stats-icon {
        background: var(--color-accent) !important;
    }
    
    /* Logo should be WHITE in dark mode, not orange */
    .brand-logo {
        background: #ffffff !important;
    }
    
    .brand-logo i {
        color: #2c2c2c !important;
    }
    
    /* Dark theme specific hover effects */
    .btn-primary:hover,
    .btn-primary-cta:hover {
        background: var(--color-accent-hover) !important;
    }
    
    /* Fix icon visibility in dark mode */
    .fa, .fas, .far, .fal, .fab {
        color: inherit;
    }
    
    /* Navigation selected item and username - MUCH BRIGHTER */
    .nav-link-custom.active,
    .nav-link-custom.active span {
        color: #ffffff !important;
        font-weight: 600 !important;
    }
    
    .nav-link-custom.active i {
        color: #ffffff !important;
    }
    
    /* Navigation hover state - BRIGHTER */
    .nav-link-custom:hover {
        color: #e5e5e5 !important;
    }
    
    .nav-link-custom:hover i {
        color: #e5e5e5 !important;
    }
    
    .user-name {
        color: #ffffff !important;
        font-weight: 500 !important;
    }
    
    .user-dropdown-toggle {
        color: #ffffff !important;
    }
    
    /* Theme toggle button in dark mode */
    .theme-toggle-btn {
        color: #b8b8b8 !important;
    }
    
    .theme-toggle-btn:hover {
        background: var(--bg-hover) !important;
        color: #ffffff !important;
    }
    
    /* Make sure copy icons and small buttons are visible */
    .btn-link,
    .btn-outline-secondary {
        color: var(--text-secondary) !important;
    }
    
    .btn-link:hover,
    .btn-outline-secondary:hover {
        color: var(--text-primary) !important;
    }
    
    /* Stats card numbers visibility */
    .stats-value,
    .card-title,
    h1, h2, h3, h4, h5, h6 {
        color: var(--text-primary) !important;
    }
    
    /* Original URL visibility - BRIGHTER */
    .text-truncate,
    .url-link,
    .short-url-link {
        color: #e5e5e5 !important;
    }

    /* Short URL hover - make it WHITE for visibility */
    .short-url-link:hover {
        color: #ffffff !important;
        text-decoration: underline !important;
    }
    
    /* Dropdown menu three-dot button */
    .dropdown-toggle,
    .three-dots-menu {
        color: var(--text-secondary) !important;
    }
    
    .dropdown-toggle:hover,
    .three-dots-menu:hover {
        color: #ffffff !important;
        background: rgba(255, 255, 255, 0.1) !important;
    }
    
    /* Table action buttons */
    .btn-action {
        border-color: var(--border-primary) !important;
        color: var(--text-secondary) !important;
    }
    
    .btn-action:hover {
        background: var(--bg-hover) !important;
        color: var(--text-primary) !important;
    }
    
    /* Stat Bubbles in Dark Mode - Use accent gradient */
    .stat-bubble {
        background: linear-gradient(135deg, rgba(255, 107, 53, 0.15) 0%, rgba(255, 107, 53, 0.08) 100%) !important;
        border: 1px solid rgba(255, 107, 53, 0.2) !important;
    }

    .stat-bubble-value {
        color: #ffffff !important;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    }

    .stat-bubble-label {
        color: #ffa07a !important;
    }

    /* Modal close button - make it white/bright in dark mode */
    .btn-close {
        filter: invert(1) grayscale(100%) brightness(200%);
        opacity: 0.8;
    }

    .btn-close:hover {
        opacity: 1;
    }
}

/* ========================================
   THEME TOGGLE BUTTON (Optional)
   ======================================== */
.theme-toggle {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 1000;
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.theme-toggle i {
    color: var(--text-primary);
    font-size: 1.25rem;
}

/* ========================================
   PAGINATION
   ======================================== */
.pagination {
    gap: 0.25rem;
}

.page-link {
    border: 1px solid var(--border-primary) !important;
    background: var(--bg-surface) !important;
    color: var(--text-secondary) !important;
    border-radius: 6px !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    transition: all 0.2s ease !important;
}

.page-link:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-secondary) !important;
}

.page-item.active .page-link {
    background: var(--color-brand) !important;
    border-color: var(--color-brand) !important;
    color: var(--text-inverse) !important;
}

.page-item.disabled .page-link {
    background: var(--bg-surface) !important;
    border-color: var(--border-primary) !important;
    color: var(--text-tertiary) !important;
    opacity: 0.5 !important;
}

/* ========================================
   SMOOTH TRANSITIONS
   ======================================== */
* {
    transition-property: background-color, border-color, color, fill, stroke;
    transition-duration: 0.2s;
    transition-timing-function: ease;
}

/* Disable transitions on theme change for instant switch */
.theme-transitioning * {
    transition: none !important;
}

