/* ---------------------------------------------------------
   Venus Pilot Theme & Stylesheet (index.css)
   --------------------------------------------------------- */

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #151c2c;
  --border-color: #1f293d;

  --color-text-main: #f3f4f6;
  --color-text-muted: #9ca3af;
  --color-text-sub: #6b7280;

  --color-accent: #00d2ff;
  --color-green: #00ff8c;
  --color-red: #ff3c78;
  --color-yellow: #ffd200;
  --color-blue: #00d2ff;
  --color-pink: #b400ff;

  --font-family: 'Outfit', sans-serif;
  --font-mono: 'Roboto Mono', monospace;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-primary);
  color: var(--color-text-main);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  padding: 20px;
}

.app-container {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------------------------------------------------------
   Header
   --------------------------------------------------------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.brand-logo {
  height: 32px;
  width: auto;
  border-radius: 4px;
}

.brand-text-container {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ffffff;
}

.sub-brand {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--color-text-sub);
  display: block;
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: rgba(0, 255, 140, 0.1);
  border: 1px solid rgba(0, 255, 140, 0.3);
  padding: 4px 10px;
  border-radius: 4px;
}

.live-dot {
  width: 8px;
  height: 8px;
  background-color: var(--color-green);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--color-green);
  animation: blink 1.5s infinite;
}

.live-text {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-green);
  letter-spacing: 0.5px;
}

.header-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--color-text-sub);
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-main);
}

.simulated-clock {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 500;
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.05);
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Buttons */
.btn {
  font-family: var(--font-family);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--color-accent);
  color: #000000;
}

.btn-primary:hover {
  background-color: #5ce6ff;
  box-shadow: 0 0 12px rgba(0, 210, 255, 0.4);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--color-text-main);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.btn-large {
  font-size: 15px;
  padding: 12px 28px;
  border-radius: 6px;
}

/* ---------------------------------------------------------
   Pipeline Bar
   --------------------------------------------------------- */
.pipeline-bar {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 10px 20px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  /* Wraps. Adding the pipeline controls made this row too wide for a narrow
     viewport, and a non-wrapping flex row pushed the page 50px past the
     viewport -- which the fixed-position modals then inherited, since they
     size against the document rather than the window. */
  flex-wrap: wrap;
}

.pipeline-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--color-text-sub);
}

.pipeline-status {
  display: flex;
  gap: 15px;
}

.status-node {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  position: relative;
  padding-left: 18px;
}

.status-node::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  width: 8px;
  height: 8px;
  background-color: var(--border-color);
  border-radius: 50%;
}

.status-node.active::before {
  background-color: var(--color-green);
  box-shadow: 0 0 6px var(--color-green);
}

.pipeline-stats {
  display: flex;
  gap: 20px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.highlight {
  color: #ffffff;
  font-weight: 600;
}

.pipeline-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.frame-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-sub);
  text-transform: uppercase;
}

.frame-val {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
}

/* ---------------------------------------------------------
   Dashboard Grid & Cards
   --------------------------------------------------------- */
.dashboard-grid {
  display: grid;
  /* Four tracks: the three core outputs plus live Machine State. Core Output 2
     stays widest because it holds one tile per monitored machine. */
  grid-template-columns: 1fr 1.3fr 1.1fr 1.1fr;
  gap: 20px;
}
/* This grid had no breakpoints at all -- three fixed tracks on any width. Four
   across needs them: a laptop cannot carry four core cards side by side. */
@media (max-width: 1250px) {
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-sub {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--color-text-sub);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
}

/* Card 1: Presence */
.presence-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  gap: 12px;
}

.progress-large-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.presence-value-row {
  display: flex;
  align-items: flex-end;
}

.presence-pct-val {
  font-size: 32px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background-color: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-accent), var(--color-green));
  border-radius: 3px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Card 2: Utilisation Grid */
