/* ==========================================================================
   Madrina Professional Search - Premium Purple Theme (#895dad)
   ========================================================================== */

/* متغیرهای رنگی اختصاصی */
:root {
    --madrina-primary: #895dad;
    --madrina-primary-light: #9f75bf;
    --madrina-primary-dark: #684187;
    --madrina-glow: rgba(137, 93, 173, 0.4);
    --madrina-glass-bg: rgba(22, 16, 29, 0.88);
}

/* 1. دکمه بازکننده جستجو (آیکون + کلمه جستجو) */
.madrina-search-trigger-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(137, 93, 173, 0.08);
    border: 1.5px solid var(--madrina-primary);
    padding: 8px 18px;
    border-radius: 50px;
    color: var(--madrina-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 15px rgba(137, 93, 173, 0.12);
    direction: rtl;
}

.madrina-search-trigger-btn .madrina-search-icon {
    stroke: var(--madrina-primary);
    transition: transform 0.3s ease;
}

.madrina-search-trigger-btn:hover {
    background: var(--madrina-primary);
    color: #ffffff;
    box-shadow: 0 6px 22px var(--madrina-glow);
    transform: translateY(-2px);
}

.madrina-search-trigger-btn:hover .madrina-search-icon {
    stroke: #ffffff;
    transform: scale(1.1);
}

/* 2. مدال تمام‌صفحه (Overlay) */
.madrina-search-overlay {
    position: fixed;
    inset: 0;
    background: var(--madrina-glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 999999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 70px 20px 40px;
    direction: rtl;
    overflow-y: auto;
}

.madrina-search-overlay.is-active {
    opacity: 1;
    visibility: visible;
}

.madrina-search-modal-container {
    width: 100%;
    max-width: 800px;
    position: relative;
    transform: translateY(-25px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.madrina-search-overlay.is-active .madrina-search-modal-container {
    transform: translateY(0);
}

/* --- اصلاح آیکون بستن (X) برای دیده شدن --- */

/* کانتینر دکمه بستن */
.madrina-search-close-btn {
    position: absolute;
    top: -50px;
    left: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 44px; /* کمی بزرگتر برای دسترسی بهتر */
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0; /* حذف پدینگ اضافی */
    box-sizing: border-box;
}

/* استایل مستقیم برای خود آیکون SVG درون دکمه */
.madrina-search-close-btn svg {
    width: 24px !important; /* اندازه صریح آیکون */
    height: 24px !important; /* اندازه صریح آیکون */
    display: block;
    stroke: currentColor; /* استفاده از رنگ سفید والد */
    stroke-width: 2.5; /* ضخامت خطوط ضربدر */
}

.madrina-search-close-btn:hover {
    background: var(--madrina-primary); /* تغییر پس‌زمینه به بنفش برند هنگام هاور */
    border-color: var(--madrina-primary);
    transform: rotate(90deg); /* افکت چرخشی جذاب */
    color: #ffffff;
}

/* 3. کادر ورودی اصلی */
.madrina-search-box-wrapper {
    margin-bottom: 35px;
}

.madrina-search-field-group {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1.5px solid rgba(137, 93, 173, 0.3);
    border-radius: 20px;
    padding: 18px 24px;
    transition: all 0.35s ease;
}

.madrina-search-field-group:focus-within {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--madrina-primary);
    box-shadow: 0 0 30px var(--madrina-glow);
}

.madrina-field-icon {
    stroke: var(--madrina-primary);
    margin-left: 15px;
    flex-shrink: 0;
}

#madrina-search-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: #ffffff;
    font-size: 18px;
    font-weight: 400;
}

#madrina-search-input::placeholder {
    color: rgba(255, 255, 255, 0.45);
}

.madrina-search-hint {
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
    margin-top: 10px;
    margin-right: 8px;
}

/* لودر چرخان بنفش */
.madrina-loader-spinner {
    display: none;
    width: 22px;
    height: 22px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--madrina-primary);
    border-radius: 50%;
    animation: madrina-spin 0.8s linear infinite;
}

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

/* 4. نتایج دسته‌بندی‌شده */
.madrina-search-results-wrapper {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.madrina-result-category-block {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(137, 93, 173, 0.2);
    border-radius: 16px;
    padding: 20px;
}

.madrina-category-title {
    color: var(--madrina-primary-light);
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(137, 93, 173, 0.2);
    display: flex;
    align-items: center;
    gap: 8px;
}

.madrina-results-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.madrina-result-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 16px;
    border-radius: 12px;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.02);
    transition: all 0.25s ease;
}

.madrina-result-item:hover {
    background: rgba(137, 93, 173, 0.2);
    transform: translateX(-4px);
}

.madrina-result-thumb {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid rgba(137, 93, 173, 0.3);
}

