/**
 * ╔═══════════════════════════════════════════════════════════════════════════╗
 * ║           EventOS - Ultra-Professional Responsive Design System           ║
 * ║           نظام التصميم المتجاوب الاحترافي                                ║
 * ╚═══════════════════════════════════════════════════════════════════════════
 *
 * Architecture: Mobile-First Responsive Design
 * Breakpoints: 320px (Mobile) → 768px (Tablet) → 1024px (Desktop) → 1440px (Large)
 * Typography: Fluid Type Scale (clamp())
 * Layout: CSS Grid + Flexbox with Container Queries
 * Performance: GPU Acceleration, Lazy Loading, Minimal Reflows
 */

/* ═══════════════════════════════════════════════════════════════════════════
   1. CSS VARIABLES - Design Tokens
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    /* Fluid Typography Scale */
    --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
    --text-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
    --text-lg: clamp(1.125rem, 1rem + 0.65vw, 1.375rem);
    --text-xl: clamp(1.25rem, 1.1rem + 0.8vw, 1.75rem);
    --text-2xl: clamp(1.5rem, 1.3rem + 1vw, 2.25rem);
    --text-3xl: clamp(1.875rem, 1.6rem + 1.4vw, 3rem);
    --text-4xl: clamp(2.25rem, 1.9rem + 1.8vw, 4rem);
    
    /* Fluid Spacing */
    --space-xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.5rem);
    --space-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
    --space-md: clamp(0.75rem, 0.6rem + 0.75vw, 1.25rem);
    --space-lg: clamp(1rem, 0.8rem + 1vw, 2rem);
    --space-xl: clamp(1.5rem, 1.2rem + 1.5vw, 3rem);
    --space-2xl: clamp(2rem, 1.5rem + 2.5vw, 5rem);
    
    /* Responsive Border Radius */
    --radius-sm: clamp(0.375rem, 0.3rem + 0.35vw, 0.75rem);
    --radius-md: clamp(0.75rem, 0.6rem + 0.75vw, 1.25rem);
    --radius-lg: clamp(1rem, 0.8rem + 1vw, 1.75rem);
    --radius-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2.5rem);
    
    /* Responsive Sidebar Width */
    --sidebar-width: 280px;
    --sidebar-collapsed: 80px;
    --mobile-navbar-height: 64px;
    --bottom-nav-height: 72px;
    
    /* Touch Targets (Minimum 44px for accessibility) */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    --touch-target-large: 56px;
    
    /* Z-Index Scale */
    --z-base: 1;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal: 300;
    --z-toast: 400;
    --z-tooltip: 500;
}

/* ═══════════════════════════════════════════════════════════════════════════
   2. BASE RESET - Mobile-First Foundation
   ═══════════════════════════════════════════════════════════════════════════ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Almarai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--neo-text-primary);
    background: var(--neo-bg);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent pull-to-refresh on mobile web apps */
