/**
 * Smart Responsive System
 * Auto SEO Pilot - SaaS Platinum Edition v20.4
 * 
 * نظام ذكي شامل للاستجابة الكاملة والمرونة
 * يستخدم CSS Logical Properties لضمان العمل الصحيح في RTL و LTR
 */

/* ============================================
   SIDEBAR FLEXIBILITY SYSTEM
   ============================================ */
/* NOTE: All .modern-sidebar rules are now in unified-layout.css
   This file should NOT define sidebar positioning rules to avoid conflicts */


/* ============================================
   MAIN CONTENT FLEXIBILITY
   ============================================ */
/* NOTE: Main content positioning is handled by unified-layout.css */
/* This file should not define base .main-content rules to avoid conflicts */
/* unified-layout.css loads LAST and is the single source of truth */

/* DISABLED: Base main-content rules - handled by unified-layout.css */
/*
.main-content {
    margin-inline-start: var(--sidebar-width);
    padding: 30px;
    min-height: auto; /* Changed from 100vh to auto to prevent empty space */
    padding-bottom: 50px;
    position: relative;
    width: calc(100% - var(--sidebar-width));
    box-sizing: border-box;
    background: var(--bg-main-gradient);
    z-index: 1;
    
    transition: 
        margin-inline-start 0.3s ease,
        margin-inline-end 0.3s ease,
        width 0.3s ease,
        padding-inline-start 0.3s ease,
        padding-inline-end 0.3s ease,
        background 0.3s ease;
}
*/

/* ============================================
   MAIN CONTENT SECTIONS
   ============================================ */
/* NOTE: Main content sections positioning is handled by unified-layout.css */
/* This file should not define base .main-content-section rules to avoid conflicts */

/* DISABLED: Base main-content-section rules - handled by unified-layout.css */
/*
.main-content-section {
    padding: 30px;
    min-height: 100vh;
    box-sizing: border-box;
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: var(--sidebar-width);
    inset-inline-end: 0;
    width: calc(100% - var(--sidebar-width));
    z-index: 90;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 100vh;
    background: var(--bg-main-gradient);
    
    transition: 
        inset-inline-start 0.3s ease,
        inset-inline-end 0.3s ease,
        width 0.3s ease,
        padding 0.3s ease,
        background 0.3s ease;
}
*/

/* Mobile: main-content-section should be relative, not fixed */
/* NOTE: This is handled by unified-layout.css */
@media (max-width: 991px) {
    /* unified-layout.css handles this */
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */
/* NOTE: Sidebar and main content positioning is handled by unified-layout.css */

/* DISABLED: Now handled by Tailwind CSS classes */
/* Tablet: 769px - 992px - Sidebar becomes off-canvas */
/*
@media (max-width: 992px) and (min-width: 769px) {
    /* Sidebar: Hidden by default, slides in */
    .modern-sidebar {
        width: 70vw !important;
        max-width: 320px !important;
        min-width: 250px !important;
        
        /* RTL: Slide from right - HIDDEN by default */
        transform: translateX(100%) !important;
        inset-inline-end: 0;
        inset-inline-start: auto;
        visibility: hidden !important;
        opacity: 0 !important;
        
        /* Enhanced transitions */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.3s ease,
                    visibility 0.3s ease,
                    box-shadow 0.3s ease;
        
        /* Ensure proper z-index - must be above overlay when active */
        z-index: 10000 !important;
    }
    
    /* LTR: Slide from left - HIDDEN by default */
    [dir="ltr"] .modern-sidebar {
        transform: translateX(-100%) !important;
        inset-inline-start: 0;
        inset-inline-end: auto;
        visibility: hidden !important;
        opacity: 0 !important;
    }
    
    /* Active State - SHOW when active - CRITICAL FIX */
    .modern-sidebar.mobile-active {
        transform: translateX(0) !important;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        display: flex !important;
        /* Ensure sidebar is above overlay */
        z-index: 10000 !important;
    }
    
    /* Overlay enhancements */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 9999;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    
    /* Main Content: Full Width - NOTE: unified-layout.css handles this */
    /* These rules are kept for backward compatibility but unified-layout.css overrides */
    .main-content,
    .main-content-section {
        margin-inline-start: 0 !important;
        margin-inline-end: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: var(--spacing-lg);
        inset-inline-start: 0 !important;
        inset-inline-end: 0 !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }
    
    /* Ensure all content inside respects container */
    .main-content > *,
    .main-content-section > * {
        max-width: 100% !important;
        box-sizing: border-box;
    }
    
    /* Prevent horizontal overflow */
    body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    html {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
*/

/* DISABLED: All sidebar/main-content rules now in unified-layout.css */
/* Mobile overlay and body scroll handled by unified-layout.css */

/* DISABLED: Now handled by Tailwind CSS classes */
/* Small Mobile: Max 480px - Sidebar rules disabled */
/* 
@media (max-width: 480px) {
    .modern-sidebar {
        width: 85vw !important;
        max-width: var(--sidebar-width) !important;
        transform: translateX(100%) !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }
    
    [dir="ltr"] .modern-sidebar {
        transform: translateX(-100%) !important;
    }
    
    .modern-sidebar.mobile-active {
        transform: translateX(0) !important;
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        display: flex !important;
        z-index: 10000 !important;
    }
}
*/

/* Main Content: NOTE: unified-layout.css handles positioning */
/* These rules only adjust padding, unified-layout.css handles margin/width */
@media (max-width: 480px) {
    .main-content,
    .main-content-section {
        padding-inline-start: var(--spacing-sm) !important;
        padding-inline-end: var(--spacing-sm) !important;
        padding-top: var(--spacing-sm) !important;
        padding-bottom: var(--spacing-sm) !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    
    /* Ensure no horizontal overflow - CRITICAL */
    body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        position: relative !important;
    }
    
    html {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}
/* ============================================
   LANGUAGE SWITCHER RESPONSIVE
   ============================================ */

.language-switcher {
    position: relative;
    display: inline-block;
}

.lang-switch-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
    border: 1.5px solid rgba(99, 102, 241, 0.3);
    border-radius: 14px;
    color: #ffffff;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}

/* High Specificity Rules for language switcher text - without !important */
button.lang-switch-btn.modern-btn,
button#langSwitchBtn.modern-btn,
.modern-btn.lang-switch-btn,
#langSwitchBtn.modern-btn {
    color: #ffffff;
}

button.lang-switch-btn.modern-btn span#currentLangDisplay,
button#langSwitchBtn.modern-btn span#currentLangDisplay,
.modern-btn.lang-switch-btn span#currentLangDisplay,
#langSwitchBtn.modern-btn span#currentLangDisplay,
button.lang-switch-btn span#currentLangDisplay,
button#langSwitchBtn span#currentLangDisplay {
    color: #ffffff;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.lang-switch-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s ease;
}

.lang-switch-btn:hover::before {
    left: 100%;
}

@media (max-width: 480px) {
    .lang-switch-btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }
    
    .lang-switch-btn span {
        display: none;
    }
}

