/* ─── Reset & Variables ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --uc-blue:   #003262;
  --uc-gold:   #FDB515;
  --bg:        #f0f2f7;
  --surface:   #ffffff;
  --border:    #dde1ea;
  --text:      #1a1a2e;
  --text-muted:#6b7280;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.07), 0 4px 14px rgba(0,0,0,.05);
  --admit-high:#16a34a;
  --admit-mid: #d97706;
  --admit-low: #dc2626;
  --admit-none:#94a3b8;
  --panel-h:   480px;   /* shared height of both chart panels */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Loading ─── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.93);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.loading-overlay.hidden { display: none; }
.loading-box { text-align: center; color: var(--text-muted); }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--border); border-top-color: var(--uc-blue);
  border-radius: 50%; animation: spin .7s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-msg { font-size: .875rem; }

/* ─── Header ─── */
header {
  background: var(--uc-blue);
  color: #fff;
  padding: 12px 24px;
  box-shadow: 0 2px 8px rgba(0,50,98,.3);
}
.header-inner {
  max-width: 1600px; margin: 0 auto;
}
header h1 { font-size: 1.15rem; font-weight: 700; line-height: 1.3; }
.subtitle { color: #90b4d4; font-size: .78rem; margin-top: 2px; }

/* ─── Main ─── */
main {
  flex: 1;
  max-width: 1600px; width: 100%; margin: 0 auto;
  padding: 14px 20px 20px;
  display: flex; flex-direction: column; gap: 14px;
}

/* ─── Notes bar ─── */
.notes-bar {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-left: 3px solid var(--uc-blue);
  border-radius: var(--radius);
  padding: 10px 16px;
}
.notes-title {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--uc-blue);
  margin-bottom: 6px;
}
.notes-bar ul {
  list-style: none;
  padding: 0; margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.notes-bar li {
  position: relative;
  padding-left: 13px;
  font-size: .76rem;
  color: var(--text);
  line-height: 1.5;
}
.notes-bar li::before {
  content: '•';
  color: var(--uc-blue);
  font-weight: 700;
  position: absolute;
  left: 0;
}
.notes-bar strong { font-weight: 600; }
.notes-bar a { color: var(--uc-blue); text-decoration: none; }
.notes-bar a:hover { text-decoration: underline; }

/* ══════════════════════════════════ ROW 1: Two chart panels ═════════════════ */

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: stretch;   /* both panels stretch to the same height */
}

/* ─── Chart Panel (shared by TS and Compare) ─── */
.chart-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: var(--panel-h);
  overflow: hidden;
}

