/**
 * ============================================================================
 * RESPONSIVE SYSTEM - Albousala Laravel
 * ============================================================================
 * 
 * هذا الملف يضيف طبقة تجاوب فوق التنسيقات الموجودة
 * بدون تعديل أو حذف أي CSS موجود
 * 
 * المبادئ:
 * 1. mobile-first approach
 * 2. يحترم جميع الأنماط الموجودة
 * 3. يستخدم !important فقط عند الضرورة
 * 4. متوافق مع Bootstrap 5.3 RTL
 * ============================================================================
 */

/* ==========================================
   CSS VARIABLES FOR RESPONSIVE SPACING
   ========================================== */
:root {
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    --container-sm: 540px;
    --container-md: 720px;
    --container-lg: 960px;
    --container-xl: 1140px;
    --container-xxl: 1320px;
}

/* ==========================================
   BASE RESPONSIVE UTILITIES
   ========================================== */

/* Fluid Typography */
html {
    font-size: 16px;
}

@media (max-width: 1200px) {
    html { font-size: 15px; }
}

@media (max-width: 992px) {
    html { font-size: 14px; }
}

@media (max-width: 576px) {
    html { font-size: 13px; }
}

/* ==========================================
   CONTAINER RESPONSIVE PATTERNS
   ========================================== */

/* Main Layout Container */
.responsive-container {
    width: 100%;
    max-width: var(--container-xxl);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
}

@media (min-width: 576px) {
    .responsive-container {
        max-width: var(--container-sm);
        padding-left: var(--space-lg);
        padding-right: var(--space-lg);
    }
}

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

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

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

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

/* ==========================================
   GRID RESPONSIVE UTILITIES
   ========================================== */

/* Auto-fit Grid */
.responsive-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-md);
}

@media (min-width: 576px) {
    .responsive-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .responsive-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

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

/* ==========================================
   CARD RESPONSIVE PATTERNS
   ========================================== */

.responsive-card {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.responsive-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

@media (max-width: 768px) {
    .responsive-card {
        border-radius: 0.5rem;
        margin-bottom: var(--space-md);
    }
}

/* Card Body Padding */
.responsive-card-body {
    padding: var(--space-lg);
}

@media (max-width: 768px) {
    .responsive-card-body {
        padding: var(--space-md);
    }
}

/* ==========================================
   TABLE RESPONSIVE PATTERNS
   ========================================== */

.responsive-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.responsive-table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
}

@media (max-width: 768px) {
    .responsive-table {
        font-size: 0.875rem;
    }
    
    .responsive-table th,
    .responsive-table td {
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }
}

/* Card-based table for mobile */
@media (max-width: 576px) {
    .table-cards thead {
        display: none;
    }
    
    .table-cards tbody tr {
        display: block;
        margin-bottom: var(--space-md);
        background: white;
        border-radius: 0.5rem;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        padding: var(--space-md);
    }
    
    .table-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px solid #f1f5f9;
    }
    
    .table-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
    }
    
    .table-cards td:last-child {
        border-bottom: none;
    }
}

/* ==========================================
   FORM RESPONSIVE PATTERNS
   ========================================== */

.responsive-form-group {
    margin-bottom: var(--space-md);
}

.responsive-form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-md);
}

@media (min-width: 768px) {
    .responsive-form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1200px) {
    .responsive-form-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.responsive-form-grid .full-width {
    grid-column: 1 / -1;
}

/* Input sizing */
.responsive-input {
    width: 100%;
    min-height: 44px; /* Touch-friendly */
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.responsive-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    outline: none;
}

@media (max-width: 576px) {
    .responsive-input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 0.625rem 0.875rem;
    }
}

/* ==========================================
   NAVIGATION RESPONSIVE PATTERNS
   ========================================== */

.responsive-nav {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

@media (max-width: 992px) {
    .responsive-nav {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        height: 100vh;
        background: white;
        flex-direction: column;
        padding: var(--space-xl);
        transition: right 0.3s ease;
        z-index: 1000;
        box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    }
    
    .responsive-nav.open {
        right: 0;
    }
    
    .mobile-menu-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
        z-index: 999;
    }
    
    .mobile-menu-overlay.open {
        opacity: 1;
        visibility: visible;
    }
}

