/* ==========================================
   SEARCH BOX WITH SETTINGS BUTTON - FIXED
   سرچ باکس با دکمه تنظیمات (اصلاح شده)
========================================== */

/* =====================
   CRITICAL FIXES
===================== */

/* Reset WordPress Styles */
.header-search *,
.search-wrapper * {
    box-sizing: border-box !important;
}

/* =====================
   SEARCH WRAPPER
===================== */

.search-wrapper {
    position: relative !important;
    width: 100% !important;
    max-width: 400px !important;
    margin: 0 !important;
}

.header-search {
    position: relative !important;
    width: 100% !important;
    max-width: 400px !important;
    margin: 0 !important;
}

/* =====================
   SEARCH FORM
===================== */

.search-form {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
    height: 42px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    transition: all 0.3s ease !important;
    margin: 0 !important;
    padding: 0 !important;
}

.search-form:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.15) !important;
}

.search-form:focus-within {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.1) !important;
}

/* =====================
   SETTINGS BUTTON (چپ)
===================== */

.search-settings-btn {
    flex-shrink: 0 !important;
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: var(--primary-color) !important;
    border: none !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    color: var(--background-dark) !important;
    padding: 0 !important;
    margin: 0 !important;
    order: 1 !important;
}

.search-settings-btn:hover {
    background: var(--primary-hover) !important;
    transform: rotate(90deg) !important;
}

.search-settings-btn:active {
    transform: rotate(90deg) scale(0.95) !important;
}

.search-settings-btn svg {
    width: 20px !important;
    height: 20px !important;
    display: block !important;
}

/* =====================
   SEARCH INPUT (وسط)
===================== */

.search-field {
    flex: 1 !important;
    height: 42px !important;
    padding: 0 16px !important;
    background: transparent !important;
    border: none !important;
    color: var(--text-primary) !important;
    font-size: 0.875rem !important;
    font-family: 'Vazirmatn', 'Tahoma', sans-serif !important;
    outline: none !important;
    direction: rtl !important;
    text-align: right !important;
    margin: 0 !important;
    order: 2 !important;
}

.search-field::placeholder {
    color: rgba(255, 255, 255, 0.5) !important;
}

/* =====================
   SEARCH SUBMIT (راست)
===================== */

.search-submit {
    flex-shrink: 0 !important;
    width: 42px !important;
    height: 42px !important;
    min-width: 42px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: transparent !important;
    border: none !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    color: var(--text-muted) !important;
    padding: 0 !important;
    margin: 0 !important;
    order: 3 !important;
    text-indent: 0 !important;
    font-size: 0 !important;
}

.search-submit:hover {
    color: var(--primary-color) !important;
    background: rgba(255, 255, 255, 0.05) !important;
}

.search-submit svg {
    width: 18px !important;
    height: 18px !important;
    display: block !important;
}

/* =====================
   REMOVE WEBKIT DEFAULTS
===================== */

.search-field::-webkit-search-decoration,
.search-field::-webkit-search-cancel-button,
.search-field::-webkit-search-results-button,
.search-field::-webkit-search-results-decoration {
    display: none !important;
    -webkit-appearance: none !important;
}

/* =====================
   TOP HEADER VARIATION
===================== */

.header-layout-top .top-header-actions .search-wrapper,
.header-layout-top .top-header-actions .header-search {
    max-width: 300px !important;
}

.header-layout-top .top-header-actions .search-form {
    height: 40px !important;
}

.header-layout-top .top-header-actions .search-settings-btn,
.header-layout-top .top-header-actions .search-submit,
.header-layout-top .top-header-actions .search-field {
    height: 40px !important;
}

.header-layout-top .top-header-actions .search-settings-btn,
.header-layout-top .top-header-actions .search-submit {
    width: 40px !important;
    min-width: 40px !important;
}

.header-layout-top .top-header-actions .search-field {
    font-size: 0.85rem !important;
}

/* =====================
   SIDEBAR MODE
===================== */

.header-layout-sidebar .search-wrapper,
.header-layout-sidebar .header-search {
    max-width: 450px !important;
}

/* =====================
   RESPONSIVE
===================== */

@media (max-width: 1024px) {
    .header-layout-top .top-header-actions .search-wrapper {
        max-width: 260px !important;
    }
    
    .search-field {
        font-size: 0.8rem !important;
    }
}

@media (max-width: 768px) {
    .header-layout-sidebar .search-wrapper {
        max-width: 100% !important;
    }
    
    .header-layout-top .top-header-actions .search-wrapper {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .search-form {
        height: 38px !important;
    }
    
    .search-settings-btn,
    .search-submit,
    .search-field {
        height: 38px !important;
    }
    
    .search-settings-btn,
    .search-submit {
        width: 38px !important;
        min-width: 38px !important;
    }
    
    .search-settings-btn svg {
        width: 18px !important;
        height: 18px !important;
    }
    
    .search-submit svg {
        width: 16px !important;
        height: 16px !important;
    }
}

/* =====================
   ANIMATION
===================== */

@keyframes settingsRotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.search-settings-btn.loading {
    animation: settingsRotate 1s linear infinite !important;
    pointer-events: none !important;
}

/* =====================
   FOCUS STYLES
===================== */

.search-settings-btn:focus,
.search-submit:focus {
    outline: 2px solid var(--primary-color) !important;
    outline-offset: 2px !important;
}

/* =====================
   TOOLTIP (اختیاری)
===================== */

.search-settings-btn[data-tooltip] {
    position: relative;
}

.search-settings-btn[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 9999;
}

.search-settings-btn[data-tooltip]:hover::before {
    opacity: 1;
}

/* ==========================================
   ADVANCED SEARCH MODAL - FIX Z-INDEX
   اصلاح مشکل Modal زیر سرچ باکس
========================================== */

/* Modal Container - بالاترین z-index */
.advanced-search-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 99999 !important;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.advanced-search-modal.active {
    display: flex !important;
}

/* Overlay */
.advanced-search-overlay {
    position: absolute !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.85) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    animation: fadeIn 0.3s ease !important;
    z-index: 1 !important;
}

/* Content Box */
.advanced-search-content {
    position: relative !important;
    z-index: 2 !important;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%) !important;
    border-radius: 20px !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5) !important;
    width: 100% !important;
    max-width: 900px !important;
    max-height: 90vh !important;
    overflow: hidden !important;
    animation: slideUp 0.4s ease !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

/* اطمینان از اینکه Modal روی header قرار می‌گیرد */
.site-header,
.site-header-top {
    z-index: 1000 !important;
}

.advanced-search-modal {
    z-index: 99999 !important;
}