/* ==========================================================================
   StockScan Demo — estilos base
   ========================================================================== */

:root {
  --bg-fondo: #FAFAFA;
  --bg-card: #FFFFFF;
  --texto-principal: #1A1A1A;
  --texto-secundario: #6B7280;
  --acento: #367C2B;
  --acento-hover: #2A5F22;
  --exito: #10B981;
  --alerta: #F59E0B;
  --error: #EF4444;
  --borde: #E5E7EB;

  /* Variantes más oscuras de exito/alerta/error, solo para texto o fondos con
     texto blanco: los tonos de arriba no llegan al contraste AA (4.5:1) en
     esos usos. Se mantienen los tonos originales para el resto (insignias,
     iconos, fondo del toast de alerta con texto oscuro, que sí cumplen). */
  --exito-accesible: #0A7A54;
  --alerta-accesible: #B45309;
  --error-accesible: #B91C1C;

  --top-bar-h: 60px;
  --bottom-nav-h: 72px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-fondo);
  color: var(--texto-principal);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button, input {
  font-family: inherit;
}

/* Foco visible consistente para navegación por teclado (no en clic con ratón) */
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible,
.pieza-card:focus-visible {
  outline: 2px solid var(--acento);
  outline-offset: 2px;
}

/* ---------- Barra superior ---------- */

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-bar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--borde);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  z-index: 100;
}

.top-bar__title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.top-bar__action {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Contenido ---------- */

.content {
  padding-top: calc(var(--top-bar-h) + env(safe-area-inset-top) + 16px);
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 16px);
  min-height: 100%;
}

.screen {
  padding: 0 16px;
  animation: fade-in 200ms ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.screen[hidden] {
  display: none;
}

/* ---------- Barra inferior de navegación ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--borde);
  display: flex;
  z-index: 100;
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--texto-secundario);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
}

.bottom-nav__item svg {
  width: 24px;
  height: 24px;
}

.bottom-nav__item--active {
  color: var(--acento);
}

/* ---------- Componentes comunes ---------- */

.buscador {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--borde);
  border-radius: 12px;
  font-size: 16px;
  background: var(--bg-card);
  margin-bottom: 16px;
}

.buscador:focus {
  outline: 2px solid var(--acento);
  outline-offset: 1px;
}

