.jwa-portfolio-map {
    align-items: center;
    padding: 6rem clamp(1.5rem, 5vw, 3.5rem);
}

/* KPI container */
.jwa-portfolio-map__kpis {
    display: flex;
    margin-top: 3rem;
    border-top: 1px solid var(--wp--preset--color--gray-lighter);
    border-bottom: 1px solid var(--wp--preset--color--gray-lighter);
    position: relative;
    transition:
        opacity 0.45s ease,
        transform 0.5s ease;
}

/* Two-column layout (default) */
.jwa-portfolio-map__kpis--two-col {
    flex-direction: row;
}

/* Stacked layout for 3+ KPIs: visually match provided design */
.jwa-portfolio-map__kpis--stacked {
    flex-direction: column;
}

.jwa-portfolio-map__kpis--stacked .jwa-portfolio-map__kpi {
    display: grid;
    grid-template-columns: 1fr 2fr;
    align-items: center;
    text-align: left;
    gap: 18px;
}

.jwa-portfolio-map__kpis--stacked .jwa-portfolio-map__kpi-label {
    text-align: right;
    margin-top: 0;
}

.jwa-portfolio-map__kpis--stacked .jwa-portfolio-map__kpi-value {
    width: 30%;
    font-size: clamp(2.4rem, 5.5vw, 3.5rem);
}

.jwa-portfolio-map__kpi {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 1;
    padding: 0.25rem .5rem;
}

.jwa-portfolio-map__kpi:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 1px;
    background-color: var(--wp--preset--color--gray-lighter);
}

@media (max-width: 559px) {
  .jwa-portfolio-map__kpi:not(:last-child)::after {
    background: none;
  }
}

.jwa-portfolio-map__kpis--stacked .jwa-portfolio-map__kpi:not(:last-child)::after {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 1px;
}

.jwa-portfolio-map__kpis--stacked .jwa-portfolio-map__kpi:not(:last-child)::after {
    /* horizontal divider in stacked mode */
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 1px;
}

.jwa-portfolio-map__kpi-value,
.jwa-portfolio-map__kpi-label {
    text-align: center;
}

.jwa-portfolio-map__kpi-label {
    margin-top: 0.75rem;
}

.jwa-portfolio-map__kpis--stacked .jwa-portfolio-map__kpi-value {
    text-align: left;
}

.jwa-portfolio-map__kpis--stacked .jwa-portfolio-map__kpi-label {
    text-align: left;
}

.jwa-portfolio-map__kpis--left-align .jwa-portfolio-map__kpi {
    align-items: flex-start;
    text-align: left;
}

.jwa-portfolio-map__kpis--left-align .jwa-portfolio-map__kpi-value,
.jwa-portfolio-map__kpis--left-align .jwa-portfolio-map__kpi-label {
    text-align: left;
}

.jwa-portfolio-map__map-container {
    width: 100%;
}

.jwa-portfolio-map__map {
    width: 100%;
    height: auto;
}

.jwa-portfolio-map__map .state {
    /* Use explicit map fill color per request */
    fill: #e9e8e7;
    @apply stroke-gray-lighter;
    stroke-width: 0.5px;
}

.dark .jwa-portfolio-map__map .state {
    /* Keep same fill in dark mode for consistency */
    fill: #e9e8e7;
    @apply stroke-medium-blue;
}

/* Borders overlay for better definition */
.jwa-portfolio-map__map .state-borders {
    vector-effect: non-scaling-stroke;
    stroke: #bfc6cf;
    stroke-width: 0.6px;
    fill: none;
}

.dark .jwa-portfolio-map__map .state-borders {
    stroke: #6a8cbc;
}

.jwa-portfolio-map__map .location-dot-group {
    pointer-events: none;
}

.jwa-portfolio-map__map-container {
    position: relative;
}

/* Overlay mode: stack SVG over fallback to avoid vertical jump */
.jwa-portfolio-map[data-overlay] .jwa-portfolio-map__map-container {
    position: relative;
}

.jwa-portfolio-map[data-overlay] .jwa-portfolio-map__map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* During overlay fade, keep container height locked; TS will remove data-overlay after done */

