/* =====================================================================
   app.css — Estilos propios del ecosistema de autopartes.
   Ubicacion: /var/www/html/assets/css/app.css
   Tailwind (CDN o build) cubre la utileria; aqui van:
     1. Variables y base
     2. Componentes reutilizables (.card, .btn, .input, .badge, toggle)
     3. Animaciones y detalles
     4. TICKET TERMICO 80mm (@media print)   <-- critico
   ===================================================================== */

/* ------------------------------ 1. Base ------------------------------ */
:root {
  --marca:        #2563eb;
  --marca-oscuro: #1d4ed8;
  --oferta:       #e11d48;
  --tinta:        #0f172a;
  --gris:         #64748b;
  --linea:        #e5e7eb;
  --radio:        14px;

  /* Ancho de impresora termica: 80mm totales, ~72mm imprimibles */
  --ticket-ancho: 80mm;
  --ticket-padding: 3mm;
}

* { -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--tinta);
  background: #fafafa;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Numeros tabulares en precios: alineacion perfecta en columnas */
.tnum, .precio { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--marca);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Ocultar scrollbar manteniendo el scroll (carruseles horizontales) */
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
/* Alias pedido por la Fase 13 (carruseles de categorias en movil) */
.scrollbar-hide { -ms-overflow-style: none; scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }
.scrollbar-hide::-webkit-scrollbar { display: none; }

