/* ---------- Tokens ---------- */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #5d6878;
  --faint: #8a94a6;
  --line: #e2e6ec;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fe;
  --danger: #c62828;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(20, 30, 50, 0.16);
  --panel-w: 306px;
  --drawer-w: 360px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Component display rules (e.g. .icon-btn { display: grid }) must not override [hidden]. */
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; position: relative; overflow: hidden; }
.panel {
  width: var(--panel-w); flex: 0 0 var(--panel-w);
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden; z-index: 500;
}
.panel-body { overflow-y: auto; padding: 0 16px 16px; flex: 1; }
/* isolation keeps Leaflet's internal z-indexes (controls use 1000) below the drawer. */
.map-wrap { flex: 1; position: relative; min-width: 0; isolation: isolate; }
/* While the drawer is open on desktop, move the right-hand map controls clear of it. */
.app.drawer-open .leaflet-right { right: var(--drawer-w); transition: right 0.15s; }
#map { position: absolute; inset: 0 0 var(--ad-strip-h, 0px); background: #dfe5ec; }

/* ---------- Ad strip under the map (see js/ads.js) ---------- */
.ad-strip {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 0 8px; background: var(--panel); border-top: 1px solid var(--line);
}
.ad-label {
  margin: 0 0 3px; font-size: 10px; line-height: 1.2; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--faint);
}
.ad-placeholder {
  display: grid; place-items: center; border: 1px dashed #b8c2cf; border-radius: 4px;
  background: repeating-linear-gradient(135deg, #f4f6f9 0 10px, #eef1f5 10px 20px);
  color: var(--muted); font-size: 12px;
}
/* Ad card under Download Data (desktop only; see js/ads.js), styled like the export card. */
.ad-card {
  margin: 10px 0 0; padding: 10px 0 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); display: flex; flex-direction: column; align-items: center;
}
/* With details open, keep the ad centered in the visible map area left of the drawer. */
.app.drawer-open .ad-strip { right: var(--drawer-w); }

