:root {
  --bg-base: #0a0b0f;
  --bg-surface: #111318;
  --bg-card: #16181f;
  --bg-card-hover: #1c1f29;
  --bg-input: #0e1015;
  --border: #1e2130;
  --border-focus: #6366f1;
  --text-primary: #e9eaf0;
  --text-secondary: #8b8fa8;
  --text-muted: #545874;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.12);
  --yellow: #f59e0b;
  --yellow-dim: rgba(245, 158, 11, 0.12);
  --blue: #3b82f6;
  --sidebar-w: 220px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Inter', -apple-system, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
}

/* ───── Layout ───── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ───── Sidebar ───── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 0;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: var(--accent-glow);
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(99,102,241,0.2);
}

.nav-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.footer-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ───── Main Content ───── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 58px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

#page-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

/* ───── Buttons ───── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  font-family: var(--font);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover { background: var(--red-dim); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-card); }

.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ───── Cards ───── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ───── Stats Grid ───── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: all 0.15s ease;
}

.stat-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ───── Monitor List ───── */
.monitor-list { display: flex; flex-direction: column; gap: 8px; }

.monitor-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.monitor-item:hover {
  border-color: rgba(99,102,241,0.3);
  background: var(--bg-card-hover);
  transform: translateX(2px);
}

.monitor-status-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.monitor-info { flex: 1; min-width: 0; }

.monitor-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.monitor-target {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.monitor-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.monitor-type-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 30px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.monitor-nodes-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 30px;
}

.monitor-response {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  min-width: 60px;
  text-align: right;
}

/* ───── Status Colors ───── */
.status-up { background: var(--green); box-shadow: 0 0 8px rgba(34,197,94,0.5); }
.status-down { background: var(--red); box-shadow: 0 0 8px rgba(239,68,68,0.5); }
.status-unknown { background: var(--text-muted); }

.badge-ping { background: rgba(59,130,246,0.15); color: var(--blue); border: 1px solid rgba(59,130,246,0.3); }
.badge-service { background: rgba(168,85,247,0.15); color: #a855f7; border: 1px solid rgba(168,85,247,0.3); }
.badge-website { background: rgba(34,197,94,0.1); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.badge-heartbeat { background: rgba(245,158,11,0.1); color: var(--yellow); border: 1px solid rgba(245,158,11,0.3); }

.text-up { color: var(--green); }
.text-down { color: var(--red); }
.text-unknown { color: var(--text-muted); }

/* ───── Status Dots ───── */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-dot.online { background: var(--green); animation: pulse-green 2s infinite; }
.status-dot.offline { background: var(--red); }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
  50% { box-shadow: 0 0 0 4px rgba(34,197,94,0); }
}

/* ───── Table ───── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(30,33,48,0.6);
  color: var(--text-secondary);
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: rgba(255,255,255,0.02); }

td .badge { display: inline-block; }

/* ───── Forms ───── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-select { cursor: pointer; }
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* ───── Node Selector ───── */
.node-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.node-checkbox-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.15s;
  user-select: none;
}

.node-checkbox-item:hover { border-color: var(--accent); color: var(--text-primary); }
.node-checkbox-item.selected { background: var(--accent-glow); border-color: rgba(99,102,241,0.4); color: var(--accent); }
.node-checkbox-item input[type="checkbox"] { accent-color: var(--accent); }

/* ───── Uptime Bars ───── */
.uptime-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 24px;
}

.uptime-bar {
  flex: 1;
  border-radius: 2px;
  min-width: 4px;
  transition: opacity 0.15s;
}
.uptime-bar:hover { opacity: 0.8; }

/* ───── Progress Bars ───── */
.progress-bar-track {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ───── Metrics Grid ───── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.metric-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

/* ───── Modal ───── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}

.modal-title { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-surface);
  position: sticky;
  bottom: 0;
}

/* ───── Toast ───── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
  animation: slideInRight 0.25s ease;
  min-width: 260px;
  max-width: 360px;
}

.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast-info { border-left: 3px solid var(--accent); }

/* ───── Empty State ───── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 42px; margin-bottom: 12px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state-sub { font-size: 13.5px; }

/* ───── Loading ───── */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 14px;
  color: var(--text-muted);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ───── Uptime Pill ───── */
.uptime-pct {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 30px;
}
.uptime-pct.good { background: var(--green-dim); color: var(--green); }
.uptime-pct.warn { background: var(--yellow-dim); color: var(--yellow); }
.uptime-pct.bad  { background: var(--red-dim); color: var(--red); }

/* ───── Code ───── */
.code-block {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-secondary);
  word-break: break-all;
  position: relative;
}

/* ───── Divider ───── */
.divider { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

/* ───── Page header ───── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header-left h1 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 2px;
}
.page-header-left p { font-size: 13px; color: var(--text-muted); }

/* ───── Section title ───── */
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ───── Node card ───── */
.node-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all 0.15s;
}
.node-card:hover { border-color: rgba(99,102,241,0.3); }
.node-card-info { flex: 1; }
.node-card-name { font-weight: 600; font-size: 14px; margin-bottom: 3px; }
.node-card-host { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.node-card-actions { display: flex; gap: 6px; }
.nodes-grid { display: flex; flex-direction: column; gap: 10px; }

/* ───── Animations ───── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───── Public status page ───── */
body.status-page-view {
  overflow: auto;
  background: var(--bg-base);
}
.sp-container { max-width: 760px; margin: 0 auto; padding: 40px 20px; }
.sp-header { text-align: center; margin-bottom: 36px; }
.sp-title { font-size: 28px; font-weight: 800; margin-bottom: 8px; }
.sp-overall {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  border-radius: 30px;
  font-weight: 600;
  font-size: 14px;
}
.sp-overall.up { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.sp-overall.down { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.sp-monitor-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 10px;
}
.sp-monitor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sp-monitor-name { font-weight: 600; font-size: 14px; }
