/* ===================================================================
   Lex — Asistente legal IA Exa Jurídico
   Bot conversacional con form-first lead capture
   - FAB abajo-izquierda (libera la derecha para WhatsApp)
   - Panel chat 380x560 con mini-form siempre visible
   - Paleta heredada de exajuridico.com (#215D81 / #1B9AAA / #1C3B5A)
   =================================================================== */

:root {
  --lex-primary: #215D81;
  --lex-secondary: #1C3B5A;
  --lex-teal: #1B9AAA;
  --lex-bg: #FFFFFF;
  --lex-bg-soft: #F5F8FB;
  --lex-bg-alt: #E3EDF9;
  --lex-ink: #161616;
  --lex-ink-soft: #4D5A66;
  --lex-ink-dim: #67B2B7;
  --lex-line: #CAD2DA;
  --lex-coral: #FFBC7D;
}

/* --------------------- FAB (botón flotante) --------------------- */
.lex-fab {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--lex-primary);
  color: #fff !important;
  padding: 12px 18px 12px 12px;
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(28, 59, 90, 0.35), 0 4px 8px rgba(0, 0, 0, 0.12);
  text-decoration: none !important;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  border: none;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.lex-fab:hover, .lex-fab:focus-visible {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 14px 32px rgba(28, 59, 90, 0.45), 0 6px 12px rgba(0, 0, 0, 0.18);
  background: var(--lex-secondary);
  outline: none;
}
.lex-fab__avatar {
  width: 40px; height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--lex-teal), var(--lex-primary));
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: visible;
}
.lex-fab__avatar svg { width: 30px; height: 30px; display: block; }
.lex-fab__avatar::after {
  content: '';
  position: absolute;
  right: -2px; bottom: -2px;
  width: 12px; height: 12px;
  background: #2BD980;
  border: 2px solid var(--lex-primary);
  border-radius: 50%;
}
.lex-fab__label { white-space: nowrap; }
.lex-fab__pulse {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 2px solid var(--lex-primary);
  animation: lex-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes lex-pulse {
  0%   { transform: scale(1);   opacity: .55; }
  100% { transform: scale(1.4); opacity: 0;   }
}

/* Tooltip de bienvenida */
.lex-fab__tip {
  position: absolute;
  left: calc(100% + 14px);
  bottom: 8px;
  background: #fff;
  color: var(--lex-ink);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(28, 59, 90, 0.18);
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.lex-fab__tip::before {
  content: '';
  position: absolute;
  left: -6px; bottom: 14px;
  width: 12px; height: 12px;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: -2px 2px 4px rgba(28, 59, 90, 0.06);
}
.lex-fab.is-tip-on .lex-fab__tip { opacity: 1; transform: translateX(0); }

/* --------------------- Panel chat ------------------------------- */
.lex-panel {
  position: fixed;
  left: 20px;
  bottom: 90px;
  z-index: 9999;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--lex-bg);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(28, 59, 90, 0.28), 0 8px 16px rgba(0, 0, 0, 0.08);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--lex-ink);
  border: 1px solid var(--lex-line);
}
.lex-panel.is-open { display: flex; animation: lex-pop .22s ease-out; }
@keyframes lex-pop {
  from { transform: translateY(12px) scale(.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* Header */
.lex-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--lex-secondary), var(--lex-primary));
  color: #fff;
}
.lex-head__avatar {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--lex-teal), rgba(255,255,255,0.18));
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: visible;
}
.lex-head__avatar svg { width: 32px; height: 32px; display: block; }
.lex-head__avatar::after {
  content: '';
  position: absolute;
  right: -1px; bottom: -1px;
  width: 12px; height: 12px;
  background: #2BD980;
  border: 2px solid var(--lex-secondary);
  border-radius: 50%;
}
.lex-head__title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 18px;
  font-weight: 400;
  margin: 0; line-height: 1.1;
}
.lex-head__sub {
  font-size: 11px;
  opacity: .85;
  margin: 2px 0 0;
  letter-spacing: 0.04em;
}
.lex-head__close {
  margin-left: auto;
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lex-head__close:hover { background: rgba(255,255,255,0.22); }

/* Disclaimer permanente bajo el header */
.lex-disclaimer {
  background: #FFF6E5;
  color: #6B4914;
  border-bottom: 1px solid #F4DDA8;
  padding: 9px 14px 9px 36px;
  font-size: 11.5px;
  line-height: 1.45;
  position: relative;
}
.lex-disclaimer::before {
  content: '⚖️';
  font-size: 14px;
  position: absolute;
  left: 12px;
  top: 8px;
}
.lex-disclaimer strong { color: var(--lex-secondary); font-weight: 600; }

/* Tótem hero (mascota grande al primer mensaje) */
.lex-totem {
  align-self: center;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  padding: 8px 0 4px;
  margin-bottom: 2px;
  animation: lex-totem-in .45s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes lex-totem-in {
  from { opacity: 0; transform: scale(.7); }
  to   { opacity: 1; transform: scale(1);  }
}
.lex-totem__avatar {
  position: relative;
  width: 96px; height: 96px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--lex-secondary) 0%, var(--lex-primary) 60%, var(--lex-teal) 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 14px 36px rgba(28, 59, 90, 0.32);
  margin-bottom: 10px;
}
.lex-totem__avatar svg { width: 82px; height: 82px; display: block; }
.lex-totem__avatar::before, .lex-totem__avatar::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(33, 93, 129, 0.35);
  animation: lex-ring 2.6s ease-out infinite;
  pointer-events: none;
}
.lex-totem__avatar::after { animation-delay: 1.3s; }
@keyframes lex-ring {
  0%   { transform: scale(.85); opacity: .7; }
  100% { transform: scale(1.4);  opacity: 0;   }
}
.lex-totem__greet {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 20px;
  color: var(--lex-secondary);
  margin: 4px 0 2px;
  line-height: 1.15;
}
.lex-totem__greet em { color: var(--lex-teal); font-style: italic; }
.lex-totem__sub {
  font-size: 12px;
  color: var(--lex-ink-soft);
  margin: 0 0 8px;
  max-width: 280px;
  line-height: 1.45;
}
.lex-totem__feats {
  list-style: none; padding: 0; margin: 6px 0 0;
  width: 100%; max-width: 300px;
  display: flex; flex-direction: column; gap: 6px;
}
.lex-totem__feats li {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--lex-line);
  padding: 8px 11px; border-radius: 10px;
  font-size: 12.5px; color: var(--lex-ink);
  text-align: left;
}
.lex-totem__feats .tick {
  flex: 0 0 18px; width: 18px; height: 18px;
  border-radius: 50%;
  background: rgba(27, 154, 170, 0.15);
  color: var(--lex-teal);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}

