/* ============================================================
   conversaciones.css — Responsive completo
   Paleta WhatsApp clara/oscura. Sin espacio desperdiciado.
   ============================================================ */

/* ---------------------------------------------------------------------------
   Variables
   --------------------------------------------------------------------------- */
:root {
  --wa-accent: var(--button-bg, var(--institutional-accent, #0f4c81));
  --wa-accent-text: var(--button-text, #ffffff);
  /* Personalización controla el acento; las superficies de lectura quedan
     neutras para mantener contraste con cualquier paleta institucional. */
  --wa-surface: #ffffff;
  --wa-soft: color-mix(in srgb, var(--wa-accent) 6%, #ffffff);
  --wa-radius-panel:  18px;
  --wa-radius-item:   14px;
  --wa-radius-msg:    16px;
  --wa-radius-avatar: 10px;
  --wa-sidebar-w:     300px;
  --wa-gap:           12px;
  --wa-avatar-size:   40px;
  --wa-shadow-panel:  0 2px 16px rgba(17,27,33,0.09);
  --wa-shadow-btn:    0 1px 6px rgba(17,27,33,0.08);
  --wa-transition:    background 0.15s ease, border-color 0.15s ease,
                      color 0.15s ease, transform 0.15s ease;

  /* Sidebar */
  --wa-sb-bg:              #f0f2f5;
  --wa-sb-border:          #d1d5db;

  /* Items */
  --wa-item-bg:            #ffffff;
  --wa-item-bg-hover:      #f5f6f6;
  --wa-item-bg-active:     color-mix(in srgb, var(--wa-accent) 13%, #ffffff);
  --wa-item-border:        #e9edef;

  /* Chat panel */
  --wa-chat-bg:            #dfe7dc;
  --wa-chat-head-bg:       #f0f2f5;
  --wa-chat-input-bg:      #f0f2f5;

  /* Bubbles */
  --wa-bubble-in-bg:       #ffffff;
  --wa-bubble-in-border:   #e2e8f0;
  --wa-bubble-in-text:     #111b21;
  --wa-bubble-out-bg:      color-mix(in srgb, var(--wa-accent) 13%, #ffffff);
  --wa-bubble-out-border:  color-mix(in srgb, var(--wa-accent) 28%, #ffffff);
  --wa-bubble-out-text:    #111b21;

  /* Buttons */
  --wa-btn-bg:             #ffffff;
  --wa-btn-border:         #d1d5db;
  --wa-btn-text:           #374151;
  --wa-btn-active-bg:      #111b21;
  --wa-btn-active-text:    #ffffff;

  /* Send */
  --wa-send-bg:            var(--wa-accent);
  --wa-send-text:          var(--wa-accent-text);
  --wa-send-hover:         var(--institutional-button-hover, var(--wa-accent));

  /* Text */
  --wa-text-primary:       #111b21;
  --wa-text-muted:         #667781;
}

/* ---------------------------------------------------------------------------
   Reset básico del módulo
   --------------------------------------------------------------------------- */
.wa-page *,
.wa-page *::before,
.wa-page *::after {
  box-sizing: border-box;
}

/* ---------------------------------------------------------------------------
   SHELL — ocupa todo el espacio disponible sin márgenes extra del sistema
   --------------------------------------------------------------------------- */
.wa-page {
  /* Elimina el padding/margin que el contenedor padre normalmente agrega */
  margin: 0;
  padding: 0;
  width: 100%;
  min-width: 0;
  color: var(--wa-text-primary);
}

/* Cabecera editorial: la fotografía aporta contexto y la marca conserva el
   control cromático mediante las variables globales de Personalización. */
.wa-hero {
  align-items: center;
  background-image:
    linear-gradient(90deg, var(--wa-surface) 0%, color-mix(in srgb, var(--wa-surface) 96%, transparent) 38%, transparent 72%),
    linear-gradient(180deg, transparent 62%, var(--wa-surface) 100%),
    url("/notificaciones/assets/conversaciones-hero-v1.png?v=1");
  background-position: center, center, center right;
  background-repeat: no-repeat;
  background-size: cover;
  border: 1px solid color-mix(in srgb, var(--wa-accent) 16%, #dbe5f0);
  border-radius: 24px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  display: flex;
  min-height: 174px;
  margin-bottom: 14px;
  overflow: hidden;
  padding: 26px 45% 26px 28px;
  position: relative;
}

.wa-hero::after {
  background: linear-gradient(90deg, var(--wa-accent), transparent);
  bottom: 0;
  content: "";
  height: 4px;
  left: 0;
  position: absolute;
  width: 46%;
}

.wa-hero-copy {
  align-items: center;
  display: flex;
  gap: 18px;
  position: relative;
  z-index: 1;
}

.wa-hero-icon {
  align-items: center;
  background: color-mix(in srgb, var(--wa-accent) 11%, var(--wa-surface));
  border: 1px solid color-mix(in srgb, var(--wa-accent) 20%, transparent);
  border-radius: 20px;
  color: var(--wa-accent);
  display: inline-flex;
  flex: 0 0 66px;
  font-size: 1.75rem;
  height: 66px;
  justify-content: center;
}

.wa-hero-kicker {
  color: var(--wa-accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  margin: 0 0 4px;
}

.wa-hero h1 {
  color: var(--wa-text-primary);
  font-size: clamp(1.75rem, 3vw, 2.55rem);
  line-height: 1.05;
  margin: 0;
}

.wa-hero-copy > div > p:last-child {
  color: var(--wa-text-muted);
  font-size: 0.96rem;
  line-height: 1.45;
  margin: 8px 0 0;
  max-width: 510px;
}

/* Anula el header del sistema (content-section-head) en móvil —
   ya no existe en el HTML nuevo, pero por seguridad: */
.wa-page .content-section-head { display: none; }

.wa-shell {
  display: grid;
  grid-template-columns: var(--wa-sidebar-w) minmax(0, 1fr);
  gap: var(--wa-gap);
  /* Altura calculada descontando el topbar del sistema (~60px) y
     el header de la sección (~0px, ya lo eliminamos) */
  height: calc(100dvh - 256px);
  min-height: 400px;
  overflow: hidden;
}

.wa-page .content-section-body,
.wa-page .card-body {
  padding: 0;
}

/* ---------------------------------------------------------------------------
   Sidebar
   --------------------------------------------------------------------------- */
.wa-sidebar {
  background: color-mix(in srgb, var(--wa-soft) 68%, var(--wa-surface));
  border: 1px solid var(--wa-sb-border);
  border-radius: var(--wa-radius-panel);
  box-shadow: var(--wa-shadow-panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  min-height: 0;
  overflow: hidden;
}

/* ---------------------------------------------------------------------------
   Chat panel
   --------------------------------------------------------------------------- */
.wa-chat {
  background: var(--wa-chat-bg);
  border: 1px solid var(--wa-sb-border);
  border-radius: var(--wa-radius-panel);
  box-shadow: var(--wa-shadow-panel);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 860px) {
  .wa-hero { display: none; }
}

/* ---------------------------------------------------------------------------
   Cabecera sidebar — una sola fila, sin overflow
   --------------------------------------------------------------------------- */
.wa-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.wa-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 0;
}

.wa-profile-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.wa-profile-text strong,
.wa-profile-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wa-profile-text strong {
  font-size: 0.9rem;
  color: var(--wa-text-primary);
}

.wa-profile-text small {
  font-size: 0.75rem;
  color: var(--wa-text-muted);
}

.wa-profile img {
  width: var(--wa-avatar-size);
  height: var(--wa-avatar-size);
  border-radius: var(--wa-radius-avatar);
  object-fit: cover;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Grupos de acciones
   --------------------------------------------------------------------------- */
.wa-head-actions,
.wa-chat-tools,
.wa-chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Botones icono
   --------------------------------------------------------------------------- */
.wa-icon-btn,
.wa-send-btn {
  border: 1px solid var(--wa-btn-border);
  background: var(--wa-btn-bg);
  color: var(--wa-btn-text);
  border-radius: var(--wa-radius-item);
  cursor: pointer;
  transition: var(--wa-transition);
  touch-action: manipulation;
}

.wa-exit-modules-btn {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--wa-btn-border);
  background: var(--wa-btn-bg);
  color: var(--wa-btn-text);
  border-radius: var(--wa-radius-item);
  box-shadow: var(--wa-shadow-btn);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: var(--wa-transition);
  flex-shrink: 0;
}

.wa-exit-modules-btn:hover {
  background: var(--wa-btn-active-bg);
  color: var(--wa-btn-active-text);
  border-color: var(--wa-btn-active-bg);
  transform: translateY(-1px);
}

.wa-icon-btn {
  width: 38px;
  height: 38px;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--wa-shadow-btn);
  flex-shrink: 0;
}

.wa-btn-label {
  display: none;
}

.wa-icon-btn:hover {
  background: var(--wa-btn-active-bg);
  color: var(--wa-btn-active-text);
  border-color: var(--wa-btn-active-bg);
  transform: translateY(-1px);
}

.wa-icon-btn:active,
.wa-send-btn:active {
  transform: translateY(0);
}

.wa-send-btn {
  padding: 0 16px;
  font-weight: 600;
  white-space: nowrap;
  border-radius: var(--wa-radius-item);
  box-shadow: var(--wa-shadow-btn);
  background: var(--wa-send-bg);
  color: var(--wa-send-text);
  border: none;
  min-height: 40px;
}

.wa-send-btn:hover {
  background: var(--wa-send-hover);
  transform: translateY(-1px);
}

.wa-mobile-back-btn {
  display: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--wa-btn-border);
  background: var(--wa-btn-bg);
  color: var(--wa-btn-text);
  border-radius: var(--wa-radius-item);
  align-items: center;
  justify-content: center;
  box-shadow: var(--wa-shadow-btn);
  flex-shrink: 0;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------------------------------------------------------------------------
   Texto auxiliar
   --------------------------------------------------------------------------- */
.wa-empty,
.wa-item-msg,
.wa-msg-meta,
.wa-modal-info small {
  color: var(--wa-text-muted);
  font-size: 0.8rem;
}

/* ---------------------------------------------------------------------------
   Búsqueda
   --------------------------------------------------------------------------- */
.wa-search-wrap {
  flex-shrink: 0;
}

.wa-search-wrap input,
.wa-input input,
.wa-modal-search-wrap input {
  width: 100%;
  border: 1px solid var(--wa-item-border);
  background: var(--wa-item-bg);
  border-radius: var(--wa-radius-item);
  padding: 9px 12px;
  color: var(--wa-text-primary);
  outline: none;
  transition: border-color 0.15s ease;
  font-size: 0.875rem;
}

.wa-search-wrap input:focus,
.wa-input input:focus,
.wa-modal-search-wrap input:focus {
  border-color: var(--wa-send-bg);
}

/* El shell puede aplicar --field-color globalmente a los campos. Esta regla
   conserva un fondo legible dentro del chat incluso cuando ese color es rojo. */
.wa-page .wa-search-wrap input,
.wa-page .wa-input input,
.wa-page .wa-modal-search-wrap input {
  background-color: #ffffff !important;
  color: #111b21 !important;
  caret-color: var(--wa-accent);
}

.wa-page .wa-search-wrap input::placeholder,
.wa-page .wa-input input::placeholder,
.wa-page .wa-modal-search-wrap input::placeholder {
  color: #667781 !important;
  opacity: 1;
}

/* ---------------------------------------------------------------------------
   Lista de conversaciones
   --------------------------------------------------------------------------- */
.wa-list,
.wa-messages,
.wa-modal-list {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--wa-item-border) transparent;
  -webkit-overflow-scrolling: touch;
}

.wa-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 0;
}

/* ---------------------------------------------------------------------------
   Ítem de conversación
   --------------------------------------------------------------------------- */
.wa-item {
  width: 100%;
  border: 1px solid var(--wa-item-border);
  background: var(--wa-item-bg);
  border-radius: var(--wa-radius-item);
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  text-align: left;
  transition: var(--wa-transition);
  touch-action: manipulation;
}

.wa-item.active {
  border-color: #b8e8b0;
  background: var(--wa-item-bg-active);
}

.wa-item:hover {
  border-color: var(--wa-sb-border);
  background: var(--wa-item-bg-hover);
}

/* ---------------------------------------------------------------------------
   Avatares
   --------------------------------------------------------------------------- */
.wa-item-avatar,
.wa-chat-avatar,
.wa-modal-avatar {
  width: var(--wa-avatar-size);
  height: var(--wa-avatar-size);
  border-radius: var(--wa-radius-avatar);
  background: var(--wa-item-bg-hover);
  color: var(--wa-text-primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: 0 0 var(--wa-avatar-size);
  overflow: hidden;
  font-size: 0.82rem;
}

.wa-item-avatar img,
.wa-chat-avatar img,
.wa-modal-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

/* ---------------------------------------------------------------------------
   Contenido del ítem
   --------------------------------------------------------------------------- */
.wa-item-main,
.wa-modal-info {
  min-width: 0;
  flex: 1;
}

.wa-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 2px;
}

.wa-item-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--wa-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-item-time {
  font-size: 0.72rem;
  white-space: nowrap;
  color: var(--wa-text-muted);
  flex-shrink: 0;
}

.wa-item-msg {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--wa-send-bg);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Cabecera del chat
   --------------------------------------------------------------------------- */
.wa-chat-head,
.wa-modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wa-chat-head {
  background: var(--wa-chat-head-bg);
  border-bottom: 1px solid var(--wa-item-border);
  border-radius: var(--wa-radius-panel) var(--wa-radius-panel) 0 0;
  padding: 10px 14px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.wa-chat-contact {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1 1 0;
}

.wa-chat-contact strong,
.wa-chat-contact small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wa-chat-contact strong { font-size: 0.9rem; color: var(--wa-text-primary); }
.wa-chat-contact small  { font-size: 0.78rem; color: var(--wa-text-muted); }

/* ---------------------------------------------------------------------------
   Mensajes
   --------------------------------------------------------------------------- */
.wa-messages {
  flex: 1 1 0;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%2300a884' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Burbujas */
.wa-msg {
  max-width: min(78%, 600px);
  border-radius: var(--wa-radius-msg);
  padding: 9px 13px;
  border: 1px solid var(--wa-bubble-in-border);
  background: var(--wa-bubble-in-bg);
  color: var(--wa-bubble-in-text);
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(17,27,33,0.1);
  font-size: 0.875rem;
}

/* Fix: forzar color correcto para mensajes entrantes */
.wa-msg.wa-msg--in {
  color: var(--wa-bubble-in-text) !important;
}

.wa-msg--out {
  align-self: flex-end;
  background: var(--wa-bubble-out-bg);
  border-color: var(--wa-bubble-out-border);
  color: var(--wa-bubble-out-text);
}

/* ---------------------------------------------------------------------------
   Área de input
   --------------------------------------------------------------------------- */
.wa-input {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--wa-item-border);
  background: var(--wa-chat-input-bg);
  border-radius: 0 0 var(--wa-radius-panel) var(--wa-radius-panel);
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Modal
   --------------------------------------------------------------------------- */
.wa-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17,27,33,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;  /* Mayor que elementos del sistema */
  overflow-y: auto;
}

.wa-modal-backdrop.open {
  display: flex;
}

/* Bloquear scroll del body cuando el modal está abierto */
body.wa-modal-open {
  overflow: hidden;
}

.wa-modal {
  background: var(--wa-item-bg);
  border: 1px solid var(--wa-item-border);
  border-radius: var(--wa-radius-panel);
  box-shadow: var(--wa-shadow-panel);
  padding: 16px;
  width: min(480px, 100%);
  max-height: min(85dvh, 700px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}

.wa-modal-head {
  justify-content: space-between;
  flex-shrink: 0;
}

.wa-modal-head span {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--wa-text-primary);
}

.wa-modal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 0;
  overflow-y: auto;
}

.wa-modal-user {
  border: 1px solid var(--wa-item-border);
  border-radius: var(--wa-radius-item);
  padding: 9px 11px;
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: var(--wa-transition);
  touch-action: manipulation;
}

.wa-modal-user:hover {
  background: var(--wa-item-bg-hover);
  border-color: var(--wa-sb-border);
}

.wa-modal-user input {
  margin-left: auto;
  accent-color: var(--wa-send-bg);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.wa-modal-search-wrap {
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Estado vacío
   --------------------------------------------------------------------------- */
.wa-empty-state {
  border: 1px dashed var(--wa-item-border);
  border-radius: var(--wa-radius-panel);
  padding: 24px 16px;
  text-align: center;
  color: var(--wa-text-muted);
  font-size: 0.875rem;
}

.wa-empty {
  text-align: center;
  padding: 16px;
  color: var(--wa-text-muted);
  font-size: 0.82rem;
}

/* ---------------------------------------------------------------------------
   Notificaciones flotantes
   --------------------------------------------------------------------------- */
#wa-floating-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.wa-floating-note {
  width: min(320px, calc(100vw - 32px));
  background: var(--wa-text-primary);
  color: #f0f2f5;
  border-radius: var(--wa-radius-panel);
  padding: 11px 14px;
  box-shadow: 0 6px 24px rgba(17,27,33,0.22);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: auto;
  line-height: 1.45;
  font-size: 0.875rem;
}

.wa-floating-note.show {
  opacity: 1;
  transform: translateY(0);
}

.wa-floating-note strong {
  display: block;
  margin-bottom: 2px;
  font-weight: 600;
  font-size: 0.82rem;
  opacity: 0.75;
}

/* ---------------------------------------------------------------------------
   Herramientas chat
   --------------------------------------------------------------------------- */
.wa-chat-tools {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--wa-text-muted);
}

.wa-chat-tools select,
#wa-notify-scope {
  border: 1px solid var(--wa-item-border);
  background: var(--wa-item-bg);
  border-radius: 8px;
  padding: 5px 8px;
  color: var(--wa-text-primary);
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}

/* ============================================================
   RESPONSIVE — Breakpoints
   ============================================================ */

/* ── 1100px — sidebar ligeramente más estrecho ─────────────── */
@media (max-width: 1100px) {
  :root { --wa-sidebar-w: 260px; }
}

/* ── 860px — móvil: una sola columna, sin espacio arriba ────── */
@media (max-width: 860px) {
  .wa-page {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    margin-top: calc(-1 * clamp(12px, 2vw, 24px));
    padding: 0;
  }

  .wa-shell {
    grid-template-columns: 1fr;
    width: 100vw;
    max-width: 100vw;
    height: calc(100dvh - 56px);
    min-height: calc(100dvh - 56px);
    gap: 0;
    border-radius: 0;
  }

  .wa-sidebar {
    width: 100vw;
    min-height: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    border-bottom: none;
    box-shadow: none;
    padding: 8px 10px calc(92px + env(safe-area-inset-bottom));
    gap: 6px;
  }

  .wa-chat {
    display: none;
    width: 100vw;
    min-height: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: none;
  }

  /* Cuando hay chat activo en móvil */
  .wa-shell.wa-mobile-chat-active .wa-sidebar {
    display: none;
  }

  .wa-shell.wa-mobile-chat-active .wa-chat {
    display: flex;
    height: 100%;
  }

  /* Botón volver */
  .wa-mobile-back-btn {
    display: inline-flex;
  }

  /* Cabecera sidebar: todo en una fila sin overflow */
  .wa-sidebar-head {
    gap: 4px;
    padding-bottom: 0;
    align-items: flex-start;
  }

  .wa-head-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    justify-content: space-around;
    gap: 10px;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
    background: var(--wa-sb-bg);
    border-top: 1px solid var(--wa-sb-border);
    box-shadow: 0 -8px 24px rgba(17, 27, 33, 0.12);
    backdrop-filter: blur(14px);
  }

  .wa-head-actions .wa-icon-btn {
    width: auto;
    min-width: 78px;
    height: auto;
    padding: 8px 10px;
    border-radius: 18px;
    flex: 1 1 0;
    flex-direction: column;
    gap: 4px;
    box-shadow: none;
  }

  .wa-head-actions .wa-icon-btn i {
    font-size: 1rem;
  }

  .wa-head-actions .wa-btn-label {
    display: block;
    font-size: 0.69rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.01em;
  }

  /* Iconos un poco más pequeños en móvil */
  .wa-icon-btn {
    width: 34px;
    height: 34px;
    font-size: 0.84rem;
    border-radius: 12px;
  }

  /* Chat head sin flex-wrap para no empujar herramientas abajo */
  .wa-chat-head {
    padding: 8px 10px;
    flex-wrap: nowrap;
    gap: 4px;
  }

  /* Las herramientas del chat se colapsan */
  .wa-chat-tools label {
    display: none; /* oculta la etiqueta "Fuentes" / "Alcance" en móvil */
  }

  .wa-chat-tools select,
  #wa-notify-scope {
    font-size: 0.78rem;
    padding: 4px 6px;
  }

  /* Mensajes */
  .wa-messages {
    padding: 10px 8px;
    gap: 6px;
  }

  .wa-msg {
    max-width: 88%;
    padding: 7px 10px;
    font-size: 0.84rem;
  }

  /* Input de mensaje */
  .wa-input {
    padding: 8px 10px;
    gap: 6px;
    position: sticky;
    bottom: 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .wa-send-btn {
    min-height: 42px;
    padding: 0 14px;
    font-size: 0.875rem;
  }

  /* Lista sin padding extra abajo */
  .wa-list {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  /* Items más compactos */
  .wa-item {
    min-height: 62px;
    padding: 7px 8px;
    gap: 7px;
    border-radius: 12px;
  }

  .wa-item-top {
    margin-bottom: 1px;
  }

  .wa-item-name {
    font-size: 0.83rem;
  }

  .wa-item-msg,
  .wa-item-time {
    font-size: 0.72rem;
  }

  .wa-profile-text strong {
    font-size: 0.84rem;
  }

  .wa-profile-text small {
    font-size: 0.71rem;
  }

  .wa-search-wrap input,
  .wa-input input {
    border-radius: 999px;
    padding: 8px 12px;
  }

  /* Modal — sheet desde abajo en móvil */
  .wa-modal-backdrop {
    padding: 0;
    align-items: flex-end;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .wa-modal {
    width: 100%;
    max-height: min(88dvh, 700px);
    border-radius: 20px 20px 0 0;
    padding: 14px;
  }

  /* Notificaciones flotantes */
  #wa-floating-stack {
    right: 10px;
    left: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .wa-floating-note {
    width: 100%;
  }
}

/* ── 560px — teléfonos pequeños ─────────────────────────────── */
@media (max-width: 560px) {

  .wa-page {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    margin-top: -12px;
  }

  .wa-shell {
    height: calc(100dvh - 52px);
    min-height: calc(100dvh - 52px);
  }

  .wa-sidebar {
    padding: 6px 8px calc(90px + env(safe-area-inset-bottom));
    gap: 6px;
  }

  /* Sidebar head: avatar más pequeño, texto acortado */
  :root { --wa-avatar-size: 36px; }

  .wa-profile-text strong {
    font-size: 0.85rem;
  }

  /* Input en columna (botón bajo el textarea) */
  .wa-input {
    flex-wrap: wrap;
    gap: 5px;
  }

  .wa-input input {
    flex: 1 1 100%;
    font-size: 16px; /* evita zoom en iOS */
  }

  .wa-send-btn {
    flex: 1 1 100%;
    min-height: 42px;
    font-size: 16px;
  }

  /* Buscador con font-size 16px para evitar zoom iOS */
  .wa-search-wrap input,
  .wa-modal-search-wrap input,
  #wa-notify-scope {
    font-size: 16px;
  }

  /* Chat head: avatar + título + volver en compacto */
  .wa-chat-head {
    padding: 7px 8px;
  }

  .wa-chat-contact strong { font-size: 0.85rem; }
  .wa-chat-contact small  { font-size: 0.72rem; }

  .wa-chat-actions .wa-icon-btn {
    width: 32px;
    height: 32px;
  }

  .wa-head-actions {
    padding-left: 8px;
    padding-right: 8px;
  }

  .wa-head-actions .wa-icon-btn {
    min-width: 0;
    padding: 8px 6px;
  }

  .wa-head-actions .wa-btn-label {
    font-size: 0.66rem;
  }
}

/* ── 360px — teléfonos muy pequeños ─────────────────────────── */
@media (max-width: 360px) {
  .wa-shell {
    height: calc(100dvh - 50px);
  }

  .wa-icon-btn {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
  }

  .wa-item-name { font-size: 0.82rem; }
  .wa-msg       { font-size: 0.84rem; }
}

/* ============================================================
   Modo oscuro
   ============================================================ */
[data-theme="dark"] {
  --wa-sb-bg:              #1f2c33;
  --wa-sb-border:          #2a3942;
  --wa-item-bg:            #111b21;
  --wa-item-bg-hover:      #182229;
  --wa-item-bg-active:     #0d2e1e;
  --wa-item-border:        #2a3942;
  --wa-chat-bg:            #0b141a;
  --wa-chat-head-bg:       #202c33;
  --wa-chat-input-bg:      #202c33;
  --wa-bubble-in-bg:       #202c33;
  --wa-bubble-in-border:   #2a3942;
  --wa-bubble-in-text:     #e9edef;
  --wa-bubble-out-bg:      #005c4b;
  --wa-bubble-out-border:  #00443a;
  --wa-bubble-out-text:    #e9edef;
  --wa-btn-bg:             #202c33;
  --wa-btn-border:         #2a3942;
  --wa-btn-text:           #aebac1;
  --wa-btn-active-bg:      #e9edef;
  --wa-btn-active-text:    #111b21;
  --wa-text-primary:       #e9edef;
  --wa-text-muted:         #8696a0;
}
