.listing-not-found {
    padding-left: 20px;
}
.listing-view {
    padding: 0 20px;
}

/* Container for images and map side by side */
.listing-top-container {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    height: 350px; /* Fix total row height */
}

/* Desktop layout using CSS Grid */
.listing-images-container {
    display: grid;
    grid-template-columns: 70% 30%;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "title badges"
        "images images";
    gap: 15px;
}

.listing-title-container {
    grid-area: title;
    padding-bottom: 10px;
}

.listing-badges-container {
    grid-area: badges;
    display: flex;
    justify-content: flex-end;
    padding-bottom: 10px;
    padding-right: 15px;
}

.listing-images-wrapper {
    grid-area: images;
    height: 100%;
    padding-right: 15px;
    max-height: 265px;
}

.listing-title {
    font-size: 21px;
    color: var(--color-primary);
    font-family: var(--font-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.listing-images-container {
    border-radius: 8px;
    padding: 15px;
    background-color: #f9f9f9;
    box-sizing: border-box; /* Include padding in width/height */
    flex: 0 0 calc(70% - 7.5px); /* 70% minus half the gap so total with gap is 100% */
    height: 350px; /* Fixed height */
    overflow: hidden; /* Hide overflow */
    /* Grid layout is defined in the Desktop layout section */
}

.listing-images {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden; /* Hide vertical scrollbar */
    gap: 15px;
    scroll-behavior: smooth;
    border: none; /* Ensure no border */
    flex: 1 1 auto; /* Fill remaining height under the title within 270px container */
    min-height: 0; /* Allow flex child to shrink */
    position: relative; /* Add position relative for absolute positioning of scrollbar */
    scrollbar-width: auto; /* Firefox - changed from thin to auto for larger scrollbar */
    scrollbar-color: #fff transparent; /* Firefox - white scrollbar with transparent track */
    height: 100%; /* Ensure it takes up the full height of its parent container */
}

/* Webkit scrollbar styling */
.listing-images::-webkit-scrollbar {
    height: 12px; /* Increased from 8px to 12px for larger scrollbar */
    position: absolute; /* Position the scrollbar absolutely */
    bottom: 0; /* Align to bottom */
    width: 100%; /* Full width */
    z-index: 10; /* Ensure scrollbar appears above images */
}

.listing-images::-webkit-scrollbar-track {
    border-radius: 4px;
    background-color: transparent; /* Transparent track */
}

.listing-images::-webkit-scrollbar-thumb {
    background-color: var(--color-dark); /* Dark scrollbar thumb for Chrome */
    border-radius: 4px;
}

.listing-image, .listing-thumbnail-image {
    flex: 0 0 auto;
    width: 380px;
    height: 100%; /* Fill the entire available height */
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.listing-image:hover, .listing-thumbnail-image:hover {
    transform: scale(1.02);
    cursor: pointer;
}

/* Desktop view: Show all images in a horizontal row */
@media (min-width: 769px) {
    /* Show all images in desktop view */
    .hidden-image {
        display: block;
    }

    /* Make sure main image is visible and properly sized in desktop view */
    .main-image {
        width: 380px;
        height: 100%;
    }

    /* Display thumbnail images in desktop view */
    .listing-thumbnail-images {
        display: flex;
        flex-direction: row;
        gap: 15px;
    }

    /* Style thumbnail images in desktop view */
    .listing-thumbnail {
        height: 100%;
    }

    .listing-thumbnail-image {
        width: 380px;
        height: 100%;
    }
}

.no-images {
    padding: 30px;
    text-align: center;
    color: #777;
    font-style: italic;
    width: 100%;
}

.listing-info-container {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    margin-top: 20px;
    flex-wrap: nowrap;
    width: 100%;
    box-sizing: border-box;
}

.listing-creator-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background-color: #f8f8f8;
    border-radius: 8px;
    font-family: var(--font-primary);
    color: var(--color-dark);
    font-size: 15px;
    flex: 0 0 calc(70% - 7.5px);
    box-sizing: border-box;
}

.listing-date-panel {
    padding: 10px;
    background-color: #f8f8f8;
    border-radius: 8px;
    font-family: var(--font-primary);
    color: var(--color-dark);
    font-size: 15px;
    text-align: center;
    flex: 0 0 calc(15% - 11.25px);
    box-sizing: border-box;
}

.listing-date-panel h4 {
    color: var(--color-dark);
    margin: 0 0 5px 0;
    font-size: 14px;
}

.listing-date-panel p {
    margin: 0;
    font-size: 13px;
}

.listing-owner-info {
    color: var(--color-darker);
    display: flex;
    align-items: center;
    flex-grow: 1;
}

.listing-owner-info img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    margin-right: 10px;
    object-fit: cover;
}

.listing-description {
    padding: 15px;
    background-color: #f8f8f8;
    border-radius: 8px;
}

.listing-top-details {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 15px;
}

.listing-top-detail {
    flex: 1;
    text-align: center;
}

.listing-description-text {
    margin-bottom: 20px;
    padding-bottom: 15px;
    font-size: 14px;
}

.listing-cost {
    padding-top: 10px;
}

.listing-date-panel h4,
.listing-description h4,
.listing-description-text h4,
.listing-cost h4 {
    color: var(--color-darker);
    margin: 0 0 5px 0;
    font-size: 16px;
}

.listing-top-detail h4 {
    color: var(--color-darker);
    margin: 0 0 5px 0;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    display: block;
}

.listing-date-panel p,
.listing-description p,
.listing-top-detail p,
.listing-cost p {
    color: var(--color-dark);
    margin: 0;
    font-size: 14px;
}

/* Listing details have been integrated into the description panel */

.listing-badges {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}

.listing-badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    color: white;
    user-select: none;
}

