/**
 * Cedec Map Builder Styles
 * Refined for Modern Look & Accessibility
 */

/* Info Box Container */
.cedec-map-info-box {
    background: #ffffff;
    padding: 0;
    font-family: 'DM Sans', 'Inter', 'Helvetica Neue', Arial, sans-serif;
    min-width: 300px;
    max-width: 340px;
    color: #333;
    pointer-events: auto;
    /* Ensure clickable */
    position: relative;
    z-index: 9999;
    border-radius: 12px;
}

/* Image */
.cedec-map-info-box-image {
    width: 100%;
    height: 200px;
    background-size: cover;
    background-position: center;
    border-radius: 12px 12px 0 0;
}

/* Content Wrapper */
.cedec-map-info-box-content {
    padding: 24px;
}

/* Type Label */
.cedec-map-info-box-type {
    display: inline-block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    color: #888;
    margin-bottom: 8px;
    background: #f3f4f6;
    padding: 4px 12px;
    border-radius: 4px;
}

/* Title */
.cedec-map-info-box-title {
    font-size: 22px;
    /* Bigger font as requested */
    font-weight: 700;
    line-height: 1.3;
    margin: 0 0 16px 0;
    color: #111;
}

/* Enforce link styling on the title */
.cedec-map-info-box-title a {
    text-decoration: none;
    color: #111;
    transition: color 0.2s ease;
    display: block;
}

.cedec-map-info-box-title a:hover {
    color: #2563eb;
    /* Primary Blue Hover */
}

/* Publication Date */
.cedec-map-info-box-date {
    font-size: 14px;
    color: #666;
    margin: 0 0 16px 0;
    line-height: 1.5;
}

/* Excerpt */
.cedec-map-info-box-excerpt {
    font-size: 14px;
    color: #666;
    margin: 0 0 16px 0;
    line-height: 1.5;
}

/* Link Button */
.cedec-map-info-box-link {
    display: block;
    width: 100%;
    text-align: center;
    padding: 14px 0;
    background-color: #D4D654;
    color: #222;
    text-decoration: none;
    font-weight: 700;
    font-size: 15px;
    border-radius: 8px;
    transition: all 0.2s;
    margin-top: 10px;
}

.cedec-map-info-box-link:hover {
    background-color: #c0c24d;
    color: #000;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* --- Google Maps Overrides --- */

/* Remove default padding and shadow from the wrapper */
.gm-style .gm-style-iw-c {
    padding: 0 !important;
    border-radius: 12px !important;
    overflow: visible !important;
    /* Allow shadow/interaction */
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18) !important;
    background: transparent !important;
    /* Let our box handle bg */
}

.gm-style .gm-style-iw-d {
    overflow: hidden !important;
    max-height: none !important;
    background: white;
    /* Ensure bg is white */
    border-radius: 12px;
}

/* Hide the little arrow tail for a cleaner "floating" card look */
.gm-style .gm-style-iw-t::after {
    display: none !important;
}

/* Custom Close Button Styling */
.gm-style .gm-style-iw>button {
    top: 12px !important;
    right: 12px !important;
    background: rgba(255, 255, 255, 0.95) !important;
    border-radius: 50% !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    height: 30px !important;
    width: 30px !important;
    opacity: 1 !important;
    /* Force visible */
}

.gm-style .gm-style-iw>button span {
    margin: 8px auto !important;
    /* Center the X */
}

/* HIDE WPGMZA Default Elements so only our Custom Box shows */
.wpgmza_infowindow_title,
.wpgmza_infowindow_address {
    display: none !important;
}

/* Ensure the description container has no padding that messes up our box */
.wpgmza_infowindow_description {
    margin: 0 !important;
    padding: 0 !important;
}

/* --- Top Bar (Borders + Legend) --- */

