/* ============================================================
   VIALVISION — Design System
   Reference: dark dashboard, lime-green accent, mono data font
   Breakpoints:
     Desktop  : > 768px   (full sidebar)
     Mobile   : ≤ 768px   (bottom nav)
     Small    : ≤ 480px   (compact layout)
     RPi LCD  : ≤ 480px width OR ≤ 320px height (ultra-compact)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Syne:wght@600;700;800&family=Outfit:wght@300;400;500;600&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-base:    #0A0A0A;
  --bg-card:    #141414;
  --bg-sidebar: #0D0D0D;
  --bg-input:   #1A1A1A;
  --bg-hover:   #1E1E1E;

  /* Accent — lime green from reference */
  --accent:       #C5F135;
  --accent-dim:   rgba(197, 241, 53, 0.10);
  --accent-glow:  rgba(197, 241, 53, 0.25);
  --accent-text:  #0A0A0A;

  /* Secondary accent — purple */
  --purple:     #7C6FF7;
  --purple-dim: rgba(124, 111, 247, 0.12);

  /* Text */
  --text:       #F0F0F0;
  --text-muted: #666666;
  --text-dim:   #333333;

  /* Status */
  --success: #22C55E;
  --danger:  #EF4444;

  /* Borders */
  --border:       #1E1E1E;
  --border-light: #2C2C2C;

  /* Misc */
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  16px;
  --sidebar-w:  220px;
  --nav-h:      60px;   /* mobile bottom nav height */

  /* Fonts */
  --font-body:  'Outfit', sans-serif;
  --font-brand: 'Syne', sans-serif;
  --font-mono:  'JetBrains Mono', monospace;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ───────────────────────────────────────────── */
#app {
  display: flex;
  height: 100dvh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  flex-shrink: 0;
  z-index: 100;
}

.brand {
  font-family: var(--font-brand);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 2.5rem;
  letter-spacing: -0.02em;
}
.brand i { font-size: 1.1rem; }

.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-links li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
  user-select: none;
}
.nav-links li i {
  width: 16px;
  text-align: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}
.nav-links li:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.nav-links li.active {
  color: var(--accent);
  background: var(--accent-dim);
}
.nav-links li.active i { color: var(--accent); }

.system-status {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.system-status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  box-shadow: 0 0 6px var(--success);
}

