@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap");

:root {
  --dh-font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --dh-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
  --dh-radius: 6px;

  --dh-topbar-bg: #004567;
  --dh-topbar-edge: #0a5a85;
  --dh-accent: #2ea3d8;
  --dh-accent-strong: #1c7fb0;

  --dh-bg: #0e1217;
  --dh-surface: #161c24;
  --dh-surface-raised: #1d242e;
  --dh-border: #283039;
  --dh-border-soft: #1f262e;
  --dh-text: #e6edf3;
  --dh-text-strong: #f3f7fa;
  --dh-text-muted: #8a96a3;
  --dh-ok: #3fb950;
  --dh-warn: #d8a32a;
  --dh-bad: #f0625d;

  --dh-cell-empty: #222b35;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--dh-bg);
  color: var(--dh-text);
  font-family: var(--dh-font);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 52px;
  padding: 0 1.25rem;
  background: var(--dh-topbar-bg);
  border-bottom: 1px solid var(--dh-topbar-edge);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  color: #fff;
  text-decoration: none;
}
.topbar-brand .brand-mark {
  display: inline-block;
  width: 0.55rem;
  height: 1.05rem;
  background: var(--dh-accent);
  border-radius: 2px;
  transform: translateY(2px);
}
.topbar-section {
  font-family: var(--dh-mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.7);
  padding-left: 1rem;
  border-left: 1px solid rgba(255, 255, 255, 0.22);
}
.topbar-conn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--dh-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.85);
}
.topbar-conn .conn-age { color: rgba(255, 255, 255, 0.55); }
.conn-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--dh-text-muted);
}
.conn-dot.live {
  background: var(--dh-ok);
  box-shadow: 0 0 6px rgba(63, 185, 80, 0.7);
  animation: pulse 2s ease-in-out infinite;
}
.conn-dot.down { background: var(--dh-bad); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

main {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 3vw, 2.5rem) 3rem;
  /* App-shell scroll: only main scrolls so the topbar and footer (grid rows)
     stay pinned to the viewport. min-height:0 lets the 1fr track shrink. */
  overflow-y: auto;
  min-height: 0;
}

section {
  margin-bottom: 1.25rem;
  padding: 1.1rem 1.25rem;
  background: var(--dh-surface);
  border: 1px solid var(--dh-border);
  border-radius: var(--dh-radius);
}

.banner {
  border-left: 4px solid var(--dh-warn);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  background: var(--dh-surface-raised);
  border-radius: 0 var(--dh-radius) var(--dh-radius) 0;
  font-size: 0.9rem;
}

.cluster-head {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 1.25rem;
  justify-content: space-between;
}
.gauge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  flex: 1 1 28rem;
}
.gauge {
  border: 1px solid var(--dh-border);
  border-radius: var(--dh-radius);
  padding: 0.7rem 0.9rem;
  background: var(--dh-surface-raised);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.gauge-label {
  font-size: 0.68rem;
  color: var(--dh-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.gauge-value {
  font-family: var(--dh-mono);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--dh-text-strong);
  line-height: 1.1;
}
.gauge-unit {
  font-family: var(--dh-mono);
  font-size: 0.7rem;
  color: var(--dh-text-muted);
  text-transform: uppercase;
}
.gauge-sep { color: var(--dh-text-muted); margin: 0 0.25rem; }
.gauge-queued { color: var(--dh-warn); }

.spark-wrap {
  flex: 1 1 18rem;
  min-width: 14rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border: 1px solid var(--dh-border);
  border-radius: var(--dh-radius);
  background: var(--dh-surface-raised);
  padding: 0.7rem 0.9rem;
}
.spark-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.spark-caption {
  font-size: 0.68rem;
  color: var(--dh-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.spark-legend {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.62rem;
  color: var(--dh-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.lg {
  display: inline-block;
  width: 0.75rem;
  height: 0.18rem;
  border-radius: 1px;
}
.lg-gpu { background: var(--dh-accent); }
.lg-wall { background: var(--dh-warn); margin-left: 0.45rem; }
.spark { position: relative; width: 100%; flex: 1 1 auto; min-height: 64px; max-height: 200px; }
/* Absolutely positioned so the SVG's rendered size never feeds back into the
   .spark box that ResizeObserver measures (which would loop on resize). */
.spark svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.grid-line { stroke: var(--dh-border); stroke-width: 0.5; }
.grid-line-v { stroke-dasharray: 2 2; }
.axis-line { stroke: var(--dh-border-soft); stroke-width: 0.9; }
.grid-label {
  fill: var(--dh-text-muted);
  font-family: var(--dh-mono);
  font-size: 8px;
}
.line-gpu { stroke: var(--dh-accent); stroke-width: 1.4; stroke-linejoin: round; }
.line-wall { stroke: var(--dh-warn); stroke-width: 1.4; stroke-linejoin: round; }

.lg-tx { background: var(--dh-accent); }
.lg-rx { background: var(--dh-warn); margin-left: 0.45rem; }
.line-tx { stroke: var(--dh-accent); stroke-width: 1.3; stroke-linejoin: round; }
.line-rx { stroke: var(--dh-warn); stroke-width: 1.3; stroke-linejoin: round; }
.dot-tx { fill: var(--dh-accent); }
.dot-rx { fill: var(--dh-warn); }

.empty {
  text-align: center;
  color: var(--dh-text-muted);
  font-family: var(--dh-mono);
  font-size: 0.9rem;
}

.node-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.node-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--dh-text-strong);
  font-family: var(--dh-mono);
}
.node-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  align-items: center;
}
.node-stat {
  font-size: 0.8rem;
  color: var(--dh-text-muted);
  font-family: var(--dh-mono);
}
.node-state {
  font-family: var(--dh-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.08rem 0.45rem;
  border-radius: 3px;
}
.state-idle { color: var(--dh-ok); background: rgba(63, 185, 80, 0.12); }
.state-busy { color: var(--dh-accent); background: rgba(46, 163, 216, 0.12); }
.state-down { color: var(--dh-bad); background: rgba(240, 98, 93, 0.14); }
.state-drained { color: var(--dh-warn); background: rgba(216, 163, 42, 0.14); }
.state-unknown { color: var(--dh-text-muted); background: rgba(255, 255, 255, 0.05); }

.no-metrics {
  font-family: var(--dh-mono);
  font-size: 0.85rem;
  color: var(--dh-warn);
  padding: 0.6rem 0.8rem;
  border: 1px dashed var(--dh-border);
  border-radius: var(--dh-radius);
  background: rgba(216, 163, 42, 0.06);
}

.banner.bad { border-left-color: var(--dh-bad); }
.banner.bad b, .banner.bad strong { color: var(--dh-bad); }
.banner-dot, .offline-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--dh-bad);
  box-shadow: 0 0 6px rgba(240, 98, 93, 0.7);
  animation: pulse 1.6s ease-in-out infinite;
  margin-right: 0.35rem;
  vertical-align: middle;
}

.node.down {
  border-color: var(--dh-bad);
  box-shadow: inset 3px 0 0 var(--dh-bad);
  background: linear-gradient(180deg, rgba(240, 98, 93, 0.06), var(--dh-surface));
}
.node-down-badge {
  font-family: var(--dh-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--dh-bad);
  background: rgba(240, 98, 93, 0.14);
  padding: 0.08rem 0.45rem;
  border-radius: 3px;
}
.node-stale-badge,
.node-maint-badge {
  font-family: var(--dh-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--dh-warn);
  background: rgba(216, 163, 42, 0.14);
  padding: 0.08rem 0.45rem;
  border-radius: 3px;
}
.node-offline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--dh-mono);
  font-size: 0.9rem;
  color: var(--dh-bad);
  padding: 1.1rem 1rem;
  border: 1px dashed var(--dh-bad);
  border-radius: var(--dh-radius);
  background: rgba(240, 98, 93, 0.06);
}

