/* Responsive map workspace. Loaded after the active theme stylesheet. */
.map-page {
    --map-panel-width: 310px;
    max-width: 1800px;
    margin-inline: auto;
}

.map-page .text-light {
    color: var(--text) !important;
}

.map-page-header {
    min-height: 3.5rem;
}

.map-result-summary {
    color: var(--text);
    background: var(--surface);
    border: 1px solid rgba(212, 175, 55, 0.45);
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    font-size: 0.88rem;
    white-space: nowrap;
}

.map-workspace {
    display: grid;
    grid-template-columns: var(--map-panel-width) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}

.map-main {
    min-width: 0;
}

#legend.map-filter-panel {
    position: sticky;
    inset: auto;
    top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0;
    height: calc(100dvh - 7.5rem);
    min-height: 600px;
    padding: 1rem;
    overflow: auto;
    color: var(--text);
    background: var(--surface);
    border: 1px solid rgba(212, 175, 55, 0.45);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
    transform: none;
    visibility: visible;
    opacity: 1;
    z-index: 10;
}

.map-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding-bottom: 0.9rem;
}

.map-filter-close {
    display: none;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    font-size: 1.45rem;
    line-height: 1;
}

.map-filter-section {
    padding: 1rem 0;
    border-top: 1px solid rgba(212, 175, 55, 0.25);
}

.map-filter-title {
    margin: 0 0 0.7rem;
    color: var(--gold);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.map-filter-panel .form-switch {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 2.25rem;
}

.map-filter-panel .form-check-input {
    flex: 0 0 auto;
    margin: 0;
}

.map-filter-menu-btn {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    text-align: left;
}

.map-filter-panel .filter-dropdown {
    position: static !important;
    inset: auto !important;
    width: 100%;
    max-width: none;
    max-height: 17rem;
    margin-top: 0.35rem;
    overflow-y: auto;
    transform: none !important;
}

.map-status-filters {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
}

.map-page .status-filter-item {
    display: flex;
    min-width: 0;
    min-height: 5.25rem;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 0.25rem;
    color: var(--text);
    background: rgba(128, 128, 128, 0.08);
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
}

.map-page .status-filter-item:hover,
.map-page .status-filter-item:focus-visible {
    transform: none;
    border-color: rgba(212, 175, 55, 0.55);
    outline: none;
}

.map-page .status-filter-item.active {
    border-color: var(--gold);
}

.map-page .status-label {
    display: block;
    color: var(--text);
    font-size: 0.7rem;
    line-height: 1.15;
    text-shadow: none;
}

.map-toolbar {
    display: grid;
    grid-template-columns: minmax(250px, 1fr) auto minmax(145px, auto);
    gap: 0.65rem;
    align-items: end;
    margin-bottom: 0.65rem;
}

.map-search-wrap {
    position: relative;
    min-width: 0;
}

.map-search-wrap .form-control {
    min-height: 44px;
}

.map-search-results {
    position: absolute;
    z-index: 1200;
    top: calc(100% + 0.35rem);
    left: 0;
    right: 0;
    max-height: min(22rem, 55vh);
    overflow-y: auto;
    border: 1px solid rgba(212, 175, 55, 0.55);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.map-search-results .list-group-item {
    min-height: 48px;
    padding: 0.65rem 0.8rem;
}

.map-toolbar-actions {
    display: flex;
    gap: 0.4rem;
}

.map-toolbar-actions .btn {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    white-space: nowrap;
}

#toggle-legend-btn {
    display: none;
}

.map-provider-control {
    min-width: 145px;
}

.map-provider-control .form-label {
    display: block;
    color: var(--text);
    font-size: 0.72rem;
}

.map-provider-control .form-select {
    min-height: 44px;
}

.map-page #map {
    width: 100%;
    height: calc(100dvh - 10.5rem);
    min-height: 610px;
    overflow: hidden;
    border-width: 2px;
    border-radius: 14px;
}

/*
 * OpenLayers indsætter viewporten med height: 100%. Når kortets højde kommer
 * fra min-height i det responsive layout, kan procenthøjden ende som 0 px.
 * Absolutte kanter bruger containerens faktiske renderede højde og virker
 * derfor ens i normal- og fullscreenvisning.
 */
.map-page #map > .ol-viewport {
    position: absolute !important;
    inset: 0;
    width: auto !important;
    height: auto !important;
}

.map-state-overlay {
    position: absolute;
    z-index: 900;
    top: 0.75rem;
    left: 50%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    max-width: calc(100% - 2rem);
    padding: 0.6rem 0.85rem;
    color: var(--text);
    background: var(--surface);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border: 1px solid rgba(212, 175, 55, 0.55);
    border-radius: 999px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    transform: translateX(-50%);
    white-space: nowrap;
}

/* map-state-overlay har sin egen display-regel og indlæses efter temaet. */
.map-state-overlay.wk-hidden {
    display: none !important;
}

.map-page #map:fullscreen {
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
}

body.map-pseudo-fullscreen-open {
    overflow: hidden;
    overscroll-behavior: none;
}

.map-page #map.map-pseudo-fullscreen {
    position: fixed !important;
    z-index: 2000;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    max-height: none;
    border: 0;
    border-radius: 0;
}

