/* ============================================================
   iv-chat.css — presentacion del CHAT WEB embebible (V1).

   Mismo sistema que iv-directory.css: todo el tema deriva de
   --iv-accent (configurable por el negocio) + variables claro/
   oscuro; el movimiento vive integramente aqui (el JS solo pone y
   quita clases) y se apaga completo con prefers-reduced-motion.
   Mobile-first: en pantallas <=480px el panel ocupa el ancho de la
   pantalla con margenes dignos.
   ============================================================ */

.iv-chat {
  --iv-accent: #11c15b;
  --iv-bg: #ffffff;
  --iv-fg: #1a1a1a;
  --iv-fg-muted: #6b7280;
  --iv-border: rgba(0, 0, 0, 0.08);
  --iv-shadow: 0 10px 34px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.08);
  --iv-panel-bg: #ffffff;
  --iv-thread-bg: #f7f8fa;
  --iv-bubble-in-bg: #eceef1;
  --iv-bubble-in-fg: #1a1a1a;
  --iv-card-bg: #ffffff;
  --iv-input-bg: #ffffff;

  position: fixed;
  bottom: 20px;
  z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--iv-fg);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.iv-chat *,
.iv-chat *::before,
.iv-chat *::after {
  box-sizing: inherit;
}

.iv-chat--bottom-right { right: 20px; align-items: flex-end; }
.iv-chat--bottom-left { left: 20px; align-items: flex-start; }

@media (prefers-color-scheme: dark) {
  .iv-chat:not([data-iv-theme="light"]) {
    --iv-bg: #1d2129;
    --iv-fg: #f3f4f6;
    --iv-fg-muted: #9aa1ac;
    --iv-border: rgba(255, 255, 255, 0.1);
    --iv-shadow: 0 12px 38px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(0, 0, 0, 0.35);
    --iv-panel-bg: #232834;
    --iv-thread-bg: #1d2129;
    --iv-bubble-in-bg: #2d3342;
    --iv-bubble-in-fg: #f3f4f6;
    --iv-card-bg: #232834;
    --iv-input-bg: #2d3342;
  }
}

.iv-chat[data-iv-theme="dark"] {
  --iv-bg: #1d2129;
  --iv-fg: #f3f4f6;
  --iv-fg-muted: #9aa1ac;
  --iv-border: rgba(255, 255, 255, 0.1);
  --iv-shadow: 0 12px 38px rgba(0, 0, 0, 0.5), 0 2px 10px rgba(0, 0, 0, 0.35);
  --iv-panel-bg: #232834;
  --iv-thread-bg: #1d2129;
  --iv-bubble-in-bg: #2d3342;
  --iv-bubble-in-fg: #f3f4f6;
  --iv-card-bg: #232834;
  --iv-input-bg: #2d3342;
}

/* ---- launcher ---- */

