/* ==========================================================================
   Demo viva "site-builder" (hero de /pagina-web): Ana LL arma una página web
   en el Constructor de Página y la vista previa se llena en vivo.
   Markup: resources/views/web/partials/anim/site-builder.blade.php
   Estados en la raíz:
     data-chat     chat IA abierto sobre el constructor
     data-focus    caja de mensaje enfocada
     data-mods     ya hay al menos un módulo (oculta "Aún no hay módulos" y el esqueleto)
     data-palette  forest | logo   (forest = verde inicial; logo = azul y blanco del logotipo)
     data-cursor   puntero visible
   Clase .is-on: mensajes del chat, módulos del constructor y secciones de la página.
   Pasos del plan: .is-run / .is-done.
   ========================================================================== */

/* ---------- Paleta: modo claro ---------- */
.lla-site-builder {
  --lla-bg: #ffffff;
  --lla-surface: #f8f9fa;
  --lla-surface-2: #eef1f5;
  --lla-text: #1e2022;
  --lla-text-2: #3d4554;
  --lla-muted: #5b6676;
  --lla-border: #e1e6ee;
  --lla-border-2: #d0d7e2;
  --lla-shadow: 0 32px 64px -24px rgba(22, 34, 58, .38), 0 10px 24px -10px rgba(22, 34, 58, .18);
  --lla-shadow-sm: 0 1px 3px rgba(22, 34, 58, .10), 0 1px 2px rgba(22, 34, 58, .06);
  --lla-glow-a: rgba(32, 134, 253, .18);
  --lla-glow-b: rgba(109, 40, 217, .13);
  --lla-dot-r: #ff5f57;
  --lla-dot-y: #febc2e;
  --lla-dot-g: #28c840;
  --lla-success: #198754;
  --lla-warning: #f5a623;
  --lla-cursor-fill: #1e2022;
  --lla-cursor-edge: #ffffff;
  --lla-cursor-ring: rgba(32, 134, 253, .55);

  /* Panel (tema Front del panel company) */
  --lla-panel: #377dff;
  --lla-panel-soft: #e6eeff;
  --lla-on-panel: #ffffff;

  /* Persona Ana LL (AiPersona: color #6D28D9) */
  --lla-ana: #6d28d9;

  /* Página de ejemplo: paleta "Bosque" de ll-design.vue (primer armado, en verde) */
  --lla-p: #2d6a4f;
  --lla-s: #52b788;
  --lla-t: #40916c;
  --lla-ptext: #1b4332;
  --lla-pbg: #e1f5e9;
  --lla-hero-bg: #d3efde;
  --lla-hero-fg: #1b4332;
}

/* Colores del logotipo (Clínica Central Americana): botones azules y fondo blanco.
   Azul marino #013688, azul medio #026cd4 y azul claro #57adfb salen del logo. */
.lla-site-builder[data-palette="logo"] {
  --lla-p: #013688;
  --lla-s: #57adfb;
  --lla-t: #026cd4;
  --lla-ptext: #002246;
  --lla-pbg: #ffffff;
  --lla-hero-bg: #ffffff;
  --lla-hero-fg: #002246;
}

/* ---------- Sitio en modo oscuro: solo lo que está FUERA de las ventanas ----------
   El panel y las páginas (plantilla 4) no tienen modo oscuro: las ventanas se quedan en claro. */
html[data-theme="dark"] .lla-site-builder {
  --lla-glow-a: rgba(77, 159, 255, .16);
  --lla-glow-b: rgba(167, 139, 250, .14);
  --lla-shadow: 0 32px 64px -24px rgba(0, 0, 0, .75), 0 10px 24px -10px rgba(0, 0, 0, .5);
}

/* ---------- Escena ---------- */
.lla-site-builder {
  max-width: 680px;
  margin-inline: auto;
  color: var(--lla-text);
  line-height: 1.3;
  text-align: left;
}

.lla .lla-site-builder__stage {
  --lla-w: 680;
  --lla-h: 470;
}

.lla-site-builder :where(b, small, strong, p) {
  margin: 0;
  font-size: inherit;
  color: inherit;
}

.lla-site-builder .bi::before { vertical-align: 0; }

