/* ============ theme tokens ============ */

:root {
  --radius: 0;
  --c-lesser: #1a9850;
  --c-partial: #66bd63;
  --c-known: #fdae61;
  --c-mainstream: #d73027;
  --c-excluded: #8a93a3;
}

html[data-theme="light"] {
  --app-bg: linear-gradient(150deg, #eef2f7 0%, #e4e9f2 55%, #dde4ef 100%);
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-bg-strong: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-shadow: 0 8px 28px rgba(30, 41, 59, 0.08);
  --text: #1e293b;
  --muted: #64748b;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: rgba(29, 78, 216, 0.09);
  --input-bg: rgba(255, 255, 255, 0.7);
  --border: rgba(30, 41, 59, 0.12);
  --row-hover: rgba(29, 78, 216, 0.06);
  --track: rgba(30, 41, 59, 0.10);
  --on-accent: #ffffff;
}

html[data-theme="dark"] {
  --app-bg: linear-gradient(150deg, #0d1320 0%, #101828 55%, #0e1525 100%);
  --glass-bg: rgba(23, 32, 51, 0.50);
  --glass-bg-strong: rgba(19, 27, 44, 0.78);
  --glass-border: rgba(148, 163, 184, 0.14);
  --glass-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --text: #e2e8f0;
  --muted: #8e9bb3;
  --accent: #5b8def;
  --accent-hover: #7aa3f5;
  --accent-soft: rgba(91, 141, 239, 0.13);
  --input-bg: rgba(10, 16, 28, 0.55);
  --border: rgba(148, 163, 184, 0.16);
  --row-hover: rgba(91, 141, 239, 0.09);
  --track: rgba(148, 163, 184, 0.16);
  --on-accent: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
}

#app {
  display: flex;
  height: 100%;
  background: var(--app-bg);
}

/* ============ sidebar ============ */

#sidebar {
  width: 430px;
  flex-shrink: 0;   /* width is controlled by JS (drag-resize) once the user grabs the handle */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px;
  background: transparent;
  border-right: 1px solid var(--border);
  transition: width 0.15s ease; /* only visible on the collapse/expand double-click jump, not while dragging (JS disables it mid-drag) */
}
#sidebar.collapsed { padding-left: 8px; padding-right: 8px; }

/* Drag handle between sidebar and map — grab to resize, double-click to collapse/expand */
#sidebarResize {
  flex: 0 0 6px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  z-index: 5;
}
#sidebarResize:hover, #sidebarResize.dragging { background: var(--accent-soft, rgba(59,130,246,0.25)); }
#sidebarResize::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 36px;
  border-radius: 2px;
  background: var(--border);
}

#sidebar::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--track); border-radius: 0; }
#sidebar::-webkit-scrollbar-track { background: transparent; }

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0;
}

.theme-toggle {
  width: auto;
  margin: 0;
  padding: 4px 12px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 0;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

.subtitle {
  margin: 4px 0 14px;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.55;
  margin: 0 0 14px;
}

.hint b { color: var(--text); }

/* export sub-selection readout ("Clip for export") */
#exportClipInfo:empty { display: none; }

#cfRunInfo.warn { color: #d73027; }
#exportClipInfo {
  margin-top: 8px;
  padding: 6px 9px;
  border-left: 3px solid #e8710a;
  background: rgba(232, 113, 10, 0.10);
  border-radius: 4px;
}
#exportClipInfo a { color: #e8710a; }

/* imported-CSV readout ("Import Previous Export") — same pattern as #exportClipInfo, own accent */
#importInfo:empty { display: none; }
#importInfo {
  margin-top: 8px;
  padding: 6px 9px;
  border-left: 3px solid #2b7a4b;
  background: rgba(43, 122, 75, 0.10);
  border-radius: 4px;
}
#importInfo a { color: #2b7a4b; }

/* ---- glass panels ---- */

.panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 14px;
  margin-bottom: 12px;
}

h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

h2 small {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  opacity: 0.8;
}

.live-tag {
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 0;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-soft);
}

/* ---- fields & buttons ---- */

.field {
  display: block;
  margin-bottom: 10px;
  font-size: 12.5px;
  font-weight: 500;
}