@supports (-webkit-touch-callout: none) {
    body {
        overscroll-behavior-y: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   3. RESPONSIVE GRID SYSTEM
   ═══════════════════════════════════════════════════════════════════════════ */

.responsive-container {
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
}

@media (min-width: 640px) {
    .responsive-container {
        max-width: 640px;
    }
}

@media (min-width: 768px) {
    .responsive-container {
        max-width: 768px;
    }
}

@media (min-width: 1024px) {
    .responsive-container {
        max-width: 1024px;
    }
}

@media (min-width: 1280px) {
    .responsive-container {
        max-width: 1280px;
    }
}

@media (min-width: 1536px) {
    .responsive-container {
        max-width: 1536px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   4. RESPONSIVE NAVIGATION - Desktop Sidebar / Mobile Bottom Nav
   ═══════════════════════════════════════════════════════════════════════════ */

/* Desktop Sidebar (Default) */
.os-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: linear-gradient(180deg, var(--neo-surface) 0%, rgba(30,41,59,0.98) 100%);
    backdrop-filter: blur(20px);
    border-left: 1px solid rgba(255,255,255,0.05);
    z-index: var(--z-sticky);
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* Mobile: Transform Sidebar to Bottom Navigation */
@media (max-width: 1023px) {
    .os-sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: var(--bottom-nav-height);
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        padding: var(--space-sm) var(--space-md);
        border-left: none;
        border-top: 1px solid rgba(255,255,255,0.05);
        overflow: visible;
    }
    
    .os-sidebar .sidebar-brand,
    .os-sidebar .sidebar-section-title,
    .os-sidebar .nav-category-header,
    .os-sidebar .nav-subitems {
        display: none;
    }
    
    .os-sidebar .nav-section {
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        width: 100%;
        margin: 0;
    }
    
    .os-sidebar .nav-item {
        flex-direction: column;
        align-items: center;
        gap: var(--space-xs);
        padding: var(--space-sm);
        min-width: var(--touch-target-large);
        min-height: var(--touch-target-large);
    }
    
    .os-sidebar .nav-item i {
        font-size: 1.25rem;
        width: auto;
    }
    
    .os-sidebar .nav-item span {
        font-size: var(--text-xs);
    }
    
    .os-sidebar .nav-item::before {
        display: none;
    }
    
    /* Add top border indicator for active state on mobile */
    .os-sidebar .nav-item.active {
        background: transparent;
        border-top: 3px solid var(--primary);
        margin-top: -3px;
    }
}

/* Mobile Hamburger Menu (Alternative for complex navigation) */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    z-index: calc(var(--z-sticky) + 10);
    width: var(--touch-target-large);
    height: var(--touch-target-large);
    background: rgba(30,41,59,0.9);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-md);
    color: white;
    font-size: 1.5rem;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

@media (max-width: 1023px) {
    .mobile-menu-toggle {
        display: flex;
    }
}

/* Mobile Menu Overlay */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(8px);
    z-index: calc(var(--z-sticky) + 5);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
    display: block;
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════════════
   5. RESPONSIVE MAIN CONTENT AREA
   ═══════════════════════════════════════════════════════════════════════════ */

.os-main {
    margin-right: var(--sidebar-width);
    padding: var(--space-xl);
    min-height: 100vh;
    min-height: 100dvh;
    transition: margin 0.3s ease;
}

@media (max-width: 1023px) {
    .os-main {
        margin-right: 0;
        margin-bottom: var(--bottom-nav-height);
        padding: var(--space-md);
        padding-top: calc(var(--mobile-navbar-height) + var(--space-md));
    }
}

/* Mobile Top Navigation Bar */
.mobile-top-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-navbar-height);
    background: linear-gradient(180deg, var(--neo-surface) 0%, rgba(30,41,59,0.95) 100%);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    z-index: var(--z-sticky);
    padding: 0 var(--space-md);
    align-items: center;
    justify-content: space-between;
}

