:root {
  --bg: #141313;
  --surface-1: #1c1b1b;
  --surface-2: #201f1f;
  --surface-3: #2a2a2a;
  --text: #e5e2e1;
  --text-muted: #c5c6ca;
  --text-faint: #8f9194;
  --border: #45474a;
  --border-faint: #353435;

  --healthy: #10b981;
  --low: #f59e0b;
  --medium: #f97316;
  --high: #ef4444;
  --neutral: #8f9194;

  --x-color: #f87171;
  --y-color: #60a5fa;
  --z-color: #34d399;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Ambient severity ring + inner glow over the entire viewport.
   Clinical/industrial pattern: an operator should sense machine state
   from peripheral vision without having to focus on any value. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  border: 0 solid transparent;
  box-shadow: none;
  transition: border 400ms ease-out, box-shadow 400ms ease-out;
}

body.severity-baseline::before {
  border-width: 2px;
  border-color: var(--healthy);
  box-shadow: inset 0 0 80px rgba(16, 185, 129, 0.06);
}

body.severity-low::before {
  border-width: 3px;
  border-color: var(--low);
  box-shadow: inset 0 0 100px rgba(245, 158, 11, 0.11);
}

body.severity-medium::before {
  border-width: 4px;
  border-color: var(--medium);
  box-shadow: inset 0 0 130px rgba(249, 115, 22, 0.15);
}

body.severity-high::before {
  border-width: 5px;
  border-color: var(--high);
  box-shadow: inset 0 0 180px rgba(239, 68, 68, 0.22);
}

button,
input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  background: var(--surface-3);
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 12px;
}

/* App shell */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border-faint);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Sidebar */
.brand {
  font-weight: 700;
  letter-spacing: 0.05em;
  font-size: 14px;
  margin-bottom: 24px;
  color: var(--text);
}

.asset-card {
  background: var(--surface-2);
  border: 1px solid var(--border-faint);
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 24px;
}

.asset-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.asset-id {
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.01em;
}

.asset-status {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background-color 80ms;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border-faint);
}

.nav-icon {
  font-size: 14px;
}

/* Recent Predictions page */
.history-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-faint);
}

.history-page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.history-page-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.history-page-count {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text-faint);
}

.history-page-list {
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-faint);
  border-radius: 6px;
  overflow: hidden;
}

.history-row {
  display: grid;
  grid-template-columns: 100px 1fr auto 70px;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-faint);
}

.history-row:last-child {
  border-bottom: none;
}

.history-row:hover {
  background: var(--surface-2);
}

.history-row-time {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: -0.01em;
}

.history-row-state {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-row-severity {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-row-sev-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.history-row-sev-label.baseline { color: var(--healthy); }
.history-row-sev-label.low { color: var(--low); }
.history-row-sev-label.medium { color: var(--medium); }
.history-row-sev-label.high { color: var(--high); }

.history-row-count {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text-faint);
  text-align: right;
}

.history-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  background: var(--neutral);
}

.history-dot.baseline { background: var(--healthy); }
.history-dot.low { background: var(--low); }
.history-dot.medium { background: var(--medium); }
.history-dot.high { background: var(--high); }

.history-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-faint);
  font-style: italic;
  font-size: 13px;
}

.sidebar-footer {
  border-top: 1px solid var(--border-faint);
  padding-top: 12px;
  margin-top: 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

.meta-label {
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.meta-value {
  color: var(--text-muted);
  font-family: "JetBrains Mono", monospace;
}

/* Preview-mode banner (GitHub Pages) */
.preview-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(245, 158, 11, 0.13);
  border-bottom: 1px solid rgba(245, 158, 11, 0.45);
  font-size: 12px;
  color: var(--text);
  flex-shrink: 0;
}

.preview-banner-tag {
  background: var(--low);
  color: #0e0e0e;
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 9999px;
}

.preview-banner-text {
  flex: 1;
  color: var(--text-muted);
}

.preview-banner a {
  color: var(--low);
  text-decoration: none;
  font-weight: 600;
}

.preview-banner a:hover {
  text-decoration: underline;
}

/* Topbar */
.topbar {
  height: 56px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-faint);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--surface-1);
}

.topbar-title {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neutral);
  display: inline-block;
}

.dot.connected { background: var(--healthy); }
.dot.warning { background: var(--low); }
.dot.danger { background: var(--high); }

/* Hero */
.hero {
  margin: 24px;
  padding: 24px;
  border: 1px solid var(--border-faint);
  border-radius: 6px;
  background: var(--surface-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  transition: background-color 400ms ease-out, border-color 400ms ease-out;
}

.hero.healthy {
  background: rgba(16, 185, 129, 0.10);
  border-color: rgba(16, 185, 129, 0.40);
}

.hero.low {
  background: rgba(245, 158, 11, 0.13);
  border-color: rgba(245, 158, 11, 0.50);
}

.hero.medium {
  background: rgba(249, 115, 22, 0.15);
  border-color: rgba(249, 115, 22, 0.55);
}

.hero.high {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.60);
}

.hero.stale {
  background: var(--surface-1);
  border-color: var(--border-faint);
  opacity: 0.75;
}

.badge.badge-warn {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(245, 158, 11, 0.55);
  color: var(--low);
}