.gpu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.25rem, 1fr));
  gap: 0.6rem;
}

.gpu-cell {
  position: relative;
  height: 5rem;
  border: 1px solid var(--dh-border);
  border-radius: var(--dh-radius);
  background: var(--dh-cell-empty);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.gpu-cell.idle { opacity: 0.82; }
.gpu-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: var(--dh-radius);
}
.gpu-cell.allocated {
  border-color: var(--glow, var(--dh-accent));
  box-shadow: 0 0 0 1px var(--glow, var(--dh-accent)),
              0 0 12px -2px var(--glow, var(--dh-accent));
}

.gpu-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  opacity: 0.85;
  transition: height 0.6s cubic-bezier(0.22, 1, 0.36, 1),
              background 0.6s ease;
}

.gpu-body {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.4rem 0.5rem;
}
.gpu-model {
  font-family: var(--dh-mono);
  font-size: 0.64rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  line-height: 1.15;
}
.gpu-util {
  font-family: var(--dh-mono);
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  align-self: flex-end;
}

.gpu-tip {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: calc(100% + 0.4rem);
  transform: translateX(-50%);
  min-width: 11rem;
  display: none;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.7rem;
  background: #0b0f14;
  border: 1px solid var(--dh-border);
  border-radius: var(--dh-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 0.75rem;
  color: var(--dh-text);
}
.gpu-tip strong {
  font-family: var(--dh-mono);
  font-size: 0.72rem;
  color: var(--dh-accent);
  margin-bottom: 0.15rem;
}
.gpu-tip span { display: flex; justify-content: space-between; gap: 0.75rem; }
.gpu-tip b { font-family: var(--dh-mono); color: var(--dh-text-strong); }
.gpu-tip .tip-alloc {
  margin-top: 0.2rem;
  justify-content: center;
  font-family: var(--dh-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dh-accent);
}
.gpu-cell:hover { z-index: 5; }
.gpu-cell:hover .gpu-tip { display: flex; }

.node-body {
  display: flex;
  align-items: stretch;
  gap: 0.9rem;
}
.node-body .gpu-grid { flex: 1 1 auto; min-width: 0; }
.node-divider {
  flex: 0 0 1px;
  align-self: stretch;
  background: var(--dh-border);
}
.vitals {
  flex: 0 0 auto;
  display: flex;
  gap: 0.6rem;
}
.vital-cell {
  position: relative;
  width: 8.25rem;
  min-height: 5rem;
  border: 1px solid var(--dh-border);
  border-radius: var(--dh-radius);
  background: var(--dh-cell-empty);
  overflow: hidden;
}
.vital-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  opacity: 0.85;
  transition: height 0.6s cubic-bezier(0.22, 1, 0.36, 1), background 0.6s ease;
}
.vital-body {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.4rem 0.5rem;
}
.vital-label {
  font-family: var(--dh-mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}
.vital-val {
  font-family: var(--dh-mono);
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  align-self: flex-end;
}
.vital-sub {
  font-family: var(--dh-mono);
  font-size: 0.62rem;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  align-self: flex-end;
}

.status-footer {
  background: var(--dh-topbar-bg);
  border-top: 1px solid var(--dh-topbar-edge);
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.8rem;
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.status-footer a { color: #fff; }
