/* SteerSafe API status page: a one-screen live monitor in the brand's deep blue and cyan. */
:root {
  --bg: #050e22;
  --surface: rgba(16, 33, 70, 0.55);
  --surface-strong: #0c1b3d;
  --border: rgba(120, 160, 230, 0.16);
  --border-strong: rgba(18, 181, 240, 0.35);
  --text: #e8eefb;
  --muted: #8ea0c4;
  --faint: #5d6f96;
  --cyan: #12b5f0;
  --ok: #2fd18b;
  --warn: #f5b84b;
  --bad: #ff6b6b;
  --state: var(--faint);
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* The overall state colours the radar, the pill and the status text. */
body[data-state="ok"] { --state: var(--ok); }
body[data-state="degraded"] { --state: var(--warn); }
body[data-state="down"] { --state: var(--bad); }

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image:
    radial-gradient(60vw 50vh at 85% -10%, rgba(18, 181, 240, 0.14), transparent),
    linear-gradient(rgba(120, 160, 230, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 160, 230, 0.05) 1px, transparent 1px);
  background-size: auto, 48px 48px, 48px 48px;
  color: var(--text);
  font: 14px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }

/* Top bar */
.bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  height: 58px;
  flex: none;
  border-bottom: 1px solid var(--border);
  background: rgba(5, 14, 34, 0.82);
}
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; margin-inline-end: 6px; }
.brand img { height: 26px; width: auto; display: block; }
.brand-label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); white-space: nowrap; padding-inline-start: 12px; border-inline-start: 1px solid var(--border); }
.chip { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; white-space: nowrap; }
.chip.mono { text-transform: none; letter-spacing: 0; }
.bar-spacer { flex: 1; }
.clock { font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.clock::after { content: " UTC"; color: var(--faint); font-size: 11px; }

.pill { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; border-radius: 999px; padding: 6px 12px; border: 1px solid var(--border); background: var(--surface); white-space: nowrap; color: var(--state); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--state); flex: none; animation: pulse 2s infinite; }

/* Time to the next health check, draining along the bottom of the bar */
.next { position: absolute; inset: auto 0 -1px 0; height: 2px; }
.next span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, transparent, var(--cyan)); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--state) 60%, transparent); }
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* The platform's size, in the top bar */
.figures { display: flex; gap: 16px; margin-inline-start: 8px; font-size: 12px; color: var(--faint); white-space: nowrap; }
.figures b { color: var(--text); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; margin-inline-end: 2px; }

/* Grid of tiles: fills the screen on a desktop or a wall display. The small readings go along the top, the chart
   and the services take the full width under them, and the check log runs down the right side. */
.grid {
  flex: 1;
  display: grid;
  gap: 12px;
  padding: 12px;
  grid-template-columns: 1.3fr 1fr 1fr 1.05fr;
  grid-template-rows: minmax(140px, 0.62fr) minmax(200px, 1fr) minmax(190px, 1fr) auto;
  grid-template-areas:
    "status uptime db log"
    "latency latency routing log"
    "workers workers workers log"
    "flow flow flow log";
}
.status-tile { grid-area: status; }
.routing-tile { grid-area: routing; }
.latency-tile { grid-area: latency; }
.uptime-tile { grid-area: uptime; }
.db-tile { grid-area: db; }
.workers-tile { grid-area: workers; }
.flow-tile { grid-area: flow; }
.log-tile { grid-area: log; }

