/* استایل کلی */
#ads-map-wrapper {
    position: fixed;
    top: 0; bottom: 0; right: 0; left: 0;
    display: flex;
    flex-direction: column;
    font-family: Vazir, Tahoma, sans-serif;
    direction: rtl;
    background: #fff;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* تعریف متغیرهای CSS برای رنگ‌ها */
:root {
    --primary-red: #920000;
    --primary-white: #ffffff;
    --light-gray-bg: #f9f9f9;
    --dark-text: #333;
    --border-color: #ddd;
    --link-hover-color: #7a0000;
}

/* هدر بالا */
#ads-map-header {
    height: 60px;
    background-color: rgba(255, 255, 255, 0.8); /* هدر سفید کمرنگ و شفاف */
    position: fixed; /* حالا fixed است تا روی نقشه ثابت بماند */
    top: 0;
    left: 0;
    right: 0;
    width: 100%; /* مطمئن شوید تمام عرض را می گیرد */
    display: flex;
    align-items: center;
    padding: 0 20px; /* فاصله استاندارد از اطراف */
    box-shadow: 0 1px 5px rgba(0,0,0,0.2);
    z-index: 1000; /* روی نقشه و کاروسل قرار بگیرد */
    justify-content: space-between; /* لوگو راست، فیلتر چپ */
	flex-direction: row-reverse;
}

#ads-map-logo {
    height: 40px;
    flex-shrink: 0;
}

/* کانتینر نقشه - تمام فضای باقی‌مانده را می‌گیرد */
#ads-map-container {
    flex: 1;
    min-height: 1px;
    z-index: 1; /* زیر هدر و کاروسل */
    width: 100%;
    position: absolute; /* روی هم قرار بگیرد و تمام فضای والد را پر کند */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* --- بخش کاروسل آگهی‌ها --- */
#ads-map-carousel-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 200px;
    padding-bottom: 20px;
    background: transparent;
    z-index: 900; /* پایین تر از هدر */
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    box-sizing: border-box;
}

#ads-map-carousel-container.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

#ads-map-carousel-wrapper {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    margin: 0;
    position: relative;
    box-sizing: border-box;
    padding: 0 15px;
}

/* وقتی فقط یک کارت در کاروسل هست، آن را وسط‌چین کن */
#ads-map-carousel-wrapper.single-card-center {
    justify-content: center !important;
}

/* محتوای داخلی کاروسل - جایی که کارت‌ها قرار می‌گیرند */
#ads-map-carousel-content {
    display: flex !important;
    flex-direction: row !important;
}

/* افکت سایه برای کاروسل */
.carousel-shadow {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    z-index: 901;
    pointer-events: none;
    transition: box-shadow 0.3s ease;
}

.carousel-shadow.left {
    left: 0;
    box-shadow: inset 20px 0 20px -20px rgba(0,0,0,0.5);
}

.carousel-shadow.right {
    right: 0;
    box-shadow: inset -20px 0 20px -20px rgba(0,0,0,0.5);
}


/* استایل‌دهی به عناصر داخلی کارت آگهی */
.ad-card {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start;
    width: 200px !important;
    height: 200px !important;
    flex-shrink: 0 !important;
    background-color: var(--primary-white);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin: 0 8px !important;
    padding: 10px !important;
    box-sizing: border-box !important;
    scroll-snap-align: center;
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.ad-card:first-child {
    margin-right: 15px !important;
}
.ad-card:last-child {
    margin-left: 15px !important;
}


.ad-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

.ad-thumb {
    width: 100% !important;
    height: 80px !important;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 5px !important;
    flex-shrink: 0;
}

.ad-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ad-details {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    min-width: 0 !important;
    flex-grow: 1;
    justify-content: space-between;
}

.ad-title {
    font-size: 13px;
    font-weight: bold;
    color: var(--dark-text);
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    margin-bottom: 2px;
    line-height: 1.2;
}

.ad-price {
    font-size: 12px;
    color: var(--primary-red);
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.ad-address {
    font-size: 9px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0;
}

.ad-category {
    display: none !important;
}

/* استایل اسکرول‌بار برای مرورگرهای Webkit (اختیاری) */
#ads-map-carousel-wrapper::-webkit-scrollbar {
    height: 8px;
}

#ads-map-carousel-wrapper::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

#ads-map-carousel-wrapper::-webkit-scrollbar-thumb {
    background-color: rgba(146, 0, 0, 0.6);
    border-radius: 4px;
}

