:root {
  --bg: #080D1A;
  --surface: #101B31;
  --surface-2: #16233F;
  --border: #223154;
  --text: #E8EDF7;
  --text-secondary: #8C9AB8;
  --text-tertiary: #5A6785;
  --accent: #3B82F6;
  --accent-bright: #60A5FA;
  --cyan: #22D3EE;
  --purple: #A78BFA;
  --orange: #FB923C;
  --green: #22C55E;
  --red: #EF4444;
  --font-sans: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ---------------------------------------------------------------- hero */

.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #0B1730 0%, #0A1428 55%, #081022 100%);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  flex-wrap: wrap;
}
.hero-mountains { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.hero-left, .hero-right { position: relative; z-index: 1; display: flex; align-items: center; gap: 18px; }
.hero-logo { height: 40px; width: auto; display: block; filter: drop-shadow(0 2px 10px rgba(59,130,246,0.45)); }
.hero-divider { width: 1px; height: 40px; background: linear-gradient(to bottom, transparent, var(--border) 20%, var(--border) 80%, transparent); }
.hero-title .ht1 { font-size: 22px; font-weight: 800; letter-spacing: 0.06em; color: var(--text); }
.hero-title .ht2 { font-size: 10.5px; font-weight: 600; letter-spacing: 0.14em; color: var(--text-secondary); margin-top: 2px; }
.hero-clock { text-align: right; }
.clock-time { font-family: var(--font-mono); font-size: 20px; font-weight: 600; color: var(--text); }
.clock-date { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }
.hero-status { display: flex; align-items: center; gap: 9px; }
.status-title { font-size: 13px; font-weight: 600; color: var(--green); }
.status-sub { font-size: 11px; color: var(--text-tertiary); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-tertiary); display: inline-block; box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
.status-dot.ok { background: var(--green); animation: pulse-ring 2s infinite; }
.status-dot.err { background: var(--red); }

/* narrow screens: pin the clock + status to the top-right corner */
@media (max-width: 760px) {
  .hero { flex-wrap: nowrap; padding-right: 130px; align-items: flex-start; }
  .hero-right {
    position: absolute; top: 14px; right: 16px; z-index: 2;
    flex-direction: column; align-items: flex-end; gap: 6px;
  }
  .hero-clock { text-align: right; }
  .clock-time { font-size: 17px; }
  .hero-status { align-items: flex-start; }
  .hero-status > div { text-align: right; }
}

@media (max-width: 480px) {
  .hero { padding: 16px 18px; padding-right: 116px; }
  .hero-left { gap: 12px; }
  .hero-divider { display: none; }
  .hero-title .ht1 { font-size: 16px; white-space: nowrap; }
  .hero-title .ht2 { display: none; }
  .hero-status .status-sub { display: none; }
  .clock-date { display: none; }
}

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

/* ------------------------------------------------------------- toolbar */

.toolbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.toolbar-left { display: flex; align-items: center; gap: 12px; }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px; background: rgba(34,197,94,0.12); color: var(--green);
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; padding: 4px 10px; border-radius: 999px;
}
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: pulse-ring 1.6s infinite; }
.toolbar-label { font-size: 12px; color: var(--text-tertiary); }
.interval-select {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 12px; font-family: var(--font-mono); cursor: pointer;
}
.next-update { font-size: 11px; color: var(--text-tertiary); font-family: var(--font-mono); min-width: 70px; }
.toolbar-right { display: flex; align-items: center; gap: 10px; }

.btn-primary {
  background: var(--accent); color: #fff; border: none; padding: 8px 18px;
  border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: var(--font-sans);
}
.btn-primary:active { opacity: 0.85; }
.btn-icon {
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; padding: 7px; border-radius: 7px;
}
.btn-icon:hover { color: var(--text); border-color: var(--accent); }

.btn-tv {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--accent); background: rgba(59,130,246,0.12); color: var(--accent);
  padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 600;
  text-decoration: none; cursor: pointer; font-family: var(--font-sans);
}
.btn-tv:hover { background: var(--accent); color: #fff; }

/* ---------------------------------------------------------------- body */

.body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 210px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px; padding: 16px 12px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px;
  border: none; background: transparent; color: var(--text-secondary); font-size: 13.5px; font-weight: 500;
  cursor: pointer; text-align: left; font-family: var(--font-sans);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(59,130,246,0.14); color: var(--accent); }

