/* CRM fase 4 · Etapa 3 · Chats (primero el celular) + marca Élite Group.
   Todo lo de Chats cuelga de #view-chats, .bottom-nav o body.has-chats: no cambia
   la cartera ni la supervisión de quien no tiene el interruptor crm_chat. */

:root {
  --eg-turquesa: #00B8B8;
  --eg-turquesa-texto: #007A7A;   /* turquesa con contraste suficiente sobre blanco */
  --eg-turquesa-suave: #DDF5F5;
  --eg-amarillo: #F8E800;
  --eg-verde: #08B840;
  --eg-marino: #36445F;
  --eg-negro: #111418;
  --eg-azul-leido: #2F8CFF;
  --ch-fondo: #F1F4F6;
  --ch-linea: #E3E8EE;
  --ch-gris: #6B7585;
  --ch-nav-alto: 62px;
}

/* --- Marca: logo en la cabecera y en el acceso ------------------------------ */
.brand-mark {
  border-color: rgba(255, 255, 255, 0.35);
  background: #ffffff url("/brand/icono-192.png") center / 82% no-repeat;
  color: transparent;
  font-size: 0;
}

/* --- Navegación: pestaña Chats (escritorio) y barra inferior (celular) ------ */
.nav-badge,
.bottom-nav-badge {
  min-width: 18px;
  height: 18px;
  margin-left: auto;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--eg-amarillo);
  color: var(--eg-negro);
  font-size: 10px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

.bottom-nav {
  display: none;
}

@media (max-width: 820px) {
  /* has-bottom-nav (movil.js): también sin Chats, si hay Cartera y Resumen. */
  body.has-chats .bottom-nav,
  body.has-bottom-nav .bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 900;
    display: grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    height: calc(var(--ch-nav-alto) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--ch-linea);
    background: #ffffff;
    box-shadow: 0 -4px 18px rgba(17, 20, 24, 0.06);
  }

  body.has-chats.ch-chat-abierto .bottom-nav {
    display: none;
  }

  .bottom-nav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: var(--ch-gris);
    font: inherit;
    font-size: 11px;
    font-weight: 650;
    cursor: pointer;
  }

  .bottom-nav-item svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .bottom-nav-item.is-active {
    color: var(--eg-turquesa-texto);
  }

  .bottom-nav-item.is-active::before {
    content: "";
    position: absolute;
    top: 0;
    width: 36px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--eg-turquesa);
  }

  .bottom-nav-badge {
    position: absolute;
    top: 6px;
    left: calc(50% + 6px);
    margin: 0;
  }

  /* Con la barra inferior el contenido no queda tapado. El menú de arriba se mantiene en las
     demás vistas (Seguimiento y Campañas no están en la barra) y solo se oculta en Chats. */
  body.has-chats .main-content,
  body.has-bottom-nav .main-content {
    padding-bottom: calc(var(--ch-nav-alto) + env(safe-area-inset-bottom) + 14px);
  }

  body.has-chats.vista-chats .sidebar,
  body.has-chats.vista-chats .topbar,
  body.has-chats.vista-chats .app-footer {
    display: none;
  }

  body.has-chats.vista-chats .main-content {
    padding: 0 0 calc(var(--ch-nav-alto) + env(safe-area-inset-bottom));
  }
}

/* Escritorio: Chats usa todo el alto disponible. */
body.vista-chats .topbar,
body.vista-chats .app-footer {
  display: none;
}

/* --- Contenedor -------------------------------------------------------------- */
#view-chats {
  color: var(--eg-negro);
}

.ch {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  height: calc(100vh - 38px);
  height: calc(100dvh - 38px);
  overflow: hidden;
  border: 1px solid var(--ch-linea);
  border-radius: 12px;
  background: #ffffff;
}

.ch svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ch button,
.ch input,
.ch textarea,
.ch select {
  font: inherit;
}

/* --- Lista ------------------------------------------------------------------ */
.ch-lista-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--ch-linea);
}

.ch-lista-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 14px 10px 8px 16px;
}

.ch-marca {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ch-marca img {
  border-radius: 8px;
}

.ch-marca h2 {
  margin: 0;
  color: var(--eg-negro);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.ch-envivo {
  margin-left: auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #C5CCD6;
}

.ch-envivo.is-on {
  background: var(--eg-verde);
  box-shadow: 0 0 0 3px rgba(8, 184, 64, 0.18);
}

.ch-buscar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 16px 8px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--ch-fondo);
  color: var(--ch-gris);
}

