/* ─────────────────────────────────────────────────────────────────────────────
   Grupos internos de WhatsApp: lista de grupos + chat del grupo. Se usa igual en
   el panel de administrador (index.html) y en el de sucursal (panel.html). La
   lógica vive en grupos.js; las burbujas, la caja para escribir y la tarjeta de
   descarga son las mismas de la conversación (conversacion.css, clases .cv-).

   Se adapta al ANCHO DEL CONTENEDOR:
   - 760 px o más: lista a la izquierda y chat a la derecha.
   - Menos: solo la lista; al abrir un grupo, solo el chat (con flecha para volver).
   ───────────────────────────────────────────────────────────────────────────── */
.gr {
  container-type: inline-size;
  container-name: gr;
  display: flex;
  height: 100%;
  min-height: 0;
  width: 100%;
  background: var(--surface, #fff);
  color: var(--text, #1E293B);
  font-size: 14px;
  overflow: hidden;
}
.gr *, .gr *::before, .gr *::after { box-sizing: border-box; }
.gr button { font-family: inherit; }

/* ── Lista de grupos ── */
.gr-lista {
  flex: 0 0 340px; width: 340px; min-width: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border, #E2E8F0);
  background: var(--surface, #fff);
}
.gr-lista-cab { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; }
.gr-lista-cab b { font-size: 16px; flex: 1; }
.gr-lista-cab .cv-btn-icono { margin-left: -8px; }
.gr-ayuda { font-size: 12px; color: var(--muted, #64748B); padding: 0 16px 10px; line-height: 1.4; }
.gr-buscar { position: relative; padding: 0 12px 10px; }
.gr-buscar:first-child { padding-top: 12px; }
.gr-buscar:first-child i { margin-top: 1px; }
.gr-buscar i { position: absolute; left: 24px; top: 50%; transform: translateY(-50%); margin-top: -5px; color: var(--muted, #64748B); font-size: 15px; pointer-events: none; }
.gr .gr-buscar input { width: 100%; padding-left: 36px; border-radius: 10px; background: var(--bg, #F1F5F9); }
.gr-items { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 8px 10px; }
.gr-item {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  border: none; background: none; border-radius: 12px; padding: 10px 10px; cursor: pointer; color: inherit;
}
.gr-item:hover { background: var(--bg, #F1F5F9); }
.gr-item.activo { background: var(--primario-suave, #EEF4FF); }
.gr-item-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 700; letter-spacing: .02em;
}
.gr-item-cuerpo { flex: 1; min-width: 0; }
.gr-item-arriba { display: flex; align-items: baseline; gap: 8px; }
.gr-item-nombre { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-item-hora { font-size: 11px; color: var(--muted, #64748B); flex-shrink: 0; }
.gr-item.con-pendientes .gr-item-hora { color: var(--cv-verde-osc, #128C7E); font-weight: 600; }
.gr-item-abajo { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.gr-item-vista { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted, #64748B); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-item-lineas { font-size: 11px; color: var(--suave, #94A3B8); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-insignia {
  flex-shrink: 0; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #fff; background: #25D366;
}
.gr-insignia.arroba { background: #F59E0B; }
.gr-seccion { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; color: var(--suave, #94A3B8); text-transform: uppercase; letter-spacing: .05em; padding: 14px 10px 6px; }
.gr-item.oculto { opacity: .6; }
.gr-item.oculto .gr-item-avatar { filter: grayscale(1); }
.gr-sistema-oculto { background: #F1F5F9; color: #475569; }
.gr .gr-btn-ocultar[hidden] { display: none; }
.gr .gr-btn-ocultar:not([hidden]) { display: inline-flex !important; } /* el estilo de "Ficha" lo esconde en pantallas anchas */
.gr-vacio-lista { padding: 30px 16px; text-align: center; color: var(--muted, #64748B); font-size: 13px; line-height: 1.5; }
.gr-vacio-lista i { display: block; font-size: 40px; opacity: .3; margin-bottom: 8px; }

/* ── Chat del grupo ── */
.gr-chat { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.gr-sin-grupo {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--bg, #F1F5F9); color: var(--muted, #64748B); text-align: center; padding: 20px;
}
.gr-sin-grupo i { font-size: 52px; opacity: .25; }
.gr-sin-grupo p { font-size: 14px; max-width: 320px; line-height: 1.5; }
.gr .cv-avatar.gr-avatar { font-size: 14px; font-weight: 700; }
.gr .gr-volver { display: none; }

/* Separador de día y aviso del sistema dentro del chat */
.gr-dia, .gr-sistema {
  align-self: center; font-size: 11.5px; color: #54656F; background: rgba(255,255,255,.92);
  border-radius: 8px; padding: 4px 10px; margin: 6px 0; box-shadow: 0 1px 1px rgba(0,0,0,.06); text-align: center;
}
.gr-sistema { background: #FFF8E1; color: #6B5B1F; max-width: 90%; line-height: 1.4; }
.gr-mas {
  align-self: center; border: none; border-radius: 999px; background: rgba(255,255,255,.95); color: var(--cv-verde-osc, #128C7E);
  font-size: 12px; font-weight: 600; padding: 6px 14px; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.08); margin-bottom: 4px;
}

/* Quién escribió (en grupos cada burbuja lleva el nombre) */
.gr-autor { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 2px; }
.gr-autor small { font-weight: 500; color: var(--cv-tenue, #64748B); margin-left: 4px; }
.gr-arroba { color: #0B7BD3; font-weight: 600; }
.cv-msg.gr-me-mencionan { box-shadow: 0 0 0 2px #F59E0B, 0 1px 1px rgba(0,0,0,.06); }
.gr-tag-mencion {
  display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700;
  color: #92400E; background: #FEF3C7; border-radius: 999px; padding: 1px 7px; margin-bottom: 4px;
}

/* Contestar como: línea con la que sale el mensaje */
.gr-como {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px 0; font-size: 12px; color: var(--cv-tenue, #64748B);
  background: var(--cv-fondo, #fff); border-top: 1px solid var(--cv-borde, #E2E8F0);
}
.gr-como + .cv-escribir { border-top: none; }
.gr-como .ld, .gr-como select { min-width: 0; max-width: 240px; }
.gr-como select { border: 1px solid var(--cv-borde, #E2E8F0); border-radius: 8px; padding: 3px 8px; font: inherit; font-size: 12px; background: var(--cv-fondo, #fff); color: var(--cv-texto, #1E293B); }
.gr-como .ld-boton { min-height: 28px; padding: 3px 8px 3px 10px; font-size: 12px; }
.gr-como-linea { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; color: var(--cv-texto, #1E293B); }
.gr-punto { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Lista para mencionar con @ (aparece arriba de la caja para escribir) */
.gr-arrobas {
  display: none; max-height: 220px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--cv-fondo, #fff); border-top: 1px solid var(--cv-borde, #E2E8F0); padding: 4px 6px;
  box-shadow: 0 -6px 16px rgba(15,23,42,.06);
}
.gr-arrobas.visible { display: block; }
.gr-arroba-op {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: none; background: none;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; color: var(--cv-texto, #1E293B); font-size: 13px;
}
.gr-arroba-op:hover, .gr-arroba-op.sel { background: var(--primario-suave, #EEF4FF); }
.gr-arroba-ini {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.gr-arroba-nombre { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-arroba-tel { font-size: 11.5px; color: var(--cv-tenue, #64748B); flex-shrink: 0; }
.gr-arroba-vacio { padding: 10px; font-size: 12.5px; color: var(--cv-tenue, #64748B); }
.gr .gr-btn-arroba { font-size: 19px; margin-left: -6px; }

/* ── Contenedor angosto: una cosa a la vez ── */
@container gr (max-width: 759px) {
  .gr-lista { flex: 1 1 auto; width: 100%; border-right: none; }
  .gr-chat { display: none; }
  .gr.chat-abierto .gr-lista { display: none; }
  .gr.chat-abierto .gr-chat { display: flex; }
  .gr .gr-volver { display: inline-flex; }
}
@container gr (min-width: 760px) and (max-width: 1000px) {
  .gr-lista { flex-basis: 290px; width: 290px; }
}