.lla-site-builder__glow { position: absolute; border-radius: 50%; pointer-events: none; }
.lla-site-builder__glow--a { left: -30px; top: 0; width: 420px; height: 420px; background: radial-gradient(closest-side, var(--lla-glow-a), transparent); }
.lla-site-builder__glow--b { left: 300px; top: 110px; width: 400px; height: 400px; background: radial-gradient(closest-side, var(--lla-glow-b), transparent); }

/* ---------- Ventanas ---------- */
.lla-site-builder__win {
  position: absolute;
  overflow: hidden;
  border: 1px solid var(--lla-border);
  border-radius: 14px;
  background: var(--lla-bg);
  box-shadow: var(--lla-shadow);
}

.lla-site-builder__win--panel { left: 0; top: 6px; width: 440px; height: 458px; }
.lla-site-builder__win--site { left: 372px; top: 36px; width: 304px; height: 428px; z-index: 2; }

.lla-site-builder__chrome {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 12px;
  border-bottom: 1px solid var(--lla-border);
  background: var(--lla-surface);
}

.lla-site-builder__dots { display: flex; flex: none; gap: 5px; }
.lla-site-builder__dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--lla-dot-r); }
.lla-site-builder__dots i:nth-child(2) { background: var(--lla-dot-y); }
.lla-site-builder__dots i:nth-child(3) { background: var(--lla-dot-g); }

.lla-site-builder__url {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--lla-bg);
  font-size: 10.5px;
  color: var(--lla-muted);
  white-space: nowrap;
}
.lla-site-builder__url > span { overflow: hidden; text-overflow: ellipsis; }
.lla-site-builder__url .bi { flex: none; font-size: 8.5px; color: var(--lla-success); }

/* ---------- Constructor (ll-page-builder) ----------
   El lado derecho queda tapado por la vista previa: el contenido llega hasta 360px. */
.lla-site-builder__body {
  height: calc(100% - 32px);
  padding: 16px 94px 16px 18px;
  background: var(--lla-surface);
  font-size: 12px;
}

.lla-site-builder__h { display: block; font-size: 17px; font-weight: 600; color: var(--lla-text); }

.lla-site-builder__actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 16px; }

.lla-site-builder__btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--lla-panel);
  border-radius: 6px;
  background: var(--lla-panel);
  color: var(--lla-on-panel);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .15s var(--lla-ease), background-color .2s var(--lla-ease), color .2s var(--lla-ease);
}
.lla-site-builder__btn--outline { background: var(--lla-bg); color: var(--lla-panel); }
.lla-site-builder__btn.is-pressed { transform: scale(.95); background: var(--lla-panel); color: var(--lla-on-panel); }

.lla-site-builder__label {
  display: block;
  margin: 0 0 6px;
  font-size: 9.5px !important;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--lla-muted) !important;
}
.lla-site-builder__label--line { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.lla-site-builder__label--line::after { content: ''; flex: 1; border-top: 1px solid var(--lla-border-2); }

.lla-site-builder__list { display: flex; flex-direction: column; gap: 6px; }

.lla-site-builder__empty {
  padding: 16px 12px;
  border: 1px dashed var(--lla-border-2);
  border-radius: 8px;
  color: var(--lla-muted);
  text-align: center;
  font-size: 11px;
}
.lla-site-builder[data-mods] .lla-site-builder__empty { display: none; }

.lla-site-builder__mod {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--lla-border);
  border-radius: 8px;
  background: var(--lla-bg);
  box-shadow: var(--lla-shadow-sm);
}
.lla-site-builder__list .lla-site-builder__mod { display: none; }
.lla-site-builder__list .lla-site-builder__mod.is-on { display: flex; animation: lla-sib-in .45s var(--lla-ease) both; }

.lla-site-builder__grip { flex: none; color: var(--lla-muted); font-size: 13px; }
.lla-site-builder__mod-info { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.lla-site-builder__mod-info b { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; }
.lla-site-builder__mod-info small { margin-top: 1px; padding-left: 19px; color: var(--lla-muted); font-size: 10.5px; }
.lla-site-builder__mod-edit { flex: none; color: var(--lla-muted); font-size: 11px; }

.lla-site-builder__switch {
  position: relative;
  flex: none;
  width: 26px;
  height: 15px;
  border-radius: 999px;
  background: var(--lla-panel);
}
.lla-site-builder__switch::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
}