.ch-buscar svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.ch-buscar input {
  width: 100%;
  min-height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--eg-negro);
  font-size: 16px;   /* 16px: iOS no hace zoom al enfocar */
}

.ch-filtros {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 0 16px 10px;
  overflow-x: auto;       /* si no entran, se deslizan; nunca se cortan */
  scrollbar-width: none;
}

.ch-filtros::-webkit-scrollbar {
  display: none;
}

.ch-chip {
  flex: none;
  min-height: 32px;
  padding: 0 13px;
  border: 1px solid var(--ch-linea);
  border-radius: 16px;
  background: #ffffff;
  color: var(--eg-marino);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.ch-chip.is-on {
  border-color: var(--eg-turquesa);
  background: var(--eg-turquesa-suave);
  color: var(--eg-turquesa-texto);
}

.ch-asesor {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 16px 10px;
  color: var(--eg-marino);
  font-size: 13px;
  font-weight: 650;
}

.ch-asesor[hidden] {
  display: none;
}

.ch-asesor select {
  min-height: 34px;
  max-width: 100%;
  padding: 0 28px 0 10px;
  border: 1px solid var(--ch-linea);
  border-radius: 10px;
  background: #ffffff;
  color: var(--eg-negro);
  font-size: 14px;
}

.ch-lista {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0 0 8px;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}

.ch-item {
  display: flex;
  width: 100%;
  gap: 12px;
  padding: 11px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.ch-item:hover {
  background: #F7F9FA;
}

.ch-item.is-active {
  background: var(--eg-turquesa-suave);
}

.ch-avatar {
  display: grid;
  width: 46px;
  height: 46px;
  flex: none;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  font-size: 15px;
  font-weight: 750;
}

.ch-avatar.t1 { background: #00A3A3; }
.ch-avatar.t2 { background: #36445F; }
.ch-avatar.t3 { background: #0E8F6E; }
.ch-avatar.t4 { background: #5B6B8C; }
.ch-avatar.t5 { background: #1F8FB3; }

.ch-item-main {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 3px;
  padding-bottom: 11px;
  border-bottom: 1px solid #EEF1F4;
}

.ch-item-top,
.ch-item-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.ch-item-top strong {
  overflow: hidden;
  color: var(--eg-negro);
  font-size: 16px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-item-top time {
  flex: none;
  color: var(--ch-gris);
  font-size: 12px;
}

.ch-item.is-unread .ch-item-top strong {
  font-weight: 800;
}

.ch-item.is-unread .ch-item-top time {
  color: var(--eg-negro);
  font-weight: 700;
}

.ch-preview {
  overflow: hidden;
  color: var(--ch-gris);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-item.is-unread .ch-preview {
  color: var(--eg-negro);
}

.ch-quien {
  color: var(--eg-marino);
  font-weight: 650;
}

.ch-dot {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 50%;
  background: var(--eg-amarillo);
  box-shadow: 0 0 0 1.5px rgba(17, 20, 24, 0.35);
}

.ch-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ch-ventana,
.ch-tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 10px;
  background: #EEF8F2;
  color: #067A2D;
  font-size: 11px;
  font-weight: 650;
}

.ch-ventana.is-vence {
  background: #FFF6CC;
  color: #7A5A00;
}

.ch-ventana.is-cerrada {
  background: #EEF1F4;
  color: var(--ch-gris);
}

.ch-tag {
  background: #EEF1F6;
  color: var(--eg-marino);
}

.ch-tag-dueno {
  background: var(--eg-turquesa-suave);
  color: var(--eg-turquesa-texto);
}

.ch-tag-alerta {
  background: #FFF6CC;
  color: #7A5A00;
}

.ch-estado {
  padding: 28px 20px;
  color: var(--ch-gris);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  list-style: none;
}

.ch-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--eg-turquesa-texto);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

/* --- Panel del chat -------------------------------------------------------- */
.ch-chat-panel {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--ch-fondo);
}

.ch-vacio-escritorio {
  display: grid;
  flex: 1;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--ch-gris);
}

.ch-vacio-escritorio img {
  opacity: 0.85;
}

.ch-chat {
  position: relative;
  display: flex;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}

.ch-chat-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 60px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--ch-linea);
  background: #ffffff;
}

.ch-chat-head .ch-avatar {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

.ch-chat-titulo {
  display: grid;
  min-width: 0;
  flex: 1;
  padding: 2px 4px;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.ch-chat-titulo strong {
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-chat-titulo span {
  color: var(--ch-gris);
  font-size: 12px;
}

.ch-icon {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: none;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--eg-marino);
  cursor: pointer;
}

.ch-icon:hover {
  background: #F1F4F6;
}

.ch-icon svg {
  width: 23px;
  height: 23px;
}

.ch-volver {
  display: none;
}

.ch-bot {
  color: var(--eg-turquesa-texto);
}

.ch-bot.is-pausado {
  position: relative;
  color: #A0A8B5;
}

.ch-bot.is-pausado::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 2px;
  background: #C2414B;
  transform: rotate(-45deg);
}

.ch-mensajes {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 8px 12px 14px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.ch-cargar {
  min-height: 18px;
  color: var(--ch-gris);
  font-size: 12px;
  text-align: center;
}

.ch-burbujas {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: auto 0 0;   /* chat corto: pegado abajo, como en WhatsApp */
  padding: 0;
  list-style: none;
}

.ch-dia,
.ch-sistema {
  display: flex;
  justify-content: center;
  margin: 10px 0 6px;
}

.ch-dia span {
  padding: 4px 12px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 1px 1px rgba(17, 20, 24, 0.08);
  color: var(--eg-marino);
  font-size: 12px;
  font-weight: 650;
}

.ch-sistema {
  margin: 4px 0;
}

.ch-sistema span {
  max-width: 85%;
  padding: 3px 10px;
  border-radius: 8px;
  background: rgba(54, 68, 95, 0.07);
  color: var(--ch-gris);
  font-size: 11.5px;
  text-align: center;
}

.ch-nota {
  display: flex;
  justify-content: center;
  margin: 6px 0;
}

.ch-nota > div {
  max-width: 88%;
  padding: 7px 12px 6px;
  border: 1px dashed #C7CFDA;
  border-radius: 10px;
  background: #E9EDF1;
  color: #3D4757;
  font-size: 13px;
  text-align: center;
}

.ch-nota-quien {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ch-gris);
  font-size: 11px;
  font-weight: 700;
}

.ch-nota-quien svg {
  width: 13px;
  height: 13px;
}

.ch-nota p {
  margin: 3px 0 0;
  line-height: 1.4;
}

.ch-nota time {
  display: block;
  color: var(--ch-gris);
  font-size: 10.5px;
}

.ch-b {
  display: flex;
  flex-direction: column;
  transition: transform 160ms ease;
}

.ch-b.is-in {
  align-items: flex-start;
}

.ch-b.is-out {
  align-items: flex-end;
}

.ch-burbuja {
  position: relative;
  max-width: min(78%, 520px);
  padding: 6px 9px 5px;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 1px 1px rgba(17, 20, 24, 0.09);
  font-size: 15px;
  line-height: 1.38;
  overflow-wrap: anywhere;
}

.ch-b.is-in .ch-burbuja {
  border-top-left-radius: 3px;
}

.ch-b.is-out .ch-burbuja {
  border-top-right-radius: 3px;
}

.ch-b-asesor .ch-burbuja {
  background: var(--eg-turquesa-suave);
}

.ch-b-asistente .ch-burbuja {
  border: 1px solid #DCE3EC;
  background: #F7F9FC;
}

.ch-autor {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
  color: var(--eg-turquesa-texto);
  font-size: 12px;
  font-weight: 750;
}

.ch-autor-bot {
  color: var(--eg-marino);
}

.ch-autor svg {
  width: 14px;
  height: 14px;
}

.ch-texto a {
  color: var(--eg-turquesa-texto);
}

.ch-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  float: right;
  margin: 6px 0 -3px 10px;
  color: var(--ch-gris);
  font-size: 11px;
}

.ch-estado-msg {
  display: inline-flex;
  color: #8D96A4;
}

.ch-tick {
  width: 16px;
  height: 11px;
  stroke-width: 1.7;
}

.ch-estado-msg.is-entregado {
  color: var(--eg-verde);
}

.ch-estado-msg.is-leido {
  color: var(--eg-azul-leido);
}

.ch-estado-msg.is-enviando .ch-tick {
  width: 13px;
  height: 13px;
}

.ch-fallo {
  max-width: min(78%, 520px);
  margin: 3px 2px 2px;
  color: #B42318;
  font-size: 12px;
  text-align: right;
}

.ch-cita {
  margin: 1px 0 5px;
  padding: 5px 8px;
  border-left: 3px solid var(--eg-turquesa);
  border-radius: 6px;
  background: rgba(17, 20, 24, 0.05);
  color: var(--eg-marino);
  font-size: 13px;
}

.ch-cita span {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.ch-responder {
  position: absolute;
  top: 50%;
  display: none;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(17, 20, 24, 0.15);
  color: var(--eg-marino);
  cursor: pointer;
  transform: translateY(-50%);
}

.ch-responder svg {
  width: 17px;
  height: 17px;
}

.ch-b.is-in .ch-responder { right: -38px; }
.ch-b.is-out .ch-responder { left: -38px; }

@media (hover: hover) {
  .ch-b:hover .ch-responder {
    display: grid;
  }
}

.ch-b.is-citando .ch-burbuja {
  box-shadow: 0 0 0 2px var(--eg-turquesa);
}

.ch-img {
  display: block;
  margin: -2px -5px 4px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: #E3E8EE;
  cursor: zoom-in;
}

.ch-img img {
  display: block;
  width: 100%;
  max-width: 280px;
  max-height: 320px;
  min-height: 80px;
  object-fit: cover;
}

.ch-audio {
  width: 250px;
  max-width: 100%;
  height: 40px;
  margin: 2px 0 4px;
}

.ch-video {
  display: block;
  width: 280px;
  max-width: 100%;
  margin: 0 -4px 4px;
  border-radius: 8px;
  background: #000000;
}

.ch-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 210px;
  margin: 2px 0 4px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(17, 20, 24, 0.05);
  color: var(--eg-negro);
  text-decoration: none;
}

.ch-doc svg {
  width: 26px;
  height: 26px;
  flex: none;
  color: var(--eg-turquesa-texto);
}

.ch-doc span {
  display: grid;
  min-width: 0;
}

.ch-doc strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-doc small {
  color: var(--ch-gris);
}

/* --- Pie ------------------------------------------------------------------- */
.ch-pie {
  position: relative;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--ch-fondo);
}

.ch-avisos {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px 6px;
}

.ch-aviso {
  color: var(--ch-gris);
  font-size: 12px;
}

.ch-aviso + .ch-aviso::before {
  content: "·";
  margin-right: 6px;
}

.ch-aviso.is-vence {
  color: #8A6500;
  font-weight: 700;
}

.ch-caja {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.ch-caja textarea {
  flex: 1;
  min-height: 46px;
  max-height: 140px;
  padding: 12px 14px;
  border: 0;
  border-radius: 23px;
  outline: 0;
  background: #ffffff;
  box-shadow: 0 1px 1px rgba(17, 20, 24, 0.08);
  color: var(--eg-negro);
  font-size: 16px;
  line-height: 1.35;
  resize: none;
}

.ch-clip {
  width: 46px;
  height: 46px;
  background: #ffffff;
  box-shadow: 0 1px 1px rgba(17, 20, 24, 0.08);
}

.ch-enviar {
  display: grid;
  width: 46px;
  height: 46px;
  flex: none;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--eg-turquesa);
  color: #ffffff;
  cursor: pointer;
}

.ch-enviar svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: currentColor;
}

.ch-citando {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px;
  padding: 6px 6px 6px 10px;
  border-left: 4px solid var(--eg-turquesa);
  border-radius: 10px;
  background: #ffffff;
}

.ch-citando div {
  display: grid;
  min-width: 0;
  flex: 1;
}

.ch-citando small {
  color: var(--eg-turquesa-texto);
  font-weight: 750;
}

.ch-citando span {
  overflow: hidden;
  color: var(--eg-marino);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-rapidas,
.ch-menu-adjunto {
  position: absolute;
  right: 8px;
  bottom: calc(100% + 4px);
  left: 8px;
  z-index: 5;
  max-height: 50vh;
  overflow-y: auto;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 8px 30px rgba(17, 20, 24, 0.18);
}

.ch-rapidas ul {
  margin: 0;
  padding: 6px 0;
  list-style: none;
}

.ch-rapidas li {
  display: flex;
  align-items: center;
}

.ch-rapida {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 2px;
  padding: 9px 14px;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.ch-rapida:hover {
  background: #F4F7F9;
}

.ch-rapida strong {
  color: var(--eg-turquesa-texto);
}

.ch-rapida-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ch-rapida em {
  padding: 0 6px;
  border-radius: 8px;
  background: #EEF1F6;
  color: var(--eg-marino);
  font-size: 11px;
  font-style: normal;
}

.ch-rapida span {
  overflow: hidden;
  color: var(--eg-marino);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-rapida-nueva {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border-top: 1px solid var(--ch-linea);
  text-align: left;
  text-decoration: none;
}

.ch-form-rapida {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.ch-form-rapida label {
  display: grid;
  gap: 4px;
  color: var(--eg-marino);
  font-size: 13px;
  font-weight: 650;
}

.ch-form-rapida input:not([type="checkbox"]),
.ch-form-rapida textarea,
.ch-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--ch-linea);
  border-radius: 10px;
  font-size: 16px;
}

.ch-form-rapida .ch-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.ch-form-acciones,
.ch-cerrada-acciones,
.ch-resultados {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ch-form-acciones {
  justify-content: flex-end;
}

.ch-menu-adjunto {
  right: auto;
  display: flex;
  gap: 4px;
  padding: 10px;
}

.ch-menu-adjunto[hidden],
.ch-rapidas[hidden] {
  display: none;
}

.ch-menu-adjunto button {
  display: grid;
  width: 82px;
  justify-items: center;
  gap: 6px;
  padding: 10px 4px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--eg-marino);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.ch-menu-adjunto button:hover {
  background: #F4F7F9;
}

.ch-menu-adjunto svg {
  width: 44px;
  height: 44px;
  padding: 10px;
  border-radius: 50%;
  background: var(--eg-turquesa-suave);
  color: var(--eg-turquesa-texto);
}

.ch-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--ch-linea);
  border-radius: 21px;
  background: #ffffff;
  color: var(--eg-marino);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.ch-btn svg {
  width: 18px;
  height: 18px;
}

.ch-btn-primario {
  border-color: var(--eg-turquesa);
  background: var(--eg-turquesa);
  color: #ffffff;
}

.ch-btn:disabled {
  opacity: 0.5;
}

.ch-cerrada {
  padding: 12px 10px 6px;
  text-align: center;
}

.ch-cerrada p {
  margin: 0 0 10px;
  color: var(--eg-marino);
  font-size: 14px;
  line-height: 1.45;
}

.ch-cerrada-acciones {
  justify-content: center;
}

/* --- Hojas (adjunto y ficha) ---------------------------------------------- */
.ch-hoja {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  background: rgba(17, 20, 24, 0.38);
}

.ch-hoja[hidden] {
  display: none;
}

.ch-hoja-panel {
  display: flex;
  width: 100%;
  max-height: 92%;
  flex-direction: column;
  border-radius: 18px 18px 0 0;
  background: #ffffff;
}

.ch-hoja-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 6px 18px;
  font-size: 16px;
}

.ch-hoja-previa {
  display: grid;
  place-items: center;
  padding: 8px 16px;
  overflow: auto;
}

.ch-hoja-previa img {
  max-width: 100%;
  max-height: 50vh;
  border-radius: 10px;
}

.ch-hoja-panel .ch-caja {
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
}

.ch-hoja-panel .ch-caja textarea {
  background: var(--ch-fondo);
  box-shadow: none;
}

.ch-ficha-cuerpo {
  padding: 0 18px 18px;
  overflow-y: auto;
  color: var(--eg-negro);
  font-size: 14px;
  line-height: 1.45;
}

.ch-ficha-cuerpo h4 {
  margin: 16px 0 6px;
  color: var(--eg-marino);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ch-ficha-cuerpo p {
  margin: 0;
}

.ch-ficha-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ch-ficha-cita {
  margin-top: 10px !important;
  color: #067A2D;
  font-weight: 700;
}

.ch-frases,
.ch-seguimiento {
  margin: 0;
  padding-left: 18px;
}

.ch-resultados {
  margin-top: 8px;
}

.ch-resultados .ch-btn {
  min-height: 38px;
  font-size: 13px;
}

/* --- Visor de imágenes ------------------------------------------------------ */
.ch-visor {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 12, 16, 0.92);
}

.ch-visor[hidden] {
  display: none;
}

.ch-visor img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.ch-visor-cerrar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  cursor: pointer;
}

.ch-visor-cerrar svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

/* --- Celular (360–430 px): lista a pantalla completa; el chat se abre encima --- */
@media (max-width: 820px) {
  .ch {
    display: block;
    height: calc(100vh - var(--ch-nav-alto) - env(safe-area-inset-bottom));
    height: calc(100dvh - var(--ch-nav-alto) - env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
  }

  .ch-lista-panel {
    height: 100%;
    border-right: 0;
  }

  .ch-lista-head {
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .ch-chat-panel {
    display: none;
  }

  .ch.is-chat-abierto .ch-chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 1200;
    display: flex;
    height: 100vh;
    height: 100dvh;
  }

  .ch-volver {
    display: inline-grid;
    width: 36px;
    margin-right: -4px;
  }

  .ch-burbuja {
    max-width: 84%;
  }

  .ch-chat-head .ch-icon {
    width: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ch-b {
    transition: none;
  }
}

/* --- Etapa 4 · Avisos en este dispositivo --------------------------------- */
.ch-avisos-btn {
  color: var(--eg-marino);
}

.av-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 8px;
  padding: 8px 6px 8px 12px;
  border-radius: 12px;
  background: #FFFBD6;
  border: 1px solid #F1E37A;
  color: var(--eg-negro);
  font-size: 13px;
  line-height: 1.35;
}

.av-banner span {
  flex: 1;
}

.av-banner .ch-link {
  font-weight: 800;
  white-space: nowrap;
}

.av-x {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ch-gris);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.av-capa {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(17, 20, 24, 0.45);
}

.av-panel {
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: #ffffff;
  box-shadow: 0 -8px 30px rgba(17, 20, 24, 0.18);
}

.av-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 17px;
  color: var(--eg-negro);
}

.av-estado {
  margin: 10px 0 14px;
  color: var(--eg-marino);
  font-size: 15px;
  line-height: 1.45;
}

.av-botones {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.av-guia {
  border-top: 1px solid var(--ch-linea);
  padding-top: 10px;
  color: var(--eg-marino);
  font-size: 13px;
  line-height: 1.5;
}

.av-guia summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--eg-turquesa-texto);
}