.listing-badges .listing-badge {
    line-height: 15px;
}

/* Toggle icon in clickable badges */
.toggle-icon {
    display: inline-block;
    margin-right: 4px;
    font-size: 12px;
    margin-top: -1px;
}

/* Clickable badge styles */
.listing-badge.clickable {
    cursor: pointer;
}

/* Lightbox overlay */
.lightbox {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    justify-content: center;
    align-items: center;
}

.lightbox-content {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 90%;
    max-height: 80%;
}

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

.lightbox .nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background-color: rgba(0,0,0,0.5);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: white;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
    z-index: 10000;
}

.lightbox .nav:hover {
    background-color: rgba(0,0,0,0.8);
}

.lightbox .prev {
    left: 20px;
}

.lightbox .next {
    right: 20px;
}

/* Map styles */
.listing-map-container {
    border-radius: 8px;
    background-color: #f9f9f9;
    box-sizing: border-box; /* Include padding/border in width/height */
    flex: 0 0 calc(30% - 7.5px); /* 30% minus half the gap so total with gap is 100% */
    height: 350px; /* Match row height */
    padding: 15px;
}

.listing-map-container h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--color-primary);
    font-family: var(--font-primary);
}

#province-map-container {
    width: 100%;
    height: 100%;
    border: 1px solid #ccc;
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    box-sizing: border-box;
}

#province-map-display {
    width: 100%;
    height: 200px;
    position: relative;
    background-color: var(--color-primary);
    box-sizing: border-box;
    aspect-ratio: auto; /* Disable fixed aspect ratio; we fix height instead */
}

/* Leaflet specific overrides */
.leaflet-container {
    font-family: var(--font-primary), serif !important;
}

/* Leaflet image protection to prevent global CSS from stretching tiles/overlays */
.leaflet-container img {
    max-width: none !important;
}

/* Styles for the edit and delete buttons container */
.listing-actions-container {
    display: flex;
    justify-content: flex-end;
    margin-top: 15px;
    padding: 0 20px;
}

.listing-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.listing-actions .btn {
    font-family: var(--font-primary);
}

.listing-actions .btn-primary {
    border: 1px solid var(--color-white);
}

.no-underline {
    text-decoration: none;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
}

.modal-content h3 {
    color: var(--color-darker);
    margin-top: 0;
}

