/* ============================================================
   VARIABLES Y CONFIGURACIÓN BASE
   ============================================================ */
:root {
  --azul-oscuro: #1a3a63;
  --azul-medio: #2c5282;
  --amarillo-tienda: #f6ad55;
  --amarillo-hover: #ed8936;
  --blanco: #ffffff;
  --gris-fondo: #f7fafc;
  --gris-texto: #4a5568;
  --gris-suave: #e2e8f0;
  --color-exito: #48bb78;
  --color-error: #f56565;
  --color-stock-bajo: #ed8936;
  --sombra-suave: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --sombra-card: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radio-m: 12px;
  --radio-s: 8px;
  --fuente-principal: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--fuente-principal);
  background-color: var(--gris-fondo);
  color: var(--gris-texto);
  line-height: 1.5;
  padding: 0;
}

/* ============================================================
   HEADER
   ============================================================ */
header#encabezado {
  background: linear-gradient(135deg, var(--azul-oscuro) 0%, var(--azul-medio) 100%);
  color: var(--blanco);
  padding: 20px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border-bottom: 4px solid var(--amarillo-tienda);
  box-shadow: var(--sombra-suave);
  margin-bottom: 24px;
}

#logo_tienda {
  width: 55px; height: 55px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--blanco);
  box-shadow: var(--sombra-suave);
  transition: transform 0.3s ease;
}

#logo_tienda:hover { transform: scale(1.05); }

#logo_imagen {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--blanco);
  box-shadow: var(--sombra-suave);
}

header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  text-transform: uppercase;
  background: linear-gradient(120deg, var(--blanco) 60%, var(--amarillo-tienda) 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ============================================================
   CONTENEDOR PRINCIPAL
   ============================================================ */
main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 500px;
  margin: 0 auto;
  padding: 0 16px 40px 16px;
}

/* ============================================================
   STATUS
   ============================================================ */
.status {
  background: var(--blanco);
  padding: 10px 16px;
  border-radius: var(--radio-s);
  border: 1px solid var(--gris-suave);
  font-size: 0.9rem;
  color: var(--azul-oscuro);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--sombra-suave);
}

.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background-color: var(--gris-texto);
  transition: background-color 0.3s ease;
}
.dot.active { background-color: var(--color-exito); animation: pulse 1.5s infinite; }
.dot.error  { background-color: var(--color-error); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(72,187,120,0.7); }
  70%  { box-shadow: 0 0 0 10px rgba(72,187,120,0); }
  100% { box-shadow: 0 0 0 0 rgba(72,187,120,0); }
}

/* ============================================================
   CÁMARA
   ============================================================ */
.cam-card {
  background: #111;
  border-radius: var(--radio-m);
  overflow: hidden;
  position: relative;
}

#reader { width: 100%; }

.cam-overlay {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  z-index: 10;
  pointer-events: none;
}

.scan-frame {
  width: 280px; height: 130px;
  border: 2px dashed var(--amarillo-tienda);
  border-radius: var(--radio-s);
  position: relative;
  background: transparent;
}

.scan-line { display: none; }

/* ============================================================
   BOTONES
   ============================================================ */
.controls { 
  gap: 12px; 
  justify-content: center;
  justify-items: auto;
  display: flex;
  align-items: center;
}

.top-row { 
  display: flex; 
  gap: 12px; 
  justify-content: center;
  justify-items: auto;
  flex-wrap: wrap;
}

.btn {
  min-width: 200px;
  padding: 16px 28px;
  border: none;
  border-radius: var(--radio-s);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--sombra-suave);
}
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-start  { background-color: var(--color-exito); color: var(--blanco); flex: 1; font-size: 1.1rem; }
.btn-start:hover { background-color: #38a169; }
.btn-stop   { background-color: var(--color-error); color: var(--blanco); flex: 1; }
.btn-stop:hover { background-color: #e53e3e; }
.btn-manual { background-color: var(--azul-oscuro); color: var(--blanco); flex: 1; }
.btn-manual:hover { background-color: var(--azul-medio); }

/* ============================================================
   MANUAL OPTIONS
   ============================================================ */
.manual-options {
  display: none;
  flex-direction: column;
  gap: 12px;
  background: var(--blanco);
  border-radius: var(--radio-m);
  padding: 20px;
  box-shadow: var(--sombra-card);
  border: 1px solid var(--gris-suave);
}
.manual-options.visible { display: flex; }

.btn-option {
  padding: 14px 20px;
  border: none;
  border-radius: var(--radio-s);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--sombra-suave);
  background-color: var(--amarillo-tienda);
  color: var(--azul-oscuro);
}
.btn-option:hover { background-color: var(--amarillo-hover); }
.btn-option:active { transform: translateY(1px); box-shadow: none; }

/* ============================================================
   PANEL MANUAL
   ============================================================ */
.manual-panel {
  display: none;
  flex-direction: column;
  gap: 12px;
  background: var(--blanco);
  border-radius: var(--radio-m);
  padding: 20px;
  box-shadow: var(--sombra-card);
  border: 1px solid var(--gris-suave);
}
.manual-panel.visible { display: flex; }
.manual-panel label { font-size: 0.9rem; font-weight: 700; color: var(--azul-oscuro); text-transform: uppercase; letter-spacing: 0.5px; }

.input-row { display: flex; gap: 10px; }

.manual-panel input,
.nombre-panel input {
  flex: 1;
  padding: 16px 18px;
  border: 2px solid var(--gris-suave);
  border-radius: calc(var(--radio-s) * 1.2);
  font-size: 1.1rem;
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
  color: var(--azul-oscuro);
  background: #fcfdff;
}
.manual-panel input:focus,
.nombre-panel input:focus {
  outline: none;
  border-color: var(--azul-medio);
  box-shadow: 0 0 0 3px rgba(44,82,130,0.12);
  background: #ffffff;
}

.btn-search {
  padding: 0 20px;
  background-color: var(--amarillo-tienda);
  color: var(--azul-oscuro);
  border: none;
  border-radius: var(--radio-s);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s;
}
.btn-search:hover { background-color: var(--amarillo-hover); }

/* ============================================================
   TARJETA DE RESULTADOS
   ============================================================ */
.result-card {
  display: none;
  background: var(--blanco);
  border-radius: var(--radio-m);
  padding: 24px;
  box-shadow: var(--sombra-card);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}
.result-card.visible { display: block; animation: slideIn 0.4s ease-out; }

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

.result-card.success { border-color: var(--color-exito); }
.result-card.error   { border-color: var(--color-error); background-color: #fff5f5; }

.result-card.success::before {
  content: '✓';
  position: absolute;
  top: -20px; right: -10px;
  font-size: 10rem;
  color: rgba(72,187,120,0.05);
  font-weight: 900;
}

.result-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--blanco);
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
}
.result-tag.ok  { background-color: var(--color-exito); }
.result-tag.err { background-color: var(--color-error); }