@media (max-width: 1023px) {
    .mobile-top-bar {
        display: flex;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   6. RESPONSIVE GRID & CARDS
   ═══════════════════════════════════════════════════════════════════════════ */

.responsive-grid {
    display: grid;
    gap: var(--space-lg);
}

/* Default: Single column on mobile */
.responsive-grid {
    grid-template-columns: 1fr;
}

/* Tablet: 2 columns */
@media (min-width: 640px) {
    .responsive-grid--2cols {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop: Full columns */
@media (min-width: 1024px) {
    .responsive-grid--3cols {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .responsive-grid--4cols {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .responsive-grid--dashboard {
        grid-template-columns: 3fr 1fr;
    }
}

/* Responsive Cards */
.responsive-card {
    background: var(--neo-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    border: 1px solid rgba(255,255,255,0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
    /* Desktop: Hover effects */
    .responsive-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    }
}

@media (hover: none) and (pointer: coarse) {
    /* Mobile: Active states instead of hover */
    .responsive-card:active {
        transform: scale(0.98);
        background: rgba(255,255,255,0.05);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   7. RESPONSIVE TABLES → CARDS
   ═══════════════════════════════════════════════════════════════════════════ */

/* Desktop: Traditional Table */
@media (min-width: 1024px) {
    .responsive-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .responsive-table {
        width: 100%;
        border-collapse: collapse;
    }
    
    .responsive-table th,
    .responsive-table td {
        padding: var(--space-md);
        text-align: right;
        border-bottom: 1px solid rgba(255,255,255,0.05);
    }
    
    .responsive-table th {
        font-weight: 700;
        color: var(--neo-text-secondary);
        font-size: var(--text-sm);
    }
    
    .responsive-table tbody tr:hover {
        background: rgba(255,255,255,0.02);
    }
}

/* Mobile: Card Layout */
@media (max-width: 1023px) {
    .responsive-table {
        display: block;
    }
    
    .responsive-table thead {
        display: none;
    }
    
    .responsive-table tbody {
        display: flex;
        flex-direction: column;
        gap: var(--space-md);
    }
    
    .responsive-table tr {
        display: flex;
        flex-direction: column;
        background: var(--neo-surface);
        border-radius: var(--radius-md);
        padding: var(--space-md);
        border: 1px solid rgba(255,255,255,0.05);
    }
    
    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--space-sm) 0;
        border-bottom: 1px solid rgba(255,255,255,0.03);
    }
    
    .responsive-table td:last-child {
        border-bottom: none;
    }
    
    /* Add labels from data attributes */
    .responsive-table td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--neo-text-secondary);
        font-size: var(--text-xs);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   8. TOUCH-OPTIMIZED UI ELEMENTS
   ═══════════════════════════════════════════════════════════════════════════ */

/* Large tap targets for mobile */
.btn-touch {
    min-height: var(--touch-target-comfortable);
    min-width: var(--touch-target-comfortable);
    padding: var(--space-sm) var(--space-lg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.btn-touch-large {
    min-height: var(--touch-target-large);
    min-width: var(--touch-target-large);
    padding: var(--space-md) var(--space-xl);
}

/* Active states for touch devices */
@media (hover: none) and (pointer: coarse) {
    .btn-touch:active,
    .btn-touch-large:active {
        transform: scale(0.95);
        opacity: 0.9;
    }
    
    /* Remove hover-only effects */
    .hover-only {
        display: none !important;
    }
}

/* Touch-friendly form elements */
input, select, textarea {
    min-height: var(--touch-target-comfortable);
    font-size: 16px; /* Prevent zoom on iOS */
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.05);
    color: var(--neo-text-primary);
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}

/* ═══════════════════════════════════════════════════════════════════════════
   9. RESPONSIVE TYPOGRAPHY
   ═══════════════════════════════════════════════════════════════════════════ */

.responsive-heading-1 {
    font-size: var(--text-3xl);
    font-weight: 800;
    line-height: 1.2;
}

.responsive-heading-2 {
    font-size: var(--text-2xl);
    font-weight: 700;
    line-height: 1.3;
}

.responsive-heading-3 {
    font-size: var(--text-xl);
    font-weight: 600;
    line-height: 1.4;
}

.responsive-text {
    font-size: var(--text-base);
    line-height: 1.6;
}

.responsive-text-small {
    font-size: var(--text-sm);
    line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════════════════
   10. RESPONSIVE MODALS & OVERLAYS
   ═══════════════════════════════════════════════════════════════════════════ */

.responsive-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.responsive-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(10px);
}

.responsive-modal-content {
    position: relative;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    background: var(--neo-surface);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    border: 1px solid rgba(255,255,255,0.1);
}

@media (max-width: 639px) {
    .responsive-modal {
        align-items: flex-end;
        padding: 0;
    }
    
    .responsive-modal-content {
        max-height: 95vh;
        max-height: 95dvh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding: var(--space-md);
    }
}

/* Bottom Sheet for mobile */
@media (max-width: 639px) {
    .bottom-sheet {
        animation: slide-up 0.3s ease-out;
    }
    
    @keyframes slide-up {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
    
    .bottom-sheet-handle {
        width: 40px;
        height: 4px;
        background: rgba(255,255,255,0.2);
        border-radius: 2px;
        margin: 0 auto var(--space-md);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   11. RESPONSIVE STATS & CHARTS
   ═══════════════════════════════════════════════════════════════════════════ */

.stats-grid {
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 640px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-card {
    background: var(--neo-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    border: 1px solid rgba(255,255,255,0.05);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

@media (hover: hover) {
    .stat-card:hover::after {
        transform: scaleX(1);
    }
}

/* Chart containers */
.chart-container {
    position: relative;
    width: 100%;
    min-height: 200px;
}

@media (min-width: 768px) {
    .chart-container {
        min-height: 300px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   12. LAZY LOADING & PERFORMANCE
   ═══════════════════════════════════════════════════════════════════════════ */

.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-image.loaded {
    opacity: 1;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0.05) 25%,
        rgba(255,255,255,0.1) 50%,
        rgba(255,255,255,0.05) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   13. UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════════════ */

.hide-mobile { display: none; }
.hide-desktop { display: block; }

@media (min-width: 1024px) {
    .hide-mobile { display: block; }
    .hide-desktop { display: none; }
}

.text-center-mobile { text-align: center; }

@media (min-width: 768px) {
    .text-center-mobile { text-align: inherit; }
}

.full-width-mobile {
    width: 100%;
}

@media (min-width: 768px) {
    .full-width-mobile {
        width: auto;
    }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    .safe-area-inset {
        padding-left: max(var(--space-md), env(safe-area-inset-left));
        padding-right: max(var(--space-md), env(safe-area-inset-right));
        padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   14. PRINT STYLES
   ═══════════════════════════════════════════════════════════════════════════ */

@media print {
    .os-sidebar,
    .mobile-top-bar,
    .mobile-menu-toggle,
    .bottom-nav {
        display: none !important;
    }
    
    .os-main {
        margin: 0 !important;
        padding: 20px !important;
    }
    
    .neo-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   15. ACCESSIBILITY ENHANCEMENTS
   ═══════════════════════════════════════════════════════════════════════════ */

@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;
    }
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .responsive-card,
    .stat-card {
        border-width: 2px;
    }
}

/* ============================================
   MOBILE RTL FIXES - CLEAN
   ============================================ */

@media (max-width: 1023px) {
  /* Basic RTL */
  html {
    direction: rtl;
  }
  
  body {
    direction: rtl;
    text-align: right;
  }
  
  /* Main content area */
  .os-main,
  .sidebar-space {
    direction: rtl;
    text-align: right;
    margin-right: 0 !important;
    margin-left: 0 !important;
    padding-right: 16px !important;
    padding-left: 16px !important;
    padding-top: 80px !important;
  }
  
  /* Headers and text */
  h1, h2, h3, h4, h5, h6 {
    text-align: right;
  }
  
  p {
    text-align: right;
  }
  
  /* Stat cards */
  .stat-card {
    direction: rtl;
    text-align: right;
  }
  
  .stat-card > div {
    flex-direction: row-reverse;
  }
  
  /* Buttons and actions */
  .btn,
  button {
    direction: rtl;
  }
  
  /* Grid layouts */
  .grid {
    direction: rtl;
  }
  
  /* Flex containers */
  .flex {
    direction: rtl;
  }
  
  /* Form elements */
  input, select, textarea {
    direction: rtl;
    text-align: right;
  }
  
  /* Lists */
  ul, ol {
    padding-right: 20px;
    padding-left: 0;
  }
}
