/* ═══════════════════════════════════════════════════════
   Chat Widget — estilos
   Para cambiar colores edita sólo las variables de :root
   ═══════════════════════════════════════════════════════ */

:root {
  --cw-color:        #147D78;
  --cw-color-hover:  #0f5a5a;
  --cw-color-light:  #e8f5e9;
  --cw-user-bubble:  #dcf8c6;
  --cw-bg-messages:  #e5ddd5;
  --cw-online-dot:   #4ade80;
  --cw-check-color:  #53bdeb;
  --cw-danger:       #ef4444;
}

/* ── FAB (botón flotante) ─────────────────────────────── */
#cw-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--cw-color);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
  transition: background .15s, transform .2s;
  padding: 0;
}
#cw-fab:hover  { background: var(--cw-color-hover); transform: scale(1.07); }
#cw-fab:active { transform: scale(.94); }

#cw-fab svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  position: absolute;
  transition: opacity .15s, transform .2s;
}
#cw-fab .cw-ico-chat  { opacity: 1; transform: scale(1) rotate(0deg); }
#cw-fab .cw-ico-close { opacity: 0; transform: scale(.6) rotate(-90deg); }

#cw-fab.cw-open .cw-ico-chat  { opacity: 0; transform: scale(.6) rotate(90deg); }
#cw-fab.cw-open .cw-ico-close { opacity: 1; transform: scale(1) rotate(0deg); }

/* Badge de notificación */
#cw-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--cw-danger);
  border: 2px solid #fff;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
#cw-badge.show { display: flex; }

/* ── Ventana del chat ─────────────────────────────────── */
#cw-win {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9998;
  width: 370px;
  height: 590px;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  transform: translateY(18px) scale(.97);
  opacity: 0;
  pointer-events: none;
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), opacity .2s;
  transform-origin: bottom right;
}
#cw-win.cw-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* ── Handle de redimensión ───────────────────────────── */
#cw-resize {
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 10;
  border-radius: 16px 0 0 0;
}

/* ── Header ──────────────────────────────────────────── */
#cw-header {
  background: var(--cw-color);
  color: #fff;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#cw-av {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  overflow: hidden;
}
#cw-av img { width: 100%; height: 100%; object-fit: cover; }
#cw-hinfo  { flex: 1; line-height: 1.3; }
#cw-hname  { font-size: 15px; font-weight: 600; }
#cw-hstatus {
  font-size: 11.5px;
  opacity: .8;
  display: flex;
  align-items: center;
  gap: 5px;
}
#cw-hstatus::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cw-online-dot);
  display: inline-block;
}
#cw-hclose {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  opacity: .75;
  line-height: 1;
  padding: 0 2px;
}
#cw-hclose:hover { opacity: 1; }

/* ── Gate Turnstile ──────────────────────────────────── */
#cw-gate {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 22px;
  text-align: center;
  transition: opacity .22s;
}
#cw-gate-emoji  { font-size: 48px; margin-bottom: 14px; line-height: 1; }
#cw-gate-emoji img { display: block; background: #fff; border-radius: 50%; padding: 6px; }
#cw-gate h3     { font-size: 15px; font-weight: 700; color: #111827; margin: 0 0 6px; font-family: inherit; }
#cw-gate p      { font-size: 12.5px; color: #6b7280; line-height: 1.6; margin: 0 0 18px; font-family: inherit; }
#cw-gate-ts     { min-height: 65px; display: flex; align-items: center; justify-content: center; }
#cw-gate-btn {
  margin-top: 12px;
  width: 100%;
  max-width: 220px;
  padding: 11px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  background: #d1d5db;
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: not-allowed;
  transition: background .2s;
}
#cw-gate-btn.cw-ready            { background: var(--cw-color); cursor: pointer; }
#cw-gate-btn.cw-ready:hover      { background: var(--cw-color-hover); }
#cw-gate-note { font-size: 10.5px; color: #9ca3af; margin-top: 12px; font-family: inherit; }

/* ── Área de mensajes ────────────────────────────────── */
#cw-msgs {
  flex: 1;
  overflow-y: auto;
  background: var(--cw-bg-messages);
  padding: 10px 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#cw-msgs::-webkit-scrollbar       { width: 4px; }