/* Hamburger Menu Button */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
}

@media (max-width: 992px) {
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ==========================================
   BUTTON RESPONSIVE PATTERNS
   ========================================== */

.responsive-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.5rem;
    transition: all 0.2s;
    cursor: pointer;
    border: none;
    min-height: 44px; /* Touch-friendly */
}

@media (max-width: 576px) {
    .responsive-btn {
        width: 100%;
        padding: 0.875rem 1rem;
    }
    
    .responsive-btn-group {
        display: flex;
        flex-direction: column;
        gap: var(--space-sm);
    }
}

/* ==========================================
   SIDEBAR RESPONSIVE PATTERNS
   ========================================== */

.responsive-sidebar {
    width: 260px;
    min-height: 100vh;
    background: #1e293b;
    color: white;
    transition: all 0.3s;
}

@media (max-width: 992px) {
    .responsive-sidebar {
        position: fixed;
        top: 0;
        right: -260px;
        z-index: 1000;
        box-shadow: -4px 0 20px rgba(0,0,0,0.2);
    }
    
    .responsive-sidebar.open {
        right: 0;
    }
    
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
        z-index: 999;
    }
    
    .sidebar-overlay.open {
        opacity: 1;
        visibility: visible;
    }
}

/* ==========================================
   SPACING RESPONSIVE UTILITIES
   ========================================== */

/* Responsive padding */
.responsive-p { padding: var(--space-md); }
.responsive-px { padding-left: var(--space-md); padding-right: var(--space-md); }
.responsive-py { padding-top: var(--space-md); padding-bottom: var(--space-md); }

@media (min-width: 768px) {
    .responsive-p { padding: var(--space-lg); }
    .responsive-px { padding-left: var(--space-lg); padding-right: var(--space-lg); }
    .responsive-py { padding-top: var(--space-lg); padding-bottom: var(--space-lg); }
}

/* Responsive margin */
.responsive-m { margin: var(--space-md); }
.responsive-mb { margin-bottom: var(--space-md); }

@media (min-width: 768px) {
    .responsive-m { margin: var(--space-lg); }
    .responsive-mb { margin-bottom: var(--space-lg); }
}

/* ==========================================
   TEXT RESPONSIVE UTILITIES
   ========================================== */

.responsive-text-xs { font-size: clamp(0.75rem, 2vw, 0.875rem); }
.responsive-text-sm { font-size: clamp(0.875rem, 2vw, 1rem); }
.responsive-text-base { font-size: clamp(1rem, 2.5vw, 1.125rem); }
.responsive-text-lg { font-size: clamp(1.125rem, 3vw, 1.25rem); }
.responsive-text-xl { font-size: clamp(1.25rem, 4vw, 1.5rem); }
.responsive-text-2xl { font-size: clamp(1.5rem, 5vw, 2rem); }
.responsive-text-3xl { font-size: clamp(1.875rem, 6vw, 2.5rem); }

/* Text truncation */
.responsive-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 576px) {
    .responsive-truncate-mobile {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ==========================================
   IMAGE RESPONSIVE UTILITIES
   ========================================== */

.responsive-img {
    max-width: 100%;
    height: auto;
    display: block;
}

.responsive-img-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.responsive-img-contain {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ==========================================
   HIDE/SHOW RESPONSIVE UTILITIES
   ========================================== */

.hide-mobile { display: none; }

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

/* ==========================================
   PRINT STYLES
   ========================================== */

@media print {
    .no-print,
    .responsive-sidebar,
    .mobile-menu-toggle,
    .sidebar-overlay {
        display: none !important;
    }
    
    .responsive-container {
        max-width: 100%;
        padding: 0;
    }
}

/* ==========================================
   REDUCED MOTION
   ========================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==========================================
   DARK MODE SUPPORT (Future-proofing)
   ========================================== */

@media (prefers-color-scheme: dark) {
    /* Ready for dark mode implementation */
}
