/* ==============================
   Components CSS
   تنسيق المكونات الأساسية المتكررة
   ============================== */

/* --- شريط التنقل (Navbar) — International Standard ---
   Refs: Apple.com • IKEA • Amazon • Material Design 3
   Height: 64px | Font: 15px | Spacing: 28px gap
   --------------------------------------------------- */
.navbar {
    background-color: var(--white-glass);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    box-shadow: 0 1px 0 rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

[data-theme="dark"] .navbar {
    background-color: rgba(15, 23, 42, 0.92);
    border-bottom-color: rgba(255,255,255,0.07);
    box-shadow: 0 1px 0 rgba(255,255,255,0.05), 0 4px 20px rgba(0,0,0,0.3);
}

/* إضافة ظل عند السكرول */
.navbar.scrolled {
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;            /* 64px = المعيار الدولي (Apple/Google/IKEA) */
    gap: 16px;
}

/* الشعار */
.logo {
    font-size: 1.3rem;       /* 21px */
    font-weight: 800;
    color: var(--primary-color);
    letter-spacing: -0.3px;
    white-space: nowrap;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.logo:hover { opacity: 0.8; }

/* ——— روابط التنقل الرئيسية ——— */
.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;                /* gap صغير — padding الرابط نفسه يُعطي المسافة */
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1;
    justify-content: center; /* توسيط الروابط الرئيسية */
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;       /* 12px أفقي = touch-friendly */
    font-size: 15px;         /* 15px = المعيار الدولي لروابط الـ Nav */
    font-weight: 500;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 8px;
    transition: color 0.2s ease, background 0.2s ease;
    white-space: nowrap;
    position: relative;
}

/* خط تحتي متحرك عند الـ hover */
.nav-links a::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 12px;
    left: 12px;
    height: 2px;
    background: var(--primary-color);
    border-radius: 2px;
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-links a:hover {
    color: var(--primary-color);
    background: rgba(var(--primary-rgb), 0.06);
}
.nav-links a:hover::after,
.nav-links a.active-link::after {
    transform: scaleX(1);
}

.nav-links a.active-link {
    color: var(--primary-color);
    font-weight: 600;
}

/* ——— أدوات اليمين (Cart + Login + Dark + Lang) ——— */
.nav-utils {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* زر أيقونة (Dark Mode / Lang) */
.nav-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s, color 0.2s;
}
.nav-icon-btn:hover {
    background: rgba(var(--primary-rgb), 0.08);
    color: var(--primary-color);
}

/* زر اللغة */
.nav-lang-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: 8px;
    border: 1.5px solid var(--border-color);
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.nav-lang-btn:hover {
    border-color: var(--primary-color);
    background: rgba(var(--primary-rgb), 0.06);
    color: var(--primary-color);
}

/* زر السلة */
.nav-cart-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 50px;
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s;
    white-space: nowrap;
}
.nav-cart-btn:hover {
    background: rgba(var(--primary-rgb), 0.18);
    transform: translateY(-1px);
}
.cart-badge {
    background: var(--primary-color);
    color: white;
    border-radius: 50px;
    padding: 1px 7px;
    font-size: 12px;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
}

/* زر تسجيل الدخول */
.nav-login-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: 8px;
    background: var(--primary-color);
    color: white !important;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s;
    white-space: nowrap;
}
.nav-login-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}
.nav-login-btn::after { display: none !important; }

/* فاصل عمودي خفيف */
.nav-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    flex-shrink: 0;
    margin: 0 4px;
}


/* --- الأزرار (Buttons) --- */
.btn {
    display: inline-block;
    padding: 12px 28px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    transition: var(--transition);
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.btn-primary {
    background: var(--primary-gradient);
    color: #ffffff;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, var(--primary-hover) 0%, var(--primary-color) 100%);
}

.btn-block {
    width: 100%;
    display: block;
}

/* --- نظام الشبكة (Grid System للمنتجات) --- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

/* --- البطاقات (Cards - للمنتجات) --- */
.card {
    background-color: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-8px);
}

