:root {
    --bg: #f4f7f6;
    --surface: #ffffff;
    --surface-2: #edf4f1;
    --text: #17342b;
    --muted: #60756e;
    --line: #d8e3df;
    --primary: #0b7253;
    --primary-hover: #075a41;
    --danger: #b42318;
    --shadow: 0 16px 40px rgba(10, 45, 35, .16);
    --topbar-height: 74px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { overflow: hidden; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.skip-link {
    position: fixed; left: 1rem; top: -5rem; z-index: 5000;
    padding: .75rem 1rem; color: #fff; background: #111; border-radius: .5rem;
}
.skip-link:focus { top: 1rem; }

.topbar {
    height: var(--topbar-height); display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; padding: 0 1.1rem; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line);
    position: relative; z-index: 1200;
}
.brand { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.brand-mark {
    display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 auto; border-radius: 12px;
    color: #fff; background: var(--primary); font-size: .8rem; font-weight: 800; letter-spacing: .06em;
}
.brand h1 { margin: 0; font-size: 1.15rem; line-height: 1.2; }
.brand p { margin: .15rem 0 0; color: var(--muted); font-size: .78rem; }
.topbar-actions { display: flex; gap: .5rem; }

.workspace { height: calc(100dvh - var(--topbar-height)); display: grid; grid-template-columns: minmax(0,1fr) 390px; }
.map-panel { position: relative; min-width: 0; }
#map { width: 100%; height: 100%; background: #dce8e3; }
#map.is-selecting { cursor: crosshair; }

.sidebar {
    position: relative; z-index: 1100; overflow-y: auto; overscroll-behavior: contain;
    padding: 1rem; background: var(--surface); border-left: 1px solid var(--line);
    scrollbar-gutter: stable;
}
.sidebar-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.sidebar-header h2 { margin: 0; font-size: 1.25rem; }
.eyebrow { margin: 0 0 .2rem; color: var(--primary); font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.icon-button { display: none; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--surface-2); color: var(--text); font-size: 1.6rem; }

fieldset { margin: 0 0 .8rem; padding: .9rem; border: 1px solid var(--line); border-radius: 12px; }
legend { padding: 0 .35rem; font-size: .9rem; font-weight: 750; }
label { display: block; margin: .65rem 0 .3rem; color: var(--muted); font-size: .78rem; font-weight: 650; }
input[type="search"], select {
    width: 100%; min-height: 42px; padding: .6rem .7rem; border: 1px solid #bfcfc9; border-radius: 8px;
    background: var(--surface); color: var(--text);
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
    outline: 3px solid rgba(11,114,83,.25); outline-offset: 2px;
}
.input-action { display: flex; gap: .45rem; align-items: stretch; }
.input-action input { min-width: 0; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.check-row { display: flex; align-items: center; gap: .55rem; color: var(--text); }
.check-row input { width: 18px; height: 18px; accent-color: var(--primary); }
input[type="range"] { width: 100%; accent-color: var(--primary); }
.help { margin: .25rem 0 .6rem; color: var(--muted); font-size: .76rem; line-height: 1.45; }

.button { min-height: 40px; padding: .55rem .8rem; border: 1px solid transparent; border-radius: 8px; font-weight: 700; white-space: nowrap; }
.button-primary { color: #fff; background: var(--primary); }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { color: var(--text); background: var(--surface-2); border-color: var(--line); }
.form-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.text-button { padding: .4rem 0; border: 0; background: transparent; color: var(--danger); text-decoration: underline; }

.loading, .map-status, .legend {
    position: absolute; z-index: 800; left: 50%; transform: translateX(-50%); border: 1px solid rgba(20,60,48,.16);
    border-radius: 999px; background: rgba(255,255,255,.94); box-shadow: 0 6px 18px rgba(20,60,48,.15);
}
.loading { top: 1rem; padding: .55rem .9rem; font-size: .8rem; font-weight: 700; }
.map-status { bottom: 1rem; padding: .45rem .75rem; max-width: calc(100% - 2rem); font-size: .72rem; text-align: center; }
.map-status.error { color: #fff; background: var(--danger); }
.legend { left: 4rem; top: 1rem; transform: none; display: flex; flex-wrap: wrap; gap: .5rem; padding: .45rem .6rem; font-size: .68rem; }
.legend span { white-space: nowrap; }
.dot { display: inline-block; width: 9px; height: 9px; margin-right: .2rem; border-radius: 50%; }
.dot-fb { background: #0b7253; } .dot-fs { background: #d97706; } .dot-ml { background: #2563eb; } .dot-mo { background: #7c3aed; }

.server-cluster-icon { background: transparent; border: 0; }
.server-cluster-bubble {
    display: grid; place-items: center; width: 100%; height: 100%; padding: 3px;
    border: 3px solid #fff; border-radius: 50%; color: #fff; box-shadow: 0 3px 10px rgba(15,23,42,.38);
    font-size: .7rem; font-weight: 800; line-height: 1; text-align: center;
}

.station-marker-icon {
    display: grid !important; place-items: center; background: transparent; border: 0;
}
.station-marker-dot {
    display: block; width: 16px; height: 16px; border: 3px solid #fff; border-radius: 50%;
    box-shadow: 0 2px 8px rgba(15,23,42,.5); transition: transform .12s ease, box-shadow .12s ease;
}
.station-marker-icon:hover .station-marker-dot,
.station-marker-icon:focus .station-marker-dot {
    transform: scale(1.35); box-shadow: 0 3px 12px rgba(15,23,42,.62);
}
.station-marker-fb { background: #0b7253; }
.station-marker-fs { background: #d97706; }
.station-marker-ml { background: #2563eb; }
.station-marker-mo { background: #7c3aed; }
.station-marker-default { background: #475569; }

.analysis { margin-top: 1rem; padding: .9rem; border-radius: 12px; background: var(--surface-2); }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.analysis h3 { margin: 0; font-size: 1rem; }
.analysis h4 { margin: .9rem 0 .4rem; font-size: .76rem; }
.badge { padding: .2rem .45rem; border-radius: 999px; background: var(--surface); color: var(--muted); font-size: .65rem; }
.metrics { display: grid; grid-template-columns: repeat(3,1fr); gap: .45rem; margin-top: .8rem; }
.metrics div { padding: .6rem .3rem; border-radius: 9px; background: var(--surface); text-align: center; }
.metrics strong, .metrics span { display: block; }
.metrics strong { font-size: 1.05rem; }
.metrics span { margin-top: .12rem; color: var(--muted); font-size: .64rem; }
.analysis-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.ranking { margin: 0; padding-left: 1.25rem; font-size: .7rem; }
.ranking li { margin: .22rem 0; padding-left: .15rem; }
.ranking span { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.about { margin: 1rem 0; padding: .75rem; border: 1px solid var(--line); border-radius: 10px; font-size: .76rem; line-height: 1.5; }
.about summary { cursor: pointer; font-weight: 700; }
.about p:last-child { margin-bottom: 0; }

.station-popup { min-width: min(360px, 72vw); }
.station-popup h3 { margin: 0 0 .55rem; font-size: 1rem; }
.station-popup dl { display: grid; grid-template-columns: minmax(95px,auto) 1fr; gap: .3rem .65rem; margin: 0; font-size: .75rem; }
.station-popup dt { color: var(--muted); font-weight: 650; }
.station-popup dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.station-popup a { color: var(--primary); }
.leaflet-popup-content { margin: 14px 18px; }
.backdrop { display: none; }
.noscript { position: fixed; inset: auto 1rem 1rem; z-index: 5000; padding: 1rem; color: #fff; background: #8a1c13; }

@media (max-width: 900px) {
    :root { --topbar-height: 64px; }
    .brand p { display: none; }
    .workspace { display: block; }
    .map-panel { height: 100%; }
    .sidebar {
        position: fixed; z-index: 3000; left: 0; right: 0; bottom: 0; top: max(3rem, env(safe-area-inset-top));
        padding: 1rem max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
        border: 0; border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform .22s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.is-open { transform: translateY(0); }
    .icon-button { display: grid; place-items: center; }
    .backdrop { position: fixed; z-index: 2500; inset: 0; width: 100%; border: 0; background: rgba(4,24,18,.45); }
    .backdrop:not([hidden]) { display: block; }
    .legend { left: 3.8rem; top: .65rem; max-width: calc(100% - 4.5rem); }
    .map-status { bottom: max(1rem, env(safe-area-inset-bottom)); }
}

@media (max-width: 470px) {
    .topbar { padding: 0 .65rem; }
    .brand-mark { width: 38px; height: 38px; }
    .brand h1 { font-size: 1rem; }
    #filters-toggle { padding-inline: .65rem; font-size: .78rem; }
    .two-columns, .analysis-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
