/* The look follows vizsim/unfallkarte, so the vizsim maps read as a family: the
   same colours, cards, headings, popups and tooltips. Layout and controls are this
   map's own: panel on the left, timeline at the bottom. */

:root {
    --ui-surface: #ffffff;
    --ui-border: #e3e5e9;
    --ui-divider: #eceef1;
    --ui-shadow: 0 14px 40px rgba(15, 23, 42, 0.18);
    --ui-shadow-sm: 0 6px 16px rgba(0, 0, 0, 0.12);
    --ui-radius: 16px;
    --ui-radius-sm: 12px;
    --ui-text: #1f2937;
    --ui-text-strong: #111827;
    --ui-text-muted: #6b7280;
    --ui-text-sub: #374151;
    --ui-accent: #1d4ed8;
    --ui-accent-hover: #1e40af;
    --ui-accent-soft: rgba(29, 78, 216, 0.12);
    --ui-hover: #f3f4f6;
    --ui-focus: #2563eb;

    --panel-width: 340px;
    --edge: 10px;
    /* Measured by ui.js: the timeline's height, and the room the attribution
       takes from the bottom edge. The fallbacks are their usual sizes. */
    --timeline-h: 150px;
    --corner-h: 34px;
    /* The timeline sits on the attribution, which needs one line or, open on a
       narrow screen, several. */
    --tl-bottom: max(34px, var(--corner-h));
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ui-text);
}

#map {
    position: absolute;
    inset: 0;
}

button,
select {
    font: inherit;
}

:focus-visible {
    outline: 2px solid var(--ui-focus);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

/* ───── Loading and errors ───── */

.loading {
    position: absolute;
    top: 12px;
    /* Centred in the map area right of the panel. */
    left: calc(50% + (var(--panel-width) + var(--edge)) / 2);
    transform: translateX(-50%);
    z-index: 4;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 13px;
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: 999px;
    box-shadow: var(--ui-shadow-sm);
    font-size: 12px;
    color: var(--ui-text-muted);
    pointer-events: none;
}

.loading.is-visible {
    display: flex;
}

.loading-spinner {
    width: 13px;
    height: 13px;
    flex: none;
    border: 2px solid var(--ui-accent-soft);
    border-top-color: var(--ui-accent);
    border-radius: 50%;
    animation: loading-spin 0.7s linear infinite;
}

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

.fatal {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    max-width: min(92vw, 560px);
    padding: 10px 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--ui-radius-sm);
    box-shadow: var(--ui-shadow-sm);
    color: #991b1b;
    font-size: 13px;
    line-height: 1.4;
}

/* ───── Panel ───── */

.legend {
    position: absolute;
    top: var(--edge);
    left: var(--edge);
    z-index: 3;
    width: var(--panel-width);
    max-width: calc(100% - 2 * var(--edge));
    /* Ends above the scale bar, which MapLibre places bottom left. */
    max-height: calc(100% - 2 * var(--edge) - 34px);
    /* No padding on top: the sticky title row carries it, or content would show
       through a gap above it while scrolling. */
    padding: 0 16px 12px;
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow);
    font-size: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}

.legend::-webkit-scrollbar {
    width: 10px;
}

.legend::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 999px;
    border: 3px solid var(--ui-surface);
}

.legend.collapsed .legend-body,
.legend.collapsed .legend-footer {
    display: none;
}

.legend-title {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 -16px;
    padding: 14px 16px 10px;
    background: var(--ui-surface);
    cursor: pointer;
}

/* A soft shadow under the title while the panel scrolls beneath it; a line would
   double up with the first section's divider. */
.legend:not(.collapsed) .legend-title {
    box-shadow: 0 6px 10px -8px rgba(15, 23, 42, 0.45);
}

.grow {
    flex: 1 1 auto;
    min-width: 0;
}

.legend-heading {
    margin: 0 0 4px;
    line-height: 0;
}

.legend-heading img {
    display: block;
    width: auto;
    height: 40px;
    margin-left: -3px;
}

.legend-subtext {
    font-size: 12px;
    line-height: 1.4;
    color: var(--ui-text-muted);
}