.madrina-result-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.madrina-result-item-title {
    color: #ffffff;
    font-size: 15px;
    font-weight: 500;
}

.madrina-result-item-excerpt {
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    line-height: 1.5;
}

.madrina-no-results {
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    padding: 40px;
    font-size: 15px;
}

/* ==========================================================================
   Responsive Styles - Mobile View
   ========================================================================== */

@media screen and (max-width: 768px) {
    /* ۱. مخفی کردن کلمه "جستجو" در موبایل */
    .madrina-search-trigger-btn .madrina-search-btn-text {
        display: none !important;
    }

    /* ۲. گرد کردن کامل دکمه در موبایل به شکل یک دایره زیبا */
    .madrina-search-trigger-btn {
        padding: 0 !important;
        width: 42px;
        height: 42px;
        border-radius: 50% !important;
        justify-content: center;
        align-items: center;
        gap: 0;
    }

    /* ۳. تنظیم اندازه و جابه‌جایی آیکون درون دکمه */
    .madrina-search-trigger-btn .madrina-search-icon {
        margin: 0;
        width: 20px;
        height: 20px;
    }

    /* ۴. بهبود موقعیت دکمه بستن (ضربدر) در موبایل */
    .madrina-search-close-btn {
        top: -45px;
        left: 5px;
        width: 38px;
        height: 38px;
    }
    
    .madrina-search-close-btn svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* ۵. بهینه‌سازی کادر مدال جستجو در موبایل */
    .madrina-search-overlay {
        padding: 55px 15px 25px;
    }

    .madrina-search-field-group {
        padding: 12px 16px;
    }

    #madrina-search-input {
        font-size: 15px;
    }
}

/* ==========================================================================
   Fix Mobile Horizontal Scroll & Body Lock Issues
   ========================================================================== */

/* جلوگیری کلی از اسکرول افقی در کل صفحات سایت */
html, body {
    max-width: 100% !important;
    overflow-x: hidden !important;
}

/* اصلاح استایل مدال برای جلوگیری از محاسبه عرض اسکرول‌بار در موبایل */
.madrina-search-overlay {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* پشتیبانی از ارتفاع دینامیک مرورگرهای موبایل */
    background: var(--madrina-glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 999999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 70px 20px 40px;
    direction: rtl;
    overflow-y: auto;
    overflow-x: hidden !important; /* جلوگیری قطعی از اسکرول افقی مدال */
    -webkit-overflow-scrolling: touch; /* اسکرول نرم در آیفون/iOS */
    box-sizing: border-box;
}

/* کلاسی که هنگام باز شدن مدال به body داده می‌شود */
body.madrina-search-active {
    overflow: hidden !important;
    touch-action: none;
}

/* ==========================================================================
   Fix Safari & Mobile Chrome Auto-Zoom + Layout Shift Issues
   ========================================================================== */

/* ۱. جلوگیری از زوم خودکار مرورگرهای موبایل با تنظیم اندازه فونت به حداقل 16px */
#madrina-search-input {
    font-size: 16px !important; /* مانع اصلی زوم خودکار Safari و Chrome */
    -webkit-text-size-adjust: 100%;
}

/* ۲. قفل کردن لایه html و body برای جلوگیری از اسکرول افقی و زوم مانده در Safari */
html.madrina-search-active,
body.madrina-search-active {
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    touch-action: none !important;
}

/* ۳. اصلاح پوزیشن overlay برای Safari iOS هنگام بالا آمدن کیبورد */
.madrina-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: -webkit-fill-available; /* حل مشکل ارتفاع در Safari iOS */
    overflow-y: auto;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

@media screen and (max-width: 768px) {
    #madrina-search-input {
        font-size: 16px !important; /* اطمینان مجدد از 16px بودن در موبایل */
    }
}

/* ==========================================================================
   Anti Auto-Zoom & Strict Mobile Layout Protection
   ========================================================================== */

/* غیرفعال کردن اکید زوم خودکار روی ورودی‌ها در iOS */
#madrina-search-input {
    font-size: 16px !important;
    transform: scale(1) !important;
    -webkit-text-size-adjust: 100% !important;
    touch-action: manipulation !important;
}

/* جلوگیری از اسکرول و زوم ماندن صفحه اصلی */
html.madrina-search-active,
body.madrina-search-active {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    touch-action: none !important;
}

/* مدال جستجو با استفاده از visualViewport */
.madrina-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: var(--madrina-glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 999999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 60px 20px 40px;
    direction: rtl;
    overflow-y: auto;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
}

@media screen and (max-width: 768px) {
    /* تنظیم اندازه برای جلوگیری از هرگونه زوم محاسباتی در گوشی */
    #madrina-search-input {
        font-size: 16px !important;
    }
}