/* app.css — PWA de reparto. Pensada para usarse con una mano, en la calle,
   con sol y guantes: tipografía grande y botones altos. */

:root {
  --pri: #0d6efd;
  --ok: #198754;
  --warn: #fd7e14;
  --mal: #dc3545;
  --gris: #6c757d;
  --fondo: #f2f4f7;
  --linea: #dee2e6;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

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

/* El atributo `hidden` del HTML lo pisa cualquier regla de autor que declare
   `display` (por ejemplo `.modal{display:flex}` o `.btn{display:inline-block}`).
   Sin esto, los elementos marcados como hidden se ven igual. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: #212529;
  font-size: 16px;
  padding-bottom: calc(64px + var(--safe-bot));
}

/* ---------------- Barra superior ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .5rem;
  background: var(--pri); color: #fff;
  padding: calc(.7rem + var(--safe-top)) .9rem .7rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.tb-titulo { display: flex; flex-direction: column; line-height: 1.15; flex: 1; min-width: 0; }
.tb-titulo strong { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-sub { font-size: .78rem; opacity: .85; }
.tb-btn {
  background: rgba(255,255,255,.18); border: 0; color: #fff;
  font-size: 1.2rem; border-radius: 10px; padding: .35rem .55rem; position: relative;
}
.badge-campana {
  position: absolute; top: -5px; right: -5px; background: var(--mal); color: #fff;
  border-radius: 999px; font-size: .68rem; padding: .05rem .35rem; font-weight: 700;
}
.chip-red {
  font-size: .7rem; padding: .2rem .5rem; border-radius: 999px;
  background: rgba(255,255,255,.2); white-space: nowrap;
}
.chip-red.online  { background: rgba(255,255,255,.28); }
.chip-red.offline { background: var(--mal); }

/* ---------------- Vistas ---------------- */
.vista { display: none; }
.vista.activa { display: block; }

.centro { padding: 1.5rem 1.2rem; text-align: center; max-width: 460px; margin: 0 auto; }
.logo { font-size: 3.2rem; }
h1 { font-size: 1.3rem; margin: .4rem 0 .6rem; }
.ayuda { color: var(--gris); font-size: .88rem; line-height: 1.45; }
.msg { min-height: 1.4rem; font-size: .9rem; margin-top: .8rem; font-weight: 600; }
.msg.error { color: var(--mal); }
.msg.ok { color: var(--ok); }

/* ---------------- Botones ---------------- */
.btn {
  display: inline-block; width: 100%; border: 0; border-radius: 12px;
  padding: .85rem 1rem; font-size: 1rem; font-weight: 600;
  cursor: pointer; margin-top: .6rem;
}
.btn-lg { padding: 1rem; font-size: 1.05rem; }
.btn-pri { background: var(--pri); color: #fff; }
.btn-sec { background: #fff; color: #212529; border: 1px solid var(--linea); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-peligro { background: var(--mal); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; }

.separador { display: flex; align-items: center; gap: .6rem; color: var(--gris);
             font-size: .8rem; margin: 1rem 0 .3rem; }
.separador::before, .separador::after { content: ""; flex: 1; height: 1px; background: var(--linea); }

.input-codigo {
  width: 100%; text-align: center; font-size: 1.7rem; letter-spacing: .3rem;
  font-family: ui-monospace, Menlo, Consolas, monospace; text-transform: uppercase;
  padding: .7rem; border: 2px solid var(--linea); border-radius: 12px;
}
.input-codigo:focus { outline: 0; border-color: var(--pri); }

/* ---------------- Cámara ---------------- */
#camaraCaja video {
  width: 100%; max-width: 380px; border-radius: 14px; background: #000; aspect-ratio: 1/1;
  object-fit: cover;
}

/* ---------------- Listas y tarjetas ---------------- */
.barra-acciones {
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem .9rem; background: #fff; border-bottom: 1px solid var(--linea);
  position: sticky; top: 0; z-index: 10;
}
.barra-acciones .btn { width: auto; margin: 0; padding: .55rem .9rem; font-size: .9rem; }
/* Botón de filtro del mapa cuando está aplicado */
.barra-acciones .btn.activo {
  background: var(--pri); color: #fff; border-color: var(--pri); font-weight: 600;
}
.btn-filtro::before { content: "◉ "; }
.pendientes { font-size: .8rem; color: var(--warn); font-weight: 600; }

.lista { padding: .8rem; display: flex; flex-direction: column; gap: .7rem; }

.card {
  background: #fff; border-radius: 14px; padding: .85rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card h3 { margin: 0 0 .5rem; font-size: .95rem; }

.cliente { border-left: 5px solid var(--gris); }
.cliente.pendiente { border-left-color: var(--warn); }
.cliente.entregado { border-left-color: var(--ok); }
.cliente.rebotado  { border-left-color: var(--mal); }
.cliente-top { display: flex; align-items: flex-start; gap: .5rem; }
.cliente-nom { font-weight: 700; font-size: .95rem; flex: 1; line-height: 1.25; }
.cliente-meta { font-size: .78rem; color: var(--gris); margin-top: .25rem; }
.cliente-nums { display: flex; gap: 1rem; margin-top: .45rem; font-size: .82rem; }
.cliente-nums b { font-variant-numeric: tabular-nums; }

/* Aviso de visita abierta: late suave para que no pase desapercibido */
.visita-abierta {
  border: 2px solid var(--pri); background: #eaf1ff;
  animation: latido 2.2s ease-in-out infinite;
}
@keyframes latido {
  0%, 100% { box-shadow: 0 0 0 0 rgba(13,110,253,.30); }
  50%      { box-shadow: 0 0 0 7px rgba(13,110,253,0); }
}

.pill {
  font-size: .7rem; padding: .18rem .5rem; border-radius: 999px;
  font-weight: 700; white-space: nowrap; color: #fff;
}
.pill.gris { background: var(--gris); }
.pill.ok   { background: var(--ok); }
.pill.warn { background: var(--warn); }
.pill.mal  { background: var(--mal); }

.kv { display: flex; justify-content: space-between; gap: 1rem;
      padding: .35rem 0; border-bottom: 1px solid #f1f3f5; font-size: .87rem; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--gris); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .78rem; }

.resumen { display: flex; gap: .45rem; padding: .8rem .8rem 0; }
.resumen .r-item {
  flex: 1; background: #fff; border-radius: 12px; padding: .55rem .3rem; text-align: center;
  cursor: pointer; border: 2px solid transparent; transition: border-color .12s, transform .08s;
  position: relative; user-select: none;
}
.resumen .r-item:active { transform: scale(.97); }
/* Tarjeta tildada = filtro activo */
.resumen .r-item.sel { border-color: var(--pri); background: #eaf1ff; }
.resumen .r-item.sel::after {
  content: "✓"; position: absolute; top: -7px; right: -7px;
  background: var(--pri); color: #fff; border-radius: 50%;
  width: 20px; height: 20px; font-size: .72rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.resumen .r-num { font-size: 1.35rem; font-weight: 700; line-height: 1; }
.resumen .r-lbl { font-size: .68rem; color: var(--gris); margin-top: .2rem; }

/* Cliente para volver más tarde */
.cliente.volver { border-left-color: var(--pri); }

.vacio { text-align: center; color: var(--gris); padding: 2.5rem 1rem; }

/* ---------------- Tabbar ---------------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--linea);
  padding-bottom: var(--safe-bot);
}
.tab {
  flex: 1; border: 0; background: none; padding: .5rem 0 .45rem;
  font-size: 1.25rem; color: var(--gris); display: flex; flex-direction: column;
  align-items: center; gap: .1rem;
}
.tab span { font-size: .68rem; font-weight: 600; }
.tab.activo { color: var(--pri); }

/* ---------------- Mapa ---------------- */
#mapa { width: 100%; height: calc(100vh - 210px); min-height: 320px; }
.leaflet-container { font-family: inherit; }
.mk-pin {
  width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.45); display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: .7rem; font-weight: 700;
}
.mk-pendiente { background: var(--warn); }
.mk-entregado { background: var(--ok); }
.mk-rebotado  { background: var(--mal); }
.pop-nom { font-weight: 700; font-size: .88rem; margin-bottom: .2rem; }
.pop-btn {
  display: block; width: 100%; margin-top: .45rem; text-align: center;
  background: var(--pri); color: #fff; border-radius: 8px; padding: .45rem;
  text-decoration: none; font-weight: 600; font-size: .82rem; border: 0;
}

/* ---------------- Cliente / visita ---------------- */
.cronometro {
  margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700;
  color: var(--ok); font-size: 1rem;
}
.comp-fila {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem 0; border-bottom: 1px solid #f1f3f5;
}
.comp-fila:last-child { border-bottom: 0; }
.comp-datos { flex: 1; min-width: 0; }
.comp-nro { font-weight: 700; font-size: .88rem; }
.comp-sub { font-size: .76rem; color: var(--gris); margin-top: .15rem; }
.comp-fila .btn { width: auto; margin: 0; padding: .5rem .8rem; font-size: .85rem; }

/* ---------------- Modal ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-caja {
  background: #fff; width: 100%; max-width: 520px;
  border-radius: 18px 18px 0 0; padding: 1.1rem 1rem calc(1.1rem + var(--safe-bot));
  max-height: 88vh; overflow-y: auto;
}
.modal-caja h3 { margin: 0 0 .3rem; font-size: 1.05rem; }
.lbl { display: block; font-size: .8rem; color: var(--gris); margin: .8rem 0 .25rem; font-weight: 600; }
.select, .textarea {
  width: 100%; padding: .75rem; font-size: 1rem; border: 1px solid var(--linea);
  border-radius: 10px; font-family: inherit; background: #fff;
}
.select:focus, .textarea:focus { outline: 0; border-color: var(--pri); }
.modal-botones { display: flex; gap: .6rem; margin-top: 1rem; }
.modal-botones .btn { margin: 0; }
.obligatorio { color: var(--mal); }

/* ---------------- Modal de aviso / confirmación ---------------- */
.aviso-caja { text-align: center; padding-top: 1.4rem; }
.aviso-icono {
  width: 58px; height: 58px; border-radius: 50%; margin: 0 auto .7rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.7rem; font-weight: 700; line-height: 1;
}
.aviso-caja h3 { margin: 0 0 .4rem; font-size: 1.1rem; }
.aviso-texto { color: var(--gris); font-size: .9rem; line-height: 1.5; white-space: pre-line; }
.aviso-texto b { color: #212529; }

.av-info    .aviso-icono { background: #cfe2ff; color: #084298; }
.av-exito   .aviso-icono { background: #d1e7dd; color: #0a3622; }
.av-aviso   .aviso-icono { background: #fff3cd; color: #664d03; }
.av-peligro .aviso-icono { background: #f8d7da; color: #58151c; }
.av-peligro #avOk { background: var(--mal); }
.av-aviso   #avOk { background: var(--warn); }

/* ---------------- Toast (estilo alerta) ---------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-bot));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: .55rem;
  padding: .7rem 1rem; border-radius: 12px; font-size: .88rem; font-weight: 500;
  z-index: 60; max-width: min(92vw, 460px); text-align: left;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  border: 1px solid transparent;
  animation: toast-in .18s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.toast .t-ico {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; color: #fff;
}
/* Paleta de alertas de Bootstrap */
.toast          { background: #cff4fc; color: #055160; border-color: #b6effb; }
.toast .t-ico   { background: #087990; }
.toast.ok       { background: #d1e7dd; color: #0a3622; border-color: #badbcc; }
.toast.ok .t-ico{ background: #198754; }
.toast.mal      { background: #f8d7da; color: #58151c; border-color: #f5c2c7; }
.toast.mal .t-ico{ background: #dc3545; }
.toast.aviso    { background: #fff3cd; color: #664d03; border-color: #ffecb5; }
.toast.aviso .t-ico { background: #fd7e14; }
