/* =========================================
   SaaS-Style Instant Search Dropdown
   Clean, Professional, Dark Theme
   Unique Prefix: sc-
   ========================================= */

/* Search Form Container */
.sc-search-form-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 900px; /* Increased width */
    margin: 0 auto; /* Center if needed */
}

/* Inner Wrapper for Alignment (Desktop & Mobile) */
.sc-search-inner {
    display: flex;
    width: 100%;
    align-items: center;
    flex: 1;
}

/* Input Field */
.sc-search-input {
    flex: 1;
    height: 48px !important;
    background-color: #1e2025 !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-left: none !important; /* Merge with button */
    border-radius: 0 5px 5px 0 !important; /* RTL Radius */
    color: #fff !important;
    font-size: 0.95rem;
    padding: 0 16px !important;
    font-family: 'Tajawal', sans-serif;
    transition: all 0.2s ease;
    box-shadow: none !important;
    order: 1; /* Input First */
}

.sc-search-input:focus {
    background-color: #23262b !important;
    border-color: #3d5afe !important;
    z-index: 2;
}

.sc-search-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

/* Search Button */
.sc-search-btn {
    width: 52px;
    height: 48px;
    background-color: #3d5afe !important;
    border: none !important;
    border-radius: 5px 0 0 5px !important; /* RTL Radius */
    color: #fff !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    order: 2; /* Button Second */
}

.sc-search-btn:hover {
    background-color: #304ffe !important;
}

.sc-search-btn:active {
    transform: scale(0.96);
}

/* Dropdown Container */
.sc-search-results-wrapper {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0; /* Full width */
    width: 100%;
    background: #1e2025;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 5px;
    z-index: 1000;
    max-height: 480px;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    padding: 0;
    font-family: 'Tajawal', sans-serif;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    direction: rtl; /* Ensure RTL layout inside */
    text-align: right;
}

/* Active State */
.sc-search-results-wrapper:not(.d-none) {
    display: block !important;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Scrollbar */
.sc-search-results-wrapper::-webkit-scrollbar { width: 4px; }
.sc-search-results-wrapper::-webkit-scrollbar-track { background: transparent; }
.sc-search-results-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* Section Headers */
.sc-search-results-wrapper .sc-results-head {
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.03);
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
}

/* Search Items */
.sc-search-results-wrapper .sc-result-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 12px;
    color: #e2e8f0;
    text-decoration: none;
    transition: background 0.15s;
    border-right: 3px solid transparent; /* RTL Indicator */
    position: relative;
}

.sc-search-results-wrapper .sc-result-item:hover,
.sc-search-results-wrapper .sc-result-item.selected {
    background: rgba(61, 90, 254, 0.08);
    border-right-color: #3d5afe;
}

/* Item Image */
.sc-search-results-wrapper .sc-result-item img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
    background: #2a2d35;
    border: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
    order: 1; /* First in RTL (Right) */
}

/* Item Details */
.sc-search-results-wrapper .sc-result-item .sc-details {
    flex: 1;
    min-width: 0; /* Fix flex overflow */
    display: flex;
    flex-direction: column;
    justify-content: center;
    order: 2; /* Middle */
}

