/* ===== FIXED HORIZONTAL SCROLLING - SAFE APPROACH ===== */
html, body {
    width: 100%;
    max-width: 100vw; /* Viewport width */
    overflow-x: clip; /* Safe for root elements */
    position: relative;
    margin: 0;
    padding: 0;
}

/* REMOVE: contain: content - causes issues */
#main,
#footer {
    /* contain: content; REMOVE THIS LINE */
    max-width: 100%;
    overflow-x: clip; /* Better than hidden */
}

.container,
.container-fluid,
.row {
    max-width: 100%;
    overflow-x: clip;
}

/* FIXED: Disable expensive effects on elements that might overflow */
.glass-card,
.premium-card,
.dropdown-menu {
    transform-origin: center;
    /* REMOVED: will-change: transform; */
}

/* FIXED: Safe overflow for specific containers */
.hero-section,
.modal-content,
.card-body {
    overflow-y: auto;
    overflow-x: visible; /* Allow natural overflow */
}

/* FIXED: Mobile overflow fixes */
@media (max-width: 768px) {
    body::-webkit-scrollbar:horizontal {
        height: 0;
        display: none;
    }
    
    .container, .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }
    
    /* Disable ALL expensive effects on mobile */
    .glass-card,
    .premium-card,
    .glass-nav,
    .btn-glass,
    .btn-gradient {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        filter: none !important;
        transform: none !important;
        box-shadow: var(--shadow) !important;
    }
    
    /* Simplify animations on mobile */
    .animate-float,
    .gradient-text {
        animation: none !important;
    }
}

/* ===== CSS RESET & OPTIMIZED VARIABLES ===== */
:root {
    /* Layout */
    --sidebar-width: 280px;
    --header-height: 56px;
    
    /* Light Theme (Default) */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-header: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    --bg-footer: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    
    /* Glass Morphism Variables - REDUCED FOR PERFORMANCE */
    --glass-bg: rgba(255, 255, 255, 0.08); /* Reduced opacity */
    --glass-border: rgba(255, 255, 255, 0.15); /* Reduced opacity */
    --glass-shadow: 0 8px 24px rgba(31, 38, 135, 0.15); /* Lighter shadow */
    --blur-amount: 8px; /* Reduced from 12px */
    
    /* Text Colors */
    --text-primary: #2c3e50;
    --text-secondary: #5a6c7d;
    --text-muted: #64748b;
    --text-light: #ffffff;
    
    /* UI Colors */
    --border-color: #e2e8f0;
    --accent-color: #3498db;
    --accent-hover: #2980b9;
    --gold-color: #ffd700;
    --gold-hover: #ffed4a;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --info-color: #3498db;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    --gradient-gold: linear-gradient(135deg, #ffd700 0%, #ffed4a 100%);
    --gradient-success: linear-gradient(135deg, #27ae60 0%, #229954 100%);
    
    /* Shadows - LIGHTER FOR PERFORMANCE */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 12px 28px rgba(0, 0, 0, 0.1);
    --shadow-xxl: 0 20px 40px rgba(0, 0, 0, 0.15);
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-standard: 250ms cubic-bezier(0.4, 0, 0.2, 1); /* Reduced from 300ms */
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1); /* Reduced from 500ms */

    /* RGB values for rgba() usage */
    --accent-color-rgb: 52, 152, 219;
    --gold-color-rgb: 255, 215, 0;
    
    /* Animations */
    --animation-duration: 0.5s; /* Reduced from 0.6s */
}

[data-theme="dark"] {
    --bg-primary: #0f1419;
    --bg-secondary: #1a202c;
    --bg-card: #2d3748;
    --bg-header: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    --bg-footer: linear-gradient(135deg, #0f1419 0%, #1a202c 100%);
    
    /* Glass Morphism - Dark - REDUCED */
    --glass-bg: rgba(30, 41, 59, 0.3);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    
    /* Text Colors */
    --text-primary: #e2e8f0;
    --text-secondary: #cbd5e0;
    --text-muted: #a0aec0;
    --text-light: #ffffff;
    
    /* UI Colors */
    --border-color: #4a5568;
    --accent-color: #4a9fe3;
    --accent-hover: #63b3ed;
    --gold-color: #ffd700;
    --gold-hover: #ffed4a;
    --success-color: #48bb78;
    --warning-color: #ed8936;
    --danger-color: #fc8181;
    --info-color: #4a9fe3;
    
    /* Gradients - Dark */
    --gradient-primary: linear-gradient(135deg, #4a9fe3 0%, #3182ce 100%);
    
    /* Shadows - Dark - REDUCED */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.15);
    --shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.25);
    --shadow-xl: 0 12px 28px rgba(0, 0, 0, 0.3);
    --shadow-xxl: 0 20px 40px rgba(0, 0, 0, 0.35);
    
    --accent-color-rgb: 74, 159, 227;
    --gold-color-rgb: 255, 215, 0;
}

