/* Novus Drift — the operations dashboard. Dark, dense, quiet until something is wrong. */

:root {
  color-scheme: dark;
  --page: #080b10;
  --surface-1: #0f141b;
  --surface-2: #151c26;
  --surface-3: #1b2431;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --grid: rgba(255, 255, 255, 0.06);
  --axis: rgba(255, 255, 255, 0.16);
  --crosshair: rgba(255, 255, 255, 0.35);
  --gauge-track: rgba(255, 255, 255, 0.08);
  --text-primary: #eef2f7;
  --text-secondary: #aab4c3;
  --text-muted: #6f7b8b;
  --accent: #3987e5;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e5484d;
  /* Series colours follow the entity, never the row. */
  --s-mcp: #3987e5;
  --s-mt: #d95926;
  --s-caddy: #199e70;
  --s-postgres: #c98500;
  --s-umami: #d55181;
  --s-monitor: #9085e9;
  --s-proxy: #e66767;
  --s-other: #7d8794;
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(ellipse 80% 40% at 50% -10%, rgba(57, 135, 229, 0.16), transparent 60%),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size:
    100% 100%,
    48px 48px,
    48px 48px;
  min-height: 100vh;
}

a {
  color: var(--accent);
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

/* ---- header ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: rgba(8, 11, 16, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand .mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3987e5, #7fb4f5);
  box-shadow: 0 0 18px rgba(57, 135, 229, 0.5);
  display: grid;
  place-items: center;
  color: #06101c;
  font-family: var(--font-mono);
  font-size: 13px;
}

.brand small {
  color: var(--text-muted);
  font-weight: 500;
}

.overall {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-weight: 600;
  font-size: 13px;
}

.overall[data-state='critical'] {
  border-color: rgba(229, 72, 77, 0.6);
  background: rgba(229, 72, 77, 0.12);
}

.overall[data-state='warning'] {
  border-color: rgba(250, 178, 25, 0.5);
  background: rgba(250, 178, 25, 0.1);
}

.spacer {
  flex: 1;
}

.range {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-1);
}

.range button {
  background: transparent;
  border: 0;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
}

.range button[aria-pressed='true'] {
  background: var(--surface-3);
  color: var(--text-primary);
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.live[data-on='true'] {
  color: var(--text-secondary);
}

.clock {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
}

.ghost:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.25);
}

/* ---- status dots ---- */

.dot {
  position: relative;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex: none;
}

.dot[data-state='ok'] {
  background: var(--good);
  box-shadow: 0 0 10px rgba(12, 163, 12, 0.7);
}

.dot[data-state='warning'] {
  background: var(--warning);
  box-shadow: 0 0 10px rgba(250, 178, 25, 0.7);
}

.dot[data-state='critical'] {
  background: var(--critical);
  box-shadow: 0 0 10px rgba(229, 72, 77, 0.8);
}

.dot[data-state='ok']::after,
.dot[data-state='critical']::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  color: inherit;
  opacity: 0;
  animation: pulse 2.4s ease-out infinite;
}

.dot[data-state='ok']::after {
  color: var(--good);
}

.dot[data-state='critical']::after {
  color: var(--critical);
  animation-duration: 1.2s;
}

