/* ===========================================================================
   PANELESA — asistente virtual (chat-widget.js)

   Replaces the old floating WhatsApp bubble in the same corner. WhatsApp is
   still one tap away: it is the "Contactar Asesor" button inside the panel.
   =========================================================================== */

/* ---- launcher ----------------------------------------------------------- */
.pchat-fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px;
  border: 0; padding: 0;
  border-radius: 50%;
  background: var(--color-primary, #0b3d6d);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
  cursor: pointer;
  z-index: 9000;
  transition: transform .2s, box-shadow .2s, opacity .18s;
}
.pchat-fab svg { width: 30px; height: 30px; }
.pchat-fab:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0, 0, 0, .35); }
.pchat-fab:focus-visible { outline: 3px solid #ffd34d; outline-offset: 3px; }
.pchat-fab[hidden] { display: none; }
/* unread/attention dot for the first visit */
.pchat-fab .pchat-dot {
  position: absolute; top: 2px; right: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: #ed1c24; border: 2px solid #fff;
}

/* ---- panel -------------------------------------------------------------- */
.pchat-panel {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 380px;
  max-width: calc(100vw - 28px);
  height: 560px;
  max-height: calc(100vh - 36px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
  display: flex; flex-direction: column;
  overflow: hidden;
  z-index: 9001;
  font-family: 'Open Sans', system-ui, sans-serif;
  transform-origin: bottom right;
  animation: pchat-in .16s ease-out;
}
@keyframes pchat-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }
@media (prefers-reduced-motion: reduce) { .pchat-panel { animation: none; } }
.pchat-panel[hidden] { display: none; }

.pchat-head {
  background: var(--color-primary, #0b3d6d);
  color: #fff;
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  flex: 0 0 auto;
}
.pchat-head-ico {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.pchat-head-ico svg { width: 20px; height: 20px; }
.pchat-title { font-weight: 700; font-size: .95rem; line-height: 1.2; }
/* Igual que .lcd-beta / .cbx-beta / .cont-beta en las herramientas de diseño */
.pchat-beta {
  display: inline-block;
  font-size: .62rem; font-weight: 800; letter-spacing: .08em;
  background: var(--color-accent, #f2ad2e); color: var(--color-primary, #002060);
  padding: 2px 7px; border-radius: 3px;
  vertical-align: middle; margin-left: 8px;
}
.pchat-sub { font-size: .72rem; opacity: .85; }
.pchat-head-actions { margin-left: auto; display: flex; gap: 2px; }
.pchat-x {
  background: transparent; border: 0; color: #fff; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; font-size: 1.1rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.pchat-x:hover { background: rgba(255, 255, 255, .16); }

/* ---- log ---------------------------------------------------------------- */
.pchat-log {
  flex: 1 1 auto; overflow-y: auto;
  padding: 14px; background: #f4f7fa;
  display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
.pchat-msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; font-size: .86rem; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.pchat-bot { align-self: flex-start; background: #fff; color: #26323d; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.pchat-me { align-self: flex-end; background: var(--color-primary, #0b3d6d); color: #fff; border-bottom-right-radius: 4px; }
.pchat-msg a { color: #1f7ae0; font-weight: 600; text-decoration: underline; }
.pchat-me a { color: #cfe4ff; }

/* quick-reply / menu chips */
.pchat-chips { display: flex; flex-wrap: wrap; gap: 6px; align-self: flex-start; max-width: 100%; }
.pchat-chip {
  background: #fff; border: 1px solid #c9d6e2; color: #14507f;
  border-radius: 999px; padding: 7px 12px; font-size: .8rem; font-weight: 600;
  cursor: pointer; text-align: left; font-family: inherit;
}
.pchat-chip:hover { background: #eaf2fb; border-color: #1f7ae0; }
.pchat-chip-link { text-decoration: none; display: inline-block; }

/* advisor (WhatsApp) call to action */
.pchat-wa {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 8px;
  background: #25D366; color: #fff; text-decoration: none;
  border-radius: 999px; padding: 9px 15px; font-size: .84rem; font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .14);
}
.pchat-wa svg { width: 18px; height: 18px; }
.pchat-wa:hover { filter: brightness(1.06); }

/* typing indicator */
.pchat-typing { display: flex; gap: 4px; align-items: center; padding: 11px 14px; }
.pchat-typing span { width: 7px; height: 7px; border-radius: 50%; background: #9fb0c0; animation: pchat-blink 1.1s infinite; }
.pchat-typing span:nth-child(2) { animation-delay: .18s; }
.pchat-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes pchat-blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

/* ---- composer ----------------------------------------------------------- */
.pchat-form { flex: 0 0 auto; display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e3e9ef; background: #fff; align-items: flex-end; }
.pchat-input {
  flex: 1 1 auto; resize: none; border: 1px solid #ccd7e2; border-radius: 12px;
  padding: 9px 11px; font-size: .86rem; font-family: inherit; line-height: 1.4;
  max-height: 90px; min-height: 38px; color: #26323d;
}
.pchat-input:focus { outline: 2px solid #1f7ae0; outline-offset: -1px; border-color: #1f7ae0; }
.pchat-send {
  flex: 0 0 auto; width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: var(--color-primary, #0b3d6d); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.pchat-send svg { width: 18px; height: 18px; }
.pchat-send:disabled { opacity: .45; cursor: default; }
.pchat-legal { font-size: .64rem; color: #8a97a3; text-align: center; padding: 0 10px 8px; background: #fff; }

/* A 320 px "Asistente PANELESA" + BETA no cabe en una línea y el distintivo
   caía debajo del título, estirando la cabecera. Un punto menos de tamaño lo
   devuelve a su sitio; a 390 px ya entraba sin tocar nada. */
@media (max-width: 360px) {
  /* 167 px disponibles frente a 134 (título) + 41 (distintivo) = 175: faltaban
     8 px. Se recorta el relleno y el hueco de la cabecera para ganar sitio, y
     se baja un punto el título. */
  .pchat-head { padding: 12px 10px; gap: 8px; }
  .pchat-title { font-size: .82rem; }
  .pchat-beta { font-size: .56rem; padding: 2px 5px; margin-left: 6px; }
}

/* ---- mobile: full sheet ------------------------------------------------- */
@media (max-width: 600px) {
  .pchat-fab { width: 50px; height: 50px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .pchat-fab svg { width: 26px; height: 26px; }
  .pchat-panel {
    right: 0; left: 0; bottom: 0; top: 0;
    width: 100%; max-width: 100%; height: 100%; max-height: 100%;
    border-radius: 0;
  }
}
