/* ═══════════════════════════════════════════════════════
   mobile-results-fix.css
   إصلاح شامل لتجربة الهاتف — البحث + النتائج
   ═══════════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* ═══════════════════════════════════════
       1. مربع البحث الكبير
       ═══════════════════════════════════════ */
    .search-widget {
        z-index: 1100 !important; /* أعلى من 1010 (أزرار الخريطة) */
        /* باقي الخصائص كما هي */
        width: calc(100% - 32px) !important;
        bottom: 16px !important;
        border-radius: 20px !important;
        max-height: 80vh !important;
        overflow-y: auto !important;
    }

    /* 3. نافذة أشكال الخريطة (فوق المربع المصغر وتفتح بجانب الأزرار) */
    .map-style-popup {
        z-index: 1010 !important; 
        bottom: 170px !important;
        right: 75px !important;
    }

    /* 4. الأزرار العائمة الخاصة بالنتائج والبحث (أعلى شيء دائماً) */
    .mobile-results-toggle,
    .mobile-new-search-fab {
        z-index: 1200 !important; /* أعلى من الجميع */
    }

    /* المربع المصغر */
    .search-mini {
        z-index: 1000 !important;
        /* باقي خصائص المربع المصغر تبقى كما هي */
        bottom: 16px !important;
        width: calc(100% - 32px) !important;
        height: auto !important;
        min-height: 50px;
        flex-wrap: wrap !important;
        padding: 8px 12px !important;
        border-radius: 20px !important;
        gap: 6px !important;
    }

    .search-mini.show {
        display: flex !important;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    /* ═══ المفضلات داخل المربع المصغر ═══ */
    .mini-fav-section {
        display: flex !important;
        width: 100%;
        flex-direction: column;
        gap: 4px;
        border-top: 1px solid rgba(0,0,0,.06);
        padding-top: 6px;
        margin-top: 2px;
    }

    .mini-fav-title {
        font-size: 11px;
        font-weight: 800;
        color: #94a3b8;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .mini-fav-chips {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
    }

    .mini-fav-chip {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 5px 10px;
        border-radius: 16px;
        background: rgba(255,255,255,.7);
        border: 1px solid #e2e8f0;
        font-size: 11px;
        font-weight: 700;
        color: #1e293b;
        cursor: pointer;
        transition: all .2s;
        white-space: nowrap;
    }

    .mini-fav-chip:active {
        transform: scale(.95);
        background: #fff;
        border-color: #4f6ef7;
    }

    .mini-fav-routes-wrap {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
    }

    .mini-fav-route {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
        border-radius: 12px;
        background: rgba(255,255,255,.7);
        border: 1px solid #e2e8f0;
        font-size: 11px;
        font-weight: 700;
        color: #1e293b;
        cursor: pointer;
        transition: all .2s;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* 2. أزرار الخريطة (فوق المربع المصغر، تحت المربع الكبير) */
    .map-controls {
        z-index: 1010 !important; /* أعلى من 1000 وأقل من 1100 */
        bottom: 170px !important; /* لرفع الأزرار فوق المربع المصغر */
    }

    .mini-fav-route:active {
        transform: scale(.95);
        border-color: #4f6ef7;
    }

    .mini-fav-route i {
        color: #4f6ef7;
        font-size: 10px;
    }


    /* ═══════════════════════════════════════
       2. لوحة النتائج — bottom sheet
       ═══════════════════════════════════════ */
    .results-panel {
        z-index: 1500 !important;
        top: auto !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 55vh !important;
        max-height: 55vh !important;
        border-radius: 20px 20px 0 0 !important;
        transform: translateY(100%) !important;
        box-shadow: 0 -8px 40px rgba(0, 0, 0, .15) !important;
        transition: transform .35s cubic-bezier(.4, 0, .2, 1),
                    height .35s cubic-bezier(.4, 0, .2, 1) !important;
    }

    .results-panel.show {
        transform: translateY(0) !important;
    }

    /* ثلاث مراحل للسحب */
    .results-panel.mobile-full {
        height: 85vh !important;
        max-height: 85vh !important;
    }

    .results-panel.mobile-half {
        height: 55vh !important;
        max-height: 55vh !important;
    }

    .results-panel.mobile-peek {
        height: 130px !important;
        max-height: 130px !important;
        overflow: hidden !important;
    }

    .results-panel.mobile-peek .rp-list {
        display: none !important;
    }

    .results-panel.mobile-peek .rp-trip-summary {
        display: none !important;
    }

    /* مقبض السحب */
    .results-panel::before {
        content: '';
        display: block;
        width: 40px;
        height: 5px;
        background: #d1d5db;
        border-radius: 3px;
        margin: 8px auto 2px;
        flex-shrink: 0;
    }

    .rp-close {
        width: 40px !important;
        height: 40px !important;
        font-size: 20px !important;
        background: #fee2e2 !important;
        color: #dc2626 !important;
        border-radius: 12px !important;
    }

    .rp-close:active {
        background: #fecaca !important;
        transform: scale(0.95);
    }

    .rp-header {
        padding: 2px 16px 0 !important;
        border-bottom: 1px solid #f1f5f9 !important;
    }

    .rp-header-top {
        margin-bottom: 6px !important;
    }

    .rp-title {
        font-size: 15px !important;
    }

    .rp-trip-summary {
        padding: 6px 10px !important;
        font-size: 11px !important;
        margin-bottom: 8px !important;
    }

    .rp-list {
        flex: 1;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding-bottom: max(20px, env(safe-area-inset-bottom)) !important;
    }

    .rc {
        padding: 12px 16px !important;
    }

    .sort-tab {
        padding: 6px 4px !important;
        font-size: 11px !important;
    }

    /* إخفاء مربع البحث عند ظهور النتائج */
    .search-mini.hide-for-results {
        transform: translateX(-50%) translateY(200px) !important;
        opacity: 0 !important;
        pointer-events: none !important;
        transition: all .3s ease !important;
    }

    .search-widget.hide-for-results {
        transform: translateX(-50%) translateY(200px) !important;
        opacity: 0 !important;
        pointer-events: none !important;
        transition: all .3s ease !important;
    }

    /* زر إظهار النتائج */
    .mobile-results-toggle {
        display: none;
        position: fixed;
        bottom: 80px;
        right: 16px;
        z-index: 1350;
        width: 52px;
        height: 52px;
        border-radius: 16px;
        background: linear-gradient(135deg, #4f6ef7, #3b4fd4);
        color: #fff;
        border: none;
        font-size: 18px;
        cursor: pointer;
        box-shadow: 0 4px 20px rgba(79, 110, 247, .4);
        align-items: center;
        justify-content: center;
        transition: all .3s ease;
    }

    .mobile-results-toggle.show {
        display: flex !important;
    }

    .mobile-results-toggle:active {
        transform: scale(0.92);
    }

    .mobile-results-toggle .badge {
        position: absolute;
        top: -4px;
        right: -4px;
        background: #f43f5e;
        color: #fff;
        font-size: 10px;
        font-weight: 800;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2px solid #fff;
    }

    /* زر بحث جديد عائم */
    .mobile-new-search-fab {
        display: none;
        position: fixed;
        bottom: 80px;
        left: 16px;
        z-index: 1350;
        width: 44px;
        height: 44px;
        border-radius: 14px;
        background: rgba(255,255,255,.92);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: 1px solid rgba(255,255,255,.5);
        color: #4f6ef7;
        font-size: 16px;
        cursor: pointer;
        box-shadow: 0 4px 16px rgba(0,0,0,.1);
        align-items: center;
        justify-content: center;
        transition: all .3s ease;
    }

    .mobile-new-search-fab.show {
        display: flex !important;
    }

    .mobile-new-search-fab:active {
        transform: scale(0.92);
    }

    /* لا تحريك أزرار الخريطة على الهاتف */
    .map-controls.shifted {
        right: 16px !important;
    }

    .map-style-btn.shifted {
        right: 16px !important;
    }

    .map-style-popup.shifted {
        right: 16px !important;
    }
}

/* شاشات كبيرة */
@media (min-width: 769px) {
    .mobile-results-toggle {
        display: none !important;
    }

    .mobile-new-search-fab {
        display: none !important;
    }

    .mini-fav-section {
        display: none !important;
    }
}