/* Ensure navbar (and its mobile dropdown) always appears above the map overlay */
.navbar {
    position: relative;
    z-index: 1100;
}

/* ── Mobile navbar: floating dropdown style ── */
@media (max-width: 768px) {
    .navbar-collapse {
        position: absolute;
        top: 100%;
        right: 0.5rem;
        width: auto;
        min-width: 10rem;
        background: #d0e4f7;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        padding: 0.5rem 0;
        z-index: 1050;
    }

    .navbar-collapse .nav-link {
        padding: 0.4rem 1rem;
        color: #1a1a1a;
    }

    .navbar-collapse .nav-link:hover {
        background: rgba(255, 255, 255, 0.4);
    }

    .navbar-collapse .dropdown-menu {
        background: transparent;
        box-shadow: none;
        border: none;
        padding: 0;
    }

    .navbar-collapse .dropdown-item {
        padding: 0.35rem 1.5rem;
        font-size: 0.9rem;
    }

    .navbar-collapse .dropdown-item:hover {
        background: rgba(255, 255, 255, 0.4);
    }
}

.map-overlay {
    position: absolute;
    top: 5rem;
    left: 1.5rem;
    width: 400px;

    background: white;
    border-radius: 12px;
    padding: 0.5rem 0.625rem;

    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

/* ── Overlay accordion: halved padding on header + body ── */
.map-overlay .accordion-button {
    padding: 0.5rem 0.625rem;
}
.map-overlay .accordion-body {
    padding: 0.5rem 0.625rem;
}

/* ── Mobile overlay toggle tab ── */
.map-overlay-toggle {
    display: none;           /* hidden on desktop */
}

@media (max-width: 768px) {
    .map-overlay {
        width: calc(100% - 1rem);
        left: 0.5rem;
        top: 4.0rem;
        padding: 0.25rem 0.5rem;
        max-height: calc(100% - 5rem);
        overflow-y: auto;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    .map-overlay.collapsed {
        transform: translateY(-100%);
        opacity: 0;
        pointer-events: none;
    }

    /* Remove inner scroll on section details so only the overlay scrolls */
    .map-overlay #section-details-text {
        max-height: none;
        overflow-y: visible;
    }

    .map-overlay-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 0.8rem;
        right: 4.8rem;
        width: 2.1rem;
        height: 2.1rem;
        background: white;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        cursor: pointer;
        font-size: 1.3rem;
        color: #555;
        z-index: 1200;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    .map-overlay-toggle:active {
        background: #eee;
    }

    /* Tighter accordion spacing on mobile */
    .map-overlay .accordion-button {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }

    .map-overlay .accordion-body {
        padding: 0.5rem 0.75rem;
    }

    /* Reduce internal spacing within options */
    .map-overlay .mt-3 {
        margin-top: 0.5rem !important;
    }

    .map-overlay .mt-2 {
        margin-top: 0.25rem !important;
    }

    .map-overlay .my-3 {
        margin-top: 0.5rem !important;
        margin-bottom: 0.5rem !important;
    }
}

/* ── Loading overlay: visible until real map data arrives ── */
.map-loading-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 500;                      /* above leaflet panes, below .map-overlay (1000) */

    background-size: cover;
    background-position: center;
    filter: brightness(0.6);

    display: flex;
    align-items: center;
    justify-content: center;

    transition: opacity 0.4s ease;
}

.map-loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.map-loading-overlay__label {
    filter: brightness(1.67);          /* counteract parent brightness(0.6) */
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-shadow: 0 1px 6px rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.map-loading-overlay__spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid rgba(255,255,255,0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: overlay-spin 0.9s linear infinite;
}

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

/* ── Leaflet polyline hover effect ── */
.leaflet-interactive:hover {
    stroke-width: 8 !important;
    stroke-opacity: 0.7 !important;
}


/* ── Map legend (top-right overlay) ── */
.map-legend {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 500;
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 6px;
    padding: 0.5rem 0.6rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 0.85rem;
    max-width: 12rem;
    pointer-events: auto;
}
.map-legend:empty {
    display: none;
}
.map-legend-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #333;
}
.map-legend-list {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.map-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.15rem 0.25rem;
    background: transparent;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    text-align: left;
    color: #222;
    font: inherit;
}
.map-legend-item:hover {
    background: rgba(0,0,0,0.06);
}
.map-legend-swatch {
    display: inline-block;
    width: 1rem;
    height: 0.35rem;
    border-radius: 1px;
    flex-shrink: 0;
}
.map-legend-label {
    white-space: nowrap;
}