.field small { color: var(--muted); font-weight: 400; }

.field input[type="number"],
.field select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}

.field input[type="number"]:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.field select { cursor: pointer; }
.field select option { background: var(--app-bg); color: var(--text); }

label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  margin-bottom: 10px;
  cursor: pointer;
}

input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

button {
  width: 100%;
  padding: 9px;
  margin-top: 6px;
  border: 1px solid transparent;
  border-radius: 0;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover:not(:disabled) { background: var(--accent-hover); }

button:disabled {
  background: var(--track);
  color: var(--muted);
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

button.ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---- log ---- */

.log {
  max-height: 160px;
  overflow-y: auto;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  background: rgba(9, 14, 26, 0.85);
  color: #9fb6d9;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 9px;
  white-space: pre-wrap;
  line-height: 1.6;
}

.log:empty::before { content: "Idle."; color: #56637d; }
.log .err { color: #f08989; }
.log .ok  { color: #6fce9e; }

.muted { color: var(--muted); font-size: 12.5px; }

/* ---- pipeline overview ---- */

.funnel-step { margin-bottom: 8px; }

.funnel-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 3px;
}

.funnel-head b { font-variant-numeric: tabular-nums; }

.funnel-bar {
  height: 6px;
  background: var(--track);
  border-radius: 0;
  overflow: hidden;
}

.funnel-bar div {
  height: 100%;
  background: var(--accent);
  border-radius: 0;
  transition: width 0.25s ease;
}

.class-summary {
  margin: 12px 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.class-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 5px;
}

.class-row .cl { flex: 1; }

.class-row em {
  font-style: normal;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.class-row b {
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: right;
}

table.stats {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  table-layout: fixed;
}

table.stats th, table.stats td {
  border-bottom: 1px solid var(--border);
  padding: 5px 4px;
  text-align: right;
  white-space: nowrap;
  color: var(--text);
}

table.stats th { width: 38px; }
table.stats th:first-child { width: auto; }
table.stats th.thbar { width: 84px; }

table.stats th:first-child, table.stats td.tname, table.stats tfoot td:first-child {
  text-align: left;
}

table.stats td.tname {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.stats thead th {
  color: var(--accent);
  font-weight: 600;
}

tr.type-row { cursor: pointer; }
tr.type-row:hover { background: var(--row-hover); }

table.stats tfoot tr.type-row td {
  font-weight: 700;
  border-top: 2px solid var(--accent);
}

td.tdbar { padding-left: 8px; }

.mini-stack {
  display: flex;
  height: 8px;
  border-radius: 0;
  overflow: hidden;
  background: var(--track);
}

.mini-stack span { height: 100%; }

tr.type-detail { display: none; }
tr.type-detail.open { display: table-row; }

tr.type-detail td {
  font-size: 10.5px;
  color: var(--muted);
  text-align: left;
  white-space: normal;
  line-height: 1.7;
  padding: 6px 8px;
  background: var(--row-hover);
}

tr.type-detail td b { color: var(--text); font-weight: 600; }

/* ---- legend ---- */

.legend {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12.5px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.legend em {
  margin-left: auto;
  font-style: normal;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.legend-method {
  font-size: 10.5px;
  color: var(--muted);
  opacity: 0.75;
  margin-top: 2px;
}

.dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--glass-border);
}

/* ---- results ---- */

.result-item {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 8px;
  font-size: 12.5px;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.1s;
}

.result-item:hover { background: var(--row-hover); }

.result-item .rank {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  min-width: 20px;
}

.result-item .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-item .rtype {
  color: var(--muted);
  font-size: 10.5px;
  font-family: "Cascadia Code", Consolas, monospace;
}

.result-item .score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 0;
  color: #fff;
}

/* Suspect Wikidata/Commons match — see enrichWikidata's QID plausibility gate */
.badge-warn {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  color: #7a3e00;
  background: #ffe1a8;
  border: 1px solid #e0a53f;
}

.badge-info {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  color: #0b4a7a;
  background: #cfe8ff;
  border: 1px solid #6fa8dc;
}

.detail-links a.chip-warn {
  color: #7a3e00;
  border-color: #e0a53f;
  background: #fff6e6;
}
.detail-links a.chip-warn:hover {
  background: #ffe1a8;
}

/* ============ map, tooltip & detail panel ============ */

#map {
  flex: 1;
  position: relative;
  background: transparent;
}

/* place search — glass box, top of map (right of the Leaflet controls) */
.search-box {
  position: absolute;
  top: 12px;
  left: 56px;
  width: min(320px, 60%);
  z-index: 1001; /* above the detail panel edge and Leaflet controls */
}

.search-history-label {
  padding: 6px 13px 2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.search-box input {
  width: 100%;
  padding: 9px 13px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: 0;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  outline: none;
}

.search-box input::placeholder { color: var(--muted); }
.search-box input:focus { border-color: var(--accent); }

.search-results {
  display: none;
  margin-top: 6px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: 0;
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
}

.search-results.open { display: block; }

.search-item {
  padding: 8px 13px;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--row-hover); }

.search-item b {
  display: block;
  font-weight: 600;
  color: var(--text);
}

.search-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-empty {
  padding: 10px 13px;
  font-size: 12px;
  color: var(--muted);
}

/* weight bar — resizable zones, bottom-center of map */
.weight-bar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 260px));
  min-width: 320px;
  z-index: 1000; /* above Leaflet panes */
  background: var(--glass-bg-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 0;
  box-shadow: var(--glass-shadow);
  padding: 10px 14px 12px;
}

.wb-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 8px;
}

.wb-header small {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.wb-reset {
  width: auto;
  margin: 0;
  padding: 2px 10px;
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.wb-reset:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.wb-track {
  position: relative;
  display: flex;
  height: 38px;
  border-radius: 0;
  overflow: hidden;
  user-select: none;
}

.wb-seg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: #fff;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: none; /* widths must track the pointer exactly while dragging */
}

.wb-seg b {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.wb-seg .wb-val {
  width: 34px;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  text-align: center;
  font-size: 10px;
  font-family: inherit;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
  cursor: text;
}
.wb-seg .wb-val:focus {
  opacity: 1;
  outline: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 2px;
}
/* hide the native spinner arrows — the field is for typing an exact value, not stepping */
.wb-seg .wb-val::-webkit-outer-spin-button,
.wb-seg .wb-val::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.wb-seg .wb-val[type="number"] {
  -moz-appearance: textfield;
}

.wb-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14px;
  transform: translateX(-50%);
  cursor: col-resize;
  z-index: 2;
  touch-action: none;
}

.wb-handle::after {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.35);
}

.wb-handle:hover::after { background: #fff; }

/* basemap toggle — floating glass pill, bottom-left of map */
.basemap-toggle {
  position: absolute;
  bottom: 16px;
  left: 14px;
  z-index: 1000; /* above Leaflet panes */
  width: auto;
  margin: 0;
  padding: 6px 14px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 0;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  color: var(--text);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.basemap-toggle:hover:not(:disabled) {
  background: var(--glass-bg-strong);
  color: var(--accent);
  border-color: var(--accent);
}

/* trail / commune overlay buttons — stacked above basemap toggle */
.map-overlay-btn {
  position: absolute;
  bottom: 52px;       /* default: just above basemap toggle */
  left: 14px;
  z-index: 1000;
  width: auto;
  margin: 0;
  padding: 6px 14px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 0;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  color: var(--text);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
}
.map-overlay-btn:hover:not(:disabled) {
  background: var(--glass-bg-strong);
  color: var(--accent);
  border-color: var(--accent);
}

/* commune / municipality map labels */
.commune-label {
  background: none;
  border: none;
  font-size: 10px;
  font-weight: 700;
  color: #333;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
  white-space: nowrap;
  pointer-events: none;
}
[data-theme="dark"] .commune-label {
  color: #ddd;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}

/* area grid ("Grid" button) — numbered cell badges, centred on each cell; click = select cell */
.grid-label { background: none; border: none; }
.grid-label span {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 22px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  white-space: nowrap;
  color: #6d28d9;
  background: #fff;
  border: 1.5px solid #7c3aed;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  cursor: pointer;
}
.grid-label span:hover { background: #ede9fe; }
.grid-label.run span      { color: #fff; background: #d97706; border-color: #b45309; }
.grid-label.exported span { color: #fff; background: #16a34a; border-color: #15803d; }
.grid-label.selected span { outline: 3px solid #3388ff; outline-offset: 1px; }
.grid-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.commune-label--dept {
  font-size: 11px;
  color: #555;
  font-style: italic;
}

/* D5 → trail button inside dimension row */
.d5-trail-btn {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  font-size: 10.5px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 0;
  cursor: pointer;
  vertical-align: middle;
}
.d5-trail-btn:hover {
  background: var(--accent);
  color: var(--on-accent);
}

/* trail legend inside the map (only shown when overlay is visible) */
#trailLegend {
  position: absolute;
  top: 130px;
  left: 14px;
  z-index: 1000;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  padding: 8px 12px;
  font-size: 10.5px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: none;
}
#trailLegend.visible { display: block; }

/* hover tooltip — glass card with score overview */
.poi-tooltip {
  background: var(--glass-bg-strong) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border) !important;
  border-radius: 0 !important;
  box-shadow: var(--glass-shadow) !important;
  color: var(--text) !important;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.55;
  padding: 8px 11px !important;
}

.poi-tooltip::before { display: none; } /* hide leaflet tooltip arrow */

.poi-tooltip b { font-weight: 600; }

.poi-tooltip .tt-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
}

.poi-tooltip .tt-dims,
.poi-tooltip .tt-muted {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.poi-tooltip .tt-warn {
  color: #b36b00;
  font-size: 10.5px;
  font-weight: 600;
}

.poi-tooltip .tt-info {
  color: #1a6bab;
  font-size: 10.5px;
  font-weight: 600;
}

/* detail panel — strong glass */
#detailPanel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 372px;
  max-width: 85%;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 0;
  box-shadow: var(--glass-shadow);
  z-index: 1000; /* above Leaflet panes/controls */
  transform: translateX(calc(100% + 24px));
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.25, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#detailPanel.open { transform: translateX(0); }

#detailClose {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 30px;
  height: 30px;
  padding: 0;
  margin: 0;
  border-radius: 0;
  background: var(--track);
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  z-index: 1;
}

#detailClose:hover { background: var(--accent-soft); color: var(--accent); }

#detailContent {
  flex: 1 1 auto;
  min-height: 0; /* allow the flex child to shrink so overflow-y can kick in */
  overflow-y: auto;
  padding: 18px;
  font-size: 13px;
}

#detailContent::-webkit-scrollbar { width: 8px; }
#detailContent::-webkit-scrollbar-thumb { background: var(--track); border-radius: 0; }

.detail-header h3 {
  margin: 0 30px 4px 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.detail-type {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}
.detail-type-osm { opacity: 0.75; }

.detail-header .badge { margin-left: 0; }

.detail-hero {
  margin: -18px -18px 14px;
  height: 150px;
  overflow: hidden;
  background: var(--track);
}

.detail-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.score-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 16px 0 4px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--glass-border);
  border-radius: 0;
}

.score-ring {
  position: relative;
  width: 84px;
  height: 84px;
  flex-shrink: 0;
}

.ring-bg {
  fill: none;
  stroke: var(--track);
  stroke-width: 8;
}

.ring-val {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dasharray 0.35s ease;
}

.ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-text b {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.ring-text span {
  font-size: 8.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.score-class {
  font-size: 14px;
  font-weight: 700;
}

.score-rank {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.dim-w {
  font-style: normal;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0 6px;
  margin-left: 4px;
  vertical-align: 1px;
}

.detail-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.detail-section h4 {
  margin: 0 0 10px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.dim { margin-bottom: 11px; }

.dim-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
}

.dim-val { font-weight: 700; font-variant-numeric: tabular-nums; }

.dim-bar {
  height: 6px;
  background: var(--track);
  border-radius: 0;
  overflow: hidden;
}

.dim-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 0;
  transition: width 0.25s ease;
}

.dim-detail {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.7;
}

.attr {
  display: inline-block;
  font-size: 10px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 0;
  border: 1px solid var(--border);
  color: var(--muted);
}

.attr.on {
  background: rgba(26, 152, 80, 0.12);
  border-color: rgba(26, 152, 80, 0.4);
  color: var(--c-lesser);
}

.attr.off { text-decoration: line-through; opacity: 0.7; }

.abstract {
  margin: 0;
  line-height: 1.6;
  white-space: pre-line;
}

/* coordinate box under "About" */
.coord-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--accent-soft, #f0f4f8);
  border: 1px solid var(--border, #d7dde3);
  font-size: 12.5px;
}
.coord-pair {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.coord-copy {
  cursor: pointer;
  border: 1px solid var(--border, #d7dde3);
  background: #fff;
  padding: 1px 7px;
  font-size: 12px;
  line-height: 1.4;
}
.coord-copy:hover { background: var(--accent-soft, #f0f4f8); }
.coord-link {
  margin-left: auto;
  color: var(--accent, #2c6cb0);
  text-decoration: none;
  font-weight: 600;
}
.coord-link:hover { text-decoration: underline; }

.detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.detail-links a.chip {
  padding: 5px 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 0;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.detail-links a.chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* attribution control is disabled in JS; hide any leftovers defensively */
.leaflet-control-attribution { display: none !important; }

/* ================================================================
   CATEGORY FILTER PANEL
   ================================================================ */

.panel-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.panel-head-row h2 { margin: 0; }
.panel-head-actions { display: flex; gap: 6px; }
button.ghost.tiny {
  padding: 2px 8px;
  font-size: 11px;
}

.category-filter {
  max-height: 260px;
  overflow-y: auto;
  margin-top: 8px;
  scrollbar-width: thin;
}
.cf-group { margin-bottom: 4px; }
.cf-parent {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  padding: 3px 0;
  color: var(--text);
}
.cf-children {
  margin-left: 16px;
  border-left: 2px solid var(--border);
  padding-left: 8px;
  margin-bottom: 4px;
}
.cf-child {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  cursor: pointer;
  padding: 2px 0;
  color: var(--text-muted);
}
.cf-parent small { font-weight: 400; color: var(--text-muted); }
.cf-child:hover, .cf-parent:hover { color: var(--accent); }
.cf-check { accent-color: var(--accent); }

/* ================================================================
   V_INT BADGE
   ================================================================ */

.badge-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
/* ================================================================
   SCORE RING (detail panel)
   ================================================================ */

.score-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}
.score-ring {
  position: relative;
  width: 84px;
  height: 84px;
  flex-shrink: 0;
}
.score-ring svg { transform: rotate(-90deg); width: 84px; height: 84px; }
.ring-bg  { fill: none; stroke: var(--border); stroke-width: 6; }
.ring-val { fill: none; stroke-width: 6; stroke-linecap: round; transition: stroke-dasharray 0.4s ease; }
.ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.ring-text b  { font-size: 16px; font-weight: 800; }
.ring-text span { font-size: 9px; opacity: 0.55; margin-top: 2px; }
.score-meta { flex: 1; }
.score-class { font-weight: 700; font-size: 14px; }
.score-rank  { font-size: 11px; opacity: 0.6; margin-top: 4px; }

/* ================================================================
   SEASON CALENDAR (D6)
   ================================================================ */

.season-loading {
  font-size: 12px;
  opacity: 0.55;
}
.season-calendar {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 3px;
  margin: 6px 0;
}
.sc-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 2px 4px;
  border-radius: 2px;
  border: 1px solid transparent;
  cursor: default;
  position: relative;
}
.sc-open   { background: #d1fae5; border-color: #6ee7b7; color: #065f46; }
.sc-closed { background: #fee2e2; border-color: #fca5a5; color: #7f1d1d; }
[data-theme="dark"] .sc-open   { background: #064e3b; border-color: #059669; color: #6ee7b7; }
[data-theme="dark"] .sc-closed { background: #450a0a; border-color: #dc2626; color: #fca5a5; }
.sc-m {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.sc-photo {
  font-size: 7px;
  margin-top: 1px;
  opacity: 0.7;
}
.sc-leg {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 3px;
}
.sc-leg.sc-open   { background: #d1fae5; border: 1px solid #6ee7b7; }
.sc-leg.sc-closed { background: #fee2e2; border: 1px solid #fca5a5; }

/* Wikipedia pageviews bar chart (detail panel, below Seasonality) */
.pv-chart {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  align-items: end;
  gap: 3px;
  height: 56px;
  margin: 6px 0 2px;
}
.pv-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  cursor: default;
}
.pv-bar {
  width: 100%;
  min-height: 2px;
  border-radius: 2px 2px 0 0;
  background: #93c5fd;
}
.pv-bar.pv-peak { background: #f59e0b; }
.pv-bar.pv-low  { background: #cbd5e1; }
[data-theme="dark"] .pv-bar       { background: #3b82f6; }
[data-theme="dark"] .pv-bar.pv-peak { background: #fbbf24; }
[data-theme="dark"] .pv-bar.pv-low  { background: #475569; }
.pv-m {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-top: 2px;
  opacity: 0.7;
}

/* ================================================================
   PIPELINE FUNNEL STATS
   ================================================================ */

.funnel { margin-bottom: 14px; }
.funnel-step { margin-bottom: 8px; }
.funnel-head {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  margin-bottom: 3px;
}
.funnel-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.funnel-bar > div {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.class-summary { margin-bottom: 14px; }
.class-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 0;
}
.class-row .cl { flex: 1; }
.class-row em  { width: 32px; text-align: right; opacity: 0.55; }
.class-row b   { width: 32px; text-align: right; font-weight: 700; }

.mini-stack {
  display: flex;
  height: 8px;
  border-radius: 2px;
  overflow: hidden;
  width: 120px;
  background: var(--border);
}
.mini-stack span { display: block; height: 100%; }

/* ================================================================
   DETAIL HERO IMAGE
   ================================================================ */

.detail-hero {
  width: 100%;
  max-height: 180px;
  overflow: hidden;
  background: var(--border);
  margin-bottom: 12px;
}
.detail-hero img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}
.detail-header { margin-bottom: 12px; }
.detail-header h3 { margin: 0 0 4px; font-size: 17px; }
.detail-type { font-size: 12px; opacity: 0.6; margin-bottom: 6px; }

/* ================================================================
   DIMENSION ROWS (detail panel)
   ================================================================ */

.dim { margin-bottom: 14px; }
.dim-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 4px;
}
.dim-w {
  font-size: 10px;
  font-weight: 400;
  opacity: 0.55;
  margin-left: 4px;
}
.dim-val {
  font-weight: 800;
  font-size: 14px;
}
.dim-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.dim-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}
.dim-detail {
  font-size: 11px;
  opacity: 0.65;
  line-height: 1.4;
}

/* ================================================================
   SEARCH MODE TABS
   ================================================================ */

.mode-tabs {
  display: flex;
  gap: 5px;
  margin-bottom: 10px;
}
.mode-tab {
  flex: 1;
  padding: 7px 6px;
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.mode-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.mode-tab:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* ================================================================
   MUNICIPALITY AUTOCOMPLETE
   ================================================================ */

.munic-search-wrap { position: relative; margin-top: 6px; }
.munic-search-wrap input {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
}
.munic-search-wrap input:focus { border-color: var(--accent); }
.munic-results {
  display: none;
  position: absolute;
  left: 0; right: 0;
  top: calc(100% + 3px);
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 2000;
  max-height: 220px;
  overflow-y: auto;
}
.munic-results.open { display: block; }
.munic-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.munic-item:last-child { border-bottom: none; }
.munic-item:hover:not(.munic-empty) { background: var(--row-hover); }
.munic-item b { display: block; font-weight: 600; color: var(--text); font-size: 12.5px; }
.munic-item span { display: block; color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.munic-empty { color: var(--muted); cursor: default; }
.munic-selected-label {
  margin-top: 8px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  min-height: 18px;
}

/* ================================================================
   ACCESS ROUTE BUTTON (inside D4 dim row)
   ================================================================ */

.access-route-btn {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 10.5px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 0;
  cursor: pointer;
  vertical-align: middle;
  width: auto;
  margin-top: 0;
}
.access-route-btn:hover { background: var(--accent); color: var(--on-accent); }
