.main-content {
  padding: 40px 0;
  overflow-x: hidden;
}

.row {
  display: flex;
  gap: 32px;
  
  // Mobile Stacking
  @media (max-width: 768px) {
    flex-direction: column;
  }
}

.col-left {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  gap: 20px;

  @media (max-width: 768px) {
    flex: 1 1 auto;
    width: 100%;
  }
}

.col-right {
  flex: 1;
  width: 100%; // full width on mobile
}

.upload-zone {
  height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 2px dashed var(--border-color);
  cursor: pointer;
  transition: all 0.3s ease;
  
  @media (max-width: 768px) {
    height: 200px; // Shorter on mobile
  }

  @media (max-width: 480px) {
    padding: 1.5rem;
    .upload-icon { font-size: 2.5rem; }
  }
  
  &:hover {
    border-color: var(--accent-green);
    background: rgba(0, 166, 81, 0.05);
  }
  
  &.has-file {
    border-style: solid;
    border-color: var(--accent-gold);
  }
  
  &.dragging {
    border-color: var(--accent-gold);
    background: rgba(255, 215, 0, 0.1);
    transform: scale(1.02);
  }
}

.upload-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.controls {
  padding: 24px;
}

.field {
  margin-bottom: 20px;
  
  label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 600;
  }
  
  .input {
    width: 100%;
    padding: 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font-main);
    transition: background 0.3s ease, border-color 0.2s ease, color 0.3s ease;
    
    &:focus {
      outline: none;
      border-color: var(--accent-gold);
    }
  }
}

.btn-primary {
  width: 100%;
}

.results-panel {
  min-height: 500px;
  display: flex;
  flex-direction: column;
}

.panel-title {
  font-size: 1.25rem;
  margin-bottom: 24px;
  color: var(--accent-gold);
}

.no-results, .loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 60px 0;
  color: var(--text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 32px;

  @media (max-width: 768px) {
    grid-template-columns: repeat(2, 1fr); // 2 cards per row on mobile
  }

  @media (max-width: 480px) {
    grid-template-columns: 1fr; // Single column for very small phones
  }
}

.card {
  background: var(--input-bg);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background 0.3s ease, border-color 0.3s ease;
  
  .card-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
  }
  
  .card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
  }
  
  &.alert {
    border-color: var(--danger);
    background: rgba(220, 53, 69, 0.1);
    
    .card-value { color: var(--danger); }
  }
  
  &.highlight {
    border-color: var(--accent-gold);
    background: rgba(255, 215, 0, 0.05);
    
    .card-value { color: var(--accent-gold); }
  }
}

.detection-canvas-wrapper {
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  width: 100%;

  canvas {
    width: 100% !important;
    height: auto !important;
    display: block;
  }
}

// ── Engine toggle bar ──────────────────────────────────────────────────────────
.engine-toggle-bar {
  display: flex;
  gap: 8px;
  padding: 16px 20px 0;
  flex-wrap: wrap;
}

.engine-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 10px 10px 0 0;
  border: 1px solid var(--border-color);
  border-bottom: none;
  background: var(--input-bg);
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    color: var(--text-primary);
    background: var(--panel-glass);
  }

  &.active {
    background: var(--panel-glass);
    color: var(--text-primary);
    border-color: var(--accent-gold);
    color: var(--accent-gold);
  }
}

