:root {
  --bg-app:       #f3f4f6;
  --bg-surface:   #ffffff;
  --bg-card:      #ffffff;
  /* Light surfaces only — panel headers and summary strips */
  --bg-card-2:    #f1f5f9;
  --bg-card-muted:#f8fafc;
  --bg-input:     #ffffff;
  --border:       #e5e7eb;
  --border-hi:    #d1d5db;
  --text-primary: #0f172a;
  --text-dim:     #1e293b;
  --text-muted:   #64748b;
  --ok:           #10b981;
  --ok-dim:       rgba(16,185,129,0.08);
  --ok-glow:      rgba(16,185,129,0.18);
  --warn:         #f59e0b;
  --warn-dim:     rgba(245,158,11,0.09);
  --warn-glow:    rgba(245,158,11,0.2);
  --bad:          #ef4444; /* Brief.pk Red */
  --bad-dim:      rgba(239,68,68,0.08);
  --bad-glow:     rgba(239,68,68,0.18);
  --accent:       #0f172a;
  --accent-dim:   rgba(15,23,42,0.05);
  --brand-red:    #ef4444;
  --brand-blue:   #2563eb;
  --mono-font:    "JetBrains Mono", monospace;
  --ui-font:      "Inter", system-ui, sans-serif;
  --brand-font:   "Playfair Display", serif;
  --r-sm:         6px;
  --r:            10px;
  --r-lg:         14px;
  --ease-out:     cubic-bezier(0.16,1,0.3,1);
  --shadow-sm:    0 1px 2px rgba(15,23,42,0.05), 0 2px 8px rgba(15,23,42,0.04);
  --shadow:       0 1px 3px rgba(15,23,42,0.06), 0 4px 16px rgba(15,23,42,0.05);
  --shadow-lg:    0 2px 6px rgba(15,23,42,0.06), 0 8px 32px rgba(15,23,42,0.07);
}

/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--ui-font);
  font-size: clamp(14px, 2.8vw, 15px);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* subtle dot grid — lighter on small screens */
  background-image: radial-gradient(rgba(15,23,42,0.045) 1px, transparent 1px);
  background-size: 28px 28px;
  background-attachment: fixed;
}

/* ── Chrome accent line ─────────────────────────────── */
.chrome-line {
  height: 3px;
  background: linear-gradient(90deg,
    var(--brand-red) 0%,
    var(--accent) 40%,
    #7c3aed 70%,
    var(--brand-red) 100%);
  background-size: 200% 100%;
  animation: shimmer 6s linear infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Topbar (mobile-first: stack, then row at sm+) ───── */
.brand-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.topbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
  padding: max(0.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.875rem max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border), var(--shadow-sm);
}
.main-logo {
  font-family: var(--brand-font);
  font-size: clamp(1.45rem, 7vw, 2rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.04em;
  line-height: 1;
}
.dot-pk {
  color: var(--brand-red);
}
h1 {
  margin: 0;
  font-family: var(--mono-font);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 600;
}
.brand-sub {
  display: none;
}
.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: .42rem;
  border: 1px solid rgba(5,150,105,0.28);
  border-radius: 999px;
  padding: .3rem .7rem .3rem .5rem;
  background: var(--ok-dim);
  font: 600 .68rem var(--mono-font);
  letter-spacing: .1em;
  color: var(--ok);
  white-space: nowrap;
}
.live-dot {
  position: relative;
  width: 7px;
  height: 7px;
  flex-shrink: 0;
}
.live-dot::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--ok);
  animation: core-pulse 2s ease-in-out infinite;
}
.live-dot::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 1.5px solid var(--ok);
  opacity: 0;
  animation: ring-pulse 2s ease-out infinite;
}
@keyframes core-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}
@keyframes ring-pulse {
  0%   { transform: scale(0.9); opacity: 0.5; }
  100% { transform: scale(2.2); opacity: 0; }
}