.sc-search-results-wrapper .sc-result-item .sc-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.sc-search-results-wrapper .sc-result-item .sc-meta {
    font-size: 0.75rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Price Tag */
.sc-search-results-wrapper .sc-result-item .sc-price {
    font-weight: 700;
    color: #3d5afe;
    font-size: 0.85rem;
    background: rgba(61, 90, 254, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
    flex-shrink: 0;
    order: 3; /* Last in RTL (Left) */
    margin-right: auto; /* Push to far left if needed, but flex handles it */
}

/* No Results */
.sc-search-results-wrapper .sc-no-results {
    padding: 30px;
    text-align: center;
    color: #64748b;
    font-size: 0.9rem;
}

/* Mobile Adjustments */
@media (max-width: 1199px) {
    .sc-search-form-container {
        max-width: 100%;
    }
    
    .sc-search-results-wrapper {
        position: static;
        margin-top: 10px;
        box-shadow: none;
        border: 1px solid rgba(255,255,255,0.08);
    }
}

/* Desktop Layout Improvements */
@media (min-width: 1200px) {
    .mobile-top-search-theme-mod {
        flex-grow: 1;
        margin: 0 2rem;
    }
}

/* =========================================
   Mobile Search Overlay & Improvements
   ========================================= */
@media (max-width: 1199px) {
    .sc-mobile-search-overlay {
        display: none; /* Hidden by default */
        position: fixed; /* Fixed viewport */
        top: 0;
        left: 0;
        right: 0;
        bottom: 0; /* Full height */
        width: 100vw;
        height: 100vh;
        background: #0f172a; /* Solid dark background for better readability */
        z-index: 99999;
        overflow-y: auto; /* Scrollable content */
        padding: 0;
    }
    
    .sc-mobile-search-overlay.active {
        display: flex;
        flex-direction: column;
        animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes slideDown {
        from { opacity: 0; transform: translateY(-20px); }
        to { opacity: 1; transform: translateY(0); }
    }

    /* Container for Form */
    .sc-mobile-search-overlay .sc-mobile-search-box {
        display: contents;
    }

    /* Form Layout - Flexbox for Top Bar & Results */
    .sc-mobile-search-overlay .sc-search-form-container {
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 16px;
        gap: 0;
        height: 100%; /* Fill overlay */
    }

    /* Inner Wrapper for Input & Buttons */
    .sc-mobile-search-overlay .sc-search-inner {
        display: flex;
        width: 100%;
        gap: 0;
        align-items: center;
        flex-shrink: 0;
        margin-bottom: 16px;
    }
    
    /* Top Bar Elements */
    
    /* Search Button (Left in RTL if row-reverse, or use order) */
    .sc-mobile-search-overlay .sc-search-btn {
        background-color: #3d5afe !important;
        color: #fff !important;
        border: none !important;
        height: 48px !important;
        width: 48px !important;
        border-radius: 5px 0 0 5px !important;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        cursor: pointer;
        flex-shrink: 0;
        transition: transform 0.2s;
        box-shadow: 0 4px 12px rgba(61, 90, 254, 0.3);
        order: 2; /* Button after input */
    }
    
    /* Input (Middle) */
    .sc-mobile-search-overlay .sc-search-input {
        background-color: #1e293b !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
        border-left: none !important;
        color: #fff !important;
        height: 48px !important;
        border-radius: 0 5px 5px 0 !important;
        padding: 0 16px !important;
        font-size: 1rem !important;
        flex: 1; /* Take remaining width */
        box-shadow: none !important;
        transition: all 0.2s;
        order: 1; /* Input first */
    }
    
    .sc-mobile-search-overlay .sc-search-input:focus {
        border-color: #3d5afe !important;
        background-color: #253045 !important;
    }

    /* Close Button (Right in RTL if row-reverse, or use order) */
    .sc-mobile-close-btn {
        color: #94a3b8;
        background: transparent;
        border: none;
        padding: 0;
        width: 40px;
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        order: 3; /* Last visually (Left in RTL) */
        margin-right: 12px;
    }

    /* Dropdown Adjustment for Mobile - The Results Area */
    .sc-search-results-wrapper {
        position: static !important;
        margin-top: 0 !important;
        width: 100% !important;
        flex-grow: 1; /* Fill rest of height */
        max-height: none !important;
        overflow-y: auto !important; /* Scrollable results */
        box-shadow: none !important;
        border: none !important;
        background: transparent !important;
        order: 10; /* Force to new line */
    }
    
    /* Hide scrollbar for cleaner look */
    .sc-search-results-wrapper::-webkit-scrollbar {
        width: 4px;
    }
    
    /* Results Items for Mobile */
    .sc-search-results-wrapper .sc-result-item {
        background: #1e293b;
        border: 1px solid rgba(255,255,255,0.05);
        border-radius: 5px;
        margin-bottom: 8px;
        padding: 12px;
    }

    .sc-search-results-wrapper .sc-results-head {
        background: transparent;
        color: #64748b;
        font-size: 0.85rem;
        padding: 0 4px 12px 4px;
        border-bottom: none;
        position: static;
    }
}