.result-cb {
  font-family: monospace;
  font-size: 0.9rem;
  color: #a0aec0;
  margin-bottom: 12px;
  background: var(--gris-fondo);
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
}

.result-nombre {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--azul-oscuro);
  line-height: 1.3;
  margin-bottom: 16px;
}

.result-precio {
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--color-exito);
  line-height: 1;
  letter-spacing: -2px;
  margin-bottom: 16px;
}
.result-precio small { font-size: 1.5rem; color: #a0aec0; font-weight: 400; margin-left: 4px; }

/* ── Existencias ── */
.result-existencias {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radio-s);
  font-size: 1rem;
  font-weight: 600;
  border: 2px solid transparent;
}
.result-existencias.stock-ok   { background: #f0fff4; border-color: var(--color-exito); color: #276749; }
.result-existencias.stock-bajo { background: #fffaf0; border-color: var(--color-stock-bajo); color: #7b341e; }
.result-existencias.stock-cero { background: #fff5f5; border-color: var(--color-error); color: #9b2c2c; }

.result-existencias .stock-icono { font-size: 1.4rem; }
.result-existencias .stock-numero { font-size: 1.5rem; font-weight: 900; }

/* ── Error ── */
.error-msg {
  color: var(--color-error);
  font-weight: 700;
  font-size: 1.1rem;
  background: rgba(245,101,101,0.1);
  padding: 12px;
  border-radius: var(--radio-s);
}

/* ============================================================
   SPINNER
   ============================================================ */
.spinner {
  display: block;
  width: 40px; height: 40px;
  margin: 20px auto;
  border: 4px solid var(--gris-suave);
  border-top-color: var(--azul-medio);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   OVERLAY: resultado se superpone a la cámara
   ============================================================ */
.display-container {
  position: relative;
  width: 100%;
  min-height: 300px;
}

.cam-card {
  position: relative;
  width: 100%;
  transition: opacity 0.3s ease;
}

.cam-card.hidden {
  opacity: 0;
  pointer-events: none;
  position: absolute;
  top: 0; left: 0;
}

.result-card {
  display: none;
  width: 100%;
}

.result-card.visible {
  display: block;
}

/* ============================================================
   EXISTENCIAS (sin colores)
   ============================================================ */
.result-existencias {
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--gris-fondo);
  border: 1px solid var(--gris-suave);
  border-radius: var(--radio-s);
  font-size: 1rem;
  color: var(--gris-texto);
}

/* ============================================================
   BUSCADOR POR NOMBRE
   ============================================================ */
.nombre-panel {
  display: none;
  flex-direction: column;
  gap: 12px;
  background: var(--blanco);
  border-radius: var(--radio-m);
  padding: 20px;
  box-shadow: var(--sombra-card);
  border: 1px solid var(--gris-suave);
}
.nombre-panel.visible { display: flex; }

.nombre-panel label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--azul-oscuro);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================================
   LISTA DE RESULTADOS POR NOMBRE
   ============================================================ */
.lista-resultados {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
}

.lista-item {
  background: var(--blanco);
  border: 1px solid var(--gris-suave);
  border-radius: var(--radio-s);
  padding: 14px 16px;
  box-shadow: var(--sombra-suave);
}

.lista-nombre {
  font-size: 1rem;
  font-weight: 700;
  color: var(--azul-oscuro);
  margin-bottom: 4px;
}

.lista-cb {
  font-size: 0.8rem;
  color: #a0aec0;
  margin-bottom: 8px;
  font-family: monospace;
}

.lista-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.lista-precio {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--color-exito);
}

.lista-existencias {
  font-size: 0.9rem;
  color: var(--gris-texto);
  background: var(--gris-fondo);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--gris-suave);
}

.lista-vacio, .lista-error {
  text-align: center;
  padding: 20px;
  color: var(--gris-texto);
  background: var(--blanco);
  border-radius: var(--radio-s);
  border: 1px solid var(--gris-suave);
}

.lista-error { color: var(--color-error); }