.top-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 1;
  min-width: min(100%, 12rem);
}
.ghost-btn {
  border: 1px solid var(--border-hi);
  background: var(--bg-surface);
  border-radius: var(--r-sm);
  padding: 0.62rem 1rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-dim);
  font: 500 0.8rem var(--mono-font);
  cursor: pointer;
  transition: border-color .2s, color .2s, background .2s, box-shadow .2s;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}
.ghost-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--accent-dim);
  box-shadow: none;
}

/* ── Incident Banner (GitHub Style) ────────────────── */
.incident-banner {
  padding: 1.5rem 1.4rem;
  background: var(--bad);
  color: #fff;
  font-family: var(--ui-font);
  transition: transform .3s var(--ease-out), opacity .3s;
}
.incident-banner.warn { background: var(--warn); }
.incident-banner.bad  { background: var(--bad); }
.incident-banner.hidden { display: none; }

.banner-content {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 max(0, env(safe-area-inset-left)) 0 max(0, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
}
.banner-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}
.banner-meta {
  font-size: 0.9rem;
  opacity: 0.9;
  flex: 1;
}
.banner-link {
  color: #fff;
  text-decoration: underline;
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* ── Layout Container ───────────────────────────────── */
.layout {
  max-width: 1040px;
  margin: 1.25rem auto 2rem;
  padding: 0 max(1rem, env(safe-area-inset-left)) 0 max(1rem, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Status Hero ────────────────────────────────────── */
.status-hero {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.75rem 1rem 2rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.status-hero .hero-status-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}
.status-orb {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  position: relative;
  transition: all .4s var(--ease-out);
}
.status-orb[data-state="operational"] { background: var(--ok); box-shadow: 0 0 0 8px var(--ok-dim), 0 0 25px var(--ok-glow); }
.status-orb[data-state="degraded"]    { background: var(--warn); box-shadow: 0 0 0 8px var(--warn-dim), 0 0 25px var(--warn-glow); }
.status-orb[data-state="outage"]      { background: var(--bad); box-shadow: 0 0 0 8px var(--bad-dim), 0 0 25px var(--bad-glow); }

/* breathing animation */
.status-orb::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0;
  animation: orb-breathe 3s infinite;
}
.status-orb[data-state="operational"]::after { color: var(--ok); }
.status-orb[data-state="degraded"]::after    { color: var(--warn); }
.status-orb[data-state="outage"]::after      { color: var(--bad); }

@keyframes orb-breathe {
  0%   { transform: scale(0.9); opacity: 0; }
  50%  { opacity: 0.3; }
  100% { transform: scale(1.3); opacity: 0; }
}

.status-hero h2 {
  margin: 0;
  font-family: var(--brand-font);
  font-size: clamp(1.35rem, 6.5vw, 2.8rem);
  letter-spacing: -0.04em;
  color: var(--text-primary);
  line-height: 1.12;
  padding: 0 0.25rem;
  word-break: break-word;
}
.status-hero .hero-meta {
  margin-top: 0.8rem;
  color: var(--text-muted);
  font: 500 clamp(0.75rem, 3vw, 0.95rem) var(--mono-font);
  line-height: 1.45;
}

/* ── Panel & Headings ──────────────────────────────── */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}
.panel-head {
  padding: 1rem 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-card-muted) 0%, var(--bg-card-2) 100%);
}
.panel-head h2 {
  margin: 0;
  font: 600 .75rem var(--mono-font);
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-primary);
}
.panel-head p {
  margin: 0.4rem 0 0;
  font-size: .85rem;
  color: var(--text-dim);
}

/* ── Unified Status Grid ────────────────────────────── */
.status-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  padding: 1rem;
}
.status-card {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 1rem 1rem 1.15rem;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: transform .2s var(--ease-out), box-shadow .2s;
}
@media (hover: hover) {
  .status-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
  }
}
.status-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.status-card-name {
  font-weight: 700;
  font-size: clamp(0.95rem, 3.5vw, 1.1rem);
  color: var(--text-primary);
  line-height: 1.25;
  padding-right: 0.35rem;
}
.status-card-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  font-weight: 800;
}
.status-card-icon.ok   { background: var(--ok); }
.status-card-icon.warn { background: var(--warn); }
.status-card-icon.bad  { background: var(--bad); }

