* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: #f5f7fa;
    color: #222;
}

#application {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;

    padding: 18px 20px 14px;

    background: white;
    border-bottom: 1px solid #ddd;
}

.app-header h1 {
    margin: 0;
    font-size: 1.85rem;
    line-height: 1.15;
}

.eyebrow {
    margin: 0;
    color: #666;
    font-size: 12px;
    text-transform: uppercase;
}

.header-description {
    margin: 6px 0 0;
    color: #666;
    line-height: 1.35;
}

.secondary-button {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: #2563eb;
    color: white;
}

.controls-section {
    display: grid;
    gap: 10px;

    padding: 12px 20px 14px;

    background: white;
    border-bottom: 1px solid #ddd;
}

.section-heading {
    margin: 0 0 8px;
    font-size: 1.15rem;
    line-height: 1.2;
}

.disaster-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.disaster-button {
    border: none;
    border-radius: 999px;

    padding: 8px 14px;

    cursor: pointer;
    background: #d1d5db;
}

.disaster-button.selected {
    background: #2563eb;
    color: white;
}

.disaster-button.active-alert {
    border: 2px solid #dc2626;
}

.map-card {
    position: relative;
    flex: 1;
    min-height: 0;
}

#map {
    width: 100%;
    height: calc(100vh - 270px);
    min-height: 430px;
}

.map-empty-state {
    position: absolute;
    top: 12px;
    left: 50%;
    z-index: 1000;

    max-width: calc(100% - 140px);
    padding: 9px 12px;

    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);

    font-size: 0.9rem;
    text-align: center;

    transform: translateX(-50%);
}

.hidden {
    display: none;
}

.map-legend {
    position: absolute;

    bottom: calc(
        14px
        + var(
            --visible-resource-panel-height,
            0px
        )
    );

    left: 14px;
    z-index: 1000;

    max-width: 220px;
    max-height: calc(
        100%
        - var(
            --visible-resource-panel-height,
            0px
        )
        - 28px
    );

    padding: 12px;

    overflow-y: auto;

    background: white;
    border-radius: 8px;

    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.15);

    transition:
        bottom 0.2s ease,
        max-height 0.2s ease;
}

.map-legend strong {
    display: block;
    margin-bottom: 3px;
}

.map-card {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: white;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.legend-row[hidden] {
    display: none !important;
}

.legend-symbol {
    width: 16px;
    height: 16px;
    display: inline-block;
}

.resource-panel {
    --resource-panel-height: 52vh;

    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;

    height: var(--resource-panel-height);
    max-height: calc(100vh - 20px);
    min-height: 90px;

    display: flex;
    flex-direction: column;

    background: white;

    border-top-left-radius: 16px;
    border-top-right-radius: 16px;

    box-shadow:
        0 -4px 20px rgba(0, 0, 0, 0.25);

    transform: translateY(100%);
    transition:
        transform 0.3s ease,
        height 0.2s ease;

    z-index: 2000;
    overflow: hidden;
}

.resource-panel.open {
    transform: translateY(0);
}

.resource-panel.dragging {
    transition: none;
    user-select: none;
}

.resource-panel-handle {
    position: relative;
    flex: 0 0 auto;

    min-height: 54px;
    padding: 10px 16px 8px;

    cursor: ns-resize;
    touch-action: none;

    background: white;
    border-bottom: 1px solid #e5e7eb;
}

.panel-drag-indicator {
    width: 48px;
    height: 5px;

    margin: 0 auto;

    border-radius: 999px;
    background: #cbd5e1;
}

.panel-toolbar {
    position: absolute;
    top: 8px;
    right: 16px;

    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-size-button,
.panel-close-button {
    width: 34px;
    height: 34px;

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

    border: none;
    border-radius: 50%;

    background: #f1f5f9;
    color: #1f2937;

    font-size: 20px;
    line-height: 1;

    cursor: pointer;
}

.panel-size-button:hover,
.panel-close-button:hover {
    background: #e2e8f0;
}

.panel-size-button:focus-visible,
.panel-close-button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.35);
    outline-offset: 2px;
}

.resource-panel-content {
    flex: 1;
    min-height: 0;

    padding: 6px 24px 24px;

    overflow-y: auto;
    overscroll-behavior: contain;
}

.resource-type {
    color: #666;
    text-transform: uppercase;
    font-size: 12px;
}

.resource-details dt {
    font-weight: bold;
    margin-top: 12px;
}

.resource-details dd {
    margin-left: 0;
    margin-top: 4px;
}

.route-planner {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.route-planner h3 {
    margin: 0 0 14px;
    font-size: 1.1rem;
}

.route-planner > label {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
}

#routeOriginAddress {
    width: 100%;
    padding: 11px 12px;

    border: 1px solid #cbd5e1;
    border-radius: 8px;

    background: white;
    color: #222;

    font: inherit;
}

#routeOriginAddress:focus {
    outline: 3px solid rgba(37, 99, 235, 0.18);
    border-color: #2563eb;
}