/* The ⓘ is drawn with CSS: the Unicode glyph is missing from many system fonts. */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 11px;
    height: 11px;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 8px;
    font-weight: 400;
    font-style: normal;
    line-height: 1;
    letter-spacing: 0;
    text-transform: none;
    vertical-align: middle;
    color: var(--ui-text-muted);
    cursor: help;
    user-select: none;
}

/* Chevron as an SVG mask on ::before, so the focus ring is not masked with it.
   Open points down, folded points left. */
.toggle-arrow {
    --arrow-color: #9ca3af;
    position: relative;
    flex: none;
    display: inline-block;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    background: none;
    transform: rotate(90deg);
    transition: transform 0.2s ease;
    cursor: pointer;
}

.toggle-arrow::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--arrow-color);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4 6.5 10 12.5 16 6.5' fill='none' stroke='%23000' stroke-width='5.5' stroke-linecap='round' stroke-linejoin='miter'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4 6.5 10 12.5 16 6.5' fill='none' stroke='%23000' stroke-width='5.5' stroke-linecap='round' stroke-linejoin='miter'/%3E%3C/svg%3E") center / contain no-repeat;
}

.toggle-arrow.open {
    transform: rotate(0deg);
}

.toggle-arrow:hover {
    --arrow-color: #6b7280;
}

.toggle-arrow:focus-visible {
    outline-offset: 4px;
}

.toggle-root {
    width: 24px;
    height: 24px;
    margin-top: 6px;
}

@media (prefers-reduced-motion: reduce) {
    .toggle-arrow {
        transition: none;
    }

    .loading-spinner {
        animation: none;
    }
}

/* ───── Sections ───── */

.legend-section {
    padding: 10px 0;
    border-top: 1px solid var(--ui-divider);
}

.legend-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
    color: var(--ui-text-strong);
    cursor: pointer;
    user-select: none;
}

.legend-section.collapsed .legend-section-title {
    margin-bottom: 0;
}

.legend-section.collapsed .legend-section-content {
    display: none;
}

/* ───── Controls ───── */

.btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background: var(--ui-surface);
    font-size: 12px;
    color: var(--ui-text);
    cursor: pointer;
    transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}

.btn:hover {
    background: var(--ui-hover);
}

.btn[aria-pressed="true"] {
    border-color: var(--ui-accent);
    background: var(--ui-accent);
    color: #fff;
}

.btn svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
}

.legend select {
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background-color: var(--ui-surface);
    font-size: 12px;
    color: var(--ui-text);
    cursor: pointer;
}

.legend select:hover {
    border-color: #cfd4da;
}

.area-row {
    position: relative;
    display: flex;
    gap: 6px;
}

.area-row select {
    flex: 1 1 auto;
}

/* The area search: a field and its suggestions below (search.js). The list takes
   the whole row, field and button, so names have room. */
.area-search {
    flex: 1 1 auto;
    min-width: 0;
}

.area-search input {
    box-sizing: border-box;
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background: var(--ui-surface);
    font: inherit;
    font-size: 12px;
    color: var(--ui-text);
}

.area-search input:hover {
    border-color: #cfd4da;
}

.area-search input:focus {
    outline: 2px solid var(--ui-focus);
    outline-offset: -1px;
}

.area-results {
    position: absolute;
    z-index: 30;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: min(360px, 50vh);
    overflow-y: auto;
    margin: 0;
    padding: 4px;
    list-style: none;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow-sm);
}

/* Two lines: the name in full, then level and where it is. */
.area-results li {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 6px 9px;
    border-radius: 6px;
    font-size: 12.5px;
    line-height: 1.3;
    cursor: pointer;
}

.area-results li:hover,
.area-results li[aria-selected="true"] {
    background: var(--ui-hover);
}

.area-results__name {
    overflow-wrap: anywhere;
    color: var(--ui-text-strong);
}

.area-results__meta {
    overflow-wrap: anywhere;
    font-size: 11px;
    color: var(--ui-text-muted);
}

.area-results .area-results__empty {
    color: var(--ui-text-muted);
    cursor: default;
}

.legend-meta {
    margin: 6px 0 0;
    font-size: 11.5px;
    color: var(--ui-text-muted);
}

