/* Olevy · el asistente de Olevior Studio.
   Misma gramática visual que assets/css/studio.css: filos de un pixel, radios
   cortos, rótulos en mono y la flecha ↗ que recorre todo el sitio.
   El widget lo inyecta assets/js/chat-widget.js; aquí sólo vive su apariencia. */

.olevy {
  --olevy-ink: #0b2a4a;
  --olevy-blue: #0B2A4A;
  --olevy-ice: #dceaf8;
  --olevy-line: #d7e2ec;
  --olevy-paper: #f6f8fb;
  --olevy-dim: #50667b;
  --olevy-mute: #7d94a9;
  --olevy-night: linear-gradient(158deg, #061729 0%, #0b2a4a 58%, #050f1d 100%);
  --olevy-lift: 0 30px 70px -34px rgba(6, 23, 41, .55);
  --olevy-ease: cubic-bezier(.16, 1, .3, 1);

  position: fixed;
  right: clamp(16px, 2.4vw, 28px);
  bottom: clamp(16px, 2.4vw, 28px);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--font-sans);
  color: var(--olevy-ink);
}

.olevy-label {
  font-family: var(--font-mono);
  font-size: .75rem;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.olevy-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;
}

.olevy-dot {
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffffff;
}

/* ---- Invitación (estado cerrado) ---------------------------------- */
/* Va fuera del flujo: si ocupara sitio, el panel abriría un hueco encima
   del lanzador del tamaño de una invitación invisible. */
.olevy-teaser {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  z-index: 1;
  width: 292px;
  max-width: calc(100vw - 32px);
  background: #fff;
  border: 1px solid var(--olevy-line);
  border-radius: 8px 8px 2px 8px;
  box-shadow: 0 20px 44px -28px rgba(6, 23, 41, .65);
  opacity: 0;
  transform: translateY(10px) scale(.97);
  transition: opacity .32s var(--olevy-ease), transform .32s var(--olevy-ease);
  pointer-events: none;
}

.olevy-teaser.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.olevy.is-open .olevy-teaser {
  opacity: 0;
  transform: translateY(6px) scale(.97);
  pointer-events: none;
}

.olevy-teaser__open {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  border-radius: inherit;
}

.olevy-teaser__mark,
.olevy-panel__mark {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: var(--olevy-ice);
}

.olevy-teaser__body { min-width: 0; }
.olevy-teaser__body .olevy-label { color: var(--olevy-mute); }

.olevy-teaser__line {
  display: block;
  margin-top: 5px;
  font-size: .875rem;
  line-height: 1.45;
  letter-spacing: -.01em;
  color: var(--olevy-ink);
}

.olevy-teaser__arrow {
  margin-left: auto;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--olevy-mute);
  transition: transform .22s var(--olevy-ease), color .22s;
}

.olevy-teaser__open:hover .olevy-teaser__arrow {
  transform: translate(3px, -3px);
  color: var(--olevy-blue);
}

.olevy-teaser__dismiss {
  position: absolute;
  top: -9px;
  right: -9px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--olevy-line);
  color: var(--olevy-dim);
  font-size: 13px;
  line-height: 1;
  box-shadow: 0 6px 14px -8px rgba(6, 23, 41, .6);
  transition: color .2s, border-color .2s;
}

.olevy-teaser__dismiss:hover { color: var(--olevy-ink); border-color: #9fb6ca; }

/* ---- Lanzador ------------------------------------------------------ */
.olevy-launcher {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-height: 52px;
  padding: 0 20px 0 15px;
  border: 1px solid #17436d;
  border-radius: 8px;
  background: var(--olevy-night);
  color: #eaf3fc;
  box-shadow: var(--olevy-lift);
  transition: transform .26s var(--olevy-ease), box-shadow .26s var(--olevy-ease);
}

.olevy-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 26px 52px -26px rgba(6, 23, 41, .72);
}

.olevy-launcher__mark { display: flex; }

.olevy-launcher__label {
  font-size: .9375rem;
  letter-spacing: -.01em;
}

.olevy-launcher__x { display: none; }

.olevy.is-open .olevy-launcher {
  gap: 0;
  width: 52px;
  padding: 0;
  justify-content: center;
}

.olevy.is-open .olevy-launcher__mark,
.olevy.is-open .olevy-launcher__label,
.olevy.is-open .olevy-launcher .olevy-dot { display: none; }

.olevy.is-open .olevy-launcher__x { display: block; }

/* En modo lectura cierra la cabecera o el velo: el lanzador sobra. */
.olevy.is-expanded .olevy-launcher { display: none; }

