:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-dim: rgba(42, 120, 214, 0.12);
  --status-good: #0ca30c;
  --status-good-dim: rgba(12, 163, 12, 0.12);
  --status-warning: #c98500;
  --status-warning-dim: rgba(201, 133, 0, 0.14);
  --status-critical: #d03b3b;
  --status-critical-dim: rgba(208, 59, 59, 0.12);
  --track: rgba(11, 11, 11, 0.07);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
}

main {
  padding: 20px 28px 40px;
  max-width: 1600px;
  margin: 0 auto;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 20px 28px 12px;
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.logo {
  align-self: center;
  border-radius: 8px;
}

.topbar-title h1 {
  font-size: 22px;
  font-weight: 600;
  margin: 0;
}

.clock {
  font-size: 14px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.log-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
}

.log-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.alert-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--status-critical-dim);
  color: var(--status-critical);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.alert-badge:hover {
  filter: brightness(0.95);
}

.alert-badge.flash {
  animation: alertFlash 0.6s ease-in-out 2;
}

@keyframes alertFlash {
  0%, 100% { background: var(--status-critical-dim); transform: scale(1); }
  50% { background: var(--status-critical); color: #fff; transform: scale(1.08); }
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-good);
  box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.5);
  animation: pulse 2s infinite;
}

.live-dot.stale {
  background: var(--status-critical);
  animation: none;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.45); }
  70%  { box-shadow: 0 0 0 6px rgba(12, 163, 12, 0); }
  100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); }
}

.muted { color: var(--muted); }

.error-banner {
  margin: 16px 28px 0;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--status-critical-dim);
  color: var(--status-critical);
  border: 1px solid rgba(230, 103, 103, 0.35);
  font-size: 14px;
}

/* ---------- Alerts ---------- */

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

.alerts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--status-critical-dim);
  border: 1px solid rgba(208, 59, 59, 0.30);
  color: var(--text-primary);
  font-size: 13px;
}

.alert-item .alert-message {
  font-weight: 600;
  color: var(--status-critical);
}

.alert-item .alert-since {
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: 12px;
}

/* ---------- Sparkline ---------- */

.trend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 10px;
  padding-top: 8px;
  border-top: 1px solid var(--gridline);
}

.trend-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.trend-row svg {
  display: block;
}

/* ---------- Stat tiles ---------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 20px 0 28px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 30px;
  font-weight: 600;
}

/* ---------- Sections ---------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0;
}

/* ---------- Node cards ---------- */

.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.node-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.node-card:hover {
  border-color: var(--accent);
}

.node-card.active-filter {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.node-card.offline {
  opacity: 0.55;
  cursor: default;
}

.node-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.node-name {
  font-size: 16px;
  font-weight: 600;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

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

.pill.good { background: var(--status-good-dim); color: var(--status-good); }
.pill.good .pill-dot { background: var(--status-good); }

.pill.critical { background: var(--status-critical-dim); color: var(--status-critical); }
.pill.critical .pill-dot { background: var(--status-critical); }

.pill.neutral { background: var(--track); color: var(--muted); }
.pill.neutral .pill-dot { background: var(--muted); }

.meter-row {
  margin-bottom: 10px;
}

.meter-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.meter-track {
  height: 6px;
  border-radius: 4px;
  background: var(--track);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
}

.meter-fill.warning { background: var(--status-warning); }
.meter-fill.critical { background: var(--status-critical); }

.temp-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 10px;
}

.chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--track);
  color: var(--text-secondary);
  white-space: nowrap;
}

.chip.warning { background: var(--status-warning-dim); color: var(--status-warning); }
.chip.critical { background: var(--status-critical-dim); color: var(--status-critical); }
.chip.good { background: var(--status-good-dim); color: var(--status-good); }

.node-footer {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--gridline);
  padding-top: 10px;
  margin-top: 4px;
}

/* ---------- VM table ---------- */

.vm-filter {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  width: 260px;
}

.vm-filter::placeholder { color: var(--muted); }

.filter-select {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination button {
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

.pagination button:not(:disabled):hover {
  border-color: var(--accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge.critical { background: var(--status-critical-dim); color: var(--status-critical); }
.badge.good { background: var(--status-good-dim); color: var(--status-good); }
.badge.neutral { background: var(--track); color: var(--muted); }

#nodeFilterTag { cursor: pointer; }

.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

thead th[data-sort] {
  cursor: pointer;
  user-select: none;
}

thead th[data-sort]:hover {
  color: var(--text-primary);
}

thead th[data-sort]::after {
  content: "";
  display: inline-block;
  width: 10px;
}

thead th.sorted-asc::after {
  content: "▲";
  color: var(--accent);
  font-size: 9px;
  margin-left: 3px;
}

thead th.sorted-desc::after {
  content: "▼";
  color: var(--accent);
  font-size: 9px;
  margin-left: 3px;
}

tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

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

tbody tr:hover { background: rgba(11, 11, 11, 0.03); }

td.num { font-variant-numeric: tabular-nums; text-align: right; }
thead th.num { text-align: right; }

.status-cell {
  display: flex;
  align-items: center;
  gap: 7px;
}

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

.status-dot.running { background: var(--status-good); }
.status-dot.stopped { background: var(--muted); }

.empty-state {
  text-align: center;
  padding: 30px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  main { padding: 16px; }
}
