/**
 * Fullscreen barcode / QR scanner — mobile owner only (desktop unchanged).
 */

#hydraBarcodeScanner {
  position: fixed;
  inset: 0;
  z-index: var(--z-scanner);
  display: flex;
  align-items: stretch;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease, visibility 0s linear 220ms;
}

#hydraBarcodeScanner.hydra-scan-open {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
  transition: opacity 220ms ease, visibility 0s linear 0s;
}

#hydraBarcodeScanner .hydra-scan-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.82);
  backdrop-filter: blur(10px);
}

#hydraBarcodeScanner .hydra-scan-panel {
  position: relative;
  width: 100%;
  max-width: 100vw;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #0b1220;
  color: #f8fafc;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: box-shadow 280ms ease;
}

#hydraBarcodeScanner .hydra-scan-panel.hydra-scan-panel--success {
  box-shadow: inset 0 0 0 2px rgba(34, 197, 94, 0.65);
}

#hydraBarcodeScanner .hydra-scan-head {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

#hydraBarcodeScanner .hydra-scan-close {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  background: rgba(30, 41, 59, 0.85);
  color: #e2e8f0;
}

#hydraBarcodeScanner .hydra-scan-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
  padding-right: 56px;
}

#hydraBarcodeScanner .hydra-scan-stage {
  position: relative;
  flex: 1;
  min-height: min(52vh, 420px);
  overflow: hidden;
  background: #020617;
}

#hydraBarcodeScanner .hydra-scan-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#hydraBarcodeScanner .hydra-scan-reader-slot {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#hydraBarcodeScanner .hydra-scan-reader-slot:not(.hydra-scan-reader-active) {
  display: none;
}

#hydraBarcodeScanner .hydra-scan-video:not(.hydra-scan-video-active) {
  display: none;
}

#hydraBarcodeScanner .hydra-scan-frame {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  width: min(72vw, 280px);
  height: min(72vw, 280px);
  max-height: 46vh;
  border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.38);
  pointer-events: none;
}

#hydraBarcodeScanner .hydra-scan-line {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  width: min(68vw, 260px);
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(96, 165, 250, 0.35), transparent);
  animation: hydra-scan-line-move 2.4s ease-in-out infinite;
  pointer-events: none;
  opacity: 0.85;
}

@keyframes hydra-scan-line-move {
  0%,
  100% {
    transform: translate(-50%, calc(-50% - 96px));
    opacity: 0.35;
  }

  50% {
    transform: translate(-50%, calc(-50% + 96px));
    opacity: 0.95;
  }
}

@media (prefers-reduced-motion: reduce) {
  #hydraBarcodeScanner .hydra-scan-line {
    animation: none;
    top: 46%;
    transform: translate(-50%, -50%);
  }
}

#hydraBarcodeScanner .hydra-scan-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  margin: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: rgba(226, 232, 240, 0.82);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

#hydraBarcodeScanner .hydra-scan-footer {
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.2), rgba(15, 23, 42, 0.96));
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}

#hydraBarcodeScanner .hydra-scan-foot-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

#hydraBarcodeScanner .hydra-scan-foot-btn {
  flex: 1;
  border: 0;
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  background: rgba(30, 41, 59, 0.95);
  color: #e2e8f0;
}

#hydraBarcodeScanner .hydra-scan-foot-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#hydraBarcodeScanner .hydra-scan-manual {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#hydraBarcodeScanner .hydra-scan-manual input {
  flex: 1;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.65);
  color: #f8fafc;
}

#hydraBarcodeScanner .hydra-scan-manual button {
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
}

#hydraBarcodeScanner .hydra-scan-status {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.95);
  text-align: center;
}

body.hydra-scan-active {
  overflow: hidden;
}

/* Post-scan / error bottom sheets (inside scanner root) */
#hydraBarcodeScanner .hydra-scan-sub-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: calc(var(--z-scanner) + 5);
  max-height: min(78vh, 520px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
}

#hydraBarcodeScanner .hydra-scan-sub-host:not([hidden]) {
  pointer-events: auto;
}

#hydraBarcodeScanner .hydra-scan-sub-host[hidden] {
  display: none !important;
}