.av-guia p {
  margin: 8px 0 0;
}

@media (min-width: 821px) {
  .av-capa {
    align-items: center;
  }

  .av-panel {
    border-radius: 18px;
  }
}

/* Mensajes (toast) en el celular con Chats: arriba, por encima de la barra inferior y del chat.
   Antes quedaban abajo, tapados por la barra Chats · Cartera · Resumen. */
@media (max-width: 820px) {
  body.has-chats .toast,
  body.has-bottom-nav .toast {
    top: calc(env(safe-area-inset-top) + 10px);
    right: 12px;
    bottom: auto;
    left: 12px;
    z-index: 1500;
    max-width: none;
    font-size: 14px;
    line-height: 1.4;
  }
}

/* Celular: todo lo que se toca mide al menos 44 × 44 px (revisado en el simulador a 360 y 412 px).
   En PC Chats no cambia. */
@media (max-width: 820px) {
  .ch-icon,
  .ch-chat-head .ch-icon {
    width: 44px;
    height: 44px;
  }

  .ch-volver {
    width: 44px;
    margin-right: -6px;
  }

  /* Con los íconos más grandes, la cabecera del chat gana espacio quitando separación. */
  .ch-chat-head {
    gap: 2px;
    padding-right: 6px;
    padding-left: 4px;
  }

  .ch-chat-titulo {
    min-height: 44px;
  }

  .ch-buscar input,
  .ch-asesor select,
  .ch-input,
  .ch-btn,
  .ch-resultados .ch-btn {
    min-height: 44px;
  }

  .ch-chip {
    min-height: 44px;
    padding: 0 16px;
    border-radius: 22px;
  }

  .ch-link {
    min-height: 44px;
  }

  .av-x {
    width: 44px;
    height: 44px;
    margin: -6px -8px -6px 0;
  }
}