.legend-meta:empty {
    display: none;
}

/* ───── Category rows ───── */

/* Column captions over the trend lines and the km badges. Widths match the rows. */
.legend-columns {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: -2px 0 4px;
    padding: 0 4px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ui-text-sub);
}

.legend-columns__date {
    flex: 1 1 auto;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    font-size: 11px;
    color: var(--ui-text-muted);
}

.legend-columns__spark {
    width: 52px;
    text-align: center;
}

.legend-columns__km {
    width: 42px;
    text-align: center;
    white-space: nowrap;
    cursor: help;
}

.legend-columns__km .info-icon {
    margin-left: 1px;
    vertical-align: 0;
}

/* Category rows are switches: click hides the category, click again shows it.
   Buttons, so the browser defaults have to be undone. */
.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    margin: 0 0 1px;
    padding: 3px 4px;
    border: 0;
    border-radius: 6px;
    background: none;
    font-size: 12px;
    line-height: 1.3;
    text-align: left;
    color: inherit;
    cursor: pointer;
    transition: background-color 0.12s;
}

.legend-item:hover {
    background: var(--ui-hover);
}

.legend-color {
    width: 18px;
    height: 6px;
    flex: none;
}

.legend-label {
    flex: 1 1 auto;
    min-width: 0;
}

.legend-spark-holder {
    display: inline-flex;
    flex: none;
}

.legend-spark {
    overflow: visible;
}

.legend-spark polyline {
    fill: none;
    stroke: #9ca3af;
    stroke-width: 1.25;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.legend-spark circle {
    stroke: #fff;
    stroke-width: 1.5;
}

/* Hidden categories step back, as before. */
.legend-item[aria-checked="false"] {
    opacity: 0.35;
}

.legend-item[aria-checked="false"] .legend-color line {
    stroke: var(--ui-text-muted);
}

.count-badge {
    flex: none;
    min-width: 42px;
    padding: 1px 7px;
    border-radius: 999px;
    background: #eef2f7;
    font-size: 10.5px;
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
    text-align: center;
    white-space: nowrap;
    color: #475569;
}

.legend-hint {
    margin: 6px 4px 0;
    font-size: 11px;
    line-height: 1.45;
    color: var(--ui-text-muted);
}

.zoom-link {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.zoom-link:hover {
    color: var(--ui-text-strong);
}

/* ───── Changes ───── */

/* As unfallkarte's analysis disclaimer: amber, because the numbers need it. */
.legend-disclaimer {
    margin: 0 0 10px;
    padding: 6px 9px;
    border-left: 3px solid #f59e0b;
    border-radius: 0 8px 8px 0;
    background: #fffbeb;
    font-size: 11.5px;
    line-height: 1.45;
    color: #78350f;
}

.change-range {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--ui-text-muted);
}

.change-range strong {
    color: var(--ui-text-strong);
    font-weight: 700;
}

.change-range__hint {
    font-size: 11px;
}

.change-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
}

.change-table th {
    padding: 0 0 4px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--ui-text-muted);
    text-align: left;
    white-space: nowrap;
}

.change-table td {
    padding: 3px 0;
    border-top: 1px solid #f1f3f5;
    vertical-align: middle;
}

.change-table .num {
    padding-left: 8px;
    text-align: right;
    white-space: nowrap;
}

.change-table .is-zero {
    color: var(--ui-text-muted);
}

.change-name {
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.3;
}

.change-table tfoot td {
    border-top: 1px solid var(--ui-border);
    font-weight: 700;
    color: var(--ui-text-strong);
}

/* ───── About ───── */

.legend-prose p {
    margin: 0 0 8px;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--ui-text);
}

.legend-prose p:last-child {
    margin-bottom: 0;
}

.legend-prose a {
    color: var(--ui-accent);
}

.legend-prose code {
    padding: 0 3px;
    border-radius: 4px;
    background: var(--ui-hover);
    font-size: 10.5px;
}

/* ───── Background: map or aerial photo ───── */