@keyframes pulse {
  0% {
    transform: scale(0.6);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

/* ---- layout ---- */

main {
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  gap: 20px;
}

section > h2 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

section > h2::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.grid-charts {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 60%), var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
  animation: rise 0.5s ease-out both;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card h3 .sub {
  font-weight: 500;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---- status tiles ---- */

.tile {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto;
  gap: 4px 10px;
  align-items: start;
}

.tile[data-state='critical'] {
  border-color: rgba(229, 72, 77, 0.5);
  box-shadow: inset 0 0 0 1px rgba(229, 72, 77, 0.2);
}

.tile[data-state='warning'] {
  border-color: rgba(250, 178, 25, 0.45);
}

.tile .name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tile .value {
  grid-column: 1 / -1;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.tile .value.critical {
  color: var(--critical);
}

.tile .value.warning {
  color: var(--warning);
}

.tile .meta {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
}

.tile .meta span {
  white-space: nowrap;
}

.tile canvas.spark {
  grid-column: 1 / -1;
  width: 100%;
  height: 30px;
  display: block;
  margin-top: 4px;
}

.checks {
  grid-column: 1 / -1;
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.checks span {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-3);
}

.checks span[data-ok='true'] {
  background: var(--good);
}

.checks span[data-ok='false'] {
  background: var(--critical);
}

/* ---- gauges ---- */

.gauge-card {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: center;
}

.gauge-wrap {
  position: relative;
  width: 96px;
  height: 96px;
}

.gauge-wrap canvas {
  width: 96px;
  height: 96px;
  display: block;
}

.gauge-wrap .gauge-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.gauge-card .label {
  color: var(--text-secondary);
  font-weight: 600;
}

.gauge-card .detail {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  margin-top: 4px;
}

/* ---- charts ---- */

.chart-card {
  display: flex;
  flex-direction: column;
}

/* A fixed height, so the canvas sizing itself to the box can never grow the box. */
.chart {
  position: relative;
  height: 220px;
  display: flex;
  flex-direction: column;
}

.chart-canvas {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  cursor: crosshair;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  padding: 6px 0 0 46px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.chart-legend:empty {
  display: none;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
}

.swatch-line {
  width: 14px;
  height: 2px;
  border-radius: 1px;
}

.swatch-rect {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: rgba(15, 20, 27, 0.96);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  min-width: 140px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.chart-tooltip-time {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  margin-bottom: 4px;
}

.chart-tooltip-row {
  display: grid;
  grid-template-columns: 12px auto 1fr;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}

.chart-tooltip-row strong {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.chart-tooltip-key {
  width: 12px;
  height: 2px;
  border-radius: 1px;
}

.chart-tooltip-name {
  color: var(--text-secondary);
}

/* ---- tables ---- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: 0;
}

td.num,
th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

td canvas.spark {
  width: 110px;
  height: 24px;
  display: block;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-secondary);
}

.pill[data-state='ok'] {
  color: #5fd35f;
  background: rgba(12, 163, 12, 0.14);
}

.pill[data-state='warning'] {
  color: var(--warning);
  background: rgba(250, 178, 25, 0.14);
}

.pill[data-state='critical'] {
  color: #ff7b7f;
  background: rgba(229, 72, 77, 0.16);
}

.swatch-cell {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 8px;
  vertical-align: middle;
}

/* ---- errors ---- */

.error-list {
  display: grid;
  gap: 8px;
}

.error-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
}

.error-item:hover {
  border-color: var(--border-strong);
}

.error-item .count {
  font-family: var(--font-mono);
  font-weight: 650;
  font-size: 15px;
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.error-item .msg {
  font-family: var(--font-mono);
  font-size: 12.5px;
  word-break: break-word;
}

.error-item .where {
  color: var(--text-muted);
  font-size: 11.5px;
  margin-top: 3px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.error-item .when {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}

.error-item pre {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--page);
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow: auto;
}

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

/* ---- logs ---- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.toolbar select,
.toolbar input {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

.toolbar input {
  min-width: 200px;
  flex: 1;
}

.terminal {
  background: #05080c;
  border: 1px solid var(--border);
  border-radius: 10px;
  height: 460px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  padding: 8px 0;
}

.line {
  display: grid;
  grid-template-columns: 78px 92px 48px 1fr;
  gap: 10px;
  padding: 1px 12px;
  animation: slide 0.25s ease-out both;
  white-space: pre-wrap;
  word-break: break-word;
}

.line:hover {
  background: rgba(255, 255, 255, 0.04);
}

@keyframes slide {
  from {
    opacity: 0;
    transform: translateX(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.line .t {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.line .svc {
  font-weight: 600;
}

.line .lvl {
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  align-self: center;
}

.line[data-level='debug'] {
  color: var(--text-muted);
}

.line[data-level='info'] .lvl {
  color: var(--text-muted);
}

.line[data-level='warn'] .lvl {
  color: var(--warning);
}

.line[data-level='error'] {
  background: rgba(229, 72, 77, 0.08);
}

.line[data-level='error'] .lvl {
  color: var(--critical);
}

.line .extra {
  color: var(--text-muted);
}

/* ---- alerts ---- */

.alert-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.alert-row:last-child {
  border-bottom: 0;
}

.alert-row .title {
  font-weight: 600;
}

.alert-row .detail {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
  white-space: pre-wrap;
}

.alert-row .when {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
}

.firing {
  display: grid;
  gap: 8px;
}

.firing-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(229, 72, 77, 0.45);
  background: rgba(229, 72, 77, 0.1);
}

.firing-item[data-severity='warning'] {
  border-color: rgba(250, 178, 25, 0.45);
  background: rgba(250, 178, 25, 0.08);
}

.firing-item .since {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.jobs {
  display: grid;
  gap: 10px;
}

.job {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-2);
}

.job .unit {
  font-family: var(--font-mono);
  font-size: 12px;
}

.job .when {
  grid-column: 2;
  color: var(--text-muted);
  font-size: 11.5px;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 12.5px;
}

.kv dt {
  color: var(--text-muted);
}

.kv dd {
  margin: 0;
  font-family: var(--font-mono);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: grid;
  gap: 8px;
}

.toast div {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: rise 0.3s ease-out both;
  max-width: 360px;
}

.toast div[data-severity='critical'] {
  border-left-color: var(--critical);
}

.toast div[data-severity='warning'] {
  border-left-color: var(--warning);
}

.toast div[data-severity='ok'] {
  border-left-color: var(--good);
}

footer {
  padding: 10px 20px 30px;
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-mono);
  text-align: center;
}

/* ---- login ---- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login form {
  width: min(360px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 28px;
  display: grid;
  gap: 14px;
}

.login h1 {
  margin: 0;
  font-size: 18px;
}

.login p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.login input {
  background: var(--page);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}

.login button {
  background: var(--accent);
  color: #06101c;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  font-weight: 650;
  cursor: pointer;
}

.login .refused {
  color: var(--critical);
  font-size: 13px;
  display: none;
}

.login[data-refused='true'] .refused {
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 640px) {
  main {
    padding: 12px;
  }
  .topbar {
    flex-wrap: wrap;
    gap: 8px 12px;
  }
  .clock,
  .live {
    display: none;
  }
  .line {
    grid-template-columns: 62px 1fr;
  }
  .line .svc,
  .line .lvl {
    display: none;
  }
  .grid-charts {
    grid-template-columns: 1fr;
  }
}

.span-all {
  grid-column: 1 / -1;
}

.card h3.mt {
  margin-top: 16px;
}
