/* Ensure no horizontal scrollbar on html and body when viewing map */
html, body.view-map {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
    /* Allow vertical scrolling if needed */
    overflow-y: auto;
}

/* View Map Button Container */
.view-map-button-container {
    display: flex;
    justify-content: flex-end;
    margin-top: -20px;
    margin-bottom: 20px;
}

#shardSelector, #provinceSelector, #valleySelector, #storageSelector {
    position: absolute;
    z-index: 100;
}
/* View Map Page Styles */
.view-map-container {
    width: 100%;
    height: 100%;
    min-height: 600px; /* Ensure minimum height for the container */
    margin: 0 auto;
    padding: 0;
    display: flex; /* Use flexbox to ensure child elements expand properly */
    flex-direction: column; /* Stack children vertically */
}

.view-map-container h2 {
    margin: 0 auto;
    padding-bottom: 20px;
}

/* Selectors panel */
.selectors-panel {
    position: absolute; /* Position absolutely over the map */
    top: 10px; /* Position from the top */
    left: 10px; /* Position from the left */
    z-index: 1000; /* Ensure it's above the map */
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    display: flex;
    padding: 8px;
    width: auto; /* Only as wide as needed */
    font-size: 14px;
    border: 1px solid var(--color-primary-hover);
    transition: transform 0.3s ease; /* Smooth transition for collapsing/expanding */
}

/* Desktop toggle button */
.desktop-toggle-button {
    display: none; /* Hidden by default, shown only on desktop */
    position: relative;
    width: 24px;
    height: 24px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s ease;
    margin-left: 10px; /* Add margin between category selector and toggle button */
}

.desktop-toggle-button:hover {
    opacity: 0.8;
}

.toggle-icon {
    stroke: var(--color-primary);
    display: block;
}

/* Collapsed state for selectors panel */
.selectors-panel.collapsed {
    transform: translateX(calc(-100% + 30px)); /* Leave space for the toggle button */
    box-shadow: none;
    min-width: 18px;
    min-height: 13px;
    margin-left: 6px;
}

/* Hide location selectors when panel is collapsed */
.selectors-panel.collapsed .location-selector {
    display: none;
}

/* When collapsed, rotate the toggle button icon */
.selectors-panel.collapsed .desktop-toggle-button .toggle-icon {
    transform: rotate(180deg); /* Rotate the icon to point right */
}

/* Ensure the toggle button is visible in the collapsed panel */
.selectors-panel.collapsed .desktop-toggle-button {
    position: absolute;
    right: 3px;
    top: 3px;
}

/* Desktop-only styles */
@media (min-width: 769px) {
    .desktop-toggle-button {
        display: flex; /* Show on desktop */
    }
}

/* Selector styles (shared between province and shard) */
.location-selector {
    width: 150px;
}

/* Selector styles (shared between province and shard) */
.location-selector select {
    font-size: 14px;
}

/* Selector styles (shared between province, shard, and category) */
.shard-selector {
    margin-right: 10px;
}

.province-selector {
    margin-right: 10px;
}

.category-selector {
    margin-right: 0;
}

.province-selector label, .shard-selector label, .category-selector label {
    font-weight: bold;
    display: block;
    margin-bottom: 3px;
}

.province-selector select, .shard-selector select, .category-selector select {
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #ccc;
    width: 100%;
}

/* Font size for select options */
.location-selector select option {
    font-size: 13px;
}

/* Spinner for AJAX loading */
.spinner {
    display: inline-block;
    width: 7px;
    height: 7px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spinner 0.8s linear infinite;
    margin-left: 5px;
    vertical-align: middle;
    margin-top: -3px;
}

@keyframes spinner {
    to {transform: rotate(360deg);}
}

/* Map container styles */
.map-container {
    position: relative;
    width: 100%;
    height: 100vh; /* Take full viewport height */
    min-height: 600px; /* Ensure minimum height even if parent container is not sized properly */
    margin: 0;
    border-radius: 0; /* Remove border radius for full-screen effect */
    box-shadow: none; /* Remove shadow for full-screen effect */
    flex-grow: 1; /* Allow the map container to grow and fill available space */
}