.card-img-wrapper {
    width: 100%;
    height: 200px;
    overflow: hidden;
    background-color: var(--secondary-color); /* خلفية في حال تأخر الصورة */
}

.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* لضمان عدم تشوه الصورة وتعبئتها للمساحة */
}

.card-body {
    padding: 15px;
    text-align: center;
}

.card-title {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: var(--text-color);
}

.card-price {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.2rem;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    direction: rtl;
}
.card-price span[dir="ltr"] {
    direction: ltr;
    display: inline-block;
}

/* تحديث وسم السعر في صفحة التفاصيل */
.price-tag {
    display: flex;
    align-items: center;
    gap: 8px;
    direction: rtl;
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.5rem;
    margin-bottom: 20px;
}

/* --- النماذج (Forms) --- */
.form-group {
    margin-bottom: 15px;
    text-align: right;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
    background-color: var(--bg-color);
    color: var(--text-color);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: var(--white);
    box-shadow: 0 0 0 4px rgba(139, 90, 43, 0.1);
}

/* ==========================================================================
   نظام التجاوب المطور (Responsive Mobile System)
   يشمل: شريط التنقل السفلي، القائمة الجانبية المنزلقة، والبطاقات الثنائية للجوال
   ========================================================================== */

/* --- أزرار الهمبرغر للهاتف (Hamburger Menu Button) --- */
.hamburger-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1.5px solid var(--border-color);
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    font-size: 18px;
    transition: var(--transition);
}
.hamburger-btn:hover {
    background: rgba(var(--primary-rgb), 0.06);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* --- القائمة الجانبية المنزلقة (Mobile Sliding Drawer) --- */
.mobile-drawer {
    position: fixed;
    top: 0;
    right: -310px; /* مخفي خارج الشاشة من اليمين (RTL) */
    width: 300px;
    height: 100vh;
    background-color: var(--white-glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: -5px 0 25px rgba(0,0,0,0.12);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    border-left: 1px solid var(--border-color);
}
.mobile-drawer.open {
    right: 0; /* إظهار القائمة */
}

.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* محتوى القائمة الجانبية */
.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}
.drawer-close {
    background: transparent;
    border: none;
    font-size: 20px;
    color: var(--text-color);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.drawer-close:hover {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary-color);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.drawer-links {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.drawer-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
    border-radius: 10px;
    transition: var(--transition);
}
.drawer-links a i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    color: var(--text-light);
    transition: color 0.2s;
}
.drawer-links a:hover {
    background: rgba(var(--primary-rgb), 0.08);
    color: var(--primary-color);
}
.drawer-links a:hover i,
.drawer-links a.active-link i {
    color: var(--primary-color);
}
.drawer-links a.active-link {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary-color);
}

.drawer-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.drawer-utils-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.drawer-utils-row .nav-lang-btn,
.drawer-utils-row .nav-icon-btn {
    flex: 1;
    justify-content: center;
    border: 1px solid var(--border-color) !important;
    height: 38px;
    border-radius: 8px;
}

/* --- شريط التنقل السفلي المخصص للموبايل (Mobile Bottom Navigation) --- */
.mobile-bottom-nav {
    display: none; /* مخفي بالافتراضي في الكمبيوتر */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 62px;
    background-color: var(--white-glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
    z-index: 999;
    padding-bottom: env(safe-area-inset-bottom); /* لدعم هواتف iPhone الحديثة */
}

.bottom-nav-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    height: 100%;
    padding: 0 10px;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    gap: 4px;
    width: 20%;
    height: 100%;
    position: relative;
    transition: color 0.2s;
}
.bottom-nav-item i {
    font-size: 20px;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.bottom-nav-item:hover,
.bottom-nav-item.active {
    color: var(--primary-color);
}
.bottom-nav-item.active i {
    transform: scale(1.15) translateY(-2px);
}

/* عداد السلة الصغير للشريط السفلي */
.bottom-nav-badge {
    position: absolute;
    top: 5px;
    right: 50%;
    transform: translateX(18px);
    background-color: var(--primary-color);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid var(--white);
    padding: 0 3px;
}

/* --- تعديلات التجاوب للشاشات (Media Queries) --- */

/* 1. الأجهزة اللوحية (iPad/Tablets) والشاشات المتوسطة (< 1024px) */
@media (max-width: 1023px) {
    .nav-container {
        padding: 0 15px;
    }
    .nav-links {
        display: none !important; /* إخفاء الروابط الطويلة على الأجهزة اللوحية والهواتف */
    }
    .hamburger-btn {
        display: flex; /* إظهار زر همبرغر بديل للروابط المخفية */
    }
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 16px;
    }
}

