:root {
    --primary-bg: #ffffff;
    --primary-text: #1a1a1a;
    --secondary-bg: #f5f5f5;
    --border-color: #e0e0e0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --primary-bg: #1a1a1a;
    --primary-text: #ffffff;
    --secondary-bg: #2d2d2d;
    --border-color: #404040;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100vh;
    overflow: hidden;
    background: var(--primary-bg);
    color: var(--primary-text);
    transition: background-color 0.3s, color 0.3s;
}

#map {
    width: 100%;
    height: 100%;
}

/* Info panel (top-right). Height is capped so the basemap attribution
 * stays visible at the bottom of the screen even with a long sign list. */
.info-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 280px;
    max-height: calc(100vh - 60px);   /* ~48 px reserve for the attribution + spacing */
    background: var(--primary-bg);
    border-radius: 8px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    overflow: hidden;
}

.info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;     /* header stays fixed; only info-content scrolls */
}

.info-header__titles {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.info-header h1 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

/* Minimize button (− icon) — collapses the panel to just the header. */
.panel-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--primary-text);
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 120ms ease;
}

.panel-toggle:hover {
    background: rgba(0, 0, 0, 0.08);
}

.panel-toggle svg {
    width: 16px;
    height: 16px;
}

/* When collapsed, the "−" rotates 90° into a "|" — readable hint that it
 * will expand the panel back. The title attribute also flips via JS. */
.panel-toggle[aria-expanded="false"] svg {
    transform: rotate(90deg);
}

.info-panel.is-collapsed .info-content {
    display: none;
}

.info-panel.is-collapsed {
    /* When collapsed, drop the max-height cap so the panel hugs the header. */
    max-height: none;
}

/* Visually-hidden text for screen readers only. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.info-header__subtitle {
    font-size: 10px;
    color: var(--primary-text);
    opacity: 0.6;
    line-height: 1.2;
}

.info-header__subtitle a {
    color: inherit;
}

.info-content {
    padding: 12px 14px;
    font-size: 12px;
    color: var(--primary-text);
    overflow-y: auto;
    flex: 1 1 auto;
}

.legend-toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.legend-toggle-row--sub {
    margin-left: 12px;
    margin-bottom: 4px;
    font-size: 12px;
    opacity: 0.9;
}

/* Dependent toggle (e.g. "Zusatzzeichen") when its parent toggle is off. */
.legend-toggle-row--inactive {
    opacity: 0.4;
    pointer-events: none;
}

.legend-toggle-row__title h3 {
    font-size: 13px;
    font-weight: 600;
    margin: 0;
}

.legend-footer {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.legend-footer__badge {
    display: inline-flex;
    flex-shrink: 0;
    line-height: 0;
}

.legend-footer__badge img {
    height: 20px;
    display: block;
}

.legend-footer__issues {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--primary-text);
    opacity: 0.75;
    text-decoration: none;
    flex-shrink: 0;
    transition: opacity 120ms ease;
}

.legend-footer__issues:hover {
    opacity: 1;
}

.legend-footer__issues svg {
    flex-shrink: 0;
}

/* Zoom hint shown when the user is zoomed out past the pmtile minzoom.
 * Toggled via [hidden] attribute on the element — no class shenanigans. */
.zoom-hint {
    margin-top: 8px;
    padding: 8px 10px;
    background: #fff7ed;          /* amber-50 — gentle attention without alarm */
    border: 1px solid #fdba74;    /* amber-300 */
    color: #7c2d12;               /* amber-900 */
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.35;
}

[data-theme="dark"] .zoom-hint {
    background: #3a2410;
    border-color: #9a3412;
    color: #fed7aa;
}

.zoom-hint strong {
    font-weight: 600;
}

/* ───── Top-N sign counters (info-panel) ───── */

.top-signs-section {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.top-signs-header {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--primary-text);
}

.top-signs-total {
    font-weight: 400;
    font-size: 11px;
    opacity: 0.6;
    margin-left: 4px;
}

.top-signs-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.top-signs-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    min-height: 22px;
    cursor: pointer;
    border-radius: 4px;
    padding: 1px 3px;
    margin: 0 -3px;
    position: relative;
    transition: background-color 120ms ease;
}

.top-signs-item:hover:not(.top-signs-item--hidden) {
    /* soft amber, matches the map-side hover glow (#fbbf24) */
    background-color: rgba(251, 191, 36, 0.22);
}

/* Click-to-hide: a translucent white veil + muted opacity on contents. */
.top-signs-item--hidden::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 4px;
    pointer-events: none;
}

