:root {
  --bg: #09090b;
  --panel: rgba(12, 12, 15, 0.88);
  --line: rgba(255, 255, 255, 0.08);
  --txt: #f8fafc;
  --txt-soft: #cbd5e1;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-soft: #60a5fa;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  --cyan: #22d3ee;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --view-accent: #4f8cff;
  --view-accent-strong: #2563eb;
  --view-soft: rgba(79, 140, 255, 0.18);
  --view-glow: rgba(79, 140, 255, 0.28);
}

body[data-view='score'] { --view-accent: #4f8cff; --view-accent-strong: #2563eb; --view-soft: rgba(79, 140, 255, 0.18); --view-glow: rgba(79, 140, 255, 0.28); }
body[data-view='economy'] { --view-accent: #14b8a6; --view-accent-strong: #0f766e; --view-soft: rgba(20, 184, 166, 0.18); --view-glow: rgba(20, 184, 166, 0.28); }
body[data-view='mobility'] { --view-accent: #06b6d4; --view-accent-strong: #0e7490; --view-soft: rgba(6, 182, 212, 0.18); --view-glow: rgba(6, 182, 212, 0.28); }
body[data-view='talent'] { --view-accent: #f59e0b; --view-accent-strong: #d97706; --view-soft: rgba(245, 158, 11, 0.18); --view-glow: rgba(245, 158, 11, 0.28); }
body[data-view='resilience'] { --view-accent: #22c55e; --view-accent-strong: #15803d; --view-soft: rgba(34, 197, 94, 0.18); --view-glow: rgba(34, 197, 94, 0.28); }
body[data-view='risk'] { --view-accent: #f43f5e; --view-accent-strong: #be123c; --view-soft: rgba(244, 63, 94, 0.18); --view-glow: rgba(244, 63, 94, 0.28); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--txt); font-family: var(--font); overflow: hidden; }
body { display: flex; flex-direction: column; }
button, input, select { font: inherit; }

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  color: #0f172a;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.25);
  flex: 0 0 auto;
}

.title-wrap h1 { margin: 0; font-size: 15px; font-weight: 850; letter-spacing: -0.03em; }
.title-wrap small { display: block; margin-top: 2px; color: #64748b; font-size: 10px; font-weight: 600; }

.search { position: relative; flex: 1; max-width: 320px; }
.search input {
  width: 100%;
  min-height: 38px;
  padding: 0 12px 0 34px;
  border: 1.5px solid #dbeafe;
  border-radius: 10px;
  background: #f8fafc;
  color: #0f172a;
  outline: none;
}
.search input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1); }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: #64748b; font-size: 13px; }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: none;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(226, 232, 240, 0.12);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  z-index: 30;
}
.search-results.show { display: block; }
.search-item { padding: 10px 12px; color: var(--txt-soft); font-size: 12px; cursor: pointer; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.search-item:hover { background: rgba(59, 130, 246, 0.12); color: #fff; }

.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.toolbar-select, .toolbar-btn, .intel-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid #dbeafe;
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
}
.toolbar-btn.is-active { color: #fff; background: var(--view-accent); border-color: var(--view-accent); }
.mobile-themes { display: none; }
.mobile-theme-btn {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.06);
  color: var(--txt-soft);
  cursor: pointer;
}
.mobile-theme-btn.is-active {
  background: var(--view-accent);
  border-color: var(--view-accent);
  box-shadow: 0 10px 24px var(--view-glow);
  color: #fff;
}

.main { display: flex; flex: 1; min-height: 0; }
.map-shell { position: relative; flex: 1; min-width: 0; height: 100%; }
#map { width: 100%; height: 100%; }

.loading {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(2, 6, 23, 0.58);
  backdrop-filter: blur(6px);
}
.loading.hidden { display: none; }
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent-soft);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading-text { color: var(--txt-soft); font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

.layers, .stats, .map-legend {
  position: absolute;
  z-index: 20;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.layers { top: 12px; left: 12px; width: 200px; padding: 10px 12px; border-radius: 14px; }
.layers h3, .map-legend h3, .section-title {
  margin: 0 0 8px;
  color: var(--view-accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.layer-row { display: flex; align-items: center; gap: 8px; min-height: 30px; color: var(--txt-soft); font-size: 12px; }
.layer-row input { accent-color: var(--accent); }
.layer-dot { width: 10px; height: 10px; border-radius: 999px; }
.layer-dot--regions { background: var(--accent); }
.layer-dot--labels { background: var(--cyan); }
.layer-dot--capitals { background: var(--amber); }
.layer-dot--connections { background: var(--purple); }
.layer-count { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 10px; }

.stats { left: 12px; bottom: 12px; display: flex; gap: 10px; padding: 10px 12px; border-radius: 14px; }
.stat { min-width: 72px; text-align: center; }
.stat b { display: block; color: #fff; font-family: var(--mono); font-size: 12px; font-weight: 800; }
.stat small { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; }

.map-legend { right: 12px; bottom: 12px; width: 240px; padding: 10px 12px; border-radius: 14px; }
.legend-scale { display: flex; align-items: center; gap: 8px; color: var(--txt-soft); font-size: 11px; }
.legend-bar { flex: 1; height: 8px; border-radius: 999px; background: linear-gradient(90deg, #ef4444, #f59e0b, #22c55e); }
.legend-note { margin-top: 8px; color: var(--muted); font-size: 10px; }

.intel {
  width: 420px;
  height: 100%;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(12, 12, 15, 0.98), rgba(15, 23, 42, 0.96));
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(18px);
}
.intel-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.intel-kicker { color: var(--accent-soft); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.intel-head h2 { margin: 6px 0 0; font-size: 20px; line-height: 1.05; letter-spacing: -0.03em; }
.intel-actions { display: flex; gap: 6px; }
.intel-btn { background: rgba(255, 255, 255, 0.04); border-color: var(--line); color: var(--txt-soft); }
#sheetToggleBtn { display: none; }
.intel-compact {
  display: none;
  margin-top: 6px;
  color: color-mix(in srgb, var(--view-accent) 76%, white 24%);
  font-size: 12px;
  font-weight: 700;
}

.intel-hero {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(circle at top left, var(--view-soft), transparent 42%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
}
.hero-main { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px; align-items: center; }
.hero-score {
  padding: 14px 12px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--view-accent) 24%, #07111f 76%), rgba(2, 6, 23, 0.84));
  border: 1px solid color-mix(in srgb, var(--view-accent) 34%, white 12%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 16px 30px rgba(0, 0, 0, 0.18);
}
.hero-label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
.hero-value { margin-top: 8px; font-size: 34px; font-family: var(--mono); font-weight: 800; }
.hero-price { font-size: 22px; font-weight: 900; color: color-mix(in srgb, var(--view-accent) 78%, white 22%); font-family: var(--mono); letter-spacing: -0.04em; }
.hero-sub { margin-top: 6px; color: var(--txt-soft); font-size: 12px; line-height: 1.4; }
.hero-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.hero-card {
  padding: 10px 8px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--view-accent) 8%, rgba(255,255,255,0.04) 92%), rgba(255, 255, 255, 0.03));
  border: 1px solid color-mix(in srgb, var(--view-accent) 18%, rgba(255,255,255,0.08) 82%);
  border-radius: 12px;
  text-align: center;
}
.hero-card b { display: block; font-size: 16px; font-weight: 900; font-family: var(--mono); }
.hero-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; }

.intel-content { flex: 1; overflow: auto; padding: 16px; }
.empty-state { padding: 20px; border: 1px dashed rgba(255, 255, 255, 0.12); border-radius: 14px; color: var(--txt-soft); line-height: 1.55; }
.intel-section { margin-bottom: 18px; }
.score-list { display: grid; gap: 8px; }
.score-row { display: grid; grid-template-columns: 90px minmax(0, 1fr) 42px; gap: 8px; align-items: center; }
.score-row span { color: var(--txt-soft); font-size: 12px; }
.score-track { height: 10px; background: rgba(255, 255, 255, 0.06); border-radius: 999px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 999px; }
.score-value { color: #fff; font-family: var(--mono); font-size: 11px; font-weight: 700; text-align: right; }

.grid-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-card {
  padding: 12px;
  border-radius: 12px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--view-accent) 8%, rgba(255,255,255,0.04) 92%), rgba(255, 255, 255, 0.03));
  border: 1px solid color-mix(in srgb, var(--view-accent) 14%, rgba(255,255,255,0.08) 86%);
}
.grid-card b { display: block; color: #fff; font-family: var(--mono); font-size: 18px; }
.grid-card small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }

.risk-row, .fact-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.risk-row:last-child, .fact-row:last-child { border-bottom: 0; }
.risk-row span, .fact-row span { color: var(--txt-soft); font-size: 12px; }
.risk-row b, .fact-row b { font-size: 12px; font-weight: 800; font-family: var(--mono); }

.pill-list { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { padding: 6px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.08); color: var(--txt-soft); font-size: 11px; }

.region-label {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(9, 9, 11, 0.74);
  border: 1px solid color-mix(in srgb, var(--view-accent) 30%, rgba(255,255,255,0.12) 70%);
  color: color-mix(in srgb, var(--view-accent) 42%, white 58%);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}
.capital-dot { width: 14px; height: 14px; border-radius: 50%; background: #f59e0b; border: 2px solid rgba(255, 255, 255, 0.8); box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.16); }

.mapboxgl-popup-content {
  background: rgba(15, 23, 42, 0.96);
  color: #fff;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.34);
}
.mapboxgl-popup-close-button { color: #cbd5e1; }

@media (max-width: 980px) {
  .main { display: block; }
  .intel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 56vh;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .layers, .map-legend { max-width: calc(100vw - 24px); }
  .stats {
    left: 12px;
    bottom: calc(56vh + 12px);
    width: min(260px, calc(100vw - 24px));
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .map-legend {
    right: 12px;
    bottom: calc(56vh + 12px);
    width: min(220px, calc(100vw - 24px));
  }
}

@media (max-width: 760px) {
  .top {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    z-index: 40;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) auto;
    grid-template-areas:
      'logo search toolbar'
      'themes themes themes';
    gap: 6px;
    padding: 8px;
    border-radius: 16px;
    background: rgba(7, 12, 24, 0.82);
    border: 1px solid color-mix(in srgb, var(--view-accent) 16%, rgba(255,255,255,0.08) 84%);
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.36);
    backdrop-filter: blur(18px);
    color: #f8fafc;
  }
  .logo {
    grid-area: logo;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    font-size: 10px;
  }
  .title-wrap {
    display: none;
  }
  .search {
    grid-area: search;
    order: initial;
    max-width: none;
    width: 100%;
  }
  .search input {
    min-height: 34px;
    padding: 0 10px 0 30px;
    border-radius: 999px;
    border-color: rgba(148, 163, 184, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 13px;
  }
  .search input::placeholder {
    color: #cbd5e1;
  }
  .search input:focus {
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.16);
  }
  .search-icon {
    left: 10px;
    color: #cbd5e1;
  }
  .toolbar {
    grid-area: toolbar;
    width: auto;
    flex-wrap: nowrap;
    overflow: visible;
    padding-bottom: 0;
  }
  .mobile-themes {
    grid-area: themes;
    display: flex;
    gap: 5px;
    overflow-x: auto;
    padding-bottom: 1px;
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  .mobile-themes::-webkit-scrollbar {
    display: none;
  }
  .toolbar::-webkit-scrollbar {
    display: none;
  }
  .toolbar-btn, .toolbar-select, .mobile-theme-btn {
    flex: 0 0 auto;
    min-width: max-content;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    font-size: 12px;
  }
  #styleSelect,
  #resetViewBtn,
  #themeSelect {
    display: none;
  }
  .toolbar-btn.is-active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
  }
  .toolbar-btn[data-level='regions'],
  .toolbar-btn[data-level='districts'] {
    min-width: 0;
    padding: 0 9px;
  }
  .layers,
  .stats,
  .map-legend {
    display: none;
  }
  .intel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(50vh, 390px);
    border: 1px solid color-mix(in srgb, var(--view-accent) 18%, rgba(255,255,255,0.08) 82%);
    border-radius: 22px 22px 18px 18px;
    overflow: hidden;
    background:
      radial-gradient(circle at top right, var(--view-soft), transparent 36%),
      linear-gradient(180deg, rgba(10, 14, 26, 0.96), rgba(13, 18, 31, 0.94));
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.42);
  }
  .intel::before {
    content: '';
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.24);
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
  }
  .intel-head {
    padding: 16px 12px 8px;
    gap: 6px;
  }
  .intel-compact {
    display: block;
    margin-top: 4px;
    font-size: 11px;
  }
  .intel-head h2 {
    font-size: 16px;
  }
  .intel-actions {
    gap: 4px;
  }
  #shareBtn,
  #focusBtn {
    display: none;
  }
  #sheetToggleBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .intel-btn {
    min-height: 28px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 10px;
  }
  .intel-hero {
    padding: 10px 12px;
  }
  .hero-main {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
  }
  .hero-score {
    padding: 8px;
    border-radius: 10px;
  }
  .hero-label {
    font-size: 9px;
  }
  .hero-value {
    margin-top: 4px;
    font-size: 23px;
  }
  .hero-price {
    font-size: 14px;
  }
  .hero-sub {
    display: none;
  }
  .hero-cards {
    display: none;
  }
  .intel-content {
    padding: 10px 12px 14px;
  }
  .intel.is-collapsed {
    max-height: 88px;
  }
  .intel.is-collapsed .intel-hero,
  .intel.is-collapsed .intel-content {
    display: none;
  }
  .intel.is-collapsed .intel-head {
    padding-bottom: 14px;
    border-bottom: 0;
  }
  .grid-cards {
    display: none;
  }
  .intel-section:nth-of-type(2) {
    display: none;
  }
  .intel-section:nth-of-type(3) {
    margin-bottom: 10px;
  }
  .pill-list {
    gap: 6px;
  }
  .pill {
    padding: 5px 8px;
    font-size: 10px;
  }
  .score-row {
    grid-template-columns: 64px minmax(0, 1fr) 30px;
    gap: 5px;
  }
  .score-row span,
  .risk-row span,
  .fact-row span,
  .risk-row b,
  .fact-row b {
    font-size: 10px;
  }
  .score-track {
    height: 8px;
  }
  .section-title {
    font-size: 10px;
    margin-bottom: 6px;
  }
  .region-label {
    padding: 5px 9px;
    font-size: 10px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .capital-dot {
    width: 10px;
    height: 10px;
    border-width: 1.5px;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.14);
  }
}
