/* ============================================================
   AGENTE DENTAL - Chat flotante
   Estilos aislados con prefijo .ad- para no chocar con la web
   ============================================================ */

.ad-root {
  --ad-primary: #0A4D68;
  --ad-primary-hover: #088395;
  --ad-accent: #05BFDB;
  --ad-bg: #FFFFFF;
  --ad-bg-soft: #F0F4F8;
  --ad-text: #102A43;
  --ad-text-soft: #334E68;
  --ad-border: #D9E2EC;
  --ad-user-bubble: #0A4D68;
  --ad-user-text: #FFFFFF;
  --ad-bot-bubble: #F0F4F8;
  --ad-bot-text: #102A43;
  --ad-shadow: 0 16px 48px rgba(16, 42, 67, 0.18);

  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ad-text);
  line-height: 1.55;
  box-sizing: border-box;
}

.ad-root *,
.ad-root *::before,
.ad-root *::after {
  box-sizing: border-box;
}

/* ---------- Burbuja flotante (cerrada) ---------- */
.ad-bubble {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--ad-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 10px 30px rgba(10, 77, 104, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483000;
  transition: transform .2s ease, box-shadow .2s ease;
}
.ad-bubble:hover {
  transform: scale(1.06);
  box-shadow: 0 14px 36px rgba(10, 77, 104, 0.55);
}
.ad-bubble svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}
.ad-bubble-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}
.ad-bubble.ad-hidden { display: none; }

.ad-bubble::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--ad-primary);
  opacity: .5;
  animation: ad-pulse 2.2s ease-out infinite;
}
@keyframes ad-pulse {
  0%   { transform: scale(0.9);  opacity: .6; }
  100% { transform: scale(1.5);  opacity: 0;  }
}

/* ---------- Ventana del chat ---------- */
.ad-window {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 40px);
  background: var(--ad-bg);
  border-radius: 18px;
  box-shadow: var(--ad-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483000;
  border: 1px solid var(--ad-border);
  animation: ad-slide-up .25s ease-out;
}
.ad-window.ad-open { display: flex; }

@keyframes ad-slide-up {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Header ---------- */
.ad-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ad-primary);
  color: #fff;
}
.ad-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.ad-header-info { flex: 1; min-width: 0; }
.ad-header-title {
  font-weight: 600;
  font-size: 15px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ad-header-status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.ad-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #27C86B;
}
.ad-status-dot.ad-off { background: #F0A020; }

.ad-header-actions {
  display: flex;
  gap: 4px;
}
.ad-icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.ad-icon-btn:hover { background: rgba(255,255,255,0.18); }
.ad-icon-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ---------- Área de mensajes ---------- */
.ad-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--ad-bg-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.ad-messages::-webkit-scrollbar { width: 6px; }
.ad-messages::-webkit-scrollbar-thumb {
  background: var(--ad-border);
  border-radius: 3px;
}

.ad-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: ad-msg-in .2s ease-out;
  font-size: 14.5px;
}
@keyframes ad-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ad-msg-user {
  align-self: flex-end;
  background: var(--ad-user-bubble);
  color: var(--ad-user-text);
  border-bottom-right-radius: 4px;
}
.ad-msg-bot {
  align-self: flex-start;
  background: var(--ad-bot-bubble);
  color: var(--ad-bot-text);
  border-bottom-left-radius: 4px;
}
.ad-msg-bot a {
  color: var(--ad-primary);
  font-weight: 500;
}

/* ---------- Typing indicator ---------- */
.ad-typing {
  align-self: flex-start;
  background: var(--ad-bot-bubble);
  padding: 12px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  animation: ad-msg-in .2s ease-out;
}
.ad-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ad-text-soft);
  opacity: 0.6;
  animation: ad-blink 1.2s infinite ease-in-out;
}
.ad-typing span:nth-child(2) { animation-delay: .2s; }
.ad-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes ad-blink {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ---------- Quick actions (botones bajo header) ---------- */
.ad-quick {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: var(--ad-bg);
  border-bottom: 1px solid var(--ad-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.ad-quick::-webkit-scrollbar { display: none; }
.ad-quick button {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--ad-border);
  background: var(--ad-bg);
  color: var(--ad-text);
  font-size: 12.5px;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.ad-quick button:hover {
  background: var(--ad-primary);
  color: #fff;
  border-color: var(--ad-primary);
}

/* ---------- Input ---------- */
.ad-input-wrap {
  padding: 10px 12px;
  background: var(--ad-bg);
  border-top: 1px solid var(--ad-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.ad-input {
  flex: 1;
  border: 1px solid var(--ad-border);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  background: var(--ad-bg-soft);
  color: var(--ad-text);
  resize: none;
  max-height: 100px;
  min-height: 40px;
  outline: none;
  transition: border-color .15s ease;
  line-height: 1.35;
}
.ad-input:focus { border-color: var(--ad-primary); }
.ad-input::placeholder { color: var(--ad-text-soft); }

.ad-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ad-primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s ease, transform .1s ease;
}
.ad-send:hover:not(:disabled) { background: var(--ad-primary-hover); }
.ad-send:active:not(:disabled) { transform: scale(0.94); }
.ad-send:disabled { opacity: 0.4; cursor: not-allowed; }
.ad-send svg { width: 18px; height: 18px; fill: currentColor; }

/* ---------- Footer (WhatsApp + legal) ---------- */
.ad-footer {
  padding: 6px 12px 10px;
  background: var(--ad-bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--ad-text-soft);
}
.ad-footer a {
  color: var(--ad-text-soft);
  text-decoration: none;
}
.ad-wa {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #25D366;
  color: #fff !important;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s ease;
}
.ad-wa:hover { background: #1EB954; }
.ad-wa svg { width: 14px; height: 14px; fill: currentColor; }

/* ---------- Tarjeta de resumen de cita ---------- */
.ad-card {
  align-self: stretch;
  background: var(--ad-bg);
  border: 1px solid var(--ad-border);
  border-radius: 12px;
  padding: 14px;
  animation: ad-msg-in .3s ease-out;
}
.ad-card h4 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--ad-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ad-card-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px dashed var(--ad-border);
  font-size: 13.5px;
}
.ad-card-row:last-of-type { border-bottom: none; }
.ad-card-row strong { color: var(--ad-text-soft); font-weight: 500; }
.ad-card-row span { color: var(--ad-text); font-weight: 500; text-align: right; }
.ad-card-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}
.ad-card-actions button {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s ease;
}
.ad-btn-primary {
  background: var(--ad-primary);
  color: #fff;
}
.ad-btn-primary:hover { background: var(--ad-primary-hover); }
.ad-btn-secondary {
  background: var(--ad-bg-soft);
  color: var(--ad-text);
  border: 1px solid var(--ad-border) !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .ad-window {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .ad-bubble {
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
  }
}

/* ---------- Modo oscuro ---------- */
.ad-root[data-theme="dark"] {
  --ad-primary: #05BFDB;
  --ad-primary-hover: #38D3E8;
  --ad-accent: #088395;
  --ad-bg: #0D1B26;
  --ad-bg-soft: #142834;
  --ad-text: #E8F0F5;
  --ad-text-soft: #8FA8B8;
  --ad-border: #1F3342;
  --ad-user-bubble: #05BFDB;
  --ad-user-text: #0D1B26;
  --ad-bot-bubble: #1A2F3E;
  --ad-bot-text: #E8F0F5;
  --ad-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