#leaflet-map {
    width: 100%;
    height: 100%;
    min-height: 500px; /* Ensure minimum height even if container is not sized properly */
    z-index: 1;
    /* Allow overflow for map rendering */
    overflow: visible !important;
}

.leaflet-fade-anim .leaflet-popup,
.leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
    transition: none !important;
    opacity: 1 !important;
}

.leaflet-fade-anim .leaflet-popup.leaflet-popup-closing {
    opacity: 0 !important;
    display: none !important;
    transition: none !important;
}

/* Leaflet specific overrides */
.leaflet-container {
    font-family: var(--font-primary), serif !important;
    background: transparent !important;
    /* Allow overflow for map rendering but prevent scrollbars */
    overflow: visible !important;
}

/* Additional Leaflet control container overrides */
.leaflet-control-container {
    /* Allow overflow for controls but prevent scrollbars */
    overflow: visible !important;
}

/* Additional Leaflet container overrides to prevent scrollbars */
.leaflet-pane,
.leaflet-map-pane,
.leaflet-overlay-pane,
.leaflet-marker-pane,
.leaflet-popup-pane,
.leaflet-tooltip-pane {
    /* Allow overflow for map elements but prevent scrollbars */
    overflow: visible !important;
}

/* Leaflet marker styles */
.leaflet-marker-icon {
    cursor: pointer;
}

/* ===== POPUP STYLES ===== */
/* Base popup container */
.leaflet-popup {
    position: absolute;
    z-index: 1000;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Popup content wrapper */
.leaflet-popup-content-wrapper {
    background-color: white;
    border-radius: 4px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    overflow: visible;
    padding: 0;
    width: 340px;
}

/* Popup content */
.leaflet-popup-content {
    margin: 0 !important;
    padding: 0;
    width: 340px !important;
    height: 265px;
    overflow: visible;
}

/* Popup tip container and tip */
.leaflet-popup-tip-container {
    width: 40px;
    height: 20px;
    position: absolute;
    left: 50%;
    margin-left: -20px;
    overflow: hidden;
    pointer-events: none;
}

.leaflet-popup-tip {
    background-color: white;
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2);
    width: 17px;
    height: 17px;
    padding: 1px;
    margin: -10px auto 0;
    transform: rotate(45deg);
}

/* ===== LISTING CARD STYLES ===== */
/* Listing popup container */
.listing-popup-leaflet {
    width: 340px;
}

/* Listing card link */
.map-listing-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
    width: 100%;
}

/* Main listing card */
.map-listing-card {
    width: 100%;
    background-color: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 0 0 0 #000000, 0 1px 12px rgba(0, 0, 0, 1);
}

/* Gold highlight for plot_sale listings without changing layout size */
.map-listing-card.plot-sale-highlight {
    /* Use inset box-shadow to simulate a border that does not affect element size */
    box-shadow: inset 0 0 0 0 #d4af37, 0 1px 12px rgba(0, 0, 0, 1);
}

/* Card title */
.map-listing-card-title {
    color: black;
    font-size: 15px;
    font-weight: normal;
    padding: 7px 7px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    max-width: 340px; /* Ensure title doesn't exceed popup width */
    box-sizing: border-box;
    display: block;
}

/* Images container */
.map-listing-card-images-container {
    height: 160px;
    display: flex;
    width: 326px;
    margin-left: 7px;
    gap: 2px;
}

/* Main image */
.map-listing-card-main-image {
    flex: 2;
    overflow: hidden;
}

/* When there's only one image, make the main image take full width */
.map-listing-card-images-container.single-image .map-listing-card-main-image {
    flex: 1;
    width: 100%;
}

/* Hide thumbnail container when there's only one image */
.map-listing-card-images-container.single-image .map-listing-card-thumbnail-images {
    display: none;
}

.map-listing-card-main-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0; /* Reset border-radius, we'll apply specific ones based on image count */
}

/* Single image: all 4 corners have border-radius */
.map-listing-card-images-container.single-image .map-listing-card-main-image img {
    border-radius: 5px;
}

