/* ─── Reset & variables ──────────────────────────────────────────────────── */

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

:root {
  --bg:           #0f0f1a;
  --bg-card:      #1a1a2e;
  --bg-input:     #20203a;
  --border:       #2a2a4a;
  --border-hi:    #3a3a5e;
  --text:         #e6e6f0;
  --text-muted:   #8b8ba8;
  --accent:       #4ade80;
  --accent-dim:   #22c55e;
  --warn:         #f97316;
  --danger:       #e94560;
  --link:         #5dade2;
  --link-hover:   #85c1e9;
  --grid:         #22223a;
  --font-sans:    "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head:    "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.site-main { flex: 1; padding: 1.5rem 0 3rem; }

/* ─── Header / footer ────────────────────────────────────────────────────── */

.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}
.site-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.site-title {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
}
.site-title:hover { color: var(--accent); text-decoration: none; }
.site-nav a {
  margin-left: 1rem;
  color: var(--text-muted);
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  padding: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
}
.footer-meta { margin-top: 0.35rem; font-size: 0.8rem; }

/* ─── Dashboard header ───────────────────────────────────────────────────── */

.dashboard-header { padding: 1rem 1.25rem 0.5rem; }
.dashboard-header h1 {
  font-size: 1.75rem;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.dashboard-header .lead { color: var(--text-muted); }

/* ─── Purpose / ethics statement ─────────────────────────────────────────── */

.purpose-statement {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--link);
  border-radius: 0.2rem;
  padding: 1rem 1.25rem;
  margin-top: 1.25rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}
.purpose-statement h2 {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.purpose-statement p + p { margin-top: 0.55rem; }
.purpose-statement strong { color: var(--text); }

/* ─── Filters ────────────────────────────────────────────────────────────── */

.filters {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.2rem;
  padding: 1rem 1.25rem;
  margin-top: 1.25rem;
}
.filters-heading {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}
.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}
.filters-grid label {
  display: flex;
  flex-direction: column;
  font-size: 0.825rem;
  color: var(--text-muted);
  gap: 0.3rem;
}
.filters-grid select,
.filters-grid input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0.35rem;
  padding: 0.4rem 0.5rem;
  font: inherit;
  font-size: 0.875rem;
}
.filters-grid select { min-height: 5rem; }
.filters-grid select option { padding: 0.15rem 0.25rem; text-transform: capitalize; }

/* Checkbox-panel multi-selects (replace native <select multiple>) */
.filter-multi {
  display: flex;
  flex-direction: column;
  font-size: 0.825rem;
  color: var(--text-muted);
  gap: 0.3rem;
}
.filter-multi-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.filter-multi-label { font-weight: 500; }
.filter-multi-count { font-size: 0.75rem; color: var(--accent); }
.filter-multi-search {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0.35rem;
  padding: 0.3rem 0.5rem;
  font: inherit;
  font-size: 0.8rem;
}
.filter-multi-options {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  padding: 0.35rem 0.5rem;
  max-height: 8rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.filter-multi-scroll { max-height: 10rem; }
.filters-grid label.filter-check {
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  user-select: none;
  border: 1px solid transparent;
  transition: background-color 0.1s, color 0.1s, border-color 0.1s;
}
.filters-grid label.filter-check:hover {
  background: rgba(93, 173, 226, 0.08);
  color: var(--text);
}
/* Visually hide the checkbox but keep it focusable for keyboard/a11y. */
.filters-grid label.filter-check input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
/* Selection state: green text — implies "checked" without a filled box. */
.filters-grid label.filter-check:has(input[type="checkbox"]:checked) {
  color: var(--accent);
  font-weight: 600;
}
.filters-grid label.filter-check:has(input[type="checkbox"]:checked):hover {
  color: var(--accent-dim);
  background: rgba(74, 222, 128, 0.08);
}
/* Keyboard focus ring on the (invisible) checkbox should highlight the label. */
.filters-grid label.filter-check:focus-within {
  outline: 2px solid var(--link);
  outline-offset: 1px;
}

.range-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.range-inputs input { flex: 1; min-width: 0; }

.filters-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}
.filters-actions button {
  background: var(--bg-input);
  border: 1px solid var(--border-hi);
  color: var(--text);
  border-radius: 0.35rem;
  padding: 0.4rem 0.9rem;
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}
.filters-actions button:hover { border-color: var(--accent); color: var(--accent); }
.active-count { font-size: 0.875rem; color: var(--text-muted); }
.active-count strong { color: var(--text); }

/* ─── KPIs ───────────────────────────────────────────────────────────────── */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
  margin-top: 1.25rem;
}
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.2rem;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.kpi-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.kpi-value {
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--accent);
}

/* ─── Chart card extras ──────────────────────────────────────────────────── */

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.chart-card-header h3 {
  margin: 0;
}
.btn-group {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.link-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--link);
  border-radius: 0.35rem;
  padding: 0.3rem 0.65rem;
  font: inherit;
  font-size: 0.825rem;
  cursor: pointer;
}
.link-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.chart-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0 0 0.6rem;
  font-style: italic;
}

/* ─── Map ────────────────────────────────────────────────────────────────── */

.map-section { margin-top: 1.25rem; }
.map-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.link-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f0f1a;
}
.link-btn.is-active:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: #0f0f1a;
}
.area-select-mode { cursor: crosshair !important; }
.area-select-mode .leaflet-interactive { cursor: crosshair !important; }
.map-canvas {
  height: 480px;
  border-radius: 0.2rem;
  border: 1px solid var(--border);
  background: #0a0a14;
}
.map-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0;
}
/* Leaflet popups/tooltips: dark mode tweaks */
.leaflet-tooltip {
  background: #1a1a2e;
  color: var(--text);
  border: 1px solid var(--border-hi);
  font-size: 0.8rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.leaflet-tooltip-top:before { border-top-color: var(--border-hi); }
.leaflet-control-attribution {
  background: rgba(15, 15, 26, 0.85) !important;
  color: var(--text-muted) !important;
}
.leaflet-control-attribution a { color: var(--link) !important; }

/* ─── Charts ─────────────────────────────────────────────────────────────── */

.charts {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1rem;
}
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.2rem;
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chart-card h3 {
  font-size: 1rem;
  margin-bottom: 0.85rem;
  color: var(--text);
  font-weight: 600;
}
.chart-wide { grid-column: 1 / -1; }
.chart-wrap {
  position: relative;
  height: 300px;
}
.chart-wrap-tall { height: 380px; }
.chart-pie .chart-wrap { height: 280px; }

@media (max-width: 800px) {
  .charts { grid-template-columns: 1fr; }
  .chart-wide { grid-column: auto; }
}