/* Controls area — sits above the chart body */
.panel-controls {
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.school-picker-wrap {
  display: flex; flex-direction: column; gap: 4px;
}

.inline-filters {
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* Chart body — fills remaining space, keeps canvas bottom aligned */
.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 8px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.chart-title { font-size: .95rem; font-weight: 700; color: var(--uc-blue); }
.chart-sub   { font-size: .76rem; color: var(--text-muted); margin-top: 2px; }

.chart-legend {
  display: flex; gap: 12px; flex-wrap: wrap; flex-shrink: 0;
}
.legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: .75rem; color: var(--text-muted); white-space: nowrap;
}
.legend-bar {
  width: 14px; height: 10px; border-radius: 2px;
  background: rgba(59,130,246,.5); flex-shrink: 0;
}
.legend-line {
  width: 20px; height: 3px; border-radius: 2px; flex-shrink: 0;
}
.legend-line.red   { background: #dc2626; }
.legend-line.green { background: #16a34a; }

/* Canvas wrapper fills remaining vertical space → guarantees bottom alignment */
.chart-canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}
.chart-canvas-wrap canvas {
  position: absolute; inset: 0; width: 100% !important; height: 100% !important;
}

.chart-note {
  flex-shrink: 0;
  margin-top: 6px;
  font-size: .7rem; color: var(--text-muted); text-align: center;
}

/* No-data message */
.no-data-msg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: .875rem;
}

/* ─── Compare chips ─── */
.cmp-tags {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  min-height: 28px;
  max-height: 68px;
  overflow-y: auto;
}
.cmp-hint {
  font-size: .78rem; color: var(--text-muted); font-style: italic;
}
.cmp-chip {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 8px 3px 6px;
  border-radius: 20px; border: 1.5px solid;
  font-size: .75rem;
}
.chip-dot  { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.chip-name {
  font-weight: 600; color: var(--text);
  max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip-city { color: var(--text-muted); font-size: .7rem; }
.chip-remove {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1rem; line-height: 1; padding: 0 0 0 2px;
  display: flex; align-items: center;
}
.chip-remove:hover { color: var(--text); }

/* ─── Shared form elements ─── */
.ctrl-label {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  display: block; margin-bottom: 3px;
}

.filter-group { display: flex; flex-direction: column; }

/* Shared style: native selects + the school-type dropdown button look identical */
.filter-group select,
.type-dropdown-btn {
  padding: 6px 26px 6px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: .82rem; font-family: inherit;
  background-color: var(--surface); cursor: pointer; outline: none;
  min-height: 34px; color: var(--text);
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  text-align: left; width: 100%;
}
.filter-group select:focus,
.type-dropdown-btn:focus { border-color: var(--uc-blue); }

/* School search inputs */
.school-search-wrap { position: relative; }

#ts-school-input,
#cmp-school-input,
#map-school-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: .85rem; font-weight: 600; color: var(--uc-blue);
  outline: none; min-height: 34px;
}
#ts-school-input:focus,
#cmp-school-input:focus,
#map-school-input:focus { border-color: var(--uc-blue); }

/* School autocomplete dropdown */
.school-dropdown {
  position: absolute; top: calc(100% + 3px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
  box-shadow: var(--shadow);
  max-height: 220px; overflow-y: auto;
  z-index: 400; list-style: none;
}
.school-dropdown.hidden { display: none; }
.school-dropdown li {
  padding: 7px 12px; cursor: pointer;
  border-bottom: 1px solid #f0f2f5;
  min-height: 44px;  /* touch-friendly */
  display: flex; flex-direction: column; justify-content: center;
}
.school-dropdown li:last-child { border-bottom: none; }
.school-dropdown li:hover, .school-dropdown li.active { background: #eff6ff; }
.dd-name { font-size: .85rem; font-weight: 600; }
.dd-loc  { font-size: .75rem; color: var(--text-muted); margin-top: 1px; }

/* ══════════════════════════════════ ROW 2: Full-width map ═══════════════════ */

.map-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.map-controls {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  position: relative;  /* create stacking context above the map */
  z-index: 2;
}

.map-school-picker {
  flex: 1 1 180px;
  display: flex; flex-direction: column; gap: 3px;
}

.map-legend-inline {
  display: flex; flex-direction: column; gap: 4px;
}
.map-legend {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: .78rem; color: var(--text-muted);
}
.dot {
  width: 11px; height: 11px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}
.dot.high { background: var(--admit-high); }
.dot.mid  { background: var(--admit-mid); }
.dot.low  { background: var(--admit-low); }
.dot.none { background: var(--admit-none); }

/* School type multi-select dropdown */
.type-dropdown { position: relative; }

.type-dropdown-panel {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 300;
  white-space: nowrap;
  min-width: 170px;
}
.type-dropdown-panel.hidden { display: none; }

.type-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  cursor: pointer;
  color: var(--text);
  user-select: none;
}
.type-check input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--uc-blue);
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.map-school-count {
  font-size: .78rem; color: var(--text-muted);
  align-self: flex-end; margin-left: auto; white-space: nowrap;
}

.map-container {
  flex: 1;
  min-height: 460px;
  position: relative;  /* explicit; Leaflet also sets this via JS */
  z-index: 0;          /* creates stacking context → contains all Leaflet pane z-indexes */
}

/* Leaflet tooltip override */
.leaflet-tooltip { background: none; border: none; box-shadow: none; padding: 0; }
.leaflet-tooltip::before { display: none; }
.map-tooltip {
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 13px; box-shadow: var(--shadow);
  font-family: inherit; font-size: .8rem; line-height: 1.6;
  pointer-events: none; min-width: 170px;
}
.tt-name  { font-weight: 700; color: var(--uc-blue); font-size: .85rem; }
.tt-loc   { color: var(--text-muted); font-size: .73rem; margin-bottom: 5px; }
.tt-row   { display: flex; justify-content: space-between; gap: 18px; }
.tt-label { color: var(--text-muted); }
.tt-value { font-weight: 700; }

/* ─── Footer ─── */
footer {
  text-align: center; padding: 10px 20px 20px;
  font-size: .72rem; color: var(--text-muted);
  max-width: 1600px; margin: 0 auto; width: 100%;
}
footer a { color: var(--uc-blue); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ════════════════════════════════════ MOBILE ════════════════════════════════ */

@media (max-width: 900px) {
  :root { --panel-h: auto; }   /* panels self-size on mobile */

  .charts-row {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    height: auto;
  }

  /* Give canvas a fixed height when panel is not stretched */
  .chart-canvas-wrap {
    height: 240px;
    position: relative;
    flex: none;
  }

  .map-container { min-height: 380px; }
}

@media (max-width: 600px) {
  header { padding: 10px 16px; }
  header h1 { font-size: 1rem; }
  .subtitle { display: none; }

  main { padding: 10px 12px 16px; gap: 10px; }

  .inline-filters { flex-direction: column; }
  .filter-group select { font-size: .85rem; }

  .map-controls { gap: 8px; }
  .map-container { min-height: 320px; }

  .chart-canvas-wrap { height: 200px; }

  .map-school-picker { flex-basis: 100%; }

  footer { padding: 8px 12px 16px; }
}
