:root {
  --bg: #0b1220;
  --surface: #0f1a2e;
  --surface-2: #152544;
  --border: #203257;
  --text: #e6edf7;
  --text-dim: #9fb0cc;
  --accent: #5aa0ff;
  --accent-2: #7bd3a7;
  --danger: #ff6b6b;
  --warning: #f0b429;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(ellipse at top left, #132041 0%, #0b1220 55%, #070d1a 100%);
  color: var(--text);
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }

/* ===== HEADER ===== */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  background: rgba(11,18,32,0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1600px; margin: 0 auto;
  padding: 16px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 18px; }
.brand-mark {
  width: 76px; height: 76px; flex: 0 0 76px;
  border-radius: 18px;
  background: linear-gradient(135deg, #1e3a8a 0%, #5aa0ff 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; letter-spacing: 0.04em;
  color: white; text-align: center; line-height: 1.2;
  box-shadow: 0 8px 24px rgba(90,160,255,0.25);
}
.brand-title h1 { font-size: 22px; }
.brand-title p { margin: 4px 0 0; color: var(--text-dim); font-size: 13px; }

.tabs { display: flex; gap: 8px; background: var(--surface); padding: 6px; border-radius: 12px; border: 1px solid var(--border); }
.tab {
  background: transparent; border: none; color: var(--text-dim);
  padding: 8px 16px; border-radius: 8px; font-weight: 500; font-size: 13px;
  cursor: pointer; transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: white; font-weight: 600; }

/* ===== KPI ROW ===== */
.kpi-row {
  max-width: 1600px; margin: 0 auto;
  padding: 20px 28px 12px;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}
.kpi-value { font-size: 26px; font-weight: 700; color: var(--text); }
.kpi-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-accent {
  background: linear-gradient(135deg, rgba(90,160,255,0.18), rgba(123,211,167,0.12));
  border-color: rgba(90,160,255,0.4);
}
.kpi-accent .kpi-value { font-size: 20px; }

/* ===== VIEW TOGGLE ===== */
.view { display: none; max-width: 1600px; margin: 0 auto; padding: 12px 28px 24px; }
.view.active { display: block; }

#view-map.active {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 18px;
  height: calc(100vh - 220px);
  min-height: 600px;
}

/* ===== SIDEBAR ===== */
.sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex; flex-direction: column;
  overflow: hidden;
}

