/* =========================================================
   Dash Masternode Map — modern, mobile-first stylesheet
   ========================================================= */

:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #21252e;
  --surface-3: #2a2f3a;
  --border: #2a2f3a;
  --text: #e7ecf3;
  --text-dim: #9aa3b2;
  --text-faint: #6b7280;
  --accent: #008de4;        /* Dash blue */
  --accent-2: #1ab1ff;
  --success: #2ecc71;
  --warning: #f5b041;
  --danger: #e74c3c;
  --evo: #1ab1ff;
  --regular: #2ecc71;
  --banned: #e74c3c;
  --inactive: #6b7280;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.30);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --topbar-bg-1: rgba(15,17,21,0.92);
  --topbar-bg-2: rgba(15,17,21,0.78);
}

:root[data-theme="light"] {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --surface-3: #eef0f5;
  --border: #e3e6ed;
  --text: #1a1d24;
  --text-dim: #4b5563;
  --text-faint: #6b7280;
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.18);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.10);
  --topbar-bg-1: rgba(255,255,255,0.92);
  --topbar-bg-2: rgba(255,255,255,0.78);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

#map {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--bg);
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: linear-gradient(180deg, var(--topbar-bg-1) 0%, var(--topbar-bg-2) 100%);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 1100;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.topbar__logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(0, 141, 228, 0.4);
}

.topbar__title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar__title h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__title .subtitle {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s;
}

.icon-btn:hover { background: var(--surface-3); }
.icon-btn:active { transform: scale(0.97); }
.icon-btn.is-active { color: var(--accent-2); border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }

/* Top-bar inline chips: total / active */
.topbar__stats {
  display: none;
  gap: 6px;
  margin-right: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}
.chip--total .chip__dot { background: var(--accent); }
.chip--active .chip__dot { background: var(--success); }
.chip__value { color: var(--text); font-weight: 600; }

@media (min-width: 720px) {
  .topbar__stats { display: inline-flex; }
  .topbar { padding-left: 18px; padding-right: 18px; }
  .topbar__title h1 { font-size: 1.15rem; }
}

/* ---------- Stale-data warning banner ---------- */

.stale-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
  z-index: 1090;
}
.stale-banner[hidden] { display: none; }

.stale-banner--warning {
  background: linear-gradient(180deg, rgba(245, 176, 65, 0.20), rgba(245, 176, 65, 0.08));
  border-bottom-color: rgba(245, 176, 65, 0.55);
}
.stale-banner--critical {
  background: linear-gradient(180deg, rgba(231, 76, 60, 0.24), rgba(231, 76, 60, 0.10));
  border-bottom-color: rgba(231, 76, 60, 0.60);
}
.stale-banner--unknown {
  background: linear-gradient(180deg, rgba(149, 165, 166, 0.18), rgba(149, 165, 166, 0.08));
  border-bottom-color: rgba(149, 165, 166, 0.40);
}

.stale-banner__icon {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
}
.stale-banner__icon svg { width: 14px; height: 14px; }
.stale-banner--warning .stale-banner__icon { color: var(--warning); }
.stale-banner--critical .stale-banner__icon { color: var(--danger); }
.stale-banner--unknown .stale-banner__icon { color: var(--text-dim); }

.stale-banner__text {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--text);
}
.stale-banner__title {
  font-weight: 600;
  margin-right: 6px;
}
.stale-banner__detail {
  color: var(--text-dim);
}

.stale-banner__close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}
.stale-banner__close:hover { color: var(--text); background: var(--surface-3); }
.stale-banner__close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.stale-banner__close svg { width: 14px; height: 14px; }

@media (max-width: 480px) {
  .stale-banner { padding: 8px 12px; font-size: 12.5px; gap: 8px; }
  .stale-banner__title { display: block; margin: 0 0 2px; }
}

/* Freshness summary card in the Overview / About tabs */
.freshness {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}
.freshness--warning { border-color: rgba(245, 176, 65, 0.55); }
.freshness--critical { border-color: rgba(231, 76, 60, 0.65); }
.freshness--unknown { border-color: rgba(149, 165, 166, 0.45); }
.freshness__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--success);
}
.freshness--warning .freshness__dot { background: var(--warning); }
.freshness--critical .freshness__dot { background: var(--danger); }
.freshness--unknown .freshness__dot { background: var(--text-faint); }
.freshness__text { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; min-width: 0; }
.freshness__title { color: var(--text); font-weight: 600; display: block; margin-bottom: 2px; }

/* ---------- Panel (mobile bottom sheet / desktop side panel) ---------- */

.panel {
  position: fixed;
  z-index: 1200;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.28s cubic-bezier(.22,.61,.36,1);
  will-change: transform;
}

/* Mobile: bottom sheet */
.panel {
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 18px 18px 0 0;
  border-bottom: none;
  max-height: 80vh;
  padding-bottom: var(--safe-bottom);
  transform: translateY(calc(100% - 60px));   /* peek state */
}

.panel.is-open { transform: translateY(0); }
.panel.is-collapsed { transform: translateY(100%); }