/* ===== PERFORMANCE OPTIMIZED BASE STYLES ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Smooth scroll ONLY when preferred */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
        scroll-padding-top: 80px;
    }
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-size-adjust: 100%;
}

body {
    font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    
    /* REMOVED: will-change, transform properties - they cause jank */
    /* REMOVED: overflow-x: hidden - already declared above */
    
    /* Optimize for scrolling */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

a {
    text-decoration: none;
    color: inherit;
}

/* Containment - FIXED: Only apply to non-animated elements */
#main,
#footer,
.static-container {
    contain: content; /* More permissive than 'layout style paint' */
}

/* ===== OPTIMIZED GLASS MORPHISM ===== */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur-amount));
    -webkit-backdrop-filter: blur(var(--blur-amount));
    border: 1px solid var(--glass-border);
    border-radius: 20px; /* Reduced from 24px */
    box-shadow: var(--glass-shadow);
    transition: var(--transition-standard);
    
    /* Use will-change only when element will actually change */
    /* REMOVED: will-change: transform, backdrop-filter; */
}

.glass-card-hover:hover {
    transform: translateY(-6px) scale(1.01); /* Reduced from -8px 1.02 */
    backdrop-filter: blur(calc(var(--blur-amount) + 2px));
    -webkit-backdrop-filter: blur(calc(var(--blur-amount) + 2px));
    box-shadow: var(--shadow-xl); /* Reduced from xxl */
}

/* ===== OPTIMIZED PREMIUM CARDS ===== */
.premium-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px; /* Reduced from 20px */
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition-standard), 
                box-shadow var(--transition-standard); /* Split for performance */
    overflow: hidden;
    position: relative;
    
    /* REMOVED: will-change - causes performance issues */
}

.premium-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px; /* Reduced from 4px */
    background: var(--gradient-primary);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.premium-card:hover {
    transform: translateY(-8px) scale(1.01); /* Reduced from -10px 1.02 */
    box-shadow: var(--shadow-xl);
}

.premium-card:hover::before {
    opacity: 1;
}

.card-gradient {
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(var(--accent-color-rgb), 0.08) 100%);
}

/* ===== OPTIMIZED BUTTONS ===== */
.btn-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(8px); /* Reduced from 10px */
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 10px 24px; /* Reduced from 12px 28px */
    border-radius: 10px; /* Reduced from 12px */
    font-weight: 600;
    transition: all var(--transition-standard);
    position: relative;
    overflow: hidden;
    
    /* REMOVED: will-change */
}

/* Optimize the hover effect for performance */
.btn-glass:hover {
    transform: translateY(-2px); /* Reduced from -3px */
    box-shadow: var(--shadow-md); /* Reduced from lg */
}

/* Remove expensive ::before animation */
.btn-glass::before {
    display: none; /* This animation is expensive */
}

.btn-gradient {
    background: var(--gradient-primary);
    border: none;
    color: white;
    padding: 12px 28px; /* Reduced from 14px 32px */
    border-radius: 10px; /* Reduced from 12px */
    font-weight: 600;
    transition: transform var(--transition-standard), 
                box-shadow var(--transition-standard); /* Split */
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.btn-gradient:hover {
    transform: translateY(-2px); /* Reduced from -3px */
    box-shadow: 0 8px 24px rgba(var(--accent-color-rgb), 0.3); /* Reduced */
}

/* Remove expensive ::after effect */
.btn-gradient::after {
    display: none;
}

.btn-gold {
    background: var(--gradient-gold);
    border: none;
    color: #333;
    padding: 12px 28px;
    border-radius: 10px;
    font-weight: 600;
    transition: transform var(--transition-standard), 
                box-shadow var(--transition-standard);
}

.btn-gold:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(255, 215, 0, 0.3);
}

