/* ==========================================================================
   IMungro Interactive Map Widget
   ========================================================================== */

/* ── Wrapper ──────────────────────────────────────────────────────────────── */
.im-imap-wrap {
    position: relative;
    width: 100%;
    font-family: 'EB Garamond', Georgia, serif;
    color: #e8d5a3;
    box-sizing: border-box;
    /* Height containment — activated when --im-max-height is set via widget control */
    max-height: var(--im-max-height, none);
    overflow: hidden;
}

.im-imap-title {
    text-align: center;
    font-size: clamp(1.2rem, 3vw, 2rem);
    color: #f2ca50;
    margin: 0 0 16px;
    text-shadow: 0 0 18px rgba(242,202,80,.45);
    letter-spacing: .04em;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.im-imap-layout {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    position: relative;
}

.im-imap-legend-right  .im-imap-layout { flex-direction: row; }
.im-imap-legend-left   .im-imap-layout { flex-direction: row-reverse; }
.im-imap-legend-bottom .im-imap-layout { flex-direction: column; }

/* ── Canvas ───────────────────────────────────────────────────────────────── */
.im-imap-canvas-wrap {
    flex: 1 1 auto;
    min-width: 0;
    /* Hard clip — prevents any child (markers, overlays, popups) from
       overflowing the image bounds and pushing the layout out */
    overflow: hidden;
    border-radius: 6px;
    position: relative;
    /* When max-height is active on the wrap, this flex child must also
       shrink — it should never grow taller than its available space */
    min-height: 0;
    max-height: inherit;
}

.im-imap-canvas {
    position: relative;
    display: block;
    width: 100%;
    transform-origin: 0 0;
    will-change: transform;
    cursor: default;
    transition: transform .05s linear;
}

.im-imap-img {
    display: block;
    width: 100%;
    /* height: auto lets the image grow freely by default.
       When --im-max-height is active, we want height to fill the
       available space (shrinking the image) while maintaining aspect ratio. */
    height: auto;
    max-width: 100%;
    max-height: var(--im-max-height, none);
    object-fit: contain;
    object-position: top center;
    user-select: none;
    pointer-events: none;
    border-radius: 4px;
}

/* ── Markers layer ────────────────────────────────────────────────────────── */
.im-imap-markers {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* ── Hotspot marker ───────────────────────────────────────────────────────── */
.im-imap-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    width:  var(--im-marker-size, 30px);
    height: var(--im-marker-size, 30px);
    border-radius: 50%;
    border: 2px solid var(--hs-color, var(--im-def-color, #f2ca50));
    background: var(--hs-bg, var(--im-def-bg, rgba(0,0,0,.65)));
    /* number color is separate from border color */
    color: var(--hs-num-color, var(--hs-color, var(--im-def-color, #f2ca50)));
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'EB Garamond', serif;
    font-size: calc(var(--im-marker-size, 30px) * 0.44);
    font-weight: 700;
    cursor: pointer;
    pointer-events: all;
    z-index: 10;
    outline: none;
    /* Idle continuous pulse — makes the map feel live */
    animation: im-marker-idle 2.8s ease-in-out infinite;
}

/* Each marker gets a staggered delay so they pulse out of phase */
.im-imap-marker:nth-child(1)  { animation-delay: 0s; }
.im-imap-marker:nth-child(2)  { animation-delay: .35s; }
.im-imap-marker:nth-child(3)  { animation-delay: .7s; }
.im-imap-marker:nth-child(4)  { animation-delay: 1.05s; }
.im-imap-marker:nth-child(5)  { animation-delay: 1.4s; }
.im-imap-marker:nth-child(6)  { animation-delay: 1.75s; }
.im-imap-marker:nth-child(7)  { animation-delay: 2.1s; }
.im-imap-marker:nth-child(8)  { animation-delay: 2.45s; }
.im-imap-marker:nth-child(9)  { animation-delay: 0.18s; }
.im-imap-marker:nth-child(10) { animation-delay: 0.53s; }
.im-imap-marker:nth-child(11) { animation-delay: 0.88s; }
.im-imap-marker:nth-child(12) { animation-delay: 1.23s; }

/* Hover / focus overrides the idle to give instant feedback */
.im-imap-marker:hover,
.im-imap-marker:focus {
    animation: none;
    transform: translate(-50%, -50%) scale(1.4);
    box-shadow: 0 0 18px var(--hs-color, #f2ca50), 0 0 0 4px rgba(242,202,80,.25);
    transition: transform .18s ease, box-shadow .18s ease;
}

.im-imap-marker-num { pointer-events: none; line-height: 1; }

.im-imap-marker-dot {
    width: 40%;
    height: 40%;
    border-radius: 50%;
    background: var(--hs-color, var(--im-def-color, #f2ca50));
    box-shadow: 0 0 6px var(--hs-color, #f2ca50);
    pointer-events: none;
}

/* ── Idle pulse keyframes ─────────────────────────────────────────────────── */
/*   Subtle: scale 1 → 1.12 → 1, glow expands and fades                      */
@keyframes im-marker-idle {
    0%   {
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 0 4px rgba(0,0,0,.5),
                    0 0 0   0   var(--hs-color, #f2ca50);
    }
    40%  {
        transform: translate(-50%, -50%) scale(1.12);
        box-shadow: 0 0 10px rgba(0,0,0,.4),
                    0 0 0   6px rgba(242,202,80,.18);
    }
    70%  {
        transform: translate(-50%, -50%) scale(1.06);
        box-shadow: 0 0 8px  rgba(0,0,0,.4),
                    0 0 0   4px rgba(242,202,80,.10);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 0 4px rgba(0,0,0,.5),
                    0 0 0   0   var(--hs-color, #f2ca50);
    }
}

/* ── Legend-click zoom-pop keyframe ──────────────────────────────────────── */
/*   Triggered by JS adding .im-imap-marker-zoom to the clicked marker        */
@keyframes im-marker-zoom-pop {
    0%   { transform: translate(-50%,-50%) scale(1); }
    35%  { transform: translate(-50%,-50%) scale(var(--im-zoom-pop, 1.6));
           box-shadow: 0 0 22px var(--hs-color,#f2ca50), 0 0 0 8px rgba(242,202,80,.22); }
    70%  { transform: translate(-50%,-50%) scale(calc(var(--im-zoom-pop, 1.6) * 0.88));
           box-shadow: 0 0 12px var(--hs-color,#f2ca50), 0 0 0 4px rgba(242,202,80,.12); }
    100% { transform: translate(-50%,-50%) scale(1); box-shadow: none; }
}

.im-imap-marker-zoom {
    animation: im-marker-zoom-pop 0.65s cubic-bezier(.22,.68,0,1.4) forwards !important;
}

/* ── Click-activate pulse (overrides idle momentarily) ───────────────────── */
@keyframes im-marker-pulse {
    0%   { transform: translate(-50%,-50%) scale(1);   box-shadow: 0 0 0  0   var(--hs-color,#f2ca50); }
    30%  { transform: translate(-50%,-50%) scale(1.7); box-shadow: 0 0 0 12px rgba(242,202,80,.2); }
    65%  { transform: translate(-50%,-50%) scale(1.3); box-shadow: 0 0 0  7px rgba(242,202,80,.1); }
    100% { transform: translate(-50%,-50%) scale(1);   box-shadow: 0 0 0  0   rgba(242,202,80,0); }
}

.im-imap-marker-anim {
    animation: im-marker-pulse 0.75s ease forwards !important;
}

/* ── Popup ────────────────────────────────────────────────────────────────── */
.im-imap-popup {
    position: absolute;
    z-index: 50;
    background: rgba(10,6,4,.96);
    border: 1px solid rgba(242,202,80,.38);
    border-radius: 6px;
    padding: 14px 16px 12px;
    min-width: 180px;
    max-width: 260px;
    box-shadow: 0 4px 24px rgba(0,0,0,.75);
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity .22s ease, transform .22s ease;
}

.im-imap-popup-visible {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.im-imap-popup-close {
    position: absolute;
    top: 6px; right: 8px;
    background: none; border: none;
    color: #888; font-size: 13px; cursor: pointer;
    padding: 2px 4px; line-height: 1;
}
.im-imap-popup-close:hover { color: #f2ca50; }

.im-imap-popup-title {
    font-size: var(--im-popup-title-size, 14px);
    font-weight: 700;
    color: var(--im-popup-title-color, #f2ca50);
    margin-bottom: 6px;
    padding-right: 20px;
}

.im-imap-popup-desc {
    font-size: var(--im-popup-desc-size, 12px);
    color: var(--im-popup-desc-color, #c8b89a);
    line-height: 1.5;
}

/* ── Legend label circle pulse (per-label, class added by JS) ────────────── */
/*   Only .im-imap-label-num-pulse circles animate — hotspot markers untouched */
@keyframes im-label-circle-pulse {
    0%   { box-shadow: 0 0 0 0   var(--lbl-color, #f2ca50); }
    60%  { box-shadow: 0 0 0 8px rgba(242,202,80,0); }
    100% { box-shadow: 0 0 0 0   rgba(242,202,80,0); }
}
.im-imap-label-num-pulse {
    animation: im-label-circle-pulse 2.4s ease-out infinite;
}

/* ── Legend label flicker (per-label, class im-imap-label-flicker on lWrap) ─ */
/*   The circle num is not rendered in flicker mode (JS skips it).             */
/*   Only the .im-imap-label-box text span flickers.                           */
@keyframes im-label-flicker {
    0%,  100% { opacity: 1;    }
    42%        { opacity: 0.45; }
    47%        { opacity: 1;    }
    52%        { opacity: 0.6;  }
    57%        { opacity: 1;    }
}
.im-imap-label-flicker .im-imap-label-box {
    animation: im-label-flicker 3s ease-in-out infinite;
}
/* Hover pauses the flicker */
.im-imap-label-flicker:hover .im-imap-label-box,
.im-imap-label-flicker:focus .im-imap-label-box {
    animation-play-state: paused;
    opacity: 1;
}

/* ── Sidebar Legend ───────────────────────────────────────────────────────── */
.im-imap-legend {
    flex: 0 0 220px;
    max-width: 240px;
    background: var(--im-legend-bg, rgba(10,6,4,.88));
    border: 1px solid rgba(242,202,80,.2);
    border-radius: 6px;
    overflow: hidden;
    transition: transform .3s ease, opacity .3s ease;
}

.im-imap-legend-bottom .im-imap-legend {
    flex: 0 0 auto;
    max-width: 100%;
    width: 100%;
}

.im-imap-legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 8px;
    border-bottom: 1px solid rgba(242,202,80,.15);
}

.im-imap-legend-title {
    font-size: .9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: #f2ca50;
}

.im-imap-legend-close {
    display: none;
    background: none; border: none;
    color: #666; font-size: 14px; cursor: pointer;
    padding: 2px 4px;
}
.im-imap-legend-close:hover { color: #f2ca50; }

.im-imap-legend-list {
    list-style: none;
    margin: 0;
    padding: 8px 0;
    max-height: 440px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(242,202,80,.2) transparent;
}

.im-imap-legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 14px;
    cursor: pointer;
    transition: background .15s ease;
    border-left: 3px solid transparent;
    color: var(--im-legend-fg, #e8d5a3);
    font-size: .88rem;
}

.im-imap-legend-item:hover {
    background: rgba(242,202,80,.08);
    border-left-color: rgba(242,202,80,.4);
}

.im-imap-legend-item-active {
    background: rgba(242,202,80,.12) !important;
    border-left-color: #f2ca50 !important;
    color: #f2ca50 !important;
}

.im-imap-legend-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: .78rem;
    font-weight: 700;
    flex-shrink: 0;
    background: #f2ca50;
    color: #111;
}

.im-imap-legend-label { flex: 1; }

.im-imap-legend-toggle { display: none; }
.im-imap-drawer-handle { display: none; }

/* ── Placeholder ──────────────────────────────────────────────────────────── */
.im-map-placeholder {
    padding: 48px 24px;
    text-align: center;
    border: 2px dashed #555;
    border-radius: 6px;
    color: #888;
    font-size: .9rem;
}

/* ── Image Overlays ───────────────────────────────────────────────────────── */
.im-imap-overlays {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

.im-imap-overlay-img {
    position: absolute;
    height: auto;
    pointer-events: none;
    user-select: none;
    display: block;
}

/* ── Map Legend Labels (inline on-image — circle + text, mirrors sidebar) ── */
.im-imap-labels {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 8;
}

.im-imap-label {
    position: absolute;
    display: flex;
    align-items: center;
    /* gap set inline by JS from lbl_circle_gap control — no hardcoded gap here */
    pointer-events: all;
    cursor: pointer;
}

/* right: label extends to the right of anchor — anchor = left edge of circle */
.im-imap-label-dir-right {
    flex-direction: row;
    transform: translate(-13px, -13px); /* center the 26px circle on the anchor */
}

/* left: label extends left — shift whole label so right edge of circle is at anchor */
.im-imap-label-dir-left {
    flex-direction: row-reverse;
    transform: translate(calc(-100% + 13px), -13px);
}

/* up: label extends upward — bottom of box at anchor */
.im-imap-label-dir-up {
    flex-direction: column-reverse;
    align-items: center;
    transform: translate(-13px, calc(-100% + 13px));
}

/* down: circle then box below */
.im-imap-label-dir-down {
    flex-direction: column;
    align-items: center;
    transform: translate(-13px, -13px);
}

/* Numbered circle — hollow hotspot style, fully styled via Elementor controls */
.im-imap-label-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* width, height, font-size, background, border, color all set inline by JS */
    border-radius: 50%;
    font-weight: 700;
    flex-shrink: 0;
    font-family: 'EB Garamond', Georgia, serif;
    box-sizing: border-box;
    transition: transform .2s ease, box-shadow .2s ease;
    /* Idle pulse — mirrors .im-imap-marker animation so labels feel live too */
    animation: im-label-num-idle 2.8s ease-in-out infinite;
}

/* Stagger label circles opposite-phase to hotspots for visual variety */
.im-imap-label:nth-child(1) .im-imap-label-num { animation-delay: .6s; }
.im-imap-label:nth-child(2) .im-imap-label-num { animation-delay: .95s; }
.im-imap-label:nth-child(3) .im-imap-label-num { animation-delay: 1.3s; }
.im-imap-label:nth-child(4) .im-imap-label-num { animation-delay: 1.65s; }
.im-imap-label:nth-child(5) .im-imap-label-num { animation-delay: 2.0s; }
.im-imap-label:nth-child(6) .im-imap-label-num { animation-delay: 2.35s; }
.im-imap-label:nth-child(7) .im-imap-label-num { animation-delay: 0.3s; }
.im-imap-label:nth-child(8) .im-imap-label-num { animation-delay: 0.72s; }
.im-imap-label:nth-child(9) .im-imap-label-num { animation-delay: 1.1s; }

@keyframes im-label-num-idle {
    0%   { transform: scale(1);    box-shadow: 0 0 4px rgba(0,0,0,.5), 0 0 0 0 currentColor; }
    40%  { transform: scale(1.10); box-shadow: 0 0 8px rgba(0,0,0,.4), 0 0 0 4px rgba(242,202,80,.15); }
    70%  { transform: scale(1.05); box-shadow: 0 0 6px rgba(0,0,0,.4), 0 0 0 2px rgba(242,202,80,.08); }
    100% { transform: scale(1);    box-shadow: 0 0 4px rgba(0,0,0,.5), 0 0 0 0 currentColor; }
}

/* Text box */
.im-imap-label-box {
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    padding: 0 8px;
    letter-spacing: .02em;
    font-family: 'EB Garamond', Georgia, serif;
}

.im-imap-label:hover .im-imap-label-num {
    animation: none;
    transform: scale(1.3);
    filter: brightness(1.25);
}
.im-imap-label:hover .im-imap-label-box {
    filter: brightness(1.15);
}

/* Hide labels on mobile — insufficient screen real estate */
@media (max-width: 767px) {
    .im-imap-labels { display: none; }
}

/* ==========================================================================
   Tablet (768 – 1024px): legend → fixed side panel
   ========================================================================== */
@media (max-width: 1024px) and (min-width: 768px) {

    .im-imap-layout { flex-direction: column !important; }

    .im-imap-legend {
        position: fixed;
        top: 50%;
        right: -260px;
        transform: translateY(-50%);
        z-index: 200;
        max-width: 240px;
        max-height: 70vh;
        overflow-y: auto;
        box-shadow: -4px 0 24px rgba(0,0,0,.65);
        transition: right .3s ease;
    }

    .im-imap-legend.im-imap-legend-open { right: 0; }
    .im-imap-legend-close { display: block; }

    .im-imap-legend-toggle {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        position: fixed;
        top: 50%;
        right: 0;
        transform: translateY(-50%) rotate(-90deg);
        transform-origin: right center;
        background: rgba(10,6,4,.9);
        border: 1px solid rgba(242,202,80,.3);
        border-bottom: none;
        color: #f2ca50;
        font-size: .8rem;
        font-weight: 700;
        letter-spacing: .08em;
        padding: 6px 14px;
        cursor: pointer;
        z-index: 201;
        border-radius: 4px 4px 0 0;
    }
}

/* ==========================================================================
   Mobile (<768px): legend → bottom drawer
   ========================================================================== */
@media (max-width: 767px) {

    .im-imap-layout { flex-direction: column !important; }
    .im-imap-canvas-wrap { width: 100%; }

    .im-imap-legend {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        max-width: 100%;
        width: 100%;
        z-index: 200;
        border-radius: 12px 12px 0 0;
        transform: translateY(calc(100% - 48px));
        transition: transform .35s cubic-bezier(.4,0,.2,1);
        max-height: 65vh;
        overflow: hidden;
    }

    .im-imap-legend.im-imap-legend-open { transform: translateY(0); }
    .im-imap-legend-list { max-height: calc(65vh - 100px); overflow-y: auto; }
    .im-imap-legend-header { display: none; }

    .im-imap-drawer-handle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 20px;
        background: rgba(10,6,4,.97);
        border-top: 2px solid rgba(242,202,80,.3);
        cursor: pointer;
        font-size: .9rem;
        font-weight: 700;
        color: #f2ca50;
        letter-spacing: .06em;
        text-transform: uppercase;
        user-select: none;
    }

    .im-imap-drawer-arrow {
        font-size: .8rem;
        transition: transform .3s ease;
    }

    .im-imap-legend-toggle { display: none !important; }

    /* Popup slides up from bottom on mobile */
    .im-imap-popup {
        position: fixed !important;
        bottom: 60px !important;
        left: 50% !important;
        transform: translateX(-50%) translateY(20px) !important;
        top: auto !important;
        width: 88vw;
        max-width: 340px;
    }

    .im-imap-popup-visible {
        transform: translateX(-50%) translateY(0) !important;
    }

    /* Slightly smaller markers on mobile */
    .im-imap-marker {
        width:  calc(var(--im-marker-size, 30px) * 0.85) !important;
        height: calc(var(--im-marker-size, 30px) * 0.85) !important;
        font-size: calc(var(--im-marker-size, 30px) * 0.37) !important;
    }
}
