/**
 * GeoJSON Map Manager - Frontend Styles
 * Version: 1.5.0
 * Description: Static CSS for mobile-friendly map with side panel
 *
 * Note: Dynamic values (colors, heights) are set via CSS custom properties
 * that are injected inline by JavaScript.
 */

/* CSS Custom Properties with defaults (overridden by inline styles) */
:root {
    --geojson-map-height-desktop: 70vh;
    --geojson-map-height-mobile: 60vh;
    --geojson-panel-header-bg: #3388ff;
    --geojson-panel-header-text: #ffffff;
}

/* Map and Side Panel Container */
.geojson-map-wrapper {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
    height: var(--geojson-map-height-desktop) !important;
    min-height: 300px !important;
    max-height: 90vh !important;
    max-height: 90dvh !important; /* iOS Safari dynamic viewport */
    border-radius: 8px !important;
    overflow: hidden !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
    /* Prevent WordPress theme interference */
    box-sizing: border-box !important;
    line-height: normal !important;
    font-size: 14px !important;
}

/* Map container - takes remaining space */
.geojson-map {
    flex: 1 !important;
    min-width: 0 !important;
    height: var(--geojson-map-height-desktop) !important;
    min-height: 300px !important;
    position: relative !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
}

/* Leaflet container must fill the map div */
.geojson-map .leaflet-container {
    width: 100% !important;
    height: 100% !important;
}

/* Reset common WordPress theme styles that break Leaflet */
.geojson-map * {
    box-sizing: border-box !important;
}
.geojson-map img {
    max-width: none !important;
    max-height: none !important;
}

/* Side Panel Styles */
.geojson-side-panel {
    width: 320px !important;
    min-width: 280px !important;
    max-width: 400px !important;
    height: 100% !important;
    background: #ffffff !important;
    color: #333333 !important;
    border-left: 1px solid rgba(0,0,0,0.1) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
    display: flex !important;
    flex-direction: column !important;
    box-shadow: -2px 0 10px rgba(0,0,0,0.05) !important;
    box-sizing: border-box !important;
}

.geojson-side-panel-header {
    padding: 16px 20px !important;
    border-bottom: none !important;
    background: var(--geojson-panel-header-bg) !important;
    color: var(--geojson-panel-header-text) !important;
}

.geojson-side-panel-header h3 {
    margin: 0 !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    color: var(--geojson-panel-header-text) !important;
}

.geojson-side-panel-content {
    flex: 1 !important;
    padding: 16px 20px !important;
    overflow-y: auto !important;
}

.geojson-side-panel-placeholder {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
    text-align: center !important;
    color: inherit !important;
    opacity: 0.6 !important;
    padding: 20px !important;
}

.geojson-side-panel-placeholder-icon {
    font-size: 48px !important;
    margin-bottom: 16px !important;
    opacity: 0.5 !important;
}

.geojson-side-panel-placeholder p {
    margin: 0 !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
}

/* Feature info table in side panel */
.geojson-info-table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 14px !important;
}

.geojson-info-table tr {
    border-bottom: 1px solid rgba(0,0,0,0.08) !important;
}

.geojson-info-table tr:last-child {
    border-bottom: none !important;
}

.geojson-info-table td {
    padding: 10px 0 !important;
    vertical-align: top !important;
}

.geojson-info-table .info-label {
    font-weight: 600 !important;
    color: inherit !important;
    width: 40% !important;
    padding-right: 12px !important;
    opacity: 0.8 !important;
}

.geojson-info-table .info-value {
    color: inherit !important;
    word-break: break-word !important;
}

