:root {
  --ink: #1c1b16;
  --muted: #5c574c;
  --paper: #f4f0e6;
  --panel: #fffdf7;
  --rule: #d8d1c2;
  --before: #1f4e79;
  --before-soft: #d7e4f0;
  --after: #8f1d1d;
  --after-soft: #f3d6d4;
  --shadow: 0 10px 30px rgba(28, 27, 22, 0.16);
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

a { color: var(--before); }
a:hover { color: var(--after); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.85rem 1.25rem 0.95rem;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
  z-index: 20;
}
.brand .title {
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 650;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 38rem;
}
.search { position: relative; min-width: 18rem; flex: 0 1 24rem; }
.search input {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  background: #fff;
}
.search-results {
  position: absolute;
  right: 0;
  left: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: var(--shadow);
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  max-height: 20rem;
  overflow: auto;
  z-index: 30;
}
.search-results button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.5rem 0.75rem;
  font: inherit;
  cursor: pointer;
}
.search-results button:hover,
.search-results button:focus { background: var(--paper); }
.search-results .kicker {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.workspace {
  position: relative;
  flex: 1 1 auto;
  min-height: 16rem;
  min-width: 0;
  overflow: hidden;
}
#map {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  background: #ddd6c8;
  z-index: 0;
  isolation: isolate;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 24px;
  z-index: 15;
  width: min(22rem, calc(100% - 24px));
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem 1rem;
}
.legend h2 {
  margin: 0 0 0.6rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.legend-row { display: flex; gap: 0.7rem; margin-bottom: 0.65rem; }
.legend-row p { margin: 0.15rem 0 0; font-size: 0.82rem; color: var(--muted); }
.swatch { flex: 0 0 1.15rem; width: 1.15rem; height: 1.15rem; margin-top: 0.2rem; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.swatch-before { background: var(--before); border-radius: 50%; }
.swatch-after {
  background: var(--after);
  transform: rotate(45deg);
  border-radius: 2px;
  width: 0.95rem;
  height: 0.95rem;
  margin: 0.28rem 0.12rem 0;
}
.legend-filters { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.88rem; margin: 0.4rem 0 0.5rem; }
.legend-note { margin: 0; font-size: 0.78rem; color: var(--muted); }

.panel {
  position: absolute;
  top: 0;
  right: 0;
  left: auto;
  height: 100%;
  width: min(28.5rem, 100%);
  max-width: 100%;
  background: var(--panel);
  border-left: 1px solid var(--rule);
  box-shadow: var(--shadow);
  overflow: auto;
  z-index: 1200;
  padding: 1.25rem 1.35rem 2.5rem;
}
.panel-close {
  position: sticky;
  top: 0;
  float: right;
  border: 0;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.kicker {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel h1 {
  font-family: var(--serif);
  font-size: 1.7rem;
  line-height: 1.2;
  margin: 0 0 0.5rem;
  font-weight: 650;
}
.panel h2 {
  font-family: var(--serif);
  font-size: 1.15rem;
  margin: 1.3rem 0 0.45rem;
}
.panel p, .panel li { line-height: 1.5; }
.meta-line { color: var(--muted); margin: 0 0 0.8rem; }
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  margin-right: 0.3rem;
}
.badge-before { background: var(--before-soft); color: var(--before); }
.badge-after { background: var(--after-soft); color: var(--after); }
.badge-charged { background: #f3e6c8; color: #6a4b00; }
.badge-convicted { background: #e1eadb; color: #1d3b16; }

.card-list, .source-list { list-style: none; padding: 0; margin: 0; }
.card-list li, .source-list li {
  border-top: 1px solid var(--rule);
  padding: 0.7rem 0;
}
.card-list a { font-weight: 650; text-decoration: none; }
.source-list a { word-break: break-word; }
.source-meta { display: block; font-size: 0.8rem; color: var(--muted); }

.site-footer {
  border-top: 1px solid var(--rule);
  padding: 0.65rem 1.25rem 0.8rem;
  background: var(--panel);
  font-size: 0.8rem;
  color: var(--muted);
  z-index: 12;
}
.site-footer p { margin: 0.15rem 0; }

.leaflet-popup-pane { z-index: 1100; }
.leaflet-control-container .leaflet-bottom { z-index: 500; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); }
.leaflet-popup {
  max-width: min(360px, calc(100vw - 24px));
}
.leaflet-popup-content-wrapper {
  max-width: 100%;
}
.leaflet-popup-content {
  margin: 0.85rem 1rem;
  min-width: 12rem;
  max-width: 100%;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--sans);
}
.leaflet-popup-content h3 { font-family: var(--serif); margin: 0.35rem 0 0.35rem; font-size: 1.05rem; }
.popup-actions { margin-top: 0.5rem; }

.leaflet-control-attribution {
  font-size: 10px;
  line-height: 1.4;
  background: rgba(255, 253, 247, 0.72) !important;
  color: var(--muted);
  padding: 0 6px;
  border-radius: 4px 0 0 0;
  max-width: min(18rem, calc(100% - 16px));
}
.leaflet-control-attribution a { color: inherit; }
.leaflet-control-attribution .attribution-toggle {
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 650;
  color: var(--ink);
  cursor: pointer;
  padding: 0 2px;
  margin: 0;
}
.leaflet-control-attribution:not(.is-collapsed) .attribution-toggle {
  margin-right: 0.35rem;
}
.leaflet-control-attribution.is-collapsed > :not(.attribution-toggle) {
  display: none;
}

.marker-pin {
  display: block;
  box-shadow: 0 0 0 2px #fff, 0 1px 4px rgba(0,0,0,.35);
}
.marker-before {
  width: 16px;
  height: 16px;
  margin-left: -8px;
  margin-top: -8px;
  background: var(--before);
  border-radius: 50%;
}
.marker-after {
  width: 15px;
  height: 15px;
  margin-left: -7px;
  margin-top: -7px;
  background: var(--after);
  transform: rotate(45deg);
  border-radius: 2px;
}


.stats-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 1.25rem;
  padding: 0.55rem 1.25rem 0.6rem;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  z-index: 19;
}
.stats-showing {
  margin: 0;
  flex: 1 0 100%;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--ink);
}
.stats-showing[hidden] { display: none; }
.stats-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.6rem;
  list-style: none;
  margin: 0;
  padding: 0;
  align-items: flex-start;
}
.stats-metrics li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15rem 0.45rem;
}
.stats-incidents { flex: 1 1 16rem; }
.stats-value {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1;
}
.stats-label {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}
.stats-split {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  flex: 1 0 100%;
  margin-top: 0.2rem;
  font-size: 0.82rem;
}
.stats-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 650;
}
.stats-chip-before { color: var(--before); }
.stats-chip-after { color: var(--after); }
.stats-chip-before::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--before);
  box-shadow: 0 0 0 1px #fff, 0 0 0 2px var(--before);
  flex: 0 0 auto;
}
.stats-chip-after::before {
  content: "";
  width: 0.58rem;
  height: 0.58rem;
  background: var(--after);
  transform: rotate(45deg);
  border-radius: 1px;
  box-shadow: 0 0 0 1px #fff, 0 0 0 2px var(--after);
  flex: 0 0 auto;
}