.lista-piezas {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pieza-card {
  background: var(--bg-card);
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color 150ms ease;
}

.pieza-card:active {
  border-color: var(--acento);
}

.pieza-card__info {
  min-width: 0;
}

.pieza-card__codigo {
  font-size: 15px;
  font-weight: 700;
  color: var(--acento);
  margin: 0;
}

.pieza-card__descripcion {
  font-size: 15px;
  color: var(--texto-principal);
  margin: 2px 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pieza-card__ubicacion {
  font-size: 13px;
  color: var(--texto-secundario);
  margin: 0;
}

.pieza-card__stock {
  flex-shrink: 0;
  text-align: right;
}

.pieza-card__stock-num {
  font-size: 24px;
  font-weight: 800;
  display: block;
  line-height: 1;
}

.pieza-card__stock-label {
  font-size: 11px;
  color: var(--texto-secundario);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pieza-card--stock-bajo .pieza-card__stock-num {
  color: var(--alerta-accesible);
}

.estado-vacio {
  text-align: center;
  color: var(--texto-secundario);
  padding: 60px 20px;
  font-size: 15px;
}

.estado-vacio__icono {
  width: 56px;
  height: 56px;
  color: var(--acento);
  margin-bottom: 16px;
}

.estado-vacio__titulo {
  color: var(--texto-principal);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
}

.estado-vacio__acciones {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.placeholder-proximamente {
  text-align: center;
  padding: 80px 20px;
  color: var(--texto-secundario);
}

.placeholder-proximamente h2 {
  color: var(--texto-principal);
  font-size: 24px;
  margin-bottom: 8px;
}

/* ---------- Botones ---------- */

.btn {
  height: 60px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 150ms ease, transform 100ms ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primario {
  background: var(--acento);
  color: #fff;
  width: 100%;
}

.btn--primario:active {
  background: var(--acento-hover);
}

.btn--latido {
  animation: latido 2.2s ease-in-out infinite;
}

.btn--latido:active {
  animation: none;
}

@keyframes latido {
  0%, 100% { box-shadow: 0 0 0 0 rgba(54, 124, 43, 0.35); }
  50% { box-shadow: 0 0 0 10px rgba(54, 124, 43, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .btn--latido { animation: none; }
}

.btn--secundario {
  background: var(--bg-card);
  color: var(--texto-principal);
  border: 1px solid var(--borde);
  width: 100%;
}

.btn--icono {
  height: 44px;
  width: 44px;
  padding: 0;
  background: none;
  color: var(--texto-principal);
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  z-index: 200;
  animation: fade-in 200ms ease;
}

.modal {
  background: var(--bg-card);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal__titulo {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.modal__campo {
  margin-bottom: 14px;
}

.modal__campo label {
  display: block;
  font-size: 13px;
  color: var(--texto-secundario);
  margin-bottom: 4px;
}

.modal__campo input {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--borde);
  border-radius: 10px;
  font-size: 16px;
}

.modal__campo input:disabled {
  background: var(--bg-fondo);
  color: var(--texto-secundario);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stepper__btn {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  border: 1px solid var(--borde);
  background: var(--bg-card);
  font-size: 22px;
  font-weight: 700;
  color: var(--acento);
  cursor: pointer;
}

.stepper__input {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}

/* ---------- Pantalla Escanear ---------- */

.escaner-idle {
  text-align: center;
  padding: 60px 16px 20px;
}

.escaner-idle__icono {
  width: 72px;
  height: 72px;
  color: var(--acento);
  margin-bottom: 20px;
}

.escaner-idle p {
  color: var(--texto-secundario);
  font-size: 15px;
  margin-bottom: 28px;
}

.escaner-camara {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lector-camara {
  width: 100%;
  min-height: 340px;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
}

.escaner-error {
  padding-top: 12px;
}

.escaner-error__mensaje {
  color: var(--error-accesible);
  font-size: 15px;
  margin-bottom: 20px;
}

.resultado-card {
  background: var(--bg-card);
  border: 1px solid var(--borde);
  border-radius: 16px;
  padding: 28px 20px;
  text-align: center;
  margin-top: 8px;
}

.resultado-card__codigo {
  font-size: 22px;
  font-weight: 800;
  color: var(--acento);
  margin: 0 0 4px;
}

.resultado-card__descripcion {
  font-size: 16px;
  margin: 0 0 20px;
}

.resultado-card__stock-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--texto-secundario);
  margin: 0;
}

.resultado-card__stock {
  font-size: 52px;
  font-weight: 800;
  margin: 2px 0 20px;
  line-height: 1;
}

.resultado-card--no-encontrada .resultado-card__aviso {
  color: var(--error-accesible);
  font-weight: 700;
  font-size: 18px;
  margin: 0 0 6px;
}

.resultado-card--no-encontrada .resultado-card__codigo {
  margin-bottom: 24px;
}

.resultado-card .btn {
  width: 100%;
  margin-bottom: 10px;
}

.resultado-card .stepper {
  justify-content: center;
  margin-bottom: 20px;
}

/* ---------- Pantalla Ajustes ---------- */

.ajustes-seccion {
  margin-bottom: 28px;
}

.ajustes-seccion__titulo {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--texto-secundario);
  font-weight: 700;
  margin: 0 0 10px;
}

.ajustes-seccion .btn {
  margin-bottom: 10px;
}

.sobre-app-texto {
  font-size: 14px;
  color: var(--texto-secundario);
  line-height: 1.5;
  margin: 0 0 12px;
}

.ajustes-fila {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
}

.ajustes-fila__label {
  font-size: 15px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch__slider {
  position: absolute;
  inset: 0;
  background-color: var(--borde);
  transition: background-color 150ms ease;
  border-radius: 28px;
  cursor: pointer;
}

.toggle-switch__slider::before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: transform 150ms ease;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-switch__slider {
  background-color: var(--acento);
}

.toggle-switch input:checked + .toggle-switch__slider::before {
  transform: translateX(22px);
}

/* ---------- Historial ---------- */

.historial-item {
  background: var(--bg-card);
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 8px;
}

.historial-item__fila-superior {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.historial-item__tipo {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--borde);
  color: var(--texto-secundario);
}

.historial-item__tipo--entrada { background: rgba(16, 185, 129, 0.15); color: #0d9668; }
.historial-item__tipo--alta { background: rgba(54, 124, 43, 0.15); color: var(--acento); }
.historial-item__tipo--edicion { background: rgba(107, 114, 128, 0.15); color: var(--texto-secundario); }
.historial-item__tipo--importacion { background: rgba(245, 158, 11, 0.15); color: #b45309; }

.historial-item__fecha {
  font-size: 12px;
  color: var(--texto-secundario);
}

.historial-item__detalle {
  font-size: 14px;
  margin: 0 0 2px;
}

.historial-item__stock {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.historial-item__cantidad {
  font-size: 13px;
  font-weight: 600;
  color: var(--texto-secundario);
}

/* ---------- Modal de import Excel ---------- */

.modal__campo select {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--borde);
  border-radius: 10px;
  font-size: 16px;
  background: var(--bg-card);
}

.import-preview-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
  border: 1px solid var(--borde);
  border-radius: 10px;
}

.import-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.import-preview-table th,
.import-preview-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--borde);
  text-align: left;
  white-space: nowrap;
}

.import-preview-table th {
  background: var(--bg-fondo);
  font-weight: 700;
}

/* ---------- Toasts ---------- */

.toast-container {
  position: fixed;
  top: calc(var(--top-bar-h) + env(safe-area-inset-top) + 12px);
  left: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--texto-principal);
  color: #fff;
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: toast-in 200ms ease;
}

.toast--exito {
  background: var(--exito-accesible);
}

.toast--error {
  background: var(--error-accesible);
}

.toast--alerta {
  background: var(--alerta);
  color: #1A1A1A;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