.panel__handle {
  height: 28px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.panel__handle::before {
  content: "";
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: var(--surface-3);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 8px;
  flex: 0 0 auto;
}

.panel__header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.panel__close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.panel__close:hover { color: var(--text); background: var(--surface-3); }

.panel__tabs {
  display: flex;
  gap: 4px;
  padding: 4px 12px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: 0 0 auto;
}

.panel__tab {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-dim);
  border-radius: 8px 8px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  position: relative;
  top: 1px;
}
.panel__tab:hover { color: var(--text); }
.panel__tab.is-active {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.panel__body {
  overflow-y: auto;
  padding: 12px 14px calc(20px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
}

/* Desktop: dock as a right-side panel */
@media (min-width: 900px) {
  .panel {
    top: 80px;
    right: 18px;
    bottom: 18px;
    left: auto;
    width: 360px;
    max-height: none;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding-bottom: 0;
    transform: translateX(0);
  }
  .panel.is-collapsed { transform: translateX(calc(100% + 36px)); }
  .panel__handle { display: none; }
  .panel__header { padding: 14px 16px 8px; }
}

/* ---------- Stats blocks ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.stat__label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}
.stat__value {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.stat__sub {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 1px;
}

.section { margin-bottom: 16px; }
.section__title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.section__hint {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.bar-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.bar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  position: relative;
  overflow: hidden;
}
.bar__fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0,141,228,0.10) 0%, rgba(0,141,228,0.04) 100%);
  transform-origin: left;
  z-index: 0;
}
.bar__label,
.bar__count { position: relative; z-index: 1; }
.bar__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.bar__count {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  font-weight: 500;
}

.flag {
  display: inline-block;
  font-size: 14px;
  line-height: 1;
}

/* ---------- Filters ---------- */

.field {
  display: block;
  margin-bottom: 12px;
}
.field__label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.input,
.select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
}
.input:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 141, 228, 0.25);
}

.input--search {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>");
  background-repeat: no-repeat;
  background-position: 10px 50%;
  background-size: 16px 16px;
  padding-left: 34px;
}

.toggle-group {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.toggle {
  padding: 8px 6px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, color 0.15s ease;
}
.toggle .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
}
.toggle:hover { color: var(--text); }
.toggle.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--border);
}

.filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  transition: background 0.15s ease, transform 0.05s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(0.98); }
.btn--ghost { background: transparent; }

/* ---------- Floating action button (mobile) ---------- */

.fab {
  position: fixed;
  right: 14px;
  bottom: calc(78px + var(--safe-bottom));   /* sits above the peek panel */
  z-index: 1150;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
}
.fab:hover { background: var(--surface-2); }
.fab svg { width: 22px; height: 22px; }

@media (min-width: 900px) {
  .fab { display: none; }
  /* Once the side panel is dismissed there's no other reopen affordance on
     desktop, so reveal the FAB. The selector relies on .fab being a sibling
     that follows .panel in the DOM. */
  .panel.is-collapsed ~ .fab { display: grid; }
}

/* ---------- Legend ---------- */

.legend__swatch { width: 10px; height: 10px; border-radius: 50%; }

/* ---------- Map themed overrides ---------- */

.leaflet-container {
  background: #0c0e12;
  font-family: inherit;
}

/* Hide ugly default focus outline on map tiles, keep on controls */
.leaflet-container:focus { outline: none; }

.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
}
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-2) !important; }
.leaflet-top.leaflet-left { top: 78px; }
@media (min-width: 720px) { .leaflet-top.leaflet-left { top: 82px; } }

.leaflet-control-attribution {
  background: rgba(15, 17, 21, 0.65) !important;
  color: var(--text-faint) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
  border-radius: 6px 0 0 0 !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }

/* Popup */
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  border-radius: 12px !important;
  box-shadow: var(--shadow-lg) !important;
}
.leaflet-popup-tip {
  background: var(--surface) !important;
  border: 1px solid var(--border);
}
.leaflet-popup-content {
  margin: 12px 14px !important;
  font-size: 13px !important;
  line-height: 1.5;
  min-width: 200px;
}
.leaflet-popup-close-button {
  color: var(--text-dim) !important;
  padding: 6px 8px !important;
}

.popup__title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.popup__row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12px;
  padding: 2px 0;
}
.popup__row strong { color: var(--text); font-weight: 500; }
.popup__id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text-faint);
  word-break: break-all;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.popup__id--alt {
  margin-top: 4px;
  padding-top: 4px;
  border-top: none;
}
.popup__id__label {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.popup__badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.popup__badge--active { background: rgba(46, 204, 113, 0.16); color: var(--success); }
.popup__badge--banned { background: rgba(231, 76, 60, 0.16); color: var(--danger); }
.popup__badge--evo    { background: rgba(26, 177, 255, 0.16); color: var(--evo); }
.popup__badge--regular{ background: rgba(46, 204, 113, 0.16); color: var(--regular); }
.popup__badge--other  { background: rgba(149, 165, 166, 0.16); color: var(--text-dim); }

/* Marker cluster customizations (use Default theme colors but tint to brand) */
.marker-cluster-small  { background-color: rgba(0, 141, 228, 0.30) !important; }
.marker-cluster-small div { background-color: rgba(0, 141, 228, 0.80) !important; color: #fff; }
.marker-cluster-medium { background-color: rgba(26, 177, 255, 0.30) !important; }
.marker-cluster-medium div { background-color: rgba(26, 177, 255, 0.80) !important; color: #fff; }
.marker-cluster-large  { background-color: rgba(245, 176, 65, 0.30) !important; }
.marker-cluster-large div { background-color: rgba(245, 176, 65, 0.85) !important; color: #1a1d24; }

.mn-marker {
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease;
}
.mn-marker:hover { transform: scale(1.15); }

/* ---------- Empty state in tabs ---------- */

.empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---------- Loading overlay ---------- */

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 2000;
  transition: opacity 0.25s ease;
}
.loading.is-hidden { opacity: 0; pointer-events: none; }
.loading__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--text-dim);
  font-size: 13px;
}
.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent-2);
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Visually-hidden helper ---------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
