/* ==========================
   Widget del asistente VES
   Reutiliza las variables del tema, con valores de reserva por si el widget
   se usa en un contexto donde styles.css no esté cargado.
   ========================== */

.ves-ai {
  --ves-ai-primary: var(--color-primary, #f36729);
  --ves-ai-primary-dark: var(--color-primary-dark, #d74c17);
  --ves-ai-surface: var(--color-surface, #fff);
  --ves-ai-soft: var(--color-soft-background, #fff1e5);
  --ves-ai-text: var(--color-text, #040403);
  --ves-ai-muted: var(--color-text-muted, #6b655d);
  --ves-ai-border: var(--color-border, #ece7e0);
  --ves-ai-dark: var(--color-dark-background, #0f0e0d);
  --ves-ai-radius: 16px;

  position: fixed;
  right: clamp(12px, 3vw, 24px);
  bottom: clamp(12px, 3vw, 24px);
  z-index: 9990;
  font-family: var(--font-body, system-ui, sans-serif);
  color: var(--ves-ai-text);
}

/* El tema no define una clase para texto solo audible, así que el widget
   lleva la suya y no depende de nada externo. */
.ves-ai__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- Botón lanzador ---- */

.ves-ai__launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px 12px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--ves-ai-primary);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(15, 14, 13, 0.18);
  transition: transform 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

.ves-ai__launcher:hover {
  background: var(--ves-ai-primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(15, 14, 13, 0.24);
}

.ves-ai__launcher:focus-visible {
  outline: 3px solid var(--ves-ai-dark);
  outline-offset: 3px;
}

.ves-ai__launcher-icon {
  display: inline-flex;
}

/* Se retira del flujo, no solo de la vista: si dejara su hueco, el panel no
   quedaría anclado al borde inferior. */
.ves-ai[data-state="open"] .ves-ai__launcher {
  display: none;
}

/* ---- Panel ---- */

.ves-ai__panel {
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 24px));
  max-height: min(640px, calc(100vh - 48px));
  background: var(--ves-ai-surface);
  border: 1px solid var(--ves-ai-border);
  border-radius: var(--ves-ai-radius);
  box-shadow: 0 20px 60px rgba(15, 14, 13, 0.22);
  overflow: hidden;
  animation: ves-ai-in 0.22s ease;
}

.ves-ai__panel[hidden] {
  display: none;
}

@keyframes ves-ai-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ves-ai__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--ves-ai-dark);
  color: #fff;
}

.ves-ai__title {
  margin: 0;
  font-family: var(--font-display, inherit);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
  color: #fff;
}

.ves-ai__subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.72);
}

.ves-ai__close {
  flex-shrink: 0;
  display: inline-flex;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.ves-ai__close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.ves-ai__close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ---- Aviso previo ---- */

.ves-ai__consent {
  padding: 18px;
  background: var(--ves-ai-soft);
  border-bottom: 1px solid var(--ves-ai-border);
}

.ves-ai__consent[hidden] {
  display: none;
}

.ves-ai__consent p {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ves-ai-muted);
}

.ves-ai__consent a {
  color: var(--ves-ai-primary-dark);
  text-decoration: underline;
}

.ves-ai__accept {
  padding: 9px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--ves-ai-dark);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.ves-ai__accept:hover {
  background: #000;
}

/* ---- Conversación ---- */

.ves-ai__log {
  flex: 1;
  min-height: 180px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ves-ai__log[hidden] {
  display: none;
}

.ves-ai__msg {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ves-ai__msg--bot {
  align-self: flex-start;
  background: var(--ves-ai-soft);
  border-bottom-left-radius: 4px;
}

.ves-ai__msg--user {
  align-self: flex-end;
  background: var(--ves-ai-dark);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ves-ai__msg--error {
  align-self: stretch;
  max-width: 100%;
  background: #fdecec;
  color: #8c1c1c;
  font-size: 13.5px;
}

/* ---- Fuentes, valoración y llamada a la acción ---- */

.ves-ai__meta {
  align-self: flex-start;
  max-width: 88%;
  margin-top: -6px;
  font-size: 12.5px;
  color: var(--ves-ai-muted);
}

.ves-ai__sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.ves-ai__source {
  padding: 3px 9px;
  border: 1px solid var(--ves-ai-border);
  border-radius: 999px;
  color: var(--ves-ai-muted);
  font-size: 12px;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.ves-ai__source:hover {
  border-color: var(--ves-ai-primary);
  color: var(--ves-ai-primary-dark);
}

.ves-ai__cta {
  align-self: flex-start;
  display: inline-block;
  margin-top: 2px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--ves-ai-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.ves-ai__cta:hover {
  background: var(--ves-ai-primary-dark);
  color: #fff;
}

.ves-ai__rate {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.ves-ai__rate-btn {
  padding: 3px 11px;
  border: 1px solid var(--ves-ai-border);
  border-radius: 999px;
  background: transparent;
  color: var(--ves-ai-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ves-ai__rate-btn:hover {
  border-color: var(--ves-ai-primary);
  color: var(--ves-ai-primary-dark);
}

/* ---- Sugerencias ---- */

.ves-ai__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px 12px;
}

.ves-ai__suggestions[hidden] {
  display: none;
}

.ves-ai__chip {
  padding: 7px 13px;
  border: 1px solid var(--ves-ai-border);
  border-radius: 999px;
  background: var(--ves-ai-surface);
  color: var(--ves-ai-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.ves-ai__chip:hover {
  border-color: var(--ves-ai-primary);
  color: var(--ves-ai-primary-dark);
}

/* ---- Formulario ---- */

.ves-ai__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--ves-ai-border);
  background: var(--ves-ai-surface);
}

.ves-ai__form[hidden] {
  display: none;
}

.ves-ai__input {
  flex: 1;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--ves-ai-border);
  border-radius: 12px;
  background: var(--ves-ai-surface);
  color: inherit;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  resize: none;
}

.ves-ai__input:focus {
  outline: 2px solid var(--ves-ai-primary);
  outline-offset: -1px;
  border-color: transparent;
}

.ves-ai__send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--ves-ai-primary);
  color: #fff;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.ves-ai__send:hover:not(:disabled) {
  background: var(--ves-ai-primary-dark);
}

.ves-ai__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---- Indicador de espera ---- */

.ves-ai__typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.ves-ai__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ves-ai-muted);
  animation: ves-ai-blink 1.2s infinite ease-in-out;
}

.ves-ai__typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.ves-ai__typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes ves-ai-blink {
  0%, 80%, 100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

/* ---- Adaptación a pantallas pequeñas ---- */

@media (max-width: 480px) {
  .ves-ai {
    right: 10px;
    left: 10px;
    bottom: 10px;
  }

  .ves-ai__panel {
    width: 100%;
    max-height: calc(100vh - 20px);
  }

  .ves-ai__launcher {
    float: right;
  }

  .ves-ai__launcher-label {
    display: none;
  }

  .ves-ai__launcher {
    padding: 14px;
  }
}

/* ---- Preferencia de movimiento reducido ---- */

@media (prefers-reduced-motion: reduce) {
  .ves-ai__panel {
    animation: none;
  }

  .ves-ai__launcher,
  .ves-ai__send,
  .ves-ai__chip,
  .ves-ai__source {
    transition: none;
  }

  .ves-ai__typing span {
    animation: none;
    opacity: 0.6;
  }
}
