:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1b1d22;
  --muted: #5d6270;
  --line: #e2e0da;
  --accent: #0f5c4d;
  --accent-soft: #e3f0ec;
  --warn-bg: #fff4d6;
  --warn-ink: #5a4100;
  --warn-line: #e9c96b;

  /* pin colours (brief: red, orange, blue, purple) */
  --red: #c62828;
  --orange: #e8710a;
  --blue: #1f5fbf;
  --purple: #7b3fb5;

  --sidebar: 340px;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(20, 22, 30, 0.16);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg); }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #2f7de1; outline-offset: 2px; }

/* ---- header + disclaimer ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--ink); color: #fff;
  position: relative; z-index: 1200; /* keeps the mobile dropdown above the map and drawer */
}
/* brand stays pinned left at every width: it takes the free space and lets the subtitle wrap */
.brand { flex: 1 1 auto; min-width: 0; text-align: left; }
.brand h1 {
  margin: 0; font-size: 1.15rem; letter-spacing: 0.01em; white-space: nowrap;
  display: flex; align-items: center; justify-content: flex-start; gap: 8px;
}
.brand .logo { display: block; width: 1.95em; height: 1.3em; border-radius: 2px; flex: none; }
.brand p { margin: 2px 0 0; font-size: 0.8rem; color: #c9ccd4; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: none; }
.site-menu { display: flex; align-items: center; gap: 8px; }
.topbar-btn {
  border: 1px solid #fff6; background: transparent; color: #fff;
  border-radius: 8px; padding: 7px 12px; font: inherit; font-size: 0.85rem; cursor: pointer;
}
.topbar-btn:hover { background: #ffffff1a; }
.drawer-toggle, .menu-toggle { display: none; }
.menu-toggle { font-size: 1.15rem; line-height: 1; padding: 6px 11px; }

.disclaimer {
  padding: 7px 16px; font-size: 0.8rem; line-height: 1.45;
  background: var(--warn-bg); color: var(--warn-ink); border-top: 1px solid var(--warn-line);
}

/* ---- methodology modal ---- */
.modal {
  width: min(620px, calc(100% - 32px)); max-height: calc(100% - 48px); overflow-y: auto;
  padding: 22px 24px 20px; border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  background: var(--surface); color: var(--ink); font-size: 0.92rem; line-height: 1.55;
}
.modal::backdrop { background: rgba(20, 22, 30, 0.55); }
.modal h2 { margin: 0 44px 10px 0; font-size: 1.25rem; }
.modal h3 { margin: 18px 0 6px; font-size: 0.98rem; color: var(--accent); }
.modal p { margin: 0 0 10px; }
.modal ul { margin: 0 0 10px; padding-left: 20px; }
.modal li { margin-bottom: 3px; }
.modal .defs { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 12px; }
.modal .defs dt { font-weight: 700; }
.modal .defs dd { margin: 0; }
.modal-wide { width: min(820px, calc(100% - 32px)); }
.incident-list { list-style: none; margin: 0; padding: 0; }
.modal .incident-list li { margin: 0; padding: 12px 0; border-top: 1px solid var(--line); }
.modal .incident-list h3 { margin: 0 0 4px; font-size: 0.95rem; color: var(--ink); }
.modal .incident-list p { margin: 0 0 6px; font-size: 0.88rem; }
.incident-meta { color: var(--muted); font-size: 0.8rem !important; }
.incident-list [lang="ur"] { font-family: "Noto Nastaliq Urdu", serif; line-height: 2; }

/* ---- layout ---- */
.layout { flex: 1; display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 0; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }

/* ---- tabs ---- */
.tabs { display: flex; position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; padding: 12px 8px; border: 0; background: none; font: inherit; font-weight: 600;
  font-size: 0.9rem; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tabpanel { padding: 14px 16px 24px; }

/* ---- filters ---- */
.count { margin: 0 0 14px; font-size: 0.9rem; color: var(--muted); }
.count strong { color: var(--ink); }
.group { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }
.group legend, .field-label {
  display: block; padding: 0; margin-bottom: 8px; font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.years { display: flex; gap: 6px; font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }

/* two overlaid range inputs = one slider with two handles */
.range { position: relative; height: 28px; }
.range::before {
  content: ""; position: absolute; left: 0; right: 0; top: 12px; height: 4px; border-radius: 2px; background: var(--line);
}
.range input {
  position: absolute; inset: 0; width: 100%; margin: 0; background: none; pointer-events: none;
  -webkit-appearance: none; appearance: none;
}
.range input::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 4px #0005; cursor: pointer;
}
.range input::-moz-range-thumb {
  pointer-events: auto; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 4px #0005; cursor: pointer;
}
.range input::-moz-range-track { background: none; }

.checks { display: grid; gap: 6px; }
.check { display: flex; align-items: center; gap: 9px; font-size: 0.92rem; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.check svg { flex: none; }
.check .n { margin-left: auto; color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

select {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 0.92rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--ink);
}
.reset {
  width: 100%; padding: 9px; font: inherit; font-weight: 600; font-size: 0.88rem; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); border: 1px solid #c4ddd5; border-radius: 8px;
}
.download {
  width: 100%; margin-top: 8px; padding: 9px; font: inherit; font-weight: 600; font-size: 0.88rem; cursor: pointer;
  background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 8px;
}
.download:hover { background: #0b4a3e; }
.download:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- legal library ---- */
.intro { margin: 0 0 14px; font-size: 0.86rem; line-height: 1.5; color: var(--muted); }
.muted { color: var(--muted); }
.act { margin-bottom: 18px; }
.act h3 { margin: 0 0 4px; font-size: 0.95rem; }
.act-links { margin: 0 0 8px; font-size: 0.8rem; }
.act-note {
  margin: 0 0 10px; padding: 8px 10px; font-size: 0.82rem; line-height: 1.5;
  background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0;
}
.law-group {
  margin: 12px 0 6px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.law { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: var(--surface); }
.law summary {
  display: flex; gap: 6px; padding: 9px 11px; cursor: pointer; font-size: 0.88rem; line-height: 1.35; list-style: none;
}
.law summary::-webkit-details-marker { display: none; }
.law summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s; }
.law[open] summary::before { transform: rotate(90deg); }
.law summary b { color: var(--accent); margin-right: 4px; }
.law[open] summary { border-bottom: 1px solid var(--line); }
.law .body { padding: 9px 11px 11px; font-size: 0.85rem; line-height: 1.5; }
.law .body p { margin: 0 0 8px; }
.law .penalty { color: var(--muted); }
.law .official { font-weight: 600; }

/* ---- detail panel ---- */
.detail {
  position: absolute; z-index: 1000; top: 12px; right: 12px; bottom: 12px; width: min(390px, calc(100% - 24px));
  overflow-y: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 18px 20px;
}
.close {
  position: absolute; top: 8px; right: 10px; width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: #f0efeb; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted);
}
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 40px 10px 0; }
.badge { font-size: 0.74rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; color: #fff; }
.badge.cat { background: #eceae4; color: var(--ink); }
.detail h2 { margin: 0 0 12px; font-size: 1.12rem; line-height: 1.35; }
.detail h2:focus { outline: none; } /* focused programmatically so screen readers start at the headline */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0 0 14px; font-size: 0.87rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.summary { font-size: 0.93rem; line-height: 1.6; margin: 0 0 16px; }
.source {
  display: inline-block; padding: 9px 14px; border-radius: 8px; background: var(--accent); color: #fff;
  font-weight: 600; font-size: 0.9rem; text-decoration: none;
}
.source:hover { background: #0b4a3e; }
.source-name { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }

[lang="ur"] {
  font-family: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", serif; line-height: 2.1; font-size: 1.05em;
}
.detail h2[lang="ur"] { line-height: 2; }

.map-message {
  position: absolute; z-index: 900; left: 50%; top: 16px; transform: translateX(-50%); margin: 0;
  max-width: calc(100% - 32px); padding: 10px 14px; border-radius: 8px; background: var(--surface);
  box-shadow: var(--shadow); font-size: 0.9rem;
}

/* ---- data & trends dashboard ---- */
.view-toggle[aria-pressed="true"] { background: #fff; color: var(--ink); border-color: #fff; }
.dashboard { position: absolute; z-index: 950; inset: 0; overflow-y: auto; padding: 18px 20px 24px; background: var(--bg); }
.dash-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-bottom: 14px; }
.dash-head h2 { margin: 0; font-size: 1.2rem; }
.dash-head p { margin: 0; font-size: 0.9rem; }
.dash-head strong { color: var(--ink); }
.dash-message { position: static; transform: none; margin: 0 0 14px; max-width: none; }
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card {
  margin: 0; min-width: 0; padding: 14px 16px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.card-wide { grid-column: 1 / -1; }
.card figcaption {
  margin-bottom: 10px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}
.chart-box { position: relative; height: 240px; }
.chart-box.chart-tall { height: 280px; }
.dash-note { margin: 14px 0 0; font-size: 0.8rem; line-height: 1.5; }

/* ---- pins + legend ---- */
.sw-pin { background: none; border: 0; }
.sw-pin svg { display: block; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45)); }
.sw-pin.active svg { transform: scale(1.35); }
.sw-cluster { background: none; border: 0; }
.sw-cluster div {
  display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;
  border-radius: 50%; border: 3px solid #fff; background: var(--accent); color: #fff;
  font: 700 0.8rem/1 "Inter", system-ui, sans-serif; font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.sw-cluster:hover div { background: #0b4a3e; }
.legend {
  background: var(--surface); padding: 10px 12px; border-radius: 8px; box-shadow: var(--shadow);
  font: 0.78rem/1.5 "Inter", system-ui, sans-serif; color: var(--ink);
}
.legend h4 { margin: 0 0 4px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.legend div { display: flex; align-items: center; gap: 6px; }
.legend section + section { margin-top: 8px; }

/* ---- small screens: header menu becomes a ☰ dropdown, sidebar a drawer, detail a bottom sheet ---- */
@media (max-width: 767px) {
  .drawer-toggle, .menu-toggle { display: inline-block; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand h1 { font-size: 1.05rem; }
  .brand p { font-size: 0.72rem; }
  .topbar-actions { position: relative; gap: 6px; }
  .topbar-btn { padding: 6px 9px; font-size: 0.8rem; }
  .menu-toggle { padding: 5px 10px; font-size: 1.1rem; }
  .site-menu {
    display: none; position: absolute; top: calc(100% + 8px); right: 0; min-width: 200px;
    flex-direction: column; align-items: stretch; gap: 2px; padding: 6px;
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  }
  .site-menu.open { display: flex; }
  .site-menu .topbar-btn {
    border: 0; border-radius: 6px; padding: 11px 12px; text-align: left;
    font-size: 0.92rem; color: var(--ink); background: none;
  }
  .site-menu .topbar-btn:hover { background: var(--accent-soft); }
  .site-menu .view-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
  .disclaimer { font-size: 0.72rem; padding: 6px 12px; }
  .modal { padding: 18px 16px 16px; }
  .layout { grid-template-columns: 1fr; position: relative; }
  .sidebar {
    position: absolute; z-index: 1100; inset: 0 auto 0 0; width: min(340px, 88vw);
    transform: translateX(-102%); transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .detail { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62%; }
  .legend { display: none; }
  .dashboard { padding: 14px 16px 20px; }
  .dash-grid { grid-template-columns: 1fr; }
}
