:root {
  --bg: #f2efe6;
  --panel: #ffffff;
  --ink: #1f2a1f;
  --muted: #4d5b4d;
  --accent: #1a7f6b;
  --accent-2: #d1852c;
  --card-shadow: 0 14px 30px rgba(20, 32, 20, 0.1);
  --border: #e1ddd3;
  --panel-tint: #fbfaf5;
  --btn-height: 32px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #f9f6f0 0%, #eee8dd 45%, #e7dfcf 100%);
}

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 28px 48px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  background: linear-gradient(135deg, #ffffff 0%, #f8f4ea 70%);
  padding: 28px 32px;
  border-radius: 20px;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 11px;
  color: var(--accent);
  margin: 0 0 8px;
  font-weight: 600;
}

.hero h1 {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 34px;
  margin: 0 0 8px;
}

.subhead {
  margin: 0;
  color: var(--muted);
  max-width: 520px;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  min-width: 260px;
}

.hero-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 12px;
  flex: 1;
  max-width: 520px;
}

.kpi-card {
  background: #ffffff;
  border: 1px solid rgba(26, 127, 107, 0.25);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 8px 16px rgba(26, 127, 107, 0.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  min-height: 110px;
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
}

.kpi-label--multiline {
  max-width: 120px;
  line-height: 1.1;
}

.kpi-icon {
  font-size: 28px;
  line-height: 1;
  opacity: 0.85;
  pointer-events: none;
}

.kpi-icon--school,
.kpi-icon--students {
  font-size: 34px;
}

.kpi-value {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: #1c3027;
  white-space: nowrap;
  line-height: 1.1;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

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

.pill-button {
  border: 1px solid var(--accent);
  color: white;
  background: var(--accent);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-family: "IBM Plex Sans", sans-serif;
  box-shadow: 0 10px 18px rgba(26, 127, 107, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  min-height: var(--btn-height);
}

.pill-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 22px rgba(26, 127, 107, 0.32);
}

.pill-button.active {
  background: #14584d;
  border-color: #14584d;
}

.file-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(26, 127, 107, 0.35);
  min-height: var(--btn-height);
}

.file-pill input {
  display: none;
}

.file-pill.small {
  padding: 4px 10px;
  font-size: 12px;
  box-shadow: 0 8px 16px rgba(26, 127, 107, 0.25);
  min-height: 26px;
}

.file-pill.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: none;
}

.inline-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.input-sm {
  width: 90px;
}

.ghost {
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 6px 14px;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  min-height: var(--btn-height);
}

.status {
  font-size: 12px;
  color: var(--muted);
}

.content {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 22px;
  margin-top: 26px;
}

.panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 20px 18px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  position: sticky;
  top: 24px;
  height: fit-content;
}

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

.panel-header .ghost.subtle {
  margin-top: -2px;
}

.panel-header h2 {
  margin: 0;
  line-height: 1;
}

.panel h2 {
  margin-top: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 19px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 6px 0 10px;
}

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

.mode-option {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-button {
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  font-family: "IBM Plex Sans", sans-serif;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  min-height: var(--btn-height);
}

.mode-toggle .mode-button {
  flex: 1;
  width: auto;
}

.view-toggle .mode-button {
  width: 100%;
}

.mode-button.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(26, 127, 107, 0.25);
}

.mode-button:hover {
  transform: translateY(-1px);
}

.control {
  margin-bottom: 12px;
}

.control label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.control input:not([type='checkbox']),
.control select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 8px 10px;
  background: var(--panel-tint);
  font-size: 14px;
}

.control select[multiple] {
  height: 110px;
}

.control input:not([type='checkbox']):focus,
.control select:focus {
  outline: 2px solid rgba(26, 127, 107, 0.2);
  border-color: rgba(26, 127, 107, 0.4);
}

.inline-label {
  font-size: 12px;
  color: var(--muted);
}

