/* Asistente virtual de xdmarc.xcitione.com. Todas las clases llevan el prefijo xdchat- para no chocar con Tailwind. */
#xdchat-root {
  --xdchat-bg: #ffffff;
  --xdchat-text: #0a1a4a;
  --xdchat-muted: #64748b;
  --xdchat-border: #e2e8f0;
  --xdchat-user-bubble: #f1f5f9;
  --xdchat-accent: #0040df;
  --xdchat-accent-dark: #0a1a4a;
  --xdchat-chip-bg: #e8eeff;
  --xdchat-gradient: linear-gradient(135deg, #0040df 0%, #0a1a4a 100%);
  --xdchat-radius: 14px;
  --xdchat-ease: 0.18s ease;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

#xdchat-root [hidden] { display: none !important; }

/* Solo para lectores de pantalla */
.xdchat-sr-only {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}

/* Lanzador */
.xdchat-fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 4px 4px;
  border: none;
  border-radius: 999px;
  background: var(--xdchat-gradient);
  box-shadow: 0 6px 22px rgba(0, 64, 223, 0.4);
  cursor: pointer;
  font-family: inherit;
  transition: transform var(--xdchat-ease), box-shadow var(--xdchat-ease);
}
.xdchat-fab:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0, 64, 223, 0.5); }
.xdchat-fab:focus-visible { outline: 2px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 5px rgba(0, 64, 223, 0.55); }
.xdchat-fab-icon {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.16); color: #fff;
}
.xdchat-fab-icon svg { width: 24px; height: 24px; }
.xdchat-fab-label { color: #fff; font-size: 14px; font-weight: 700; white-space: nowrap; }
.xdchat-unread {
  position: absolute; top: 2px; left: 36px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #ef4444; border: 2px solid #fff;
}

/* Panel lateral */
.xdchat-panel {
  position: fixed;
  top: 16px; right: 16px; bottom: 16px;
  z-index: 10000;
  width: 400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--xdchat-bg);
  color: var(--xdchat-text);
  border-radius: var(--xdchat-radius);
  box-shadow: 0 20px 60px rgba(4, 12, 30, 0.45);
  animation: xdchat-slide-in 0.24s ease;
}
@keyframes xdchat-slide-in {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

.xdchat-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 12px 18px;
}
.xdchat-title { margin: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; font-size: 15px; line-height: 1.3; }
.xdchat-title strong { font-weight: 700; color: var(--xdchat-text); }
.xdchat-title span { color: var(--xdchat-muted); font-size: 13px; }
.xdchat-close {
  display: flex; padding: 6px; border: none; border-radius: 8px;
  background: none; color: var(--xdchat-text); cursor: pointer;
  transition: background var(--xdchat-ease);
}
.xdchat-close:hover { background: var(--xdchat-user-bubble); }
.xdchat-close:focus-visible, .xdchat-chip:focus-visible, .xdchat-send:focus-visible, .xdchat-action:focus-visible, .xdchat-link:focus-visible {
  outline: 2px solid var(--xdchat-accent); outline-offset: 2px;
}
.xdchat-close svg { width: 22px; height: 22px; }

