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

:root {
  --blue-dark:   #003366;
  --blue-mid:    #005b9e;
  --blue-light:  #0081c9;
  --teal:        #009b9e;
  --accent:      #e8530a;
  --bg:          #f4f6f9;
  --sidebar-w:   340px;
  --header-h:    56px;
  --text:        #1a1a2e;
  --muted:       #6b7a99;
  --border:      #d8dce8;
  --panel-bg:    #ffffff;
  --radius:      8px;
  --shadow:      0 2px 12px rgba(0,0,0,.10);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.18);
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────── */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue-mid) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.header-brand { display: flex; align-items: center; gap: 12px; }

.header-logo {
  height: 36px;
  filter: brightness(0) invert(1);
  opacity: .9;
}

.header-title { display: flex; flex-direction: column; }
.header-main  { font-size: 16px; font-weight: 700; letter-spacing: .3px; }
.header-sub   { font-size: 11px; opacity: .75; font-weight: 300; }

.header-stats { display: flex; gap: 8px; }

.stat-pill {
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 500;
}
.stat-pill.filtered { background: rgba(232,83,10,.6); border-color: rgba(232,83,10,.8); }
.hidden { display: none !important; }

.btn-view-toggle {
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 20px;
  padding: 3px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .2px;
  transition: background .15s, border-color .15s;
}
.btn-view-toggle:hover { background: rgba(255,255,255,.30); }
.btn-view-toggle.active { background: rgba(255,255,255,.90); color: var(--blue-dark); }

/* ── App layout ──────────────────────────────────────────────── */
.app-container {
  display: flex;
  height: 100vh;
  padding-top: var(--header-h);
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar-inner { padding: 16px 14px 32px; }

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

.filter-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--blue-dark);
}

.btn-reset {
  font-size: 12px;
  color: var(--blue-light);
  background: none;
  border: 1px solid var(--blue-light);
  border-radius: 4px;
  padding: 3px 10px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.btn-reset:hover { background: var(--blue-light); color: #fff; }

/* Search */
.filter-group { margin-bottom: 12px; }

.filter-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 5px;
}

.search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--blue-light); }

/* Accordion sections */
.filter-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}

.filter-section-title {
  font-size: 13px;
  font-weight: 600;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  color: var(--blue-dark);
  list-style: none;
}
.filter-section-title::-webkit-details-marker { display: none; }
.filter-section-title::after {
  content: '▾';
  font-size: 11px;
  transition: transform .2s;
  margin-left: auto;
  margin-right: 0;
}
details[open] > .filter-section-title::after { transform: rotate(-180deg); }

.filter-count {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-right: 6px;
}

.filter-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
}

.select-all-btn + .select-all-btn {
  border-left: 1px solid var(--border);
  padding-left: 6px;
}

.select-all-btn {
  font-size: 10px;
  font-weight: 600;
  color: var(--blue-light);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.select-all-btn:hover { color: var(--blue-dark); }

.filter-body {
  padding: 10px 12px 12px;
  background: #fff;
}

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

/* Checkbox pills for IA */
.ia-pills { display: flex; flex-direction: column; gap: 5px; }

.ia-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  transition: background .12s;
  border: 1.5px solid transparent;
}
.ia-pill:hover { background: var(--bg); }
.ia-pill.active { border-color: currentColor; background: var(--bg); }

.ia-pill input[type="checkbox"] { display: none; }

.ia-label { flex: 1; line-height: 1.3; }

.ia-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border-radius: 10px;
  padding: 1px 6px;
  flex-shrink: 0;
}

/* Select filters */
.filter-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
  outline: none;
  padding: 4px;
}
.filter-select option { padding: 3px 6px; }

/* Model checkboxes */
.model-grid { display: flex; flex-direction: column; gap: 4px; }
.model-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
  padding: 3px 0;
}
.model-item input[type="checkbox"] {
  width: 14px; height: 14px; accent-color: var(--blue-mid); cursor: pointer;
}

/* Region checkboxes */
.region-list { display: flex; flex-direction: column; gap: 3px; max-height: 200px; overflow-y: auto; }
.region-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 0;
  line-height: 1.3;
}
.region-item input[type="checkbox"] { width: 13px; height: 13px; accent-color: var(--blue-mid); cursor: pointer; }

/* ── Map ─────────────────────────────────────────────────────── */
.map-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: #cdd8e3;
}

#globe-view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000918;
}

/* ── Detail panel ────────────────────────────────────────────── */
.detail-panel {
  position: absolute;
  top: 0; right: 0;
  width: 360px;
  height: 100%;
  background: var(--panel-bg);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  z-index: 500;
  transform: translateX(0);
  transition: transform .25s ease;
}
.detail-panel.hidden { transform: translateX(110%); }

.detail-close {
  position: sticky;
  top: 0;
  float: right;
  margin: 10px 10px 0 0;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 30px; height: 30px;
  font-size: 14px;
  cursor: pointer;
  z-index: 10;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.detail-close:hover { background: var(--bg); }

#detail-content { padding: 16px 18px 24px; }

.detail-ps-id {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .8px;
  margin-bottom: 2px;
}

.detail-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--blue-dark);
  line-height: 1.2;
  margin-bottom: 4px;
}

.detail-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-section {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.detail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 8px;
}

.detail-desc {
  font-size: 12px;
  line-height: 1.6;
  color: #444;
  max-height: 120px;
  overflow-y: auto;
}

