/* ═══════════════════════════════════════════════════════════════
   TopSEO · Panel WhatsApp (Etapa 2 Hub WhatsApp)
   Bandeja nativa del agente, embebida en "Mi negocio". Tema OLED
   (usa los tokens de css/variables.css). Debe verse parte del admin,
   no un iframe pegado.
═══════════════════════════════════════════════════════════════ */

#whatsapp-page {
  --wa-in: rgba(255, 255, 255, 0.05);          /* burbuja cliente (izq) */
  --wa-ia: rgba(56, 161, 219, 0.14);           /* burbuja IA (der, azul marca) */
  --wa-ia-bd: rgba(56, 161, 219, 0.28);
  --wa-human: rgba(16, 185, 129, 0.16);        /* burbuja humano (der, verde) */
  --wa-human-bd: rgba(16, 185, 129, 0.30);
  --wa-radius: 14px;
}

/* [hidden] debe GANAR siempre. Varias reglas de abajo ponen display:flex/inline-flex,
   que sin esto anulan el atributo `hidden` y dejan visibles banners, el aviso vacío,
   el hilo sin abrir y el badge del nav a cero (bug clásico [hidden] vs clase de
   display). Scope: el panel + el badge del nav (que vive en el sidebar). */
#whatsapp-page [hidden],
#wa-nav-badge[hidden] { display: none !important; }

/* ── Barra superior del panel ── */
.wa-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.9rem; flex-wrap: wrap;
}
.wa-bar__title { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.wa-bar__title h2 {
  font-size: 1.05rem; font-weight: 600; color: var(--text-primary); margin: 0;
  letter-spacing: -0.01em;
}
.wa-bar__title i { color: #25D366; }
.wa-bar__actions { display: flex; align-items: center; gap: 0.6rem; }

/* Pill de conexión */
.wa-conn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.72rem; color: var(--text-secondary);
  padding: 0.28rem 0.6rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg-card);
}
.wa-conn::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted); transition: background 0.25s;
}
.wa-conn[data-state="on"]::before { background: var(--success); box-shadow: 0 0 8px rgba(16, 185, 129, 0.6); }
.wa-conn[data-state="off"]::before { background: var(--warning); }

/* Botón pausa global */
.wa-pause {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: 0.8rem; font-weight: 500; color: var(--text-primary);
  padding: 0.42rem 0.85rem; border-radius: 10px; cursor: pointer;
  background: var(--bg-elevated); border: 1px solid var(--border);
  transition: all 0.2s var(--ease-antigravity);
}
.wa-pause:hover { border-color: var(--border-hover); }
.wa-pause.is-paused {
  background: var(--danger-bg); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5;
}
.wa-pause i { width: 15px; height: 15px; }

/* Banner de pausa activa */
.wa-pausebar {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.6rem 0.9rem; margin-bottom: 0.8rem; border-radius: 10px;
  background: var(--danger-bg); border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5; font-size: 0.82rem;
}
.wa-pausebar i { width: 16px; height: 16px; flex: 0 0 auto; }

/* Aviso sin-config */
.wa-notice { display: flex; align-items: center; justify-content: center; padding: 3rem 1rem; }
.wa-notice__card {
  max-width: 460px; text-align: center; padding: 2rem;
  background: var(--bg-card); border: 1px dashed var(--border); border-radius: var(--wa-radius);
}
.wa-notice__card strong { display: block; color: var(--text-primary); font-size: 1rem; margin-bottom: 0.5rem; }
.wa-notice__card p { color: var(--text-secondary); font-size: 0.85rem; line-height: 1.55; margin: 0; }

/* ── Layout de dos columnas ── */
.wa-inbox {
  display: grid; grid-template-columns: 340px 1fr;
  /* La cabecera del admin ocupa ~184px + la barra del panel; dejamos margen para
     que la bandeja no se salga del viewport (con o sin banner de pausa). */
  height: calc(100vh - 250px); min-height: 440px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--wa-radius); overflow: hidden;
}

