:root {
  --navy: #0d2b4e;
  --teal: #0a7c8c;
  --teal-light: #12a8bc;
  --green: #1a9e6f;
  --yellow: #e8a020;
  --red: #c8352a;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --border: #d9e3ef;
  --text: #1a2535;
  --text-muted: #5a6a80;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(13, 43, 78, 0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@keyframes spin { to { transform: rotate(360deg); } }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ── Header ── */
header {
  background: linear-gradient(135deg, var(--navy) 0%, #164a7c 100%);
  color: white;
  padding: 40px 24px 32px;
  text-align: center;
}

header h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

header p {
  font-size: 1rem;
  opacity: 0.82;
  max-width: 600px;
  margin: 0 auto;
}

/* ── Navigation tabs ── */
nav {
  background: var(--navy);
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 0 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

nav button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.65);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

nav button:hover { color: white; }
nav button.active { color: white; border-bottom-color: var(--teal-light); }

/* ── Main layout ── */
main {
  max-width: 1200px;
  margin: 32px auto;
  padding: 0 16px;
}

.section { display: none; }
.section.visible { display: block; }

/* ── Controls ── */
.controls {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}

.control-group { display: flex; flex-direction: column; gap: 5px; }
.control-group label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.controls input,
.controls select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  min-width: 180px;
  transition: border-color 0.2s;
}

.controls input:focus,
.controls select:focus {
  outline: none;
  border-color: var(--teal);
}

/* ── Table ── */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  background: var(--navy);
  color: white;
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
}