/* Mode chips as in unfallkarte's legend. */
.legend-modes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.legend-chip {
    padding: 4px 10px;
    border: 1px solid var(--ui-border);
    border-radius: 999px;
    background: var(--ui-hover);
    font-size: 12px;
    line-height: 1.2;
    color: var(--ui-text);
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.legend-chip:hover {
    border-color: #cfd4da;
}

.legend-chip[aria-checked="true"] {
    border-color: var(--ui-accent);
    background: var(--ui-accent-soft);
    font-weight: 700;
    color: var(--ui-text-strong);
}

.legend-chip:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.legend-meta strong {
    color: var(--ui-text-strong);
}

.legend-meta__credit {
    display: block;
    margin-top: 3px;
    font-size: 10.5px;
}

/* ───── Footer ───── */

.legend-footer {
    margin: 0;
    padding-top: 9px;
    border-top: 1px solid var(--ui-divider);
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--ui-text-muted);
}

.legend-footer a {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #4b5563;
    text-decoration: none;
}

.legend-footer a span {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.legend-footer a:hover {
    color: var(--ui-text-strong);
}

.legend-footer svg {
    flex: none;
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* ───── MapLibre's zoom buttons in the card look ───── */

.maplibregl-ctrl-top-right .maplibregl-ctrl-group:not(:empty) {
    overflow: hidden;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    box-shadow: var(--ui-shadow-sm);
}

.maplibregl-ctrl-top-right .maplibregl-ctrl-group button {
    width: 36px;
    height: 36px;
}

.maplibregl-ctrl-top-right .maplibregl-ctrl-group button + button {
    border-top-color: var(--ui-divider);
}

/* ───── Timeline ───── */

.timeline-panel {
    position: absolute;
    z-index: 2;
    /* Right of the panel, on the attribution. */
    left: calc(var(--panel-width) + 2 * var(--edge));
    right: var(--edge);
    bottom: var(--tl-bottom);
    max-width: 920px;
    padding: 10px 14px 8px;
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow);
}

.tl-head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 4px;
}

.tl-buttons {
    display: flex;
    gap: 6px;
}

.tl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface);
    color: #4b5563;
    cursor: pointer;
    transition: background-color 0.12s;
}

.tl-btn:hover {
    background: var(--ui-hover);
    color: var(--ui-text-strong);
}

.tl-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tl-btn--play {
    width: 40px;
    border-color: var(--ui-accent);
    background: var(--ui-accent);
    color: #fff;
}

.tl-btn--play:hover {
    background: var(--ui-accent-hover);
    color: #fff;
}

.tl-btn--play .icon-play {
    fill: currentColor;
    stroke-width: 1;
}

.tl-btn--play .icon-pause,
.tl-btn--play.is-playing .icon-play {
    display: none;
}

.tl-btn--play.is-playing .icon-pause {
    display: block;
}

.tl-readout {
    display: flex;
    flex-direction: column;
    gap: 1px;
    line-height: 1.2;
}

.tl-readout--right {
    margin-left: auto;
    text-align: right;
}

.tl-readout__label {
    white-space: nowrap;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ui-text-sub);
}

.tl-readout__label .info-icon {
    margin-left: 2px;
    vertical-align: 0;
}

.tl-readout strong {
    font-size: 16px;
    font-weight: 700;
    color: var(--ui-text-strong);
    font-variant-numeric: tabular-nums;
}

/* Which aerial photo goes with the date, while the photo is on. */
.tl-chip {
    align-self: center;
    padding: 2px 9px;
    border: 1px solid var(--ui-accent);
    border-radius: 999px;
    background: var(--ui-accent-soft);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    color: var(--ui-accent);
    cursor: help;
}

.timeline {
    position: relative;
    border-radius: 6px;
    cursor: pointer;
    touch-action: none;
    user-select: none;
}

.timeline:focus-visible {
    outline-offset: 1px;
}

.tl-svg {
    display: block;
    overflow: visible;
}

.tl-svg text {
    font-size: 10.5px;
    fill: var(--ui-text-muted);
    font-variant-numeric: tabular-nums;
}

.tl-grid line {
    stroke: var(--ui-divider);
    stroke-width: 1;
}

.tl-axis line,
.tl-stops line {
    stroke: #b6bcc6;
    stroke-width: 1;
}