.jwa-portfolio-map__map,
.jwa-portfolio-map__fallback {
    transition:
        opacity 0.6s ease,
        transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: opacity, transform;
}

.jwa-portfolio-map__fallback {
    display: block;
    opacity: 1;
}

.jwa-portfolio-map__map {
    opacity: 0;
}

[data-map-stage='rendered'] .jwa-portfolio-map__map,
[data-map-stage='fading-out-fallback'] .jwa-portfolio-map__map,
[data-map-stage='done'] .jwa-portfolio-map__map {
    opacity: 1;
}

[data-map-stage='fading-out-fallback'] .jwa-portfolio-map__fallback {
    opacity: 0;
}

[data-map-stage='done'] .jwa-portfolio-map__fallback {
    display: none;
}

.jwa-portfolio-map__legend {
    display: flex;
    gap: 2rem;
    margin-top: 1.25rem;
    padding-top: 0.75rem;
    justify-content: center;
    margin-left: auto;
    margin-right: auto;
    flex-wrap: wrap;
    transition:
        opacity 0.45s ease,
        transform 0.5s ease;
}

.jwa-portfolio-map__legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    line-height: 1.2;
    @apply text-gray-medium;
}

.dark .jwa-portfolio-map__legend-item {
    @apply text-blue-lighter;
}

.jwa-portfolio-map__legend-dot {
    position: relative;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--wp--preset--color--gray-light);
}

.dark .jwa-portfolio-map__legend-dot {
    background-color: var(--wp--preset--color--gray-light);
}

.jwa-portfolio-map__legend-dot--active {
    background-color: var(--wp--preset--color--primary);
}

.dark .jwa-portfolio-map__legend-dot--active {
    background-color: var(--wp--preset--color--vibrant-light-blue);
}

/* Explicit inactive style (gray) */
.jwa-portfolio-map__legend-dot--inactive {
    background-color: var(--wp--preset--color--gray-light);
}

/* Use inner element for white highlight */
.jwa-portfolio-map__legend-dot-inner {
    display: block;
    width: 5px;
    height: 5px;
    background: #fff;
    border-radius: 999px;
}

/* Slight spacing so labels don't crowd the dot */
.jwa-portfolio-map__legend-item .jwa-portfolio-map__legend-dot {
    margin-right: 0.4rem;
}

/* Animate KPI + legend only if map stages are present; otherwise show immediately */
[data-map-stage] .jwa-portfolio-map__kpis,
[data-map-stage] .jwa-portfolio-map__legend {
    opacity: 0;
    transform: translateY(10px);
}

[data-map-stage='rendered'] .jwa-portfolio-map__kpis,
[data-map-stage='fading-out-fallback'] .jwa-portfolio-map__kpis,
[data-map-stage='done'] .jwa-portfolio-map__kpis,
[data-map-stage='rendered'] .jwa-portfolio-map__legend,
[data-map-stage='fading-out-fallback'] .jwa-portfolio-map__legend,
[data-map-stage='done'] .jwa-portfolio-map__legend {
    opacity: 1;
    transform: translateY(0);
}

/* Editor / ACF preview: ensure always visible (no staging attributes there) */
.acf-block-preview .jwa-portfolio-map__kpis,
.acf-block-preview .jwa-portfolio-map__legend,
.block-editor-block-preview__content .jwa-portfolio-map__kpis,
.block-editor-block-preview__content .jwa-portfolio-map__legend {
    opacity: 1 !important;
    transform: none !important;
}

/* Mobile (below 560px): stack KPIs vertically */
@media (max-width: 559px) {
    .jwa-portfolio-map__kpis {
        flex-direction: column;
        margin-top: 2rem;
    }

    .jwa-portfolio-map__kpi {
        padding: 1.15rem 0 1.25rem;
    }

    .jwa-portfolio-map__kpi-value {
        font-size: clamp(2.2rem, 11vw, 3.2rem);
    }

    .jwa-portfolio-map__legend {
        gap: 1.25rem;
        font-size: 0.75rem;
    }
}

/* Ultra-small devices (≤380px) tighten legend further */
@media (max-width: 380px) {
    .jwa-portfolio-map__legend {
        gap: 0.75rem;
    }

    .jwa-portfolio-map__legend-item {
        gap: 0.4rem;
    }
}