.travel-mode-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;

    margin: 16px 0;
    padding: 0;

    border: 0;
}

.travel-mode-options legend {
    width: 100%;
    margin-bottom: 8px;
    font-weight: 700;
}

.travel-mode-options label {
    display: inline-flex;
    align-items: center;
    gap: 7px;

    padding: 9px 13px;

    border: 1px solid #cbd5e1;
    border-radius: 999px;

    background: #f8fafc;
    cursor: pointer;
}

.travel-mode-options label:has(input:checked) {
    border-color: #2563eb;
    background: #dbeafe;
    color: #1d4ed8;
}

.travel-mode-options input {
    margin: 0;
}

.route-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

#showRouteButton,
#clearRouteButton {
    min-height: 40px;
    padding: 10px 16px;

    border-radius: 8px;
    cursor: pointer;

    font: inherit;
    font-weight: 700;
}

#showRouteButton {
    border: 0;
    background: #2563eb;
    color: white;
}

#showRouteButton:hover {
    background: #1d4ed8;
}

#showRouteButton:disabled {
    opacity: 0.65;
    cursor: wait;
}

#clearRouteButton {
    border: 1px solid #cbd5e1;
    background: white;
    color: #334155;
}

#clearRouteButton:hover {
    background: #f1f5f9;
}

.selected-resource-pin-symbol {
    position: relative;

    width: 14px;
    height: 18px;

    margin-left: 1px;
    margin-right: 1px;

    background: #3b82c4;
    border: 2px solid white;
    border-radius: 50% 50% 50% 0;

    box-shadow:
        0 0 0 1px #1d4f91;

    transform: rotate(-45deg);
}

.selected-resource-pin-symbol::after {
    content: '';

    position: absolute;
    top: 4px;
    left: 4px;

    width: 4px;
    height: 4px;

    background: white;
    border-radius: 50%;
}

.route-start-symbol {
    width: 16px;
    height: 16px;

    background: #f4d03f;
    border: 2px solid #8a6d00;
    border-radius: 50%;
}

.route-status {
    min-height: 20px;
    margin: 12px 0 0;

    color: #475569;
    font-size: 0.92rem;
    line-height: 1.4;
}

.route-status.error {
    color: #b91c1c;
}

.route-warning {
    margin: 12px 0 0;
    padding: 10px 12px;

    border-left: 4px solid #f59e0b;
    border-radius: 4px;

    background: #fffbeb;
    color: #78350f;

    font-size: 0.86rem;
    line-height: 1.4;
}

.active-route-symbol {
    width: 20px;
    height: 6px;

    border-top: 2px solid white;
    border-bottom: 2px solid white;

    background: #0f172a;
}

.tsunami-safe-symbol {
    background: #4ade80;
    border: 2px solid #15803d;
}

.airport-symbol {
    background: #a78bfa;
    border: 2px dashed #6d28d9;
}

.refuge-symbol,
.fire-station-symbol,
.police-station-symbol,
.hospital-symbol,
.airport-destination-symbol {
    width: 16px;
    height: 16px;
    border-radius: 50%;
}

.refuge-symbol {
    background: #60a5fa;
    border: 2px solid #1d4ed8;
}

.fire-station-symbol {
    background: #f97316;
    border: 2px solid #c2410c;
}

.police-station-symbol {
    background: #6366f1;
    border: 2px solid #3730a3;
}

.hospital-symbol {
    background: #ef4444;
    border: 2px solid #b91c1c;
}

.airport-destination-symbol {
    background: #a78bfa;
    border: 2px solid #6d28d9;
}

.leaflet-tooltip {
    pointer-events: none;
    white-space: nowrap;
    border: 0;
    border-radius: 6px;
    padding: 6px 9px;
    box-shadow: 0 2px 8px rgb(0 0 0 / 18%);
    font-size: 0.85rem;
    font-weight: 600;
}

.resource-tooltip {
    pointer-events: none;
    white-space: nowrap;

    padding: 7px 10px;

    background: white;
    border: 1px solid #d1d5db;
    border-radius: 6px;

    font-size: 0.85rem;
    font-weight: 700;
    color: #222;

    box-shadow: 0 3px 10px rgb(0 0 0 / 22%);
}