.tile {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 16px 18px;
  overflow: hidden;
}
.tile h2 { margin: 0 0 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.big { margin: 0; font-size: clamp(26px, 3vw, 40px); font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big small { font-size: 0.42em; color: var(--muted); font-weight: 500; margin-inline-start: 4px; }
.big.mono { font-weight: 600; letter-spacing: -0.03em; }
.big.ok { color: var(--ok); }
.big.warn { color: var(--warn); }
.big.bad { color: var(--bad); }
.sub { margin: 8px 0 0; color: var(--faint); font-size: 12px; }

/* Status: the radar beside the reading */
.status-tile { flex-direction: row; align-items: center; gap: 18px; }
.status-body { min-width: 0; }
.status-tile .big { font-size: clamp(24px, 2.3vw, 38px); }
.radar { position: relative; flex: none; width: clamp(96px, 8.5vw, 140px); aspect-ratio: 1; }
.radar > * { position: absolute; left: 50%; top: 50%; border-radius: 50%; translate: -50% -50%; }
.ring { border: 1px solid color-mix(in srgb, var(--state) 35%, transparent); }
.r1 { width: 100%; height: 100%; animation: ripple 3s ease-out infinite; }
.r2 { width: 66%; height: 66%; }
.r3 { width: 33%; height: 33%; }
.sweep {
  width: 100%;
  height: 100%;
  background: conic-gradient(from 0deg, transparent 0deg, transparent 290deg, color-mix(in srgb, var(--state) 55%, transparent) 360deg);
  -webkit-mask: radial-gradient(closest-side, #000 98%, transparent 100%);
  mask: radial-gradient(closest-side, #000 98%, transparent 100%);
  animation: spin 3s linear infinite;
}
.radar-mark { width: 22%; height: auto; border-radius: 0; filter: drop-shadow(0 0 14px rgba(18, 181, 240, 0.6)); }
.state-text { color: var(--state); }
body[data-state="down"] .sweep, body[data-state="checking"] .sweep { animation-duration: 8s; }

@keyframes spin { to { rotate: 360deg; } }
@keyframes ripple {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--state) 35%, transparent); }
  100% { box-shadow: 0 0 0 18px transparent; }
}

/* Response time chart, scrolling under the numbers */
.latency-tile .big { position: relative; z-index: 1; }
.stats { position: absolute; top: 14px; right: 18px; z-index: 1; display: flex; gap: 16px; margin: 0; font-size: 12px; }
.stats div { text-align: right; }
.stats dt { color: var(--faint); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }
.stats dd { margin: 0; color: var(--text); font-variant-numeric: tabular-nums; }
.chart { position: absolute; inset: auto 0 0 0; width: 100%; height: 68%; }
.chart-grid line { stroke: rgba(120, 160, 230, 0.08); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-head {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: #7fdcff;
  box-shadow: 0 0 0 4px rgba(18, 181, 240, 0.25), 0 0 16px rgba(18, 181, 240, 0.9);
  opacity: 0;
}

/* Uptime */
.minute { display: block; height: 3px; margin-top: 12px; border-radius: 3px; background: rgba(120, 160, 230, 0.12); overflow: hidden; }
.minute span { display: block; height: 100%; width: 0; background: var(--cyan); border-radius: 3px; }
.uptime-tile .big { margin-top: auto; font-size: clamp(24px, 2.6vw, 38px); }
.uptime-tile .sub { margin-bottom: auto; }

/* Database link */
.db-tile .big { margin-top: auto; }
.link { display: flex; align-items: center; gap: 10px; margin: 14px 0 auto; }
.end { flex: none; font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--cyan); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; background: var(--surface-strong); }
.wire { position: relative; flex: 1; height: 2px; background: rgba(120, 160, 230, 0.18); border-radius: 2px; }
.wire i, .wire b { position: absolute; top: -2px; width: 6px; height: 6px; border-radius: 50%; }
.wire i { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); animation: out 1.8s linear infinite; }
.wire b { background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: back 1.8s linear infinite; }
.wire i:nth-child(2) { animation-delay: -0.6s; }
.wire i:nth-child(3) { animation-delay: -1.2s; }
.wire b:nth-child(5) { animation-delay: -0.9s; }
.db-down .wire { background: rgba(255, 107, 107, 0.4); }
.db-down .wire i, .db-down .wire b { display: none; }

@keyframes out { from { left: 0; } to { left: calc(100% - 6px); } }
@keyframes back { from { left: calc(100% - 6px); } to { left: 0; } }

/* Road distances and times: the provider, then a meter per daily cap and the fallback estimate. The marks are where
   background work (60%) and operations (85%) stop calling the provider; the fill turns amber and red as it passes them. */