.hero-state {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.hero-asset {
  font-family: "JetBrains Mono", monospace;
}

.hero-time {
  color: var(--text-faint);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.40);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.hero-right {
  display: flex;
  align-items: flex-end;
  gap: 36px;
}

.conf-block {
  text-align: right;
}

.conf-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.conf-value {
  font-family: "JetBrains Mono", monospace;
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}

.conf-block-sm {
  text-align: right;
  padding-bottom: 6px;
}

.conf-label-sm {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 2px;
}

.conf-value-sm {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  color: var(--text-faint);
  line-height: 1;
}

/* Content area */
.content {
  flex: 1;
  overflow: auto;
  padding: 0 24px 24px 24px;
}

.mode-view[hidden] {
  display: none;
}

/* Upload */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 6px;
  padding: 48px 24px;
  text-align: center;
  background: var(--surface-1);
  transition: border-color 100ms, background-color 100ms;
}

.upload-zone.dragging {
  border-color: var(--text);
  background: var(--surface-2);
}

.upload-icon {
  font-size: 32px;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.upload-title {
  font-weight: 600;
  font-size: 18px;
  margin-bottom: 6px;
}

.upload-sub {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.upload-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
}

.rpm-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.rpm-label input {
  width: 90px;
  background: var(--surface-3);
  border: 1px solid var(--border-faint);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 4px;
  font-family: "JetBrains Mono", monospace;
}

.rpm-label input:focus {
  outline: none;
  border-color: var(--text);
}

.btn {
  padding: 8px 18px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.btn:hover {
  background: var(--border-faint);
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn-primary:hover {
  background: #ffffff;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.upload-hint {
  font-size: 12px;
  color: var(--text-faint);
}

.upload-error {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--high);
  border-radius: 4px;
  color: var(--high);
  font-size: 13px;
}

/* Severity timeline strip (rhythm-strip style — last ~60s of severity) */
.severity-timeline {
  position: relative;
  height: 22px;
  border: 1px solid var(--border-faint);
  border-radius: 3px;
  background: var(--surface-1);
  margin-bottom: 16px;
  overflow: hidden;
}

.severity-timeline canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.severity-timeline-tag {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: rgba(20, 19, 19, 0.65);
  padding: 1px 5px;
  border-radius: 2px;
  pointer-events: none;
}

.severity-timeline-tag.tag-left { left: 6px; }
.severity-timeline-tag.tag-right { right: 6px; }

/* Stream bar */
.stream-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-1);
  border: 1px solid var(--border-faint);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.eco-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 18px;
  flex-shrink: 0;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border-faint);
  border-radius: 9999px;
  transition: background-color 160ms ease-out, border-color 160ms ease-out;
}

.toggle-track::before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  left: 2px;
  top: 2px;
  background: var(--text-faint);
  border-radius: 50%;
  transition: transform 160ms ease-out, background-color 160ms ease-out;
}

.toggle-switch input:checked + .toggle-track {
  background: rgba(229, 226, 225, 0.18);
  border-color: var(--text);
}

.toggle-switch input:checked + .toggle-track::before {
  transform: translateX(16px);
  background: var(--text);
}

.toggle-switch input:focus-visible + .toggle-track {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.eco-toggle:hover .toggle-track {
  border-color: var(--border);
}

.stream-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stream-rate {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text-faint);
}

.eco-msg {
  margin-top: 24px;
  text-align: center;
  padding: 64px 24px;
  background: var(--surface-1);
  border: 1px dashed var(--border-faint);
  border-radius: 6px;
}

.eco-msg-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 6px;
}

.eco-msg-sub {
  color: var(--text-muted);
}

/* Plot grid */
.plot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 320px;
  gap: 16px;
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border-faint);
  border-radius: 6px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  height: 320px;
  overflow: hidden;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
  gap: 12px;
}

.panel-title-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.panel-legend {
  display: flex;
  gap: 12px;
  font-size: 11px;
  font-weight: 600;
}

.leg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  transition: opacity 100ms;
}

.leg:hover {
  opacity: 0.8;
}

.leg.disabled {
  opacity: 0.25;
}

.leg::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 1px;
  display: inline-block;
}

.leg-x { color: var(--x-color); }
.leg-x::before { background: var(--x-color); }
.leg-y { color: var(--y-color); }
.leg-y::before { background: var(--y-color); }
.leg-z { color: var(--z-color); }
.leg-z::before { background: var(--z-color); }

.chart {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* Stats table */
.stats-table {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 1px;
  background: var(--border-faint);
  border: 1px solid var(--border-faint);
  border-radius: 4px;
  overflow: hidden;
}

.stats-table > div {
  background: var(--surface-1);
  padding: 10px 12px;
  font-size: 12px;
}

.stats-table .stats-head {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.stats-table .stats-cell {
  font-family: "JetBrains Mono", monospace;
  text-align: right;
  letter-spacing: -0.01em;
}

.stats-table .stats-row-label {
  font-weight: 500;
  color: var(--text-muted);
}

/* uPlot tweaks */
.uplot {
  font-family: inherit;
  width: 100%;
}

.u-legend {
  font-size: 11px;
  color: var(--text-muted);
}

.u-axis {
  color: var(--text-faint);
}
