/* ============================================================
   OCR Industrial — Mobile-First SPA
   Complementa Tailwind CDN con reglas de layout full-screen.
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden {
  display: none !important;
}

/* ---- Paneles de estado ---- */

.state-panel {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: none;
  flex-direction: column;
}

.state-panel.active {
  display: flex;
}

/* ---- ESTADO A: Cámara ---- */

.camera-feed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #020617;
}

.capture-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1.5rem, env(safe-area-inset-bottom));
  background: linear-gradient(
    180deg,
    rgba(2, 6, 23, 0.72) 0%,
    rgba(2, 6, 23, 0.05) 35%,
    rgba(2, 6, 23, 0.05) 55%,
    rgba(2, 6, 23, 0.88) 100%
  );
  pointer-events: none;
}

.capture-header {
  width: 100%;
  text-align: center;
  pointer-events: none;
}

.scan-frame {
  flex: 1;
  width: min(88vw, 420px);
  max-height: 42vh;
  margin: 1rem 0;
  border: 2px solid rgba(56, 189, 248, 0.55);
  border-radius: 1rem;
  box-shadow:
    0 0 0 9999px rgba(2, 6, 23, 0.35),
    inset 0 0 24px rgba(56, 189, 248, 0.08);
}

.btn-scan {
  width: 100%;
  min-height: 56px;
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: 9999px;
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: #f8fafc;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow:
    0 10px 30px rgba(14, 165, 233, 0.35),
    0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn-scan:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-scan:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.capture-actions {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.625rem;
  width: min(92vw, 360px);
}

.btn-flash {
  min-height: 48px;
  padding: 0.75rem 1.25rem;
  border: 2px solid rgba(148, 163, 184, 0.45);
  border-radius: 9999px;
  background: rgba(15, 23, 42, 0.72);
  color: #e2e8f0;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  touch-action: manipulation;
}

.btn-flash::before {
  content: "⚡";
  margin-right: 0.4rem;
}

.btn-flash.is-active {
  border-color: #facc15;
  background: rgba(234, 179, 8, 0.22);
  color: #fef9c3;
  box-shadow: 0 0 18px rgba(250, 204, 21, 0.25);
}

.btn-flash:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-flash:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 360px) {
  .capture-actions {
    width: min(94vw, 360px);
  }

  .btn-flash {
    min-height: 44px;
    font-size: 0.875rem;
  }

  .btn-scan {
    min-height: 52px;
    font-size: 1rem;
  }
}

/* ---- ESTADO B: Revisión ---- */

.review-top {
  flex: 1 1 50%;
  min-height: 0;
  background: #020617;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #1e293b;
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0f172a;
}

.review-bottom {
  flex: 1 1 50%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #0f172a;
}

.results-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.result-text {
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  font-weight: 700;
  line-height: 1.35;
  word-break: break-word;
  color: #f1f5f9;
  margin: 0 0 0.875rem;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.strategy-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  background: #1e293b;
  border: 1px solid #334155;
  font-size: 0.75rem;
  font-weight: 600;
  color: #7dd3fc;
}

.confidence-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.confidence-value {
  font-size: 1.125rem;
  font-weight: 800;
}

.confidence-high {
  color: #4ade80;
}

.confidence-low {
  color: #fb923c;
}

.confidence-critical {
  color: #f87171;
}

.result-message {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: #94a3b8;
  line-height: 1.4;
}

.action-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.625rem;
  padding: 0.75rem 1rem max(1rem, env(safe-area-inset-bottom));
  border-top: 1px solid #1e293b;
  background: #0b1220;
}

@media (min-width: 480px) {
  .action-bar {
    grid-template-columns: repeat(3, 1fr);
  }
}

.action-btn {
  min-height: 48px;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 0.875rem;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.action-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.action-btn-primary {
  background: #16a34a;
  color: #f0fdf4;
}

.action-btn-secondary {
  background: #1d4ed8;
  color: #eff6ff;
}

.action-btn-danger {
  background: #334155;
  color: #f8fafc;
  border: 1px solid #475569;
}

/* ---- Loader ---- */

.loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(2, 6, 23, 0.82);
  backdrop-filter: blur(4px);
}

.loader-spinner {
  width: 3rem;
  height: 3rem;
  border: 3px solid rgba(148, 163, 184, 0.25);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.loader-text {
  font-size: 1rem;
  font-weight: 600;
  color: #e2e8f0;
  letter-spacing: 0.02em;
}

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

/* ---- Error de cámara ---- */

.camera-error {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  padding: 1.5rem;
}
