:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --ink: #17201c;
  --muted: #66736d;
  --line: #d8ded9;
  --teal: #14746f;
  --blue: #285e8e;
  --amber: #b98322;
  --rust: #a94328;
  --red: #8f1f1f;
  --green: #4d7c35;
  --shadow: 0 16px 40px rgba(23, 32, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 24px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ghost-button,
.primary-link {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
}

.primary-link {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px 32px 42px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.geography-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.metric strong.metric-status {
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
}

.evidence {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.evidence h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.evidence-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 13px;
}

.evidence-row strong {
  text-align: right;
}

.evidence-note {
  margin: 8px 0 0;
  font-size: 12px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.notice {
  margin: 16px 0;
  padding: 12px 14px;
  border-left: 4px solid var(--amber);
  background: #fff8e7;
  color: #553a0b;
  line-height: 1.45;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 0.85fr);
  gap: 16px;
  align-items: start;
}

.panel,
.table-section,
.methodology-grid {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.map-panel {
  grid-row: span 2;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 10px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.pager button:disabled {
  opacity: 0.45;
  cursor: default;
}

.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

#streetMap {
  width: 100%;
  height: 620px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
  /* Force a paint clip so Leaflet's composited zoom/pan layers stay inside the
     rounded box (border-radius + overflow:hidden alone does not clip them). */
  contain: paint;
  isolation: isolate;
}

.legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.choropleth-legend {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.legend-swatch {
  width: 18px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(23, 32, 28, 0.12);
}

.leaflet-container {
  font: inherit;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  box-shadow: var(--shadow);
}

.map-popup {
  min-width: 240px;
}

.map-popup h3 {
  margin: 0 0 5px;
  font-size: 15px;
  line-height: 1.2;
}

.map-popup p {
  margin: 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.map-popup strong {
  color: var(--ink);
}

.map-tools {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: none;
}

.toggle-label input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.chart {
  min-height: 230px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 170px) 1fr minmax(44px, auto);
  align-items: center;
  gap: 10px;
  margin: 11px 0;
  font-size: 13px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
}

.system-detail {
  display: grid;
  gap: 12px;
}

.detail-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.component-grid {
  display: grid;
  gap: 8px;
}

.component-row {
  display: grid;
  grid-template-columns: 150px 1fr 44px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.fact {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 8px;
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.fact strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
}

.table-section {
  margin-top: 16px;
  padding: 16px;
}

.table-wrap {
  overflow: auto;
  max-height: 620px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  background: var(--surface);
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  z-index: 1;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #eaf4f1;
}

.methodology-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin-top: 16px;
  padding: 18px;
  line-height: 1.55;
}

.methodology-grid p,
.methodology-grid li {
  color: var(--muted);
}

.tooltip {
  position: fixed;
  pointer-events: none;
  max-width: 280px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 12px;
  z-index: 10;
}

.muted {
  color: var(--muted);
}

@media (max-width: 1100px) {
  .summary-grid,
  .geography-grid,
  .filters,
  .dashboard-grid,
  .methodology-grid {
    grid-template-columns: 1fr 1fr;
  }

  .map-panel {
    grid-column: span 2;
  }

}

@media (max-width: 720px) {
  .app-header,
  .panel-header,
  .detail-title {
    display: grid;
  }

  .app-shell,
  .app-header {
    padding-left: 16px;
    padding-right: 16px;
  }

  .summary-grid,
  .geography-grid,
  .filters,
  .dashboard-grid,
  .methodology-grid,
  .fact-grid {
    grid-template-columns: 1fr;
  }

  .map-panel {
    grid-column: auto;
  }

  h1 {
    font-size: 22px;
  }
}
