:root {
  color-scheme: dark;
  --bg: #08090f;
  --bg-elevated: #0d0f1a;
  --surface: #111318;
  --surface-hover: #161924;
  --border: rgba(255, 255, 255, 0.055);
  --border-strong: rgba(255, 255, 255, 0.1);
  --text: #e8eaf0;
  --text-secondary: #8b90a0;
  --text-muted: #50566a;
  --ok: #22c55e;
  --ok-dim: rgba(34, 197, 94, 0.1);
  --ok-border: rgba(34, 197, 94, 0.22);
  --ok-glow: rgba(34, 197, 94, 0.06);
  --down: #ef4444;
  --down-dim: rgba(239, 68, 68, 0.1);
  --down-border: rgba(239, 68, 68, 0.22);
  --down-glow: rgba(239, 68, 68, 0.06);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.1);
  --warn-border: rgba(245, 158, 11, 0.22);
  --unk: #4b5568;
  --unk-dim: rgba(75, 85, 104, 0.15);
  --unk-border: rgba(75, 85, 104, 0.25);
  --accent: #6366f1;
  --accent-dim: rgba(99, 102, 241, 0.1);
  --lat-fast: #22c55e;
  --lat-mid: #f59e0b;
  --lat-slow: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition: 0.18s 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(8, 9, 15, 0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

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

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

.logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.3);
}

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

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

/* Live indicator dot */
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--unk);
  transition: background var(--transition);
  flex-shrink: 0;
}
.live-dot.live-ok {
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
  animation: livePulse 2.5s ease-out infinite;
}
.live-dot.live-down { background: var(--down); }

@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0.5); }
  70%  { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0); }
}

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

.refresh-btn {
  width: 32px; height: 32px; border-radius: 9px;
  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.94); }
.refresh-btn.spinning svg { animation: spin 0.75s ease-in-out; }

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

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

/* ── Status Banner ── */
.status-banner {
  border-radius: var(--radius-lg);
  padding: 26px 28px 22px;
  border: 1px solid var(--border);
  background: var(--surface);
  position: relative; overflow: hidden;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Top color stripe */
.status-banner::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--unk);
  transition: background 0.3s ease;
}

/* Background glow */
.status-banner::after {
  content: "";
  position: absolute; inset: 0; pointer-events: none;
  background: transparent;
  transition: background 0.4s ease;
}

.status-banner.all-ok::before { background: var(--ok); }
.status-banner.all-ok::after  { background: radial-gradient(ellipse 60% 80% at 5% 50%, var(--ok-glow), transparent 70%); }
.status-banner.all-ok { border-color: var(--ok-border); box-shadow: 0 0 0 1px var(--ok-border) inset; }

.status-banner.has-down::before { background: var(--down); }
.status-banner.has-down::after  { background: radial-gradient(ellipse 60% 80% at 5% 50%, var(--down-glow), transparent 70%); }
.status-banner.has-down { border-color: var(--down-border); box-shadow: 0 0 0 1px var(--down-border) inset; }

.status-banner-inner { display: flex; align-items: center; gap: 16px; position: relative; z-index: 1; }

.status-icon {
  width: 50px; height: 50px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: var(--unk-dim); color: var(--unk);
  transition: all 0.3s ease;
}
.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: 19px; 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: 14px; flex-wrap: wrap; position: relative; z-index: 1; }

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

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

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

.kpi-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--text-muted);
}
.kpi-value { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; margin-top: 6px; }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ── Section ── */
.section-block { margin-top: 26px; }
.section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--text-muted); margin-bottom: 10px;
}

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

.ext-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  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: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: 13px; }
.ext-badge { font-size: 11px; font-weight: 600; padding: 3px 9px; 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); animation: pulse 2s ease-in-out infinite; }
.ext-badge.unknown { color: var(--unk);  background: var(--unk-dim);  border: 1px solid var(--unk-border); }

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

.ext-details {
  display: flex; gap: 16px; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border); flex-wrap: wrap;
}
.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: 12px; font-weight: 600; }

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

.svc-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  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: 10px; }
.svc-info { min-width: 0; flex: 1; }
.svc-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.svc-target { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.svc-badge { font-size: 10px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; flex-shrink: 0; letter-spacing: 0.2px; }
.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); animation: pulse 2s ease-in-out infinite; }
.svc-badge.unknown { color: var(--unk);  background: var(--unk-dim);  border: 1px solid var(--unk-border); }

/* ── Uptime history bars ── */
.uptime-bars {
  display: flex; gap: 2px; align-items: flex-end;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
}
.ubar {
  flex: 1; height: 24px; border-radius: 2px;
  background: var(--unk-dim);
  transition: opacity 0.2s;
  cursor: default;
}
.ubar:hover { opacity: 0.7; }
.ubar.ok   { background: rgba(34, 197, 94, 0.55); }
.ubar.down { background: rgba(239, 68, 68, 0.65); }
.ubar.unk  { background: rgba(75, 85, 104, 0.3); }

.uptime-bar-label {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 5px;
}
.uptime-bar-pct { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.uptime-bar-hint { font-size: 10px; color: var(--text-muted); }

/* ── Uptime progress bar ── */
.uptime-progress-wrap {
  height: 3px; border-radius: 999px;
  background: var(--unk-dim); overflow: hidden;
  margin-top: 4px;
}
.uptime-progress-bar {
  height: 100%; border-radius: 999px;
  background: var(--ok);
  transition: width 0.4s ease;
}
.uptime-progress-bar.mid  { background: var(--warn); }
.uptime-progress-bar.low  { background: var(--down); }

/* ── Latency color classes ── */
.lat-fast { color: var(--lat-fast) !important; }
.lat-mid  { color: var(--lat-mid)  !important; }
.lat-slow { color: var(--lat-slow) !important; }

/* ── Metrics row ── */
.svc-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px 10px;
  margin-top: 10px;
}
.svc-metric { display: flex; flex-direction: column; gap: 2px; }
.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: 12px; font-weight: 600; color: var(--text-secondary); }

.svc-footer { margin-top: 8px; font-size: 11px; color: var(--text-muted); line-height: 1.5; }
.svc-error  { color: var(--down); opacity: 0.85; }

/* ── 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); }

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

.svc-card {
  animation: fadeIn 0.25s ease both;
}
.svc-card:nth-child(1)  { animation-delay: 0.01s; }
.svc-card:nth-child(2)  { animation-delay: 0.02s; }
.svc-card:nth-child(3)  { animation-delay: 0.03s; }
.svc-card:nth-child(4)  { animation-delay: 0.04s; }
.svc-card:nth-child(5)  { animation-delay: 0.05s; }
.svc-card:nth-child(6)  { animation-delay: 0.06s; }
.svc-card:nth-child(7)  { animation-delay: 0.07s; }
.svc-card:nth-child(8)  { animation-delay: 0.08s; }
.svc-card:nth-child(9)  { animation-delay: 0.09s; }
.svc-card:nth-child(10) { animation-delay: 0.10s; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

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

@media (max-width: 700px) {
  .services-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .header-inner { height: 50px; padding: 0 16px; }
  .header-chip  { display: none; }
  .main         { padding: 14px 16px 48px; }
  .status-banner { padding: 18px 16px 16px; }
  .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: 13px; }
  .kpi-value    { font-size: 18px; }
  .ext-grid     { grid-template-columns: 1fr; }
  .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; }
}
