:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #263449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --border: #334155;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; }
.brand span { color: var(--accent); }
.brand em { color: var(--muted); font-style: normal; font-weight: 500; margin-left: 4px; }
.units .unit {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 5px 12px; cursor: pointer; font-size: 13px;
}
.units .unit:first-child { border-radius: 6px 0 0 6px; }
.units .unit:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.units .unit.active { background: var(--accent); color: #04263a; font-weight: 600; }

.hero { padding: 22px 20px 8px; }
.hero h1 { margin: 0 0 6px; font-size: 26px; }
.hero .sub { margin: 0 0 6px; color: var(--muted); }
.hero .stats { margin: 0; color: var(--accent); font-size: 14px; }

.layout {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  padding: 16px 20px 24px;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.map-wrap { position: relative; min-height: 540px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
#map { position: absolute; inset: 0; background: #0b1220; }
.leaflet-popup-content { font-size: 13px; line-height: 1.5; }
.leaflet-popup-content a { color: #1d4ed8; }
.map-missing {
  display: flex; align-items: center; justify-content: center; height: 100%;
  color: var(--muted); text-align: center; padding: 20px; background: var(--panel);
}
.map-missing code { color: var(--accent); }
.legend {
  position: absolute; left: 10px; bottom: 10px; background: rgba(15,23,42,.9);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  z-index: 450; pointer-events: none;
}
.legend strong { display: block; margin-bottom: 4px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 3px 0 8px; vertical-align: middle; }
.dot.downhill { background: #2563eb; }
.dot.nordic { background: #16a34a; }
.dot.mixed { background: #9333ea; }
.dot.unknown { background: #6b7280; }

.table-wrap { display: flex; flex-direction: column; min-height: 460px; }
.controls { display: flex; gap: 8px; margin-bottom: 10px; }
.controls input, .controls select {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 14px;
}
.controls input { flex: 1; }

.table-scroll { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  position: sticky; top: 0; background: var(--panel-2); text-align: left;
  padding: 10px; cursor: pointer; user-select: none; white-space: nowrap;
}
thead th.num { text-align: right; }
thead th.asc::after { content: " ▲"; color: var(--accent); }
thead th.desc::after { content: " ▼"; color: var(--accent); }
tbody td { padding: 9px 10px; border-top: 1px solid var(--border); }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel); }
.type-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.count { color: var(--muted); font-size: 13px; margin: 8px 2px 0; }

.detail { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.detail.hidden { display: none; }
.detail-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; max-width: 480px; width: 100%; padding: 22px; position: relative; }
.detail-card .close { position: absolute; right: 12px; top: 10px; background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.detail-card h2 { margin: 0 0 8px; }
.detail-card h2 small { color: var(--muted); font-weight: 500; font-size: 14px; }
.detail-card .tag { display: inline-block; color: #fff; padding: 2px 10px; border-radius: 20px; font-size: 12px; text-transform: capitalize; }
.detail-card .pref { color: var(--muted); margin: 8px 0; }
.facts { list-style: none; padding: 0; margin: 12px 0; }
.facts li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.facts li span { color: var(--muted); }
.diff .bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; margin: 6px 0; }
.diff .beg { background: #16a34a; }
.diff .int { background: #2563eb; }
.diff .adv { background: #111827; }
.diff small { color: var(--muted); }
.ext { color: var(--accent); text-decoration: none; }
.muted-note { color: var(--muted); font-size: 13px; background: var(--panel-2); padding: 8px 10px; border-radius: 6px; }
#regionFilter { max-width: 130px; }

.footer { padding: 14px 20px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); background: var(--panel); }