@media (max-width: 800px) {
  .site-header { flex-direction: column; align-items: stretch; }
  .stats-bar { padding: 0.5rem 1rem 0.55rem; }
  .stats-value { font-size: 1.2rem; }
  html, body { height: auto; min-height: 100%; }
  body { overflow-y: auto; }
  .search { min-width: 0; flex: 0 0 auto; width: 100%; }
  .workspace { min-height: 55vh; }
  .legend {
    bottom: 8px;
    width: min(16rem, calc(100% - 24px));
    padding: 0.5rem 0.65rem 0.55rem;
    max-height: 42%;
    overflow: auto;
  }
  .legend-row { margin-bottom: 0.3rem; }
  .legend-row p,
  .legend-note { display: none; }
  .legend-filters { margin: 0.15rem 0 0; }
  .panel { width: 100%; }
  .leaflet-popup {
    max-width: calc(100vw - 24px);
  }
  .leaflet-popup-content {
    min-width: 0;
    max-width: 100%;
  }
  .leaflet-control-attribution {
    max-width: calc(100vw - 24px);
  }
}

.header-nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-left: auto;
  flex: 0 0 auto;
}
.header-nav a {
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
  color: var(--ink);
  border-bottom: 2px solid transparent;
  padding-bottom: 0.1rem;
}
.header-nav a:hover,
.header-nav a[aria-current="page"] {
  color: var(--before);
  border-bottom-color: var(--before);
}

