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

:root {
  --bg-base: #09090b;
  --bg-surface: #111114;
  --bg-elevated: #18181b;
  --bg-hover: #1e1e23;
  --border: #27272a;
  --border-subtle: #1e1e22;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --text-dim: #52525b;
  --accent: #dc2626;
  --accent-hover: #ef4444;
  --accent-soft: rgba(220, 38, 38, 0.12);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.10);
  --green-border: rgba(34, 197, 94, 0.25);
  --yellow: #f59e0b;
  --yellow-soft: rgba(245, 158, 11, 0.10);
  --yellow-border: rgba(245, 158, 11, 0.25);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.10);
  --red-border: rgba(239, 68, 68, 0.25);
  --gray: #52525b;
  --gray-soft: rgba(82, 82, 91, 0.10);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Auth Gate ── */
.auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-base);
}
.auth-card {
  width: 360px;
  max-width: 90vw;
  text-align: center;
  padding: 48px 32px;
}
.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  color: white;
  font-size: 24px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}
.auth-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.auth-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 32px;
}
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-btn {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
}
.auth-btn:hover { background: var(--accent-hover); }
.auth-error {
  font-size: 13px;
  color: var(--red);
  min-height: 20px;
}

/* ── Dashboard ── */
.dashboard { max-width: 1440px; margin: 0 auto; padding: 0 24px 48px; }

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 24px;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}
.header-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}
.header-right { display: flex; align-items: center; gap: 12px; }
.header-ts { font-size: 12px; color: var(--text-dim); }
.poller-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
}
.poller-dot.ok { background: var(--green); }
.poller-dot.error { background: var(--red); }
.poller-dot.partial { background: var(--yellow); }
.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-ghost {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}
.btn-ghost:hover { color: var(--text-primary); }

/* ── Stats Bar ── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow-x: auto;
}
.stat { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.stat-value { font-size: 18px; font-weight: 600; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.stat-dot.green { background: var(--green); }
.stat-dot.yellow { background: var(--yellow); }
.stat-dot.red { background: var(--red); }
.stat-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── Alerts ── */
.alerts-container { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.alert-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border-left: 3px solid;
  font-size: 13px;
  line-height: 1.5;
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-4px); } }
.alert-banner.red {
  background: var(--red-soft);
  border-left-color: var(--red);
  color: var(--text-primary);
}
.alert-banner.yellow {
  background: var(--yellow-soft);
  border-left-color: var(--yellow);
  color: var(--text-primary);
}
.alert-banner .alert-name { font-weight: 600; }
.alert-banner .alert-reason { color: var(--text-secondary); }

/* ── Filter Bar ── */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.filter-pills { display: flex; gap: 6px; }
.pill {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
}
.pill:hover { background: var(--bg-hover); color: var(--text-primary); }
.pill.active { background: var(--accent-soft); color: var(--accent-hover); border-color: var(--accent); }
.pill .pill-count {
  display: inline-block;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  background: var(--bg-hover);
  font-size: 11px;
  margin-left: 4px;
  padding: 0 4px;
}
.pill.active .pill-count { background: rgba(99, 102, 241, 0.2); }
.filter-right { display: flex; gap: 8px; align-items: center; }
.search-input {
  width: 200px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }
.sort-select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
}
.sort-select:focus { border-color: var(--accent); }

/* ── Data Table ── */
.table-wrap {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-surface);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.data-table thead th {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table thead th.col-num { text-align: right; }
.data-table thead th.col-trend { text-align: center; }
.data-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.1s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-primary);
  vertical-align: middle;
}
.data-table tbody td.col-num { text-align: right; }
.data-table tbody td.col-trend { text-align: center; }

.col-status { width: 6px; padding: 0 !important; }
.status-bar {
  width: 3px;
  height: 32px;
  border-radius: 2px;
  margin-left: 2px;
}
.status-bar.green { background: var(--green); }
.status-bar.yellow { background: var(--yellow); }
.status-bar.red { background: var(--red); }
.status-bar.gray { background: var(--gray); }

