/* Conversaciones de ejemplo · botón flotante + ventana con iPhone.
   Patrón de see-for-yourself: botón que abre un teléfono en overlay (sin PNG, marco en CSS de phone.css). */

/* ---------- Botón flotante ---------- */
.chat-fab {
  position: fixed;
  right: var(--gutter);
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
  z-index: 55;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: var(--fab-h);
  padding: 0 18px 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--surface);
  font-size: var(--btn-size);
  font-weight: var(--btn-weight);
  box-shadow: var(--phone-shadow);
  opacity: 0;
  transition: opacity var(--dur-state) var(--ease-out), transform var(--dur-state) var(--ease-out);
}

.chat-fab { pointer-events: none; }
.chat-fab[hidden] { display: none; }
.chat-fab.is-in { opacity: 1; pointer-events: auto; }

.chat-fab__icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
}

.chat-fab__icon svg { width: 24px; height: 24px; }

/* Tres puntos de "escribiendo…" dentro del globo */
.chat-fab__dots {
  position: absolute;
  top: 16px;
  left: 50%;
  display: flex;
  gap: 3px;
  transform: translateX(-50%);
}

.chat-fab__dots i,
.chat__typing i {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

/* Globo de vista previa */
.chat-fab__preview {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--phone-shadow);
  opacity: 0;
  pointer-events: none;
  transform-origin: 100% 100%;
  transition: opacity var(--dur-state) var(--ease-out), transform var(--dur-state) var(--ease-out);
}

.chat-fab.has-preview .chat-fab__preview { opacity: 1; }

.chat-fab:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Se esconde mientras está el mini pase o la ventana */
body.mini-open .chat-fab,
body.chat-open .chat-fab { opacity: 0; pointer-events: none; }

/* ---------- Ventana ---------- */
.chat-dialog {
  width: calc(100% - 24px);
  max-width: 420px;
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--bg);
  color: var(--ink);
  overflow: auto;
}

.chat-dialog::backdrop { background: var(--backdrop); }

.chat-dialog__panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.chat-dialog__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-dialog__title {
  font-size: var(--chat-title-size);
  line-height: 1.2;
}

.chat-dialog__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: auto;
  border-radius: 50%;
  background: var(--surface);
  font-size: 14px;
}

.chat-dialog__close:focus-visible,
.chat-tab:focus-visible,
.chat-dialog__replay:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Selectores de conversación */
.chat-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
}

.chat-tab {
  flex: 1;
  min-height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: var(--chat-tab-size);
  font-weight: 600;
  color: var(--ink);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.chat-tab[aria-checked="true"] { background: var(--ink); color: var(--surface); }

/* iPhone con el chat (marco de phone.css) */
.phone--chat {
  justify-self: center;
  height: min(var(--phone-h), calc(100dvh - 300px));
  min-height: 420px;
  box-shadow: none;
}

.chat {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: calc(var(--phone-radius) - var(--phone-bezel));
  background: var(--bg);
}

.chat__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 40px 12px 10px;
  background: var(--deep);
  color: var(--on-deep);
  font-size: var(--chat-meta-size);
  font-weight: 600;
}

.phone--chat[data-giro="consultorio"] .chat__bar { background: var(--nav); }

.chat__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--on-deep-line);
  font-size: 12px;
}

.chat__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
}

.chat__body::-webkit-scrollbar { display: none; }

.chat__sep {
  align-self: center;
  margin: 4px 0;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--border);
  font-size: var(--chat-meta-size);
  color: var(--ink);
}

.chat__msg {
  max-width: 84%;
  padding: 7px 10px 5px;
  border-radius: 10px;
  font-size: var(--chat-msg-size);
  line-height: 1.35;
  white-space: pre-line;
}

.chat__msg--bot {
  align-self: flex-start;
  border-top-left-radius: 3px;
  background: var(--bubble-in);
}

.chat__msg--user {
  align-self: flex-end;
  border-top-right-radius: 3px;
  background: var(--bubble-out);
}

.chat__time {
  display: block;
  margin-top: 2px;
  font-size: var(--chat-time-size);
  color: var(--muted);
  text-align: right;
}

.chat__typing {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  color: var(--muted);
}

.chat__input {
  margin: 8px 10px 12px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  font-size: var(--chat-meta-size);
  color: var(--muted);
}

.chat-dialog__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-dialog__replay {
  font-size: 14px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Disparadores dentro de la página */
.chat-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

@media (min-width: 768px) {
  .chat-dialog__panel { padding: 20px; }
}

@media (min-width: 1440px) {
  .chat-dialog { max-width: 460px; }
  .phone--chat { width: 320px; }
}

/* ---------- Movimiento ---------- */
@media (prefers-reduced-motion: no-preference) {
  .chat-fab { transform: translateY(16px); }
  .chat-fab.is-in { transform: none; }
  body.mini-open .chat-fab,
  body.chat-open .chat-fab { transform: translateY(16px); }

  .chat-fab__dots i { animation: chat-dot 1.2s ease-in-out infinite; }
  .chat-fab__dots i:nth-child(2) { animation-delay: .15s; }
  .chat-fab__dots i:nth-child(3) { animation-delay: .3s; }

  .chat-fab__preview { transform: translateY(6px) scale(.9); }
  .chat-fab.has-preview .chat-fab__preview { transform: none; }

  .chat-fab:active { transform: scale(var(--press-scale)); transition-duration: var(--dur-press); }

  .chat-dialog[open] .chat-dialog__panel { animation: chat-in var(--dur-state) var(--ease-out); }

  .chat__msg, .chat__sep { animation: chat-bubble var(--dur-state) var(--ease-out) both; }
  .chat__typing i { animation: chat-dot 1.2s ease-in-out infinite; }
  .chat__typing i:nth-child(2) { animation-delay: .15s; }
  .chat__typing i:nth-child(3) { animation-delay: .3s; }
}

@media (prefers-reduced-motion: no-preference) and (hover: hover) {
  .chat-fab:hover { transform: translateY(-2px); }
}

@keyframes chat-dot {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

@keyframes chat-bubble {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

@keyframes chat-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