/* A marked period: faint, under everything else. */
.tl-note {
    fill: #f3f4f6;
}

.tl-svg .tl-note-label {
    font-size: 10px;
    fill: var(--ui-text-muted);
}

/* What changed in OSM, step by step: amber, as the notes on OSM's state. */
.tl-activity rect {
    fill: #f59e0b;
    opacity: 0.32;
}

.tl-svg .tl-activity-key text {
    font-size: 10px;
}

.tl-activity-key rect {
    fill: #f59e0b;
    opacity: 0.5;
}

.tl-line {
    fill: none;
    stroke: var(--ui-text-sub);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.tl-crosshair {
    stroke: #9ca3af;
    stroke-width: 1;
}

.tl-hover-dot {
    fill: #6b7280;
    stroke: var(--ui-surface);
    stroke-width: 2;
}

.tl-current-line {
    stroke: var(--ui-accent);
    stroke-width: 1;
    opacity: 0.45;
}

.tl-current-dot {
    fill: var(--ui-accent);
    stroke: var(--ui-surface);
    stroke-width: 2;
}

/* Same look as the app tooltip below. */
.tl-tooltip {
    position: absolute;
    top: 0;
    z-index: 1;
    transform: translate(-50%, calc(-100% - 6px));
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 5px 8px;
    border-radius: 6px;
    background: var(--ui-text-strong);
    box-shadow: var(--ui-shadow-sm);
    font-size: 11.5px;
    line-height: 1.35;
    white-space: nowrap;
    color: #fff;
    pointer-events: none;
}

.tl-tooltip.is-visible {
    display: flex;
}

.tl-tooltip strong {
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

.tl-tooltip span {
    color: #d1d5db;
}

.tl-tooltip .tl-tooltip__step {
    max-width: 250px;
    margin-top: 2px;
    font-size: 11px;
    white-space: normal;
    text-align: center;
    color: #fde68a;
}

.tl-details {
    margin-top: 2px;
    font-size: 11.5px;
    color: var(--ui-text-muted);
}

.tl-details summary {
    width: max-content;
    cursor: pointer;
}

.tl-details summary:hover {
    color: var(--ui-text-strong);
}

.tl-details table {
    margin-top: 4px;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    color: var(--ui-text);
}

.tl-details th,
.tl-details td {
    padding: 1px 14px 1px 0;
    text-align: right;
}

.tl-details th:first-child,
.tl-details td:first-child {
    text-align: left;
}

.tl-details[open] {
    max-height: 30vh;
    overflow-y: auto;
}

/* ───── Popup: eyebrow, title, label/value table, links in the footer ───── */

.maplibregl-popup-content {
    max-height: 75vh;
    overflow-y: auto;
    padding: 12px 14px;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    box-shadow: var(--ui-shadow);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--ui-text-strong);
}

.maplibregl-popup-close-button {
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 8px;
    font-size: 16px;
    line-height: 22px;
    color: var(--ui-text-muted);
}

.maplibregl-popup-close-button:hover {
    background: var(--ui-hover);
    color: var(--ui-text);
}

.pop-eyebrow {
    margin-bottom: 4px;
    padding-right: 22px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ui-text-muted);
}

.pop-title {
    margin-bottom: 6px;
    padding-right: 18px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--ui-text-strong);
}

.pop-cat {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 7px;
    margin-bottom: 8px;
    font-weight: 700;
}

.pop-code {
    flex-basis: 100%;
    padding-left: 25px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10.5px;
    font-weight: 500;
    overflow-wrap: anywhere;
    color: var(--ui-text-muted);
}

.pop-table {
    width: 100%;
    border-collapse: collapse;
}

.pop-table td {
    padding: 2px 0;
    vertical-align: top;
}

.pop-table td:first-child {
    padding-right: 14px;
    white-space: nowrap;
    font-weight: 600;
    color: var(--ui-text-muted);
}

.pop-meta {
    display: block;
    font-size: 11px;
    line-height: 1.4;
    color: var(--ui-text-muted);
}

.pop-foot {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 12px;
    margin-top: 9px;
    padding-top: 7px;
    border-top: 1px solid var(--ui-divider);
    font-size: 11.5px;
}