/* ---------- Panel header & search ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; }
.brand { font-size: 17px; font-weight: 650; margin: 0; display: flex; align-items: center; gap: 8px; letter-spacing: -0.01em; }
.brand a { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 22px; height: 22px; fill: var(--accent); }
.panel-toggle { display: none; }

.search { display: flex; gap: 6px; padding: 0 16px; }
.search input {
  flex: 1; min-width: 0; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: #fbfcfd;
}
.search input:focus { border-color: var(--accent); background: #fff; outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.search button, .btn {
  padding: 9px 14px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.search button:disabled { opacity: 0.6; cursor: progress; }
.status { margin: 8px 16px 12px; color: var(--muted); font-size: 13px; min-height: 19px; }
.status.error { color: var(--danger); }

/* ---------- Mode toggle ---------- */
.mode { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 9px; padding: 3px; gap: 3px; }
.mode-btn {
  border: 0; background: transparent; padding: 7px 0; border-radius: 7px;
  cursor: pointer; font-weight: 600; color: var(--muted);
}
.mode-btn[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.about-link { display: inline-flex; align-items: center; gap: 5px; margin: 6px 0 0; padding: 2px 0; }
.about-link svg { width: 15px; height: 15px; fill: currentColor; }
.about-link:hover { text-decoration: underline; }
.about-p { margin: 0; line-height: 1.55; color: var(--text); font-size: 14px; }

/* ---------- Summary ---------- */
.summary { margin: 14px 0 4px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { font-size: 11.5px; color: var(--muted); }
.showing { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.showing b { color: var(--text); }

/* ---------- Download data ---------- */
.export { margin: 14px 0 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.export-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 0 4px; }
.export-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; }
.export-dict { color: var(--accent); font-size: 13px; text-decoration: none; }
.export-dict:hover { text-decoration: underline; }
.export-desc { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.export-desc b { color: var(--text); }
.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent); padding: 7px 12px;
}
.btn-secondary svg { width: 17px; height: 17px; fill: currentColor; }
.btn-secondary:disabled { opacity: 0.6; cursor: progress; }
.export-result:empty { display: none; }
.export-result { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.dl-link {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px;
  background: var(--bg); color: var(--text); text-decoration: none;
}
.dl-link:hover { background: var(--accent-soft); }
.dl-link svg { width: 18px; height: 18px; fill: var(--accent); flex: none; }
.dl-link .dl-name { font-weight: 600; color: var(--accent); }
.dl-link .dl-meta { color: var(--muted); font-size: 12px; }
.export-note { color: var(--faint); font-size: 12px; margin: 0; }

/* ---------- Filters ---------- */
.filters-head { display: flex; align-items: baseline; justify-content: space-between; margin: 16px 0 4px; }
.filters-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 2px 4px; font-size: 13px; }
.fgroup { border-top: 1px solid var(--line); padding: 8px 0; }
.fgroup summary {
  cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 6px; padding: 2px 0;
}
.fgroup summary::-webkit-details-marker { display: none; }
.fgroup-note { font-weight: 400; font-size: 0.85em; }
.fgroup summary::before {
  content: ""; width: 6px; height: 6px; border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint);
  transform: rotate(-45deg); transition: transform 0.15s; margin: 0 4px 0 2px;
}
.fgroup[open] summary::before { transform: rotate(45deg); }
.fopts { display: flex; flex-direction: column; gap: 1px; margin-top: 6px; }
.fopt {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; user-select: none;
}
.fopt:hover { background: var(--bg); }
.fopt input { margin: 0; accent-color: var(--accent); width: 15px; height: 15px; }
.fopt .swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); }
.fopt .label { flex: 1; }
.fopt .count { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.fopt.empty .label { color: var(--faint); }
.fopt .note { font-size: 11px; color: var(--faint); }
.only-btn {
  border: 0; background: none; color: var(--accent); font-size: 11.5px; cursor: pointer; padding: 0 2px;
  visibility: hidden;
}
.fopt:hover .only-btn, .only-btn:focus-visible { visibility: visible; }
.ftwist {
  width: 16px; height: 16px; flex: none; margin: 0 -4px 0 -2px; padding: 0; border: 0; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; border-radius: 4px;
}
.ftwist::before {
  content: ""; width: 5px; height: 5px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg); transition: transform 0.15s;
}
.ftwist[aria-expanded="true"]::before { transform: rotate(45deg); }
.ftwist:hover { background: var(--line); }
#f-service > .fopt { padding-left: 24px; }
.fsub { margin: 0 0 2px 20px; padding-left: 6px; border-left: 1px solid var(--line); }
.fsub .fopt { padding-top: 3px; padding-bottom: 3px; font-size: 0.95em; }
.hint { font-size: 12px; color: var(--faint); margin: 12px 0 0; }