.col-secondary { color: var(--text-muted) !important; }

.acc-cell { display: flex; flex-direction: column; gap: 2px; }
.acc-name { font-weight: 500; color: var(--text-primary); font-size: 13px; }
.acc-reason { font-size: 11px; color: var(--text-muted); max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cpl-over { color: var(--red); }
.cpl-ok { color: var(--green); }
.cpl-neutral { color: var(--text-secondary); }

.table-empty {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Sparkline ── */
.sparkline { display: inline-block; vertical-align: middle; }
.sparkline svg { display: block; }

/* ── Skeleton ── */
.skeleton-wrap { padding: 16px; }
.skeleton-row {
  height: 52px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-elevated) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  margin-bottom: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Detail Panel ── */
.detail-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.detail-overlay.open { opacity: 1; pointer-events: auto; }
.detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 680px;
  max-width: 100vw;
  background: var(--bg-base);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  padding: 28px;
}
.detail-overlay.open .detail-panel { transform: translateX(0); }

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.detail-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.detail-sub { font-size: 12px; color: var(--text-muted); }
.detail-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.detail-status-badge.green { background: var(--green-soft); color: var(--green); border: 1px solid var(--green-border); }
.detail-status-badge.yellow { background: var(--yellow-soft); color: var(--yellow); border: 1px solid var(--yellow-border); }
.detail-status-badge.red { background: var(--red-soft); color: var(--red); border: 1px solid var(--red-border); }
.detail-status-badge.gray { background: var(--gray-soft); color: var(--text-muted); border: 1px solid var(--border); }

.detail-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
}
.detail-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.detail-reason {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}
.detail-reason.green { background: var(--green-soft); border-left: 3px solid var(--green); }
.detail-reason.yellow { background: var(--yellow-soft); border-left: 3px solid var(--yellow); }
.detail-reason.red { background: var(--red-soft); border-left: 3px solid var(--red); }
.detail-reason.gray { background: var(--gray-soft); border-left: 3px solid var(--gray); }

.detail-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.detail-metric {
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.dm-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.dm-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.dm-change { font-size: 12px; margin-top: 2px; }
.dm-change.up { color: var(--green); }
.dm-change.down { color: var(--red); }

.detail-section { margin-bottom: 28px; }
.detail-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.detail-chart-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}
.detail-chart-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.detail-table thead th {
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: right;
  border-bottom: 1px solid var(--border-subtle);
}
.detail-table thead th:first-child { text-align: left; }
.detail-table tbody td {
  padding: 8px 12px;
  color: var(--text-secondary);
  text-align: right;
  border-bottom: 1px solid var(--border-subtle);
}
.detail-table tbody td:first-child { text-align: left; color: var(--text-muted); }
.detail-table tbody tr:last-child td { border-bottom: none; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .col-secondary { display: none; }
}

@media (max-width: 768px) {
  html { font-size: 13px; }
  .dashboard { padding: 0 16px 32px; }
  .header { flex-wrap: wrap; gap: 8px; }
  .stats-bar {
    flex-wrap: wrap;
    gap: 16px;
    padding: 14px 16px;
  }
  .stat-divider { display: none; }
  .stat { min-width: calc(33% - 16px); }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-right { width: 100%; }
  .search-input { flex: 1; width: auto; }
  .table-wrap { border-radius: var(--radius-md); overflow-x: auto; }
  .data-table thead th.col-trend,
  .data-table tbody td.col-trend { display: none; }
  .detail-panel { width: 100%; }
  .detail-metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stats-bar { gap: 12px; }
  .stat { min-width: calc(50% - 12px); }
  .stat-value { font-size: 16px; }
  .data-table thead th.col-num:nth-child(n+5),
  .data-table tbody td.col-num:nth-child(n+5) { display: none; }
}
