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

:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface2:   #1c2128;
  --border:     #30363d;
  --text:       #e6edf3;
  --text-muted: #8b949e;
  --green:      #14f195;
  --purple:     #9945ff;
  --red:        #ff6b6b;
  --accent:     #9945ff;
}

html, body { height: 100%; overflow: hidden; }

body {
  display: flex;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  font-size: 14px;
}

/* ── Sidebar ──────────────────────────────────────────── */
#sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Header */
#header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
#logo { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
#logo svg { width: 24px; height: 24px; flex-shrink: 0; }
#logo h1 { font-size: 15px; font-weight: 600; color: var(--text); line-height: 1.2; }
#last-updated { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Stats grid */
#stats-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.stat-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500; }
.stat-value { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card.green .stat-value  { color: var(--green); }
.stat-card.purple .stat-value { color: var(--purple); }
.stat-card.red .stat-value    { color: var(--red); }

/* Filter buttons */
#filters {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.filter-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-bottom: 8px;
}
.filter-buttons { display: flex; gap: 6px; }
.filter-btn {
  flex: 1;
  padding: 6px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Stake Pool section ───────────────────────────────── */
#stakepool-panel {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
#stakepool-panel .section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.loading-badge {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.loading-badge.hidden { display: none; }

#stakepool-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pool-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.pool-btn:hover { color: var(--text); }
.pool-btn.active {
  color: #fff;
  border-color: var(--pool-color, var(--accent));
  background: color-mix(in srgb, var(--pool-color, var(--accent)) 25%, var(--surface2));
  box-shadow: 0 0 8px color-mix(in srgb, var(--pool-color, var(--accent)) 40%, transparent);
}
.pool-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

#stakepool-legend {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.pool-legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-choropleth-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.2);
}

/* "All pools" button - special gradient */
.pool-btn[data-pool="all"].active {
  background: linear-gradient(135deg, rgba(232,65,66,.25) 0%, rgba(255,119,0,.25) 50%, rgba(77,157,224,.25) 100%);
  border-color: rgba(255,255,255,.3);
  color: #fff;
  box-shadow: none;
}

/* ── Legend ────────────────────────────────────────────── */
#legend { padding: 12px; border-bottom: 1px solid var(--border); }
.section-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-bottom: 8px;
}
.legend-items { display: flex; flex-direction: column; gap: 6px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Countries + Versions ──────────────────────────────── */
#countries-panel, #versions-panel {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.bar-label { font-size: 12px; color: var(--text); width: 36px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.bar-track { flex: 1; height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.4s; }
.bar-count { font-size: 11px; color: var(--text-muted); width: 32px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* ── Map ──────────────────────────────────────────────── */
#map { flex: 1; height: 100vh; background: var(--bg); }

/* Dark tile treatment — ONLY on tile layer, never on markers or choropleth */
.leaflet-tile-pane {
  filter: brightness(0.5) invert(1) contrast(2.5) hue-rotate(200deg) saturate(0.4) brightness(0.65);
}

.leaflet-control-attribution {
  background: rgba(22,27,34,.85) !important;
  color: var(--text-muted) !important;
  font-size: 10px;
  border-radius: 4px 0 0 0 !important;
}
.leaflet-control-attribution a { color: var(--text-muted) !important; }
.leaflet-control-zoom a {
  background: var(--surface2) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface) !important; color: var(--green) !important; }

/* ── Node dots ─────────────────────────────────────────── */
.node-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.3);
  cursor: pointer;
  transition: transform 0.1s;
}
.node-dot:hover { transform: scale(2); }

/* ── Cluster icons ─────────────────────────────────────── */
.cluster-icon {
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #fff;
  border: 2px solid rgba(255,255,255,.3);
  background: rgba(153,69,255,.85);
  backdrop-filter: blur(2px);
  cursor: pointer;
  transition: transform 0.1s, background 0.1s;
}
.cluster-icon:hover { background: rgba(153,69,255,1); transform: scale(1.1); }
.cluster-small  { width: 32px; height: 32px; font-size: 11px; }
.cluster-medium { width: 40px; height: 40px; font-size: 13px; }
.cluster-large  { width: 50px; height: 50px; font-size: 15px; }

/* ── Node detail panel ─────────────────────────────────── */
#node-detail {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: 290px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 2000;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease;
  box-shadow: -4px 0 20px rgba(0,0,0,.4);
}
#node-detail.hidden { transform: translateX(100%); }