.pop-foot a {
    color: var(--ui-accent);
    text-decoration: none;
}

.pop-foot a:hover {
    text-decoration: underline;
}

/* ───── Tooltip for data-tip (ui.js), on body so panels never clip it ───── */

.app-tooltip {
    position: fixed;
    z-index: 9999;
    max-width: 240px;
    padding: 5px 8px;
    border-radius: 6px;
    background: var(--ui-text-strong);
    box-shadow: var(--ui-shadow-sm);
    font: 400 11.5px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 80ms ease;
}

.app-tooltip.is-visible {
    opacity: 1;
}

/* ───── Picking an Ortsteil on the map ───── */

.pick-bar {
    position: absolute;
    top: 12px;
    left: calc(50% + (var(--panel-width) + var(--edge)) / 2);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px 12px;
    width: min(460px, calc(100% - var(--panel-width) - 6 * var(--edge)));
    padding: 8px 10px 8px 14px;
    transform: translateX(-50%);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow-sm);
    font-size: 12.5px;
    line-height: 1.4;
}

.pick-hint {
    flex: 1 1 auto;
    margin: 0;
}

.pick-hint kbd {
    padding: 0 4px;
    border: 1px solid var(--ui-border);
    border-bottom-width: 2px;
    border-radius: 4px;
    font: inherit;
    font-size: 11px;
}

.maplibregl-canvas.is-picking {
    cursor: crosshair;
}

/* Name of the Ortsteil under the pointer while picking. */
.area-tooltip {
    position: absolute;
    z-index: 2;
    transform: translate(12px, -50%);
    padding: 4px 8px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow-sm);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    pointer-events: none;
}

/* ───── Scale bar ───── */

.maplibregl-ctrl-scale {
    border-color: #6b7280;
    background-color: rgba(255, 255, 255, 0.85);
    font-size: 10.5px;
    color: var(--ui-text);
}

/* ───── Narrower: the timeline takes the full width, the panel ends above it ───── */

@media (max-width: 1000px) {
    .timeline-panel {
        left: var(--edge);
        max-width: none;
    }

    .legend {
        max-height: calc(100% - 2 * var(--edge) - var(--timeline-h) - var(--tl-bottom));
    }

    .loading,
    .pick-bar {
        left: 50%;
    }
}

/* ───── Phone: panel on top, folded at start; timeline at the bottom ───── */

@media (max-width: 640px) {
    :root {
        --edge: 8px;
    }

    .legend {
        right: var(--edge);
        width: auto;
        max-width: none;
        padding: 0 14px 10px;
    }

    .legend-title {
        margin: 0 -14px;
        padding: 10px 14px 8px;
    }

    .legend-heading img {
        height: 32px;
    }

    .legend-subtext {
        font-size: 11.5px;
    }

    .legend-subtext br {
        display: none;
    }

    .toggle-root {
        width: 22px;
        height: 22px;
        margin-top: 4px;
    }

    .timeline-panel {
        padding: 8px 10px 6px;
    }

    .tl-head {
        gap: 10px;
    }

    .tl-readout strong {
        font-size: 14px;
    }

    /* "Datenstand" and "gesamt" are enough on a phone. */
    .tl-long {
        display: none;
    }

    /* Out from under the panel: the zoom buttons sit above the timeline, and step
       aside while the unfolded panel reaches down to it. */
    .maplibregl-ctrl-top-right {
        top: auto;
        bottom: calc(var(--tl-bottom) + var(--timeline-h) + var(--edge));
    }

    body.panel-open .maplibregl-ctrl-top-right {
        display: none;
    }

    .loading {
        top: auto;
        bottom: calc(var(--tl-bottom) + var(--timeline-h) + 2 * var(--edge));
    }

    .pick-bar {
        top: var(--edge);
        left: var(--edge);
        right: var(--edge);
        width: auto;
        transform: none;
    }

    /* While picking, the bar takes the folded panel's place; no Esc on a phone. */
    body.is-picking .legend {
        visibility: hidden;
    }

    .pick-hint__key {
        display: none;
    }
}