.page {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--paper);
}
.page-body {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.4rem 1.25rem 3rem;
}
.page-body h1 {
  font-family: var(--serif);
  font-size: 2rem;
  margin: 0 0 0.6rem;
  font-weight: 650;
}
.page-body h2 {
  font-family: var(--serif);
  font-size: 1.2rem;
  margin: 1.5rem 0 0.5rem;
}
body.page-open .workspace,
body.page-open .site-footer .credits { display: none; }
body.page-open .site-header { align-items: center; }

.notice {
  background: #f3e6c8;
  border: 1px solid #d9c28a;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin: 0 0 1.2rem;
}
.notice p { margin: 0 0 0.55rem; }
.notice p:last-child { margin-bottom: 0; }

.form-grid { display: grid; gap: 0.85rem; }
.form-row { display: grid; gap: 0.85rem; }
@media (min-width: 640px) {
  .form-row-2 { grid-template-columns: 1fr 1fr; }
}
label.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 650;
  font-size: 0.92rem;
}
label.field input,
label.field select,
label.field textarea {
  font: inherit;
  font-weight: 400;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
}
label.field textarea { min-height: 5.5rem; resize: vertical; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.82rem; }
.req { color: var(--after); }

.incident-block {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem;
  background: var(--panel);
  margin-bottom: 0.7rem;
}
.incident-block h3 { margin: 0 0 0.7rem; font-size: 0.95rem; }

.btn, .btn-secondary, .btn-danger {
  font: inherit;
  font-weight: 650;
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn { background: var(--before); color: #fff; }
.btn:hover { filter: brightness(1.08); }
.btn-secondary { background: #fff; border-color: var(--rule); color: var(--ink); }
.btn-danger { background: var(--after); color: #fff; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.source-input { margin-bottom: 0.45rem; }

.form-status[hidden] { display: none; }
.form-status { margin-top: 0.9rem; padding: 0.75rem 0.85rem; border-radius: 8px; }
.form-status.error { background: var(--after-soft); color: var(--after); }
.form-status.ok { background: var(--before-soft); color: var(--before); }
.form-status pre, .json-preview {
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.7rem;
  font-size: 0.8rem;
  max-height: 16rem;
  overflow: auto;
}

.hp-field {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.review-card {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
  padding: 1rem 1.1rem 1.1rem;
  margin: 0 0 1rem;
}
.review-card h2 { margin-top: 0; }
.review-card dt { font-weight: 650; margin-top: 0.55rem; }
.review-card dd { margin: 0.15rem 0 0; }
.muted { color: var(--muted); }

@media (max-width: 800px) {
  .header-nav { margin-left: 0; }
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.1rem;
  margin: 0.45rem 0 0.35rem;
}
.footer-nav a {
  font-weight: 650;
  text-decoration: none;
  color: var(--ink);
}
.footer-nav a:hover,
.footer-nav a[aria-current="page"] {
  color: var(--before);
}

.review-tabs {
  display: flex;
  gap: 0;
  margin: 1rem 0 1.25rem;
  border-bottom: 1px solid var(--rule);
}
.review-tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  font: inherit;
  font-weight: 650;
  padding: 0.4rem 0.95rem 0.5rem;
  cursor: pointer;
  color: var(--muted);
}
.review-tabs button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--before);
}
.review-tab-panel[hidden] { display: none; }
.tab-count { font-weight: 500; color: var(--muted); }