.cedec-map-top-bar {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 75%;
    max-width: 75%;
    z-index: 1000;
    font-family: 'DM Sans', 'Inter', 'Helvetica Neue', Arial, sans-serif;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.cedec-map-top-bar-content {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 6px 12px;
    flex-wrap: wrap;
}

/* Language Switcher */
.cedec-map-language-switcher {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 16px;
    border-left: 1px solid #e0e0e0;
}

.cedec-map-language-switcher a {
    font-size: 11px;
    font-weight: 600;
    color: #555;
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.cedec-map-language-switcher a:hover {
    background: #ebebeb;
    color: #333;
}

.cedec-map-language-switcher a.active {
    color: #D4D654;
    font-weight: 700;
}

.cedec-map-language-switcher .cedec-lang-separator {
    color: #ccc;
    font-size: 11px;
}

/* --- Map Panel Tabs (BORDERS / LEGEND) --- */

/* Active/selected tab */
.cedec-map-panel-tab.active,
.cedec-map-panel-tab[aria-selected="true"],
[role="tablist"] [role="tab"][aria-selected="true"] {
    color: #E9ECF1;
    background: #003E5C;
}

/* Inactive tab hover */
.cedec-map-panel-tab:not(.active):hover,
.cedec-map-panel-tab:not([aria-selected="true"]):hover,
[role="tablist"] [role="tab"]:not([aria-selected="true"]):hover {
    color: #003E5C;
    background: #D4D654;
}

/* --- Border Toggle Controls --- */

.cedec-border-controls-section {
    display: flex;
    align-items: center;
    gap: 0;
    background: transparent;
    border-radius: 0;
    padding: 0;
    padding-right: 16px;
    border-right: 1px solid #e0e0e0;
    box-shadow: none;
    min-width: auto;
}

.cedec-border-controls-title {
    display: none;
}

.cedec-border-controls-buttons {
    display: flex;
    flex-direction: row;
    gap: 0;
}

.cedec-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 4px 8px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 11px;
    font-weight: 600;
    color: #333;
    text-align: left;
}

.cedec-toggle-btn:hover {
    background: #ebebeb;
    border-color: #d0d0d0;
    transform: translateY(-1px);
}

.cedec-toggle-btn.active {
    background: #f5f5f5;
    border-color: #e0e0e0;
    color: #333;
    box-shadow: none;
}

.cedec-toggle-btn.active:hover {
    background: #ebebeb;
    border-color: #d0d0d0;
    color: #333;
}

.cedec-toggle-label {
    flex: 1;
    line-height: 14px;
    font-size: 11px;
}

/* Toggle switch (replaces old circular indicator) */
.cedec-toggle-switch {
    position: relative;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
}

.cedec-toggle-switch-track {
    width: 24px;
    height: 14px;
    border-radius: 999px;
    background: #ccc;
    border: 1px solid #999;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.cedec-toggle-switch-thumb {
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
}

.cedec-toggle-btn.active .cedec-toggle-switch-track {
    background: #D4D654;
    border-color: #D4D654;
}

.cedec-toggle-btn.active .cedec-toggle-switch-thumb {
    transform: translate(12px, -50%);
}

/* Screen-reader only (for optional toggle status text) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Map Legend --- */

.cedec-map-legend-container {
    flex: 1;
    min-width: 0;
}

.cedec-map-legend {
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
    min-width: auto;
}

.cedec-map-legend-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #555;
    margin: 0 8px 0 0;
    padding: 0;
    border: none;
    white-space: nowrap;
    display: inline-block;
}