/* ── Main Content ────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.75rem 2rem;
  min-width: 0;
}

/* Custom scrollbar */
.content::-webkit-scrollbar { width: 4px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* ── Views ───────────────────────────────────────────────── */
.view { display: none; animation: fadeUp 0.25s ease-out; }
.view.active { display: block; }

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

/* ── View Header ─────────────────────────────────────────── */
.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.view-header-left h1 {
  font-family: var(--font-brand);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.view-header-left p {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

/* Shorthand: views that use a plain <header class="view-header"> */
.view-header h1 {
  font-family: var(--font-brand);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

/* ── Home Cards ──────────────────────────────────────────── */
.cards-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 0.5rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 0% 0%, var(--accent-dim) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.card:hover::after { opacity: 1; }

.card-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 1.25rem;
  color: var(--accent);
  font-size: 1.2rem;
  border: 1px solid rgba(197,241,53,0.2);
}
.card h2 {
  font-family: var(--font-brand);
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}
.card p {
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

/* ── Panels / Workspace ──────────────────────────────────── */
.workspace {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.control-panel {
  flex: 0 0 240px;
  min-width: 200px;
}

.display-panel {
  flex: 1;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
}

/* ── Upload Zone ─────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.upload-zone:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.upload-zone i { font-size: 2rem; margin-bottom: 0.75rem; display: block; }
.upload-zone p { font-size: 0.8rem; line-height: 1.5; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  white-space: nowrap;
}
.btn.sm { width: auto; padding: 0.45rem 0.9rem; font-size: 0.8rem; }

.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
}
.btn.primary:hover { background: #D4FF3A; box-shadow: 0 0 16px var(--accent-glow); }

.btn.success {
  background: transparent;
  color: var(--success);
  border: 1px solid var(--success);
}
.btn.success:hover { background: rgba(34,197,94,0.12); }

.btn.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn.danger:hover { background: rgba(239,68,68,0.12); }

.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.btn-group { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ── Loader ──────────────────────────────────────────────── */
.loader {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--accent);
  letter-spacing: 0.05em;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 1; }
}

/* ── Result Image ────────────────────────────────────────── */
#resultImage, #streamResult {
  max-width: 100%;
  max-height: 440px;
  border-radius: var(--radius);
  display: block;
  object-fit: contain;
}

/* ── MPN Summary Bar ─────────────────────────────────────── */
.result-summary {
  display: flex;
  gap: 8px;
  margin: 1rem 0 0.75rem;
  width: 100%;
}
.summary-item {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.summary-item strong {
  font-family: var(--font-brand);
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.summary-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.summary-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

/* ── Table ───────────────────────────────────────────────── */
.table-wrapper { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  text-align: left;
}
tbody td {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }

/* ── Stream View ─────────────────────────────────────────── */
.stream-workspace { flex-direction: column; }

.video-container {
  width: 100%;
  background: #000;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 280px;
  max-height: 65vh;
}

.header-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}
.header-controls .btn { width: auto; }

.stats-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  width: 100%;
}
.stats-panel h3 {
  font-family: var(--font-brand);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

/* ── Settings ────────────────────────────────────────────── */
.settings-container { max-width: 680px; }

.settings-group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.settings-group h3 {
  font-family: var(--font-brand);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.setting-item { margin-bottom: 1.1rem; }
.setting-item:last-child { margin-bottom: 0; }

.setting-item label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-weight: 500;
}

.setting-item small {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

.setting-item select,
.setting-item input[type="range"] {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  appearance: none;
  transition: border-color 0.15s;
}
.setting-item select:focus,
.setting-item input[type="range"]:focus { border-color: var(--accent); }

.setting-item input[type="range"] {
  padding: 0;
  cursor: pointer;
  accent-color: var(--accent);
  height: 4px;
  margin-top: 0.5rem;
}

.setting-item span {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  display: inline-block;
  margin-top: 0.3rem;
}

.setting-item.checkbox label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  margin-bottom: 0;
}
.setting-item.checkbox input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Result container ────────────────────────────────────── */
.result-container { width: 100%; }

/* ============================================================
   RESPONSIVE — Mobile / Tablet (≤ 768px)
   Sidebar becomes a fixed bottom nav bar
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    width: 100%;
    height: var(--nav-h);
    flex-direction: row;
    align-items: center;
    padding: 0 0.5rem;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 200;
  }

  .brand, .system-status { display: none; }

  .nav-links {
    flex-direction: row;
    justify-content: space-around;
    width: 100%;
    gap: 0;
  }

  .nav-links li {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    border-radius: 0;
    font-size: 0.65rem;
    background: transparent !important;
  }
  .nav-links li i { font-size: 1rem; width: auto; }
  .nav-links li.active { color: var(--accent); background: transparent !important; }
  .nav-links li.active i { color: var(--accent); }

  .content {
    padding: 1rem;
    padding-bottom: calc(var(--nav-h) + 0.75rem);
    height: 100dvh;
  }

  .workspace { flex-direction: column; gap: 1rem; }
  .control-panel { flex: unset; width: 100%; min-width: unset; }
  .display-panel { min-width: unset; min-height: 200px; }

  .result-summary { flex-wrap: wrap; }
  .summary-item { flex: 1 1 calc(50% - 4px); }
  .summary-value { font-size: 0.85rem; }

  .view-header { margin-bottom: 1rem; }
  .view-header h1 { font-size: 1.3rem; }
  .view-header-left h1 { font-size: 1.3rem; }

  .settings-container { max-width: 100%; }
  .settings-group { padding: 1rem; }

  #resultImage, #streamResult { max-height: 300px; }
}

/* ============================================================
   RESPONSIVE — Small screens (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
  html { font-size: 13px; }

  .content { padding: 0.75rem; padding-bottom: calc(var(--nav-h) + 0.5rem); }

  .view-header h1,
  .view-header-left h1 { font-size: 1.2rem; }
  .view-header-left p { display: none; }
  .card p { display: none; }

  .cards-container {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }
  .card { padding: 1rem 0.75rem; }
  .card-icon { width: 36px; height: 36px; font-size: 1rem; margin-bottom: 0.75rem; }
  .card h2 { font-size: 0.85rem; }

  .panel { padding: 0.85rem; }

  .upload-zone { padding: 1.25rem 0.75rem; }
  .upload-zone i { font-size: 1.5rem; }
  .upload-zone p { font-size: 0.75rem; }

  .result-summary { gap: 5px; }
  .summary-item { padding: 0.45rem 0.6rem; }
  .summary-value { font-size: 0.8rem; }
  .summary-label { font-size: 0.62rem; }

  .settings-group { padding: 0.85rem; margin-bottom: 0.75rem; }
  .setting-item { margin-bottom: 0.85rem; }
  .setting-item small { display: none; }
}

/* ============================================================
   RESPONSIVE — RPi 3.5" LCD
   Covers both 480×320 (landscape) and 320×480 (portrait)
   ============================================================ */
@media (max-width: 480px) and (max-height: 360px),
       (max-height: 320px) {
  html { font-size: 11px; }

  :root { --nav-h: 48px; }

  .content {
    padding: 0.5rem;
    padding-bottom: calc(var(--nav-h) + 0.25rem);
    overflow-y: auto;
  }

  /* Nav — icons only, no labels */
  .nav-links li span { display: none; }
  .nav-links li { padding: 4px; }
  .nav-links li i { font-size: 1.1rem; }

  /* Home — single column small cards */
  .cards-container {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
  }
  .card { padding: 0.6rem; border-radius: var(--radius); }
  .card-icon { width: 28px; height: 28px; font-size: 0.85rem; margin-bottom: 0.4rem; }
  .card h2 { font-size: 0.75rem; }

  /* Upload — stack tightly */
  .workspace { gap: 0.5rem; }
  .upload-zone { padding: 0.75rem; }
  .upload-zone i { font-size: 1.2rem; margin-bottom: 0.3rem; }

  /* Hide non-critical elements */
  .view-header-left p,
  .stats-panel,                /* hide detection table on stream — too small */
  .setting-item small,
  .settings-group h3 i { display: none; }

  /* Stream — maximise video area */
  .video-container {
    min-height: 140px;
    max-height: 50vh;
    border-radius: var(--radius);
  }
  #streamResult { max-height: 50vh; }

  /* MPN bar — single row with tiny values */
  .result-summary { flex-wrap: nowrap; gap: 3px; margin: 0.4rem 0; }
  .summary-item { padding: 0.3rem 0.4rem; border-radius: var(--radius-sm); }
  .summary-value { font-size: 0.7rem; }
  .summary-label { display: none; }  /* label hidden; value speaks for itself */
  .summary-item strong { font-size: 0.6rem; }

  /* Tables — more compact */
  thead th, tbody td { padding: 0.3rem 0.5rem; font-size: 0.7rem; }

  /* Settings — tighter */
  .settings-group { padding: 0.6rem; margin-bottom: 0.5rem; }
  .setting-item { margin-bottom: 0.6rem; }
  .settings-group h3 { margin-bottom: 0.6rem; padding-bottom: 0.4rem; font-size: 0.7rem; }

  /* View header */
  .view-header { margin-bottom: 0.6rem; }
  .view-header h1,
  .view-header-left h1 { font-size: 1rem; }

  /* Buttons */
  .btn { padding: 0.45rem 0.75rem; font-size: 0.75rem; }
  .btn.sm { padding: 0.3rem 0.6rem; font-size: 0.7rem; }
}

/* ============================================================
   HISTORY VIEW
   ============================================================ */

/* ── Empty state ─────────────────────────────────────────── */
.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 4rem 2rem;
  color: var(--text-muted);
  text-align: center;
}
.history-empty i {
  font-size: 2.5rem;
  color: var(--text-dim);
}
.history-empty p {
  font-size: 0.875rem;
  max-width: 240px;
  line-height: 1.6;
}

/* ── Record list grid ────────────────────────────────────── */
.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

/* ── Single record card ──────────────────────────────────── */
.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s, transform 0.15s;
  position: relative;
}
.history-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
}

