/**
 * Play Page Styles
 */

/* Remove default page padding/margins */
body.page-template-template-play {
    margin: 0;
    padding: 0;
    overflow-x: hidden; /* Only hide horizontal scroll, allow header to show */
}

/* Map container starts below header */
#play-map-container {
    position: fixed;
    top: 70px; /* Space for header */
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: calc(100vh - 70px);
    z-index: 1; /* Lower than header so header stays on top */
}

/* Account for both admin bar and header */
body.page-template-template-play.admin-bar #play-map-container {
    top: 102px; /* 70px header + 32px admin bar */
    height: calc(100vh - 102px);
}

@media screen and (max-width: 782px) {
    /* Adjust for actual mobile header height */
    #play-map-container {
        top: 60px; /* Mobile header is shorter */
        height: calc(100vh - 60px);
    }

    body.page-template-template-play.admin-bar #play-map-container {
        top: 106px; /* 60px header + 46px mobile admin bar */
        height: calc(100vh - 106px);
    }
}

/* Map fills container */
#play-map {
    width: 100%;
    height: 100%;
}

/* Mapbox canvas */
#play-map .mapboxgl-canvas {
    outline: none;
}

/* Style Mapbox controls */
#play-map .mapboxgl-ctrl-group {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    border: none;
}

#play-map .mapboxgl-ctrl-group button {
    width: 36px;
    height: 36px;
    background-color: rgba(0, 0, 0, 0.05); /* Use hover color as base */
    color: #2a0845;
}

#play-map .mapboxgl-ctrl-group button:hover {
    background-color: rgba(0, 0, 0, 0.12);
}

#play-map .mapboxgl-ctrl button.mapboxgl-ctrl-icon {
    filter: invert(11%) sepia(20%) saturate(3964%) hue-rotate(259deg) brightness(87%) contrast(98%); /* Brand purple */
}

/* Keyboard controls hint */
.play-controls-hint {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    z-index: 10;
    backdrop-filter: blur(10px);
    opacity: 0.9;
}

.play-controls-hint h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 600;
}

.play-controls-hint ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.play-controls-hint li {
    margin: 4px 0;
    opacity: 0.9;
}

.play-controls-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    font-family: monospace;
    font-size: 11px;
    margin-right: 6px;
    min-width: 20px;
    text-align: center;
}

/* Mobile: hide keyboard hints */
@media screen and (max-width: 768px) {
    .play-controls-hint {
        display: none;
    }
}

/* Loading state */
#play-map-container.loading::before {
    content: 'Loading map...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 32px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

/* Fullscreen button styling */
.mapboxgl-ctrl-fullscreen {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3'/%3E%3C/svg%3E");
}

/* Smooth transitions */
#play-map,
#play-map .mapboxgl-canvas {
    transition: filter 0.3s ease;
}

/* ============================================
   Modal Styles
   ============================================ */

.listing-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
}

.listing-modal.is-open {
    display: block;
}

.listing-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    animation: fadeIn 0.3s ease;
    z-index: 10001;
}

.listing-modal-content {
    position: relative;
    width: 70%;
    max-width: 1200px;
    height: calc(100vh - 300px); /* 150px top + 150px bottom */
    margin: 150px auto 150px auto;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    animation: slideUp 0.3s ease;
    display: flex;
    flex-direction: column;
    z-index: 10001;
}

/* Account for WordPress admin bar when logged in */
body.admin-bar .listing-modal-content {
    margin-top: 182px; /* 150px + 32px admin bar */
    height: calc(100vh - 332px); /* Adjust height for admin bar */
}

.listing-modal-close {
    display: none;
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: #a6f208;
    color: #2a0845;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.listing-modal-close:hover {
    background: #2a0845;
    color: #a6f208;
}

.listing-modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.listing-modal-loading .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3B82F6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.listing-modal-loading p {
    margin-top: 20px;
    font-size: 16px;
    color: #666;
}

.listing-modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    background: white;
}

.listing-modal-body .listing-modal-iframe {
    flex: 1;
    width: 100%;
    border: none;
    display: none;
}

.listing-modal-body.is-loaded .listing-modal-iframe {
    display: block;
}

.listing-modal-back {
    display: none;
    align-self: flex-start;
    margin: 12px 12px 8px 12px;
    background: #2a0845;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
}

.listing-modal-back:hover {
    background: #3d0c63;
}

/* Mobile: show close button, hide back button */
@media (max-width: 768px) {
    .listing-modal-close {
        display: flex;
    }

    .listing-modal-back {
        display: none;
    }
}

/* Ensure Elementor content renders properly in modal */
.listing-modal-body .elementor {
    width: 100% !important;
}

.listing-modal-body .elementor-section {
    width: 100% !important;
    max-width: none !important;
}

.listing-modal-body .elementor-container {
    max-width: none !important;
}

.listing-modal-body .elementor-column-gap-default > .elementor-column > .elementor-element-populated {
    padding: 10px !important;
}

/* Fix Elementor widget spacing in modal */
.listing-modal-body .elementor-widget-wrap {
    width: 100% !important;
}

