/* =============================================== */
/* == تحسينات Responsive Design الشاملة == */
/* =============================================== */

/* Mobile First - الهواتف الذكية (أقل من 480px) */
@media (max-width: 479px) {
    html {
        font-size: 14px;
    }

    body {
        padding: 0;
        margin: 0;
    }

    /* الهيدر */
    header.main-header {
        margin-bottom: 15px;
    }

    .header-top {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }

    .logo-container {
        width: 100%;
        justify-content: center;
    }

    .header-search-container {
        width: 100%;
        max-width: none;
        margin: 0;
        order: 2;
    }

    .auth-nav {
        width: 100%;
        justify-content: center;
        gap: 8px;
        flex-wrap: wrap;
    }

    /* الأزرار - يجب أن تكون 44px على الأقل */
    button, a.btn, .btn-login, .btn-register {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
        font-size: 14px;
    }

    /* النصوص */
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 20px;
    }

    h2 {
        font-size: 18px;
    }

    h3 {
        font-size: 16px;
    }

    /* الحقول */
    input, select, textarea {
        font-size: 16px; /* منع التكبير التلقائي في iOS */
        min-height: 44px;
        padding: 12px;
    }

    .input-with-icon,
    .password-wrapper.modern-password {
        height: 44px;
    }

    /* الصور */
    img {
        max-width: 100%;
        height: auto;
    }

    /* الحاويات */
    .container {
        padding: 10px;
        margin: 10px auto;
    }

    .form-container {
        max-width: 100%;
        margin: 10px;
        padding: 20px;
    }

    /* الشبكات */
    .products-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* الجداول */
    table {
        font-size: 12px;
    }

    /* القائمة الجانبية */
    .category-sidebar {
        width: 85vw;
    }

    /* المسافات */
    .form-group {
        margin-bottom: 15px;
    }

    /* الأيقونات */
    .field-icon {
        width: 40px;
        height: 44px;
    }

    /* الأزرار الصغيرة */
    .toggle-password {
        width: 40px;
        height: 44px;
    }
}

/* الهواتف والأجهزة اللوحية الصغيرة (480px - 768px) */
@media (min-width: 480px) and (max-width: 767px) {
    html {
        font-size: 15px;
    }

    .header-top {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }

    .logo-container {
        width: 100%;
        justify-content: center;
    }

    .header-search-container {
        width: 100%;
        max-width: none;
        margin: 0;
    }

    .auth-nav {
        width: 100%;
        justify-content: center;
        gap: 10px;
    }

    button, a.btn {
        min-height: 44px;
        padding: 12px 16px;
    }

    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .container {
        padding: 12px;
    }

    .form-container {
        max-width: 100%;
        margin: 15px;
        padding: 25px;
    }

    .category-sidebar {
        width: 80vw;
    }
}

/* الأجهزة اللوحية (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .header-search-container {
        max-width: 400px;
    }

    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }

    .container {
        padding: 15px;
    }

    .category-sidebar {
        width: 320px;
    }

    button, a.btn {
        min-height: 44px;
    }
}

/* الشاشات الكبيرة (أكثر من 1024px) */
@media (min-width: 1025px) {
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 30px;
    }

    .container {
        max-width: 1300px;
        margin: 50px auto;
        padding: 0 15px;
    }
}

/* =============================================== */
/* == تحسينات عامة للـ Responsive == */
/* =============================================== */

/* استخدام Logical Properties للـ RTL/LTR */
.element {
    margin-block: 10px;
    margin-inline: 15px;
    padding-block: 10px;
    padding-inline: 15px;
}

/* الفلكس بوكس المرن */
.flex-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.flex-item {
    flex: 1 1 auto;
    min-width: 0;
}

/* الشبكات المرنة */
.grid-container {
    display: grid;
    gap: 15px;
    grid-auto-flow: dense;
}

/* الصور المرنة */
img, picture, video {
    max-width: 100%;
    height: auto;
    display: block;
}

/* الجداول المرنة */
@media (max-width: 768px) {
    table {
        display: block;
        overflow-x: auto;
    }

    thead {
        display: none;
    }

    tbody, tr, td {
        display: block;
        width: 100%;
    }

    td {
        padding: 10px;
        border-bottom: 1px solid #ddd;
    }

    td::before {
        content: attr(data-label);
        font-weight: bold;
        display: block;
        margin-bottom: 5px;
    }
}

/* الحقول المرنة */
input, select, textarea, button {
    max-width: 100%;
    box-sizing: border-box;
}

/* الأيقونات المرنة */
svg {
    max-width: 100%;
    height: auto;
}

/* =============================================== */
/* == تحسينات الوصولية (Accessibility) == */
/* =============================================== */

/* تحسين التركيز */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #3f51b5;
    outline-offset: 2px;
}

/* تحسين الأزرار */
button, a.btn {
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

button:hover, a.btn:hover {
    transform: translateY(-2px);
}

button:active, a.btn:active {
    transform: translateY(0);
}

/* =============================================== */
/* == تحسينات الأداء == */
/* =============================================== */

/* تقليل الحركات على الأجهزة المحمولة */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* تحسين الأداء للشاشات الكبيرة */
@media (min-width: 1025px) {
    .lazy-load {
        loading: lazy;
    }
}

/* =============================================== */
/* == دعم الأجهزة ذات الشاشات الصغيرة جداً == */
/* =============================================== */

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

    .form-container {
        padding: 15px;
    }

    button, a.btn {
        padding: 10px 12px;
        font-size: 13px;
    }

    .products-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

/* =============================================== */
/* == دعم الشاشات الكبيرة جداً == */
/* =============================================== */

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

    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 35px;
    }
}

/* =============================================== */
/* == دعم الأجهزة ذات الشاشات العريضة جداً == */
/* =============================================== */

@media (min-width: 1920px) {
    .container {
        max-width: 1600px;
    }

    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 40px;
    }
}

/* =============================================== */
/* == دعم الأجهزة ذات الشاشات الطويلة (Tall Screens) == */
/* =============================================== */

@media (min-height: 1000px) {
    body {
        display: flex;
        flex-direction: column;
    }

    main {
        flex: 1;
    }

    footer {
        margin-top: auto;
    }
}

/* =============================================== */
/* == دعم الأجهزة ذات الشاشات القصيرة (Short Screens) == */
/* =============================================== */

@media (max-height: 600px) {
    header {
        padding: 8px;
    }

    .form-container {
        margin: 10px auto;
        padding: 15px;
    }
}

/* =============================================== */
/* == دعم الأجهزة ذات الكثافة العالية (High DPI) == */
/* =============================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* تحسين الصور على الشاشات عالية الدقة */
    img {
        image-rendering: -webkit-optimize-contrast;
    }

    /* تحسين الخطوط */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* =============================================== */
/* == دعم الأجهزة ذات الكثافة المنخفضة (Low DPI) == */
/* =============================================== */

@media (-webkit-max-device-pixel-ratio: 1), (max-resolution: 96dpi) {
    /* تحسين الأداء على الأجهزة القديمة */
    * {
        will-change: auto;
    }
}

/* =============================================== */
/* == دعم الأجهزة ذات الاتصال البطيء == */
/* =============================================== */

@media (prefers-reduced-data: reduce) {
    /* تقليل استخدام البيانات */
    img {
        loading: lazy;
    }

    video {
        loading: lazy;
    }

    /* تعطيل الحركات الثقيلة */
    * {
        animation: none !important;
        transition: none !important;
    }
}