/* Mensajes */
.lex-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  background: var(--lex-bg-soft);
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.lex-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}
.lex-msg.is-bot {
  align-self: flex-start;
  background: #fff;
  color: var(--lex-ink);
  border: 1px solid var(--lex-line);
  border-bottom-left-radius: 4px;
}
.lex-msg.is-user {
  align-self: flex-end;
  background: var(--lex-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.lex-msg b, .lex-msg strong { font-weight: 600; }
.lex-msg a { color: var(--lex-teal); text-decoration: underline; }
.lex-msg.is-user a { color: #fff; }

/* Quick replies */
.lex-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 4px 0 8px;
  align-self: flex-start;
}
.lex-chip {
  background: #fff;
  border: 1px solid var(--lex-primary);
  color: var(--lex-primary);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.lex-chip:hover { background: var(--lex-primary); color: #fff; }

/* Typing indicator */
.lex-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--lex-line);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex; gap: 4px;
}
.lex-typing span {
  width: 7px; height: 7px;
  background: var(--lex-ink-dim);
  border-radius: 50%;
  animation: lex-blink 1.2s infinite;
}
.lex-typing span:nth-child(2) { animation-delay: .15s; }
.lex-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes lex-blink {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1; transform: translateY(-3px); }
}

/* Banner permanente: form-first */
.lex-leadbar {
  padding: 12px 14px 6px;
  background: var(--lex-bg-alt);
  border-top: 1px solid var(--lex-line);
  font-size: 12px;
  color: var(--lex-secondary);
  text-align: center;
  font-weight: 500;
  display: flex; align-items: center; gap: 8px; justify-content: center;
}
.lex-leadbar::before {
  content: '⚡';
  font-size: 14px;
}

/* Input */
.lex-input {
  display: flex; gap: 8px;
  padding: 10px 14px 12px;
  background: var(--lex-bg-alt);
  border-top: 1px solid var(--lex-line);
}
.lex-input textarea {
  flex: 1;
  border: 1px solid var(--lex-line);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  resize: none;
  background: #fff;
  color: var(--lex-ink);
  max-height: 90px;
  min-height: 38px;
  line-height: 1.4;
  transition: border-color .15s;
}
.lex-input textarea:focus { outline: none; border-color: var(--lex-primary); }
.lex-input button {
  background: var(--lex-primary);
  color: #fff;
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 40px;
  transition: background .15s, transform .1s;
}
.lex-input button:hover { background: var(--lex-secondary); }
.lex-input button:active { transform: scale(.94); }
.lex-input button:disabled { background: var(--lex-line); cursor: not-allowed; }

/* Mini-form embebido (siempre visible al final del chat) */
.lex-form {
  align-self: stretch;
  background: #fff;
  border: 1px solid var(--lex-primary);
  border-radius: 14px;
  padding: 14px;
  margin-top: 4px;
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 4px 14px rgba(28, 59, 90, 0.08);
}
.lex-form__title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: 17px;
  color: var(--lex-primary);
  margin: 0 0 4px;
  line-height: 1.2;
}
.lex-form__sub {
  font-size: 12px;
  color: var(--lex-ink-soft);
  margin: 0 0 6px;
  line-height: 1.4;
}
.lex-form input {
  width: 100%;
  border: 1px solid var(--lex-line);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--lex-ink);
  background: #fff;
  transition: border-color .15s;
}
.lex-form input:focus { outline: none; border-color: var(--lex-primary); }
.lex-form input.has-error { border-color: #D7263D; }
.lex-form__row { display: flex; gap: 6px; }
.lex-form__row > * { flex: 1; }
.lex-form__rgpd {
  font-size: 10.5px;
  color: var(--lex-ink-soft);
  line-height: 1.4;
  display: flex; gap: 6px; align-items: flex-start;
}
.lex-form__rgpd input { width: auto; flex: 0 0 auto; margin-top: 2px; }
.lex-form__rgpd a { color: var(--lex-teal); }
.lex-form__btn {
  background: var(--lex-primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 11px 16px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  margin-top: 2px;
}
.lex-form__btn:hover { background: var(--lex-secondary); }
.lex-form__btn:active { transform: scale(.98); }
.lex-form__btn:disabled { background: var(--lex-line); cursor: progress; }
.lex-form__ok {
  background: #E8F8EE;
  border: 1px solid #2BD980;
  color: #0E6B33;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}
.lex-form__ok strong { color: #094D24; }

/* Mobile */
@media (max-width: 480px) {
  .lex-fab { left: 12px; bottom: 12px; padding: 10px 14px 10px 10px; font-size: 13px; }
  .lex-fab__avatar { width: 32px; height: 32px; flex-basis: 32px; font-size: 17px; }
  .lex-fab__label { display: none; }
  .lex-fab__tip  { display: none; }
  .lex-panel {
    left: 8px; right: 8px;
    bottom: 78px;
    width: auto;
    max-width: none;
    height: calc(100vh - 100px);
  }
}

/* Si el usuario prefiere reducir movimiento */
@media (prefers-reduced-motion: reduce) {
  .lex-fab__pulse, .lex-typing span { animation: none; }
  .lex-panel.is-open { animation: none; }
}
