/* Panel de ventas EXSA Salud — mobile-first (390px), sin requests externos. */

:root {
  --azul-exsa: #1a6fb5;
  --azul-oscuro: #1a3a5c;
  --verde-plan: #27ae60;
  --rojo-alerta: #e74c3c;
  --gris-burbuja: #f0f0f0;
  --texto-principal: #2c3e50;
  --texto-secundario: #7f8c8d;

  --verde-vendedor: #1e6b3f;
  --ambar: #d68910;
  --gris-boton: #e3e6e8;
  --borde: #dfe3e6;
  --fondo: #f5f7f9;
  --blanco: #ffffff;
  --radio: 8px;
  --alto-boton: 48px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

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

[x-cloak] {
  display: none !important;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

/* ── Botones ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--alto-boton);
  padding: 0 20px;
  border: 0;
  border-radius: var(--radio);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
}

.btn:active:not(:disabled) {
  filter: brightness(0.85);
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn:focus-visible,
.icon-btn:focus-visible,
.card:focus-visible {
  outline: 3px solid var(--azul-exsa);
  outline-offset: 2px;
}

.btn-block {
  width: 100%;
}

.btn-primario {
  background: var(--azul-exsa);
  color: var(--blanco);
}

.btn-peligro {
  background: var(--rojo-alerta);
  color: var(--blanco);
}

.btn-secundario {
  background: var(--gris-boton);
  color: var(--texto-principal);
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--alto-boton);
  min-height: var(--alto-boton);
  padding: 0 8px;
  border: 0;
  border-radius: var(--radio);
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.15);
}

.icon-btn svg {
  width: 26px;
  height: 26px;
}

/* ── Login ────────────────────────────────────────────────────────────────── */

.login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--azul-oscuro);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 20px;
  background: var(--blanco);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.login-marca {
  margin: 0 0 4px;
  font-size: 26px;
  color: var(--azul-oscuro);
  text-align: center;
}

.login-sub {
  margin: 0 0 24px;
  color: var(--texto-secundario);
  text-align: center;
}

.campo {
  display: block;
  margin-bottom: 16px;
}

.campo span {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 15px;
}

.campo input {
  width: 100%;
  min-height: var(--alto-boton);
  padding: 0 14px;
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  background: var(--blanco);
  font-size: 16px; /* >= 16px: iOS no hace zoom al enfocar */
}

.campo input:focus {
  outline: none;
  border-color: var(--azul-exsa);
  box-shadow: 0 0 0 3px rgba(26, 111, 181, 0.2);
}

.error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: var(--radio);
  background: #fdecea;
  color: #a93226;
  font-size: 15px;
}

/* ── Header fijo ──────────────────────────────────────────────────────────── */

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: 4px 8px;
  padding-top: calc(4px + env(safe-area-inset-top, 0px));
  background: var(--azul-oscuro);
  color: var(--blanco);
}

.header-titulo {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding-left: 8px;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-acciones {
  display: flex;
  align-items: center;
}

.badge-contador {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--rojo-alerta);
  color: var(--blanco);
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.icon-btn.activo {
  background: rgba(255, 255, 255, 0.18);
}

.aviso-conexion {
  padding: 8px 16px;
  background: #fff4e0;
  color: #8a5a00;
  font-size: 14px;
  text-align: center;
}

/* ── Inbox ────────────────────────────────────────────────────────────────── */

.lista {
  list-style: none;
  margin: 0;
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom, 0px));
}

.lista li + li {
  margin-top: 10px;
}

