:root {
  --bg-base: #06080d;
  --bg-surface: #0b0f18;
  --bg-card: rgba(14, 19, 30, 0.85);
  --bg-elevated: #111827;
  --bg-tertiary: #141e2e;

  --text-primary: #dde6f5;
  --text-secondary: #6b7c93;
  --text-muted: #3f5068;

  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);

  --accent: #34d399;
  --accent-dim: rgba(52, 211, 153, 0.08);
  --accent-glow: rgba(52, 211, 153, 0.18);

  --color-emerald: #34d399;
  --color-sky: #60a5fa;
  --color-amber: #fbbf24;
  --color-purple: #c084fc;
  --color-red: #f87171;

  --header-bg: rgba(6, 8, 13, 0.92);
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.55);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

body.light-mode {
  --bg-base: #f2f5fb;
  --bg-surface: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-elevated: #ffffff;
  --bg-tertiary: #eaf0f8;

  --text-primary: #0d1625;
  --text-secondary: #4a5e75;
  --text-muted: #8899b0;

  --border: rgba(0, 0, 0, 0.07);
  --border-hover: rgba(0, 0, 0, 0.14);

  --accent: #059669;
  --accent-dim: rgba(5, 150, 105, 0.08);
  --accent-glow: rgba(5, 150, 105, 0.16);

  --color-emerald: #059669;
  --color-sky: #2563eb;
  --color-amber: #d97706;
  --color-purple: #7c3aed;
  --color-red: #dc2626;

  --header-bg: rgba(242, 245, 251, 0.92);
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Plus Jakarta Sans", sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  transition:
    background 0.3s ease,
    color 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.032) 1px,
    transparent 1px
  );
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 0;
}

body.light-mode::before {
  background-image: radial-gradient(
    circle,
    rgba(0, 0, 0, 0.055) 1px,
    transparent 1px
  );
}

.site-header,
.main-content,
.site-footer,
#spinner,
#ip-tooltip {
  position: relative;
  z-index: 1;
}

/* ── HEADER ─────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--header-bg);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  transition:
    background 0.3s ease,
    border-color 0.3s ease;
  overflow: hidden;
}

.site-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent) 25%,
    var(--accent) 75%,
    transparent 100%
  );
  opacity: 0.25;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.title-cursor {
  color: var(--accent);
  font-weight: 400;
  animation: blink 1.1s step-start infinite;
  margin-left: 1px;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.site-title {
  font-family: "IBM Plex Mono", monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.2;
  color: var(--text-primary);
}

.text-accent {
  color: var(--accent);
}

.site-subtitle {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  color: var(--text-muted);
  margin: 3px 0 0;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 400;
}

.header-action-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hover);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.header-action-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(52, 211, 153, 0.35);
  box-shadow: 0 0 12px var(--accent-glow);
}

body.light-mode .header-action-btn:hover {
  border-color: rgba(5, 150, 105, 0.35);
}

.theme-toggle:focus-visible,
.header-action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body.light-mode .theme-toggle .moon-icon {
  display: none;
}

body.light-mode .theme-toggle .sun-icon {
  display: block;
}

body:not(.light-mode) .theme-toggle .moon-icon {
  display: block;
}

body:not(.light-mode) .theme-toggle .sun-icon {
  display: none;
}

/* ── LAYOUT ──────────────────────────────────────── */

.main-content {
  padding: 28px 16px 56px;
  min-height: calc(100vh - 140px);
}

.container {
  max-width: 1280px;
  margin: 0 auto;
}

/* ── STAT CARDS ──────────────────────────────────── */

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 18px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition:
    border-color 0.2s ease,
    transform 0.2s ease,
    box-shadow 0.2s ease;
  animation: fadeUp 0.45s ease both;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--card-accent, var(--accent));
}

.stat-card:nth-child(1) {
  animation-delay: 0ms;
  --card-accent: var(--color-emerald);
}

.stat-card:nth-child(2) {
  animation-delay: 70ms;
  --card-accent: var(--color-sky);
}

.stat-card:nth-child(3) {
  animation-delay: 140ms;
  --card-accent: var(--color-amber);
}