.under-refinement {
  display: inline-block;
  font-size: 11px;
  font-style: italic;
  color: #8a6100;
  background: #fff4d6;
  border: 1px solid #f0c23a;
  border-radius: 10px;
  padding: 2px 8px;
}

/* A deliberate "we have none of this" answer, not a data gap — kept visually
   distinct (neutral, not amber) from .under-refinement. */
.no-capacity {
  display: inline-block;
  font-size: 11px;
  color: #666;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
}

.tag-cloud { display: flex; flex-wrap: wrap; gap: 5px; }

.tag {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  line-height: 1.4;
}
.tag.ia-tag { color: #fff; border-color: transparent; }

.model-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.model-table th {
  text-align: left;
  padding: 4px 6px;
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
  font-size: 10px;
  border-bottom: 1px solid var(--border);
}
.model-table td { padding: 4px 6px; border-bottom: 1px solid var(--bg); }
.model-table tr:last-child td { border-bottom: none; }

.timescale-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--blue-light);
  margin-right: 4px;
}

.coords {
  font-family: monospace;
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
}

/* ── Map legend ──────────────────────────────────────────────── */
.map-legend {
  position: absolute;
  bottom: 28px;
  right: 12px;
  background: rgba(255,255,255,.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  z-index: 400;
  box-shadow: var(--shadow);
  min-width: 210px;
  max-width: 260px;
  max-height: 480px;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  gap: 8px;
}

.legend-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--blue-dark);
  margin: 0 0 6px;
}

.legend-header span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
}

.legend-arrow {
  font-size: 11px;
  color: var(--muted);
  transition: transform .2s;
  line-height: 1;
}

.map-legend.collapsed .legend-arrow { transform: rotate(-90deg); }

#legend-items {
  overflow-y: auto;
  flex: 1;
  margin-top: 8px;
  transition: max-height .2s ease, opacity .2s ease;
  max-height: 400px;
  opacity: 1;
}

.map-legend.collapsed #legend-items {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-top: 0;
}

#legend-items::-webkit-scrollbar { width: 4px; }
#legend-items::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.legend-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 11px;
  margin-bottom: 4px;
  color: var(--text);
  line-height: 1.3;
}

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  border: 1.5px solid rgba(0,0,0,.15);
}

/* Mirrors the real marker style (white border), plus a thin dark ring so the
   white border stays visible against the legend panel's own white background. */
.legend-swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--blue-mid);
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.3);
  vertical-align: middle;
  margin-bottom: 2px;
}

/* Leaflet cluster override */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { border-radius: 50% !important; }

/* Scrollbar styling */
.sidebar::-webkit-scrollbar,
.detail-panel::-webkit-scrollbar,
.region-list::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-track,
.detail-panel::-webkit-scrollbar-track,
.region-list::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb,
.detail-panel::-webkit-scrollbar-thumb,
.region-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 100vw; }
  .app-container { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: 220px; border-right: none; border-bottom: 1px solid var(--border); }
  .detail-panel { width: 100%; top: auto; bottom: 0; height: 60vh; transform: translateY(0); }
  .detail-panel.hidden { transform: translateY(110%); }
  .map-legend { display: none; }
}

/* ── View switcher (4 projection options) ─────────────────── */
.view-switcher {
  display: flex;
  gap: 3px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 22px;
  padding: 2px;
}
.btn-view {
  background: transparent;
  border: none;
  border-radius: 18px;
  padding: 3px 11px;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .2px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.btn-view:hover  { background: rgba(255,255,255,.22); color: #fff; }
.btn-view.active { background: rgba(255,255,255,.92); color: var(--blue-dark); }

/* ── Globe rotation button ─────────────────────────────────── */
.btn-globe-rotate {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 500;
  background: rgba(0, 0, 0, 0.52);
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: .2px;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-globe-rotate:hover { background: rgba(0,0,0,.72); }

/* ── D3 projection view ────────────────────────────────────── */
#d3-view {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
  background: #d0e8f5;
}
#d3-view svg { display: block; }

/* ── D3 hover tooltip ──────────────────────────────────────── */
#d3-tooltip {
  position: fixed;
  background: rgba(0,0,0,.72);
  color: #fff;
  padding: 4px 9px;
  border-radius: 4px;
  font-size: 12px;
  font-family: Inter, sans-serif;
  pointer-events: none;
  display: none;
  z-index: 9000;
  white-space: nowrap;
}

/* ── Under Review status badge ─────────────────────────────── */
.status-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .4px;
  vertical-align: middle;
  text-transform: uppercase;
}
.status-badge.under-review {
  background: #fff4d6;
  color: #8a6100;
  border: 1px solid #f0c23a;
}

/* ── Other contributing partners ───────────────────────────── */
.contrib-item {
  font-size: 12.5px;
  color: var(--text, #333);
  padding: 3px 0;
  line-height: 1.35;
  border-bottom: 1px dashed #eee;
}
.contrib-item:last-child { border-bottom: none; }
.contrib-country { color: var(--muted); }

/* ── Legend under-review note ──────────────────────────────── */
.legend-note {
  font-size: 11px;
  color: var(--muted);
  padding: 6px 2px 8px;
  border-bottom: 1px solid #eee;
  margin-bottom: 6px;
}

.legend-note.legend-note-plain {
  border-bottom: none;
  padding-bottom: 2px;
  margin-bottom: 0;
}