/* ---------- Chat IA (ll-ai-chat-panel) ---------- */
.lla-site-builder__chat {
  position: absolute;
  top: 32px;
  bottom: 0;
  left: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 368px;
  padding: 12px 14px 8px;
  border-right: 1px solid var(--lla-border);
  background: var(--lla-bg);
  box-shadow: 12px 0 32px -16px rgba(22, 34, 58, .35);
  font-size: 11.5px;
  transform: translateX(-104%);
  transition: transform .5s var(--lla-ease);
}
.lla-site-builder[data-chat] .lla-site-builder__chat { transform: none; }

.lla-site-builder__chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--lla-border);
}
.lla-site-builder__persona { display: flex; flex: 1; flex-direction: column; line-height: 1.25; }
.lla-site-builder__persona b { font-size: 12.5px; font-weight: 600; }
.lla-site-builder__persona small { color: var(--lla-muted); font-size: 10.5px; }
.lla-site-builder__close { color: var(--lla-muted); font-size: 18px; line-height: 1; }

.lla-site-builder__avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--lla-ana);
  color: #fff;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
}
.lla-site-builder__avatar--sm { width: 22px; height: 22px; margin-top: 1px; font-size: 8.5px; }

.lla-site-builder__credits {
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--lla-border);
  color: var(--lla-muted);
  font-size: 10.5px;
}
.lla-site-builder__credits .bi { margin-right: 4px; color: var(--lla-warning); }
.lla-site-builder__credits b { color: var(--lla-text); font-weight: 700; }

/* Los mensajes se apilan desde abajo: lo viejo sale por arriba (como el scroll automático del chat real). */
.lla-site-builder__msgs {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
  padding: 6px 0 8px;
}

.lla-site-builder__welcome { padding: 6px 4px 10px; color: var(--lla-muted); text-align: center; font-size: 11px; }
.lla-site-builder__welcome b { color: var(--lla-text); }
.lla-site-builder__welcome p { margin-bottom: 10px; }
.lla-site-builder[data-started] .lla-site-builder__welcome { display: none; }

.lla-site-builder__starters { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.lla-site-builder__starters span {
  padding: 4px 8px;
  border: 1px solid var(--lla-panel);
  border-radius: 6px;
  color: var(--lla-panel);
  font-size: 10.5px;
  font-weight: 600;
}

.lla-site-builder__msg {
  display: none;
  align-self: flex-start;
  max-width: 85%;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--lla-surface-2);
  color: var(--lla-text);
}
.lla-site-builder__msg.is-on { display: flex; align-items: center; gap: 6px; animation: lla-sib-in .35s var(--lla-ease) both; }
.lla-site-builder__msg .lla-spinner { width: 11px; height: 11px; color: var(--lla-panel); }

.lla-site-builder__msg--user { align-self: flex-end; background: var(--lla-panel); color: var(--lla-on-panel); }

.lla-site-builder__msg--ai { align-items: flex-start !important; padding: 0; background: none; }
.lla-site-builder__msg--ai > span { padding: 6px 10px; border-radius: 10px; background: var(--lla-surface-2); }

/* Tarjeta "Construyendo tu portada" */
.lla-site-builder__job {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 9px 12px;
  border: 1px solid var(--lla-border);
  border-radius: 10px;
  background: var(--lla-bg);
  font-size: 11px;
}
.lla-site-builder__job.is-on { display: flex; animation: lla-sib-in .35s var(--lla-ease) both; }

.lla-site-builder__job-title { display: flex; align-items: center; gap: 6px; margin-bottom: 2px !important; font-weight: 600; }
.lla-site-builder__job-title .bi { color: var(--lla-panel); }
.lla-site-builder__job-done { display: none; }
.lla-site-builder__job.is-done .lla-site-builder__job-run { display: none; }
.lla-site-builder__job.is-done .lla-site-builder__job-done { display: inline; color: var(--lla-success); }

.lla-site-builder__step { display: flex; align-items: center; gap: 8px; color: var(--lla-muted); }
.lla-site-builder__step.is-run,
.lla-site-builder__step.is-done { color: var(--lla-text); }