.utilization-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.util-zone-item {
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zone-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.zone-name {
  font-size: 10px;
  font-weight: 800;
  color: var(--color-text-sub);
}

.zone-pct {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
}

.zone-progress-bg {
  width: 100%;
  height: 3px;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 1.5px;
  overflow: hidden;
}

.zone-progress-fill {
  height: 100%;
  border-radius: 1.5px;
  transition: width 0.3s ease;
}

.red-text { color: var(--color-red); }
.red-fill { background-color: var(--color-red); }
.yellow-text { color: var(--color-yellow); }
.yellow-fill { background-color: var(--color-yellow); }
.green-text { color: var(--color-green); }
.green-fill { background-color: var(--color-green); }
.blue-text { color: var(--color-blue); }
.blue-fill { background-color: var(--color-blue); }

.zone-details {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--color-text-sub);
}

.zone-badge {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 2px;
  width: fit-content;
  margin-top: 2px;
}

.badge-proxy {
  background-color: rgba(255, 210, 0, 0.08);
  color: var(--color-yellow);
  border: 1px solid rgba(255, 210, 0, 0.2);
}

.badge-carriage {
  background-color: rgba(0, 255, 140, 0.08);
  color: var(--color-green);
  border: 1px solid rgba(0, 255, 140, 0.2);
}

/* Card 3: Changeover */
.changeover-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  gap: 12px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  padding-bottom: 6px;
}

.metric-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.metric-label {
  font-size: 12px;
  color: var(--color-text-muted);
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
}

/* ---------------------------------------------------------
   Machine State Per Zone Row
   --------------------------------------------------------- */
/* Machine State now sits in ONE grid track beside the core outputs, so its
   cards stack down it rather than being squeezed four abreast. */

.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--color-text-sub);
}

.live-cards-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.live-card {
  padding: 12px;
  background-color: var(--bg-secondary);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.live-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.live-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.zone-lbl {
  font-size: 11px;
  font-weight: 800;
  color: var(--color-text-sub);
}

.badge-proxy-small, .badge-carriage-small {
  font-size: 8px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 2px;
}

.badge-proxy-small {
  border: 1px solid rgba(255, 210, 0, 0.2);
  color: var(--color-yellow);
}

.badge-carriage-small {
  border: 1px solid rgba(0, 255, 140, 0.2);
  color: var(--color-green);
}

.machine-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.state-text {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.state-productive { color: var(--color-green); }
.state-unsupervised { color: var(--color-red); }
.state-idle { color: var(--color-yellow); }
.state-stopped { color: var(--color-blue); }

.state-meta {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--color-text-sub);
}

.card-footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding-top: 10px;
}