#node-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  gap: 10px;
}
#node-detail-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
#node-detail-icon-wrap {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
}
#node-detail-icon-wrap img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface2);
  border: 1px solid var(--border);
}
#node-detail-icon-wrap:empty { display: none; }
#node-detail-name-wrap { flex: 1; min-width: 0; }
#node-detail-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#node-detail-website {
  font-size: 11px;
  color: var(--accent);
  text-decoration: none;
  display: block;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#node-detail-website:hover { text-decoration: underline; }
#node-detail-website.hidden { display: none; }

#node-detail-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.1s, background 0.1s;
}
#node-detail-close:hover { color: var(--text); background: var(--surface2); }

#node-detail-content { padding: 16px; flex: 1; }

.detail-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}
.detail-badge.validator { background: rgba(20,241,149,.15); color: var(--green); border: 1px solid rgba(20,241,149,.3); }
.detail-badge.delinquent{ background: rgba(255,107,107,.15); color: var(--red);   border: 1px solid rgba(255,107,107,.3); }
.detail-badge.rpc        { background: rgba(153,69,255,.15);  color: var(--purple);border: 1px solid rgba(153,69,255,.3); }
.detail-badge.node       { background: rgba(139,148,158,.1);  color: var(--text-muted); border: 1px solid var(--border); }

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(48,54,61,.5);
}
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }
.detail-value { font-size: 13px; color: var(--text); word-break: break-all; font-variant-numeric: tabular-nums; }
.detail-value.pubkey { font-family: 'SF Mono','Fira Code','Consolas',monospace; font-size: 12px; color: var(--accent); }
.detail-value.stake  { color: var(--green); font-weight: 600; font-size: 15px; }

/* Stake pool delegation section inside detail */
.pool-delegations { margin-top: 4px; }
.pool-delegation-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(48,54,61,.3);
  font-size: 12px;
}
.pool-delegation-row:last-child { border-bottom: none; }
.pool-color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.pool-delegation-name  { flex: 1; color: var(--text); }
.pool-delegation-stake { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ── Loading overlay ───────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,17,23,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  gap: 16px;
  transition: opacity 0.3s;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: var(--text-muted); font-size: 14px; }

/* ── Country pool indicator dots ────────────────────────── */
.bar-row { position: relative; }
.country-pool-dots {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  min-width: 20px;
}
.country-pool-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.country-pool-dot-multi {
  width: 6px;
  height: 6px;
}

/* ── Choropleth tooltip ─────────────────────────────────── */
.country-tooltip {
  background: rgba(13,17,23,0.92) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  color: var(--text) !important;
  font-size: 12px !important;
  padding: 6px 10px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5) !important;
  pointer-events: none !important;
}
.country-tooltip::before { display: none !important; }

/* ── Sidebar handle (mobile drag bar) ──────────────────── */
.sidebar-handle {
  display: none;
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
  cursor: grab;
}

/* ── Mobile toggle button (hidden on desktop) ──────────── */
#sidebar-toggle {
  display: none;
}
#sidebar-backdrop {
  display: none;
}

/* ── Responsive — 768px breakpoint ────────────────────── */
@media (max-width: 768px) {
  html, body { overflow: hidden; height: 100%; }
  body { display: block; }

  /* Map fills entire screen */
  #map {
    position: fixed;
    inset: 0;
    height: 100vh !important;
    width: 100vw;
    z-index: 1;
  }

  /* Sidebar becomes a bottom drawer */
  #sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-width: unset;
    height: 65vh;
    max-height: 65vh;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1500;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.6);
  }

  #sidebar.mobile-open {
    transform: translateY(0);
  }

  .sidebar-handle {
    display: block;
  }

  /* Backdrop overlay */
  #sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }
  #sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Floating toggle button */
  #sidebar-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    bottom: 20px;
    right: 16px;
    z-index: 1200;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 24px;
    padding: 13px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(153,69,255,0.55);
    transition: background 0.15s, transform 0.15s;
  }
  #sidebar-toggle:active { transform: scale(0.95); }

  /* Node detail panel — full-width bottom sheet */
  #node-detail {
    width: 100%;
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    height: 65vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
  }

  /* Touch-friendly tap targets */
  .filter-btn {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 13px;
  }
  .pool-btn {
    min-height: 40px;
    padding: 9px 12px;
    font-size: 13px;
  }

  /* Larger stat values */
  .stat-value { font-size: 22px; }

  /* Push zoom controls up above toggle button */
  .leaflet-bottom.leaflet-right {
    bottom: 68px !important;
  }
}