.control.checkbox-row {
  padding-left: 0;
}

.control.checkbox-row label,
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 500;
}

.control.checkbox-row input[type='checkbox'],
.checkbox-row input[type='checkbox'] {
  margin: 0;
}

.checkbox-row.disabled,
.inline-row.disabled {
  opacity: 0.55;
}

.hint {
  font-size: 11px;
  color: var(--muted);
}

.note {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.viz {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.chart-card,
.table-card {
  background: var(--panel);
  border-radius: 18px;
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
}

.filter-summary-card {
  padding: 8px 14px;
}

.filter-summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.school-search-card {
  padding: 10px 14px;
}

.school-search-card .inline-label {
  display: block;
  margin-bottom: 6px;
}

.school-search-card .inline-row input {
  flex: 1;
  min-width: 180px;
}

.school-search-card .ghost.subtle {
  padding: 6px 12px;
}

.school-search-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.school-search-choice {
  text-align: left;
  width: 100%;
  font-size: 12px;
}

.filter-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 4px 14px;
  font-size: 11px;
  color: var(--muted);
}

.filter-summary-item {
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.filter-summary-label {
  font-weight: 600;
  color: #5f6a5f;
}

.chart-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.ghost.subtle {
  border-color: rgba(26, 127, 107, 0.35);
  color: var(--accent);
  font-size: 12px;
  padding: 6px 10px;
}

.export-dialog {
  border: none;
  border-radius: 16px;
  padding: 20px;
  width: min(360px, 90vw);
  background: #ffffff;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.25);
}

.export-dialog::backdrop {
  background: rgba(14, 20, 14, 0.35);
}

.export-dialog h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.export-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.export-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.export-grid input {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 13px;
}

.export-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.chart-header,
.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}

.chart-header h3,
.table-header h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 19px;
}

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

.data-sources-note {
  font-size: 10px;
  color: #7b897b;
  margin: 2px 0 0 4px;
  font-style: italic;
}

.chart-header-actions {
  display: flex;
  align-items: center;
}

.wide-mode .content {
  grid-template-columns: 1fr;
}

.wide-mode .panel {
  display: none;
}

.split-legend {
  display: none;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}

.split-legend.active {
  display: flex;
}

.split-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.split-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.legend .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
}

.chart {
  min-height: 420px;
}

.viz-surface {
  position: relative;
  min-height: 420px;
}

.map {
  min-height: 420px;
  height: 420px;
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
}

.map-legend {
  position: absolute;
  right: 16px;
  top: 16px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 11px;
  color: var(--muted);
  min-width: 160px;
  box-shadow: 0 10px 20px rgba(20, 32, 20, 0.12);
  z-index: 2;
}

.map-legend-title {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.map-legend-section {
  margin-bottom: 8px;
}

.map-legend-label {
  margin-bottom: 4px;
  font-weight: 600;
}

.map-legend-scale {
  display: flex;
  align-items: center;
  gap: 6px;
}

.map-legend-ramp {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e6efe6 0%, #1a7f6b 100%);
  border: 1px solid rgba(31, 42, 31, 0.1);
}

.map-legend-sizes {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.map-legend-size {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.map-legend-dot {
  border-radius: 50%;
  background: rgba(26, 127, 107, 0.25);
  border: 1px solid rgba(26, 127, 107, 0.45);
}

.map-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 12px;
}

.map-control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-control-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.map-toggle {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.map-toggle-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.map-toggle-button {
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  font-family: "IBM Plex Sans", sans-serif;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.map-toggle-button.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(26, 127, 107, 0.25);
}

.map-toggle-button:hover {
  transform: translateY(-1px);
}

.map-anchor-notice {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.8);
  border: 1px dashed rgba(26, 127, 107, 0.35);
  border-radius: 10px;
  padding: 8px 10px;
}

.map-anchor-subtext {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

.map-anchor-notice.error {
  border-color: rgba(192, 57, 43, 0.5);
  color: #9b2c1f;
  background: rgba(255, 235, 232, 0.7);
}

.map-target-input {
  width: 86px;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background: #ffffff;
}

.map-target-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.map-recenter-input {
  width: 160px;
}

.map-tract-legend {
  margin-top: 8px;
}

.map-tract-education {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.map-tract-education-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.map-tract-education-select {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  background: #ffffff;
  font-size: 12px;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--ink);
}

.map-tract-ramp {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(16, 20, 20, 0.12);
}

.map-tract-labels {
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: rgba(26, 28, 26, 0.72);
}

.map-tract-labels span {
  white-space: nowrap;
}

.cluster-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #111811;
  font-weight: 600;
  font-size: 10px;
  text-align: center;
  line-height: 1.1;
  border: 2px solid #1f241f;
  box-shadow: 0 6px 14px rgba(12, 18, 12, 0.28);
  cursor: pointer;
}

.cluster-marker-label {
  white-space: pre-line;
  display: none;
}

.cluster-marker-label.is-visible {
  display: block;
  padding: 3px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.75);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.85);
}