/* ---- Panel --------------------------------------------------------- */
.olevy-scrim {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: rgba(6, 23, 41, .62);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

.olevy.is-expanded .olevy-scrim { opacity: 1; pointer-events: auto; }

.olevy-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(384px, calc(100vw - 32px));
  height: min(580px, calc(100svh - 148px));
  background: var(--olevy-paper);
  border: 1px solid var(--olevy-line);
  border-radius: 10px;
  box-shadow: var(--olevy-lift);
  overflow: hidden;
  transform-origin: 100% 100%;
  animation: olevy-in .34s var(--olevy-ease);
}

/* display:flex gana a [hidden]; hay que apagarlo a mano. */
.olevy-panel[hidden] { display: none; }

@keyframes olevy-in {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

.olevy.is-closing .olevy-panel {
  animation: olevy-out .24s ease forwards;
  pointer-events: none;
}

@keyframes olevy-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(12px) scale(.97); }
}

/* Modo lectura: el panel se centra sobre un velo, no ocupa todo el ancho. */
.olevy.is-expanded .olevy-panel {
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  width: min(760px, calc(100vw - 40px));
  height: min(780px, calc(100svh - 40px));
  border-radius: 12px;
  transform: translate(-50%, -50%);
  animation: none;
}

/* ---- Cabecera ------------------------------------------------------ */
.olevy-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: var(--olevy-night);
  border-bottom: 1px solid rgba(196, 216, 233, .18);
  color: #fff;
}

.olevy-panel__mark { flex-basis: 34px; width: 34px; height: 34px; }

.olevy-head__ident { min-width: 0; margin-right: auto; }

.olevy-head__name {
  display: block;
  font-size: .9375rem;
  letter-spacing: -.01em;
  color: #fff;
}

.olevy-head__role {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 3px;
  color: #a9c6df;
}

.olevy-icon {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(196, 216, 233, .26);
  border-radius: 6px;
  color: #d3e4f4;
  transition: background .2s, color .2s, border-color .2s;
}

.olevy-icon:hover { background: rgba(214, 233, 250, .14); color: #fff; border-color: rgba(196, 216, 233, .5); }
.olevy-icon svg { width: 14px; height: 14px; }
.olevy-head :focus-visible { outline-color: #ffffff; }

.olevy-icon__shrink { display: none; }
.olevy.is-expanded .olevy-icon__grow { display: none; }
.olevy.is-expanded .olevy-icon__shrink { display: block; }

/* ---- Conversación --------------------------------------------------- */
.olevy-stream {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.olevy-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 18px 16px 10px;
  scrollbar-width: thin;
  scrollbar-color: #c4d4e2 transparent;
}

.olevy-log::-webkit-scrollbar { width: 9px; }
.olevy-log::-webkit-scrollbar-thumb {
  background: #c9d8e5;
  border: 3px solid transparent;
  border-radius: 6px;
  background-clip: padding-box;
}

.olevy.is-expanded .olevy-log { padding-inline: max(20px, calc((100% - 660px) / 2)); }

/* 86% dentro del panel compacto; en modo lectura manda la medida en ch,
   para que la línea no se estire hasta perder el renglón. */
.olevy-turn {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: min(86%, 58ch);
  align-self: flex-start;
}

.olevy-turn--user { align-self: flex-end; align-items: flex-end; }

.olevy-turn__who {
  color: var(--olevy-mute);
  font-size: .75rem;
  letter-spacing: .09em;
}

.olevy-bubble {
  padding: 11px 14px;
  border: 1px solid #dce7f2;
  border-radius: 10px 10px 10px 3px;
  background: #fff;
  font-size: .90625rem;
  line-height: 1.6;
  letter-spacing: -.005em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.olevy-turn--user .olevy-bubble {
  background: var(--olevy-ink);
  border-color: var(--olevy-ink);
  border-radius: 10px 10px 3px 10px;
  color: #e9f2fb;
}

/* Escribiendo… */
.olevy-typing { display: flex; align-items: center; gap: 9px; padding: 13px 14px; }
.olevy-typing__label { color: var(--olevy-mute); }
.olevy-typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #8fb0cc;
  animation: olevy-bounce 1.2s infinite ease-in-out;
}
.olevy-typing i:nth-child(2) { animation-delay: .16s; }
.olevy-typing i:nth-child(3) { animation-delay: .32s; }

@keyframes olevy-bounce {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1;  transform: translateY(-3px); }
}

/* Salidas de emergencia cuando la respuesta falla. */
.olevy-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }

