:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-muted: #eef2f1;
  --ink: #17212b;
  --muted: #65717f;
  --line: #dce2e5;
  --green: #2f7663;
  --blue: #355d8a;
  --amber: #b86b25;
  --rose: #a84561;
  --shadow: 0 18px 45px rgba(27, 39, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 820px;
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.4rem);
  line-height: 1.03;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.topbar-actions {
  display: grid;
  gap: 10px;
  min-width: 260px;
}

.auth-panel,
.source-panel {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
}

.auth-panel {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  color: var(--ink);
}

.auth-panel strong,
.auth-panel span {
  display: block;
}

.auth-panel strong {
  overflow: hidden;
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-panel span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.auth-actions {
  display: flex;
  gap: 6px;
}

.auth-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.auth-panel.is-synced {
  border-color: rgba(47, 118, 99, 0.32);
}

.auth-panel.is-warning {
  border-color: rgba(184, 107, 37, 0.34);
}

.dataset-tabs {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dataset-tab {
  min-height: 38px;
  border-color: transparent;
  background: transparent;
}

.dataset-tab.is-active {
  background: var(--ink);
  color: #fff;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.metric-card {
  min-height: 118px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-top: 14px;
  font-size: 2.45rem;
  line-height: 1;
  letter-spacing: 0;
}

.controls {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, minmax(140px, 0.55fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.controls label {
  display: grid;
  gap: 7px;
}

.controls span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  color: var(--ink);
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(47, 118, 99, 0.24);
  outline-offset: 2px;
}

textarea {
  min-height: 132px;
  padding: 11px 12px;
  resize: vertical;
}

.control-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

button:hover {
  border-color: #b5c0c5;
  background: #e5ebea;
}

#exportButton {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.workflow-panel {
  margin-bottom: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.workflow-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 0;
}

.workflow-panel.is-open .workflow-header {
  margin-bottom: 14px;
}

.workflow-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.workflow-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  margin-bottom: 10px;
}

.workflow-body[hidden] {
  display: none;
}

#workflowToggleButton {
  min-width: 82px;
}

.workflow-actions label,
.template-grid label {
  display: grid;
  gap: 7px;
}

.workflow-actions span,
.template-grid span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.template-grid {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(260px, 1.4fr) minmax(240px, 1fr);
  gap: 10px;
  align-items: stretch;
}

.template-field {
  min-width: 0;
}

.insight-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1fr) minmax(0, 1.2fr) minmax(280px, 0.9fr);
  gap: 12px;
  margin-bottom: 12px;
}

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

.panel {
  min-height: 310px;
  padding: 16px;
}

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

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(120px, 1fr) 42px;
  gap: 10px;
  align-items: center;
  min-height: 34px;
}

.bar-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1f2;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.bar-row:nth-child(2n) .bar-fill {
  background: var(--blue);
}

.bar-row:nth-child(3n) .bar-fill {
  background: var(--amber);
}

.bar-count {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  text-align: right;
}

.map-panel {
  overflow: hidden;
}

#geoPlot {
  display: block;
  width: 100%;
  height: 246px;
  border-radius: 6px;
  background: linear-gradient(180deg, #f8faf9 0%, #edf3f5 100%);
}

.plot-label {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.empty-plot {
  font-size: 13px;
}

.plot-point {
  fill: var(--green);
  opacity: 0.78;
  transition:
    r 0.16s ease,
    opacity 0.16s ease;
}

.plot-point.filtered {
  fill: var(--rose);
  opacity: 0.92;
}

.table-panel {
  overflow: hidden;
}

.table-header {
  margin: 0;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.table-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 999px;
}

.official {
  background: var(--green);
}

.supplement {
  background: var(--rose);
}

.table-wrap {
  overflow: auto;
  max-height: 68vh;
}

table {
  width: 100%;
  min-width: 1580px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f9fbfb;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  user-select: none;
}

th[data-sort] {
  cursor: pointer;
}

tbody tr:hover {
  background: #f8fbfa;
}

.school-name,
.leader-name {
  display: block;
  color: var(--ink);
  font-weight: 800;
}

.subtext {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #e9efed;
  color: #24463d;
  padding: 3px 9px;
  font-size: 0.8rem;
  font-weight: 800;
}

.source-pill {
  border: 1px solid rgba(47, 118, 99, 0.25);
  background: #edf6f2;
}

.source-pill.supplemented {
  border-color: rgba(168, 69, 97, 0.25);
  background: #f9eef2;
  color: #7e3048;
}

.audit-pill {
  border: 1px solid transparent;
}

.audit-good {
  border-color: rgba(47, 118, 99, 0.28);
  background: #eaf5f1;
  color: #24463d;
}

.audit-ok {
  border-color: rgba(53, 93, 138, 0.24);
  background: #edf3fa;
  color: #284866;
}

.audit-review {
  border-color: rgba(184, 107, 37, 0.28);
  background: #fbf0e3;
  color: #7a4318;
}

.audit-bad {
  border-color: rgba(168, 69, 97, 0.28);
  background: #faedf1;
  color: #773047;
}

.audit-muted {
  border-color: rgba(101, 113, 127, 0.18);
  background: #f1f4f5;
  color: #4f5a64;
}

.audit-highlight {
  color: #7a4318;
  font-weight: 800;
}

.contact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.contact-actions a,
.contact-actions button,
.flow-actions a,
.flow-actions button {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.contact-actions button,
.flow-actions button {
  cursor: pointer;
}

.flow-cell {
  min-width: 250px;
}

.flow-status-select {
  margin-top: 8px;
  height: 36px;
  font-size: 0.84rem;
}

.flow-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.flow-actions a,
.flow-actions button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 0.78rem;
}

.flow-actions button:disabled {
  color: #96a0a8;
  cursor: not-allowed;
}

.quality-pill {
  border: 1px solid transparent;
}

.quality-good {
  border-color: rgba(47, 118, 99, 0.28);
  background: #eaf5f1;
  color: #24463d;
}

.quality-warn {
  border-color: rgba(184, 107, 37, 0.28);
  background: #fbf0e3;
  color: #7a4318;
}

.quality-review {
  border-color: rgba(53, 93, 138, 0.24);
  background: #edf3fa;
  color: #284866;
}

.quality-bad {
  border-color: rgba(168, 69, 97, 0.28);
  background: #faedf1;
  color: #773047;
}

.empty-state {
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1120px) {
  .topbar,
  .controls,
  .workflow-header,
  .template-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    display: grid;
  }

  .topbar-actions {
    min-width: 0;
  }

  .workflow-header {
    display: grid;
    align-items: stretch;
  }

  .workflow-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .metric-grid,
  .insight-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .map-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 18px;
  }

  .metric-grid,
  .insight-grid {
    grid-template-columns: 1fr;
  }

  .dataset-tabs {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .metric-card {
    min-height: 92px;
  }

  .metric-card strong {
    font-size: 2rem;
  }

  .control-actions {
    justify-content: stretch;
  }

  .control-actions button,
  .workflow-actions button {
    flex: 1;
  }

  .workflow-actions {
    grid-template-columns: 1fr;
  }
}