.uptime-row {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.uptime-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.35rem 0.5rem;
  font: 600 0.65rem var(--mono-font);
  color: var(--text-muted);
}
.uptime-bars-mini {
  display: flex;
  gap: 2px;
  height: 32px;
}
.uptime-bars-mini span {
  flex: 1;
  border-radius: 1px;
  background: #f1f5f9;
  min-width: 2px;
}
.uptime-bars-mini span.ok   { background: #10b981; }
.uptime-bars-mini span.warn { background: #f59e0b; }
.uptime-bars-mini span.bad  { background: #ef4444; }

.status-card-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem 0.75rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.status-label {
  font: 700 0.7rem var(--mono-font);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.status-label.ok   { color: var(--ok); }
.status-label.warn { color: var(--warn); }
.status-label.bad  { color: var(--bad); }

.latency-meta {
  font: 500 0.7rem var(--mono-font);
  color: var(--text-muted);
  text-align: right;
  flex: 1 1 12rem;
  min-width: 0;
  word-break: break-word;
}

/* ── Split Layout & Components ───────────────────────── */
.split-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

/* AI Router & Pulse Styling */
.ai-router-summary, .user-pulse-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  background: var(--bg-card-muted);
  border-bottom: 1px solid var(--border);
}
.ai-pill {
  padding: 0.4rem 0.8rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ai-pill .k { font: 600 0.6rem var(--mono-font); color: var(--text-muted); text-transform: uppercase; }
.ai-pill .v { font: 700 0.8rem var(--ui-font); color: var(--text-primary); }

.ai-provider-grid, .user-pulse-grid {
  padding: 1rem;
  display: grid;
  gap: 0.75rem;
}

.ai-provider-card, .user-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #fff;
}
.ai-provider-top, .user-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}
.ai-provider-name, .user-title { font-weight: 700; color: var(--text-primary); }

/* Badges */
.badge {
  font: 700 0.65rem var(--mono-font);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  text-transform: uppercase;
}
.badge.ok   { background: var(--ok-dim); color: var(--ok); }
.badge.warn { background: var(--warn-dim); color: var(--warn); }
.badge.bad  { background: var(--bad-dim); color: var(--bad); }

.health-rail {
  height: 4px;
  background: #f1f5f9;
  border-radius: 2px;
  margin: 0.8rem 0;
  overflow: hidden;
}
.health-fill { height: 100%; transition: width 1s; }
.health-fill.ok   { background: var(--ok); }
.health-fill.warn { background: var(--warn); }
.health-fill.bad  { background: var(--bad); }

.journey-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.8rem;
}
.journey-steps span {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: var(--bg-card-2);
  border-radius: 4px;
  color: var(--text-dim);
}

/* ── Deep Dive ───────────────────────────────────────── */
.deep-controls {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
}
.deep-controls label { font: 700 0.75rem var(--mono-font); color: var(--text-muted); text-transform: uppercase; }
.deep-controls select {
  padding: 0.65rem 0.85rem;
  min-height: 44px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-hi);
  font: 600 0.9rem var(--ui-font);
  outline: none;
  width: 100%;
  max-width: 100%;
}