.card {
  display: block;
  width: 100%;
  padding: 14px 14px 12px;
  border: 1px solid var(--borde);
  border-left: 5px solid transparent;
  border-radius: var(--radio);
  background: var(--blanco);
  color: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.card:active {
  background: #eef3f8;
}

.card.pendiente {
  border-left-color: var(--rojo-alerta);
}

.card-fila {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-fila + .card-fila {
  margin-top: 8px;
}

.card-nombre {
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-tiempo {
  flex-shrink: 0;
  color: var(--texto-secundario);
  font-size: 14px;
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-plan-200 {
  background: #e3effa;
  color: var(--azul-exsa);
}

.badge-plan-300 {
  background: #e2f5ea;
  color: #1d8348;
}

.badge-plan-otro {
  background: var(--gris-boton);
  color: var(--texto-principal);
}

.badge-activo {
  background: #e2f5ea;
  color: #1d8348;
}

.badge-esperando {
  background: #fdecea;
  color: #a93226;
}

.badge-pausado {
  background: #fff4e0;
  color: #8a5a00;
}

.error-lista {
  margin: 12px;
}

.vacio {
  padding: 48px 24px;
  color: var(--texto-secundario);
  text-align: center;
}

/* ── Chat ─────────────────────────────────────────────────────────────────── */

.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.chat .header {
  position: static;
  flex-shrink: 0;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-info .header-titulo {
  padding-left: 0;
}

.header-sub {
  font-size: 13px;
  opacity: 0.85;
}

.ficha {
  flex-shrink: 0;
  background: var(--blanco);
  border-bottom: 1px solid var(--borde);
}

.ficha-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: var(--alto-boton);
  padding: 0 16px;
  border: 0;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}

.ficha-toggle:active {
  background: var(--fondo);
}

.ficha-flecha {
  color: var(--texto-secundario);
}

.ficha-datos {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  padding: 0 16px 12px;
  max-height: 35vh;
  overflow-y: auto;
  font-size: 15px;
}

/* El par dt/dd va envuelto (x-for necesita un solo nodo) sin romper la grilla. */
.ficha-par {
  display: contents;
}

.ficha-datos dt {
  color: var(--texto-secundario);
}

.ficha-datos dd {
  margin: 0;
  font-weight: 600;
  word-break: break-word;
}

.ficha-vacia {
  margin: 0;
  padding: 0 16px 14px;
  color: var(--texto-secundario);
  font-size: 15px;
}

.mensajes {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}

.burbuja {
  max-width: 82%;
  margin-bottom: 8px;
  padding: 8px 12px 6px;
  border-radius: 12px;
  word-wrap: break-word;
}

/* pre-wrap solo en el texto: respeta los saltos de linea del mensaje sin
   heredar la indentacion del HTML. */
.burbuja-texto {
  white-space: pre-wrap;
}

.burbuja-autor {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
  font-weight: 700;
}

.burbuja-hora {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  text-align: right;
  opacity: 0.75;
}

.burbuja-prospecto {
  margin-right: auto;
  border-bottom-left-radius: 4px;
  background: var(--gris-burbuja);
  color: var(--texto-principal);
}

.burbuja-bot,
.burbuja-vendedor {
  margin-left: auto;
  border-bottom-right-radius: 4px;
  color: var(--blanco);
}

.burbuja-bot {
  background: var(--azul-exsa);
}

.burbuja-vendedor {
  background: var(--verde-vendedor);
}

.banner {
  flex-shrink: 0;
  padding: 10px 16px;
  background: #fff4e0;
  color: #8a5a00;
  font-size: 14px;
  text-align: center;
}

.barra {
  flex-shrink: 0;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--blanco);
  border-top: 1px solid var(--borde);
}

.barra-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.barra-input textarea {
  flex: 1;
  min-width: 0;
  min-height: var(--alto-boton);
  max-height: 140px;
  padding: 12px 14px;
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  resize: none;
  font-size: 16px;
  line-height: 1.4;
}

.barra-input textarea:focus {
  outline: none;
  border-color: var(--azul-exsa);
}

.btn-enviar {
  flex-shrink: 0;
  width: var(--alto-boton);
  padding: 0;
}

.btn-enviar svg {
  width: 22px;
  height: 22px;
}

.barra .btn-secundario {
  margin-top: 10px;
}

.barra .error {
  margin: 0 0 10px;
}

.cargando {
  padding: 48px 24px;
  color: var(--texto-secundario);
  text-align: center;
}

/* Pantallas mas anchas (tablet/escritorio): contenido centrado. */
@media (min-width: 720px) {
  .lista,
  .chat-contenido {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }
}