.content { flex: 1; padding: 20px 24px 48px; overflow-y: auto; }

.error-banner {
  background: rgba(239,68,68,0.12); border: 1px solid var(--red); color: #FCA5A5;
  padding: 12px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}

.insights { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.insight-row {
  display: flex; align-items: flex-start; gap: 10px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
}
.insight-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.insight-row.warn .insight-dot { background: var(--orange); }
.insight-row.info .insight-dot { background: var(--cyan); }
.insight-row.ok .insight-dot { background: var(--green); }

/* ----------------------------------------------------------------- grid */

.grid { display: grid; grid-template-columns: repeat(12, minmax(0,1fr)); gap: 14px; margin-bottom: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--text); }
.card-sub { font-size: 11px; color: var(--text-tertiary); font-family: var(--font-mono); }

.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* ------------------------------------------------------------- kpi/donut */

.kpi-big { font-family: var(--font-mono); font-size: 34px; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.kpi-big .unit { font-size: 15px; font-weight: 500; color: var(--text-tertiary); }

/* glowing donuts & rings */
.glow-svg { filter: drop-shadow(0 0 5px rgba(96,165,250,0.35)); }

/* big colored icon chips */
.icon-box {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-box svg { width: 22px; height: 22px; }
.kpi-delta { font-size: 12px; margin-top: 6px; }
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }
.kpi-delta.flat { color: var(--text-tertiary); }

.donut-row { display: flex; align-items: center; gap: 14px; }
.donut-legend { display: flex; flex-direction: column; gap: 7px; font-size: 11.5px; flex: 1; min-width: 0; }
.legend-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.legend-label { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.legend-val { font-family: var(--font-mono); color: var(--text); flex-shrink: 0; }

.ring-row { display: flex; justify-content: space-around; align-items: center; gap: 8px; }
.ring-item { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ring-item span.label { font-size: 10px; color: var(--text-tertiary); text-align: center; }

/* --------------------------------------------------------- cluster card */

.cluster-card { position: relative; overflow: hidden; padding: 0; display: flex; flex-direction: column; }
.cluster-illustration { position: relative; height: 150px; overflow: hidden; }
.cluster-photo {
  background: linear-gradient(180deg, rgba(8,13,26,0.15) 0%, rgba(8,13,26,0.05) 45%, rgba(16,27,49,0.9) 100%),
              url('/assets/datacenter.webp');
  background-size: cover;
  background-position: center;
}
.cluster-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border-top: 1px solid var(--border);
}
.cluster-stat { padding: 12px 10px; text-align: center; border-right: 1px solid var(--border); }
.cluster-stat:last-child { border-right: none; }
.cluster-stat .cs-val { font-family: var(--font-mono); font-size: 17px; font-weight: 700; color: var(--text); }
.cluster-stat .cs-val.ok { color: var(--green); }
.cluster-stat .cs-label { font-size: 10px; color: var(--text-tertiary); margin-top: 2px; }
.cluster-title-overlay {
  position: absolute; top: 12px; left: 16px; font-size: 13px; font-weight: 600; color: var(--text); z-index: 2;
}

/* ------------------------------------------------------------- gpu fleet */

.fleet-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
.fleet-tile {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 9px 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.fleet-tile.serving { border-color: var(--accent); }
.fleet-tile.idle { opacity: 0.55; }
.fleet-head { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 600; color: var(--text); }
.fleet-meta { font-size: 10.5px; font-family: var(--font-mono); color: var(--text-secondary); }
.fleet-bar-track { width: 100%; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.fleet-bar-fill { height: 100%; border-radius: 2px; }
.fleet-pct { font-size: 10.5px; font-family: var(--font-mono); }

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

.gauge-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.gauge-row:last-child { margin-bottom: 0; }
.gauge-label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.gauge-label .g-val { margin-left: auto; font-family: var(--font-mono); color: var(--text); }
.gauge-track { width: 100%; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }

.gauge-block { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.gauge-block:last-child { margin-bottom: 0; }
.gauge-block .gauge-body { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.gauge-block .gauge-label { font-size: 13px; }
.gauge-block .g-val { font-size: 13px; }

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

.resource-tiles { display: flex; flex-direction: column; gap: 9px; }
.resource-tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; display: flex; align-items: center; gap: 12px; }
.resource-tile .rt-val { font-family: var(--font-mono); font-size: 17px; font-weight: 700; color: var(--text); white-space: nowrap; }
.resource-tile .rt-label { font-size: 10.5px; color: var(--text-tertiary); margin-top: 2px; }

.services-list { display: flex; flex-direction: column; gap: 9px; }
.service-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.service-name { display: flex; align-items: center; gap: 8px; color: var(--text); }
.service-name .sd { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.service-badge { font-size: 10.5px; font-weight: 600; color: var(--green); background: rgba(34,197,94,0.12); padding: 3px 9px; border-radius: 999px; }
.service-badge.bad { color: var(--red); background: rgba(239,68,68,0.12); }

/* ---------------------------------------------------------- sections */

.section-header { margin-bottom: 18px; }
.section-header .sh-title { font-size: 20px; font-weight: 700; color: var(--text); }
.section-header .sh-sub { font-size: 12.5px; color: var(--text-tertiary); margin-top: 2px; }

.mono { font-family: var(--font-mono); }
.num { text-align: right; }
.dim-text { color: var(--text-tertiary); }
.warn-text { color: var(--orange); }
.card.dim { opacity: 0.6; }

.gpu-detail { display: flex; flex-direction: column; gap: 7px; }
.gpu-detail-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 4px; }
.gpu-name { font-size: 14px; font-weight: 700; color: var(--text); }
.gpu-tag { font-size: 10.5px; }
.metric-line { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-secondary); }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.detail-grid > div { display: flex; flex-direction: column; gap: 1px; }
.dg-label { font-size: 9.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.03em; }
.detail-grid .mono { font-size: 12px; color: var(--text); }

.kv-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kv-grid > div { display: flex; flex-direction: column; gap: 2px; }

.ns-list { display: flex; flex-direction: column; gap: 9px; }
.ns-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.ns-name { width: 120px; flex-shrink: 0; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ns-bar { flex: 1; height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.ns-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.ns-count { width: 64px; text-align: right; flex-shrink: 0; color: var(--text); }

.stack-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
.stack-bar.big { height: 14px; border-radius: 7px; }
.stack-bar > div { height: 100%; }
.stack-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 11px; color: var(--text-secondary); flex-wrap: wrap; }
.stack-legend i, .log-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

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

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary); border-radius: 6px; padding: 5px 11px; font-size: 12px; font-family: var(--font-mono); cursor: pointer; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.log-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 11.5px; color: var(--text-secondary); flex-wrap: wrap; }
.log-legend-item i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.log-stream { display: flex; flex-direction: column; max-height: 460px; overflow-y: auto; font-size: 12px; }
.log-line { display: grid; grid-template-columns: 60px 62px 130px 1fr; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.log-time { color: var(--text-tertiary); font-size: 11px; }
.log-level { font-size: 10.5px; text-transform: uppercase; font-weight: 600; }
.log-ns { color: var(--text-tertiary); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-msg { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------- footer */

.brand-footer {
  background: var(--surface); border-top: 1px solid var(--border); padding: 12px 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: 11px; color: var(--text-tertiary);
}
.bf-left { display: flex; align-items: center; gap: 10px; }
.bf-logo { height: 20px; opacity: 0.9; }
.bf-tag { font-weight: 600; letter-spacing: 0.05em; }
.bf-mid { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.bf-mid span { display: flex; align-items: center; gap: 5px; }
.bf-right { display: flex; align-items: center; gap: 7px; font-weight: 600; color: var(--green); }

/* --------------------------------------------------------------- modal */

.modal-overlay { position: fixed; inset: 0; background: rgba(4,8,18,0.65); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-overlay[hidden] { display: none; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 420px; max-width: 92vw; max-height: 86vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; }
.modal-head button { font-size: 20px; line-height: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-secondary); display: flex; justify-content: space-between; }
.field input[type="range"] { width: 100%; }
.field input[type="number"], .field input[type="text"] {
  font-family: var(--font-mono); font-size: 13px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); color: var(--text);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.checkbox-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--text); }
.color-swatches { display: flex; gap: 8px; }
.color-swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color-swatch.selected { border-color: var(--text); }

@media (max-width: 1100px) {
  .span-3, .span-4, .span-5, .span-6, .span-8 { grid-column: span 12; }
}