/* Two images: left image has radius on left corners */
.map-listing-card-images-container.two-images .map-listing-card-main-image img {
    border-radius: 5px 0 0 5px;
}

/* Three images: left image has radius on left corners */
.map-listing-card-images-container.three-images .map-listing-card-main-image img {
    border-radius: 5px 0 0 5px;
}

/* Thumbnail images */
.map-listing-card-thumbnail-images {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.map-listing-card-thumbnail {
    flex: 1;
    overflow: hidden;
}

.map-listing-card-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0; /* Reset border-radius, we'll apply specific ones based on image count */
}

/* Two images: right image has radius on right corners */
.map-listing-card-images-container.two-images .map-listing-card-thumbnail.single-thumbnail img {
    border-radius: 0 5px 5px 0;
}

/* Three images: top thumbnail has radius on top-right corner only */
.map-listing-card-images-container.three-images .map-listing-card-thumbnail.first-thumbnail img {
    border-radius: 0 5px 0 0;
}

/* Three images: bottom thumbnail has radius on bottom-right corner only */
.map-listing-card-images-container.three-images .map-listing-card-thumbnail.second-thumbnail img {
    border-radius: 0 0 5px 0;
}

/* Card info section */
.map-listing-card-info {
    padding: 9px 7px;
}

/* Owner info */
.map-listing-card-owner-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    margin-bottom: 5px;
}

.owner-info {
    display: flex;
    align-items: center;
}

.owner-info img.small-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-right: 8px;
    border: 1px solid #eee;
}

.owner-name {
    color: #333;
}

.location-info {
    color: #666;
}

/* Badges container */
.map-listing-card-badges-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
}

.map-listing-card-badges {
    display: flex;
    gap: 8px;
}

/* Badge styles */
.map-listing-card-badge {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    display: inline-block;
    font-weight: 500;
    color: white;
}

/* Storage and Cost info */
.map-listing-card-storage {
    font-size: 13px;
    color: var(--color-dark);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
}

.map-listing-card-cost {
    font-size: 13px;
    color: var(--color-dark);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    max-width: 40%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: normal;
}

.storage-label {
    font-size: 13px;
    color: var(--color-dark);
}

.storage-value, .cost-value {
    color: var(--color-darker);
}

/* Responsive adjustments */
@media (max-width: 1318px) {
    /* Prevent horizontal scrollbar in map container below 1318px */
    .map-container {
        /*overflow: hidden !important; !* Prevent all overflow *!*/
    }

    /* Additional overflow handling for all map-related elements */
    #leaflet-map,
    .leaflet-container,
    .leaflet-pane,
    .leaflet-map-pane {
        /* Allow overflow for map elements */
        overflow: visible;
    }

    .view-map-container,
    main.view-map {
        overflow-x: hidden; /* Prevent horizontal scrollbar */
    }

    /* Prevent horizontal scrollbars on body and html when viewing map */
    body.view-map,
    html {
        overflow-x: hidden;
        width: 100%;
        max-width: 100%;
    }
}

/* Mobile search icon styles */
.mobile-search-icon {
    display: none; /* Hidden by default, shown only on mobile */
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1001; /* Higher than selectors-panel */
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    padding: 8px;
    cursor: pointer;
    border: 1px solid var(--color-primary-hover);
}

.mobile-search-icon svg {
    display: block;
    width: 24px;
    height: 24px;
    stroke: black;
}