@media (max-width: 600px) {
    /*
     * Header
     */

    .app-header {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;

        padding: 16px;
    }

    .app-header h1 {
        font-size: 1.55rem;
        line-height: 1.08;
    }

    .header-description {
        margin-top: 7px;

        font-size: 0.93rem;
        line-height: 1.4;
    }

    .secondary-button {
        align-self: flex-end;

        min-height: 42px;
        padding: 10px 15px;

        font-size: 0.9rem;
    }


    /*
     * Disaster controls
     */

    .controls-section {
        padding: 12px 16px 13px;
        overflow: hidden;
    }

    .section-heading {
        margin-bottom: 9px;
        font-size: 1rem;
    }

    .disaster-buttons {
        flex-wrap: nowrap;
        gap: 8px;

        width: 100%;
        padding-bottom: 4px;

        overflow-x: auto;
        overscroll-behavior-x: contain;
        scroll-snap-type: x proximity;
        scrollbar-width: thin;

        -webkit-overflow-scrolling: touch;
    }

    .disaster-button {
        flex: 0 0 auto;
        scroll-snap-align: start;

        min-height: 40px;
        padding: 8px 14px;

        font-size: 0.84rem;
        white-space: nowrap;
    }


    /*
     * Map
     */

    .map-card {
        flex: none;
    }

    #map {
        height: calc(100dvh - 265px);
        min-height: 390px;
    }

    .map-empty-state {
        top: 12px;
        left: 58px;
        right: 10px;

        max-width: none;
        padding: 9px 11px;

        transform: none;

        font-size: 0.82rem;
        line-height: 1.3;
        text-align: left;
    }

    .leaflet-control-zoom a {
        width: 38px;
        height: 38px;
        line-height: 38px;

        font-size: 22px;
    }


    /*
     * Compact mobile legend
     */

    .map-legend {
        left: 10px;

        /*
        * Keep the legend above the visible panel,
        * plus extra room for the panel handle and toolbar.
        */
        bottom: calc(
            70px
            + var(
                --visible-resource-panel-height,
                0px
            )
        );

        width: auto;
        min-width: 156px;
        max-width: 185px;

        max-height: min(
            42vh,
            calc(
                100%
                - var(
                    --visible-resource-panel-height,
                    0px
                )
                - 90px
            )
        );

        padding: 9px 10px;

        overflow-y: auto;
        overscroll-behavior: contain;

        border-radius: 9px;

        font-size: 0.76rem;
        line-height: 1.15;

        transition:
            bottom 0.2s ease,
            max-height 0.2s ease;
    }

    .map-legend strong {
        margin-bottom: 4px;
        font-size: 0.86rem;
    }

    .legend-row {
        gap: 6px;
        margin-top: 5px;
    }

    .legend-symbol,
    .refuge-symbol,
    .fire-station-symbol,
    .police-station-symbol,
    .hospital-symbol,
    .airport-destination-symbol,
    .route-start-symbol {
        flex: 0 0 auto;

        width: 13px;
        height: 13px;
    }

    .selected-resource-pin-symbol {
        flex: 0 0 auto;

        width: 12px;
        height: 16px;
    }

    .selected-resource-pin-symbol::after {
        top: 3px;
        left: 3px;

        width: 4px;
        height: 4px;
    }

    .active-route-symbol {
        flex: 0 0 auto;

        width: 17px;
        height: 5px;
    }


    /*
     * Sliding resource panel
     */

    .resource-panel {
        --resource-panel-height: 58vh;

        max-height: calc(100dvh - 8px);

        border-top-left-radius: 14px;
        border-top-right-radius: 14px;
    }

    .resource-panel-handle {
        min-height: 52px;
        padding: 9px 12px 7px;
    }

    .panel-toolbar {
        top: 8px;
        right: 12px;
    }

    .panel-size-button,
    .panel-close-button {
        width: 38px;
        height: 38px;

        font-size: 21px;
    }

    .resource-panel-content {
        padding:
            4px
            16px
            calc(24px + env(safe-area-inset-bottom));

        font-size: 0.94rem;
    }

    .resource-panel-content h2 {
        margin-top: 8px;
        margin-bottom: 10px;

        font-size: 1.35rem;
        line-height: 1.15;
    }

    .resource-type {
        margin-top: 10px;
        font-size: 0.72rem;
    }

    .resource-details dt {
        margin-top: 10px;
    }


    /*
     * Mobile route form
     */

    .route-planner {
        margin-top: 20px;
        padding-top: 16px;
    }

    #routeOriginAddress {
        min-height: 46px;
        font-size: 16px;
    }

    .travel-mode-options {
        gap: 8px;
        margin: 14px 0;
    }

    .travel-mode-options label {
        min-height: 42px;
        padding: 8px 12px;
    }

    .route-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 9px;
    }

    #showRouteButton,
    #clearRouteButton {
        width: 100%;
        min-height: 44px;
        padding: 10px 12px;
    }

    .route-warning {
        font-size: 0.8rem;
    }
}

@media (max-width: 400px) {
    .app-header h1 {
        font-size: 1.4rem;
    }

    .header-description {
        font-size: 0.88rem;
    }

    #map {
        height: calc(100dvh - 250px);
        min-height: 370px;
    }

    .map-legend {
        bottom: calc(
            74px
            + var(
                --visible-resource-panel-height,
                0px
            )
        );

        max-height: min(
            38vh,
            calc(
                100%
                - var(
                    --visible-resource-panel-height,
                    0px
                )
                - 94px
            )
        );
    }

    .route-actions {
        grid-template-columns: 1fr;
    }
}

.pdf-map-container {
    position: fixed;
    left: -10000px;
    top: 0;

    width: 1400px;
    height: 700px;

    background: white;
    overflow: hidden;
    pointer-events: none;
}