/* ---------- Loading ---------- */
.loading {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 800;
  background: var(--panel); padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; font-weight: 600;
}
.loading[hidden] { display: none; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Map markers ---------- */
.tw-icon, .tx-icon, .pin-icon, .cl-icon { background: none; border: 0; }
.tw {
  --c: #5d6878;
  width: 100%; height: 100%; display: grid; place-items: center;
  background: #fff; border: 3px solid var(--c); border-radius: 50%;
  font: 700 11px/1 var(--font); color: #1c2430; box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}
.tw.reg { border-radius: 6px; }
.tw.empty { background: var(--c); border-color: #fff; border-width: 2px; }
.tx {
  --c: #5d6878;
  width: 100%; height: 100%; border-radius: 50%; background: var(--c);
  border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.45);
}
.tx.standalone { border-radius: 3px; transform: rotate(45deg) scale(0.85); }
.pin {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; background: var(--danger);
  transform: rotate(-45deg); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.cl {
  width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center;
  background: rgba(31, 111, 235, 0.85); color: #fff; font: 700 12px/1 var(--font);
  border: 3px solid rgba(255,255,255,0.85); box-shadow: 0 1px 5px rgba(0,0,0,0.35);
}
.cl.tx-cl { background: rgba(28, 36, 48, 0.82); }
.leaflet-tooltip { font: 12.5px/1.4 var(--font); padding: 6px 9px; border-radius: 6px; }
.tt-title { font-weight: 650; }
.tt-sub { color: var(--muted); }
.selected-ring { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { 0% { stroke-opacity: 1; } 100% { stroke-opacity: 0.2; } }

/* ---------- Legend ---------- */
.legend {
  background: var(--panel); border-radius: 8px; padding: 8px 10px; box-shadow: 0 1px 5px rgba(0,0,0,0.25);
  font-size: 12px; line-height: 1.6;
}
.legend-row { display: flex; align-items: center; gap: 7px; }
.legend .shape { width: 12px; height: 12px; border: 2.5px solid var(--muted); background: #fff; }
.legend .shape.round { border-radius: 50%; }
.legend .shape.square { border-radius: 3px; }
.legend .shape.diamond { border: 0; background: var(--muted); transform: rotate(45deg) scale(0.8); border-radius: 2px; }
.legend .shape.dot { border: 0; background: var(--muted); border-radius: 50%; }

/* ---------- Drawer ---------- */
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: var(--drawer-w); max-width: 100%;
  background: var(--panel); box-shadow: var(--shadow); z-index: 900;
  display: flex; flex-direction: column;
}
.drawer[hidden] { display: none; }
.drawer-bar { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--line); }
.drawer-kicker { flex: 1; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.icon-btn { border: 0; background: none; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 20px; height: 20px; fill: var(--muted); }
.drawer-body { overflow-y: auto; padding: 16px; flex: 1; }
.drawer-body h2 { font-size: 19px; margin: 0 0 4px; letter-spacing: -0.01em; word-break: break-word; }
.drawer-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 22px 0 8px; }
.sub { color: var(--muted); margin: 0 0 12px; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 10px;
  background: var(--bg); font-size: 12px; font-weight: 600; color: var(--muted); line-height: 1.35;
  /* Long licensee names wrap inside the badge instead of running past the drawer edge. */
  max-width: 100%; overflow-wrap: anywhere;
}
.badge .swatch { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 5px 14px; margin: 12px 0 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.txlist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.txlist li + li { border-top: 1px solid var(--line); }
.txrow {
  width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; cursor: pointer;
  display: grid; grid-template-columns: 10px 1fr auto; gap: 2px 9px; align-items: center;
}
.txrow:hover { background: var(--bg); }
.txrow .swatch { width: 10px; height: 10px; border-radius: 50%; }
.txrow .main { font-weight: 600; }
.txrow .meta { grid-column: 2 / -1; color: var(--muted); font-size: 12px; }
.txrow .freqs { color: var(--faint); font-size: 12px; }
.txrow.dim { opacity: 0.45; }
.txfilter { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin: -2px 0 8px; cursor: pointer; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 12px 10px; font-size: 13px; }
.timeline li::before {
  content: ""; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--accent);
}
.timeline .when { font-weight: 600; font-variant-numeric: tabular-nums; }
.timeline .what { color: var(--muted); }
table.freq { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.freq th, table.freq td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
table.freq th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }
table.freq td.num, table.freq th.num { text-align: right; }
.parent-card {
  width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: none;
  padding: 10px 12px; cursor: pointer; display: block;
}
.parent-card:hover { border-color: var(--accent); }
.parent-card b { display: block; }
.parent-card span { color: var(--muted); font-size: 12.5px; }
.empty-note { color: var(--faint); font-size: 13px; margin: 0; }
.drawer-loading { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.err { color: var(--danger); }

/* ---------- Small screens: panel on top, drawer as bottom sheet ---------- */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .panel {
    width: 100%; flex: none; max-height: 58dvh; border-right: 0; border-bottom: 1px solid var(--line);
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  }
  .panel-head { padding: 10px 16px 8px; }
  .panel-toggle {
    display: inline-block; border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
    padding: 5px 10px; font-weight: 600; cursor: pointer;
  }
  .panel.collapsed .panel-body { display: none; }
  .status { margin-bottom: 8px; }
  .drawer { top: auto; left: 0; width: 100%; height: 68dvh; border-radius: 14px 14px 0 0; }
  .app.drawer-open .leaflet-right { right: 0; }
  /* The details sheet sits above the ad instead of covering it. */
  .drawer { bottom: var(--ad-strip-h, 0px); }
  .app.drawer-open .ad-strip { right: 0; }
  .ad-strip { padding: 3px 0 6px; }
  .legend { font-size: 10.5px; line-height: 1.45; padding: 5px 7px; }
  .legend .shape { width: 9px; height: 9px; border-width: 2px; }
  .summary { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Human check (Turnstile) ---------- */
/* Empty unless Cloudflare asks for an interaction; then the widget shows here. */
.human-check:empty { display: none; }
#humanCheck { margin: 10px 16px 0; }
#humanCheckExport { margin: 10px 0 0; }