.cedec-map-legend-items {
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* Hover box wrapper for each legend entry (pin + post type + switch) */
.cedec-map-legend-item-wrapper,
.cedec-legend-hover-box {
    background: #f5f5f5 !important;
    border: 1px solid #e0e0e0 !important;
    border-radius: 6px;
    padding: 3px 6px;
    color: #333 !important;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.cedec-map-legend-item-wrapper:hover,
.cedec-legend-hover-box:hover,
.cedec-map-legend-item-wrapper.active,
.cedec-legend-hover-box.active,
.cedec-map-legend-item-wrapper[style*="background"],
.cedec-legend-hover-box[style*="background"] {
    background: #f5f5f5 !important;
    border-color: #d0d0d0 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.cedec-legend-hover-box .cedec-toggle-btn {
    background: transparent;
    border-color: transparent;
    color: #333;
    padding: 2px 4px;
}

.cedec-legend-hover-box .cedec-toggle-btn:hover {
    background: #ebebeb;
    border-color: #d0d0d0;
    color: #333;
}

.cedec-legend-hover-box .cedec-toggle-btn.active {
    background: transparent !important;
    border-color: transparent !important;
    color: #333 !important;
}

.cedec-legend-hover-box .cedec-toggle-btn.active:hover {
    background: #ebebeb !important;
    border-color: #d0d0d0 !important;
    color: #333 !important;
}

/* Ensure legend item wrappers never show pink/red backgrounds - override any possible pink */
.cedec-map-legend-item-wrapper,
.cedec-legend-hover-box {
    background-color: #f5f5f5 !important;
    background: #f5f5f5 !important;
}

.cedec-map-legend-item-wrapper .cedec-toggle-btn,
.cedec-legend-hover-box .cedec-toggle-btn {
    background-color: transparent !important;
    background: transparent !important;
}

.cedec-map-legend-item-wrapper .cedec-toggle-btn:hover,
.cedec-legend-hover-box .cedec-toggle-btn:hover {
    background-color: #ebebeb !important;
    background: #ebebeb !important;
}

/* Prevent any pink/red colors from appearing */
.cedec-map-legend-item-wrapper[style*="#FF6B6B"],
.cedec-legend-hover-box[style*="#FF6B6B"],
.cedec-map-legend-item-wrapper[style*="#ff6b6b"],
.cedec-legend-hover-box[style*="#ff6b6b"],
.cedec-map-legend-item-wrapper[style*="rgb(255, 107, 107)"],
.cedec-legend-hover-box[style*="rgb(255, 107, 107)"] {
    background: #f5f5f5 !important;
    background-color: #f5f5f5 !important;
}

.cedec-map-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cedec-map-legend-icon {
    width: 16px;
    height: 24px;
    object-fit: contain;
    flex-shrink: 0;
}

.cedec-map-legend-label {
    font-size: 11px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

/* Legend toggle: same look as Admin Regions, compact in row */
.cedec-legend-toggle-btn {
    flex: 1;
    min-width: 0;
    padding: 2px 4px;
    font-size: 11px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .cedec-map-top-bar {
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 16px);
        max-width: calc(100% - 16px);
    }
    
    .cedec-map-top-bar-content {
        padding: 6px 10px;
        gap: 12px;
        flex-direction: column;
        align-items: flex-start;
    }

    .cedec-border-controls-section {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding-right: 12px;
    }

    .cedec-border-controls-title,
    .cedec-map-legend-title {
        font-size: 10px;
        margin: 0;
    }

    .cedec-map-legend-items {
        flex-direction: column;
        align-items: flex-start;
    }

    .cedec-toggle-btn {
        padding: 4px 8px;
        font-size: 11px;
    }

    .cedec-map-legend-icon {
        width: 14px;
        height: 20px;
    }

    .cedec-map-legend-label {
        font-size: 11px;
    }

    .cedec-map-legend-item-wrapper,
    .cedec-legend-hover-box {
        padding: 3px 6px;
    }

    .cedec-legend-toggle-btn {
        padding: 2px 4px;
        font-size: 11px;
    }
}

/* --- Loading Overlay --- */

.cedec-map-container-loading {
    position: relative;
    overflow: hidden;
}

.cedec-map-container-loading>*:not(.cedec-map-loading-overlay) {
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Aggressively hide Google Maps elements during loading */
.cedec-map-container-loading .gm-style,
.cedec-map-container-loading .gm-style *,
.cedec-map-container-loading iframe {
    opacity: 0 !important;
    visibility: hidden !important;
}

.cedec-map-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    font-family: 'DM Sans', 'Inter', 'Helvetica Neue', Arial, sans-serif;
}

.cedec-map-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e0e0e0;
    border-top-color: #D4D654;
    border-radius: 50%;
    animation: cedec-map-spin 0.8s linear infinite;
}

@keyframes cedec-map-spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- Region Tooltip --- */

.cedec-region-tooltip {
    position: fixed;
    /* Use fixed to avoid positioning issues relative to map containers */
    background: #ffffff;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    font-family: 'DM Sans', 'Inter', 'Helvetica Neue', Arial, sans-serif;
    min-width: 220px;
    pointer-events: none;
    /* Make sure it doesn't flicker or block clicks */
    z-index: 99999;
    /* Higher than everything */
    transform: translate(15px, 15px);
    /* Offset from cursor */
    display: none;
    /* Hidden by default */
}

.cedec-region-tooltip-title {
    font-size: 16px;
    font-weight: 700;
    color: #111;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid #D4D654;
    /* Theme highlight */
}

.cedec-region-tooltip-stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cedec-region-stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}

.cedec-region-stat-label {
    color: #666;
    font-weight: 500;
}

.cedec-region-stat-value {
    color: #333;
    font-weight: 700;
}