.iv-chat-fab {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background-color: var(--iv-accent);
  background-image: linear-gradient(150deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 46%, rgba(0, 0, 0, 0.16));
  color: #fff;
  box-shadow: var(--iv-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s ease;
}

.iv-chat-fab:hover,
.iv-chat-fab:focus-visible {
  transform: scale(1.07);
  box-shadow: var(--iv-shadow), 0 0 26px rgba(0, 0, 0, 0.06), 0 0 22px var(--iv-accent);
}
.iv-chat-fab:active { transform: scale(0.96); }

.iv-chat-fab .iv-chat-fab-icon {
  position: absolute;
  width: 26px;
  height: 26px;
  fill: currentColor;
  transition: transform 0.34s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}
.iv-chat-fab .iv-chat-fab-icon--bolt {
  opacity: 0;
  transform: scale(0.3) rotate(-70deg);
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.85));
}
.iv-chat-fab:hover .iv-chat-fab-icon--chat,
.iv-chat-fab:focus-visible .iv-chat-fab-icon--chat {
  opacity: 0;
  transform: scale(0.3) rotate(70deg);
}
.iv-chat-fab:hover .iv-chat-fab-icon--bolt,
.iv-chat-fab:focus-visible .iv-chat-fab-icon--bolt {
  opacity: 1;
  transform: scale(1) rotate(0deg);
  animation: iv-chat-bolt-strike 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes iv-chat-bolt-strike {
  0% { transform: scale(0.3) rotate(-70deg); }
  55% { transform: scale(1.22) rotate(8deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.iv-chat-fab-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
}
.iv-chat-fab:hover .iv-chat-fab-ring,
.iv-chat-fab:focus-visible .iv-chat-fab-ring {
  opacity: 1;
  animation: iv-chat-ring-pulse 1.15s ease-out infinite;
}
@keyframes iv-chat-ring-pulse {
  0% { box-shadow: 0 0 0 0 var(--iv-accent); opacity: 0.75; }
  100% { box-shadow: 0 0 0 16px rgba(0, 0, 0, 0); opacity: 0; }
}

/* mensajes sin leer con el panel cerrado */
.iv-chat-fab-badge {
  display: none;
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  border: 2px solid var(--iv-panel-bg);
}
.iv-chat-fab-badge--visible { display: block; }

/* ---- panel ---- */

.iv-chat-panel {
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 540px;
  max-height: min(75vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--iv-panel-bg);
  border-radius: 18px;
  box-shadow: var(--iv-shadow);
  border: 1px solid var(--iv-border);
  overflow: hidden;
  animation: iv-chat-panel-in 0.3s cubic-bezier(0.21, 1.02, 0.73, 1);
  transform-origin: bottom right;
}
.iv-chat--bottom-left .iv-chat-panel { transform-origin: bottom left; }

@keyframes iv-chat-panel-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.iv-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 15px 18px;
  background-color: var(--iv-accent);
  background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 42%, rgba(0, 0, 0, 0.18));
  color: #fff;
  flex-shrink: 0;
}

.iv-chat-header-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.iv-chat-close {
  border: none;
  background: rgba(0, 0, 0, 0.14);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease;
}
.iv-chat-close:hover { background: rgba(0, 0, 0, 0.28); }

/* linea de estado: conectando / reconectando / error de inicio */
.iv-chat-status {
  display: none;
  padding: 6px 18px;
  font-size: 12px;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  flex-shrink: 0;
}
.iv-chat-status--visible { display: block; }

@media (prefers-color-scheme: dark) {
  .iv-chat:not([data-iv-theme="light"]) .iv-chat-status { background: #452c07; color: #fcd34d; }
}
.iv-chat[data-iv-theme="dark"] .iv-chat-status { background: #452c07; color: #fcd34d; }

/* Divulgacion de IA (Reglamento de IA de la UE art. 50, vigente 2026-08-02;
   S.B. 1001 de California). Persistente mientras el panel esta abierto y
   legible, pero sin competir con la conversacion: es informacion obligatoria,
   no un mensaje del negocio. */
.iv-chat-disclosure {
  padding: 7px 18px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--iv-fg-muted);
  background: var(--iv-thread-bg);
  border-block-end: 1px solid var(--iv-border);
  flex-shrink: 0;
}

/* Etiqueta de autoria sobre cada mensaje de la IA. .iv-chat-msg es flex en
   fila (para alinear la burbuja a un lado u otro); los de IA pasan a columna
   para que la etiqueta quede ENCIMA de la burbuja, no al costado. */
.iv-chat-msg--ai { flex-direction: column; align-items: flex-start; }
.iv-chat-msg-sender {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--iv-fg-muted);
  margin-block-end: 3px;
  margin-inline-start: 4px;
}

/* ---- hilo ---- */

.iv-chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: var(--iv-thread-bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.iv-chat-msg { display: flex; }
.iv-chat-msg--contact { justify-content: flex-end; }
.iv-chat-msg--agent, .iv-chat-msg--ai { justify-content: flex-start; }

.iv-chat-bubble {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13.8px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  animation: iv-chat-msg-in 0.22s ease;
}

@keyframes iv-chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.iv-chat-msg--contact .iv-chat-bubble {
  background-color: var(--iv-accent);
  background-image: linear-gradient(150deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 55%, rgba(0, 0, 0, 0.1));
  color: #fff;
  border-bottom-right-radius: 5px;
}

.iv-chat-msg--agent .iv-chat-bubble,
.iv-chat-msg--ai .iv-chat-bubble {
  background: var(--iv-bubble-in-bg);
  color: var(--iv-bubble-in-fg);
  border-bottom-left-radius: 5px;
}

/* pendiente = todavia sin confirmar por el servidor (cola local) */
.iv-chat-msg--pending .iv-chat-bubble { opacity: 0.55; }

.iv-chat-typing {
  align-self: flex-start;
  font-size: 12px;
  font-style: italic;
  color: var(--iv-fg-muted);
  padding: 2px 6px;
}

.iv-chat-divider {
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--iv-fg-muted);
  margin: 8px 0 2px;
}

/* ---- tarjetas dentro del hilo (correo, calificacion) ---- */

.iv-chat-card {
  background: var(--iv-card-bg);
  border: 1px solid var(--iv-border);
  border-radius: 14px;
  padding: 13px 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  animation: iv-chat-msg-in 0.22s ease;
}

.iv-chat-card-text { margin: 0 0 10px; color: var(--iv-fg); font-size: 13px; }
.iv-chat-card-text--ok { margin: 0; color: var(--iv-fg-muted); }

.iv-chat-card-error {
  margin: 8px 0 0;
  font-size: 12px;
  color: #dc2626;
}

.iv-chat-email-input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--iv-border);
  background: var(--iv-input-bg);
  color: var(--iv-fg);
  font-size: 13.5px;
  font-family: inherit;
  margin-bottom: 9px;
}
.iv-chat-email-input:focus {
  outline: none;
  border-color: var(--iv-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--iv-accent) 22%, transparent);
}

