/* ================================================================
   Todalapc ChatBot — Estilos
   Autor: Alberto / Todalapc.com
   ================================================================ */

:root {
  --tlpc-primary:     #0057b8;
  --tlpc-primary-dark:#003d8a;
  --tlpc-accent:      #00b4d8;
  --tlpc-bg:          #ffffff;
  --tlpc-surface:     #f4f7fb;
  --tlpc-border:      #e1e8f0;
  --tlpc-text:        #1a2332;
  --tlpc-muted:       #6b7c93;
  --tlpc-bot-bubble:  #f0f5ff;
  --tlpc-user-bubble: #0057b8;
  --tlpc-shadow:      0 8px 40px rgba(0,87,184,0.18), 0 2px 8px rgba(0,0,0,0.08);
  --tlpc-radius:      16px;
  --tlpc-font:        'Segoe UI', system-ui, -apple-system, sans-serif;
  --tlpc-z:           99999;
  --tlpc-width:       370px;
  --tlpc-height:      520px;
}

/* ── Wrapper ─────────────────────────────────────────────── */
#tlpc-bot-wrapper {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: var(--tlpc-z);
  font-family: var(--tlpc-font);
}

/* ── Botón flotante ──────────────────────────────────────── */
#tlpc-bot-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--tlpc-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,87,184,0.4);
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1),
              box-shadow 0.2s ease,
              background 0.2s ease;
  position: relative;
  outline: none;
}

#tlpc-bot-toggle:hover {
  transform: scale(1.1);
  background: var(--tlpc-primary-dark);
  box-shadow: 0 6px 28px rgba(0,87,184,0.5);
}

#tlpc-bot-toggle:focus-visible {
  outline: 3px solid var(--tlpc-accent);
  outline-offset: 3px;
}

#tlpc-bot-toggle .tlpc-icon-chat,
#tlpc-bot-toggle .tlpc-icon-close {
  font-size: 26px;
  line-height: 1;
  transition: opacity 0.2s, transform 0.3s;
  position: absolute;
}

#tlpc-bot-toggle .tlpc-icon-close {
  opacity: 0;
  transform: rotate(-90deg);
  color: #fff;
  font-style: normal;
  font-size: 20px;
  font-weight: 700;
}

#tlpc-bot-wrapper.tlpc-open #tlpc-bot-toggle .tlpc-icon-chat {
  opacity: 0;
  transform: rotate(90deg);
}

#tlpc-bot-wrapper.tlpc-open #tlpc-bot-toggle .tlpc-icon-close {
  opacity: 1;
  transform: rotate(0);
}

/* Badge de notificación */
.tlpc-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 14px;
  height: 14px;
  background: #ff3b30;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
  animation: tlpc-pulse 1.8s infinite;
}

.tlpc-badge.tlpc-visible { display: block; }

@keyframes tlpc-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.25); }
}

/* ── Ventana del chat ────────────────────────────────────── */
#tlpc-bot-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: var(--tlpc-width);
  height: var(--tlpc-height);
  background: var(--tlpc-bg);
  border-radius: var(--tlpc-radius);
  box-shadow: var(--tlpc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(.34,1.3,.64,1);
  border: 1px solid var(--tlpc-border);
}

#tlpc-bot-window[hidden] {
  display: flex !important; /* override hidden para animar */
  opacity: 0;
  transform: scale(0.85) translateY(20px);
  pointer-events: none;
  visibility: hidden;
}

#tlpc-bot-wrapper.tlpc-open #tlpc-bot-window {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
  visibility: visible;
}

/* ── Header ─────────────────────────────────────────────── */
.tlpc-header {
  background: var(--tlpc-primary);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.tlpc-header-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.tlpc-status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background: #34c759;
  border-radius: 50%;
  border: 2px solid var(--tlpc-primary);
}

.tlpc-header-info {
  flex: 1;
  min-width: 0;
}

.tlpc-header-info strong {
  display: block;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.tlpc-header-info small {
  color: rgba(255,255,255,0.75);
  font-size: 11.5px;
}

.tlpc-btn-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.tlpc-btn-close:hover { background: rgba(255,255,255,0.3); }

/* ── Área de mensajes ─────────────────────────────────────── */
.tlpc-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--tlpc-surface);
}

.tlpc-messages::-webkit-scrollbar { width: 4px; }
.tlpc-messages::-webkit-scrollbar-track { background: transparent; }
.tlpc-messages::-webkit-scrollbar-thumb { background: var(--tlpc-border); border-radius: 2px; }