.filters { padding: 18px; border-bottom: 1px solid var(--border); }
.filter-block { margin-bottom: 14px; }
.filter-block:last-child { margin-bottom: 0; }
.filter-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.filter-head h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.mini-btn {
  background: transparent; border: none; color: var(--accent);
  font-size: 11px; cursor: pointer; padding: 2px 6px;
}
.mini-btn:hover { text-decoration: underline; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 10px; border-radius: 999px;
  font-size: 12px; cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active {
  background: var(--accent); border-color: var(--accent); color: white; font-weight: 500;
}
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.detail-card {
  padding: 18px; flex: 1; overflow-y: auto;
}
.empty-detail {
  text-align: center; padding: 40px 12px; color: var(--text-dim);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-detail p { font-size: 13px; line-height: 1.5; margin: 0; }

.detail h2 { font-size: 17px; margin-bottom: 6px; line-height: 1.25; }
.detail-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 13px; color: var(--text-dim); }
.flag-lg { font-size: 18px; }
.detail-status {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: white;
}
.detail-desc { font-size: 13.5px; line-height: 1.6; color: var(--text); margin: 10px 0 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-bottom: 14px; }
.detail-grid div { font-size: 12px; }
.detail-grid .lbl { color: var(--text-dim); text-transform: uppercase; font-size: 10px; letter-spacing: 0.08em; margin-bottom: 2px; }
.detail-grid .val { color: var(--text); font-weight: 500; line-height: 1.4; }

.detail-partners { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.partner-tag { background: var(--surface-2); border: 1px solid var(--border); padding: 3px 10px; border-radius: 999px; font-size: 11px; color: var(--text-dim); }

.src-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: white;
  padding: 9px 14px; border-radius: 10px;
  text-decoration: none; font-size: 13px; font-weight: 500;
  transition: all 0.15s;
}
.src-btn:hover { background: #4a8fee; transform: translateY(-1px); }

/* ===== MAP ===== */
.map-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}
#map { width: 100%; height: 100%; background: #0b1220; }

/* Leaflet dark overrides */
.leaflet-container { background: #0b1220; font-family: 'Inter', sans-serif; }
.leaflet-control-attribution { display: none !important;
  background: rgba(15,26,46,0.85) !important; color: var(--text-dim) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-control-zoom a {
  background: var(--surface) !important; color: var(--text) !important;
  border: 1px solid var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-2) !important; }

.project-popup .leaflet-popup-content-wrapper {
  background: var(--surface); color: var(--text);
  border-radius: 10px; border: 1px solid var(--border);
}
.project-popup .leaflet-popup-tip { background: var(--surface); }
.project-popup .leaflet-popup-content { margin: 12px 14px; font-size: 13px; }
.project-popup .leaflet-popup-content strong { color: var(--text); }

/* Legend */
.legend {
  position: absolute; bottom: 14px; left: 14px;
  background: rgba(15,26,46,0.95);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  max-width: 260px;
  font-size: 11px;
  backdrop-filter: blur(8px);
  z-index: 500;
}
.legend-title { font-weight: 700; margin-bottom: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.legend-group { margin-bottom: 10px; }
.legend-group:last-child { margin-bottom: 0; }
.legend-group strong { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 4px; }
.legend-item { display: flex; align-items: center; gap: 6px; margin: 3px 0; font-size: 11.5px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.legend-line { width: 18px; height: 3px; border-radius: 2px; flex-shrink: 0; }

/* Marker custom */
.custom-marker {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  display: block;
}

/* ===== GOVERNANCE VIEW ===== */
.gov-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.gov-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  display: flex; flex-direction: column;
  gap: 14px;
}
.gov-accent {
  background: linear-gradient(135deg, rgba(90,160,255,0.12), rgba(123,211,167,0.08));
  border-color: rgba(90,160,255,0.35);
  grid-column: span 2;
}
.gov-badge {
  display: inline-block;
  background: rgba(90,160,255,0.18);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.gov-header h2 { font-size: 20px; margin-bottom: 6px; }
.gov-motto { color: var(--text-dim); font-size: 14px; font-style: italic; margin: 0; }
.gov-list {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 18px;
}
.gov-list li {
  position: relative; padding-left: 20px; font-size: 13.5px; line-height: 1.5; color: var(--text);
}
.gov-list li::before {
  content: '▸'; position: absolute; left: 0; color: var(--accent); font-weight: 700;
}
.gov-dl { margin: 0; display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; }
.gov-dl dt { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; padding-top: 2px; }
.gov-dl dd { margin: 0; font-size: 13.5px; line-height: 1.5; }
.gov-card p { margin: 0; font-size: 13.5px; line-height: 1.6; color: var(--text); }
.gov-meta { color: var(--text-dim) !important; font-size: 12.5px !important; }
.gov-src {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 500;
  margin-top: auto;
  padding-top: 4px;
}
.gov-src::after { content: '→'; transition: transform 0.15s; }
.gov-src:hover::after { transform: translateX(3px); }

/* ===== TABLE ===== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow-x: auto;
}
#projects-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
#projects-table th, #projects-table td {
  padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border);
}
#projects-table th {
  color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--surface-2); font-weight: 600;
  position: sticky; top: 0;
}
#projects-table td { color: var(--text); vertical-align: top; line-height: 1.4; }
#projects-table tr:hover td { background: rgba(90,160,255,0.06); }
#projects-table .status-pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  color: white;
}
#projects-table a { color: var(--accent); text-decoration: none; }
#projects-table a:hover { text-decoration: underline; }

/* ===== FOOTER ===== */
.footer {
  max-width: 1600px; margin: 0 auto;
  padding: 16px 28px 28px;
  color: var(--text-dim); font-size: 11.5px;
  display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  #view-map.active { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 500px; }
  .gov-grid { grid-template-columns: 1fr; }
  .gov-accent { grid-column: span 1; }
  .gov-list { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .topbar-inner { flex-direction: column; align-items: stretch; gap: 14px; }
  .tabs { justify-content: center; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .view { padding: 12px 16px 24px; }
  .brand-title h1 { font-size: 18px; }
  .gov-dl { grid-template-columns: 1fr; gap: 2px 0; }
  .gov-dl dt { margin-top: 8px; }
}