.iv-chat-card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.iv-chat-btn {
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
}
.iv-chat-btn:disabled { opacity: 0.55; cursor: default; }

.iv-chat-btn--primary { background: var(--iv-accent); color: #fff; }
.iv-chat-btn--primary:hover:not(:disabled) { filter: brightness(1.07); transform: translateY(-1px); }

/* "Saltar" bien visible: boton real con borde, no un link diminuto */
.iv-chat-btn--ghost {
  background: transparent;
  color: var(--iv-fg-muted);
  border: 1px solid var(--iv-border);
}
.iv-chat-btn--ghost:hover:not(:disabled) { color: var(--iv-fg); border-color: var(--iv-fg-muted); }

/* calificacion 1-5 */
.iv-chat-rating-row { display: flex; gap: 6px; }

.iv-chat-rating-btn {
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--iv-border);
  -webkit-text-stroke: 1px var(--iv-fg-muted);
  cursor: pointer;
  padding: 2px 3px;
  transition: color 0.12s ease, transform 0.12s ease;
}
.iv-chat-rating-btn--lit { color: #f59e0b; -webkit-text-stroke: 0; transform: scale(1.12); }
.iv-chat-rating-btn:disabled { cursor: default; }

/* ---- pie: input + enviar ---- */

.iv-chat-footer {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  border-top: 1px solid var(--iv-border);
  background: var(--iv-panel-bg);
  flex-shrink: 0;
}

.iv-chat-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--iv-border);
  background: var(--iv-input-bg);
  color: var(--iv-fg);
  font-size: 13.8px;
  font-family: inherit;
}
.iv-chat-input:focus {
  outline: none;
  border-color: var(--iv-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--iv-accent) 22%, transparent);
}
.iv-chat-input::placeholder { color: var(--iv-fg-muted); }

.iv-chat-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--iv-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: filter 0.15s ease, transform 0.15s ease;
}
.iv-chat-send:hover { filter: brightness(1.07); transform: scale(1.05); }
.iv-chat-send svg { width: 18px; height: 18px; fill: currentColor; }

/* ---- atribucion ---- */

.iv-chat-attribution {
  display: block;
  text-align: center;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--iv-fg-muted);
  text-decoration: none;
  padding: 8px 8px 10px;
  background: var(--iv-panel-bg);
  border-top: 1px solid var(--iv-border);
  transition: color 0.15s ease;
}
.iv-chat-attribution:hover { color: var(--iv-fg); }

.iv-chat-hidden { display: none !important; }

/* ---- movil: el panel ocupa el ancho con margenes dignos ---- */
@media (max-width: 480px) {
  .iv-chat-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-width: none;
    height: min(560px, calc(100dvh - 24px));
    max-height: calc(100dvh - 24px);
  }
}

/* ---- accesibilidad de movimiento ---- */
@media (prefers-reduced-motion: reduce) {
  .iv-chat-fab,
  .iv-chat-fab .iv-chat-fab-icon,
  .iv-chat-panel,
  .iv-chat-bubble,
  .iv-chat-card,
  .iv-chat-rating-btn,
  .iv-chat-send {
    transition: opacity 0.15s ease;
    animation: none !important;
  }
  .iv-chat-fab:hover,
  .iv-chat-fab:focus-visible { transform: none; }
  .iv-chat-fab:hover .iv-chat-fab-icon--chat { transform: none; }
  .iv-chat-fab:hover .iv-chat-fab-icon--bolt { transform: none; }
  .iv-chat-fab-ring { display: none; }
  .iv-chat-rating-btn--lit { transform: none; }
  .iv-chat-send:hover { transform: none; }
}
