/* ============================================================
   E&W Arabic Smart Search – Stylesheet v1.1
   ============================================================ */

/* CSS Variables – يتم تعبئتها من إعدادات الـ Admin */
:root {
    --ew-accent:      #c8a96e;
    --ew-bg:          #ffffff;
    --ew-border:      #c8a96e;
    --ew-border-w:    2px;
    --ew-radius:      10px;
    --ew-text:        #1a1a1a;
    --ew-muted:       #999999;
    --ew-hover-bg:    #faf8f5;
    --ew-shadow:      0 4px 20px rgba(0,0,0,0.10);
    --ew-font:        'Tajawal', Tahoma, Arial, sans-serif;
    --ew-pad-v:       8px;
    --ew-icon-color:  #999999;
    --ew-icon-size:   18px;
}

/* ── Wrapper ── */
.ew-search-wrapper {
    position: relative;
    width: 100%;
    font-family: var(--ew-font);
    direction: rtl;
    box-sizing: border-box;
}

/* ── Input Row ── */
.ew-search-input-wrap {
    display: flex;
    align-items: center;
    width: 100%;
    background: var(--ew-bg);
    border: var(--ew-border-w) solid var(--ew-border);
    border-radius: var(--ew-radius);
    transition: border-color 0.2s;
    overflow: hidden;
    box-sizing: border-box;
}

.ew-search-input-wrap:focus-within {
    border-color: var(--ew-accent);
}

/* ── Search Icon (inside box) ── */
.ew-search-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px 0 6px;
    color: var(--ew-icon-color);
    flex-shrink: 0;
    pointer-events: none;
}

.ew-search-icon svg {
    width: var(--ew-icon-size);
    height: var(--ew-icon-size);
}

/* ── Input ── */
.ew-search-input {
    flex: 1;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
    font-family: var(--ew-font) !important;
    font-size: 15px !important;
    color: var(--ew-text) !important;
    padding: var(--ew-pad-v) 4px !important;
    min-width: 0;
    direction: auto;
}

.ew-search-input::placeholder {
    color: var(--ew-muted);
    opacity: 1;
}

/* ── Clear Button ── */
.ew-search-clear {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 10px;
    color: var(--ew-muted);
    font-size: 13px;
    flex-shrink: 0;
    transition: color 0.15s;
}

.ew-search-clear:hover { color: var(--ew-text); }
.ew-search-clear.visible { display: flex; }

/* ── Spinner ── */
.ew-search-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid #e0e0e0;
    border-top-color: var(--ew-accent);
    border-radius: 50%;
    animation: ew-spin 0.7s linear infinite;
    margin: 0 8px;
    flex-shrink: 0;
}

.ew-search-spinner.visible { display: block; }

@keyframes ew-spin { to { transform: rotate(360deg); } }

/* ── Results Dropdown ── */
.ew-search-results {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    left: 0;
    background: var(--ew-bg);
    border: 1px solid #e8e8e8;
    border-radius: var(--ew-radius);
    box-shadow: var(--ew-shadow);
    max-height: 400px;
    overflow-y: auto;
    z-index: 99999;
    display: none;
}

.ew-search-results.open { display: block; }

/* ── Result Item ── */
.ew-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    text-decoration: none !important;
    color: var(--ew-text) !important;
    transition: background 0.12s;
    border-bottom: 1px solid #f2f2f2;
}

.ew-result-item:last-child { border-bottom: none; }
.ew-result-item:hover, .ew-result-item.focused { background: var(--ew-hover-bg); }

/* ── Thumbnail ── */
.ew-result-thumb {
    width: 46px;
    height: 46px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    border: 1px solid #ebebeb;
}

/* ── Text ── */
.ew-result-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ew-result-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ew-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    direction: auto;
}

.ew-result-title mark {
    background: rgba(200,169,110,0.22);
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}

.ew-result-price {
    font-size: 12px;
    color: var(--ew-accent);
    font-weight: 500;
}

.ew-result-price ins { text-decoration: none !important; }

/* ── No Results ── */
.ew-no-results {
    padding: 16px;
    text-align: center;
    color: var(--ew-muted);
    font-size: 14px;
}

/* ── Scrollbar ── */
.ew-search-results::-webkit-scrollbar { width: 5px; }
.ew-search-results::-webkit-scrollbar-track { background: #f5f5f5; }
.ew-search-results::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }

/* ============================================================
   MOBILE: أيقونة فقط — الصندوق يظهر عند الضغط
   ============================================================ */

/* الـ Trigger مخفي على الديسكتوب */
.ew-mobile-trigger { display: none; }

@media (max-width: 768px) {

    .ew-search-wrapper {
        width: auto;
    }

    /* إخفاء الصندوق الكامل */
    .ew-search-input-wrap { display: none; }

    /* إظهار زر الأيقونة */
    .ew-mobile-trigger {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        background: none;
        border: none;
        cursor: pointer;
        color: var(--ew-icon-color);
        padding: 0;
        border-radius: 50%;
        transition: background 0.15s;
    }

    .ew-mobile-trigger:hover { background: rgba(0,0,0,0.05); }

    /* Overlay */
    .ew-mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 99998;
    }

    .ew-mobile-overlay.open { display: block; }

    /* الصندوق فوق الـ Overlay */
    .ew-search-wrapper.mobile-open .ew-search-input-wrap {
        display: flex;
        position: fixed;
        top: 14px;
        right: 10px;
        left: 10px;
        width: auto;
        z-index: 99999;
        border-radius: 10px;
        box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    }

    .ew-search-wrapper.mobile-open .ew-search-results {
        position: fixed;
        top: 68px;
        right: 10px;
        left: 10px;
        max-height: 60vh;
        z-index: 99999;
    }
}