@media (max-width: 768px) {
    .view-map-container {
        min-height: 500px; /* Smaller minimum height on mobile */
    }

    /* Mobile popup styles */
    .leaflet-popup-content-wrapper {
        width: 220px;
        height: 210px;
    }

    .leaflet-popup-content {
        width: 220px !important;
    }

    .listing-popup-leaflet {
        width: 290px;
    }

    /* Show mobile search icon and hide selectors panel by default on mobile */
    .mobile-search-icon {
        display: block;
    }

    .selectors-panel {
        display: none; /* Hidden by default on mobile */
        position: absolute;
        top: 10px;
        left: 50px; /* Position to the right of the search icon */
        width: calc(100% - 60px); /* Full width minus padding and icon width */
        max-width: 400px; /* Maximum width to prevent it from being too wide */
        flex-direction: column; /* Stack selectors vertically on mobile */
        z-index: 1000;
        background-color: white;
        border-radius: 5px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        padding: 8px;
        margin-left: 2px;
        border: 1px solid var(--color-primary-hover);
    }

    /* Show selectors panel when it has the 'open' class */
    .selectors-panel.open {
        width: 76%;
        display: flex;
    }

    .province-selector, .shard-selector, .category-selector {
        width: 100%;
        margin-right: 0;
        margin-bottom: 13px; /* Add space between stacked selectors */
    }

    .category-selector {
        margin-bottom: 0; /* Remove margin from the last selector */
    }

    .province-selector select, .shard-selector select, .category-selector select {
        width: 100%;
        padding: 10px;
    }

    /* Mobile listing card styles */
    .map-listing-card-title {
        font-size: 12px;
        padding: 6px 5px;
        max-width: 220px;
        box-sizing: border-box;
        display: block;
    }

    .map-listing-card-images-container {
        height: 120px; /* Smaller images on mobile */
        width: 206px;
        display: flex;
        flex-direction: row;
    }

    .map-listing-card-main-image {
        height: 120px;
        flex: 2;
        max-width: 65%;
    }

    /* When there's only one image, make it take full width */
    .map-listing-card-images-container.single-image .map-listing-card-main-image {
        flex: 1;
        max-width: 100%;
    }

    /* Hide thumbnail container when there's only one image */
    .map-listing-card-images-container.single-image .map-listing-card-thumbnail-images {
        display: none;
    }

    .map-listing-card-thumbnail-images {
        flex: 1;
        display: flex;
        flex-direction: column;
        max-width: 35%;
        gap: 2px;
    }

    .map-listing-card-thumbnail {
        flex: 1;
        overflow: hidden;
        height: calc(50% - 1px);
    }

    /* Mobile border-radius rules for main image */
    /* Single image: all 4 corners have border-radius */
    .map-listing-card-images-container.single-image .map-listing-card-main-image img {
        border-radius: 5px;
    }

    /* Two images: left image has radius on left corners */
    .map-listing-card-images-container.two-images .map-listing-card-main-image img {
        border-radius: 5px 0 0 5px;
    }

    /* Three images: left image has radius on left corners */
    .map-listing-card-images-container.three-images .map-listing-card-main-image img {
        border-radius: 5px 0 0 5px;
    }

    /* Mobile border-radius rules for thumbnail images */
    .map-listing-card-thumbnail img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 0; /* Reset border-radius, we'll apply specific ones based on image count */
    }

    /* Two images: right image has radius on right corners */
    .map-listing-card-images-container.two-images .map-listing-card-thumbnail.single-thumbnail img {
        border-radius: 0 5px 5px 0;
    }

    /* Three images: top thumbnail has radius on top-right corner only */
    .map-listing-card-images-container.three-images .map-listing-card-thumbnail.first-thumbnail img {
        border-radius: 0 5px 0 0;
    }

    /* Three images: bottom thumbnail has radius on bottom-right corner only */
    .map-listing-card-images-container.three-images .map-listing-card-thumbnail.second-thumbnail img {
        border-radius: 0 0 5px 0;
    }

    .map-container {
        height: 100vh; /* Keep full viewport height on mobile */
        min-height: 500px; /* Slightly larger minimum height on mobile */
    }

    .map-listing-card-info {
        padding: 9px 7px;
    }

    .map-listing-card-owner-info {
        margin-bottom: 5px;
        font-size: 11px;
    }

    .map-listing-card-cost {
        font-size: 11px;
    }

    .owner-info img.small-avatar {
        width: 17px;
        height: 17px;
        margin-right: 6px;
    }

    .map-listing-card-badge {
        font-size: 11px;
        padding: 3px 8px;
    }

    .map-listing-card-storage .storage-label {
        font-size: 11px;
    }

    .map-listing-card-storage .storage-value {
        font-size: 11px;
    }
}