.geojson-feature-title {
    font-size: 18px !important;
    font-weight: 600 !important;
    margin: 0 0 16px 0 !important;
    padding-bottom: 12px !important;
    border-bottom: 2px solid rgba(0,0,0,0.1) !important;
    color: inherit !important;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .geojson-map-wrapper {
        flex-direction: column !important;
        height: auto !important;
        min-height: unset !important;
        max-height: none !important;
    }

    .geojson-map {
        width: 100% !important;
        height: var(--geojson-map-height-mobile) !important;
        min-height: 250px !important;
        flex: none !important;
    }

    .geojson-map .leaflet-container {
        width: 100% !important;
        height: 100% !important;
    }

    .geojson-side-panel {
        width: 100% !important;
        max-width: none !important;
        min-width: unset !important;
        height: auto !important;
        min-height: 150px !important;
        max-height: 40vh !important;
        max-height: 40dvh !important; /* iOS Safari */
        border-left: none !important;
        border-top: 1px solid rgba(0,0,0,0.1) !important;
        flex: none !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Ensure touch targets are at least 44px (Apple HIG) */
    .leaflet-control-zoom a,
    .leaflet-control-layers-toggle,
    .fullscreen-button {
        min-width: 44px !important;
        min-height: 44px !important;
        line-height: 44px !important;
        font-size: 18px !important;
    }

    /* Prevent iOS zoom on input focus */
    .search-input {
        font-size: 16px !important;
        padding: 8px 12px !important;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .geojson-map {
        height: var(--geojson-map-height-mobile) !important;
        min-height: 200px !important;
    }

    .geojson-side-panel {
        max-height: 35vh !important;
        max-height: 35dvh !important; /* iOS Safari */
    }
}

/* Feature count */
.feature-count {
    background: rgba(68, 68, 68, 0.9) !important;
    color: #ffffff !important;
    padding: 8px 16px !important;
    border-radius: 20px !important;
    font-size: 13px !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3) !important;
    display: inline-block !important;
    white-space: nowrap !important;
    text-align: center !important;
    min-width: 120px !important;
}

/* CRITICAL: SVG path styles for click/touch detection */
.geojson-polygon,
.leaflet-interactive {
    cursor: pointer !important;
    pointer-events: auto !important;
}

/* Ensure SVG container allows pointer events */
.leaflet-overlay-pane svg {
    pointer-events: auto !important;
}

.leaflet-overlay-pane svg path {
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* Custom pane SVG paths must be clickable */
.leaflet-zones-large-pane,
.leaflet-zones-medium-pane,
.leaflet-zones-small-pane,
.leaflet-zones-tiny-pane {
    pointer-events: auto !important;
}

.leaflet-zones-large-pane svg path,
.leaflet-zones-medium-pane svg path,
.leaflet-zones-small-pane svg path,
.leaflet-zones-tiny-pane svg path {
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* Touch-friendly styles - let Leaflet handle touch events */
.leaflet-container {
    touch-action: none !important; /* Leaflet manages its own touch handling */
    -webkit-tap-highlight-color: transparent !important;
    -webkit-touch-callout: none !important;
}

/* Prevent text selection on map */
.geojson-map-wrapper,
.geojson-map,
.leaflet-container {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
}

/* Allow text selection and scrolling in side panel */
.geojson-side-panel {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    touch-action: auto !important; /* Allow native scrolling in panel */
}

.geojson-side-panel-content {
    touch-action: pan-y !important; /* Allow vertical scrolling */
    -webkit-overflow-scrolling: touch !important;
}

/* Hover state for polygons (desktop only - no hover on touch) */
@media (hover: hover) and (pointer: fine) {
    .geojson-polygon:hover,
    .leaflet-interactive:hover {
        cursor: pointer !important;
    }
}

/* Search control styles */
.search-control-wrapper {
    background: white;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    margin-bottom: 10px;
    min-width: 200px;
    max-width: 300px;
}

.search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    box-sizing: border-box;
}

.search-input:focus {
    border-color: #0073aa;
    box-shadow: 0 0 0 1px #0073aa;
}

.leaflet-top.leaflet-left .search-control-wrapper {
    margin: 10px;
}

/* Loading and error states */
.geojson-loading,
.geojson-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    text-align: center;
    max-width: 80%;
    z-index: 1000;
}

.geojson-error h4 {
    margin: 0 0 10px 0;
    color: #dc3545;
}

.retry-button {
    margin-top: 15px;
    padding: 8px 16px;
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.retry-button:hover {
    background: #005177;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    margin: 0 auto 10px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #0073aa;
    border-radius: 50%;
    animation: geojson-spin 1s linear infinite;
}

@keyframes geojson-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Popup styles (legacy, kept for compatibility) */
.geojson-popup {
    max-width: 300px;
}

.popup-content-scroll {
    max-height: 200px;
    overflow-y: auto;
}

.popup-table {
    width: 100%;
    border-collapse: collapse;
}

.popup-row {
    border-bottom: 1px solid #eee;
}

.popup-label,
.popup-value {
    padding: 4px 8px;
    vertical-align: top;
}

.popup-label {
    width: 40%;
}

.no-data {
    color: #666;
    font-style: italic;
    padding: 10px;
}