#hydraBarcodeScanner .hydra-scan-sheet {
  margin: 0 auto;
  width: 100%;
  max-width: 100vw;
  border-radius: 20px 20px 0 0;
  background: #f8fafc;
  color: #0f172a;
  padding: 10px 14px calc(16px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -12px 40px rgba(2, 6, 23, 0.35);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-bottom: 0;
  animation: hydra-scan-sheet-up 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes hydra-scan-sheet-up {
  from {
    transform: translateY(18px);
    opacity: 0.85;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

#hydraBarcodeScanner .hydra-scan-sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.45);
  margin: 4px auto 10px;
}

#hydraBarcodeScanner .hydra-scan-sheet-title {
  font-size: 16px;
  font-weight: 850;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  line-height: 1.25;
}

#hydraBarcodeScanner .hydra-scan-sheet-code {
  font-size: 12px;
  font-weight: 700;
  color: #475569;
  font-family: ui-monospace, monospace;
  margin-bottom: 10px;
  word-break: break-all;
}

#hydraBarcodeScanner .hydra-scan-sheet-meta {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  line-height: 1.45;
  margin-bottom: 12px;
}

#hydraBarcodeScanner .hydra-scan-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#hydraBarcodeScanner .hydra-scan-sheet-actions .hydra-scan-sheet-btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  background: #e2e8f0;
  color: #0f172a;
}

#hydraBarcodeScanner .hydra-scan-sheet-actions .hydra-scan-sheet-btn--primary {
  background: #2563eb;
  color: #fff;
}

#hydraBarcodeScanner .hydra-scan-sheet-actions .hydra-scan-sheet-btn--ghost {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.55);
  font-weight: 700;
}

#hydraBarcodeScanner .hydra-scan-camera-perm-hint {
  display: none;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.45;
  color: rgba(226, 232, 240, 0.92);
  text-align: center;
  padding: 8px 4px 0;
}

#hydraBarcodeScanner.hydra-scan-perm-denied .hydra-scan-camera-perm-hint {
  display: block;
}

#hydraBarcodeScanner .hydra-scan-manual-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#hydraBarcodeScanner .hydra-scan-manual-primary {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}

#hydraBarcodeScanner .hydra-scan-manual {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

#hydraBarcodeScanner .hydra-scan-history {
  max-height: 132px;
  overflow-y: auto;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

#hydraBarcodeScanner .hydra-scan-history-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.95);
  padding: 8px 10px 4px;
}

#hydraBarcodeScanner .hydra-scan-history-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-top: 1px solid rgba(51, 65, 85, 0.45);
  cursor: pointer;
  text-align: left;
  width: 100%;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  background: transparent;
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 650;
}

#hydraBarcodeScanner .hydra-scan-history-item:first-of-type {
  border-top: 0;
}

#hydraBarcodeScanner .hydra-scan-history-item:active {
  background: rgba(51, 65, 85, 0.35);
}

#hydraBarcodeScanner .hydra-scan-history-code {
  font-family: ui-monospace, monospace;
  font-weight: 800;
  color: #f8fafc;
}

#hydraBarcodeScanner .hydra-scan-history-meta {
  font-size: 11px;
  color: rgba(148, 163, 184, 0.95);
  margin-top: 2px;
}

#hydraBarcodeScanner .hydra-scan-history-time {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  color: rgba(148, 163, 184, 0.85);
}

#hydraBarcodeScanner .hydra-scan-attach-list {
  max-height: 160px;
  overflow-y: auto;
  margin-bottom: 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: #fff;
}

#hydraBarcodeScanner .hydra-scan-attach-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
  font-size: 13px;
  font-weight: 650;
  color: #0f172a;
  cursor: pointer;
}

#hydraBarcodeScanner .hydra-scan-attach-row:last-child {
  border-bottom: 0;
}

#hydraBarcodeScanner .hydra-scan-attach-search {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 8px;
  box-sizing: border-box;
}

/* Products table flash after scan */
tr.hydra-scan-row-flash {
  animation: hydra-scan-row-flash 0.95s ease;
}

@keyframes hydra-scan-row-flash {
  0% {
    background-color: rgba(59, 130, 246, 0.28);
  }

  100% {
    background-color: transparent;
  }
}

/* POS — scan button: mobile only */
@media (max-width: 768px) {
  #modal .modal-card.pos-modal .pos-product-search-row {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 8px;
    align-items: stretch;
  }

  #modal .modal-card.pos-modal .pos-barcode-scan-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-height: 40px;
    padding: 0;
    border-radius: 11px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
  }

  #modal .modal-card.pos-modal .pos-barcode-scan-btn:active {
    transform: scale(0.97);
  }
}

@media (min-width: 769px) {
  #modal .modal-card.pos-modal .pos-barcode-scan-btn {
    display: none !important;
  }

  #modal .modal-card.pos-modal .pos-product-search-row {
    display: block;
  }
}