.top-signs-item--hidden {
    cursor: pointer;
}

.top-signs-item--hidden .top-signs-label,
.top-signs-item--hidden .top-signs-text,
.top-signs-item--hidden .count-badge {
    opacity: 0.5;
}

.top-signs-icon {
    display: inline-block;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.top-signs-label {
    flex: 1;
    font-variant-numeric: tabular-nums;
}

.top-signs-text {
    flex: 1;
    padding: 2px 6px;
    border: 1px solid currentColor;
    border-radius: 3px;
    background: var(--surface, #fff);
    font-size: 10px;
    line-height: 1.3;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-signs-empty {
    font-size: 11px;
    font-style: italic;
    opacity: 0.6;
}

.count-badge {
    font-size: 10px;
    padding: 0 6px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
    white-space: nowrap;
    color: var(--primary-text);
    display: inline-block;
    flex-shrink: 0;
    margin-left: auto;   /* pin to the right edge of the row */
}

.legend-source a {
    color: inherit;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 18px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #ccc;
    border-radius: 18px;
    transition: 0.2s;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: #fff;
    border-radius: 50%;
    transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #2563eb;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

/* Smaller variant used for sub-toggles (e.g. "Zusatzzeichen anzeigen").
   Defined AFTER the base rules so equal-specificity selectors land later
   in the cascade and actually override the base width/height/transform. */
.toggle-switch--sm {
    width: 26px;
    height: 14px;
}

.toggle-switch--sm .toggle-slider::before {
    height: 10px;
    width: 10px;
    left: 2px;
    bottom: 2px;
}

.toggle-switch--sm input:checked + .toggle-slider::before {
    transform: translateX(12px);
}

/* ───── Karte panel (bottom-left) ───── */

.map-settings-toggle {
    position: absolute;
    left: 16px;
    bottom: 30px;
    z-index: 6;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--primary-bg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-text);
    padding: 0;
    cursor: pointer;
}

.map-settings-toggle:hover { background: var(--secondary-bg); }
.map-settings-toggle svg { width: 22px; height: 22px; }
/* Hidden while the panel is open. JS sets aria-expanded=true to mirror state. */
.map-settings-toggle[aria-expanded="true"] { display: none; }

.map-settings-panel {
    position: absolute;
    left: 16px;
    bottom: 30px;
    width: 300px;
    max-width: calc(100vw - 32px);
    background: var(--primary-bg);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    z-index: 5;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.map-settings-panel.is-collapsed { display: none; }

.map-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.map-settings-header h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.map-settings-panel-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.basemap-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.basemap-btn {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 7px;
    background: var(--primary-bg);
    color: var(--primary-text);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
    transition: background 120ms ease, box-shadow 120ms ease;
}

.basemap-btn:hover { background: var(--secondary-bg); }

.basemap-btn.selected {
    border-color: #2563eb;
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.basemap-preview {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 7px;
    border: 1px solid var(--border-color);
    margin-bottom: 6px;
    background-size: cover;
    background-position: center;
}

.basemap-preview-positron {
    background-color: #eef3f7;
    background-image: url('assets/basemaps/positron-thumb.png');
}

.basemap-preview-osm {
    background-color: #f5f1df;
    background-image: url('assets/basemaps/osm-thumb.png');
}

.basemap-preview-satellite {
    background-color: #516146;
    background-image: url('assets/basemaps/satellite-thumb.png');
}

.basemap-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
}

.terrain-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--secondary-bg);
}

.terrain-row strong {
    display: block;
    margin-bottom: 2px;
    font-size: 12px;
}

.terrain-row p {
    margin: 0;
    font-size: 11px;
    line-height: 1.25;
    opacity: 0.7;
}

/* Toggle switch (used by the relief + buildings toggles). */
.switch {
    position: relative;
    display: inline-flex;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: #cbd5e1;
    transition: background 160ms ease;
    cursor: pointer;
}

.switch-slider::before {
    content: "";
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    transition: transform 160ms ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.switch input:checked + .switch-slider { background: #2563eb; }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }

/* MapLibre top-left navigation control needs a bit of breathing room. */
.maplibregl-ctrl-top-left {
    margin-left: 8px;
    margin-top: 8px;
}

/* Popup */
.maplibregl-popup-content {
    background: var(--primary-bg);
    color: var(--primary-text);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 12px;
}

.popup__codes {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
}

.popup__meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 8px;
    margin-bottom: 6px;
    font-size: 11px;
    opacity: 0.85;
}

.popup__meta dt {
    font-weight: 600;
}

.popup__meta dd {
    margin: 0;
}