#cw-msgs::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, .18); border-radius: 2px; }

.cw-date         { text-align: center; margin: 6px 0 10px; }
.cw-date span    { background: rgba(255, 255, 255, .75); color: #555; font-size: 11px; padding: 3px 10px; border-radius: 8px; }

/* ── Burbujas ────────────────────────────────────────── */
.cw-row           { display: flex; margin-bottom: 3px; }
.cw-row.cw-user   { justify-content: flex-end; }
.cw-row.cw-bot    { justify-content: flex-start; }

.cw-bub {
  max-width: 74%;
  padding: 7px 10px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.45;
  position: relative;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
}
.cw-bub::before { content: ''; position: absolute; top: 0; width: 0; height: 0; border-style: solid; }

.cw-row.cw-user .cw-bub {
  background: var(--cw-user-bubble);
  color: #111;
  border-top-right-radius: 2px;
  margin-right: 6px;
}
.cw-row.cw-user .cw-bub::before {
  right: -8px;
  border-width: 8px 0 0 8px;
  border-color: transparent transparent transparent var(--cw-user-bubble);
}
.cw-row.cw-bot .cw-bub {
  background: #fff;
  color: #111;
  border-top-left-radius: 2px;
  margin-left: 6px;
}
.cw-row.cw-bot .cw-bub::before {
  left: -8px;
  border-width: 8px 8px 0 0;
  border-color: transparent #fff transparent transparent;
}

.cw-meta {
  position: absolute;
  bottom: 4px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: #8a8a8a;
  white-space: nowrap;
}
.cw-check  { color: var(--cw-check-color); font-size: 11px; }
.cw-bullet { color: var(--cw-color); font-size: 13px; }
.cw-bub strong { font-weight: 600; }
.cw-bub br { display: block; content: ''; margin-top: 4px; }

/* ── Typing indicator ────────────────────────────────── */
#cw-typing { display: none; justify-content: flex-start; margin-bottom: 3px; }
#cw-typing .cw-bub {
  background: #fff;
  border-top-left-radius: 2px;
  padding: 12px 14px;
  min-width: 52px;
}
#cw-typing .cw-bub::before {
  left: -8px;
  border-width: 8px 8px 0 0;
  border-color: transparent #fff transparent transparent;
}
.cw-dots                    { display: flex; gap: 4px; align-items: center; height: 15px; }
.cw-dots span               { width: 7px; height: 7px; border-radius: 50%; background: #aaa; animation: cwBounce 1.2s infinite ease-in-out; }
.cw-dots span:nth-child(2)  { animation-delay: .2s; }
.cw-dots span:nth-child(3)  { animation-delay: .4s; }
@keyframes cwBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

/* ── Quick replies ───────────────────────────────────── */
#cw-qr    { background: #f0f0f0; border-top: 1px solid #ddd; padding: 7px 10px; flex-shrink: 0; }
#cw-ql    { font-size: 10.5px; color: #888; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; margin-bottom: 6px; }
#cw-qbtns { display: flex; flex-wrap: wrap; gap: 5px; }
.cw-qbtn {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 20px;
  padding: 4px 11px;
  font-size: 12px;
  color: var(--cw-color);
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  transition: background .15s, border-color .15s;
}
.cw-qbtn:hover { background: var(--cw-color-light); border-color: var(--cw-color); }

/* ── Barra de input ──────────────────────────────────── */
#cw-bar {
  background: #f0f0f0;
  border-top: 1px solid #ddd;
  padding: 8px 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
#cw-ta {
  flex: 1;
  border: none;
  border-radius: 22px;
  background: #fff;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 80px;
  overflow-y: auto;
  color: #111;
}
#cw-ta::placeholder { color: #aaa; }

#cw-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--cw-color);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#cw-send:hover   { background: var(--cw-color-hover); }
#cw-send:active  { transform: scale(.93); }
#cw-send:disabled { background: #a5c9ae; cursor: not-allowed; transform: none; }
#cw-send svg { width: 20px; height: 20px; fill: #fff; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 420px) {
  #cw-win  { width: calc(100vw - 16px); right: 8px; bottom: 80px; height: 70vh; }
  #cw-fab  { bottom: 16px; right: 16px; }
}