/* Burbujas */
.tlpc-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: tlpc-msg-in 0.3s cubic-bezier(.34,1.4,.64,1) both;
  max-width: 88%;
}

@keyframes tlpc-msg-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.tlpc-msg.tlpc-bot { align-self: flex-start; }
.tlpc-msg.tlpc-user { align-self: flex-end; flex-direction: row-reverse; }

.tlpc-msg-avatar {
  width: 30px;
  height: 30px;
  background: var(--tlpc-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.tlpc-msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  max-width: 100%;
}

.tlpc-msg.tlpc-bot .tlpc-msg-bubble {
  background: var(--tlpc-bot-bubble);
  color: var(--tlpc-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.tlpc-msg.tlpc-user .tlpc-msg-bubble {
  background: var(--tlpc-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.tlpc-typing .tlpc-msg-bubble {
  padding: 12px 16px;
}

.tlpc-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.tlpc-typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--tlpc-muted);
  border-radius: 50%;
  animation: tlpc-dot 1.2s infinite ease-in-out;
}

.tlpc-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.tlpc-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes tlpc-dot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%            { transform: scale(1);   opacity: 1;   }
}

/* Mensaje de fallback (WhatsApp) */
.tlpc-fallback-card {
  background: #fff;
  border: 1.5px solid var(--tlpc-border);
  border-radius: 14px;
  padding: 14px;
  margin-top: 4px;
}

.tlpc-fallback-card p {
  margin: 0 0 10px;
  font-size: 13.5px;
  color: var(--tlpc-text);
  line-height: 1.5;
}

.tlpc-btn-whatsapp {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #25d366;
  color: #fff !important;
  text-decoration: none !important;
  padding: 9px 18px;
  border-radius: 25px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s, transform 0.15s;
}

.tlpc-btn-whatsapp:hover {
  background: #1ebe5d;
  transform: translateY(-1px);
}

.tlpc-btn-whatsapp svg { flex-shrink: 0; }

/* Quick replies dentro de mensajes */
.tlpc-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tlpc-quick-reply-btn {
  background: #fff;
  border: 1.5px solid var(--tlpc-primary);
  color: var(--tlpc-primary);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: var(--tlpc-font);
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}

.tlpc-quick-reply-btn:hover {
  background: var(--tlpc-primary);
  color: #fff;
}

/* ── Sugerencias iniciales ────────────────────────────────── */
.tlpc-suggestions {
  padding: 8px 14px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--tlpc-surface);
  border-top: 1px solid var(--tlpc-border);
  flex-shrink: 0;
}

.tlpc-sug-btn {
  background: #fff;
  border: 1px solid var(--tlpc-border);
  color: var(--tlpc-text);
  padding: 5px 11px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--tlpc-font);
  transition: all 0.15s;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tlpc-sug-btn:hover {
  border-color: var(--tlpc-primary);
  color: var(--tlpc-primary);
  background: #f0f5ff;
}

.tlpc-suggestions:empty { display: none; }

/* ── Input ──────────────────────────────────────────────── */
.tlpc-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--tlpc-border);
  background: var(--tlpc-bg);
  flex-shrink: 0;
}

#tlpc-user-input {
  flex: 1;
  border: 1.5px solid var(--tlpc-border);
  border-radius: 25px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: var(--tlpc-font);
  color: var(--tlpc-text);
  outline: none;
  background: var(--tlpc-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

#tlpc-user-input:focus {
  border-color: var(--tlpc-primary);
  box-shadow: 0 0 0 3px rgba(0,87,184,0.12);
  background: #fff;
}

#tlpc-user-input::placeholder { color: var(--tlpc-muted); }

#tlpc-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tlpc-primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

#tlpc-send-btn:hover {
  background: var(--tlpc-primary-dark);
  transform: scale(1.08);
}

#tlpc-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Footer ──────────────────────────────────────────────── */
.tlpc-footer-note {
  text-align: center;
  padding: 5px 0 7px;
  font-size: 11px;
  color: var(--tlpc-muted);
  background: var(--tlpc-bg);
  flex-shrink: 0;
}

.tlpc-footer-note a {
  color: var(--tlpc-primary);
  text-decoration: none;
  font-weight: 600;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 480px) {
  #tlpc-bot-wrapper {
    bottom: 16px;
    right: 12px;
    left: 12px;
  }

  #tlpc-bot-window {
    width: 100%;
    height: calc(100vh - 110px);
    bottom: 72px;
    right: 0;
    left: 0;
    border-radius: 18px 18px 12px 12px;
  }
}