/* 2. شاشات الجوال (< 768px) */
@media (max-width: 767px) {
    .navbar {
        height: 56px;
    }
    .nav-container {
        height: 56px;
    }
    .logo {
        font-size: 1.15rem;
    }
    
    /* تبسيط وتنسيق أدوات اليمين في الهيدر */
    .nav-utils {
        gap: 4px;
    }
    .nav-utils .nav-divider,
    .nav-utils .nav-lang-btn,
    .nav-utils #frontend-theme-toggle {
        display: none !important; /* سيتم وضعها في القائمة الجانبية لتبسيط الهيدر */
    }
    .nav-utils .nav-login-btn span {
        display: none !important; /* إخفاء نص الدخول وإبقاء الأيقونة فقط */
    }
    .nav-utils .nav-login-btn {
        padding: 7px 10px;
        border-radius: 50%;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .nav-utils .nav-cart-btn {
        padding: 7px 10px;
        border-radius: 50%;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .nav-utils .nav-cart-btn span {
        position: absolute;
        top: 2px;
        left: 2px;
        font-size: 10px;
        padding: 0px 5px;
        min-width: 16px;
    }
    
    /* الجداول المتجاوبة للجوال */
    .responsive-table-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 20px;
        border-radius: var(--radius-md);
        border: 1px solid var(--border-color);
    }
    .responsive-table-wrapper table {
        min-width: 500px; /* تضمن عدم انكماش الجدول ووجوب السكرول */
    }

    /* تحسين الفلاتر وجداول الأقسام */
    .filters-bar {
        gap: 10px;
    }
    .filters-bar .form-group {
        flex: 1 1 calc(50% - 10px) !important;
    }
    .filters-bar .form-group:first-child {
        flex: 1 1 100% !important; /* مربع البحث يأخذ عرض كامل */
    }
}

/* 3. شاشات الجوال الصغيرة جداً (< 600px) - تفعيل الشريط السفلي والبطاقات الثنائية */
@media (max-width: 600px) {
    .mobile-bottom-nav {
        display: block; /* إظهار شريط التنقل السفلي */
    }
    body {
        padding-bottom: 65px; /* لمنع تغطية المحتوى السفلي بالشريط الثابت */
    }
    
    /* البطاقات الثنائية للجوال (2 columns) */
    .grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    
    /* تحسين تصميم الكارد ليناسب العرض المحدود */
    .card {
        border-radius: var(--radius-md);
    }
    .card-img-wrapper {
        height: 135px !important;
    }
    .card-body {
        padding: 10px !important;
    }
    .card-title {
        font-size: 0.9rem !important;
        margin-bottom: 6px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .card-price {
        font-size: 0.95rem !important;
        margin-bottom: 10px !important;
        flex-direction: column !important;
        gap: 2px !important;
        align-items: center !important;
    }
    .card-price div {
        margin: 0 !important;
    }
    .card .btn {
        padding: 8px 10px !important;
        font-size: 0.8rem !important;
        border-radius: 6px !important;
    }

    /* قسم تفاصيل الطلب */
    .order-details-grid {
        grid-template-columns: 1fr 1fr !important; /* عمودين بدلاً من 3 */
        gap: 10px !important;
    }
    .order-details-grid .detail-item:last-child {
        grid-column: 1 / -1; /* يأخذ كامل العرض */
    }
}