/* Custom Modern Design System & CSS Styling */

:root {
  /* HSL Color Palette - Dark Slate & Glassmorphic Base */
  --bg-app: hsl(224, 71%, 4%);
  --bg-panel: rgba(15, 23, 42, 0.6);
  --bg-panel-hover: rgba(30, 41, 59, 0.85);
  --bg-panel-active: rgba(51, 65, 85, 0.5);
  
  --border-light: rgba(255, 255, 255, 0.08);
  --border-focus: hsl(217, 91%, 60%);
  
  /* Text Colors */
  --text-primary: hsl(210, 40%, 98%);
  --text-secondary: hsl(215, 20%, 65%);
  --text-muted: hsl(215, 16%, 47%);
  
  /* Tri-Color Status Designators */
  --status-pass: hsl(142, 70%, 45%);
  --status-warn: hsl(38, 92%, 50%);
  --status-fail: hsl(350, 89%, 60%);
  
  --status-pass-bg: rgba(16, 185, 129, 0.12);
  --status-warn-bg: rgba(245, 158, 11, 0.12);
  --status-fail-bg: rgba(239, 68, 68, 0.12);

  /* Fonts */
  --font-primary: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  /* Layout Dimensions */
  --header-height: 56px;
}

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

body {
  font-family: var(--font-primary);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* App Header Styling */
.app-header {
  height: var(--header-height);
  background-color: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-logo {
  width: 24px;
  height: 24px;
  color: var(--border-focus);
}

.logo-text {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo-sub {
  font-family: var(--font-primary);
  font-weight: 300;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.system-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: rgba(255, 255, 255, 0.03);
  padding: 6px 12px;
  border-radius: 9999px;
  border: 1px solid var(--border-light);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-indicator.online {
  background-color: var(--status-pass);
  box-shadow: 0 0 8px var(--status-pass);
}

.status-text {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Core Workspace Panels Layout */
.workspace-container {
  display: grid;
  grid-template-columns: 340px 1fr 420px;
  height: calc(100vh - var(--header-height));
  width: 100%;
  overflow: hidden;
}

/* General Panel Architecture */
.panel {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-light);
  height: 100%;
  overflow: hidden;
}

.panel:last-child {
  border-right: none;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  background-color: rgba(15, 23, 42, 0.4);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.2px;
}

.panel-content {
  flex-grow: 1;
  overflow-y: auto;
}

/* Custom Thin Scrollbar */
.panel-content::-webkit-scrollbar,
.form-scroller::-webkit-scrollbar {
  width: 6px;
}

.panel-content::-webkit-scrollbar-track,
.form-scroller::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb,
.form-scroller::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.panel-content::-webkit-scrollbar-thumb:hover,
.form-scroller::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* --- PANEL 1: TRIAGE SIDEBAR --- */
.panel-triage {
  flex-shrink: 0;
}

.panel-triage .panel-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-box {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  background-color: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 12px 8px 36px;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 0.85rem;
  outline: none;
  transition: all 0.2s ease;
}

.search-box input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.filter-tabs {
  display: flex;
  gap: 4px;
  background-color: rgba(0, 0, 0, 0.2);
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

.filter-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 6px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.filter-tab.active {
  background-color: var(--bg-panel-active);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.triage-list {
  padding: 8px 0;
}

.triage-item {
  display: flex;
  flex-direction: column;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.triage-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  transition: all 0.2s ease;
}

.triage-item.status-autopass::before { background-color: var(--status-pass); }
.triage-item.status-warn::before { background-color: var(--status-warn); }
.triage-item.status-fail::before { background-color: var(--status-fail); }

.triage-item:hover {
  background-color: var(--bg-panel-hover);
}

.triage-item.active {
  background-color: var(--bg-panel-active);
}

.triage-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.triage-id {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.triage-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.triage-badge.badge-autopass {
  background-color: var(--status-pass-bg);
  color: var(--status-pass);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.triage-badge.badge-warn {
  background-color: var(--status-warn-bg);
  color: var(--status-warn);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.triage-badge.badge-fail {
  background-color: var(--status-fail-bg);
  color: var(--status-fail);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.triage-item-body {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.triage-brand {
  font-weight: 500;
  color: var(--text-primary);
}

.triage-time {
  color: var(--text-muted);
}

/* --- PANEL 2: INTERACTIVE LABEL EXPLORER --- */
.panel-explorer {
  background-color: hsl(224, 71%, 2%);
}

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

.carousel-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: rgba(255, 255, 255, 0.03);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

.btn-carousel {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.btn-carousel:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.carousel-indicator {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  min-width: 90px;
  text-align: center;
}

.explorer-viewport {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

/* Pinned Performance Metrics HUD */
.metrics-hud {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  background-color: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 10px 20px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.metric-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.metric-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--border-focus);
}

.metric-divider {
  width: 1px;
  height: 24px;
  background-color: var(--border-light);
}

/* Label Display Viewport Box */
.image-display-container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 50px; /* Leave space for HUD */
}

.label-view-box {
  position: relative;
  width: 95%;
  max-width: 680px;
  height: calc(100vh - 220px);
  max-height: 720px;
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Wraps the SVG wine label graphics */
.label-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
}

.label-wrapper svg {
  width: auto;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Bounding box absolute coordinate overlay */
.coordinate-overlay-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Let pointer events fall through to the image */
}

/* Individual bounding boxes from 0-1000 scale */
.bounding-box-highlight {
  position: absolute;
  pointer-events: auto; /* Active for hover events */
  border: 1.5px dashed var(--status-warn);
  background-color: rgba(59, 130, 246, 0.08);
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 5;
}

.bounding-box-highlight:hover,
.bounding-box-highlight.active {
  border: 1.5px solid var(--border-focus);
  background-color: rgba(59, 130, 246, 0.22);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.5);
  z-index: 20;
}

/* --- PANEL 3: TTB FORM 5100.31 --- */
.panel-form {
  position: relative;
  background-color: var(--bg-panel);
}

.panel-form .panel-header {
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 14px;
}

.form-sub-header {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  display: block;
  margin-top: 2px;
}

.form-scroller {
  padding: 20px;
  padding-bottom: 80px; /* Leave space for bottom bar */
  overflow-y: auto;
}

.compliance-form {
  display: flex;
  flex-direction: column;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: stretch; /* Stretch cell items to equal height in each row */
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.form-field.full-width {
  grid-column: span 2;
}

.form-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}

.form-field input,
.form-field select,
.form-field textarea {
  margin-top: auto; /* Push inputs to the bottom for perfect baseline alignment */
  width: 100%;
  background-color: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 0.85rem;
  outline: none;
  transition: all 0.2s ease;
}

.form-field textarea {
  resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
  background-color: rgba(0, 0, 0, 0.35);
}

/* Highlighting field container when user hovers bounding box */
.form-field.highlighted {
  border-color: var(--border-focus);
  background-color: rgba(59, 130, 246, 0.05);
}

/* Administrative Action Bar Bottom Dock */
.admin-action-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 68px;
  background-color: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
  gap: 10px;
}

.btn {
  font-family: var(--font-primary);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-action-reject {
  background-color: var(--status-fail-bg);
  color: var(--status-fail);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-action-reject:hover {
  background-color: var(--status-fail);
  color: #fff;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.3);
}

.btn-action-correct {
  background-color: var(--status-warn-bg);
  color: var(--status-warn);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.btn-action-correct:hover {
  background-color: var(--status-warn);
  color: #000;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}

.btn-action-approve {
  background-color: var(--status-pass-bg);
  color: var(--status-pass);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.btn-action-approve:hover {
  background-color: var(--status-pass);
  color: #fff;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
}

/* Toast Notification Panels */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background-color: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateX(120%);
  animation: slideIn 0.3s forwards cubic-bezier(0.4, 0, 0.2, 1);
}

.toast-icon {
  width: 16px;
  height: 16px;
}

.toast.toast-success {
  border-color: var(--status-pass);
}
.toast.toast-success .toast-icon {
  color: var(--status-pass);
}

.toast.toast-warning {
  border-color: var(--status-warn);
}
.toast.toast-warning .toast-icon {
  color: var(--status-warn);
}

.toast.toast-error {
  border-color: var(--status-fail);
}
.toast.toast-error .toast-icon {
  color: var(--status-fail);
}

@keyframes slideIn {
  to { transform: translateX(0); }
}

.toast.fade-out {
  opacity: 0;
  transform: translateY(-20px);
  transition: all 0.3s ease;
}

/* Scaling Layout Checks for Government Displays & 150% Scale */
@media (max-width: 1200px) {
  .workspace-container {
    grid-template-columns: 280px 1fr 360px;
  }
}

@media (max-height: 850px) {
  .label-view-box {
    height: calc(100vh - 180px);
    max-height: 580px;
  }
  .image-display-container {
    margin-top: 40px;
  }
}

/* --- CLIENT-SIDE REGULATORY VALIDATION STYLING --- */
.form-field.validation-pass input,
.form-field.validation-pass select,
.form-field.validation-pass textarea {
  border-color: var(--status-pass) !important;
  background-color: rgba(16, 185, 129, 0.06) !important;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.15);
}

.form-field.validation-fail input,
.form-field.validation-fail select,
.form-field.validation-fail textarea {
  border-color: var(--status-fail) !important;
  background-color: rgba(239, 68, 68, 0.06) !important;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.15);
}

/* Hover Validation Tooltip Styles */
.validation-tooltip {
  font-family: var(--font-primary);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
  border-radius: 6px;
  animation: tooltipFadeIn 0.15s forwards cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* --- MILESTONE 4: CIRCUIT BREAKER & ERROR BOUNDARY STYLING --- */

/* Full-width caution banner */
.circuit-breaker-banner {
  background-color: var(--status-warn-bg);
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--status-warn);
  padding: 10px 24px;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  z-index: 90;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.2px;
}

/* Panel 3 Header Warning State */
.panel-form .panel-header.warning-state {
  background-color: rgba(245, 158, 11, 0.08) !important;
  border-bottom: 1px solid rgba(245, 158, 11, 0.3) !important;
}

.panel-form .panel-header.warning-state h2 {
  color: var(--status-warn) !important;
}

/* Override Checkbox styling inside Action Bar */
.override-checkbox-container {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--status-warn);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 4px;
  background-color: rgba(245, 158, 11, 0.05);
  border: 1px solid rgba(245, 158, 11, 0.2);
  margin-right: auto; /* Float left of other buttons */
}

.override-checkbox-container input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--status-warn);
}

.override-checkbox-container label {
  cursor: pointer;
  user-select: none;
}

/* Disabled button lock styling */
.btn-action-approve:disabled {
  opacity: 0.35 !important;
  background-color: rgba(255, 255, 255, 0.03) !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  color: var(--text-muted) !important;
  cursor: not-allowed !important;
  box-shadow: none !important;
}

.btn-action-approve:disabled:hover {
  background-color: rgba(255, 255, 255, 0.03) !important;
  color: var(--text-muted) !important;
  box-shadow: none !important;
}

/* Ingestion Controls inside Panel 1 */
.ingestion-controls {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn-ingest {
  flex: 1;
  background-color: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-ingest:hover {
  background-color: rgba(59, 130, 246, 0.15);
  border-color: var(--border-focus);
  color: #fff;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.25);
}

.btn-ingest svg {
  width: 13px;
  height: 13px;
  transition: transform 0.2s ease;
}

.btn-ingest:hover svg {
  transform: translateY(-1px);
}

/* Panel 2 HUD Floating Tooltip Overlay Width Restraint */
.hud-tooltip {
  position: absolute;
  z-index: 10000;
  background-color: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-focus);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  color: var(--text-primary);
  max-width: 450px; /* Strict physical horizontal constraint */
  width: max-content;
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