.deep-kpis {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  background: var(--border);
}
.deep-card {
  background: #fff;
  padding: 1rem 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.deep-card .k { font: 600 0.65rem var(--mono-font); color: var(--text-muted); text-transform: uppercase; }
.deep-card .v { font: 700 1.2rem var(--brand-font); color: var(--text-primary); }

.deep-chart-wrap { padding: 1rem 0.75rem 1.25rem; background: #fff; }
#latencySpark { width: 100%; height: min(160px, 40vw); min-height: 120px; display: block; }

/* ── Incidents & History ────────────────────────────── */
.incident-list { padding: 1.4rem; display: flex; flex-direction: column; gap: 1rem; }
.incident { padding: 1.2rem; border-radius: var(--r-sm); background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--border-hi); }
.incident h3 { margin: 0 0 0.5rem; font-size: 1rem; color: var(--text-primary); }
.incident p { margin: 0; font-size: 0.9rem; color: var(--text-dim); }
.incident .when { margin-top: 0.8rem; font: 500 0.7rem var(--mono-font); color: var(--text-muted); }

#historyTableWrap {
  padding: 1rem 0.75rem 1.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { text-align: left; padding: 0.8rem; font: 700 0.7rem var(--mono-font); color: var(--text-muted); text-transform: uppercase; border-bottom: 2px solid var(--border); }
td { padding: 1rem 0.8rem; border-bottom: 1px solid var(--border); color: var(--text-dim); }

/* ── Heatmap ────────────────────────────────────────── */
#heatmapWrap {
  padding: 0.75rem 0.5rem 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.heatmap table { width: auto; min-width: min(100%, 720px); }
.hm-service { font-weight: 700; padding-right: 2rem; white-space: nowrap; font-size: 0.8rem; }
.hm-box { display: block; width: 14px; height: 14px; border-radius: 2px; background: #f1f5f9; margin: 0 auto; }
.hm-box.ok   { background: var(--ok); }
.hm-box.warn { background: var(--warn); }
.hm-box.bad  { background: var(--bad); }

/* ── Footer ─────────────────────────────────────────── */
.footer {
  max-width: 1040px;
  margin: 0 auto;
  padding-top: 1.5rem;
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  font: 500 0.8rem var(--mono-font);
  color: var(--text-muted);
}
.footer a { color: var(--accent); text-decoration: none; font-weight: 600; }

.user-meta {
  font-size: clamp(0.78rem, 2.8vw, 0.88rem);
  color: var(--text-muted);
  line-height: 1.45;
  word-break: break-word;
}

.journey-steps span {
  word-break: break-word;
}

/* ── sm+: horizontal topbar, 2-col KPIs ──────────────── */
@media (min-width: 480px) {
  .deep-kpis { grid-template-columns: repeat(2, 1fr); }
  .banner-content {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
  }
}

/* ── md+: comfortable spacing, heatmap padding ───────── */
@media (min-width: 768px) {
  .layout {
    margin: 2rem auto 3rem;
    gap: 2rem;
    padding: 0 1.5rem;
  }
  .panel-head { padding: 1.2rem 1.4rem; }
  .status-hero { padding: 2.5rem 1.75rem 3rem; }
  .status-grid { gap: 1rem; padding: 1.25rem 1.4rem; }
  .status-card { padding: 1.35rem 1.4rem; }
  .deep-controls {
    flex-direction: row;
    align-items: center;
    padding: 1.25rem 1.4rem;
  }
  .deep-controls select {
    width: auto;
    min-width: 14rem;
    max-width: min(24rem, 100%);
  }
  .deep-chart-wrap { padding: 1.75rem 1.4rem 2rem; }
  #heatmapWrap { padding: 1.25rem 1rem 1.4rem; }
  .footer {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 2rem 1.5rem;
  }
}

/* ── lg+: two-column service grid & split AI/user ─────── */
@media (min-width: 900px) {
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.4rem;
    padding-top: max(1rem, env(safe-area-inset-top));
  }
  .topbar-right {
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 1rem;
    flex: 0 1 auto;
  }
  .top-actions {
    flex: 0 0 auto;
    min-width: 0;
  }
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .split-layout { grid-template-columns: 1fr 1fr; gap: 1.5rem; }
  .deep-kpis { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 479px) {
  .banner-link {
    width: 100%;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.4);
    padding: 0.55rem 0.75rem;
    border-radius: var(--r-sm);
    text-decoration: none;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chrome-line { animation: none; }
  .status-orb::after { animation: none; }
  .live-dot::before,
  .live-dot::after { animation: none; }
}