/* Thumbnail */
.history-thumb {
  width: 100%;
  aspect-ratio: 16 / 7;
  overflow: hidden;
  background: #000;
  flex-shrink: 0;
  position: relative;
}
.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: opacity 0.2s;
}
/* Fade-in once the image loads */
.history-thumb img.loaded { opacity: 1; }
.history-thumb img:not(.loaded) { opacity: 0; }

/* Timestamp badge over the thumbnail */
.history-thumb-badge {
  position: absolute;
  bottom: 6px;
  left: 8px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  pointer-events: none;
}

/* Card body */
.history-body {
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1;
}

/* MPN result row */
.history-mpn-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.history-pattern {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.history-mpn-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.history-mpn-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 2px;
}
.history-ci {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Tube grid — 9 dots in 3 groups of 3 */
.history-tubes {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tube-group {
  display: flex;
  gap: 4px;
}
.tube-group + .tube-group {
  padding-left: 4px;
  border-left: 1px solid var(--border-light);
}
.tube-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 600;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.tube-dot.positive {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.tube-dot.negative {
  color: var(--text-dim);
}

/* Footer: filename + delete button */
.history-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
}
.history-filename {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.history-filename i {
  margin-right: 4px;
  opacity: 0.5;
}

/* Delete button */
.btn-delete {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-body);
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-delete:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

/* ── No-MPN state (tube count ≠ 9) ──────────────────────── */
.history-mpn-none {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}
.history-tubes-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Load More button container ──────────────────────────── */
.history-loadmore {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0 1.5rem;
}
.history-loadmore .btn {
  width: auto;
  min-width: 140px;
}

/* ── Export CSV button label hide on small screens ───────── */
@media (max-width: 768px) {
  .history-list {
    grid-template-columns: 1fr;
  }
  .history-mpn-value { font-size: 1.1rem; }
}

@media (max-width: 480px) {
  .history-list { gap: 0.75rem; }

  .history-body { padding: 0.7rem 0.85rem; gap: 0.5rem; }

  .history-mpn-value { font-size: 1rem; }

  .history-thumb { aspect-ratio: 16 / 6; }

  .tube-dot { width: 15px; height: 15px; font-size: 0.55rem; }

  .history-filename { max-width: 120px; }

  /* Hide the Export CSV text label, keep icon */
  .btn-label { display: none; }
}

/* ── RPi LCD overrides ───────────────────────────────────── */
@media (max-width: 480px) and (max-height: 360px),
       (max-height: 320px) {

  /* Single column, ultra-compact cards */
  .history-list { gap: 0.4rem; }

  .history-card { border-radius: var(--radius); }

  /* Hide thumbnail on RPi — too small to be useful */
  .history-thumb { display: none; }

  .history-body { padding: 0.5rem 0.65rem; gap: 0.35rem; }

  .history-mpn-value { font-size: 0.9rem; }
  .history-ci { display: none; }     /* CI too verbose at this size */

  .tube-dot { width: 13px; height: 13px; font-size: 0.5rem; }
  .tube-group { gap: 3px; }

  .history-footer { padding: 0.4rem 0.65rem; }
  .history-filename { max-width: 90px; font-size: 0.62rem; }

  /* Empty state — compact */
  .history-empty { padding: 2rem 1rem; }
  .history-empty i { font-size: 1.5rem; }
  .history-empty p { font-size: 0.75rem; }
}

/* ============================================================
   HISTORY DETAIL MODAL
   ============================================================ */

/* ── Overlay ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.80);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

/* ── Box ─────────────────────────────────────────────────── */
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.22s ease, opacity 0.22s ease;
  opacity: 0;
}
.modal-overlay.open .modal-box {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Scrollbar inside modal */
.modal-box::-webkit-scrollbar { width: 4px; }
.modal-box::-webkit-scrollbar-track { background: transparent; }
.modal-box::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

/* ── Header ──────────────────────────────────────────────── */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
  flex-shrink: 0;
}
.modal-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}
.modal-pattern {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(197,241,53,0.2);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.modal-timestamp {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.modal-close:hover {
  color: var(--text);
  border-color: var(--border-light);
  background: var(--bg-hover);
}

/* ── Image ───────────────────────────────────────────────── */
.modal-image-wrap {
  width: 100%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.modal-image-wrap img {
  width: 100%;
  max-height: 340px;
  object-fit: contain;
  display: block;
}

/* ── MPN stat row ────────────────────────────────────────── */
.modal-mpn-row {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0.75rem 1rem;
  border-right: 1px solid var(--border);
}
.modal-stat:last-child { border-right: none; }

.modal-stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.modal-stat-value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.modal-stat-value.accent { color: var(--accent); font-size: 1.15rem; }
.modal-stat-value.filename {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Tube dots ───────────────────────────────────────────── */
.modal-tubes {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
/* Reuse .tube-group and .tube-dot from history card styles */
.modal-tubes .tube-dot {
  width: 24px;
  height: 24px;
  font-size: 0.7rem;
}

/* ── Detections table section ────────────────────────────── */
.modal-table-section {
  padding: 0.85rem 1.25rem 1.25rem;
  flex: 1;
}
.modal-section-title {
  font-family: var(--font-brand);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.6rem;
}

/* Make cards clickable */
.history-card {
  cursor: pointer;
}
/* Subtle ring on hover to signal clickability */
.history-card:hover {
  border-color: var(--border-light);
  box-shadow: 0 0 0 1px var(--border-light);
}
/* But don't propagate click from the delete button */
.history-footer .btn-delete {
  position: relative;
  z-index: 2;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .modal-box { max-height: 95dvh; border-radius: var(--radius); }
  .modal-image-wrap img { max-height: 260px; }
  .modal-stat-value.accent { font-size: 1rem; }
}

@media (max-width: 480px) {
  .modal-overlay { padding: 0.5rem; align-items: flex-end; }
  .modal-box {
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    /* Slide up from bottom on small screens */
  }
  .modal-mpn-row { flex-wrap: wrap; }
  .modal-stat {
    flex: 1 1 calc(50% - 1px);
    padding: 0.6rem 0.75rem;
  }
  .modal-image-wrap img { max-height: 200px; }
  .modal-tubes .tube-dot { width: 20px; height: 20px; font-size: 0.62rem; }
}

/* RPi LCD */
@media (max-width: 480px) and (max-height: 360px),
       (max-height: 320px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box {
    max-height: 90dvh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .modal-image-wrap img { max-height: 120px; }
  .modal-header { padding: 0.6rem 0.85rem 0.5rem; }
  .modal-stat { padding: 0.4rem 0.6rem; }
  .modal-stat-value { font-size: 0.8rem; }
  .modal-stat-value.accent { font-size: 0.9rem; }
  .modal-tubes { padding: 0.5rem 0.85rem; }
  .modal-tubes .tube-dot { width: 16px; height: 16px; font-size: 0.55rem; }
  .modal-table-section { padding: 0.6rem 0.85rem 0.85rem; }
}

/* ============================================================
   MPN GUIDELINE VIEW
   ============================================================ */

/* ── Section wrapper ─────────────────────────────────────── */
.guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.guide-section-title {
  font-family: var(--font-brand);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}
.guide-section-title i { color: var(--accent); font-size: 0.85rem; }

.guide-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 1rem;
}
.guide-text:last-child { margin-bottom: 0; }
.guide-text strong { color: var(--text); font-weight: 600; }

/* ── Positive / negative badge pills ────────────────────── */
.guide-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-mono);
}
.guide-badge.positive {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(197,241,53,0.25);
}
.guide-badge.negative {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}

/* ── Dilution diagram ────────────────────────────────────── */
.guide-dilution-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}
.guide-dilution-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.guide-dilution-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  white-space: nowrap;
}
.guide-dilution-dots {
  display: flex;
  gap: 5px;
}
.guide-dilution-note {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
}
.guide-arrow {
  color: var(--border-light);
  font-size: 0.75rem;
  flex-shrink: 0;
  margin-top: -0.5rem;
}
.guide-result-group .guide-pattern-pill {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(197,241,53,0.25);
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.1em;
}

/* ── Interpretation cards ────────────────────────────────── */
.guide-interp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.guide-interp-card {
  border-radius: var(--radius);
  padding: 1rem;
  border: 1px solid;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.guide-interp-icon { font-size: 1.1rem; margin-bottom: 0.2rem; }
.guide-interp-label {
  font-family: var(--font-brand);
  font-size: 0.85rem;
  font-weight: 700;
}
.guide-interp-range {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
}
.guide-interp-desc {
  font-size: 0.72rem;
  line-height: 1.5;
  opacity: 0.8;
  margin-top: 0.2rem;
}

/* Safe */
.guide-interp-card.safe {
  background: rgba(34, 197, 94, 0.06);
  border-color: rgba(34, 197, 94, 0.25);
  color: #22C55E;
}
/* Low */
.guide-interp-card.low {
  background: rgba(197, 241, 53, 0.06);
  border-color: rgba(197, 241, 53, 0.2);
  color: var(--accent);
}
/* Medium */
.guide-interp-card.medium {
  background: rgba(251, 146, 60, 0.07);
  border-color: rgba(251, 146, 60, 0.25);
  color: #FB923C;
}
/* High */
.guide-interp-card.high {
  background: rgba(239, 68, 68, 0.07);
  border-color: rgba(239, 68, 68, 0.25);
  color: #EF4444;
}

/* ── Reference table ─────────────────────────────────────── */
.guide-table-wrap { margin-top: 0.75rem; }

.guide-table tbody tr.risk-safe   td:first-child { border-left: 3px solid #22C55E; }
.guide-table tbody tr.risk-low    td:first-child { border-left: 3px solid var(--accent); }
.guide-table tbody tr.risk-medium td:first-child { border-left: 3px solid #FB923C; }
.guide-table tbody tr.risk-high   td:first-child { border-left: 3px solid #EF4444; }

.guide-table .risk-pill {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  font-family: var(--font-mono);
  white-space: nowrap;
}
.risk-pill.safe   { background: rgba(34,197,94,0.12);   color: #22C55E; }
.risk-pill.low    { background: rgba(197,241,53,0.10);  color: var(--accent); }
.risk-pill.medium { background: rgba(251,146,60,0.12);  color: #FB923C; }
.risk-pill.high   { background: rgba(239,68,68,0.12);   color: #EF4444; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .guide-section { padding: 1.1rem; }
  .guide-interp-grid { grid-template-columns: 1fr 1fr; }
  .guide-arrow { display: none; }
  .guide-dilution-row { gap: 0.75rem; justify-content: center; }
}

@media (max-width: 480px) {
  .guide-section { padding: 0.85rem; }
  .guide-interp-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .guide-interp-card { padding: 0.65rem; }
  .guide-interp-label { font-size: 0.75rem; }
  .guide-interp-range { font-size: 0.7rem; }
  .guide-interp-desc { display: none; }
  .guide-dilution-row { gap: 0.5rem; }
  .guide-text { font-size: 0.8rem; }
}

/* RPi LCD */
@media (max-width: 480px) and (max-height: 360px),
       (max-height: 320px) {
  .guide-section { padding: 0.6rem; margin-bottom: 0.5rem; }
  .guide-section-title { font-size: 0.75rem; margin-bottom: 0.6rem; padding-bottom: 0.4rem; }
  .guide-interp-grid { grid-template-columns: 1fr 1fr; gap: 0.35rem; }
  .guide-interp-card { padding: 0.4rem 0.5rem; }
  .guide-interp-icon { font-size: 0.8rem; }
  .guide-interp-label { font-size: 0.68rem; }
  .guide-interp-range { font-size: 0.62rem; }
  .guide-dilution-row { display: none; } /* too small for diagram */
  .guide-text { font-size: 0.72rem; line-height: 1.5; }
}

/* ============================================================
   RISK INTERPRETATION — shared across all views
   ============================================================ */

/* ── Summary bar risk item (upload + stream) ─────────────── */
/* Base state — neutral until a result arrives */
.summary-item.risk-item {
  transition: background 0.3s, border-color 0.3s;
}
.summary-item.risk-item .summary-value {
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  transition: color 0.3s;
}

/* Coloured states — applied by JS */
.summary-item.risk-safe {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.3);
}
.summary-item.risk-safe .summary-value   { color: #22C55E; }

.summary-item.risk-low {
  background: rgba(197, 241, 53, 0.08);
  border-color: rgba(197, 241, 53, 0.28);
}
.summary-item.risk-low .summary-value    { color: var(--accent); }

.summary-item.risk-medium {
  background: rgba(251, 146, 60, 0.08);
  border-color: rgba(251, 146, 60, 0.3);
}
.summary-item.risk-medium .summary-value { color: #FB923C; }

.summary-item.risk-high {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
}
.summary-item.risk-high .summary-value   { color: #EF4444; }

/* ── History card risk badge ─────────────────────────────── */
.history-mpn-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
/* reuse .risk-pill from guideline — just wire the class names */
.history-risk-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  white-space: nowrap;
  text-transform: uppercase;
}
.history-risk-badge.safe   { background: rgba(34,197,94,0.12);   color: #22C55E; }
.history-risk-badge.low    { background: rgba(197,241,53,0.10);  color: var(--accent); }
.history-risk-badge.medium { background: rgba(251,146,60,0.12);  color: #FB923C; }
.history-risk-badge.high   { background: rgba(239,68,68,0.12);   color: #EF4444; }

/* history-ci moves inside meta row */
.history-mpn-meta .history-ci {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* ── Modal risk badge (header) ───────────────────────────── */
.modal-risk-badge {
  /* inherits .risk-pill styles — class applied by JS */
  flex-shrink: 0;
}

/* ── Modal risk stat cell ────────────────────────────────── */
.modal-stat-risk { transition: background 0.25s, border-color 0.25s; }

.modal-stat-risk.risk-safe {
  background: rgba(34,197,94,0.07);
  border-bottom: 2px solid #22C55E;
}
.modal-stat-risk.risk-safe   .modal-stat-value { color: #22C55E; }

.modal-stat-risk.risk-low {
  background: rgba(197,241,53,0.07);
  border-bottom: 2px solid var(--accent);
}
.modal-stat-risk.risk-low    .modal-stat-value { color: var(--accent); }

.modal-stat-risk.risk-medium {
  background: rgba(251,146,60,0.07);
  border-bottom: 2px solid #FB923C;
}
.modal-stat-risk.risk-medium .modal-stat-value { color: #FB923C; }

.modal-stat-risk.risk-high {
  background: rgba(239,68,68,0.07);
  border-bottom: 2px solid #EF4444;
}
.modal-stat-risk.risk-high   .modal-stat-value { color: #EF4444; }

/* ── RPi LCD — hide CI from history meta, keep badge ────── */
@media (max-width: 480px) and (max-height: 360px),
       (max-height: 320px) {
  .history-mpn-meta .history-ci { display: none; }
  .history-risk-badge { font-size: 0.58rem; padding: 1px 6px; }
  .summary-item.risk-item .summary-value { font-size: 0.7rem; }
}

/* ── Camera Capture Overlay (RPi upload mode) ────────────── */
/* These overlays are toggled via style.display, not the .open class,
   so we must override .modal-overlay's opacity:0 / pointer-events:none. */
#cameraCapture,
#sourceChoiceModal {
  opacity: 1;
  pointer-events: all;
}

#cameraCapture {
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  z-index: 300;
}

#sourceChoiceModal {
  display: none;
  z-index: 400;
}

.capture-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 720px;
  padding: 16px;
}

#captureVideo {
  width: 100%;
  max-height: 60vh;
  border-radius: 10px;
  background: #000;
  object-fit: cover;
}

.capture-controls {
  display: flex;
  gap: 16px;
  justify-content: center;
  width: 100%;
}

.capture-controls .btn {
  flex: 1;
  max-width: 200px;
  padding: 14px 0;
  font-size: 1rem;
}

/* ── Source Choice Modal (RPi upload) ─────────────────────── */
.source-choice-box {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px 20px 20px;
  width: min(340px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
}

.source-choice-box h3 {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.1rem;
  color: var(--text);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.source-choice-btns {
  display: flex;
  gap: 12px;
}

.source-choice-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.source-choice-btn:hover,
.source-choice-btn:focus {
  background: var(--bg-hover);
  border-color: var(--accent);
  outline: none;
}

.source-choice-btn:active {
  transform: scale(0.97);
}

.source-choice-btn i {
  font-size: 1.8rem;
  color: var(--accent);
}

.source-choice-btn span {
  font-family: var(--font-brand);
  font-size: 0.9rem;
  font-weight: 600;
}

.source-choice-btn small {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}
/* Inference backend badge (Settings) */
.backend-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
    background: #2a2a2a;
    color: #e0e0e0;
}
.backend-badge.ok   { background: #14361b; color: #9ae6a0; }   /* NCNN — fast */
.backend-badge.warn { background: #4a3210; color: #ffcf87; }   /* PyTorch — slow */

/* ── Fixed-ROI calibration modal (jig mode) ─────────────────── */
.calib-box { max-width: 900px; }
.calib-body { padding: 0 1.25rem; }
.calib-hint { color: var(--text-muted); font-size: 0.85rem; margin: 0.5rem 0 0.75rem; }
.calib-stage {
    position: relative;
    display: inline-block;
    max-width: 100%;
    line-height: 0;              /* kill inline-image gap */
    touch-action: none;         /* let pointer-drag work on touch */
    user-select: none;
    -webkit-user-select: none;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
}
.calib-stage img { display: block; max-width: 100%; height: auto; pointer-events: none; }
.roi-box {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid var(--accent, #b6f200);
    background: rgba(182, 242, 0, 0.10);
    cursor: move;
    touch-action: none;
}
.roi-box.selected {
    border-color: #ff5d9e;
    background: rgba(255, 93, 158, 0.14);
    z-index: 3;
}
.roi-num {
    position: absolute;
    top: -1px; left: -1px;
    background: var(--accent, #b6f200);
    color: #0d0d0d;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 3px 0 4px 0;
}
.roi-box.selected .roi-num { background: #ff5d9e; color: #fff; }
.roi-handle {
    position: absolute;
    right: -7px; bottom: -7px;
    width: 14px; height: 14px;
    background: #fff;
    border: 2px solid var(--accent, #b6f200);
    border-radius: 50%;
    cursor: nwse-resize;
    touch-action: none;
}
.roi-box.selected .roi-handle { border-color: #ff5d9e; }
.calib-footer { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; padding: 1rem 1.25rem; }
