:root {
  --bg: #050507;
  --glass: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-hover: rgba(255, 255, 255, 0.07);
  --glass-blur: 20px;
  --text: #f0f0f5;
  --text-muted: rgba(255, 255, 255, 0.45);
  --online: #30d158;
  --offline: #ff453a;
  --alerting: #ffd60a;
  --dormant: rgba(255, 255, 255, 0.3);
  --unknown: rgba(255, 255, 255, 0.2);
  --accent: #6366f1;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--glass);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  z-index: 10;
}

header h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.status-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-bar .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
  display: inline-block;
  margin-right: 4px;
  animation: pulse 2s infinite;
}

.status-bar .dot.inactive {
  background: var(--offline);
  animation: none;
}

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

/* ── Legend ─────────────────────────────────────────────── */
.legend {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Main layout ─────────────────────────────────────────── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Map ─────────────────────────────────────────────────── */
#map {
  flex: 1;
  min-width: 0;
}

/* ── Side panel ──────────────────────────────────────────── */
.side-panel {
  width: 360px;
  flex-shrink: 0;
  background: var(--glass);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border-left: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-section {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--glass-border);
}

.panel-section h2,
.wan-section h2,
.log-section h2 {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.6rem;
}

/* ── Summary counts ──────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.summary-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 0.5rem 0.4rem;
  text-align: center;
  transition: background 0.2s;
}

.summary-card:hover {
  background: var(--glass-hover);
}

.summary-card .count {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.summary-card .label {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.summary-card.online  .count { color: var(--online); }
.summary-card.offline .count { color: var(--offline); }
.summary-card.alerting .count { color: var(--alerting); }
.summary-card.other   .count { color: var(--dormant); }

/* ── WAN graph ───────────────────────────────────────────── */
.wan-section {
  display: flex;
  flex-direction: column;
  padding: 0.85rem 1rem;
  min-height: 180px;
  max-height: 280px;
  border-bottom: 1px solid var(--glass-border);
}

.wan-section h2 {
  flex-shrink: 0;
}

.wan-select-wrapper {
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.wan-select-wrapper select {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-size: 0.78rem;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.2s;
}

.wan-select-wrapper select:focus {
  border-color: rgba(255, 255, 255, 0.2);
}

.chart-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#wanChart {
  width: 100% !important;
  height: 100% !important;
}

.no-data {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
  margin-top: 1.5rem;
}

/* ── Status change log ───────────────────────────────────── */
.log-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.85rem 1rem;
  min-height: 0;
  overflow: hidden;
}

.log-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.log-list::-webkit-scrollbar {
  width: 4px;
}

.log-list::-webkit-scrollbar-track {
  background: transparent;
}

.log-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.72rem;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-entry .log-time {
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  min-width: 60px;
}

.log-entry .log-device {
  color: var(--text);
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-entry .log-change {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.log-entry .log-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.log-entry .log-arrow {
  color: var(--text-muted);
  font-size: 0.65rem;
}

/* ── Device popup ────────────────────────────────────────── */
.maplibregl-popup-content {
  background: rgba(20, 20, 28, 0.85) !important;
  backdrop-filter: blur(24px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(24px) saturate(180%) !important;
  color: var(--text) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: 12px !important;
  padding: 0.7rem 0.9rem !important;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif !important;
  min-width: 200px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6) !important;
}

.maplibregl-popup-tip {
  border-top-color: rgba(20, 20, 28, 0.85) !important;
  border-bottom-color: rgba(20, 20, 28, 0.85) !important;
}

.maplibregl-popup-close-button {
  color: var(--text-muted) !important;
  font-size: 1.1rem;
}

.popup-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.popup-row span:last-child {
  color: var(--text);
}

.popup-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  font-weight: 500;
  margin-top: 0.4rem;
}

.popup-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.popup-wan-btn {
  margin-top: 0.5rem;
  width: 100%;
  background: rgba(99, 102, 241, 0.3);
  backdrop-filter: blur(8px);
  color: #c7c8ff;
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  font-size: 0.74rem;
  cursor: pointer;
  transition: background 0.2s;
}

.popup-wan-btn:hover {
  background: rgba(99, 102, 241, 0.45);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .main {
    flex-direction: column;
  }

  #map {
    height: 50vh;
    flex: none;
  }

  .side-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--glass-border);
    height: 50vh;
  }
}
