.tool-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.tool-grid > .map-card {
    order: 1;
}

.tool-grid > .controls-panel {
    order: 2;
}

@media (min-width: 992px) {
    .tool-grid {
        grid-template-columns: minmax(0, 1fr) 420px;
    }
}

.map-container {
    height: clamp(320px, 60vh, 640px);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
    background: #e6ebef;
}

.map-card {
    display: flex;
    position: relative;
}

.map-card .map-container {
    flex: 1 1 auto;
    height: auto;
    min-height: clamp(320px, 60vh, 640px);
}

/* Prevent global image rules from shrinking Leaflet tiles. */
.map-container .leaflet-container,
.map-container .leaflet-pane,
.map-container .leaflet-tile-pane,
.map-container .leaflet-layer,
.map-container .leaflet-tile {
    width: 100%;
    height: 100%;
}

.map-container .leaflet-tile {
    max-width: none !important;
    max-height: none !important;
}

/* Force raster tile visibility if external CSS or extensions alter rendering. */
.map-container .leaflet-layer,
.map-container .leaflet-tile {
    opacity: 1 !important;
    visibility: visible !important;
    filter: none !important;
    mix-blend-mode: normal !important;
}

.status-chip {
    font-size: 0.85rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--bs-border-color);
    background: var(--bs-tertiary-bg);
}

.map-canvas-actions {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 700;
}

.map-maximize-button {
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--bs-border-color);
    box-shadow: 0 0.2rem 0.75rem rgba(0, 0, 0, 0.2);
}

.map-maximize-button svg {
    width: 1rem;
    height: 1rem;
    fill: currentColor;
}

.tool-grid.map-maximized {
    position: fixed;
    top: var(--map-maximized-top, 0);
    right: 0;
    bottom: var(--site-footer-height, 60px);
    left: 0;
    z-index: 1100;
    display: block;
    display: grid;
    grid-template-columns: minmax(0, 1fr) min(30rem, 38vw);
    background: var(--bs-body-bg);
    margin: 0;
    gap: 1rem;
    padding: 1rem;
    align-items: stretch;
}

.tool-grid.map-maximized .map-card {
    position: relative;
    border-radius: 0;
    margin: 0;
    min-height: 0;
}

.tool-grid.map-maximized .map-container {
    height: 100%;
    min-height: 100%;
    border-radius: 0;
    border: 0;
}

.tool-grid.map-maximized .controls-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-height: 100%;
    overflow: auto;
    margin: 0;
    box-shadow: 0 0.9rem 2rem rgba(0, 0, 0, 0.25);
}

@media (max-width: 991.98px) {
    .tool-grid.map-maximized {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(40vh, 1fr) auto;
    }

    .tool-grid.map-maximized .map-card {
        min-height: 40vh;
    }

    .tool-grid.map-maximized .controls-panel {
        max-height: 45vh;
    }
}