.olevy-mini {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid #d8e6f3;
  border-radius: 4px;
  background: var(--olevy-ice);
  color: var(--olevy-ink);
  font-size: .8125rem;
  transition: background .22s, border-color .22s, box-shadow .22s;
}

.olevy-mini:hover { background: #fff; border-color: #fff; box-shadow: 0 10px 24px -14px rgba(6, 23, 41, .55); color: var(--olevy-ink); }
.olevy-mini span { transition: transform .22s var(--olevy-ease); }
.olevy-mini:hover span { transform: translate(2px, -2px); }

/* Volver al último mensaje cuando la lectura se quedó arriba. */
.olevy-jump {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--olevy-line);
  border-radius: 6px;
  background: #fff;
  color: var(--olevy-dim);
  white-space: nowrap;
  box-shadow: 0 12px 26px -16px rgba(6, 23, 41, .7);
  transform: translate(-50%, 6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s var(--olevy-ease);
}

.olevy-jump.is-visible { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.olevy-jump:hover { color: var(--olevy-ink); border-color: #9fb6ca; }

/* ---- Atajos de inicio ---------------------------------------------- */
.olevy-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 16px 12px;
}

.olevy-starters[hidden] { display: none; }

.olevy-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border: 1px solid #d8e6f3;
  border-radius: 4px;
  background: var(--olevy-ice);
  color: var(--olevy-ink);
  font-size: .8125rem;
  line-height: 1.3;
  text-align: left;
  transition: background .22s, border-color .22s, box-shadow .22s;
}

.olevy-chip:hover { background: #fff; border-color: #fff; box-shadow: 0 10px 24px -14px rgba(6, 23, 41, .55); }
.olevy-chip span { color: var(--olevy-mute); transition: transform .22s var(--olevy-ease); }
.olevy-chip:hover span { transform: translate(2px, -2px); color: var(--olevy-blue); }

/* ---- Redacción ------------------------------------------------------ */
.olevy-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px 10px;
  background: #fff;
  border-top: 1px solid var(--olevy-line);
}

.olevy-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 132px;
  padding: 12px 13px;
  border: 1px solid #cbd9e6;
  border-radius: 6px;
  background: #fff;
  color: var(--olevy-ink);
  font-family: inherit;
  font-size: .875rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.olevy-input::placeholder { color: #93a8bb; }
.olevy-input:focus { border-color: var(--olevy-blue); box-shadow: 0 0 0 3px rgba(11, 42, 74, .13); }
.olevy-input:disabled { background: #f4f7fa; color: var(--olevy-mute); }

.olevy-send {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: var(--olevy-ink);
  color: #fff;
  font-size: 1.15rem;
  line-height: 1;
  transition: background .22s, opacity .22s;
}

.olevy-send span { display: block; transition: transform .22s var(--olevy-ease); }
.olevy-send:hover:not(:disabled) { background: var(--olevy-blue); }
.olevy-send:hover:not(:disabled) span { transform: translate(2px, -2px); }
.olevy-send:disabled { opacity: .32; cursor: default; }

.olevy-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px 12px;
  background: #fff;
  color: var(--olevy-mute);
}

.olevy-foot > span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.olevy-foot a {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--olevy-dim);
}

.olevy-foot a:hover { color: var(--olevy-blue); }

/* ---- Pantallas cortas y teléfono ------------------------------------ */
@media (max-height: 620px) {
  .olevy-panel { height: min(460px, calc(100svh - 108px)); }
}

@media (max-width: 560px) {
  .olevy { right: 14px; bottom: 14px; gap: 10px; }
  .olevy-teaser { width: min(300px, calc(100vw - 28px)); }

  .olevy-panel {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    height: min(88svh, 660px);
    border-width: 1px 0 0;
    border-radius: 14px 14px 0 0;
  }

  .olevy.is-expanded .olevy-panel {
    top: auto;
    left: 0;
    width: 100%;
    height: 96svh;
    border-radius: 14px 14px 0 0;
    transform: none;
  }

  .olevy.is-expanded .olevy-log { padding-inline: 16px; }
  .olevy.is-open .olevy-launcher { display: none; }
  .olevy-turn { max-width: 90%; }
  .olevy-form { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .olevy-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .olevy-panel,
  .olevy.is-closing .olevy-panel { animation: none; }
  .olevy-dot,
  .olevy-typing i { animation: none; }
  .olevy *,
  .olevy-scrim { transition-duration: .01ms !important; }
  .olevy-launcher:hover { transform: none; }
}