.table-wrap {
  overflow-x: auto;
}

#schoolTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#schoolTable th,
#schoolTable td {
  text-align: left;
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
}

#schoolTable th {
  font-weight: 600;
  color: var(--muted);
}

#schoolTable tbody tr:nth-child(even) {
  background: #fbfaf6;
}

#schoolTable th.sortable {
  cursor: pointer;
  user-select: none;
}

#schoolTable th.sortable::after {
  content: '↕';
  font-size: 10px;
  margin-left: 6px;
  color: rgba(123, 137, 123, 0.6);
}

#schoolTable th.sortable.sort-asc::after {
  content: '↑';
  color: rgba(26, 127, 107, 0.8);
}

#schoolTable th.sortable.sort-desc::after {
  content: '↓';
  color: rgba(26, 127, 107, 0.8);
}

.summary {
  font-size: 12px;
  color: var(--muted);
}

.meta-secondary {
  margin: 2px 0 0;
  font-size: 11px;
  color: #7b897b;
}

.meta-suppressed {
  font-size: 10px;
  color: #8b988b;
}

.select-actions {
  margin-left: 8px;
  display: inline-flex;
  gap: 6px;
}

.select-action {
  border: 1px solid #cfd6cf;
  background: #f6f8f6;
  color: #6d7b6d;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  min-height: 22px;
}

.control-divider {
  height: 1px;
  background: rgba(217, 212, 201, 0.65);
  margin: 10px 0 12px;
}

.advanced-toggle-row {
  display: flex;
  justify-content: flex-start;
}

.advanced-toggle-row .ghost.subtle {
  padding: 6px 12px;
}

.select-action:hover {
  border-color: #98b4a7;
  color: #3f6f5b;
}

.corr {
  margin: 4px 0 0;
  font-size: 11px;
  color: #6f7d6f;
  display: flex;
  align-items: center;
  gap: 6px;
}

.corr-help,
.info-help {
  font-size: 11px;
  color: #879587;
  cursor: default;
  border: 1px solid rgba(135, 149, 135, 0.35);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  position: relative;
}

.corr-help::after,
.info-help::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background: #1c2a1c;
  color: #e6efe6;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  z-index: 5;
}

.corr-help::before,
.info-help::before {
  content: '';
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: #1c2a1c transparent transparent transparent;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 5;
}

.corr-help:hover::after,
.corr-help:hover::before,
.info-help:hover::after,
.info-help:hover::before,
.info-help:focus::after,
.info-help:focus::before {
  opacity: 1;
}

@media (max-width: 1000px) {
  .content {
    grid-template-columns: 1fr;
  }
  .panel {
    position: static;
  }
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }
  .hero-actions {
    align-items: flex-start;
  }
  .hero-kpis {
    width: 100%;
    max-width: 100%;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}