.stat-card:nth-child(4) {
  animation-delay: 210ms;
  --card-accent: var(--color-purple);
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.cyan {
  background: rgba(52, 211, 153, 0.1);
  color: var(--color-emerald);
}

.stat-icon.emerald {
  background: rgba(96, 165, 250, 0.1);
  color: var(--color-sky);
}

.stat-icon.amber {
  background: rgba(251, 191, 36, 0.1);
  color: var(--color-amber);
}

.stat-icon.purple {
  background: rgba(192, 132, 252, 0.1);
  color: var(--color-purple);
}

.stat-body {
  min-width: 0;
}

.stat-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.stat-value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.stat-date {
  font-size: 0.76rem !important;
}

.stat-value .stat-sub {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0;
}

/* ── FILTERS BAR ─────────────────────────────────── */

.filters-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 12px;
  margin-bottom: 20px;
  align-items: end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  padding-left: 2px;
}

.select-wrapper,
.search-wrapper {
  position: relative;
}

.select-wrapper .select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.filter-select,
.filter-search,
.btn-export {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

.filter-select:hover,
.filter-search:hover {
  border-color: var(--border-hover);
}

.filter-select:focus,
.filter-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-elevated);
}

.filter-search {
  padding-left: 38px;
  padding-right: 14px;
}

.search-wrapper .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.filter-select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-export {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 18px;
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(52, 211, 153, 0.35);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

body.light-mode .btn-export {
  border-color: rgba(5, 150, 105, 0.35);
}

.btn-export:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-export:active {
  transform: translateY(0);
  box-shadow: none;
}

/* ── MAP ─────────────────────────────────────────── */

.map-section {
  margin-bottom: 20px;
}

#map {
  height: 420px;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--bg-surface);
  transition: border-color 0.3s ease;
}

/* ── TABLE ───────────────────────────────────────── */

.table-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.3s ease;
}

.table-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
}

.table-title {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.server-count-badge {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(52, 211, 153, 0.15);
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.04em;
}

body.light-mode .server-count-badge {
  border-color: rgba(5, 150, 105, 0.2);
}

.table-container {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

#servers {
  min-width: 880px;
  width: 100%;
  border-collapse: collapse;
}

#servers thead {
  background: var(--bg-tertiary);
}

#servers th {
  padding: 10px 14px;
  text-align: left;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

#servers th.col-sortable {
  cursor: pointer;
  transition: color 0.15s ease;
}

#servers th.col-sortable:hover {
  color: var(--text-secondary);
}

#servers th .sort-icon {
  display: inline-block;
  margin-left: 5px;
  font-size: 0.58rem;
  opacity: 0.35;
  transition: opacity 0.15s ease;
}

#servers th.col-sortable:hover .sort-icon {
  opacity: 0.7;
}

#servers th.col-sortable .sort-icon.active {
  opacity: 1;
  color: var(--accent);
}

#servers td {
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  transition:
    background 0.12s ease,
    box-shadow 0.12s ease;
}

#servers tbody tr:hover td {
  background: rgba(52, 211, 153, 0.03);
}

#servers tbody tr:hover td:first-child {
  box-shadow: inset 2px 0 0 var(--accent);
}

body.light-mode #servers tbody tr:hover td {
  background: rgba(5, 150, 105, 0.04);
}

#servers tbody tr:last-child td {
  border-bottom: none;
}

#servers .cell-mono {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
}

/* Status badges */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
}

.badge-yes {
  background: rgba(52, 211, 153, 0.1);
  color: var(--color-emerald);
  border-color: rgba(52, 211, 153, 0.18);
}

body.light-mode .badge-yes {
  background: rgba(5, 150, 105, 0.08);
  border-color: rgba(5, 150, 105, 0.2);
}

.badge-no {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  border-color: var(--border);
}

body.light-mode .badge-no {
  background: rgba(0, 0, 0, 0.03);
}

/* Backwards compat */
#servers .cell-yes {
  color: var(--color-emerald);
  font-weight: 600;
}

#servers .cell-no {
  color: var(--text-muted);
}

#servers .cell-host {
  cursor: help;
  position: relative;
}

#servers mark {
  background: rgba(52, 211, 153, 0.15);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.84rem;
  font-family: "IBM Plex Mono", monospace;
}

/* ── SCROLL HINT ─────────────────────────────────── */

.scroll-hint {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .scroll-hint {
    display: flex;
  }
}

/* ── SPINNER ─────────────────────────────────────── */

.spinner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: color-mix(in srgb, var(--bg-base) 88%, transparent);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition:
    opacity 0.35s ease,
    visibility 0.35s ease;
}