.modal-content p {
    color: var(--color-dark);
    font-size: 14px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* Favorite heart icon styles */
.favorite-heart {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.favorite-heart:hover {
    transform: scale(1.1);
}

.favorite-heart .heart-icon {
    width: 24px;
    height: 24px;
}

.favorite-heart.is-favorite .heart-icon {
    filter: none;
}

.favorite-heart:not(.is-favorite) .heart-icon {
    filter: grayscale(0);
}

/* Animation for heart icon when toggled */
@keyframes heartPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.favorite-heart.toggling .heart-icon {
    animation: heartPulse 0.5s ease;
}

.btn-contact {
    display: flex;
    align-items: center;
}

.btn-contact img {
    margin: 1px 0;
    width: 20px;
    height: 15px;
    margin-right: 15px;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    /* Adjust listing view padding */
    .listing-view {
        padding: 13px 15px;
    }

    /* Adjust listing actions container for mobile */
    .listing-actions-container {
        margin-top: 0;
        margin-bottom: 15px;
        padding: 0px 14px;
    }

    /* Stack images and map vertically */
    .listing-top-container {
        flex-direction: column;
        height: auto;
        margin-bottom: 15px;
    }

    .listing-images-container {
        flex: 0 0 100%;
        width: 100%;
        height: 300px;
        /* Change to grid layout for mobile with different areas */
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        grid-template-areas:
            "title"
            "images"
            "badges";
        gap: 10px;
        padding: 11px;
        box-sizing: border-box;
        max-width: 100%;
        overflow: hidden;
    }

    /* Mobile layout for title, images, and badges */
    .listing-images-container .listing-title-container {
        grid-area: title;
        width: 100%;
        margin-bottom: 5px;
        padding-bottom: 0;
        box-sizing: border-box;
        max-width: 100%;
        overflow: hidden;
    }

    .listing-images-container .listing-title {
        max-width: 100%;
        font-size: 16px;
    }

    .listing-images-container .listing-images-wrapper {
        grid-area: images;
        width: 100%;
        height: auto;
        box-sizing: border-box;
        max-width: 100%;
        overflow: hidden;
        padding-right: 0; /* Override desktop padding */
    }

    .listing-images-container .listing-images {
        display: flex;
        flex-wrap: wrap;
        gap: 1px;
        height: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    .listing-images-container .listing-badges-container {
        grid-area: badges;
        width: 100%;
        padding: 0;
        margin: 0;
        box-sizing: border-box;
        max-width: 100%;
        overflow: hidden;
    }

    .listing-images-container .listing-badges {
        width: 100%;
        justify-content: flex-start;
        box-sizing: border-box;
        max-width: 100%;
        overflow: hidden;
    }

    /* Make badges smaller in mobile view */
    .listing-images-container .listing-badge {
        font-size: 14px;
        box-sizing: border-box;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Mobile image layout similar to browse-listings */
    .listing-images-container .listing-images {
        display: flex;
        flex-direction: row;
        height: 200px;
        width: 100%;
        overflow-x: hidden;
    }

    /* Main image styles */
    .listing-images-container .main-image {
        flex: 2;
        max-width: 65%;
        height: 100%;
        border-radius: 0; /* Reset border-radius, we'll apply specific ones based on image count */
        object-fit: cover;
        margin-right: 1px;
    }

    /* Single image: all 4 corners have border-radius */
    .listing-images-container .listing-images.single-image .main-image {
        border-radius: 5px;
        max-width: 100%;
        margin-right: 0;
    }

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

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

    /* When there's only one image, make it take full width */
    .listing-images-container .main-image:only-child {
        max-width: 100%;
        margin-right: 0;
    }

    /* Thumbnail container styles */
    .listing-images-container .listing-thumbnail-images {
        flex: 1;
        display: flex;
        flex-direction: column;
        max-width: 35%;
        gap: 1px;
    }

    /* Individual thumbnail styles */
    .listing-images-container .listing-thumbnail {
        flex: 1;
        overflow: hidden;
        border-left: none;
        height: calc(50% - 1px);
    }

    .listing-images-container .listing-thumbnail-image {
        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 */
    .listing-images-container .listing-images.two-images .listing-thumbnail.single-thumbnail .listing-thumbnail-image {
        border-radius: 0 5px 5px 0;
    }

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

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

    /* Hide images beyond the 3rd one */
    .listing-images-container .hidden-image {
        display: none;
    }

    .listing-map-container {
        flex: 0 0 100%;
        width: 100%;
        height: 200px;
        margin-top: 0;
        padding: 10px;
    }

    #province-map-container {
        height: 200px;
    }

    /* Reorganize creator and date panels */
    .listing-info-container {
        flex-direction: column;
        gap: 15px;
        margin-top: 0;
        margin-bottom: 15px;
    }

    .listing-creator-panel {
        padding: 10px;
        flex: 0 0 100%;
        width: 100%;
    }

    /* Hide "Send a raven" text on mobile, show only the icon */
    .btn-contact span {
        display: none;
    }

    /* Single date panel showing only creation date */
    .listing-info-container .listing-date-panel {
        flex: 0 0 100%;
        width: 100%;
        text-align: center;
        padding: 15px;
        display: flex;
        flex-direction: column;
        justify-content: center; /* Center content vertically */
    }

    /* Hide the second date panel */
    .listing-info-container .listing-date-panel + .listing-date-panel {
        display: none;
    }

    /* Style the date sections */
    .listing-info-container .listing-date-panel h4 {
        display: block;
        margin-bottom: 5px;
        font-size: 14px;
    }

    .listing-info-container .listing-date-panel p {
        display: block;
        font-size: 14px;
        margin: 0; /* Ensure no extra margin */
    }

    /* Remove "Posted by" text in creator panel */
    .listing-owner-info span {
        font-size: 0; /* Hide all text */
    }

    .listing-owner-info span strong {
        font-size: 15px; /* Show only the name */
        display: inline-block; /* Ensure it's visible */
    }

    /* Reorganize listing top details */
    .listing-top-details {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        border-bottom: none;
        position: relative;
        padding-bottom: 0;
        margin-bottom: 10px;
    }

    /* First row: Shard, Province, and Valley (was Home valley) */
    .listing-top-details .listing-top-detail:nth-child(1),
    .listing-top-details .listing-top-detail:nth-child(2),
    .listing-top-details .listing-top-detail:nth-child(3) {
        flex: 1 1 30%;
        order: 1;
    }

    /* Add separator after first row */
    .listing-top-details::after {
        content: "";
        display: block;
        width: 100%;
        height: 1px;
        background-color: #e0e0e0;
        order: 2;
        margin: 10px 0;
    }

    /* Second row: Cost and Storage slots */
    .listing-top-details .listing-top-detail:nth-child(4),
    .listing-top-details .listing-top-detail:nth-child(5) {
        flex: 1 1 45%;
        order: 3;
    }

    /* Add separator after second row (only for non-POI listings) */
    .listing-top-details::before {
        content: "";
        display: block;
        width: 100%;
        height: 1px;
        background-color: #e0e0e0;
        order: 4;
        margin: 10px 0;
    }

    /* Hide the second separator for POI listings */
    .listing-top-details.poi-listing::before {
        display: none;
    }
    .btn-contact img {
        margin: 0;
        margin-right: 0;
    }
}
