/* Container Styling
 * Full-bleed, full-viewport map. `--wmr-trailmap-offset` is set by script.js to the
 * distance between the top of the document and the map (e.g. site header + admin bar)
 * when the map starts above the fold, so the map fills exactly the remaining viewport.
 * Margin-based full-bleed (no `left: 50%`) so it can't double-shift when a theme's
 * own `.alignfull` rules apply negative margins too.
 */
.wmr-trailmap-wrapper,
.entry-content > .wmr-trailmap-wrapper.alignfull {
    display: block;
    position: relative;
    isolation: isolate;
    box-sizing: border-box;
    width: 100vw;
    max-width: 100vw;
    left: auto;
    right: auto;
    margin: 0 calc(50% - 50vw);
    padding: 0;
    height: calc(100vh - var(--wmr-trailmap-offset, 0px));
    height: calc(100dvh - var(--wmr-trailmap-offset, 0px));
    min-height: 320px;
    background-color: #f1f5f9;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    font-family: inherit;
}

/* Loading Spinner */
.wmr-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.wmr-loading-spinner.is-active {
    opacity: 1;
}

.wmr-spinner-circle {
    width: 60px;
    height: 60px;
    border: 5px solid rgb(15 23 42 / 0.15);
    border-top-color: #0f172a;
    border-radius: 50%;
    animation: wmr-spin 0.8s linear infinite;
}

@keyframes wmr-spin {
    to { transform: rotate(360deg); }
}

/* Tooltip */
.wmr-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    transform: translate3d(0, 0, 0);
    will-change: transform, opacity;
    background: rgb(15 23 42 / 0.9);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 4px 6px rgb(0 0 0 / 0.2);
}

/* Left Sliding Map Switcher Drawer (Mobile-First) */
.wmr-switchers-overlay {
    position: absolute;
    top: 1rem;
    left: 0;
    z-index: 20;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    max-height: calc(100% - 5.5rem);
    transform: translateX(calc(-100% + 49px));
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.wmr-switchers-overlay.is-active {
    transform: translateX(0);
}

.wmr-switchers-tab {
    order: 2;
    pointer-events: auto;
    appearance: none;
    position: relative;
    width: 50px;
    margin-left: -1px;
    padding: 14px 14px 14px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #0f172a;
    background: rgb(255 255 255 / 0.92);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid #cbd5e1;
    border-left: none;
    border-radius: 0 12px 12px 0;
    box-shadow: 0 4px 16px rgb(15 23 42 / 0.22);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.wmr-switchers-tab::before {
    content: '';
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 32px;
    background: #64748b;
    border-radius: 2px;
}

.wmr-switchers-tab-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.wmr-switchers-tab-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    line-height: 1;
    white-space: nowrap;
    inline-size: max-content;
    flex-shrink: 0;
}

.wmr-switchers-container {
    order: 1;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
    max-height: calc(100vh - 6rem);
    max-height: calc(100dvh - 6rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: rgb(255 255 255 / 0.78);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid #e2e8f0;
    border-left: none;
    border-radius: 0 0 12px 0;
    box-shadow: 4px 4px 20px rgb(0 0 0 / 0.15);
}

/* Individual Map Switcher Item (Thumbnail Button + PDF Download Link) */
.wmr-map-switcher-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: clamp(110px, 28vw, 152px);
}

/* Individual Map Thumbnail Button (no grey backdrop) */
.wmr-map-switcher {
    appearance: none;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.wmr-map-switcher img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 6px;
    box-shadow: 0 3px 10px rgb(0 0 0 / 0.22);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wmr-map-switcher:hover img {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 6px 16px rgb(0 0 0 / 0.28);
}

.wmr-map-switcher.is-active img {
    outline: 2.5px solid #00524d;
    outline-offset: 2px;
    box-shadow: 0 4px 12px rgb(0 82 77 / 0.25);
}

.wmr-map-switcher-label {
    width: 100%;
    color: #1e293b;
    font-size: 0.8rem;
    font-weight: 600;
    padding-top: 0.35rem;
    /* Theme sets `word-break: break-word` on .wp-block-column; don't split labels mid-word */
    word-break: normal;
    overflow-wrap: normal;
    white-space: nowrap;
}

.wmr-map-switcher.is-active .wmr-map-switcher-label {
    color: #0f172a;
    font-weight: 700;
}

.wmr-map-pdf-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    margin-top: 0.2rem;
    color: #334155;
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    border-radius: 3px;
    transition: color 0.15s ease;
}

.wmr-map-pdf-link:hover {
    color: #0f172a;
    text-decoration: underline;
}

.wmr-map-note {
    margin-top: 0.2rem;
    color: #475569;
    font-size: 0.72rem;
    font-style: italic;
    line-height: 1.2;
}

.wmr-pdf-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    display: block;
}

/* Fade between maps */
.wmr-trailmap-wrapper .wmr-trailmap-canvas,
.wmr-legend-grid {
    transition: opacity 0.25s ease;
}

/* Panzoom Canvas
 * Absolutely pinned to the wrapper so its size never depends on percentage-height
 * resolution or flex behavior (both of which themes frequently break).
 */
.wmr-trailmap-wrapper .wmr-trailmap-canvas {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
}

.wmr-trailmap-wrapper .wmr-trailmap-canvas:active {
    cursor: grabbing;
}

.wmr-trailmap-wrapper.is-static-map .wmr-legend-overlay {
    display: none;
}

