/* Widget de chat — Asistente Virtual Dra. Adriana Cango (portado de index.html) */

/* ── Widget container ─────────────────────────────────────── */
#dra-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Poppins', system-ui, sans-serif;
}

/* ── Toggle button ────────────────────────────────────────── */
#dra-chat-toggle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #2c4890;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(44, 72, 144, 0.45);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: dra-pulse 2.5s infinite;
  margin-left: auto;
}
#dra-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(44, 72, 144, 0.6);
  animation: none;
}
#dra-chat-toggle svg { pointer-events: none; }
#dra-toggle-icon-open  { display: block; }
#dra-toggle-icon-close { display: none; }
#dra-chat-toggle[aria-expanded="true"] #dra-toggle-icon-open  { display: none; }
#dra-chat-toggle[aria-expanded="true"] #dra-toggle-icon-close { display: block; }

@keyframes dra-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(44, 72, 144, 0.55); }
  70%  { box-shadow: 0 0 0 14px rgba(44, 72, 144, 0); }
  100% { box-shadow: 0 0 0 0 rgba(44, 72, 144, 0); }
}

/* ── Preview bubble (auto-show after 4s) ─────────────────── */
#dra-chat-preview {
  display: none;
  opacity: 0;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  margin-bottom: 10px;
  max-width: 240px;
  margin-left: auto;
  transition: opacity 0.35s;
  cursor: pointer;
}
#dra-chat-preview img {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
#dra-preview-text { font-size: 0.8rem; color: #1e293b; line-height: 1.4; flex: 1; }
#dra-preview-close {
  background: none; border: none; cursor: pointer;
  color: #94a3b8; font-size: 1rem; padding: 0; line-height: 1;
}
[data-theme="dark"] #dra-chat-preview {
  background: #1e293b; color: #e2e8f0;
}
[data-theme="dark"] #dra-preview-text { color: #e2e8f0; }

/* ── Chat panel ───────────────────────────────────────────── */
#dra-chat-panel {
  display: none;
  flex-direction: column;
  width: 370px;
  max-width: calc(100vw - 32px);
  max-height: 580px;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  overflow: hidden;
  margin-bottom: 12px;
  transform: translateY(12px);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
#dra-chat-panel.open {
  display: flex;
  transform: translateY(0);
  opacity: 1;
}
[data-theme="dark"] #dra-chat-panel {
  background: rgba(15, 23, 42, 0.97);
}

/* ── Panel header ─────────────────────────────────────────── */
#dra-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: #2c4890;
  flex-shrink: 0;
}
#dra-chat-header img {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.4);
}
#dra-header-info { flex: 1; }
#dra-header-info strong {
  display: block;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}
#dra-header-info span {
  color: rgba(255,255,255,0.75);
  font-size: 0.72rem;
}
#dra-online-dot {
  width: 8px; height: 8px;
  background: #4ade80;
  border-radius: 50%;
  border: 2px solid #2c4890;
  margin-top: -14px;
  margin-left: -14px;
  flex-shrink: 0;
}
#dra-chat-close {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,0.7);
  font-size: 1.3rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
#dra-chat-close:hover { color: #fff; background: rgba(255,255,255,0.15); }

/* ── Scroll body (messages + cal embed) ──────────────────── */
#dra-chat-body {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}
#dra-chat-body::-webkit-scrollbar { width: 4px; }
#dra-chat-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Messages area ────────────────────────────────────────── */
#dra-chat-messages {
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dra-msg {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 0.82rem;
  line-height: 1.5;
  word-break: break-word;
}
.dra-msg-assistant {
  background: #2c4890;
  color: #fff;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.dra-msg-user {
  background: #e2e8f0;
  color: #1e293b;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
[data-theme="dark"] .dra-msg-user {
  background: #334155;
  color: #e2e8f0;
}
.dra-msg-streaming::after {
  content: '▌';
  animation: dra-blink 0.7s infinite;
  margin-left: 2px;
}
@keyframes dra-blink { 50% { opacity: 0; } }

/* ── Cal.com embed zone ───────────────────────────────────── */
#dra-cal-embed {
  display: none;
  min-height: 500px;
  margin: 4px 8px 12px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

/* ── Booking form (name + email) ──────────────────────────── */
#dra-booking-form {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
[data-theme="dark"] #dra-booking-form { border-color: #334155; }
#dra-booking-form input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
  background: #f8fafc;
  color: #1e293b;
}
[data-theme="dark"] #dra-booking-form input {
  background: #1e293b;
  border-color: #475569;
  color: #e2e8f0;
}
#dra-booking-form input:focus { border-color: #2c4890; }
#dra-booking-form input.dra-input-error { border-color: #b01e3e; }
#dra-booking-submit {
  background: #2c4890;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
#dra-booking-submit:hover { background: #1e3270; }

/* ── WhatsApp bar (contextual) ────────────────────────────── */
#dra-whatsapp-bar {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}
[data-theme="dark"] #dra-whatsapp-bar { border-color: #334155; }
#dra-whatsapp-bar a {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #16a34a;
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 20px;
  background: #dcfce7;
  transition: background 0.2s;
}
#dra-whatsapp-bar a:hover { background: #bbf7d0; }

/* ── Input area ───────────────────────────────────────────── */
#dra-chat-footer {
  border-top: 1px solid #e2e8f0;
  padding: 10px 12px 10px;
  flex-shrink: 0;
}
[data-theme="dark"] #dra-chat-footer { border-color: #334155; }

#dra-wa-escape {
  text-align: center;
  margin-bottom: 7px;
}
#dra-wa-escape a {
  font-size: 0.72rem;
  color: #64748b;
  text-decoration: none;
}
#dra-wa-escape a:hover { color: #16a34a; }

#dra-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#dra-chat-input {
  flex: 1;
  resize: none;
  border: 1.5px solid #cbd5e1;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  line-height: 1.4;
  max-height: 90px;
  overflow-y: auto;
  transition: border-color 0.2s;
  background: #f8fafc;
  color: #1e293b;
}
[data-theme="dark"] #dra-chat-input {
  background: #1e293b;
  border-color: #475569;
  color: #e2e8f0;
}
#dra-chat-input:focus { border-color: #2c4890; }
#dra-chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#dra-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #2c4890;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}
#dra-chat-send:hover:not(:disabled) { background: #1e3270; transform: scale(1.08); }
#dra-chat-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

#dra-msg-counter {
  text-align: right;
  font-size: 0.68rem;
  color: #94a3b8;
  margin-top: 5px;
}
#dra-msg-counter.dra-limit { color: #b01e3e; }

/* ── Mobile adjustments ────────────────────────────────────── */
@media (max-width: 420px) {
  #dra-chat-widget { bottom: 16px; right: 16px; }
  #dra-chat-panel { width: calc(100vw - 32px); max-height: 75vh; }
}