/* ===== OPTIMIZED TABLE ===== */
.premium-table {
    background: var(--bg-card);
    border-radius: 12px; /* Reduced from 16px */
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.premium-table thead th {
    padding: 16px 20px; /* Reduced from 18px 20px */
}

.premium-table tbody td {
    padding: 14px 20px; /* Reduced from 16px 20px */
}

.premium-table tbody tr:hover {
    background: rgba(var(--accent-color-rgb), 0.04); /* Reduced opacity */
    transform: translateX(3px); /* Reduced from 5px */
}

/* ===== OPTIMIZED PROGRESS BAR ===== */
.progress-glass {
    height: 10px; /* Reduced from 12px */
    background: var(--glass-bg);
    backdrop-filter: blur(6px); /* Reduced from 10px */
    border-radius: 8px; /* Reduced from 10px */
    overflow: hidden;
}

.progress-glass .progress-bar {
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1); /* Reduced duration */
}

/* Remove expensive shimmer animation */
.progress-glass .progress-bar::after {
    display: none;
}

/* ===== OPTIMIZED FORM ELEMENTS ===== */
.form-control-glass {
    padding: 12px 18px; /* Reduced from 14px 20px */
    border-radius: 10px; /* Reduced from 12px */
}

/* ===== OPTIMIZED ANIMATIONS ===== */
/* Remove expensive infinite animations by default */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); } /* Reduced from -10px */
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Use animations sparingly */
.animate-float {
    animation: float 4s ease-in-out infinite; /* Slower duration */
}

/* Disable gradient animation by default - too expensive */
.gradient-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    /* REMOVED: animation: gradientShift */
}

/* Loading animation - simplified */
.loading::after {
    animation: shimmer 2s infinite; /* Slower */
}

/* ===== CRITICAL PERFORMANCE OPTIMIZATIONS ===== */
/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    /* Disable all transforms and filters */
    .glass-card,
    .btn-glass,
    .btn-gradient,
    .premium-card {
        transform: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        filter: none !important;
        transition: none !important;
    }
}

/* ===== RESPONSIVE OPTIMIZATIONS ===== */
@media (max-width: 1200px) {
    :root {
        --blur-amount: 6px;
    }
    
    .glass-card {
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }
}

@media (max-width: 992px) {
    :root {
        --blur-amount: 4px;
    }
    
    .premium-card:hover {
        transform: translateY(-4px) scale(1.005);
    }
    
    .glass-card {
        border-radius: 16px;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
}

/* MOBILE - DISABLE EXPENSIVE EFFECTS */
@media (max-width: 768px) {
    :root {
        --blur-amount: 0px; /* No blur on mobile */
    }
    
    /* Disable ALL expensive effects on mobile */
    .glass-card {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
    }
    
    .btn-glass {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--bg-card);
    }
    
    /* Disable all hover transforms on touch devices */
    .btn-glass:hover,
    .btn-gradient:hover,
    .btn-gold:hover,
    .premium-card:hover,
    .glass-card-hover:hover,
    .premium-table tbody tr:hover {
        transform: none !important;
    }
    
    /* Disable all animations on mobile */
    .animate-float,
    .animate-pulse-glow,
    .gradient-text,
    .loading::after,
    .loader-spinner,
    .progress-glass .progress-bar::after {
        animation: none !important;
    }
    
    /* Simplify cards */
    .premium-card::before,
    .btn-glass::before,
    .btn-gradient::after {
        display: none;
    }
    
    /* Optimize tables for mobile */
    .premium-table {
        border-radius: 8px;
        font-size: 0.9rem;
    }
    
    .premium-table thead th,
    .premium-table tbody td {
        padding: 12px 16px;
    }
}

@media (max-width: 576px) {
    .premium-card {
        border-radius: 12px;
    }
    
    .btn-gradient,
    .btn-glass,
    .btn-gold {
        padding: 10px 20px;
        font-size: 0.9rem;
        border-radius: 8px;
    }
}

/* ===== RTL SUPPORT ===== */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .form-label-floating {
    left: auto;
    right: 18px; /* Adjusted */
}

[dir="rtl"] .password-toggle {
    left: 15px;
    right: auto;
}

[dir="rtl"] .premium-table tbody tr:hover {
    transform: translateX(-3px); /* Reduced from -5px */
}

/* Print styles */
@media print {
    .glass-card,
    .btn-glass,
    .btn-gradient,
    .page-loader,
    .navbar,
    #footer {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
    
    .premium-card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        break-inside: avoid;
    }
}