/* --------------------------- 2. Componentes -------------------------- */
.card {
  background: #fff;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.card-hover { transition: transform .18s ease, box-shadow .18s ease; }
.card-hover:hover { transform: translateY(-2px); box-shadow: 0 10px 24px -12px rgb(15 23 42 / 0.25); }

.label {
  display: block;
  font-size: .8125rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: .375rem;
}

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--linea);
  background: #fff;
  border-radius: 10px;
  padding: .625rem .75rem;
  font-size: 1rem;           /* 16px: evita el zoom automatico en iOS */
  line-height: 1.4;
  color: var(--tinta);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--marca);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.14);
}
.input[readonly] { background: #f8fafc; color: #475569; }

/* Area tactil minima recomendada (44px) en movil */
.touch { min-height: 44px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border-radius: 10px;
  padding: .625rem 1rem;
  font-size: .9375rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 44px;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .1s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primario  { background: var(--tinta); color: #fff; }
.btn-primario:hover { background: #1e293b; }

.btn-marca     { background: var(--marca); color: #fff; }
.btn-marca:hover { background: var(--marca-oscuro); }

.btn-borde     { background: #fff; color: var(--tinta); border-color: var(--linea); }
.btn-borde:hover { background: #f8fafc; }

.btn-whatsapp  { background: #25D366; color: #fff; }
.btn-whatsapp:hover { background: #1ebe5a; }

.btn-peligro   { background: #fff; color: #b91c1c; border-color: #fecaca; }
.btn-peligro:hover { background: #fef2f2; }

/* Verde: descargas / acciones de confirmacion (Fase 11: exportar a Excel) */
.btn-exito     { background: #059669; color: #fff; }
.btn-exito:hover { background: #047857; }

.btn-sm { min-height: 36px; padding: .375rem .75rem; font-size: .8125rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .2rem .5rem;
  border-radius: 999px;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.badge-oferta  { background: var(--oferta); color: #fff; }
.badge-suave   { background: #f1f5f9; color: #334155; }
.badge-ok      { background: #dcfce7; color: #166534; }
.badge-aviso   { background: #fef3c7; color: #92400e; }
.badge-error   { background: #fee2e2; color: #991b1b; }
.badge-alerta  { background: #ffedd5; color: #9a3412; }

/* Interruptor (toggle) de Ofertas — sin JS, con input checkbox + span */
.toggle { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__pista {
  width: 48px; height: 28px; border-radius: 999px;
  background: #cbd5e1; transition: background-color .2s ease; flex: none;
}
.toggle__pista::after {
  content: ''; display: block; width: 22px; height: 22px; margin: 3px;
  border-radius: 999px; background: #fff; transition: transform .2s ease;
  box-shadow: 0 1px 3px rgb(15 23 42 / .3);
}
.toggle input:checked + .toggle__pista { background: var(--oferta); }
.toggle input:checked + .toggle__pista::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle__pista { box-shadow: 0 0 0 3px rgb(37 99 235 / .3); }

/* Tabla responsiva: en movil se convierte en tarjetas */
.tabla { width: 100%; border-collapse: collapse; }
.tabla th {
  text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--gris); padding: .625rem .75rem; border-bottom: 1px solid var(--linea); white-space: nowrap;
}
.tabla td { padding: .75rem; border-bottom: 1px solid #f1f5f9; font-size: .875rem; vertical-align: middle; }

@media (max-width: 767px) {
  .tabla-cards thead { display: none; }
  .tabla-cards tr { display: block; border: 1px solid var(--linea); border-radius: 12px; margin-bottom: .75rem; background: #fff; padding: .25rem; }
  .tabla-cards td { display: flex; justify-content: space-between; gap: 1rem; border: none; border-bottom: 1px dashed #f1f5f9; padding: .5rem .625rem; }
  .tabla-cards td:last-child { border-bottom: none; }
  .tabla-cards td::before { content: attr(data-th); font-weight: 600; color: var(--gris); font-size: .75rem; text-transform: uppercase; }
}

/* Imagen de producto: contenedor cuadrado uniforme */
.producto-img {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  background: #f8fafc;
}

/* ---------------------------------------------------------------------
   FASE 17 — Inventario del panel: tarjetas (cuadricula) y filas (lista)
   El recorte de nombres largos va tambien aqui como RESPALDO por si el CDN
   de Tailwind no carga: un nombre de 180 caracteres NUNCA debe desplazar ni
   ocultar el precio ni las existencias.
   --------------------------------------------------------------------- */
.line-clamp-1,
.line-clamp-2,
.line-clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.line-clamp-1 { -webkit-line-clamp: 1; line-clamp: 1; }
.line-clamp-2 { -webkit-line-clamp: 2; line-clamp: 2; }
.line-clamp-3 { -webkit-line-clamp: 3; line-clamp: 3; }
.break-words { overflow-wrap: break-word; word-wrap: break-word; }

/* En la vista de lista los botones de accion deben ser tactiles (>= 44 px)
   aunque usen .btn-sm, y la fila nunca debe desbordar horizontalmente. */
[data-inv-vista="lista"] [data-inv-acciones] .btn {
  min-height: 44px;
  min-width: 44px;
  padding-left: .5rem;
  padding-right: .5rem;
}
[data-inv-vista="lista"] [data-inv-producto] { max-width: 100%; }
[data-inv-vista="lista"] [data-inv-nombre] { min-width: 0; }

/* ---------------------------------------------------------------------
   FASE 17b — Los CUATRO precios del producto + chip «Ver nombre» + modal.
   Va en CSS propio (no en utilidades del CDN) para que funcione igual con el
   build local de Tailwind y para poder medir el montaje con las suites.
   --------------------------------------------------------------------- */

/* Bloque de precios: dos columnas con la etiqueta arriba y el importe debajo.
   A 390 px caben los dos costados (los importes mas largos del catalogo son de
   $1,450.00) y NUNCA desborda la tarjeta. */
.inv-precios {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: .75rem;
  row-gap: .25rem;
  min-width: 0;
}
.inv-precio {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.inv-precio__label {
  font-size: .625rem;      /* 10 px */
  font-weight: 600;
  letter-spacing: .01em;
  color: #94a3b8;          /* neutral-400 */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inv-precio__valor {
  font-size: .75rem;       /* 12 px */
  font-weight: 600;
  color: #334155;          /* neutral-700 */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inv-precio__valor--fuerte { font-weight: 800; color: #0f172a; }

/* La oferta ocupa las DOS columnas (es el precio que gana en POS/portal). */
.inv-precio--oferta {
  grid-column: 1 / -1;
  margin-top: .125rem;
  padding: .15rem .4rem;
  border-radius: .5rem;
  background: #fff1f2;      /* oferta-50 */
}
.inv-precio--oferta .inv-precio__label { color: #be123c; }
.inv-precio--oferta .inv-precio__valor { color: #be123c; font-weight: 800; }

/* En la LISTA el bloque de precios va a lo ancho de la fila en el telefono y
   se estira (flex-1) en pantallas grandes: los cuatro importes en dos filas.
   OJO con la especificidad: el JS conserva `grid gap-x-3 gap-y-1` en el bloque
   para no perder los espacios si la hoja del CDN tarda en recalcular. */
[data-inv-vista="lista"] [data-inv-precios].inv-precios { width: 100%; }
@media (min-width: 640px) {
  [data-inv-vista="lista"] [data-inv-precios].inv-precios { width: auto; flex: 1 1 12rem; }
}

/* Chip «Ver nombre»: nace oculto (atributo `hidden`) y solo aparece cuando el
   nombre esta realmente recortado. Area tactil >= 32 px de alto. */
.inv-chip-nombre {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  min-height: 32px;
  margin-top: .125rem;
  padding: .15rem .55rem;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  max-width: 100%;
}
.inv-chip-nombre:hover { background: #f1f5f9; color: #0f172a; }
.inv-chip-nombre[hidden] { display: none; }
.inv-chip-nombre > svg { flex: none; }

/* Modal ligero del nombre completo (30 = por encima del menu movil). */
.inv-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: .75rem;
}
.inv-modal[hidden] { display: none; }
.inv-modal__fondo { position: absolute; inset: 0; background: rgb(15 23 42 / .55); }
.inv-modal__caja {
  position: relative;
  width: 100%;
  max-width: 32rem;
  max-height: 80vh;
  overflow-y: auto;
  border-radius: var(--radio);
  background: #fff;
  padding: 1rem;
  box-shadow: 0 24px 48px -20px rgb(15 23 42 / .55);
}
.inv-modal__nombre {
  margin-top: .75rem;
  font-size: .875rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--tinta);
}
@media (min-width: 640px) {
  .inv-modal { align-items: center; }
}

/* ---------------------------------------------------------------------
   FASE 22 — Modal del escáner de cámara (assets/js/scanner.js).
   El visor de html5-qrcode pinta su propio <video>; aquí solo el marco y
   el estado. `scanner-oculto` es la clase que alterna el JS (no .hidden,
   para no chocar con las utilidades responsive de Tailwind).
   --------------------------------------------------------------------- */
.scanner-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: .75rem;
}
.scanner-modal.scanner-oculto { display: none; }
.scanner-fondo { position: absolute; inset: 0; background: rgb(15 23 42 / .6); backdrop-filter: blur(2px); }
.scanner-caja {
  position: relative;
  width: 100%;
  max-width: 26rem;
  max-height: 86vh;
  overflow-y: auto;
  border-radius: var(--radio, 14px);
  background: #fff;
  padding: 1rem;
  box-shadow: 0 24px 48px -20px rgb(15 23 42 / .6);
}
.scanner-visor { margin-top: .75rem; overflow: hidden; border-radius: 12px; }
.scanner-visor video { width: 100% !important; height: auto !important; border-radius: 12px; }
.scanner-estado { margin-top: .6rem; }
/* Fase 22.1: guía + reintentar + cámara nativa (modo infalible). Ocultos por
   defecto; el JS los muestra cuando el stream falla (NotAllowedError u
   OverconstrainedError). */
.scanner-guia {
  display: none;
  margin-top: .6rem;
  padding: .6rem .7rem;
  border-radius: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
}
.scanner-guia-texto { margin: 0 0 .5rem 0; font-size: 12px; line-height: 1.5; color: #b91c1c; }
.scanner-reintentar { display: none; margin-top: .15rem; }
.scanner-nativo { display: none; }
@media (min-width: 640px) {
  .scanner-modal { align-items: center; }
}

/* ---------------------------------------------------------------------
   FASE 17c — LISTA en ESCRITORIO: una sola fila, el minimo al lado y el
   chip reducido al icono del ojo.
   La fila de la lista ya es `flex flex-row flex-wrap`; el reparto en una
   sola linea (nombre+ojo | datos | 4 precios | existencia | acciones) entra
   con las utilidades `xl:` (>= 1280 px: el sidebar del panel mide 16rem) que
   sirve admin/productos.php y que replica assets/js/inventario_admin.js al
   conmutar en vivo. Aqui van los detalles que no son una utilidad simple y
   que deben funcionar aunque el CDN de Tailwind no cargue.
   --------------------------------------------------------------------- */

/* Texto que solo se ve en una de las dos vistas: la existencia dice
   «12 pzas» en cuadricula y «Existencia 12» (o «Bajo») en la lista. */
.inv-solo-lista { display: none; }
[data-inv-vista="lista"] .inv-solo-grid { display: none; }
[data-inv-vista="lista"] .inv-solo-lista { display: inline; }

/* En la lista el chip «Ver nombre» es SOLO el icono del ojo: pegado al
   nombre, cuadrado y con area tactil >= 36 px. En cuadricula conserva el
   texto (que en el telefono es mas claro). */
[data-inv-vista="lista"] .inv-chip-nombre {
  margin-top: 0;
  flex: none;
  min-width: 36px;
  min-height: 36px;
  padding: .15rem .4rem;
  justify-content: center;
}
[data-inv-vista="lista"] .inv-chip-nombre__txt { display: none; }

/* «Agotado · mín. 3»: el separador solo tiene sentido en la lista. */
[data-inv-vista="lista"] [data-inv-minimo]::before { content: '· '; }

@media (min-width: 1280px) {
  /* El bloque de los 4 precios no se estira en la fila de escritorio: asi el
     reparto nombre | datos | precios | existencia | acciones es estable y los
     importes quedan al lado de los datos, nunca encima de los botones. */
  [data-inv-vista="lista"] [data-inv-precios].inv-precios { flex: none; width: auto; }
  /* Con el sidebar de 16rem, en la fila de escritorio los botones de la lista
     se quedan SOLO con su icono (conservan title y aria-label): asi el nombre
     y los datos tienen ancho real sin robar sitio a los precios. */
  [data-inv-vista="lista"] [data-inv-acciones] .btn > span { display: none; }
}

/* --------------------------- 3. Animaciones -------------------------- */
@keyframes aparecer { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.animar { animation: aparecer .28s ease both; }

@keyframes girar { to { transform: rotate(360deg); } }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgb(255 255 255 / .35); border-top-color: #fff;
  animation: girar .7s linear infinite;
}

/* Toast */
#toasts { position: fixed; inset-inline: 0; bottom: 1rem; z-index: 90; display: flex; flex-direction: column; align-items: center; gap: .5rem; pointer-events: none; padding-inline: 1rem; }
.toast {
  pointer-events: auto; max-width: 26rem; width: 100%;
  background: #0f172a; color: #fff; border-radius: 12px;
  padding: .75rem 1rem; font-size: .875rem; font-weight: 500;
  box-shadow: 0 12px 28px -10px rgb(15 23 42 / .5);
  animation: aparecer .2s ease both;
}
.toast--error { background: #b91c1c; }
.toast--ok    { background: #15803d; }

/* =====================================================================
   4. TICKET TERMICO 80mm
   Reglas de pantalla + impresion. El area imprimible es #area-ticket.
   ===================================================================== */
.ticket {
  width: var(--ticket-ancho);
  max-width: 100%;
  margin: 0 auto;
  background: #fff;
  color: #000;
  font-family: 'JetBrains Mono', ui-monospace, 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.35;
  padding: var(--ticket-padding);
  box-sizing: border-box;
}
.ticket__logo { display: block; max-width: 40mm; max-height: 20mm; object-fit: contain; margin: 0 auto 2mm; filter: grayscale(100%) contrast(1.2); }
.ticket__empresa { text-align: center; font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: .02em; }
.ticket__meta { text-align: center; font-size: 11px; }
.ticket__sep { border: 0; border-top: 1px dashed #000; margin: 2mm 0; }
.ticket__sep--solida { border-top-style: solid; }
.ticket__fila { display: flex; justify-content: space-between; gap: 2mm; }
.ticket__fila--total { font-size: 15px; font-weight: 700; }
.ticket__nombre { flex: 1 1 auto; min-width: 0; word-break: break-word; }
.ticket__cant { flex: none; width: 10mm; text-align: right; }
.ticket__importe { flex: none; width: 20mm; text-align: right; font-variant-numeric: tabular-nums; }
.ticket__concepto { padding-left: 3mm; font-size: 11px; }
.ticket__centro { text-align: center; }
.ticket__qr { display: block; margin: 2mm auto 0; width: 26mm; height: 26mm; }
.ticket__codigo { text-align: center; letter-spacing: .12em; font-size: 12px; }

/* Impresion: 80mm de ancho, sin margenes del navegador */
@page {
  size: 80mm auto;
  margin: 0;
}

@media print {
  html, body {
    width: 80mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  /* Se oculta todo y solo se muestra el ticket */
  body * { visibility: hidden !important; }
  #area-ticket, #area-ticket * { visibility: visible !important; }

  #area-ticket {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 80mm !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
  }

  .ticket {
    width: 80mm !important;
    padding: 2mm var(--ticket-padding) 8mm !important;  /* 8mm de avance de papel al cortar */
    font-size: 11.5px !important;
    box-shadow: none !important;
  }

  /* Nada que no deba imprimirse */
  .no-print, .no-print * { display: none !important; }

  /* Fuerza el render de fondos/imagenes del logo */
  .ticket__logo, .ticket * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  a[href]::after { content: none !important; }   /* sin URLs impresas */
  .ticket__fila, .ticket__sep { page-break-inside: avoid; }
}

/* Utilidad: mostrar solo al imprimir */
.solo-imprimir { display: none; }
@media print { .solo-imprimir { display: block !important; } }

/* ---------------------------------------------------------------------
   Mapas (Fase 4) — Leaflet dentro de una app con Tailwind
   Tailwind aplica `img { max-width: 100% }` a TODAS las imagenes, lo que
   deforma los tiles del mapa; y los paneles internos de Leaflet usan
   z-index hasta 1000, que taparia la cabecera fija y el drawer. El
   contenedor crea su propio contexto de apilado (z-index: 0) para que todo
   el mapa quede por debajo del resto de la interfaz.
   --------------------------------------------------------------------- */
.mapa           { position: relative; z-index: 0; overflow: hidden; }
.mapa iframe    { border: 0; }
.leaflet-container img,
.leaflet-container svg { max-width: none !important; }
.leaflet-container .leaflet-tile { width: 256px; height: 256px; }
.leaflet-container { font-family: inherit; background: #e2e8f0; }

/* Marcador-avatar: el logo del aliado en lugar del pin azul */
.marcador-aliado {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 9999px;
  border: 2px solid #2563eb;          /* marca-600 */
  background: #ffffff;
  box-shadow: 0 6px 16px -6px rgba(15, 23, 42, .55);
  overflow: hidden;
  font-weight: 800; font-size: 14px; color: #1d4ed8;
  transition: transform .15s ease;
}
.marcador-aliado img { width: 100%; height: 100%; object-fit: cover; }
.marcador-aliado--activo { transform: scale(1.12); border-color: #e11d48; }
.leaflet-marker-icon:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

/* Popup del mapa adaptado al estilo de la app */
.leaflet-popup-content-wrapper { border-radius: 14px; box-shadow: 0 18px 40px -22px rgba(15,23,42,.5); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.35; }
.mapa-popup__titulo { font-weight: 800; font-size: 14px; }
.mapa-popup__dir    { color: #64748b; }
.mapa-popup__acciones { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.mapa-popup__acciones a {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 12px; border-radius: 10px;
  font-weight: 700; font-size: 12px; text-decoration: none;
}
