/* Card scanner modal — full-screen overlay invoked from collection page.
   Matches the arcane theme defined in templates/deck_builder/collection.html
   (--bg-deep, --accent-primary, etc.) but degrades to standalone values
   when included on pages that don't define those vars. */

/* The native `hidden` attribute must always win over the component's own
   `display` rules (overlay, setlock panel, canvases, etc.), regardless of
   stylesheet load order. Tailwind Preflight's `[hidden]` reset has equal
   specificity to these class selectors, so whichever stylesheet loads last
   wins — which otherwise leaves the scanner modal visible on page load.
   Scanner JS opens elements by clearing `hidden`, so this never blocks them. */
[hidden] {
  display: none !important;
}

.nl-scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: rgba(8, 8, 14, 0.96);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  color: var(--text-primary, #f4f4f5);
}

.nl-scanner-shell {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  width: 100%;
  max-width: 1280px;
  height: 100%;
  background: var(--bg-deep, #0a0a0f);
}

/* Header */

.nl-scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle, #2a2a40);
}

.nl-scanner-header h2 {
  margin: 0;
  font-family: 'Cinzel Decorative', serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-primary, #f4f4f5);
}

.nl-scanner-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nl-scanner-setlock-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: transparent;
  border: 1px solid var(--border-subtle, #2a2a40);
  border-radius: 999px;
  color: var(--text-primary, #f4f4f5);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 120ms, background 120ms;
}
.nl-scanner-setlock-toggle:hover {
  border-color: var(--accent-primary, #a855f7);
}
.nl-scanner-setlock-toggle[aria-pressed="true"] {
  background: var(--accent-primary-dim, rgba(168, 85, 247, 0.15));
  border-color: var(--accent-primary, #a855f7);
  color: var(--accent-primary, #a855f7);
}
.nl-scanner-setlock-value {
  font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.nl-scanner-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle, #2a2a40);
  background: transparent;
  color: var(--text-primary, #f4f4f5);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.nl-scanner-close:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--accent-danger, #ef4444);
  color: var(--accent-danger, #ef4444);
}

/* Set-lock panel */

.nl-scanner-setlock-panel {
  padding: 12px 18px 14px;
  border-bottom: 1px solid var(--border-subtle, #2a2a40);
  background: var(--bg-surface, #12121a);
}
.nl-scanner-setlock-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-deep, #0a0a0f);
  border: 1px solid var(--border-subtle, #2a2a40);
  border-radius: 8px;
  color: var(--text-primary, #f4f4f5);
  font-size: 14px;
}
.nl-scanner-setlock-input:focus {
  outline: none;
  border-color: var(--accent-primary, #a855f7);
}
.nl-scanner-setlock-results {
  margin-top: 8px;
  background: var(--bg-deep, #0a0a0f);
  border: 1px solid var(--border-subtle, #2a2a40);
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
}
.nl-scanner-setlock-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle, #2a2a40);
}
.nl-scanner-setlock-result:last-child { border-bottom: 0; }
.nl-scanner-setlock-result:hover { background: var(--accent-primary-dim, rgba(168, 85, 247, 0.15)); }
.nl-scanner-setlock-result .code {
  font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  font-size: 12px;
  color: var(--accent-primary, #a855f7);
  letter-spacing: 0.04em;
}
.nl-scanner-setlock-hint {
  margin-top: 8px;
  font-size: 12px;
  color: rgba(244, 244, 245, 0.55);
}

/* Body — camera dominates, queue is a thin strip below.
   Mobile: camera ~78% of body height, queue ~22%, shutter overlays the camera.
   Desktop (>=900px): side-by-side, camera ~65% of width. */

.nl-scanner-body {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 4fr) minmax(0, 1fr);
  gap: 0;
  overflow: hidden;
  min-height: 0;
}

@media (min-width: 900px) {
  .nl-scanner-body {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    grid-template-rows: 1fr;
  }
}

.nl-scanner-stage-section {
  position: relative;
  background: #000;
  min-height: 0;
  overflow: hidden;
}

.nl-scanner-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

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

.nl-scanner-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.nl-scanner-frame-rect {
  fill: none;
  stroke: rgba(168, 85, 247, 0.9);
  stroke-width: 0.6;
  stroke-dasharray: 2 1;
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.7));
}

.nl-scanner-status {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  z-index: 4;
}
.nl-scanner-status[hidden] { display: none; }

/* Shutter overlay — floats at the bottom of the camera stage so the video
   can take the full section height. */
.nl-scanner-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
  pointer-events: none; /* let taps pass through except on the button itself */
  z-index: 3;
}
.nl-scanner-controls > * { pointer-events: auto; }

.nl-scanner-capture {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--accent-primary, #a855f7);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 100ms, opacity 120ms;
}
.nl-scanner-capture:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.nl-scanner-capture:not(:disabled):active {
  transform: scale(0.92);
}
.nl-scanner-capture-dot {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-primary, #a855f7);
  transition: background 120ms;
}
.nl-scanner-capture.scanning .nl-scanner-capture-dot {
  background: var(--accent-secondary, #f59e0b);
  animation: nl-scanner-pulse 1s ease-in-out infinite;
}

@keyframes nl-scanner-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.nl-scanner-controls-hint {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

/* Queue */

.nl-scanner-queue-section {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface, #12121a);
  border-top: 1px solid var(--border-subtle, #2a2a40);
  min-height: 0;
}

@media (min-width: 900px) {
  .nl-scanner-queue-section {
    border-top: 0;
    border-left: 1px solid var(--border-subtle, #2a2a40);
  }
}

.nl-scanner-queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle, #2a2a40);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(244, 244, 245, 0.65);
}
.nl-scanner-queue-count {
  font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  font-weight: 600;
  color: var(--accent-primary, #a855f7);
}

.nl-scanner-queue {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.nl-scanner-queue-empty {
  padding: 30px 20px;
  text-align: center;
  font-size: 13px;
  color: rgba(244, 244, 245, 0.5);
}

.nl-scanner-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: start;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle, #2a2a40);
  border-left: 3px solid transparent;
  position: relative;
}
.nl-scanner-row.match-set { border-left-color: var(--accent-success, #22c55e); }
.nl-scanner-row.match-name { border-left-color: var(--accent-secondary, #f59e0b); }
.nl-scanner-row.match-fuzzy { border-left-color: var(--accent-secondary, #f59e0b); }
.nl-scanner-row.match-none { border-left-color: var(--accent-danger, #ef4444); background: rgba(239, 68, 68, 0.04); }

.nl-scanner-row-thumb {
  width: 56px;
  height: 78px;
  border-radius: 4px;
  background: #000;
  object-fit: cover;
  display: block;
}
.nl-scanner-row-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.4);
  font-size: 20px;
  background: var(--bg-elevated, #1a1a28);
}

.nl-scanner-row-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nl-scanner-row-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #f4f4f5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nl-scanner-row-sub {
  font-size: 11.5px;
  color: rgba(244, 244, 245, 0.6);
  font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
.nl-scanner-row-source-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.match-set .nl-scanner-row-source-badge { background: rgba(34, 197, 94, 0.18); color: var(--accent-success, #22c55e); }
.match-name .nl-scanner-row-source-badge,
.match-fuzzy .nl-scanner-row-source-badge { background: rgba(245, 158, 11, 0.18); color: var(--accent-secondary, #f59e0b); }
.match-none .nl-scanner-row-source-badge { background: rgba(239, 68, 68, 0.18); color: var(--accent-danger, #ef4444); }

.nl-scanner-row-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.nl-scanner-foil {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: rgba(244, 244, 245, 0.6);
  cursor: pointer;
  user-select: none;
}
.nl-scanner-foil input { accent-color: var(--accent-primary, #a855f7); }

.nl-scanner-row-delete {
  background: transparent;
  border: 1px solid var(--border-subtle, #2a2a40);
  color: rgba(244, 244, 245, 0.55);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  cursor: pointer;
}
.nl-scanner-row-delete:hover {
  border-color: var(--accent-danger, #ef4444);
  color: var(--accent-danger, #ef4444);
}

/* Autocomplete rescue on ❌ rows */
.nl-scanner-rescue {
  grid-column: 1 / -1;
  margin-top: 6px;
  position: relative;
}
.nl-scanner-rescue-input {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-deep, #0a0a0f);
  border: 1px solid var(--border-subtle, #2a2a40);
  border-radius: 6px;
  color: var(--text-primary, #f4f4f5);
  font-size: 13px;
}
.nl-scanner-rescue-input:focus {
  outline: none;
  border-color: var(--accent-primary, #a855f7);
}
.nl-scanner-rescue-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--bg-elevated, #1a1a28);
  border: 1px solid var(--border-subtle, #2a2a40);
  border-radius: 6px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 10;
}
.nl-scanner-rescue-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle, #2a2a40);
}
.nl-scanner-rescue-result:last-child { border-bottom: 0; }
.nl-scanner-rescue-result:hover { background: var(--accent-primary-dim, rgba(168, 85, 247, 0.15)); }
.nl-scanner-rescue-result-thumb {
  width: 32px;
  height: 44px;
  border-radius: 3px;
  background: #000;
  object-fit: cover;
}
.nl-scanner-rescue-result-meta {
  font-size: 12px;
  min-width: 0;
}
.nl-scanner-rescue-result-name {
  font-weight: 600;
  color: var(--text-primary, #f4f4f5);
}
.nl-scanner-rescue-result-sub {
  color: rgba(244, 244, 245, 0.55);
  font-family: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  font-size: 10.5px;
}

/* Footer */

.nl-scanner-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-subtle, #2a2a40);
  background: var(--bg-surface, #12121a);
}
.nl-scanner-destination {
  font-size: 12px;
  color: rgba(244, 244, 245, 0.65);
}
.nl-scanner-commit {
  padding: 10px 20px;
  background: var(--accent-primary, #a855f7);
  border: 0;
  border-radius: 8px;
  color: #0a0a0f;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 120ms, opacity 120ms;
}
.nl-scanner-commit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.nl-scanner-commit:not(:disabled):hover {
  background: #c084fc;
}

/* Lock body scroll while overlay is open. Applied via JS toggling .nl-scanner-locked on <html>. */
html.nl-scanner-locked,
html.nl-scanner-locked body {
  overflow: hidden;
}