.lla-site-builder__step-ico { display: inline-flex; flex: none; justify-content: center; width: 14px; }
.lla-site-builder__step-ico > * { display: none; }
.lla-site-builder__step-ico .bi-circle { display: inline; font-size: 10px; }
.lla .lla-site-builder__step-ico .lla-spinner { display: none; width: 11px; height: 11px; color: var(--lla-panel); }
.lla-site-builder__step-ico .bi-check-lg { color: var(--lla-success); font-size: 13px; }
.lla-site-builder__step.is-run .bi-circle,
.lla-site-builder__step.is-done .bi-circle { display: none; }
.lla .lla-site-builder__step.is-run .lla-spinner { display: inline-block; }
.lla-site-builder__step.is-done .bi-check-lg { display: inline; animation: lla-sib-pop .3s var(--lla-ease) both; }

/* Caja de mensaje */
.lla-site-builder__compose { display: flex; gap: 6px; padding-top: 8px; border-top: 1px solid var(--lla-border); }

.lla-site-builder__input {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  overflow: hidden;
  border: 1px solid var(--lla-border-2);
  border-radius: 6px;
  white-space: nowrap;
  transition: border-color .2s var(--lla-ease), box-shadow .2s var(--lla-ease);
}
.lla-site-builder[data-focus] .lla-site-builder__input { border-color: var(--lla-panel); box-shadow: 0 0 0 3px var(--lla-panel-soft); }

.lla-site-builder__ph { position: absolute; left: 10px; color: var(--lla-muted); }
.lla-site-builder__typed:not(:empty) + .lla-site-builder__ph { display: none; }
/* El texto largo se recorre a la izquierda desde JS (scrollLeft), como un input que sigue al cursor. */
.lla-site-builder__typed { flex: none; }

.lla-site-builder__send {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  border-radius: 6px;
  background: var(--lla-panel);
  color: var(--lla-on-panel);
  font-size: 12px;
  transition: transform .15s var(--lla-ease);
}
.lla-site-builder__send.is-pressed { transform: scale(.9); }

.lla-site-builder__disclaimer { display: block; margin-top: 5px !important; color: var(--lla-muted) !important; text-align: center; font-size: 8.5px !important; line-height: 1.3; }

/* ---------- Vista previa: la página (plantilla 4) ---------- */
.lla-site-builder__vp {
  position: relative;
  height: calc(100% - 32px);
  overflow: hidden;
  background: var(--lla-pbg);
  transition: background-color .6s var(--lla-ease), opacity .4s var(--lla-ease);
}

.lla-site-builder__page {
  position: relative;
  color: var(--lla-ptext);
  transition: transform .7s var(--lla-ease), color .6s var(--lla-ease);
  will-change: transform;
}

.lla-site-builder__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--lla-border);
  font-size: 15px;
}
.lla-site-builder__nav .lla-site-builder__logo { display: block; width: auto; height: 21px; }
.lla-site-builder__nav .bi { font-size: 18px; color: var(--lla-ptext); }

.lla-site-builder__skeleton { display: flex; flex-direction: column; gap: 10px; padding: 22px 18px; }
.lla-site-builder__skeleton span { height: 70px; border-radius: 10px; background: var(--lla-surface-2); animation: lla-sib-pulse 1.6s ease-in-out infinite; }
.lla-site-builder__skeleton span:nth-child(2) { width: 70%; height: 14px; }
.lla-site-builder__skeleton span:nth-child(3) { height: 110px; }
.lla-site-builder[data-mods] .lla-site-builder__skeleton { display: none; }

.lla-site-builder__sec { display: none; padding: 18px; font-size: 11px; }
.lla-site-builder__sec.is-on { display: block; animation: lla-sib-grow .6s var(--lla-ease) both; }

.lla-site-builder__sec-title { display: block; margin-bottom: 8px !important; color: var(--lla-p) !important; font-size: 14px !important; font-weight: 700; transition: color .6s var(--lla-ease); }

/* Hero: banner de la clínica arriba y, debajo, la banda con el mensaje y el botón.
   La banda arranca en verde y pasa a blanco con los colores del logotipo. */
.lla-site-builder__hero {
  padding: 0;
  background: none;
  color: var(--lla-hero-fg);
}
.lla-site-builder__banner { display: block; }
.lla-site-builder__banner img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 1;
  object-fit: cover;
}
.lla-site-builder__hero-body {
  display: block;
  padding: 16px 18px 20px;
  background: var(--lla-hero-bg);
  transition: background-color .6s var(--lla-ease), color .6s var(--lla-ease);
}
.lla-site-builder__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--lla-p);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  transition: color .6s var(--lla-ease);
}
.lla-site-builder__eyebrow img { display: block; width: 14px; height: 14px; }
.lla-site-builder__hero b { display: block; font-size: 17px; font-weight: 800; line-height: 1.2; }
.lla-site-builder__hero small { display: block; margin: 8px 0 14px; opacity: .9; }

