/* ── Design Tokens ── */
:root {
  --c-bg: #0c1018;
  --c-surface: #141b27;
  --c-surface-hover: #1a2333;
  --c-border: #1e2d42;
  --c-border-subtle: #162030;
  --c-text: #d4dce8;
  --c-text-dim: #6b7d93;
  --c-text-muted: #3d4f63;
  --c-accent: #00dfa2;
  --c-accent-dim: rgba(0, 223, 162, 0.12);
  --c-healthy: #00dfa2;
  --c-healthy-dim: rgba(0, 223, 162, 0.1);
  --c-failed: #ff5c5c;
  --c-failed-dim: rgba(255, 92, 92, 0.1);
  --c-pending: #f0b429;
  --c-pending-dim: rgba(240, 180, 41, 0.1);
  --c-chart-latency: #58a6ff;
  --c-chart-tps: #00dfa2;

  --font-data: "JetBrains Mono", "Fira Code", "Cascadia Code", ui-monospace, monospace;
  --font-ui: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 1px rgba(0, 0, 0, 0.5);
  --shadow-glow-healthy: 0 0 20px rgba(0, 223, 162, 0.06);
  --shadow-glow-failed: 0 0 20px rgba(255, 92, 92, 0.06);
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-ui);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Subtle noise texture overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ── Dashboard Layout ── */
#dashboard {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-6);
}

/* ── Header ── */
.dashboard-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--c-border-subtle);
}

.dashboard-header h1 {
  font-family: var(--font-data);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--c-text);
}

.dashboard-header h1::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-accent);
  margin-right: var(--space-2);
  box-shadow: 0 0 8px var(--c-accent);
  vertical-align: middle;
}

.dashboard-meta {
  font-size: 0.8rem;
  color: var(--c-text-dim);
  font-family: var(--font-data);
}

#last-updated::before {
  content: "Updated ";
}

/* ── Status Summary ── */
#status-summary {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding: var(--space-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

.summary-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
}

.summary-stat--healthy {
  background: var(--c-healthy-dim);
}

.summary-stat--failed {
  background: var(--c-failed-dim);
}

.summary-stat--pending {
  background: var(--c-pending-dim);
}

.summary-value {
  font-family: var(--font-data);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
}

.summary-stat--healthy .summary-value {
  color: var(--c-healthy);
}

.summary-stat--failed .summary-value {
  color: var(--c-failed);
}

.summary-stat--pending .summary-value {
  color: var(--c-pending);
}

.summary-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-text-dim);
  margin-top: var(--space-1);
}

/* ── Model Grid ── */
#model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: var(--space-4);
}

/* ── Model Card ── */
.model-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-card);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  animation: cardFadeIn 0.4s ease both;
}

.model-card:hover {
  border-color: var(--c-text-muted);
  background: var(--c-surface-hover);
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger animation */
.model-card:nth-child(1) { animation-delay: 0ms; }
.model-card:nth-child(2) { animation-delay: 60ms; }
.model-card:nth-child(3) { animation-delay: 120ms; }
.model-card:nth-child(4) { animation-delay: 180ms; }
.model-card:nth-child(5) { animation-delay: 240ms; }
.model-card:nth-child(6) { animation-delay: 300ms; }
.model-card:nth-child(7) { animation-delay: 360ms; }

/* ── Card Header ── */
.model-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.model-card__name {
  font-family: var(--font-data);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-card__status {
  font-family: var(--font-data);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.status--healthy {
  color: var(--c-healthy);
  background: var(--c-healthy-dim);
  box-shadow: var(--shadow-glow-healthy);
}

.status--failed {
  color: var(--c-failed);
  background: var(--c-failed-dim);
  box-shadow: var(--shadow-glow-failed);
}

.status--pending {
  color: var(--c-pending);
  background: var(--c-pending-dim);
}

/* ── Metrics Row ── */
.model-card__metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-2);
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border-subtle);
}

.metric__value {
  font-family: var(--font-data);
  font-size: 1rem;
  font-weight: 600;
  color: var(--c-text);
  line-height: 1.2;
}

.metric__label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-text-dim);
  margin-top: 2px;
}

/* ── Error State ── */
.model-card__error {
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  background: var(--c-failed-dim);
  border: 1px solid rgba(255, 92, 92, 0.2);
  border-radius: var(--radius-sm);
  font-family: var(--font-data);
  font-size: 0.75rem;
  color: var(--c-failed);
  line-height: 1.4;
  word-break: break-word;
}

/* ── Empty State ── */
.model-card__empty {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--c-text-muted);
  font-family: var(--font-data);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.model-card__empty::before {
  content: "";
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto var(--space-2);
  border: 2px dashed var(--c-text-muted);
  border-radius: 50%;
  opacity: 0.5;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.6; }
}

/* ── Charts ── */
.model-card__charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.chart-container {
  position: relative;
  background: var(--c-bg);
  border: 1px solid var(--c-border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  min-height: 100px;
}

.chart-container__label {
  display: block;
  font-family: var(--font-data);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-text-muted);
  margin-bottom: var(--space-1);
}

.chart-container__canvas {
  width: 100%;
  height: 80px;
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  font-family: var(--font-data);
  font-size: 0.7rem;
  color: var(--c-text-muted);
}

/* ── uPlot overrides for dark theme ── */
.uplot {
  font-family: var(--font-data) !important;
}

/* ── Responsive ── */
@media (max-width: 840px) {
  #model-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-header {
    flex-direction: column;
    gap: var(--space-2);
  }

  #status-summary {
    flex-wrap: wrap;
  }

  .summary-stat {
    min-width: 60px;
  }
}

@media (max-width: 480px) {
  #dashboard {
    padding: var(--space-3);
  }

  .model-card__metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .model-card__charts {
    grid-template-columns: 1fr;
  }
}