.listing-modal-body .elementor-section-boxed > .elementor-container {
    max-width: none !important;
}

/* Fix Elementor sections that might have fixed positioning */
.listing-modal-body .elementor-section {
    position: relative !important;
}

/* Ensure images scale properly */
.listing-modal-body img {
    max-width: 100%;
    height: auto;
}

/* Hide scripts, styles, admin bar, and header/footer elements */
.listing-modal-body > script,
.listing-modal-body > style,
.listing-modal-body > link,
.listing-modal-body #wpadminbar {
    display: none !important;
}

/* Hide header and footer containers */
.listing-modal-body [data-elementor-type="header"],
.listing-modal-body [data-elementor-type="footer"],
.listing-modal-body [data-elementor-location="header"],
.listing-modal-body [data-elementor-location="footer"],
.listing-modal-body .elementor-location-header,
.listing-modal-body .elementor-location-footer {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* Show only the main single post content */
.listing-modal-body [data-elementor-type="single"],
.listing-modal-body [data-elementor-type="single-post"],
.listing-modal-body [data-elementor-type="wp-post"],
.listing-modal-body .elementor-location-single {
    display: block !important;
    visibility: visible !important;
}

/* Ensure main content area is visible and full width */
.listing-modal-body main,
.listing-modal-body .site-content,
.listing-modal-body article,
.listing-modal-body .entry-content {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
}

.listing-modal-error {
    padding: 40px;
    text-align: center;
    color: #DC2626;
}

/* Modal Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ========================================
   Individual Listing Popup Styles
   ======================================== */

/* Override default Mapbox popup styles for individual listings */
.mapboxgl-popup-content {
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: 'Open Sans', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Close button — absolute, vertically aligned with first line of type label.
   Popup padding is 16px top; type label line-height is ~21px (16px * 1.3).
   Center the 24px button over that first line: 16px + (21px - 24px)/2 ≈ 14px. */
.mapboxgl-popup-close-button {
    position: absolute;
    top: 14px;
    right: 10px;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    line-height: 24px;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
}

.mapboxgl-popup-close-button:hover {
    background: #f3f4f6;
    color: #111827;
}

/* Shared popup container — beacon and POI */
.listing-popup,
.google-places-popup {
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    /* Equal left/right padding keeps content centred; close button is absolute so doesn't affect flow */
    padding: 16px 40px 16px 40px;
    min-width: 220px;
    max-width: 300px;
}

/* Beacon type icon */
.listing-popup-icon {
    display: block;
    width: 48px;
    height: 48px;
    object-fit: contain;
    margin-bottom: 10px;
}

/* Shared title style */
.listing-popup-title,
.google-places-popup-title {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 8px;
    line-height: 1.3;
}

/* Shared type label base */
.listing-popup-type,
.google-places-popup-type {
    font-family: 'Luckiest Guy', cursive;
    font-size: 16px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 6px;
    line-height: 1.3;
}

/* Purple for beacon popups */
.listing-popup--beacon .listing-popup-type {
    color: #2a0845;
}

/* Center all content inside beacon popups */
.listing-popup--beacon {
    text-align: center;
}

.listing-popup--beacon .listing-popup-icon {
    margin-left: auto;
    margin-right: auto;
}

/* Shared sub-text: author, address, phone */
.listing-popup-author,
.google-places-popup-address,
.google-places-popup-phone {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 4px;
    line-height: 1.4;
}

/* Shared button */
.listing-popup-btn {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background-color: #2a0845;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-align: center;
    margin-top: 12px;
    box-sizing: border-box;
}

.listing-popup-btn:hover {
    background-color: #3d0c63;
}

.listing-popup-btn:active {
    background-color: #1e0632;
}

/* ========================================
   Cluster List Popup Styles
   ======================================== */

/* Override default Mapbox popup styles */
.cluster-list-popup .mapboxgl-popup-content {
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: 'Open Sans', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
}

.cluster-list-popup .mapboxgl-popup-close-button {
    font-size: 18px;
    padding: 8px;
    color: #666;
}

.cluster-list-popup .mapboxgl-popup-close-button:hover {
    background-color: rgba(42, 8, 69, 0.1);
    color: #2a0845;
}

/* Popup container */
.cluster-popup {
    font-family: 'Open Sans', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Header showing count */
.cluster-popup-header {
    padding: 12px 16px;
    background-color: #2a0845;
    color: white;
    font-weight: 700;
    font-size: 14px;
    border-radius: 8px 8px 0 0;
}

/* Scrollable list container */
.cluster-popup-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 8px 0;
}

/* Individual listing item */
.cluster-popup-item {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.cluster-popup-item:last-child {
    border-bottom: none;
}

.cluster-popup-item:hover {
    background-color: #f9fafb;
}

/* Listing title */
.cluster-popup-item-title {
    font-weight: 700;
    font-size: 14px;
    color: #333333;
    margin-bottom: 4px;
}

/* Meta info (post type and author) */
.cluster-popup-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #666;
}

/* Post type badge */
.post-type-badge {
    background-color: rgba(42, 8, 69, 0.1);
    color: #2a0845;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
}

/* Author */
.post-author {
    color: #666;
}

/* Scrollbar styling */
.cluster-popup-list::-webkit-scrollbar {
    width: 6px;
}

.cluster-popup-list::-webkit-scrollbar-track {
    background: #f3f4f6;
}

.cluster-popup-list::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.cluster-popup-list::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .cluster-list-popup .mapboxgl-popup-content {
        max-width: 280px !important;
    }

    .cluster-popup-list {
        max-height: 200px;
    }

    .cluster-popup-item-title {
        font-size: 13px;
    }
}

/* Mobile modal styles */
@media (max-width: 768px) {
    .listing-modal-content {
        width: calc(100% - 20px);
        height: calc(100vh - 250px); /* 150px top + 100px bottom */
        margin: 150px 10px 100px 10px; /* 150px top, 10px sides, 100px bottom */
        border-radius: 12px;
        max-width: none;
    }

    .listing-modal-close {
        top: 15px;
        right: 15px;
        z-index: 10002; /* Ensure it's above modal content */
    }
}

/* Disable body scroll when modal is open */
body.modal-open {
    overflow: hidden;
}

/* Prevent underlying map/header/UI from stealing clicks when modal is open */
body.modal-open #play-map-container,
body.modal-open #play-map,
body.modal-open .mapboxgl-ctrl,
body.modal-open header,
body.modal-open .site-header {
    pointer-events: none !important;
    z-index: auto !important;
}

body.modal-open .listing-modal,
body.modal-open .listing-modal * {
    pointer-events: auto;
}

/* ===================================
   Day 1: Mobile Touch Optimizations
   =================================== */

/* Ensure minimum 44px touch targets for iOS */
@media (max-width: 768px) {
    /* Larger touch targets for map controls */
    #play-map .mapboxgl-ctrl-group button {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Larger geolocate button */
    #play-map .mapboxgl-ctrl-geolocate {
        width: 44px;
        height: 44px;
    }

    /* Larger close buttons */
    .listing-modal-close {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Close button — adequate touch target without the huge circle */
    .mapboxgl-popup-close-button {
        min-width: 32px;
        min-height: 32px;
    }

    /* Larger view button in popup */
    .listing-popup-btn {
        min-height: 44px;
        padding: 12px 24px;
    }

    /* Larger cluster popup items */
    .cluster-popup-item {
        min-height: 44px;
        padding: 14px 16px;
    }

    /* Improve touch feedback */
    .cluster-popup-item:active,
    .listing-popup-btn:active,
    #play-map .mapboxgl-ctrl-group button:active {
        opacity: 0.7;
        transform: scale(0.98);
    }

    /* Prevent text selection on touch */
    .cluster-popup-item,
    .listing-popup-btn,
    #play-map .mapboxgl-ctrl-group button {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Smooth scrolling for mobile */
    .cluster-popup-list {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Hide keyboard controls hint on mobile */
    .play-controls-hint {
        display: none;
    }
}

/* iOS specific optimizations */
@supports (-webkit-touch-callout: none) {
    /* Prevent callout on long press */
    #play-map,
    .mapboxgl-canvas,
    .cluster-popup-item,
    .listing-popup-btn {
        -webkit-touch-callout: none;
    }

    /* Smooth momentum scrolling */
    .cluster-popup-list,
    .listing-modal-body {
        -webkit-overflow-scrolling: touch;
    }
}

/* Android Chrome optimizations */
@media (max-width: 768px) and (hover: none) {
    /* Remove hover states on touch devices */
    .cluster-popup-item:hover,
    .listing-popup-btn:hover,
    #play-map .mapboxgl-ctrl-group button:hover {
        background-color: inherit;
    }

    /* Use active states instead */
    .cluster-popup-item:active {
        background-color: #f3f4f6;
    }

    .listing-popup-btn:active {
        background-color: #1e0632;
    }

    #play-map .mapboxgl-ctrl-group button:active {
        background-color: rgba(0, 0, 0, 0.15);
    }
}

/* ========================================
   Day 3: Google Places Popup
   ======================================== */

/* Google Places Popup — type color (green) */
.google-places-popup-type {
    color: #7ab800;
}

.google-places-popup-actions {
    display: flex;
    gap: 8px;
}

/* ========================================
   Geocoder / Search Box Fixes
   ======================================== */

/* Ensure the entire control height is the clickable input area.
   The default geocoder CSS can create a gap between the visible
   input border and the actual pointer-events region on some screen sizes. */
.mapboxgl-ctrl-geocoder {
    box-sizing: border-box;
}

.mapboxgl-ctrl-geocoder input[type='text'] {
    /* Explicit height + line-height ensures the click target matches
       the visible input box exactly across all zoom levels */
    height: 40px;
    line-height: 40px;
    padding-top: 0;
    padding-bottom: 0;
    box-sizing: border-box;
    cursor: text;
}

/* Make the search icon part of the click target (it sits inside the input) */
.mapboxgl-ctrl-geocoder .mapboxgl-ctrl-geocoder--icon-search {
    pointer-events: none;
    top: 50%;
    transform: translateY(-50%);
}