.spinner-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.spinner-ring {
  width: 44px;
  height: 44px;
  border: 2px solid var(--border-hover);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── IP TOOLTIP ──────────────────────────────────── */

#ip-tooltip {
  position: absolute;
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.18s ease,
    visibility 0.18s ease;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-hover);
  max-width: 300px;
  min-width: 200px;
  line-height: 1.65;
}

#ip-tooltip.visible {
  opacity: 1;
  visibility: visible;
}

#ip-tooltip strong {
  color: var(--accent);
  font-weight: 600;
}

/* ── FOOTER ──────────────────────────────────────── */

.site-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  transition: background 0.3s ease;
  position: relative;
  z-index: 1;
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.footer-link {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-link:hover {
  color: var(--accent);
}

.footer-github {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-github:hover {
  color: var(--text-primary);
}

/* ── RESPONSIVE ──────────────────────────────────── */

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .filters-bar {
    grid-template-columns: 1fr;
  }

  .header-inner {
    padding: 10px 16px;
  }

  .site-title {
    font-size: 0.88rem;
  }

  .site-subtitle {
    display: none;
  }

  .main-content {
    padding: 16px 12px 36px;
  }

  #map {
    height: 300px;
  }

  #servers th,
  #servers td {
    padding: 8px 10px;
    font-size: 0.75rem;
  }

  .footer-inner {
    flex-direction: column;
    text-align: center;
  }

  .stat-card {
    padding: 14px 16px 14px 20px;
  }

  .stat-value {
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .stat-icon {
    width: 34px;
    height: 34px;
  }

  .stat-value {
    font-size: 0.88rem;
  }

  .stat-label {
    font-size: 0.58rem;
  }
}

/* ── SERVER MARKERS ──────────────────────────────── */

.server-marker {
  background: none !important;
  border: none !important;
}

.server-marker-dot {
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  box-shadow:
    0 0 8px var(--accent-glow),
    0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
  cursor: pointer;
}

.server-marker-dot:hover {
  transform: scale(1.5);
}

/* ── LEAFLET ─────────────────────────────────────── */

.leaflet-container {
  font-family: "Plus Jakarta Sans", sans-serif !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border-hover) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-lg) !important;
  color: var(--text-primary) !important;
}

.leaflet-popup-tip {
  background: var(--bg-elevated) !important;
}

.leaflet-popup-content {
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 0.82rem;
  line-height: 1.6;
  margin: 10px 14px !important;
  color: var(--text-primary) !important;
}

.leaflet-popup-content strong {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  color: var(--accent) !important;
}

.marker-cluster-small {
  background-color: rgba(52, 211, 153, 0.15) !important;
}

.marker-cluster-small div {
  background-color: rgba(52, 211, 153, 0.3) !important;
  color: #fff !important;
  font-family: "IBM Plex Mono", monospace !important;
  font-weight: 700 !important;
}

.marker-cluster-medium {
  background-color: rgba(251, 191, 36, 0.15) !important;
}

.marker-cluster-medium div {
  background-color: rgba(251, 191, 36, 0.3) !important;
  color: #fff !important;
  font-family: "IBM Plex Mono", monospace !important;
  font-weight: 700 !important;
}

.marker-cluster-large {
  background-color: rgba(248, 113, 113, 0.15) !important;
}

.marker-cluster-large div {
  background-color: rgba(248, 113, 113, 0.3) !important;
  color: #fff !important;
  font-family: "IBM Plex Mono", monospace !important;
  font-weight: 700 !important;
}

/* ── ZOOM CONTROLS ───────────────────────────────── */

.leaflet-bar {
  border: 1px solid var(--border-hover) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}

.leaflet-bar a {
  background: var(--bg-elevated) !important;
  color: var(--text-secondary) !important;
  border-bottom: 1px solid var(--border) !important;
  font-family: "IBM Plex Mono", monospace !important;
  font-weight: 700 !important;
  width: 30px !important;
  height: 30px !important;
  line-height: 28px !important;
  font-size: 15px !important;
  transition: all 0.15s ease !important;
  text-decoration: none !important;
}

.leaflet-bar a:hover {
  background: var(--accent-dim) !important;
  color: var(--accent) !important;
}

.leaflet-bar a:last-child {
  border-bottom: none !important;
}