.worker-status {
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.worker-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.worker-status.worker-present {
  color: var(--color-green);
}
.worker-status.worker-present::before {
  background-color: var(--color-green);
  box-shadow: 0 0 6px var(--color-green);
}

.worker-status.no-worker {
  color: var(--color-red);
}
.worker-status.no-worker::before {
  background-color: var(--color-red);
  box-shadow: 0 0 6px var(--color-red);
}

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

/* Zone Specific Border Indicators */
.border-blue { border-left: 3px solid var(--color-blue); }
.border-yellow { border-left: 3px solid var(--color-yellow); }
.border-pink { border-left: 3px solid var(--color-pink); }
.border-green { border-left: 3px solid var(--color-green); }

/* ---------------------------------------------------------
   Video Frame Panel
   --------------------------------------------------------- */
.video-feed-section {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.video-container {
  position: relative;
  background-color: #000000;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#video-canvas {
  width: 100%;
  max-width: 1200px;
  height: auto;
  aspect-ratio: 16 / 9;
  display: block;
}

.play-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(10, 14, 23, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  backdrop-filter: blur(4px);
  z-index: 10;
  transition: opacity 0.3s ease;
}

.play-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------
   Keyframe Animations
   --------------------------------------------------------- */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---------------------------------------------------------
   Video Controls Bar
   --------------------------------------------------------- */
.video-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px;
  margin-top: 10px;
  transition: opacity 0.3s ease;
}

.video-controls.hidden {
  display: none !important;
}

.btn-danger {
  background-color: var(--color-red);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #ff5c92;
  box-shadow: 0 0 12px rgba(255, 60, 120, 0.4);
}

/* ---------------------------------------------------------
   Modal Dialog Layout
   --------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background-color: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 1;
  visibility: visible;
  transition: all 0.3s ease;
}

.modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  width: 90%;
  max-width: 580px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
}

.modal-close-x {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal-close-x:hover {
  color: #ffffff;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 450px;
  overflow-y: auto;
}

.form-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-section h4 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--color-accent);
  letter-spacing: 0.5px;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 4px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.form-grid-three {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.form-group input {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: #ffffff;
  padding: 8px 12px;
  font-family: var(--font-family);
  font-size: 13px;
  transition: border-color 0.2s ease;
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-accent);
}

.modal-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}


/* Live carriage telemetry under each carriage-tracked zone's state text. */
.carriage-line {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
}
.carriage-line .cv-state { font-weight: 700; }
.carriage-line .cv-rolling { color: #34d399; }
.carriage-line .cv-tube    { color: #fbbf24; }
.carriage-line .cv-idle    { color: #9ca3af; }
.carriage-line .cv-unconf  { color: #6b7280; }
.carriage-line .cv-vel     { color: #e5e7eb; }

/* ══════════════════════════════════════════════════════════════════════════
   ROI calibration page (roi.html)
   ══════════════════════════════════════════════════════════════════════════ */
.roi-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  padding: 18px;
  align-items: start;
}
@media (max-width: 1100px) {
  .roi-layout { grid-template-columns: 1fr; }
}
.roi-canvas-card { padding-bottom: 10px; }
.roi-canvas-wrap { position: relative; padding: 0 14px; }
/* The canvas buffer is a fixed 1920x1080 and CSS scales it to fit; roi.js maps
   pointer coordinates back through getBoundingClientRect, so the displayed
   size can be anything. crosshair makes it obvious the image is drawable. */
#roi-canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  border: 1px solid #1f293d;
  background: #0a0e17;
  cursor: crosshair;
}
.roi-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  background: rgba(10, 14, 23, 0.85);
  border-radius: 8px;
  font-size: 0.95rem;
}
.roi-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  padding: 12px 16px 4px;
  font-size: 0.82rem;
  color: #9ca3af;
}
.roi-legend label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.sw-die, .sw-car, .sw-roi {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block;
}
.sw-die { background: #00ffff; }
.sw-car { background: #ff8c00; }
.sw-roi { background: transparent; border: 2px dashed #f3f4f6; }
.roi-cursor {
  margin-left: auto;
  font-family: 'Roboto Mono', monospace;
  color: #6b7280;
}
.roi-source {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.75rem;
  color: #6b7280;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.roi-side .card-body { display: flex; flex-direction: column; gap: 14px; }
.roi-coords {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.85rem;
  color: #f3f4f6;
  background: #0f172a;
  border: 1px solid #1f293d;
  border-radius: 6px;
  padding: 10px 12px;
}
.roi-actions { display: flex; gap: 10px; }
.roi-actions .btn { flex: 1; }
.btn-block { width: 100%; margin-top: 8px; }
.roi-status { font-size: 0.82rem; color: #9ca3af; min-height: 1.2em; line-height: 1.4; }
.roi-status-ok   { color: #34d399; }
.roi-status-warn { color: #fbbf24; }
.roi-status-err  { color: #ef4444; }
.roi-note {
  border-top: 1px solid #1f293d;
  padding-top: 12px;
  font-size: 0.82rem;
  color: #9ca3af;
}
.roi-help { border-top: 1px solid #1f293d; padding-top: 12px; }
.roi-help h4, .roi-existing h4 {
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: #6b7280; margin: 0 0 8px;
}
.roi-help p { font-size: 0.8rem; color: #9ca3af; line-height: 1.5; margin: 0 0 8px; }
.roi-help code {
  font-family: 'Roboto Mono', monospace; font-size: 0.75rem;
  background: #0f172a; padding: 1px 5px; border-radius: 3px; color: #cbd5e1;
}
.roi-existing { border-top: 1px solid #1f293d; padding-top: 12px; }
.roi-existing-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; padding: 4px 0; font-size: 0.8rem;
}
.roi-existing-row code { font-family: 'Roboto Mono', monospace; color: #9ca3af; font-size: 0.75rem; }
.dim { color: #6b7280; font-size: 0.8rem; }

/* ── Configure Source: camera fields ─────────────────────────────────────── */
.source-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.source-toggle button {
  flex: 1; padding: 9px 12px; border-radius: 6px; cursor: pointer;
  background: #0f172a; color: #9ca3af;
  border: 1px solid #1f293d; font-family: inherit; font-size: 0.85rem;
}
.source-toggle button.active {
  background: rgba(0, 210, 255, 0.12); color: #00d2ff; border-color: #00d2ff;
}
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }
.field-hint { font-size: 0.72rem; color: #6b7280; margin-top: 4px; line-height: 1.4; }
.test-result { font-size: 0.8rem; margin-top: 8px; min-height: 1.2em; line-height: 1.4; }
.test-ok  { color: #34d399; }
.test-err { color: #ef4444; }

/* Scoped the same way .video-controls.hidden is, deliberately: a generic
   .hidden{display:none} would also catch .play-overlay.hidden, which hides via
   opacity so it can fade over 300ms. A blanket display rule would snap it. */
#src-camera-fields.hidden,
#src-file-fields.hidden,
#cam-channel-group.hidden { display: none; }

/* ══════════════════════════════════════════════════════════════════════════
   Shift history table
   ══════════════════════════════════════════════════════════════════════════ */
/* Full-width row in .dashboard-grid. Without this it became a single grid item
   and sat squeezed into one column. */
.history-section { grid-column: 1 / -1; }
.history-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.history-meta { font-size: 0.75rem; color: #6b7280; white-space: nowrap; padding-top: 4px; }
/* Wide table in a fixed-width card: let the table scroll, never the page. */
.history-scroll { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; min-width: 640px; }
/* Seven narrow columns fit comfortably; the minimum is for the wider
   Completed Shifts table only. */
#core-handovers .history-table, #core-labour .history-table { min-width: 0; }
.history-table th {
  text-align: left;
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #6b7280;
  font-weight: 600;
  padding: 6px 10px;
  border-bottom: 1px solid #1f293d;
  white-space: nowrap;
}
.history-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(31, 41, 61, 0.6);
  color: #cbd5e1;
  white-space: nowrap;
}
.history-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.history-table .h-shift { color: #f3f4f6; font-weight: 600; }
.history-table .h-when { color: #9ca3af; }
.history-table tbody tr:last-child td { border-bottom: none; }
.history-total td {
  border-top: 1px solid #1f293d;
  background: rgba(0, 210, 255, 0.05);
  color: #f3f4f6;
  font-weight: 600;
}
.history-total .h-when { color: #6b7280; font-weight: 400; }
.history-empty { color: #6b7280; text-align: center; padding: 18px 0; }
.history-note { font-size: 0.72rem; color: #6b7280; margin-top: 10px; line-height: 1.5; }
.history-note span { color: #fbbf24; font-weight: 700; }

/* ══════════════════════════════════════════════════════════════════════════
   Since-shift-start totals strip
   ══════════════════════════════════════════════════════════════════════════ */
.totals-strip { grid-column: 1 / -1; padding: 14px 18px 16px; }
.totals-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; margin-bottom: 12px;
}
.totals-scope {
  font-size: 0.72rem; color: #6b7280;
  font-family: 'Roboto Mono', monospace; white-space: nowrap;
}
.totals-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 1200px) { .totals-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .totals-grid { grid-template-columns: repeat(2, 1fr); } }
.totals-item {
  display: flex; flex-direction: column; gap: 3px;
  padding-left: 12px; border-left: 2px solid #1f293d; min-width: 0;
}
.totals-label {
  font-size: 0.66rem; letter-spacing: 0.07em; text-transform: uppercase;
  color: #6b7280; font-weight: 600;
}
.totals-value {
  font-size: 1.5rem; font-weight: 700; color: #f3f4f6; line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.totals-sub {
  font-size: 0.7rem; color: #6b7280; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis;
}

/* Says WHICH handover the changeover card is describing -- this shift's, or
   the last completed one it fell back to. Without it the numbers would be
   ambiguous the moment they came from history. */
.scope-chip {
  margin-top: 6px; display: inline-block;
  font-size: 0.62rem; letter-spacing: 0.06em; text-transform: uppercase;
  font-weight: 600; padding: 2px 7px; border-radius: 3px;
  background: rgba(0, 210, 255, 0.12); color: #00d2ff;
}
.scope-chip-past { background: rgba(148, 163, 184, 0.12); color: #94a3b8; }

.presence-value-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.presence-scope {
  font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: #6b7280; font-weight: 600;
}
.presence-footer { display: flex; flex-direction: column; gap: 2px; }
.presence-sub { font-size: 0.72rem; color: #6b7280; }

/* Live preview of the URL the camera tab will actually dial. */
.url-preview-row {
  display: flex; flex-direction: column; gap: 4px;
  margin: 12px 0 10px; padding: 8px 10px;
  background: #0f172a; border: 1px solid #1f293d; border-radius: 6px;
}
.url-preview-label {
  font-size: 0.64rem; letter-spacing: 0.07em; text-transform: uppercase;
  color: #6b7280; font-weight: 600;
}
.url-preview {
  font-family: 'Roboto Mono', monospace; font-size: 0.75rem;
  color: #cbd5e1; word-break: break-all; line-height: 1.4;
}
.url-preview-bad { color: #fbbf24; }

/* ── Metric definitions on each card ─────────────────────────────────────── */
.card-def {
  margin: 6px 0 0;
  font-size: .76rem;
  line-height: 1.45;
  color: #6b7280;
  max-width: 46ch;
}

/* ── Crowding: more people at a machine than it should have ──────────────── */
.crowd-flag {
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 3px;
  background: rgba(251, 191, 36, .14);
  color: #fbbf24;
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-align: center;
}
.worker-status.worker-crowded { color: #fbbf24; }

/* Method badge on the live card header, alongside the zone label. */
.live-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.zone-method {
  font-size: .6rem; font-weight: 700; letter-spacing: .06em;
  padding: 2px 6px; border-radius: 3px;
}
.zone-machine { font-size: .78rem; color: #9ca3af; margin: 8px 0 2px; }
.live-card-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 10px; }

/* ── Live attention flags in the status bar ──────────────────────────────── */
.live-flags { display: flex; gap: 8px; align-items: center; }
.flag {
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 3px 9px;
  border-radius: 3px;
  white-space: nowrap;
}
.flag-danger { background: rgba(239, 68, 68, .16); color: #f87171; }
.flag-warn   { background: rgba(251, 191, 36, .16); color: #fbbf24; }

/* ── Info markers: definitions on hover, without cluttering the page ─────── */
.info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  margin-left: 4px;
  border-radius: 50%;
  border: 1px solid #4b5563;
  color: #9ca3af;
  font-size: .58rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: help;
  vertical-align: middle;
  position: relative;
  text-transform: none;
  letter-spacing: 0;
}
.info:hover, .info:focus-visible { border-color: #00d2ff; color: #00d2ff; outline: none; }
/* The tooltip itself. Positioned above and clamped to a readable width; the
   parent needs no positioning because the marker carries it. */
.info::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 300px;
  padding: 9px 11px;
  background: #0b1119;
  border: 1px solid #35434f;
  border-radius: 5px;
  color: #cbd5e1;
  font: 400 .72rem/1.5 'Source Sans 3', system-ui, sans-serif;
  font-style: normal;
  letter-spacing: 0;
  text-align: left;
  text-transform: none;
  box-shadow: 0 10px 28px -12px rgba(0, 0, 0, .8);
  /* display:none, not visibility:hidden. A hidden element still occupies
     layout, and these sit inside .history-scroll (overflow-x: auto) -- so the
     hidden tooltips pushed the container's scroll width past its visible width
     and put a scrollbar under the table even when nothing was hovered. */
  display: none;
  z-index: 40;
  pointer-events: none;
}
.info:hover::after, .info:focus-visible::after { display: block; }
/* Markers near the right edge would push their tooltip off-screen. */
.history-table th:last-child .info::after,
.totals-item:last-child .info::after { left: auto; right: 0; transform: none; }


/* ---- Workers by Zone -------------------------------------------------- */
.labour-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.labour-item {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* Over the configured limit -- the same warning colour the crowding flag and
   the card badge use, so the three read as one signal. */
.labour-item.labour-over {
  border-color: var(--color-yellow);
  background: rgba(217, 154, 43, 0.08);
}
.labour-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.labour-value { font-size: 30px; font-weight: 600; line-height: 1.1; }
.labour-item.labour-over .labour-value { color: var(--color-yellow); }
.labour-sub { font-size: 12px; color: var(--color-text-muted); display: flex; gap: 8px; flex-wrap: wrap; }
.lz {
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 6px;
  font-variant-numeric: tabular-nums;
}
.lz-over { border-color: var(--color-yellow); color: var(--color-yellow); }
.labour-empty { color: var(--color-text-muted); font-size: 13px; padding: 8px 0; }

/* ---- Load CSV dialog --------------------------------------------------- */
.csv-list { max-height: 260px; overflow-y: auto; }
.csv-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 13px;
}
.csv-row:hover { border-color: var(--color-accent); }
.csv-name { font-family: var(--mono, monospace); overflow-wrap: anywhere; }
.csv-meta { color: var(--color-text-muted); font-size: 12px; white-space: nowrap; }
.csv-empty { color: var(--color-text-muted); font-size: 13px; }
.csv-source {
  font-size: 12px;
  color: var(--color-text-muted);
  font-family: var(--mono, monospace);
}

/* ---- Top incidents ----------------------------------------------------- */
.incidents { list-style: none; margin: 0; padding: 0; counter-reset: inc; }
.incident {
  display: grid;
  grid-template-columns: 190px 1fr auto;
  grid-template-areas: "when what dur" "when meta meta";
  gap: 2px 14px;
  align-items: baseline;
  padding: 10px 12px 10px 14px;
  border-left: 3px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}
.incident:last-child { border-bottom: 0; }
/* Colour carries severity, and the duration is the ranked quantity, so it is
   the element that gets weight. */
.incident.inc-danger { border-left-color: var(--color-red); }
.incident.inc-warn   { border-left-color: var(--color-yellow); }
.inc-when { grid-area: when; font-variant-numeric: tabular-nums; color: var(--color-text-muted); font-size: 12px; }
.inc-what { grid-area: what; font-size: 14px; }
.inc-dur  { grid-area: dur; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.incident.inc-danger .inc-dur { color: var(--color-red); }
.incident.inc-warn   .inc-dur { color: var(--color-yellow); }
.inc-meta { grid-area: meta; font-size: 11px; color: var(--color-text-muted); }
.incidents-empty { padding: 10px 0; color: var(--color-text-muted); font-size: 13px; }
@media (max-width: 720px) {
  .incident { grid-template-columns: 1fr auto; grid-template-areas: "when dur" "what what" "meta meta"; }
}

/* ---- Charts ------------------------------------------------------------ */
/* Inline SVG, no chart library: the plant box may have no internet, and the
   CSP on this page blocks everything but same-origin assets anyway. */
/* Three equal columns: one row, one chart each. Explicit tracks rather than
   auto-fit, which on a wide screen cut this into four and left the charts
   sharing half the width with empty tracks beside them. */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px 26px;
}
@media (max-width: 1250px) {
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
}
.chart { margin: 0; }
/* Was a full-width row of its own; it is now simply the third column. */
.chart figcaption {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}
.chart-body { width: 100%; }
/* The SVG carries width/height matching its viewBox and the viewBox is built
   from the measured cell width, so it fills the box at 1:1 -- no rescaling.
   max-width only guards against a redraw lagging a shrink. */
.chartsvg { max-width: 100%; height: auto; display: block; overflow: visible; }
/* Gridlines are lifted off --border-color (#1f293d), which is fine as a panel
   edge but invisible as a 1px line across a chart. */
.chartsvg .grid { stroke: #26324a; stroke-width: 1; }
.chartsvg .ylab,
.chartsvg .xlab { font-size: 10px; fill: var(--color-text-muted); font-variant-numeric: tabular-nums; }
/* The value labels ARE the quantity, so they get full text colour, not muted.
   They previously resolved to black on a #151c2c panel. */
.chartsvg .vlab { font-size: 10px; font-weight: 600; fill: var(--color-text-main); font-variant-numeric: tabular-nums; }
.chartsvg .bar { transition: opacity .12s; }
.chartsvg .bar:hover { opacity: .8; }
.chartsvg .ln { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chartsvg .pt { stroke: var(--bg-card); stroke-width: 1.5; }

/* Series colours come from the dashboard's own palette so the charts belong to
   this product rather than looking imported from another one.
   Utilisation: zone D is the accent, being the carriage-tracked machine; the
   proxy group takes the pink, lifted from #b400ff which is too dark here. */
.s-zoneD    { fill: var(--color-accent); stroke: var(--color-accent); }
.s-group    { fill: #c46bff; stroke: #c46bff; }
.s-presence { fill: var(--color-green); stroke: var(--color-green); }
/* Coverage is context, not a KPI -- deliberately unsaturated so it does not
   compete with the presence figure beside it. */
.s-coverage { fill: #7d8ea6; stroke: #7d8ea6; }

/* Alerts are coloured by SEVERITY. Unsupervised was drawn in a friendly blue
   while Changeover-Absent was orange, which inverted the actual ranking. */
.s-unsupervised { fill: var(--color-red); stroke: var(--color-red); }
.s-discipline   { fill: var(--color-yellow); stroke: var(--color-yellow); }
.s-changeover   { fill: #c46bff; stroke: #c46bff; }
.s-crowding     { fill: #ff9c3c; stroke: #ff9c3c; }
.s-other        { fill: var(--color-text-sub); stroke: var(--color-text-sub); }

i.sw.s-zoneD        { background: var(--color-accent); }
i.sw.s-group        { background: #c46bff; }
i.sw.s-presence     { background: var(--color-green); }
i.sw.s-coverage     { background: #7d8ea6; }
i.sw.s-unsupervised { background: var(--color-red); }
i.sw.s-discipline   { background: var(--color-yellow); }
i.sw.s-changeover   { background: #c46bff; }
i.sw.s-crowding     { background: #ff9c3c; }
i.sw.s-other        { background: var(--color-text-sub); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 11px; color: var(--color-text-muted); }
.lg { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }


/* ---- See-all incidents ------------------------------------------------- */
.card-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.btn-small { padding: 5px 12px; font-size: 12px; }
.modal-wide .modal-content, .modal-content.modal-wide { max-width: 860px; }
.modal-sub { font-size: 12px; color: var(--color-text-muted); font-weight: 400; }
.incidents-scroll { max-height: 58vh; overflow-y: auto; }
.inc-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--color-text-muted);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.chip:hover { border-color: var(--color-accent); }
.chip-on { border-color: var(--color-accent); color: var(--color-text-main); }

/* Pipeline controls, in the bar already titled PIPELINE. */
.pipeline-controls { display: flex; gap: 8px; margin-left: auto; }
@media (max-width: 800px) { .pipeline-controls { margin-left: 0; } }