/* Conversación */
.xdchat-messages {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 16px;
  padding: 0 18px 16px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.xdchat-hero {
  flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 22px 18px 18px;
  border-radius: 12px;
  text-align: center;
  color: #fff;
  background:
    radial-gradient(circle at 50% 30%, rgba(96, 141, 255, 0.55), transparent 62%),
    linear-gradient(160deg, #0040df 0%, #0a1a4a 100%);
}
.xdchat-hero svg { width: 40px; height: 40px; opacity: 0.95; }
.xdchat-hero-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.xdchat-hero-sub { margin: 0; max-width: 280px; font-size: 13px; line-height: 1.45; color: rgba(255, 255, 255, 0.86); }

.xdchat-assistant { font-size: 15px; line-height: 1.6; color: var(--xdchat-text); }
.xdchat-assistant strong { font-weight: 700; }
.xdchat-user {
  align-self: flex-end;
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--xdchat-user-bubble);
  font-size: 15px; line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.xdchat-paragraph { margin: 0; }
.xdchat-paragraph + .xdchat-paragraph,
.xdchat-list + .xdchat-paragraph,
.xdchat-paragraph + .xdchat-list { margin-top: 8px; }
.xdchat-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.xdchat-list li { position: relative; padding-left: 18px; }
.xdchat-list li::before {
  content: '';
  position: absolute; left: 4px; top: 0.66em;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--xdchat-accent);
}
.xdchat-link { color: var(--xdchat-accent); text-decoration: underline; text-underline-offset: 2px; word-break: break-word; }

.xdchat-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.xdchat-action {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--xdchat-accent);
  border-radius: 8px;
  color: var(--xdchat-accent);
  font-size: 14px; font-weight: 600;
  text-decoration: none;
  transition: background var(--xdchat-ease), color var(--xdchat-ease), border-color var(--xdchat-ease);
}
.xdchat-action:first-child { background: var(--xdchat-accent); color: #fff; }
.xdchat-action:hover { background: var(--xdchat-accent-dark); border-color: var(--xdchat-accent-dark); color: #fff; }

.xdchat-typing { display: flex; gap: 5px; padding: 4px 0; }
.xdchat-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #94a3b8;
  animation: xdchat-bounce 1.2s infinite;
}
.xdchat-typing span:nth-child(2) { animation-delay: 0.2s; }
.xdchat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes xdchat-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Pie: respuestas rápidas, entrada y aviso */
.xdchat-footer { flex-shrink: 0; padding: 10px 16px 12px; border-top: 1px solid var(--xdchat-border); }
.xdchat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.xdchat-chip {
  padding: 6px 12px;
  border: none; border-radius: 999px;
  background: var(--xdchat-chip-bg);
  color: var(--xdchat-accent);
  font-family: inherit; font-size: 13px;
  cursor: pointer;
  transition: background var(--xdchat-ease);
}
.xdchat-chip:hover:not(:disabled) { background: #d3deff; }
.xdchat-chip:disabled { opacity: 0.5; cursor: default; }

.xdchat-inputbox {
  display: flex; align-items: flex-end; gap: 4px;
  padding: 6px 6px 6px 14px;
  border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fff;
  transition: border-color var(--xdchat-ease), box-shadow var(--xdchat-ease);
}
.xdchat-inputbox:focus-within { border-color: var(--xdchat-accent); box-shadow: 0 0 0 3px rgba(0, 64, 223, 0.14); }
.xdchat-input {
  flex: 1;
  max-height: 110px;
  padding: 8px 0;
  border: none; outline: none; resize: none;
  background: transparent;
  color: var(--xdchat-text);
  font-family: inherit; font-size: 15px; line-height: 1.4;
}
.xdchat-input::placeholder { color: #94a3b8; }
.xdchat-send {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: none; border-radius: 50%;
  background: var(--xdchat-accent); color: #fff;
  cursor: pointer;
  transition: background var(--xdchat-ease), opacity var(--xdchat-ease);
}
.xdchat-send:hover:not(:disabled) { background: var(--xdchat-accent-dark); }
.xdchat-send:disabled { background: #e2e8f0; color: #94a3b8; cursor: default; }
.xdchat-send svg { width: 18px; height: 18px; }

.xdchat-disclaimer { margin: 10px 4px 0; text-align: center; font-size: 11px; line-height: 1.45; color: var(--xdchat-muted); }
.xdchat-disclaimer-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.xdchat-disclaimer-link:hover { color: var(--xdchat-text); }

@media (prefers-reduced-motion: reduce) {
  .xdchat-panel, .xdchat-typing span { animation: none; }
  .xdchat-fab { transition: none; }
}

/* Móvil: pantalla completa */
@media (max-width: 480px) {
  .xdchat-panel { inset: 0; width: 100%; border-radius: 0; padding-bottom: env(safe-area-inset-bottom); }
  .xdchat-header { padding-top: calc(12px + env(safe-area-inset-top)); }
  .xdchat-hero { padding: 16px 14px 14px; }
  .xdchat-input { font-size: 16px; } /* evita el zoom de iOS al enfocar */
  .xdchat-fab { right: 16px; bottom: 20px; padding: 3px; }
  .xdchat-fab-icon { width: 50px; height: 50px; }
  .xdchat-fab-label { display: none; }
  .xdchat-unread { left: auto; right: 0; }
}