.lang-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    inset-inline-start: 0;
    background: var(--card-bg, rgba(30, 41, 59, 0.95));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    z-index: 10000;
    overflow: hidden;
    backdrop-filter: blur(10px);
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* ============================================
   UTILITY CLASSES FOR FLEXIBILITY
   ============================================ */

/* Force Layout Recalculation */
.force-reflow {
    transform: translateZ(0);
    will-change: transform;
}

/* Smooth Transitions */
.smooth-transition {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Prevent Layout Shift */
.prevent-shift {
    contain: layout style paint;
}

/* ============================================
   DIRECTION-AWARE UTILITIES
   ============================================ */

/* Margin Utilities */
.margin-start-auto {
    margin-inline-start: auto;
}

.margin-end-auto {
    margin-inline-end: auto;
}

/* Padding Utilities */
.padding-start-sm {
    padding-inline-start: 0.5rem;
}

.padding-end-sm {
    padding-inline-end: 0.5rem;
}

/* Position Utilities */
.position-start {
    inset-inline-start: 0;
}

.position-end {
    inset-inline-end: 0;
}

/* ============================================
   FIX FOR LANGUAGE SWITCHING
   ============================================ */
/* NOTE: Sidebar language switching is handled by unified-layout.css */

/* Language switching state */
body.language-switching {
    overflow: hidden;
    position: relative;
}

body.language-switching * {
    pointer-events: none;
}

body.language-switching .main-content,
body.language-switching .main-content-section {
    pointer-events: auto;
}

/* ============================================
   COMPREHENSIVE RESPONSIVE FIXES
   ============================================ */

/* Ensure all containers are flexible */
/* NOTE: .main-content and .main-content-section positioning handled by unified-layout.css */
.container,
.container-fluid {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

/* Prevent horizontal overflow on all screen sizes - CRITICAL FIX */
body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    position: relative !important;
}

html {
    overflow-x: hidden !important;
    max-width: 100vw !important;
}

/* Ensure no element causes horizontal overflow */
* {
    max-width: 100%;
    box-sizing: border-box;
}

/* Ensure sidebar doesn't cause overflow */
@media (max-width: 992px) {
    body {
        overflow-x: hidden !important;
        position: relative;
    }
    
    html {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    * {
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Flexible grids */
.grid,
.grid-stats,
.actions-grid {
    display: grid;
    gap: 1rem;
    box-sizing: border-box;
}

/* Responsive images */
img {
    max-width: 100%;
    height: auto;
}

/* Responsive tables */
table {
    width: 100%;
    overflow-x: auto;
    display: block;
}

@media (min-width: 768px) {
    table {
        display: table;
    }
}

/* Flexible buttons */
button,
.btn,
.nav-btn {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
}

/* Responsive text */
@media (max-width: 480px) {
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    p, span, div { font-size: 0.9rem; }
}

/* ============================================
   MOBILE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        position: relative !important;
    }
    
    /* Ensure all elements respect container */
    * {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Prevent any element from causing overflow */
    /* NOTE: Main content positioning handled by unified-layout.css */
    .main-content,
    .main-content-section,
    .container,
    .container-fluid {
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }
    
    /* Flexible padding */
    .main-content,
    .main-content-section {
        padding-inline-start: 15px;
        padding-inline-end: 15px;
    }
    
    /* Stack elements on mobile */
    .flex-row {
        flex-direction: column;
    }
    
    /* Full width buttons on mobile */
    button,
    .btn {
        width: 100%;
        margin-inline-start: 0;
        margin-inline-end: 0;
        box-sizing: border-box;
    }
    
    /* Ensure tables don't overflow */
    .table-wrap,
    table {
        max-width: 100% !important;
        overflow-x: auto !important;
    }
}
