:root {
  --cp: #1a1a2e;
  --ca: #e94560;
  --cf: #f0f2f5;
  --ct: #2d2d2d;
  --cv: #22c55e;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--cf); color: var(--ct); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* ── HEADER ─────────────────────────────────────────────────────────── */
.pos-header {
  background: var(--cp);
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  flex-shrink: 0;
}
.pos-logo {
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
}
.nit-badge {
  font-size: 10px;
  font-weight: 400;
  opacity: 0.6;
  margin-left: 6px;
}
.pos-busqueda { flex: 1; }
.pos-busqueda input {
  width: 100%;
  padding: 6px 12px;
  border-radius: 20px;
  border: none;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 13px;
  outline: none;
}
.pos-busqueda input::placeholder { color: rgba(255,255,255,0.4); }
.pos-busqueda input:focus { background: rgba(255,255,255,0.2); }
.pos-acciones { display: flex; gap: 6px; }
.btn-header {
  padding: 5px 10px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-header:hover { background: rgba(255,255,255,0.2); }
.btn-header.btn-warn { border-color: #fbbf24; color: #fbbf24; }

/* ── BUSQUEDA ─────────────────────────────────────────────────────────── */
.pos-busqueda {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.busqueda-icono {
  position: absolute;
  left: 12px;
  font-size: 14px;
  pointer-events: none;
}
.pos-busqueda input {
  width: 100%;
  padding: 7px 36px 7px 34px;
  border-radius: 20px;
  border: none;
  background: rgba(255,255,255,0.12);
  color: white;
  font-size: 13px;
  outline: none;
  transition: background 0.2s;
}
.pos-busqueda input::placeholder { color: rgba(255,255,255,0.4); }
.pos-busqueda input:focus { background: rgba(255,255,255,0.22); }

/* ── CATS NAV ────────────────────────────────────────────────────────── */
.pos-nav-wrap {
  background: var(--cp);
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.cats-nav {
  display: flex;
  gap: 6px;
  padding: 7px 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
.cats-nav::-webkit-scrollbar { display: none; }
.cat-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  background: transparent;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  transition: all 0.15s;
}
.cat-btn:hover  { background: rgba(255,255,255,0.12); color: white; border-color: rgba(255,255,255,0.4); }
.cat-btn.activo { background: var(--ca); border-color: var(--ca); color: white; font-weight: 700; }
.cat-icono { font-size: 14px; }
.cat-nombre { }
.cat-total {
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 0px 6px;
  font-size: 10px;
}
.cat-btn.activo .cat-total { background: rgba(255,255,255,0.3); }

/* Breadcrumb */
.pos-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 16px 7px;
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  border-top: 1px solid rgba(255,255,255,0.06);
}
.bc-link {
  background: none;
  border: none;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.bc-link:hover { color: white; }
.bc-sep { opacity: 0.4; }
.bc-actual { color: white; font-weight: 700; }

/* ── LAYOUT PRINCIPAL ───────────────────────────────────────────────── */
.pos-main {
  display: grid;
  grid-template-columns: 1fr 320px;
  flex: 1;
  overflow: hidden;
}

/* ── CATÁLOGO ────────────────────────────────────────────────────────── */
.pos-catalogo {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  padding: 12px;
  overflow-y: auto;
  align-content: start;
}
.sin-res { grid-column: 1/-1; text-align: center; padding: 2rem; color: #888; }
.prod-card {
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}
.prod-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.prod-img-wrap {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: #f8f8f8;
}
.prod-img-wrap img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.2s; }
.prod-card:hover .prod-img-wrap img { transform: scale(1.04); }
.badge-qty {
  position: absolute; top: 6px; right: 6px;
  background: var(--ca); color: white;
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.badge-stock-bajo {
  position: absolute; bottom: 4px; left: 4px;
  background: #fef3c7; color: #92400e;
  padding: 1px 5px; border-radius: 3px;
  font-size: 9px; font-weight: 700;
}
.tag-iva {
  position: absolute; top: 6px; left: 6px;
  padding: 1px 5px; border-radius: 3px;
  font-size: 9px; font-weight: 700;
}
.tag-19  { background: #fef3c7; color: #92400e; }
.tag-5   { background: #d1fae5; color: #065f46; }
.tag-ex  { background: #ede9fe; color: #5b21b6; }
.tag-exc { background: #f3f4f6; color: #6b7280; }

.prod-body { padding: 8px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.prod-sku  { font-size: 9px; color: #aaa; font-family: monospace; }
.prod-nombre { font-size: 12px; font-weight: 600; line-height: 1.2; }
.prod-precio-row { display: flex; justify-content: space-between; align-items: center; margin-top: auto; }
.prod-precio { font-size: 13px; font-weight: 700; color: var(--cp); }
.prod-stock { font-size: 10px; color: #888; }
.prod-stock.bajo { color: #f59e0b; }
.btn-agregar {
  width: 100%;
  padding: 5px;
  background: var(--ca);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  margin-top: 4px;
}
.btn-agregar:hover:not(:disabled) { background: #c73652; }
.btn-agregar:disabled { background: #ddd; cursor: not-allowed; color: #999; }
.prod-card.agotado { opacity: 0.5; }
.badge-agotado {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.45);
  color: white; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.prod-en-carro {
  font-size: 11px; font-weight: 700; color: var(--cv);
}

/* ── CAJA LATERAL ───────────────────────────────────────────────────── */
.pos-caja {
  background: white;
  border-left: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
/* #caja-contenido divide en scroll + pie fijo */
#caja-contenido {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
/* Zona scrolleable: header + lista de items */
.caja-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
/* Pie fijo: totales + botones de pago + acciones — NUNCA se oculta */
.caja-pie {
  flex-shrink: 0;
  border-top: 2px solid #e5e7eb;
  background: white;
}
.caja-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 14px;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}
.caja-titulo { font-size: 15px; font-weight: 800; color: var(--cp); }
.caja-cliente {
  font-size: 11px;
  color: #888;
  cursor: pointer;
  margin-top: 2px;
}
.caja-cliente:hover { color: var(--ca); }
.btn-limpiar {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn-limpiar:disabled { opacity: 0.3; cursor: not-allowed; }
.caja-vacia { padding: 2rem; text-align: center; color: #aaa; font-size: 13px; }
.caja-items {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.caja-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #f8f9fa;
  border-radius: 7px;
}
.ci-info { flex: 1; min-width: 0; }
.ci-nombre { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-precio { font-size: 11px; color: #666; margin-top: 2px; }
.ci-ctrl { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.ci-ctrl button {
  width: 24px; height: 24px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.1s;
}
.ci-ctrl button:hover { background: #f0f0f0; }
.ci-ctrl span { font-weight: 700; font-size: 13px; min-width: 20px; text-align: center; }

.caja-totales {
  padding: 10px 14px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.ct-row { display: flex; justify-content: space-between; font-size: 12px; }
.ct-row.iva  { color: #92400e; }
.ct-row.exc  { color: #6b7280; }
.ct-total {
  display: flex; justify-content: space-between;
  font-size: 17px; font-weight: 800;
  color: var(--cp);
  padding-top: 6px;
  border-top: 2px solid var(--cp);
  margin-top: 4px;
}

.caja-pagos {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 10px 14px;
  flex-shrink: 0;
}
.btn-pago {
  padding: 14px 6px;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.3;
  min-height: 52px;
}
.btn-pago:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-pago.efectivo      { background: #22c55e; color: white; }
.btn-pago.tarjeta       { background: #3b82f6; color: white; }
.btn-pago.transferencia { background: #8b5cf6; color: white; }
.btn-pago.credito       { background: #1e3a5f; color: white; }
.btn-pago:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }

.caja-acciones-extra {
  display: flex;
  gap: 8px;
  padding: 0 14px 14px;
  flex-shrink: 0;
}
.btn-cuadre, .btn-abrir-caja, .btn-cerrar-caja {
  flex: 1;
  padding: 9px 4px;
  border: none;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-cuadre      { background: #1a1a2e; color: white; }
.btn-abrir-caja  { background: #fbbf24; color: #1a1a2e; }
.btn-cerrar-caja { background: #f3f4f6; color: #374151; }
.btn-cuadre:hover      { background: #2d2d4e; }
.btn-abrir-caja:hover  { background: #f59e0b; }
.btn-cerrar-caja:hover { background: #e5e7eb; }

/* ── MÉTRICAS ────────────────────────────────────────────────────────── */
.metricas-panel {
  position: fixed; bottom: 10px; left: 10px;
  z-index: 300;
  background: rgba(26,26,46,0.96);
  color: white;
  border-radius: 10px;
  font-size: 11px;
  min-width: 190px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.metricas-titulo { padding: 7px 12px; font-weight: 700; font-size: 11px; cursor: pointer; background: rgba(255,255,255,0.05); border-radius: 10px 10px 0 0; }
.metricas-panel:not(.expandido) .metricas-titulo { border-radius: 10px; }
.metricas-body { padding: 4px 12px 10px; display: none; flex-direction: column; gap: 3px; }
.metricas-panel.expandido .metricas-body { display: flex; }
.metrica { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.metrica-label { color: rgba(255,255,255,0.55); }
.metrica-valor { font-weight: 700; font-family: monospace; }
.metrica.resaltado .metrica-valor { color: #fbbf24; }
.metrica.verde .metrica-valor { color: var(--cv); }
.metrica-seccion { font-size: 9px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: rgba(255,255,255,0.3); margin-top: 6px; padding-top: 4px; border-top: 1px solid rgba(255,255,255,0.08); }

/* ── RESPONSIVE MÓVIL ───────────────────────────────────────────────── */
@media (max-width: 700px) {

  body { height: 100dvh; overflow: hidden; }

  /* Header compacto */
  .pos-header   { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .pos-logo     { font-size: 12px; }
  .nit-badge    { display: none; }
  .pos-acciones { display: none; }
  .pos-busqueda { order: 3; flex-basis: 100%; }
  .pos-busqueda input { font-size: 16px; /* evita zoom iOS */ }

  /* Pills de categorías más grandes y fáciles de tocar */
  .cats-nav { padding: 8px 10px; gap: 6px; }
  .cat-btn  { padding: 8px 16px; font-size: 13px; min-height: 36px; }

  /* Layout: columna simple, catálogo toma todo el espacio */
  .pos-main {
    display: block;
    position: relative;
    overflow: hidden;
    flex: 1;
  }

  /* Catálogo: 2 columnas, scroll natural hasta el fondo */
  .pos-catalogo {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 10px 10px 90px; /* 90px = espacio para botón flotante */
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
  }

  /* Tarjetas táctiles */
  .prod-card    { border-radius: 8px; }
  .prod-img-wrap { aspect-ratio: 4/3; }
  .prod-body    { padding: 8px; gap: 4px; }
  .prod-nombre  { font-size: 12px; }
  .prod-precio  { font-size: 13px; }
  .prod-stock   { font-size: 10px; }
  /* Botón de agregar más grande para dedos */
  .btn-agregar  { padding: 10px; font-size: 13px; border-radius: 8px; min-height: 40px; }
  .tag-iva      { font-size: 8px; padding: 1px 4px; }

  /* La caja lateral de escritorio se oculta — usamos el sheet */
  .pos-caja {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 92dvh; /* más alto para que quepan items + botones */
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-top: none;
    box-shadow: 0 -6px 30px rgba(0,0,0,0.2);
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
    z-index: 200;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: white;
  }

  /* Handle pill arriba del sheet */
  .pos-caja::before {
    content: '';
    display: block;
    width: 44px; height: 5px;
    background: #d1d5db;
    border-radius: 3px;
    margin: 12px auto 4px;
    flex-shrink: 0;
  }

  /* Sheet abierto */
  .pos-caja.abierta { transform: translateY(0); }

  /* Overlay oscuro */
  .caja-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 195;
  }
  .caja-overlay.visible { display: block; }

  /* Botón flotante barra de carrito */
  .btn-caja-flotante {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--cp);
    color: white;
    border: none;
    border-radius: 0;
    padding: 14px 20px 20px; /* extra abajo para safe area */
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    z-index: 190;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.2);
  }
  .btn-caja-flotante .bcf-items {
    background: var(--ca);
    border-radius: 20px;
    padding: 4px 14px;
    font-size: 14px;
  }

  /* Contenido interno del sheet — igual que desktop: scroll + pie fijo */
  #caja-contenido {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .caja-scroll {
    -webkit-overflow-scrolling: touch;
  }

  .caja-header  { padding: 10px 16px 6px; }
  .caja-titulo  { font-size: 17px; }
  .caja-items   { padding: 6px 12px; gap: 8px; }
  .caja-item    { padding: 10px 10px; }
  .ci-nombre    { font-size: 14px; }
  .ci-precio    { font-size: 12px; }
  /* Controles +/- más grandes */
  .ci-ctrl button { width: 34px; height: 34px; font-size: 18px; }
  .ci-ctrl span   { font-size: 16px; min-width: 24px; }

  .caja-totales  { padding: 8px 16px; }
  .ct-total      { font-size: 20px; }

  .caja-pagos    { padding: 10px 12px calc(env(safe-area-inset-bottom) + 16px); gap: 10px; flex-shrink: 0; }
  .btn-pago      { padding: 18px 4px; font-size: 15px; border-radius: 14px; min-height: 58px; font-weight: 800; }

  /* Métricas: ocultas en móvil por defecto (demasiado ruido) */
  .metricas-panel { display: none; }
}

/* NAVEGADOR ENTRE SISTEMAS */
.nav-sistemas {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 50px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  transition: transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.nav-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.2); }
.nav-btn.erp  { background: #1a1a2e; color: #fff; }
.nav-btn.home { background: #f0f2f5; color: #1a1a2e; border: 1px solid #e5e7eb; }