.socket-status {
  font-size: 0.75rem;
  color: #555;
  transition: color 0.3s;

  &.live { color: #00a651; }
}

// ── Three-Column Command Center (socket engine) ────────────────────────────────
.dashboard-layout {
  display: grid;
  grid-template-columns: 320px 1fr 400px;
  gap: 24px;
  align-items: start;
  min-width: 0;
  overflow-x: hidden;

  @media (max-width: 1200px) {
    grid-template-columns: 280px 1fr 340px;
    gap: 16px;
  }

  @media (max-width: 900px) {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  @media (max-width: 768px) {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.dash-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.dash-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.dash-manifest {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  min-width: 0;

  @media (max-width: 900px) {
    position: static;
    max-height: none;
  }
}

// ── Live Manifest Panel ────────────────────────────────────────────────────────
.manifest-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: calc(100vh - 140px);
  padding: 16px;
  overflow: hidden;
}

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

.manifest-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.manifest-session-id {
  font-size: 0.65rem;
  font-family: monospace;
  color: var(--text-secondary);
}

.manifest-live-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent-green);
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to   { opacity: 0.4; }
}

.manifest-empty {
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-align: center;
  padding: 24px 8px;
  line-height: 1.6;
}

.manifest-table-scroll {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.row-selected {
  background: rgba(0, 166, 81, 0.08) !important;
  outline: 1px solid rgba(0, 166, 81, 0.3);
}

// ── Backend socket mode ────────────────────────────────────────────────────────
.backend-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

.status-label {
  color: var(--text-secondary);
  font-weight: 600;
}

.status-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: #555;
  transition: all 0.3s;

  &.live {
    background: rgba(0, 166, 81, 0.1);
    border-color: #00a651;
    color: #00a651;
  }
}

.lego-note {
  font-size: 0.72rem;
  color: var(--text-secondary);
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent-gold);
  border-radius: 6px;
  padding: 10px 12px;
  line-height: 1.5;
}

.error-note {
  font-size: 0.75rem;
  color: var(--danger);
  background: rgba(220, 53, 69, 0.08);
  border: 1px solid rgba(220, 53, 69, 0.3);
  border-radius: 8px;
  padding: 10px 12px;
}

.result-summary {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
}

.summary-header {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.summary-stat {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

// ── Webcam panel ───────────────────────────────────────────────────────────────
.webcam-panel {
  min-height: 500px;
  display: flex;
  flex-direction: column;
}

.webcam-wrapper {
  position: relative;
  flex: 1;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border-color);
  display: none;

  &.active { display: block; }
}

.webcam-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

// ── Socket input mode toggle (Webcam / Gallery) ───────────────────────────────
.input-mode-toggle {
  display: flex;
  gap: 6px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 4px;
}

.input-mode-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;

  &.active {
    background: var(--panel-glass);
    color: var(--accent-gold);
    border: 1px solid var(--accent-gold);
  }

  &:hover:not(.active) {
    color: var(--text-primary);
  }
}

// ── Gallery file picker ────────────────────────────────────────────────────────
.gallery-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 2px dashed var(--border-color);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-secondary);
  transition: border-color 0.2s ease, background 0.2s ease;

  &:hover {
    border-color: var(--accent-green);
    background: rgba(0, 166, 81, 0.04);
  }

  &.has-file {
    border-style: solid;
    border-color: var(--accent-gold);
    color: var(--text-primary);
  }
}

.gallery-pick__icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

// ── Gallery batch upload zone ──────────────────────────────────────────────────
.gallery-upload-zone {
  height: auto;
  min-height: 140px;
  padding: 20px;

  p { margin: 4px 0; }
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px !important;
}

// ── Engine info / labels ───────────────────────────────────────────────────────
.engine-info {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.engine-chip {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 12px;
  background: rgba(0, 166, 81, 0.1);
  border: 1px solid rgba(0, 166, 81, 0.3);
  color: var(--accent-green);
  letter-spacing: 0.05em;
}

.engine-label {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 10px;
  letter-spacing: 0.04em;
}

.snap-btn {
  width: 100%;
}

// ── Snap result display ────────────────────────────────────────────────────────
.snap-result-wrapper {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #000;
  flex: 1;
}

.snap-canvas {
  width: 100% !important;
  height: auto !important;
  display: block;
}

.snap-overlay-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.82rem;
  gap: 12px;
}

.snap-retry {
  margin-top: 12px;
  width: 100%;
  font-size: 0.82rem;
}

// Offline banner — shown when NestJS socket is unreachable
.nest-offline-banner {
  padding: 10px 20px;
  background: rgba(220, 53, 69, 0.12);
  border: 1px solid rgba(220, 53, 69, 0.4);
  border-radius: 8px;
  color: #f8a8ae;
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 12px;
  letter-spacing: 0.02em;
}

// Disabled state for the NestJS Socket engine tab
.engine-tab.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

