/*
═══════════════════════════════════════════════════════════════
    Mobile Responsive CSS - نظام شامل للاستجابة
═══════════════════════════════════════════════════════════════
    تاريخ: أكتوبر 2025
    الوصف: ملف CSS شامل لجعل الموقع متجاوب مع جميع الأجهزة
*/

/* ═══════════════════════════════════════════════════════════
   1. إعدادات أساسية
   ═══════════════════════════════════════════════════════════ */

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
    max-width: 100vw;
}

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

/* ═══════════════════════════════════════════════════════════
   2. Container و Grid
   ═══════════════════════════════════════════════════════════ */

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

@media (max-width: 768px) {
    .container {
        padding: 0 0.75rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.5rem;
    }
}

/* Grid System */
.products-grid,
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

@media (max-width: 1024px) {
    .products-grid,
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 1rem;
    }
}

@media (max-width: 768px) {
    .products-grid,
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .products-grid,
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   3. Product Cards
   ═══════════════════════════════════════════════════════════ */

.product-card {
    width: 100%;
    min-width: 0;
}

/* تحسين صور المنتجات على Mobile */
@media (max-width: 768px) {
    .product-card .product-image {
        width: 100%;
        height: 250px;
        position: relative;
        overflow: hidden;
        border-radius: 12px;
    }

    .product-card .product-image img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
}

@media (max-width: 480px) {
    .product-card .product-image {
        height: 200px;
    }
}

.product-card .product-info {
    padding: 0.75rem;
}

.product-card h3 {
    font-size: 1rem;
    line-height: 1.4;
    margin: 0 0 0.5rem 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

@media (max-width: 768px) {
    .product-card h3 {
        font-size: 0.9rem;
    }
    
    .product-card .product-info {
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .product-card h3 {
        font-size: 0.85rem;
        -webkit-line-clamp: 2;
    }
}

/* ═══════════════════════════════════════════════════════════
   4. Product Detail Page
   ═══════════════════════════════════════════════════════════ */

/* لا تغير على Desktop */
@media (max-width: 1024px) {
    .product-detail-grid {
        gap: 1.5rem;
    }
}

@media (max-width: 768px) {
    .product-detail-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .main-image {
        width: 100%;
        padding-top: 100%;
        position: relative;
        overflow: hidden;
        border-radius: 12px;
    }

    .main-image img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
}

.thumbnail-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
}

@media (max-width: 480px) {
    .thumbnail-images {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.25rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   5. Buttons
   ═══════════════════════════════════════════════════════════ */

/* فقط على mobile */
@media (max-width: 768px) {
    .btn,
    button {
        padding: 0.65rem 1.25rem;
        font-size: 0.95rem;
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .btn,
    button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    
    /* فقط الأزرار في forms تكون full width */
    form .btn,
    form button[type="submit"] {
        width: 100%;
    }
}

.action-buttons-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .action-buttons-group {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .action-buttons-group button {
        width: 100% !important;
        flex: 1 !important;
        min-width: auto !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   6. Forms
   ═══════════════════════════════════════════════════════════ */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    min-height: 44px;
}

@media (max-width: 480px) {
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* منع zoom في iOS */
    }
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   7. Checkout Page
   ═══════════════════════════════════════════════════════════ */

.checkout-container {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 2rem;
}

@media (max-width: 1024px) {
    .checkout-container {
        grid-template-columns: 1fr 350px;
        gap: 1.5rem;
    }
}

@media (max-width: 768px) {
    .checkout-grid {
        display: flex;
        flex-direction: column;
    }
    
    .checkout-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* ترتيب العناصر في الموبايل */
    .checkout-form {
        order: -1; /* معلومات الشحن في الأعلى */
    }
    
    .order-summary-sidebar {
        order: 1; /* ملخص الطلب في الأسفل */
    }
}

/* ═══════════════════════════════════════════════════════════
   7.5 Product Page - ترتيب الأزرار في الموبايل
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .action-buttons-group {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .action-buttons-group button {
        width: 100% !important;
        min-width: 100% !important;
        flex: 1 !important;
    }
    
    /* اشتري الآن في الأعلى */
    .btn-buy-now {
        order: -1 !important;
    }
    
    /* أضف للسلة في الأسفل */
    #addToCartBtn {
        order: 1 !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   8. Cart Page
   ═══════════════════════════════════════════════════════════ */

.cart-item {
    display: grid;
    grid-template-columns: 100px 1fr auto;
    gap: 1rem;
    align-items: center;
}

@media (max-width: 768px) {
    .cart-item {
        grid-template-columns: 80px 1fr;
        gap: 0.75rem;
    }
    
    .cart-item .item-actions {
        grid-column: 1 / -1;
        margin-top: 0.5rem;
    }
}

@media (max-width: 480px) {
    .cart-item {
        grid-template-columns: 60px 1fr;
        gap: 0.5rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   9. Header & Navigation
   ═══════════════════════════════════════════════════════════ */

.header {
    padding: 1rem 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

@media (max-width: 768px) {
    .header {
        padding: 0.75rem 0;
    }
}

.nav-menu {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

@media (max-width: 768px) {
    .nav-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        height: 100vh;
        background: var(--bg-primary, white);
        flex-direction: column;
        padding: 2rem 1rem;
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
        transition: right 0.3s ease;
        z-index: 1000;
        overflow-y: auto;
    }
    
    .nav-menu.active {
        right: 0;
    }
    
    .mobile-menu-toggle {
        display: block !important;
        background: none;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
        padding: 0.5rem;
        color: var(--text-primary);
    }
}

/* ═══════════════════════════════════════════════════════════
   10. Tables
   ═══════════════════════════════════════════════════════════ */

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

@media (max-width: 480px) {
    table {
        font-size: 0.85rem;
    }
    
    table th,
    table td {
        padding: 0.4rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   11. Product Attributes
   ═══════════════════════════════════════════════════════════ */

.attribute-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.attribute-option {
    padding: 0.75rem 1.25rem;
    border: 2px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 480px) {
    .attribute-option {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
        flex: 1 1 calc(50% - 0.375rem);
        min-width: calc(50% - 0.375rem);
    }
}

/* ═══════════════════════════════════════════════════════════
   12. Quantity Selector
   ═══════════════════════════════════════════════════════════ */

.quantity-selector {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.quantity-selector input {
    width: 80px;
    text-align: center;
}

@media (max-width: 480px) {
    .quantity-selector {
        width: 100%;
        justify-content: space-between;
    }
    
    .quantity-selector input {
        flex: 1;
        max-width: 100px;
    }
}

/* ═══════════════════════════════════════════════════════════
   13. Price Display
   ═══════════════════════════════════════════════════════════ */

.product-price-box {
    margin: 1rem 0;
}

.price {
    font-size: 1.75rem;
    font-weight: 700;
}

@media (max-width: 768px) {
    .price {
        font-size: 1.5rem;
    }
}

@media (max-width: 480px) {
    .price {
        font-size: 1.25rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   14. Modal & Popup
   ═══════════════════════════════════════════════════════════ */

.modal {
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

@media (max-width: 768px) {
    .modal {
        max-width: 95vw;
        max-height: 95vh;
        margin: 1rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   15. Typography
   ═══════════════════════════════════════════════════════════ */

h1 {
    font-size: 2.5rem;
    line-height: 1.2;
}

h2 {
    font-size: 2rem;
}

h3 {
    font-size: 1.5rem;
}

@media (max-width: 768px) {
    h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.75rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.15rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   16. Spacing Utilities
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .section {
        padding: 2rem 0;
    }
    
    .mb-4 {
        margin-bottom: 1.5rem !important;
    }
    
    .mt-4 {
        margin-top: 1.5rem !important;
    }
}

@media (max-width: 480px) {
    .section {
        padding: 1.5rem 0;
    }
    
    .mb-4 {
        margin-bottom: 1rem !important;
    }
    
    .mt-4 {
        margin-top: 1rem !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   17. Touch Optimization
   ═══════════════════════════════════════════════════════════ */

@media (hover: none) and (pointer: coarse) {
    /* للأجهزة اللمسية فقط */
    
    a, button, .clickable {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* إزالة hover effects */
    *:hover {
        transform: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   18. Landscape Mode (الوضع الأفقي)
   ═══════════════════════════════════════════════════════════ */

@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 0.5rem 0;
    }
    
    .product-detail-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .main-image {
        padding-top: 75%;
    }
}

/* ═══════════════════════════════════════════════════════════
   19. Very Small Screens (شاشات صغيرة جداً)
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 360px) {
    html {
        font-size: 14px;
    }
    
    .container {
        padding: 0 0.5rem;
    }
    
    .products-grid {
        gap: 0.25rem;
    }
    
    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   20. Print Styles
   ═══════════════════════════════════════════════════════════ */

@media print {
    .no-print,
    .header,
    .footer,
    button,
    .btn {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
    }
    
    .container {
        max-width: 100%;
    }
}

/* ═══════════════════════════════════════════════════════════
   21. Accessibility
   ═══════════════════════════════════════════════════════════ */

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

/* Focus visible للوصول بلوحة المفاتيح */
*:focus-visible {
    outline: 2px solid var(--primary-color, #2563eb);
    outline-offset: 2px;
}