/* The map element (SVG or static image) is anchored top-left (which Panzoom's
 * `contain: 'outside'` math assumes) and sized in px by script.js to "cover" the
 * container. The fallbacks below are only used before JS runs. `!important` on max-*
 * overrides common theme resets like `svg { max-width: 100%; height: auto; }` which
 * would shrink the map below cover size.
 */
.wmr-trailmap-wrapper .wmr-trailmap-canvas > svg,
.wmr-trailmap-wrapper .wmr-trailmap-canvas > .wmr-static-map-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: none !important;
    max-height: none !important;
    min-width: 0;
    margin: 0 !important;
    display: block;
    transform-origin: 50% 50%;
    -webkit-user-drag: none;
    user-select: none;
}
    transform-origin: 50% 50%;
}

.wmr-trailmap-wrapper .wmr-trailmap-canvas svg [data-tooltip],
.wmr-trailmap-wrapper .wmr-trailmap-canvas svg [id*="icon_"] {
    cursor: pointer;
}

/* Zoom Controls */
.wmr-zoom-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 5;
}

.wmr-zoom-controls button {
    background: #fff;
    border: 1px solid #e2e8f0;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    font-size: 1.25rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 4px rgb(0 0 0 / 0.1);
    color: #334155;
    transition: background 0.2s;
}

.wmr-zoom-controls button:hover {
    background: #f8fafc;
}

/* Bottom Legend Drawer (Mobile-First) */
.wmr-legend-overlay {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translate(-50%, calc(100% - 40px));
    width: 92%;
    max-width: 900px;
    background: rgb(255 255 255 / 0.65);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid #e2e8f0;
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 20px rgb(0 0 0 / 0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.wmr-legend-overlay.is-active {
    transform: translate(-50%, 0);
}

.wmr-legend-tab {
    appearance: none;
    background: transparent;
    border: none;
    border-bottom: 1px solid transparent;
    width: 100%;
    height: 40px;
    order: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: #0f172a;
    cursor: pointer;
    position: relative;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.wmr-legend-tab::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: #828282;
    border-radius: 2px;
}

.wmr-legend-overlay.is-active .wmr-legend-tab {
    border-bottom-color: #e2e8f0;
}

.wmr-legend-grid {
    order: 2;
    padding: 0.5rem;
    display: grid;
    gap: 0.25rem 0.5rem;
    grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
    /* Prevents label items from stretching horizontally/vertically into empty grid space */
    justify-items: start;
    align-items: start;
    max-height: 45vh;
    max-height: 45dvh;
    overflow-y: auto;
}

/* Reset All Filters Button */
.wmr-reset-btn {
    grid-column: 1 / -1;
    width: 100%; /* Required since justify-items: start was added to parent container */
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    padding: 0.4rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: background 0.2s, color 0.2s;
    margin-bottom: 0.25rem;
}

.wmr-reset-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.wmr-legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: #475569;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
    line-height: 1.2;
    -webkit-user-select: none;
    user-select: none; /* Prevents text selection loops on sloppy taps */
    -webkit-tap-highlight-color: transparent;
}

.wmr-legend-item:hover {
    background: #f1f5f9;
}

.wmr-legend-item input[type="checkbox"] {
    accent-color: #0f172a;
    width: 16px;
    height: 16px;
}

/* Desktop Hover Enhancements */
@media (hover: hover) and (pointer: fine) {
    .wmr-switchers-overlay:hover {
        transform: translateX(0);
    }

    .wmr-legend-overlay:hover {
        transform: translate(-50%, 0);
    }

    .wmr-legend-overlay:hover .wmr-legend-tab {
        border-bottom-color: #e2e8f0;
    }
}

/* Desktop & Tablet Sizing */
@media (min-width: 768px) {
    .wmr-switchers-overlay {
        top: 1.5rem;
    }

    .wmr-switchers-container {
        gap: 0.9rem;
        padding: 0.9rem;
    }

    .wmr-map-switcher-item {
        width: 160px;
    }

    .wmr-map-switcher-label {
        font-size: 0.875rem;
        padding-top: 0.45rem;
    }

    .wmr-map-pdf-link,
    .wmr-map-note {
        font-size: 0.78rem;
    }

    .wmr-legend-overlay {
        transform: translate(-50%, calc(100% - 50px));
    }

    .wmr-legend-tab {
        height: 50px;
        font-size: 1rem;
    }

    .wmr-legend-grid {
        padding: 0.75rem;
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }
}

/* Keyboard Focus Accessibility */
.wmr-switchers-tab:focus-visible,
.wmr-map-switcher:focus-visible,
.wmr-map-pdf-link:focus-visible,
.wmr-legend-tab:focus-visible,
.wmr-zoom-controls button:focus-visible,
.wmr-reset-btn:focus-visible,
.wmr-legend-item:focus-within {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Reduced Motion Accessibility */
@media (prefers-reduced-motion: reduce) {
    .wmr-loading-spinner,
    .wmr-spinner-circle,
    .wmr-tooltip,
    .wmr-switchers-overlay,
    .wmr-map-switcher,
    .wmr-map-switcher img,
    .wmr-map-pdf-link,
    .wmr-trailmap-wrapper .wmr-trailmap-canvas,
    .wmr-legend-grid,
    .wmr-legend-overlay {
        animation: none !important;
        transition: none !important;
    }
}