// ── Batch Status HUD ──────────────────────────────────────────────────────────
.batch-status-hud {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.batch-status-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

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

.batch-progress-bar {
  flex: 1;
  height: 8px;
  background: var(--input-bg, #2a2a2a);
  border-radius: 4px;
  overflow: hidden;
}

.batch-progress-fill {
  height: 100%;
  background: var(--accent, #00A651);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.abort-btn {
  white-space: nowrap;
  padding: 4px 10px;
  font-size: 12px;
  background: #DC3545;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;

  &:hover { background: #b02a37; }
}

// ── Audit Manifest Table ──────────────────────────────────────────────────
.audit-section {
  margin-top: 32px;
  padding-bottom: 40px;
}

.audit-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 12px;
}

.audit-table-wrapper {
  max-height: 420px;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  max-width: 100%;
}

.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;

  thead {
    position: sticky;
    top: 0;
    background: var(--input-bg);
    z-index: 1;

    th {
      padding: 10px 14px;
      text-align: left;
      font-size: 0.7rem;
      font-weight: 700;
      color: var(--text-secondary);
      text-transform: uppercase;
      letter-spacing: 0.06em;
      border-bottom: 1px solid var(--border-color);
    }
  }

  tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s ease;

    &:last-child { border-bottom: none; }
    &:hover { background: rgba(255, 255, 255, 0.03); }
    &.row-error { background: rgba(220, 53, 69, 0.05); }
  }

  td {
    padding: 9px 14px;
    color: var(--text-primary);
    vertical-align: middle;
  }
}

.cell-id {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-secondary);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-ms {
  font-variant-numeric: tabular-nums;
  color: var(--accent-green);
  font-size: 0.78rem;
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--input-bg);
  border: 1px solid var(--border-color);

  &.pill-ok  { border-color: var(--accent-green); color: var(--accent-green); }
  &.pill-err { border-color: var(--danger); color: var(--danger); }
}

.btn-evidence {
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-main);
  background: transparent;
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;

  &:hover { background: rgba(255, 215, 0, 0.08); }
}

// ── Evidence Drill-Down Panel ─────────────────────────────────────────────
.evidence-panel {
  margin-top: 32px;
  padding-bottom: 40px;
}

.evidence-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.evidence-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-gold);
  margin-right: 12px;
}

.evidence-id {
  font-size: 0.78rem;
  font-family: monospace;
  color: var(--text-secondary);
}

.evidence-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;

  @media (max-width: 768px) {
    grid-template-columns: 1fr;
  }
}

.evidence-block {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;

  &--full {
    grid-column: 1 / -1;
  }
}

.evidence-block-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent-green);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 10px;
}

.json-viewer {
  margin: 0;
  padding: 12px;
  background: #0d0d0d;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-family: 'Courier New', monospace;
  font-size: 0.72rem;
  color: #a8d8a8;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 260px;
  overflow-y: auto;
  line-height: 1.5;
}

// ── Batch Complete HUD ────────────────────────────────────────────────────────
.batch-complete-hud {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--accent, #00A651);
}

.batch-complete-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent, #00A651);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.batch-complete-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.bc-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;

  &.highlight .bc-value { color: var(--accent, #00A651); font-size: 18px; }
}

.bc-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bc-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #fff);

  &.ok    { color: var(--accent, #00A651); }
  &.alert { color: #DC3545; }
}

// ── Batch Complete — Ripeness Distribution ────────────────────────────────────
.bc-distribution {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.bc-dist-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.bc-dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bc-dist-name {
  font-size: 11px;
  color: var(--text-primary);
  width: 80px;
  flex-shrink: 0;
}

.bc-dist-bar-track {
  flex: 1;
  height: 8px;
  background: var(--input-bg, #2a2a2a);
  border-radius: 4px;
  overflow: hidden;
}

.bc-dist-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.bc-dist-pct {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

// ── Evidence Canvas (batch audit drill-down) ──────────────────────────────────
.evidence-canvas-wrapper {
  margin-bottom: 20px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #000;
}

.evidence-canvas {
  width: 100% !important;
  height: auto !important;
  display: block;
}