/* ── Columna izquierda: lista ── */
.wa-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.wa-list__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.wa-list__head h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-secondary); margin: 0; }
.wa-iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--text-secondary);
  transition: all 0.18s;
}
.wa-iconbtn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.wa-iconbtn i { width: 16px; height: 16px; }
.wa-list__scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; }

.wa-item {
  display: flex; align-items: center; gap: 0.7rem; width: 100%;
  padding: 0.7rem 1rem; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; cursor: pointer; text-align: left;
  transition: background 0.15s;
}
.wa-item:hover { background: var(--bg-elevated); }
.wa-item.is-active { background: var(--accent-muted); box-shadow: inset 2px 0 0 var(--accent); }
.wa-item.is-new { animation: waFlash 1.1s var(--ease-antigravity); }
@keyframes waFlash { 0% { background: rgba(56, 161, 219, 0.18); } 100% { background: transparent; } }

.wa-avatar {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, rgba(56, 161, 219, 0.35), rgba(236, 116, 252, 0.28));
  color: #fff; font-weight: 600; font-size: 0.85rem;
}
.wa-item__mid { flex: 1 1 auto; min-width: 0; }
.wa-item__name {
  display: flex; align-items: center; gap: 0.4rem;
  color: var(--text-primary); font-weight: 500; font-size: 0.9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wa-tag-human {
  font-size: 0.62rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.08rem 0.4rem; border-radius: 5px; flex: 0 0 auto;
  background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.3);
}
.wa-item__preview {
  color: var(--text-secondary); font-size: 0.78rem; margin-top: 0.12rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wa-item__right { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; }
.wa-item__time { font-size: 0.68rem; color: var(--text-muted); }
.wa-badge {
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #25D366; color: #04210f; font-size: 0.68rem; font-weight: 700;
}
.wa-dot-off { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }

.wa-empty { padding: 2rem 1.2rem; text-align: center; color: var(--text-secondary); font-size: 0.85rem; line-height: 1.5; }

/* ── Columna derecha: hilo ── */
.wa-thread { display: flex; flex-direction: column; min-height: 0; }
.wa-thread__empty {
  flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.8rem; color: var(--text-muted); text-align: center; padding: 2rem;
}
.wa-thread__empty i { width: 42px; height: 42px; opacity: 0.5; }
.wa-thread__empty p { font-size: 0.9rem; margin: 0; }

.wa-thread__wrap { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.wa-thread__head {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.wa-back { display: none; }
.wa-thread__who { display: flex; align-items: center; gap: 0.6rem; flex: 1 1 auto; min-width: 0; }
.wa-thread__who .wa-avatar { width: 34px; height: 34px; font-size: 0.75rem; }
.wa-th-names { min-width: 0; }
.wa-th-names strong { display: block; color: var(--text-primary); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-th-names span { color: var(--text-secondary); font-size: 0.75rem; }
.wa-thread__ctrls { display: flex; align-items: center; gap: 0.7rem; flex: 0 0 auto; }

.wa-win { font-size: 0.66rem; padding: 0.2rem 0.5rem; border-radius: 6px; white-space: nowrap; }
.wa-win.is-open { background: var(--success-bg); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.3); }
.wa-win.is-closed { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.3); }

/* Switch IA (takeover) */
.wa-switch { display: inline-flex; align-items: center; gap: 0.45rem; cursor: pointer; user-select: none; }
.wa-switch__text { font-size: 0.72rem; color: var(--text-secondary); white-space: nowrap; }
.wa-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.wa-switch__track {
  position: relative; width: 38px; height: 21px; border-radius: 999px;
  background: var(--bg-surface); border: 1px solid var(--border); transition: background 0.2s, border-color 0.2s;
}
.wa-switch__thumb {
  position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%;
  background: var(--text-secondary); transition: transform 0.2s var(--ease-antigravity), background 0.2s;
}
.wa-switch input:checked + .wa-switch__track { background: rgba(16, 185, 129, 0.25); border-color: rgba(16, 185, 129, 0.5); }
.wa-switch input:checked + .wa-switch__track .wa-switch__thumb { transform: translateX(17px); background: var(--success); }
.wa-switch input:focus-visible + .wa-switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Mensajes */
.wa-thread__msgs {
  flex: 1 1 auto; overflow-y: auto; min-height: 0;
  padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.4rem;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(56, 161, 219, 0.04), transparent 60%),
    var(--bg-primary);
}
.wa-daysep { align-self: center; font-size: 0.68rem; color: var(--text-muted); margin: 0.5rem 0; padding: 0.15rem 0.6rem; background: var(--bg-card); border-radius: 999px; }
.wa-msg { max-width: 76%; padding: 0.55rem 0.75rem; border-radius: var(--wa-radius); border: 1px solid var(--border); }
.wa-msg__body { color: var(--text-primary); font-size: 0.88rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.wa-msg__meta { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.25rem; font-size: 0.64rem; color: var(--text-muted); }
.wa-msg__author { font-weight: 600; }

.wa-msg--in { align-self: flex-start; background: var(--wa-in); border-top-left-radius: 4px; }
.wa-msg--ia { align-self: flex-end; background: var(--wa-ia); border-color: var(--wa-ia-bd); border-bottom-right-radius: 4px; }
.wa-msg--humano { align-self: flex-end; background: var(--wa-human); border-color: var(--wa-human-bd); border-bottom-right-radius: 4px; }
.wa-msg--sistema { align-self: center; background: var(--bg-card); font-size: 0.78rem; opacity: 0.85; }

/* Composer */
.wa-composer { flex: 0 0 auto; border-top: 1px solid var(--border); padding: 0.7rem 0.9rem; }
.wa-composer__oow {
  display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.55rem;
  font-size: 0.76rem; color: var(--warning);
  background: var(--warning-bg); border: 1px solid rgba(245, 158, 11, 0.3); border-radius: 8px; padding: 0.5rem 0.7rem;
}
.wa-composer__oow i { width: 15px; height: 15px; flex: 0 0 auto; }
.wa-composer__row { display: flex; align-items: flex-end; gap: 0.55rem; }
.wa-composer__row textarea {
  flex: 1 1 auto; resize: none; min-height: 40px; max-height: 140px;
  padding: 0.6rem 0.8rem; border-radius: 10px; font: inherit; font-size: 0.88rem;
  background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-primary);
  outline: none; transition: border-color 0.18s;
}
.wa-composer__row textarea:focus { border-color: rgba(56, 161, 219, 0.5); }
.wa-composer__row textarea:disabled { opacity: 0.5; cursor: not-allowed; }
.wa-send {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: #25D366; border: 0; color: #04210f; transition: filter 0.18s, transform 0.1s;
}
.wa-send:hover { filter: brightness(1.08); }
.wa-send:active { transform: scale(0.95); }
.wa-send:disabled { opacity: 0.45; cursor: not-allowed; }
.wa-send i { width: 19px; height: 19px; }
.wa-composer__err { margin: 0.5rem 0 0; font-size: 0.76rem; color: #fca5a5; }

/* Skeleton */
.wa-skeleton { display: flex; flex-direction: column; gap: 0.6rem; padding: 1rem; }
.wa-skeleton span { height: 34px; border-radius: 10px; background: linear-gradient(90deg, var(--bg-elevated), var(--bg-card), var(--bg-elevated)); background-size: 200% 100%; animation: waSkel 1.4s ease infinite; }
@keyframes waSkel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Badge de no-leídos en el nav-item "WhatsApp" */
.wa-nav-badge {
  margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #25D366; color: #04210f; font-size: 0.66rem; font-weight: 700;
}

/* ── Responsive (móvil): una columna, alterna lista/hilo ── */
@media (max-width: 820px) {
  .wa-inbox { grid-template-columns: 1fr; height: calc(100vh - 200px); }
  .wa-thread { display: none; }
  .wa-inbox[data-view="thread"] .wa-list { display: none; }
  .wa-inbox[data-view="thread"] .wa-thread { display: flex; }
  .wa-back { display: inline-flex; }
  .wa-msg { max-width: 86%; }
}

@media (prefers-reduced-motion: reduce) {
  .wa-item.is-new, .wa-skeleton span { animation: none; }
  .wa-switch__thumb { transition: none; }
}