.routing-tile .big { font-size: clamp(24px, 2.3vw, 34px); }
.routing-tile .sub { margin-top: 4px; }
.meters { display: grid; gap: 12px; margin-top: auto; padding-top: 12px; }
.meter-note { margin: 0; font-size: 11px; line-height: 1.4; color: var(--faint); }
.meter-note:empty { display: none; }
.meter-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.meter-text { color: var(--text); font-variant-numeric: tabular-nums; }
.meter-track { position: relative; display: block; height: 6px; border-radius: 6px; background: rgba(120, 160, 230, 0.12); }
.meter-fill { display: block; height: 100%; width: 0; border-radius: 6px; background: var(--cyan); box-shadow: 0 0 10px rgba(18, 181, 240, 0.6); transition: width 0.6s ease, background-color 0.3s; }
.meter[data-level="warn"] .meter-fill { background: var(--warn); box-shadow: 0 0 10px color-mix(in srgb, var(--warn) 60%, transparent); }
.meter[data-level="bad"] .meter-fill { background: var(--bad); box-shadow: 0 0 10px color-mix(in srgb, var(--bad) 60%, transparent); }
.meter[data-level="none"] .meter-track { opacity: 0.4; }
.meter[data-level="learned"] .meter-fill { background: var(--ok); box-shadow: 0 0 10px color-mix(in srgb, var(--ok) 60%, transparent); }
.meter-track i { position: absolute; top: -3px; bottom: -3px; width: 1px; background: rgba(232, 238, 251, 0.35); }
.meter-track .mark-60 { left: 60%; }
.meter-track .mark-85 { left: 85%; }
/* No routing service: nothing to count. */
.routing-tile[data-provider="none"] .meters { display: none; }

/* Background services: a moving heartbeat line per running service; stopped and switched-off ones are red */
.tile h2 .summary { float: right; letter-spacing: 0; text-transform: none; color: var(--ok); }
.tile h2 .summary.warn { color: var(--warn); }
.tile h2 .summary.bad { color: var(--bad); }
.workers { flex: 1; list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); align-content: space-evenly; gap: 6px 26px; }
.worker { --state: var(--ok); display: grid; grid-template-columns: auto max-content minmax(24px, 1fr) 62px; align-items: center; gap: 10px; padding: 3px 8px; margin: 0 -8px; border-radius: 8px; }
.worker[data-state="starting"] { --state: var(--warn); }
.worker[data-state="stalled"], .worker[data-state="off"] { --state: var(--bad); background: rgba(255, 107, 107, 0.08); }
.worker[data-state="off"] .worker-name { color: var(--muted); }
.worker[data-state="stalled"] .dot { animation: blink 1s steps(2, jump-none) infinite; }
.worker[data-state="off"] .dot { animation: none; opacity: 0.7; }
.worker-name { font-weight: 600; font-size: 13px; white-space: nowrap; }
.worker-beat { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.worker:not([data-state="running"]) .worker-beat { color: var(--state); font-weight: 600; }
.worker.idle { display: block; grid-column: 1 / -1; color: var(--faint); }
.ecg { height: 22px; overflow: hidden; position: relative; -webkit-mask: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent); mask: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent); }
.ecg svg { position: absolute; inset: 0 auto 0 0; width: 200%; height: 100%; animation: scroll 2s linear infinite; }
.ecg path { fill: none; stroke: var(--state); stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; filter: drop-shadow(0 0 4px color-mix(in srgb, var(--state) 60%, transparent)); }
.worker[data-state="starting"] .ecg svg { animation-duration: 5s; }
/* No heartbeat: a flat line, dashed when the service is switched off */
.worker[data-state="stalled"] .ecg svg, .worker[data-state="off"] .ecg svg { display: none; }
.worker[data-state="stalled"] .ecg { background: linear-gradient(var(--bad), var(--bad)) center / 100% 1.5px no-repeat; }
.worker[data-state="off"] .ecg { background: repeating-linear-gradient(90deg, rgba(255, 107, 107, 0.55) 0 5px, transparent 5px 9px) center / 100% 1.5px no-repeat; }

@keyframes blink { 50% { opacity: 0.25; } }

@keyframes scroll { to { translate: -50% 0; } }