.lla-site-builder__cta {
  display: inline-block;
  padding: 7px 16px;
  border-radius: 6px;
  background: var(--lla-p);
  color: #fff;
  font-weight: 700;
  transition: background-color .6s var(--lla-ease);
}

.lla-site-builder__text small { display: block; line-height: 1.5; color: var(--lla-ptext); opacity: .85; }

.lla-site-builder__gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.lla-site-builder__gallery span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 78px;
  overflow: hidden;
  border: 2px solid var(--lla-s);
  border-radius: 8px;
  background-color: var(--lla-s);
  transition: background-color .6s var(--lla-ease), border-color .6s var(--lla-ease);
}
.lla-site-builder__gallery img { display: block; width: 100%; height: 100%; object-fit: cover; }

.lla-site-builder__contact small { display: flex; align-items: center; gap: 6px; margin-bottom: 6px !important; }
.lla-site-builder__contact small .bi { color: var(--lla-p); transition: color .6s var(--lla-ease); }

.lla-site-builder__wa {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--lla-p);
  color: #fff;
  font-weight: 700;
  transition: background-color .6s var(--lla-ease);
}

/* ---------- Puntero ---------- */
.lla-site-builder__cursor {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  width: 22px;
  height: 22px;
  pointer-events: none;
  opacity: 0;
  transform: translate(200px, 420px);
  transition: transform .6s var(--lla-ease), opacity .3s var(--lla-ease);
  will-change: transform, opacity;
}
.lla-site-builder[data-cursor] .lla-site-builder__cursor { opacity: 1; }

.lla-site-builder__cursor svg {
  position: relative;
  display: block;
  width: 22px;
  height: 22px;
  fill: var(--lla-cursor-fill);
  stroke: var(--lla-cursor-edge);
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.lla-site-builder__cursor-ring {
  position: absolute;
  left: -10px;
  top: -12px;
  width: 28px;
  height: 28px;
  border: 2px solid var(--lla-cursor-ring);
  border-radius: 50%;
  opacity: 0;
}

.lla-site-builder__cursor.is-tap svg { animation: lla-sib-press .3s var(--lla-ease); }
.lla-site-builder__cursor.is-tap .lla-site-builder__cursor-ring { animation: lla-sib-ripple .5s var(--lla-ease); }

/* ---------- Celular: lienzo angosto, constructor arriba y vista previa abajo (sin encimarse) ---------- */
@container (max-width: 479px) {
  .lla .lla-site-builder__stage { --lla-w: 400; --lla-h: 620; }

  .lla-site-builder__win--panel { top: 0; width: 400px; height: 350px; }
  .lla-site-builder__win--site { left: 22px; top: 362px; width: 356px; height: 256px; }

  .lla-site-builder__body { padding: 14px 16px; }
  /* Sin "Elementos globales" para que quepan los 4 módulos */
  .lla-site-builder__body > .lla-site-builder__label:not(.lla-site-builder__label--line),
  .lla-site-builder__mod--global { display: none; }
  .lla-site-builder__label--line { margin-top: 0; }
  .lla-site-builder__actions { margin: 8px 0 12px; }
  .lla-site-builder__mod { min-height: 38px; padding: 5px 10px; }
  .lla-site-builder__list { gap: 5px; }

  .lla-site-builder__chat { width: 100%; border-right: 0; box-shadow: none; }

  .lla-site-builder__glow--a { left: -60px; top: 40px; }
  .lla-site-builder__glow--b { left: 40px; top: 300px; }
}

/* ---------- Keyframes ---------- */
@keyframes lla-sib-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes lla-sib-grow {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}
@keyframes lla-sib-pop {
  0% { transform: scale(.4); }
  70% { transform: scale(1.2); }
  100% { transform: none; }
}
@keyframes lla-sib-pulse { 50% { opacity: .55; } }
@keyframes lla-sib-press { 50% { transform: scale(.85); } }
@keyframes lla-sib-ripple {
  0% { opacity: .9; transform: scale(.4); }
  100% { opacity: 0; transform: scale(1.4); }
}
