/* تحويل الموقع لتطبيق محتوى بالكامل مع منع التمرير الخارجي وفتحه داخلياً */
html, body { 
    max-width: 100%; 
    box-sizing: border-box; 
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif; 
    margin: 0; 
    background-color: #121212; /* 👈 تم تغيير لون الخلفية إلى الأسود الداكن */
    color: #ffffff; /* 👈 تم تغيير لون النصوص العامة إلى الأبيض لتكون مقروءة */
    height: 100vh;
    height: 100dvh; /* احتواء كامل للشاشة */
    overflow: hidden; /* منع التمرير للصفحة بالكامل من الخارج */
    display: flex; 
    flex-direction: column; 
}
*, *:before, *:after { box-sizing: inherit; }

/* تثبيت الواجهة العلوية */
header { background-color: #131921; color: white; padding: 15px 5%; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; z-index: 100; }
header h1 { margin: 0; color: #febd69; font-size: 24px; }

/* تثبيت شريط التنقل والسماح للأزرار بالظهور الكامل دون تمرير جانبي */
nav { background-color: #232f3e; padding: 10px 5%; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; flex-shrink: 0; z-index: 100; }
.nav-links { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; justify-content: center; }
nav a { color: white; text-decoration: none; font-weight: bold; padding: 8px 12px; border-radius: 4px; cursor: pointer; transition: 0.3s; white-space: nowrap;}
nav a.active, nav a:hover { background-color: #febd69; color: #111; }
.visitor-counter-box { display: flex; align-items: center; justify-content: flex-end; }

/* 🕵️‍♂️ كود إخفاء زر الإدارة السري */
.secret-admin, .secret-admin:hover, .secret-admin.active { color: transparent !important; background-color: transparent !important; user-select: none; cursor: pointer; }

/* جعل الحاوية هي المنطقة الوحيدة القابلة للتمرير (قلب التطبيق المتحرك) */
.container { 
    padding: 20px 5% 40px 5%; /* مساحة سفلية للراحة */
    max-width: 1200px; 
    margin: 0 auto; 
    flex-grow: 1; /* تعبئة باقي مساحة الشاشة بالكامل */
    overflow-y: auto; /* السماح بالتمرير الحر الداخلي هنا فقط */
    overflow-x: hidden;
    width: 100%;
}

.page { display: none; }
.page.active { display: block; }

/* الفلاتر */
.cat-filter-bar { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 10px; scrollbar-width: none;}
.cat-filter-bar::-webkit-scrollbar { display: none; }
.cat-btn { background: white; border: 1px solid #ddd; padding: 8px 15px; border-radius: 20px; cursor: pointer; font-weight: bold; white-space: nowrap; color: #555; }
.cat-btn.active-cat { background: #2196F3; color: white; border-color: #2196F3; }
.subcat-filter-bar { display: none; gap: 8px; overflow-x: auto; padding: 10px; background: #e7f3fe; border-radius: 8px; border: 1px dashed #2196F3; scrollbar-width: none;}
.subcat-filter-bar::-webkit-scrollbar { display: none; }
.subcat-filter-bar.active { display: flex; }
.sub-btn { background: white; border: 1px solid #2196F3; padding: 5px 12px; border-radius: 15px; cursor: pointer; font-size: 13px; color: #2196F3; white-space: nowrap;}
.sub-btn.active-sub { background: #2196F3; color: white; }

/* شبكة الإعلانات والكروت بشكلها الجديد للصور العملاقة */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 15px; }
.card { background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); position: relative; display: flex; flex-direction: column; overflow: hidden; border: 1px solid #eee; padding: 0; }
.card.pinned { border: 2px solid #e91e63; background: #fffcfd; }

/* تنسيق الصور لتأخذ المساحة الكاملة بدون فراغات (المهمة 4) */
.image-gallery { width: 100%; height: 280px; background: #f0f0f0; display: flex; overflow-x: auto; scrollbar-width: none; snap-type: x mandatory; margin: 0; padding: 0; }
.image-gallery::-webkit-scrollbar { display: none; }
.image-gallery img { width: 100%; height: 100%; object-fit: cover; flex-shrink: 0; snap-align: start; }

/* مساحة النصوص السفلية المدمجة */
.card-content-area { padding: 12px; display: flex; flex-direction: column; gap: 6px; flex-grow: 1; }
.card h3 { margin: 0; font-size: 17px; color: #111; font-weight: bold; line-height: 1.4; }
.card p.desc { color: #555; font-size: 13px; margin: 0; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stats-bar { display: flex; justify-content: space-between; font-size: 12px; color: #555; background: #f9f9f9; padding: 8px; border-radius: 4px; margin-top: auto; border: 1px solid #eee; }
.stats-bar strong { color: #111; font-size: 13px; }
.category-tags { display: flex; gap: 5px; margin-bottom: 5px; flex-wrap: wrap;}
.category-tag { background: #e7f3fe; color: #2196F3; padding: 3px 8px; border-radius: 12px; font-size: 11px; font-weight: bold;}
.subcategory-tag { background: #f0f0f0; color: #666; padding: 3px 8px; border-radius: 12px; font-size: 11px; border: 1px solid #ddd; font-weight: bold;}
.status-badge { position: absolute; top: 10px; left: 10px; font-size: 11px; padding: 4px 8px; border-radius: 4px; font-weight: bold; background: #ff9800; color: white; z-index: 10;}
.status-featured { position: absolute; top: 10px; right: 10px; background: #e91e63; color: white; font-size: 11px; padding: 4px 8px; border-radius: 4px; font-weight: bold; z-index: 10; }
.contact-info { font-size: 13px; color: #444; }

/* الأزرار والنماذج */
.btn { background: #febd69; color: #111; border: none; padding: 8px 12px; cursor: pointer; font-weight: bold; border-radius: 6px; font-size: 13px; font-family: inherit;}
.btn-success { background: #4CAF50; color: white; }
.btn-danger { background: #f44336; color: white; }
.btn-info { background: #2196F3; color: white; }
.btn-feature { background: #9c27b0; color: white; }
.btn-enlarge { background: #009688; color: white; } 
.btn-purchase { background: #ff9800; color: white; } 
.btn-view { background: #131921; color: white; width: 100%; margin-top: 8px; padding: 10px; font-size: 14px; border-radius: 6px;}
.btn-gemini { background: #673ab7; color: white; width: 100%; margin-top: 10px; padding: 10px;}
.btn-whatsapp { background: #25D366; color: white; display: block; text-align: center; text-decoration: none; padding: 10px; margin-top: 10px; border-radius: 6px; font-weight: bold; font-size: 15px;}

.form-container { background: white; padding: 25px; border-radius: 8px; max-width: 650px; margin: auto; box-shadow: 0 2px 10px rgba(0,0,0,0.1);}
.form-container form h2 { margin-top: 0; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: bold; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 6px; box-sizing: border-box; font-family: inherit; }
.admin-section { background: white; padding: 20px; border-radius: 8px; margin-bottom: 25px; border-right: 5px solid #2196F3; box-shadow: 0 2px 5px rgba(0,0,0,0.05);}
.admin-controls { margin-top: 10px; padding: 10px; display: flex; gap: 5px; flex-wrap: wrap; border-top: 1px solid #eee; }
.admin-controls .btn { flex: 1; min-width: 60px; }

/* النافذة المنبثقة وزر الإغلاق العائم المضمون للموبايل */
.modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); overflow-y: auto; padding: 10px; box-sizing: border-box;}
.modal-content { background: #fff; margin: 20px auto; padding: 15px; border-radius: 12px; width: 100%; max-width: 600px; position: relative; box-sizing: border-box; }
.close-modal-btn { position: absolute; top: 12px; left: 12px; z-index: 2100; background: rgba(255,255,255,0.9); color: #333; border: 1px solid #ddd; border-radius: 50%; width: 38px; height: 38px; font-size: 26px; font-weight: bold; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.15); transition: 0.2s;}
.close-modal-btn:hover { background: #d32f2f; color: white; border-color: #d32f2f; }
.modal-images { display: flex; overflow-x: auto; gap: 10px; margin-bottom: 15px; border-radius: 8px; background: #fafafa; }
.modal-images img { max-width: 100%; height: auto; max-height: 350px; border-radius: 8px; object-fit: contain; flex-shrink: 0; }
.alert { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; padding: 15px 30px; border-radius: 6px; font-weight: bold; display: none; background: #dff0d8; color: #3c763d; border: 1px solid #d6e9c6; box-shadow: 0 4px 15px rgba(0,0,0,0.2); text-align: center; min-width: 280px; }

/* تصميم قسم المزاد */
.auction-card { border: 2px solid #2196F3 !important; }
.auction-badge { position: absolute; top: 10px; left: 10px; background: #d32f2f; color: white; padding: 4px 10px; border-radius: 4px; font-size: 11px; font-weight: bold; z-index: 10; }
.price-tag { font-size: 16px; color: #b12704; font-weight: bold; background: #fff8e1; padding: 8px; border-radius: 6px; border: 1px solid #ffe082; text-align: center; margin: 10px 0; }

/* ---------------------------------------------------
   إضافات التجاوب والمهام الجديدة
--------------------------------------------------- */

/* تأثير النبض للافتة المزاد (المهمة 6) */
@keyframes pulseGlow {
    0% { transform: scale(1); box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
    50% { transform: scale(1.02); box-shadow: 0 4px 20px rgba(233, 30, 99, 0.4); }
    100% { transform: scale(1); box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
}
#auction-banner { animation: pulseGlow 2s infinite; }

/* تجربة الموبايل المثالية وتنسيق البحث (المهمة 1 و 5) */
@media (max-width: 768px) {
    .search-container { flex-direction: column; }
    .search-box { width: 100%; }
    .image-gallery { height: 240px; } /* مواءمة طول الصورة لتناسب الشاشات الأصغر بشكل أنيق */
}

#home-grid, #auction-grid, #goods-grid, #admin-grid {
    display: grid;
    /* هذا السطر السحري يحدد حجم الكرت بـ 280 بيكسل، ويملأ الفراغات تلقائياً */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    padding: 15px;
}

@media (max-width: 600px) {
    
    nav { padding-bottom: 5px !important; }
    h1.mobile-title { display: none !important; }
    
    .nav-links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
        margin-bottom: 5px;
    }

    /* 1. إرجاع زر الإدارة لوضعه المخفي السري (شفاف وفي مكانه تماماً) */
    #nav-admin {
        color: transparent !important;
        background-color: transparent !important;
        user-select: none;
        cursor: pointer;
        flex: 0 0 10% !important;
        font-size: 8px !important;
    }

    /* 2. إخفاء حاوية الدخول القديمة وإظهار زر الموبايل الجديد بالسطر الثاني */
    #user-auth-container { display: none !important; }
    #nav-login-mobile { display: inline-flex !important; }

    /* 3. السطر الأول (3 أزرار: orbis cars، أضف إعلانك، المزاد) */
    #nav-home, #nav-add, #nav-auction { 
        flex: 0 0 31% !important; 
        font-size: 11px !important; 
        padding: 6px 0 !important; 
        text-align: center; 
        display: inline-flex !important;
        justify-content: center;
        align-items: center;
    }

    /* 4. السطر الثاني (4 أزرار: حاسبة الأقساط، بضاعتنا، تواصل معنا، تسجيل الدخول) */
    #nav-calculator, #nav-goods, #nav-contact, #nav-login-mobile { 
        flex: 0 0 23% !important; 
        font-size: 10px !important; 
        padding: 6px 0 !important; 
        text-align: center; 
        display: inline-flex !important;
        justify-content: center;
        align-items: center;
    }

    /* 5. السطر الثالث (العدادات وسعر الصرف فقط) */
    .visitor-counter-box { 
        width: 100% !important;
        display: flex !important;
        justify-content: space-around !important;
        gap: 5px !important;
        margin-top: 5px !important;
    }

    /* تنظيم خانات البحث وعرض الإعلانات */
    .search-container {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        flex-direction: unset !important;
    }
    .search-box {
        width: 100% !important;
        margin: 0 !important;
        font-size: 12px !important;
        padding: 8px !important;
    }

    #home-grid, #auction-grid, #goods-grid, #admin-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        padding: 5px !important;
    }
}

    .image-gallery {
        height: 140px !important;
    }
    .card-content-area {
        padding: 8px !important;
    }
    .card h3 {
        font-size: 13px !important;
    }
    .card p.desc {
        font-size: 11px !important;
        -webkit-line-clamp: 2 !important;
    }
    
    .stats-bar {
        flex-direction: column !important;
        align-items: center;
        gap: 4px;
        font-size: 10px !important;
        padding: 5px !important;
    }
    .stats-bar strong {
        font-size: 11px !important;
    }
    
    .btn {
        font-size: 11px !important;
        padding: 5px !important;
    }
    
    .category-tags {
        justify-content: center;
    }
}
#ad-form label, #edit-form label {
    display: block !important;
    font-weight: bold !important;
    margin-bottom: 8px !important;
    margin-top: 15px !important;
    color: #333 !important;
}
/* =========================================
   تنسيقات حاسبة الأقساط
   ========================================= */
.calculator-container { max-width: 500px; margin: 20px auto; background: #fff; padding: 25px; border-radius: 10px; box-shadow: 0 4px 10px rgba(0,0,0,0.15); color: #333; direction: rtl; }
.calculator-container h2 { text-align: center; color: #2196F3; margin-top: 0; margin-bottom: 20px; }
.calculator-container label { display: block; margin-bottom: 8px; font-weight: bold; color: #34495e; text-align: right; }
.calculator-container select, .calculator-container input { width: 100%; padding: 12px; margin-bottom: 20px; border: 1px solid #ccc; border-radius: 6px; box-sizing: border-box; font-size: 16px; font-family: inherit; }
.calculator-container button { width: 100%; padding: 12px; background-color: #4CAF50; color: white; border: none; border-radius: 6px; font-size: 18px; cursor: pointer; transition: 0.3s; font-weight: bold; font-family: inherit; }
.calculator-container button:hover { background-color: #388E3C; }
.option-card { background: #f8f9fa; border-right: 5px solid #2196F3; padding: 15px; margin-bottom: 15px; border-radius: 6px; border-left: 1px solid #eee; border-top: 1px solid #eee; border-bottom: 1px solid #eee; text-align: right; }
.option-card span { font-weight: bold; color: #d32f2f; font-size: 18px; }
.calc-error { color: #d32f2f; text-align: center; font-weight: bold; background: #ffebee; padding: 10px; border-radius: 6px; margin-top: 10px; }