/* Ride flow: a slim strip, the title beside the pipeline */
.flow-tile { flex-direction: row; align-items: center; gap: 24px; padding-block: 12px; }
.flow-tile h2 { margin: 0; flex: none; }
.flow { --cycle: 6s; flex: 1; padding-top: 9px; }
.flow-track { position: relative; height: 2px; margin: 0 10%; background: rgba(120, 160, 230, 0.18); border-radius: 2px; }
.flow-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, rgba(18, 181, 240, 0), var(--cyan)); border-radius: 2px; animation: fill var(--cycle) linear infinite; }
.packet { position: absolute; top: 50%; left: 0; width: 46px; height: 4px; margin-top: -2px; border-radius: 4px; background: linear-gradient(90deg, rgba(18, 181, 240, 0), #7fdcff); box-shadow: 0 0 12px rgba(18, 181, 240, 0.9); opacity: 0; animation: travel var(--cycle) linear infinite; }
.packet:nth-child(3) { animation-delay: calc(var(--cycle) / -3); }
.packet:nth-child(4) { animation-delay: calc(var(--cycle) * -2 / 3); }
.flow-stages { list-style: none; margin: -9px 0 0; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); }
.flow-stages li { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.node { position: relative; width: 16px; height: 16px; border-radius: 50%; background: var(--surface-strong); border: 2px solid rgba(18, 181, 240, 0.45); animation: light var(--cycle) ease-in-out infinite; }
.node::after { content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--cyan); opacity: 0; animation: node-ripple var(--cycle) ease-out infinite; }
.flow-stages li:nth-child(2) .node, .flow-stages li:nth-child(2) .node::after { animation-delay: calc(var(--cycle) * 0.2); }
.flow-stages li:nth-child(3) .node, .flow-stages li:nth-child(3) .node::after { animation-delay: calc(var(--cycle) * 0.4); }
.flow-stages li:nth-child(4) .node, .flow-stages li:nth-child(4) .node::after { animation-delay: calc(var(--cycle) * 0.6); }
.flow-stages li:nth-child(5) .node, .flow-stages li:nth-child(5) .node::after { animation-delay: calc(var(--cycle) * 0.8); }

@keyframes travel { 0% { left: -6%; opacity: 0; } 8% { opacity: 1; } 92% { opacity: 1; } 100% { left: 100%; opacity: 0; } }
@keyframes fill { 0% { width: 0; opacity: 1; } 80% { width: 100%; opacity: 1; } 100% { width: 100%; opacity: 0; } }
@keyframes light {
  0%, 100% { background: var(--surface-strong); border-color: rgba(18, 181, 240, 0.45); box-shadow: none; }
  6% { background: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 18px rgba(18, 181, 240, 0.8); }
  22% { background: var(--surface-strong); border-color: rgba(18, 181, 240, 0.45); box-shadow: none; }
}
@keyframes node-ripple { 0% { transform: scale(1); opacity: 0.9; } 20% { transform: scale(2.6); opacity: 0; } 100% { transform: scale(2.6); opacity: 0; } }

/* Check log: each check slides in at the top. Placed absolutely so a long log fills its column without stretching
   the rows. */
.log { position: absolute; inset: 42px 18px 0; overflow: hidden; list-style: none; margin: 0; padding: 0; display: grid; align-content: start; gap: 4px; font-size: 12.5px; -webkit-mask: linear-gradient(180deg, #000 75%, transparent); mask: linear-gradient(180deg, #000 75%, transparent); }
.log li { display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center; padding: 5px 10px; border-radius: 8px; background: rgba(5, 14, 34, 0.45); animation: slide-in 0.5s ease-out; }
.log li:first-child { background: rgba(18, 181, 240, 0.12); }
.log .dot { animation: none; }
.log .ok { --state: var(--ok); }
.log .degraded { --state: var(--warn); }
.log .down { --state: var(--bad); }
.log time { color: var(--muted); }
.log .ms { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.log .word { color: var(--state); min-width: 80px; text-align: right; }

@keyframes slide-in { from { opacity: 0; translate: 0 -100%; } to { opacity: 1; translate: 0 0; } }

@media (max-width: 1280px) {
  .figures { display: none; }
}

/* Tablets: two columns, scrolling */
@media (max-width: 1100px) {
  .grid {
    grid-template-columns: 1fr 1fr;
    /* Only the check log grows to fill what is left of the screen. */
    grid-template-rows: auto auto 240px auto auto auto minmax(300px, 1fr);
    grid-template-areas:
      "status status"
      "uptime db"
      "latency latency"
      "routing routing"
      "workers workers"
      "flow flow"
      "log log";
  }
}

/* Phones: one column */
@media (max-width: 680px) {
  .bar { gap: 8px; padding: 0 16px; }
  .brand-label, .chip { display: none; }
  .clock { font-size: 13px; }
  .grid {
    padding: 12px 16px;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 220px auto auto auto minmax(300px, 1fr);
    grid-template-areas: "status" "uptime" "db" "latency" "routing" "workers" "flow" "log";
  }
  .workers { grid-template-columns: 1fr; }
  .worker { grid-template-columns: auto 1fr 62px; }
  .ecg { display: none; }
  .flow-tile { flex-direction: column; align-items: stretch; gap: 8px; }
  .flow-stages li { font-size: 10.5px; }
}

/* Narrow phones: the logo and the status pill fill the bar; the check log shows the time. */
@media (max-width: 480px) {
  .brand img { height: 22px; }
  .clock { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .packet, .wire i, .wire b { display: none; }
  .flow-fill { width: 100%; }
}
