:root {
  color-scheme: dark;
  --bg: #0a0c14;
  --bg-elevated: #0f1119;
  --surface: #151822;
  --surface-hover: #1a1e2e;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.1);
  --text: #e8eaf0;
  --text-secondary: #8b90a0;
  --text-muted: #5c6070;
  --ok: #22c55e;
  --ok-dim: rgba(34, 197, 94, 0.12);
  --ok-border: rgba(34, 197, 94, 0.25);
  --down: #ef4444;
  --down-dim: rgba(239, 68, 68, 0.12);
  --down-border: rgba(239, 68, 68, 0.25);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.12);
  --warn-border: rgba(245, 158, 11, 0.25);
  --unk: #6b7280;
  --unk-dim: rgba(107, 114, 128, 0.12);
  --unk-border: rgba(107, 114, 128, 0.25);
  --accent: #6366f1;
  --accent-dim: rgba(99, 102, 241, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  font-size: 14px;
}

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 12, 20, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
}

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

.header-chip {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.refresh-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.refresh-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.refresh-btn:active {
  transform: scale(0.95);
}

.refresh-btn.spinning svg {
  animation: spin 0.8s ease-in-out;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ── Main ── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ── Status Banner ── */
.status-banner {
  border-radius: var(--radius-lg);
  padding: 28px 28px 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}

.status-banner::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--unk);
  transition: background var(--transition);
}

.status-banner.all-ok::before { background: var(--ok); }
.status-banner.has-down::before { background: var(--down); }
.status-banner.all-ok { border-color: var(--ok-border); }
.status-banner.has-down { border-color: var(--down-border); }

.status-banner-inner {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--unk-dim);
  color: var(--unk);
  transition: all var(--transition);
}

.status-banner.all-ok .status-icon {
  background: var(--ok-dim);
  color: var(--ok);
}

.status-banner.has-down .status-icon {
  background: var(--down-dim);
  color: var(--down);
}

.status-headline {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
  line-height: 1.3;
}

.status-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.status-meta {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.meta-pill {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}

/* ── KPI Cards ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--transition);
}

.kpi-card:hover {
  border-color: var(--border-strong);
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-top: 6px;
  color: var(--text);
}

.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Section blocks ── */
.section-block {
  margin-top: 28px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ── External Service Cards ── */
.ext-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.ext-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.ext-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--unk);
  transition: background var(--transition);
}

.ext-card.ext-ok::before { background: var(--ok); }
.ext-card.ext-down::before { background: var(--down); }
.ext-card.loading::before { background: var(--unk); }

.ext-card:hover {
  border-color: var(--border-strong);
}

.ext-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ext-name {
  font-weight: 600;
  font-size: 14px;
}

.ext-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.ext-badge.ok {
  color: var(--ok);
  background: var(--ok-dim);
  border: 1px solid var(--ok-border);
}

.ext-badge.down {
  color: var(--down);
  background: var(--down-dim);
  border: 1px solid var(--down-border);
}

.ext-badge.unknown {
  color: var(--unk);
  background: var(--unk-dim);
  border: 1px solid var(--unk-border);
}

.ext-target {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.ext-details {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.ext-detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ext-detail-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.ext-detail-value {
  font-size: 13px;
  font-weight: 600;
}

/* ── Service Cards ── */
.services-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.svc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.svc-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  transition: background var(--transition);
}

.svc-card.s-up::before { background: var(--ok); }
.svc-card.s-down::before { background: var(--down); }
.svc-card.s-unknown::before { background: var(--unk); }

.svc-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.svc-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.svc-info {
  min-width: 0;
  flex: 1;
}

.svc-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.svc-target {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.svc-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.svc-badge.up {
  color: var(--ok);
  background: var(--ok-dim);
  border: 1px solid var(--ok-border);
}

.svc-badge.down {
  color: var(--down);
  background: var(--down-dim);
  border: 1px solid var(--down-border);
}

.svc-badge.unknown {
  color: var(--unk);
  background: var(--unk-dim);
  border: 1px solid var(--unk-border);
}

.svc-metrics {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.svc-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 80px;
}

.svc-metric-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.svc-metric-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.svc-footer {
  margin-top: 10px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
}

.svc-error {
  color: var(--down);
  opacity: 0.8;
}

/* ── Footer ── */
.footer {
  margin-top: 40px;
  padding: 20px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.footer-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .header-inner {
    height: 50px;
    padding: 0 16px;
  }

  .header-chip {
    display: none;
  }

  .main {
    padding: 16px 16px 48px;
  }

  .status-banner {
    padding: 20px 18px 18px;
  }

  .status-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .status-icon svg {
    width: 22px;
    height: 22px;
  }

  .status-headline {
    font-size: 17px;
  }

  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .kpi-card {
    padding: 14px;
  }

  .kpi-value {
    font-size: 18px;
  }

  .ext-grid {
    grid-template-columns: 1fr;
  }

  .svc-metrics {
    gap: 12px;
  }

  .svc-metric {
    min-width: 70px;
  }

  .svc-target {
    white-space: normal;
    word-break: break-all;
  }
}

@media (max-width: 380px) {
  .kpi-row {
    grid-template-columns: 1fr;
  }

  .status-banner-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.svc-card, .ext-card {
  animation: fadeIn 0.3s ease both;
}

.svc-card:nth-child(1) { animation-delay: 0.02s; }
.svc-card:nth-child(2) { animation-delay: 0.04s; }
.svc-card:nth-child(3) { animation-delay: 0.06s; }
.svc-card:nth-child(4) { animation-delay: 0.08s; }
.svc-card:nth-child(5) { animation-delay: 0.10s; }
.svc-card:nth-child(6) { animation-delay: 0.12s; }
.svc-card:nth-child(7) { animation-delay: 0.14s; }
.svc-card:nth-child(8) { animation-delay: 0.16s; }
.svc-card:nth-child(9) { animation-delay: 0.18s; }
.svc-card:nth-child(10) { animation-delay: 0.20s; }

/* ── Pulse for active outage ── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.svc-badge.down {
  animation: pulse 2s ease-in-out infinite;
}

.ext-badge.down {
  animation: pulse 2s ease-in-out infinite;
}