thead th:hover { background: #1b3f6b; }
thead th.sorted { background: var(--teal); }

thead th .sort-icon {
  display: inline-block;
  margin-left: 5px;
  opacity: 0.5;
  font-size: 0.7rem;
}
thead th.sorted .sort-icon { opacity: 1; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

tbody tr:hover { background: #f0f5fb; }

td {
  padding: 13px 16px;
  vertical-align: middle;
}

.rank-cell {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.9rem;
  min-width: 48px;
}

.rank-medal { font-size: 1.1rem; }

.provider-name { font-weight: 600; color: var(--navy); }
.provider-creds { font-size: 0.78rem; color: var(--text-muted); }
.provider-institution { font-size: 0.8rem; color: var(--text-muted); }

.score-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.88rem;
}

.score-excellent { background: #d4f5e9; color: #0d6b47; }
.score-good      { background: #d8f0f5; color: #0a5c6b; }
.score-fair      { background: #fef3d8; color: #8a5e10; }
.score-poor      { background: #fde8e6; color: #8b1f18; }
.score-unranked  { background: #eef1f6; color: #5a6a80; font-weight: 500; }

.metric-value { font-weight: 600; }
.metric-good     { color: var(--green); }
.metric-ok       { color: var(--yellow); }
.metric-poor     { color: var(--red); }
.metric-unknown  { color: #8a9ab0; }

.not-reported    { color: #aab5c5; font-weight: 400; }
.row-unranked td { opacity: 0.72; }
.popup-unranked-note { font-size: 0.82rem; color: #8a9ab0; margin-top: 8px; line-height: 1.5; }
.page-ellipsis   { padding: 4px 6px; color: var(--text-muted); }

.specialty-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  background: #e8eef6;
  color: var(--navy);
}

/* ── Summary stats ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  border-top: 4px solid var(--teal);
}

.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--navy); line-height: 1; }
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 5px; }

/* ── Metrics education section ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.metric-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
  border-left: 5px solid var(--teal);
}

.metric-card.card-adr   { border-left-color: #1a9e6f; }
.metric-card.card-wt    { border-left-color: #0a7c8c; }
.metric-card.card-vol   { border-left-color: #5a3fc0; }
.metric-card.card-cir   { border-left-color: #c8352a; }

.metric-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
}

.metric-card .metric-abbr {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-muted);
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}

.metric-card p { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 14px; line-height: 1.65; }

.benchmark-box {
  background: var(--bg);
  border-radius: 7px;
  padding: 12px 14px;
}

.benchmark-box .benchmark-title {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.benchmark-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.benchmark-row .bm-label { color: var(--text-muted); }
.benchmark-row .bm-val   { font-weight: 600; }
.bm-good { color: var(--green); }
.bm-ok   { color: var(--yellow); }
.bm-min  { color: var(--red); }

/* ── Who can perform section ── */
.providers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-top: 0;
}

.provider-type-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}

.provider-type-card h3 { font-size: 0.97rem; font-weight: 700; color: var(--navy); margin-bottom: 8px; }
.provider-type-card p  { font-size: 0.85rem; color: var(--text-muted); line-height: 1.6; }

.section-intro {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
  margin-bottom: 24px;
  font-size: 0.93rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.section-intro strong { color: var(--text); }

.section h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 18px;
}

/* ── Scoring explainer ── */
.score-explainer {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
  margin-bottom: 24px;
}

.score-explainer h3 { font-size: 1rem; font-weight: 700; color: var(--navy); margin-bottom: 14px; }

.weight-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 0.88rem;
}

.weight-bar-wrap { flex: 1; background: var(--bg); border-radius: 4px; height: 8px; }
.weight-bar { height: 8px; border-radius: 4px; background: var(--teal); }
.weight-label { min-width: 180px; color: var(--text-muted); }
.weight-pct { min-width: 36px; font-weight: 700; color: var(--navy); text-align: right; }

.disclaimer {
  margin-top: 20px;
  padding: 14px 18px;
  background: #fff8e1;
  border-left: 4px solid var(--yellow);
  border-radius: 6px;
  font-size: 0.82rem;
  color: #6b4e10;
  line-height: 1.6;
}

/* ── Pagination ── */
.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pagination { display: flex; gap: 6px; }

.pagination button {
  padding: 5px 11px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}

.pagination button:hover { background: var(--bg); border-color: var(--teal); }
.pagination button.active { background: var(--teal); color: white; border-color: var(--teal); }
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ── Map ── */
.map-toolbar {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 20px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.locate-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  background: var(--teal);
  color: white;
  border: none;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.locate-btn:hover { background: var(--teal-light); }
.locate-btn.locating { background: var(--yellow); color: #4a2e00; }
.locate-btn.located  { background: var(--green); }

.map-radius-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.map-radius-wrap select {
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.map-radius-wrap select:focus { outline: none; border-color: var(--teal); }

.map-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
  flex-wrap: wrap;
}
.legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.2);
}
.dot-excellent { background: #1a9e6f; }
.dot-good      { background: #0a7c8c; }
.dot-fair      { background: #e8a020; }
.dot-poor      { background: #c8352a; }

.map-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  height: 600px;
}

#map-container {
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  z-index: 0;
}

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

.map-sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--navy);
  flex-shrink: 0;
}

.map-count-badge {
  background: var(--teal);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
}

#map-sidebar-list {
  overflow-y: auto;
  flex: 1;
}

.map-provider-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.map-provider-item:hover { background: #f0f5fb; }
.map-provider-item.highlighted { background: #e8f4f8; }

.map-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 3px;
}

.map-item-name {
  font-weight: 600;
  font-size: 0.87rem;
  color: var(--navy);
  line-height: 1.3;
}

.map-item-location {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

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

.map-metric-chip {
  font-size: 0.73rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 500;
}
.map-metric-chip strong { color: var(--navy); }

/* Custom marker styles */
.score-marker {
  width: 32px;
  height: 32px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}
.score-marker-inner {
  transform: rotate(45deg);
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  line-height: 1;
}

.user-location-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #2563eb;
  border: 3px solid white;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.35);
}

/* Popup override */
.leaflet-popup-content-wrapper {
  border-radius: 10px !important;
  box-shadow: 0 4px 20px rgba(13,43,78,0.15) !important;
  padding: 0 !important;
}
.leaflet-popup-content {
  margin: 0 !important;
  width: 260px !important;
}
.popup-inner {
  padding: 14px 16px;
}
.popup-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--navy);
  margin-bottom: 2px;
}
.popup-creds {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.popup-institution {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.popup-score-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.popup-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg);
  border-radius: 7px;
  padding: 10px;
}
.popup-metric { font-size: 0.78rem; color: var(--text-muted); }
.popup-metric strong { display: block; font-size: 0.88rem; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .map-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  #map-container { height: 400px; }
  .map-sidebar { max-height: 300px; }
}

@media (max-width: 640px) {
  .controls { flex-direction: column; }
  .controls input, .controls select { min-width: 0; width: 100%; }
  td, th { padding: 10px 12px; }
  .map-legend { margin-left: 0; }
}
