:root {
  --bg: #0f172a;
  --surface: rgba(30, 41, 59, 0.8);
  --surface-solid: #1e293b;
  --border: rgba(148, 163, 184, 0.15);
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.connection-lost {
  background: var(--red);
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  font-weight: 500;
}
.connection-lost.hidden { display: none; }

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.9);
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.refresh-info {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.global-status {
  font-size: 13px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}

.refresh-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.refresh-btn:hover { background: rgba(56, 189, 248, 0.15); }
.refresh-btn.spinning svg, .refresh-btn.spinning { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Topology */
.topology-section {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

#topology {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  display: block;
}

/* SVG styles */
.topo-edge { stroke: #334155; stroke-width: 2; fill: none; }
.topo-edge-wan { stroke: #334155; stroke-width: 2; fill: none; stroke-dasharray: 8 4; }
.topo-edge-proxy { stroke: #38bdf8; stroke-width: 1.5; fill: none; stroke-dasharray: 4 4; }
.topo-edge-active { stroke: var(--green); }
.topo-flow { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 6; fill: none; animation: flow 1.5s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -20; } }

.topo-node circle, .topo-node rect {
  transition: fill 0.3s, stroke 0.3s;
}

/* Device Grid */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  padding: 20px 24px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Device Card */
.device-card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.3s;
}

.device-card:hover { border-color: rgba(56, 189, 248, 0.3); }
.device-card.offline { opacity: 0.6; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.card-icon { font-size: 24px; }

.status-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 12px;
}
.status-online { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.status-offline { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.status-warning { background: rgba(234, 179, 8, 0.15); color: var(--yellow); }

.ssh-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-dim);
  cursor: help;
}

/* Metric bars */
.metric {
  margin-bottom: 12px;
}
.metric:last-child { margin-bottom: 0; }

.metric-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
}
.metric-label span:first-child { color: var(--text-dim); }
.metric-label span:last-child { font-weight: 500; }

.bar-track {
  width: 100%;
  height: 6px;
  background: rgba(148, 163, 184, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease, background 0.5s ease;
}

.bar-fill.normal { background: linear-gradient(90deg, #22c55e, #4ade80); }
.bar-fill.warning { background: linear-gradient(90deg, #eab308, #facc15); }
.bar-fill.critical { background: linear-gradient(90deg, #ef4444, #f87171); }

/* Uptime */
.uptime {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.uptime-value { color: var(--text); font-weight: 500; }

/* Services */
.services {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.service-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(148, 163, 184, 0.08);
  color: var(--text-dim);
}

.service-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.service-dot.up { background: var(--green); }
.service-dot.down { background: var(--red); }

/* Responsive */
@media (max-width: 768px) {
  .device-grid {
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .header { padding: 12px 16px; }
  .topology-section { padding: 12px; }
}