/* --- Filter Popup Styles --- */
#toggle-filters-button {
    background: var(--primary-red) !important;
    color: var(--primary-white) !important;
    border: none;
    border-radius: 5px;
    padding: 8px 10px;
    font-family: Vazir, Tahoma, sans-serif;
    font-size: 15px;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    /* این margin-left: auto قبلاً روی این عنصر بود و باید به درستی کار کند */
    margin-left: auto !important; /* این را مجدداً با !important اعمال می کنیم */
    flex-shrink: 0;
}

#toggle-filters-button span.dashicons {
    margin: 0 !important;
    color: var(--primary-white) !important;
}

#toggle-filters-button:hover {
    background: var(--link-hover-color) !important;
    color: var(--primary-white) !important;
}

/* Dashicons for filter button */
#toggle-filters-button .dashicons {
    font-size: 20px;
    width: 20px;
    height: 20px;
    line-height: 1;
}

#ads-map-filters-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    z-index: 1001;
    padding: 60px 20px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    box-sizing: border-box;
    overflow-y: auto;
}

#ads-map-filters-popup.hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

#ads-map-filters-popup:not(.hidden) {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

#ads-map-filters-popup h3 {
    margin: 0 0 10px 0;
    color: var(--primary-red);
    font-size: 22px;
    text-align: center;
}

#ads-map-filters-content {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    flex-grow: 1;
    align-content: flex-start;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 200px;
    flex-grow: 1;
    max-width: 30%;
}

.filter-group label {
    font-size: 14px;
    color: var(--dark-text);
    font-weight: bold;
}

.map-filter-select {
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: var(--primary-white);
    color: var(--dark-text);
    font-family: Vazir, Tahoma, sans-serif;
    font-size: 15px;
    cursor: pointer;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2212%22%20height%3D%2212%22%20viewBox%3D%220%200%2012%2012%22%3E%3Cpath%20fill%3D%22%23333%22%20d%3D%22M6%209L0%203h12z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: left 10px center; /* for RTL */
    padding-left: 35px;
}

.map-filter-select:hover {
    border-color: var(--primary-red);
    box-shadow: 0 0 5px rgba(146, 0, 0, 0.2);
}

.map-filter-select:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 5px rgba(146, 0, 0, 0.4);
}

.map-filter-select:disabled {
    background-color: #f0f0f0;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Button group for apply/reset */
#ads-map-filters-popup .button-group {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.samtbazar-button {
    background: var(--primary-red);
    color: var(--primary-white);
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-family: Vazir, Tahoma, sans-serif;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    flex-grow: 1;
    max-width: 200px;
}

.samtbazar-button:hover {
    background: var(--link-hover-color);
    transform: translateY(-1px);
}

.samtbazar-button-secondary {
    background: #f0f0f0;
    color: var(--dark-text);
    border: 1px solid var(--border-color);
}

.samtbazar-button-secondary:hover {
    background: #e0e0e0;
    color: var(--dark-text);
}


/* --- Loading Overlay Styles --- */
#map-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1002;
    transition: opacity 0.3s ease;
}

#map-loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border-left-color: var(--primary-red);
    animation: spin 1s ease infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#map-loading-overlay span {
    color: var(--dark-text);
    font-size: 16px;
}


/* برای ریسپانسیو بودن */
@media (max-width: 768px) {
    #ads-map-carousel-container {
        max-height: 220px;
        padding: 5px 0;
    }
    #ads-map-carousel-wrapper {
        width: calc(100% - 30px);
        margin: 0 15px;
    }
    .carousel-shadow.left { left: 0; }
    .carousel-shadow.right { right: 0; }

    .ad-card {
        width: 200px !important;
        height: 160px !important;
        margin: 0 5px !important;
        padding: 8px !important;
    }
    .ad-thumb {
        height: 60px !important;
        margin-bottom: 5px !important;
    }
    .ad-title {
        font-size: 12px;
    }
    .ad-price {
        font-size: 11px;
    }
    .ad-address {
        font-size: 8px;
    }

    #ads-map-header {
        padding: 0 15px;
    }
    #toggle-filters-button {
        padding: 6px 8px;
        font-size: 14px;
    }
    #toggle-filters-button span.dashicons {
        font-size: 18px;
        width: 18px;
        height: 18px;
    }
    #ads-map-filters-popup {
        top: 0;
        bottom: 0;
        transform: translateY(-100%);
    }
    #ads-map-filters-popup.hidden {
        transform: translateY(-100%);
    }
    #ads-map-filters-popup h3 {
        font-size: 20px;
    }
    #ads-map-filters-content {
        flex-direction: column;
    }
    .filter-group {
        min-width: 100%;
        max-width: 100%;
    }
    .samtbazar-button {
        width: 100%;
        max-width: 100%;
    }
    #ads-map-filters-popup .button-group {
        flex-direction: column;
    }
}

#goftino_w {
    display: none !important;
}

a.scrollToTop {
    display: none !important;
}