/* ==========================================================================
   Interactive Bounding Box Selector & Overlay Styles - ScanMan
   ========================================================================== */

/* The overlay layer sitting directly on top of the document page */
.bounding-box-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* individual boxes receive events */
  z-index: 10;
}

/* Crosshair mode when "Draw Box" is active */
.doc-canvas-wrapper.drawing-mode {
  cursor: crosshair !important;
}

.doc-canvas-wrapper.drawing-mode * {
  cursor: crosshair !important;
}

/* Individual Bounding Box */
.bbox-item {
  position: absolute;
  pointer-events: auto;
  border: 2px solid var(--box-cyan);
  background-color: var(--box-cyan-bg);
  border-radius: 3px;
  cursor: move;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}

.bbox-item:hover {
  border-color: #ffffff;
  background-color: rgba(56, 189, 248, 0.22);
  box-shadow: 0 0 14px var(--accent-cyan-glow);
}

/* Active / Focused Bounding Box */
.bbox-item.active {
  border-color: #ffffff;
  background-color: rgba(56, 189, 248, 0.28);
  box-shadow: 0 0 20px var(--accent-cyan-glow), inset 0 0 10px rgba(56, 189, 248, 0.2);
  z-index: 25;
}

/* Emerald Box when field is mathematically balanced */
.bbox-item.balanced {
  border-color: var(--box-emerald);
  background-color: var(--box-emerald-bg);
}
.bbox-item.balanced.active {
  border-color: #ffffff;
  box-shadow: 0 0 20px var(--accent-emerald-glow);
}

/* Amber Box when field is flagged or has a discrepancy */
.bbox-item.flagged {
  border-color: var(--box-amber);
  background-color: var(--box-amber-bg);
}
.bbox-item.flagged.active {
  border-color: #ffffff;
  box-shadow: 0 0 20px var(--accent-amber-glow);
}

/* Box Label Tag (Floating chip attached to box top-left) */
.bbox-tag {
  position: absolute;
  bottom: 100%;
  left: -2px;
  margin-bottom: 2px;
  padding: 0.15rem 0.45rem;
  background: var(--bg-app);
  color: #fff;
  border: 1px solid var(--box-cyan);
  border-radius: var(--radius-sm);
  font-size: 0.65rem;
  font-family: var(--font-mono);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.bbox-item:hover .bbox-tag,
.bbox-item.active .bbox-tag {
  opacity: 1;
  background: var(--accent-cyan);
  color: var(--text-inverse);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   8 Interactive Resize Handles
   ========================================================================== */
.bbox-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 1.5px solid var(--accent-cyan);
  border-radius: 2px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.6);
  display: none; /* only visible on active box */
  pointer-events: auto;
  z-index: 30;
}

.bbox-item.active .bbox-handle {
  display: block;
}

/* 8 Directions positioning */
.handle-nw { top: -5px; left: -5px; cursor: nwse-resize; }
.handle-n  { top: -5px; left: calc(50% - 4.5px); cursor: ns-resize; }
.handle-ne { top: -5px; right: -5px; cursor: nesw-resize; }
.handle-e  { top: calc(50% - 4.5px); right: -5px; cursor: ew-resize; }
.handle-se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.handle-s  { bottom: -5px; left: calc(50% - 4.5px); cursor: ns-resize; }
.handle-sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.handle-w  { top: calc(50% - 4.5px); left: -5px; cursor: ew-resize; }

.bbox-handle:hover {
  background: var(--accent-cyan);
  border-color: #fff;
  transform: scale(1.25);
}

/* ==========================================================================
   Floating Action Popover
   ========================================================================== */
.bbox-popover {
  position: absolute;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.65rem;
  background: rgba(14, 21, 38, 0.95);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg), 0 0 25px rgba(0, 0, 0, 0.8);
  font-size: var(--font-xs);
  pointer-events: auto;
  transform: translate(-50%, -100%);
  margin-top: -12px;
  animation: popoverFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -90%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -100%) scale(1);
  }
}

/* Popover Arrow */
.bbox-popover::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px 6px 0 6px;
  border-style: solid;
  border-color: rgba(14, 21, 38, 0.95) transparent transparent transparent;
}

.popover-select {
  padding: 0.35rem 0.6rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: var(--font-xs);
  outline: none;
  cursor: pointer;
}

.popover-select:focus {
  border-color: var(--accent-cyan);
}

.popover-apply-btn {
  padding: 0.35rem 0.75rem;
  background: var(--accent-cyan);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-inverse);
  font-weight: 700;
  font-size: var(--font-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.popover-apply-btn:hover {
  background: var(--accent-cyan-light);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

.popover-delete-btn {
  padding: 0.35rem 0.5rem;
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-rose-light);
  font-size: var(--font-xs);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.popover-delete-btn:hover {
  background: rgba(244, 63, 94, 0.35);
  color: #fff;
}