.map-exit-fullscreen {
    position: absolute;
    z-index: 1100;
    top: max(0.75rem, env(safe-area-inset-top, 0px));
    right: max(0.75rem, env(safe-area-inset-right, 0px));
    display: none;
    min-width: 44px;
    height: 44px;
    padding: 0 0.8rem;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    color: #111;
    background: var(--gold-strong, #d4af37);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
    border: 2px solid #111;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.map-exit-fullscreen span:first-child {
    font-size: 1.65rem;
    font-weight: 400;
}

.map-page #map:fullscreen .map-exit-fullscreen,
.map-page #map.map-pseudo-fullscreen .map-exit-fullscreen,
.map-page #map.map-fullscreen-active .map-exit-fullscreen {
    display: inline-flex;
}

.map-page .ol-control button {
    width: 2.35rem;
    height: 2.35rem;
    font-size: 1.25rem;
}

.map-page .ol-zoom {
    top: 0.75rem;
    left: 0.75rem;
}

.map-page .popup-container {
    width: min(340px, 80vw);
    max-height: min(520px, 70dvh);
    padding: 1rem 2.4rem 1rem 1rem;
    overflow-y: auto;
}

.map-page .popup-container p {
    margin-bottom: 0.5rem;
}

.map-page .popup-close-btn {
    width: 30px;
    height: 30px;
    color: #111;
}

.map-filter-backdrop {
    display: none;
}

body.map-filters-open {
    overflow: hidden;
}

@media (min-width: 992px) {
    .map-page {
        display: flex;
        height: max(760px, calc(100dvh - 4rem));
        flex-direction: column;
    }

    .map-page-header {
        flex: 0 0 auto;
    }

    .map-workspace {
        min-height: 0;
        flex: 1 1 auto;
        align-items: stretch;
    }

    .map-main {
        display: flex;
        min-height: 0;
        flex-direction: column;
    }

    #legend.map-filter-panel {
        height: auto;
        min-height: 0;
        align-self: stretch;
    }

    .map-toolbar {
        flex: 0 0 auto;
    }

    .map-page #map {
        height: auto;
        flex: 1 1 auto;
    }
}

@media (max-width: 1199.98px) {
    .map-button-label {
        display: none;
    }

    .map-toolbar {
        grid-template-columns: minmax(220px, 1fr) auto 145px;
    }
}

@media (max-width: 991.98px) {
    .map-page {
        display: flex;
        height: max(620px, calc(100dvh - 4rem));
        flex: 0 0 auto;
        flex-direction: column;
        padding-top: 0.75rem !important;
    }

    .map-page-header p {
        font-size: 0.9rem;
    }

    .map-workspace {
        display: flex;
        min-height: 0;
        flex: 1 1 auto;
        align-items: stretch;
    }

    .map-main {
        display: flex;
        width: 100%;
        min-height: 0;
        flex: 1 1 auto;
        flex-direction: column;
    }

    #legend.map-filter-panel {
        position: fixed;
        z-index: 1210;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: auto;
        min-height: 0;
        max-height: min(82dvh, 760px);
        padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
        border-width: 1px 0 0;
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -12px 35px rgba(0, 0, 0, 0.45);
        transform: translateY(105%);
        visibility: hidden;
        opacity: 0;
        transition: transform 0.25s ease, opacity 0.2s ease, visibility 0.25s;
    }

    #legend.map-filter-panel.show {
        transform: translateY(0);
        visibility: visible;
        opacity: 1;
    }

    .map-filter-close,
    #toggle-legend-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .map-filter-backdrop {
        position: fixed;
        z-index: 1200;
        inset: 0;
        display: block;
        width: 100%;
        height: 100%;
        padding: 0;
        background: rgba(0, 0, 0, 0.55);
        border: 0;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s ease, visibility 0.2s;
    }

    .map-filter-backdrop.show {
        opacity: 1;
        visibility: visible;
    }

    .map-toolbar {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: stretch;
    }

    .map-search-wrap {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .map-toolbar-actions {
        grid-column: 1;
        grid-row: 2;
    }

    .map-provider-control {
        grid-column: 2;
        grid-row: 2;
    }

    .map-provider-control .form-label {
        display: none;
    }

    .map-page #map {
        height: auto;
        min-height: 360px;
        max-height: none;
        flex: 1 1 auto;
    }
}

@media (max-width: 575.98px) {
    .map-page .btn {
        width: auto;
    }

    .map-page-header {
        margin-bottom: 0.65rem !important;
    }

    .map-page-header h1 {
        font-size: 1.35rem;
    }

    .map-page-header p {
        display: none;
    }

    .map-result-summary {
        max-width: 100%;
        padding: 0.3rem 0.65rem;
        overflow: hidden;
        font-size: 0.78rem;
        text-overflow: ellipsis;
    }

    .map-toolbar {
        gap: 0.45rem;
        margin-bottom: 0.45rem;
    }

    .map-toolbar-actions {
        gap: 0.3rem;
    }

    .map-toolbar-actions .btn {
        min-width: 44px;
        padding-inline: 0.65rem;
    }

    .map-provider-control {
        min-width: 122px;
    }

    .map-provider-control .form-select {
        width: 122px;
        font-size: 0.75rem;
    }

    .map-page #map {
        border-width: 1px;
        border-radius: 10px;
    }

    .map-page .popup-container {
        width: min(88vw, 340px);
        max-height: 55dvh;
    }

    .map-page .popup-container .btn {
        flex: 1 1 auto;
        min-height: 42px;
    }

    .map-state-overlay {
        top: 0.55rem;
        font-size: 0.8rem;
    }
}

@media (max-height: 700px) and (max-width: 991.98px) {
    .map-page {
        height: max(560px, calc(100dvh - 4rem));
    }
}

@media (prefers-reduced-motion: reduce) {
    #legend.map-filter-panel,
    .map-filter-backdrop {
        transition: none;
    }
}