/* ── Legend visibility toggles ── */
.map-legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}
.map-legend-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.map-legend-row .map-legend-item {
    flex: 1;
    min-width: 0;
}
.map-legend-eye {
    background: transparent;
    border: none;
    color: #555;
    padding: 0.1rem 0.25rem;
    cursor: pointer;
    line-height: 1;
    font-size: 1rem;
    border-radius: 3px;
}
.map-legend-eye:hover {
    background: rgba(0,0,0,0.06);
    color: #000;
}
.map-legend-eye-master {
    color: #333;
}
.map-legend-label-hidden {
    color: #aaa;
    text-decoration: line-through;
}

.map-region-auto-switch {
    margin-bottom: 0;
    min-height: 0;
}

.map-region-auto-switch .form-check-label {
    font-size: 0.85rem;
    color: #444;
}

/* ── Archive map legend: long region-grouped mission list ── */
.archive-map-legend {
    max-width: 22rem;
    width: min(22rem, calc(100vw - 1.5rem));
    max-height: calc(100% - 1.5rem);
    overflow-y: auto;
}

.archive-mobile-legend-item {
    display: none;
}

.archive-map-legend-mobile {
    max-height: 46vh;
    overflow-y: auto;
}

.archive-map-legend .map-legend-header {
    position: sticky;
    top: -0.5rem;
    background: rgba(255,255,255,0.96);
    z-index: 1;
    padding-top: 0.1rem;
    padding-bottom: 0.2rem;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
}

.archive-map-legend-master-summary {
    list-style: none;
    cursor: pointer;
    align-items: center;
}

.archive-map-legend-master-summary::-webkit-details-marker {
    display: none;
}

.archive-map-legend-master-summary::before {
    content: "▸";
    color: #111;
    font-size: 0.9rem;
    font-weight: 400;
    line-height: 1;
}

.archive-map-legend-master[open] > .archive-map-legend-master-summary::before {
    content: "▾";
}

.archive-map-legend-region {
    border-top: 1px solid rgba(0,0,0,0.1);
    padding: 0.15rem 0;
}

.archive-map-legend-region-header {
    padding: 0.25rem 0;
    font-size: 0.82rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 0.35rem;
    align-items: center;
}

.archive-map-legend-region-toggle {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.35rem;
    align-items: center;
    min-width: 0;
    padding: 0;
    background: transparent;
    border: none;
    color: #222;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.archive-map-legend-region-toggle:hover {
    color: #000;
}

.archive-map-legend-chevron {
    color: #666;
    font-size: 0.75rem;
}

.map-legend-region-title {
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-legend-region-count {
    color: #666;
    font-size: 0.75rem;
}

.archive-map-legend-list {
    gap: 0.05rem;
}

.archive-map-legend .map-legend-row {
    align-items: stretch;
}

.archive-map-legend .map-legend-item {
    min-height: 2rem;
    padding: 0.15rem 0.2rem;
}

.archive-map-legend .map-legend-item:disabled,
.archive-map-legend .map-legend-eye:disabled {
    cursor: default;
    opacity: 0.55;
}

.archive-legend-label-block {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}

.archive-legend-date {
    color: #666;
    font-size: 0.72rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-legend-row-disabled .archive-legend-date,
.map-legend-row-disabled .map-legend-label {
    color: #999;
}

.archive-legend-zoom {
    color: #333;
}

.archive-year-slider {
    padding: 0.25rem 0.25rem 1.5rem;
}

@media (max-width: 768px) {
    .archive-map-legend {
        display: none;
    }

    .archive-mobile-legend-item {
        display: block;
    }

    .archive-map-legend-mobile {
        display: block;
        position: static;
        width: 100%;
        max-width: none;
        max-height: none;
        overflow: visible;
        padding: 0;
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .archive-map-legend-mobile .map-legend-header {
        top: 0;
    }
}
