/* ==========================================================================
   PAGE — HOME  (directory/templates/directory/home.html)
   ==========================================================================

   Complemento de legaltica-ds.css (que NO se toca). Aquí solo vive lo que es
   exclusivo del home y no existe como componente del sistema:

     1. Subtítulo de la cabecera centrada
     2. Raíles horizontales de móvil (ciudades y abogados destacados)
     3. Orden del panel "¿Eres abogado?" en móvil
     4. Bloque "Sin letra pequeña" (cifras reales y compromisos con su fuente;
        antes "Por qué confiar", sin testimonios desde 22-10-2026)
     5. Chips del hero como <button>
     6. Modal del wizard de IA repintado con los tokens --lt-*
     7. Bloque "Herramientas gratis" (tarjetas de problema por país)
     8. «Analizar caso» de la cabecera en contorno (un solo rojo por pantalla)

   Desktop-first, un único breakpoint en 768px, igual que el design system.
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. Cabecera centrada (¿Cómo funciona Legaltica?)
   -------------------------------------------------------------------------- */

.home-head-sub {
  margin: 0;
  font-size: 16px;
  color: var(--lt-text-muted);
}


/* --------------------------------------------------------------------------
   2. Raíles (solo móvil; en desktop son grids del sistema)
   -------------------------------------------------------------------------- */

.home-rail::-webkit-scrollbar { display: none; }


/* --------------------------------------------------------------------------
   3. Chips del hero: en producción son <button> (rellenan el textarea),
      no <span> como en el mock-up.
   -------------------------------------------------------------------------- */

button.lt-chip--dark {
  font-family: var(--lt-font-body);
  line-height: 1;
  background: transparent;
}


/* --------------------------------------------------------------------------
   4. Bloque "Sin letra pequeña" (antes "Por qué confiar", 24-10-2026)
      Cabecera centrada, fila de cifras reales (de 0 a 3, según el país) y
      cuatro compromisos con el enlace al texto legal que los respalda.
      Escritorio: 4 compromisos en fila; tableta: 2x2; móvil: uno por fila.
   -------------------------------------------------------------------------- */

.home-trust__head {
  text-align: center;
  margin-bottom: 40px;
}
.home-trust__eyebrow { display: block; color: var(--lt-primary); margin-bottom: 8px; }
.home-trust__h {
  margin: 0 0 var(--lt-s-4) 0;             /* 10px */
  font-family: var(--lt-font-head);
  font-weight: 600;
  font-size: var(--lt-fs-h2-lg);           /* 32px */
  letter-spacing: -0.02em;
  color: var(--lt-ink);
}
.home-trust__sub {
  margin: 0 auto;
  max-width: 52ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--lt-text-muted);
  text-wrap: balance;
}

/* auto-fit: un país puede tener 1, 2 o 3 cifras (las que no llegan a su
   mínimo no se pintan) y siempre se reparten todo el ancho. Tope de ancho
   para que con una sola no quede un número perdido en medio del panel. */
.home-stats {
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: var(--lt-s-10);                     /* 24px */
  max-width: 760px;
  margin: 0 auto 44px auto;
}
.home-stats .lt-stat__label { text-wrap: balance; }
/* La cifra de herramientas es un enlace al hub: se ve igual que las demás,
   y solo al pasar el ratón se nota que se puede pulsar. */
a.home-stat--link { text-decoration: none; border-radius: var(--lt-r-sm); }
a.home-stat--link:hover .lt-stat__label { color: var(--lt-primary); }
a.home-stat--link:focus-visible { outline: 3px solid var(--lt-primary); outline-offset: 4px; }

.home-pledges {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
/* Fondo canvas sobre el panel blanco: separa sin otra línea de borde más. */
.home-pledge {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 20px 20px 20px;
  background: var(--lt-canvas);
  border-radius: var(--lt-r-md);
}
.home-pledge__mark { margin: 2px 0 6px 2px; }
.home-pledge__h {
  margin: 0;
  font-family: var(--lt-font-head);
  font-weight: 600;
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--lt-ink);
}
.home-pledge__p {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--lt-text-2);
}
/* El enlace a la fuente va siempre al pie de la tarjeta, alineado entre
   tarjetas aunque los textos tengan largos distintos. */
a.home-pledge__src {
  margin-top: auto;
  padding-top: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--lt-primary);
  text-decoration: none;
}
a.home-pledge__src:hover { text-decoration: underline; }

.home-trust__note {
  margin: 28px auto 0 auto;
  max-width: 70ch;
  text-align: center;
  font-size: 13px;
  line-height: 1.55;
  color: var(--lt-text-muted);
}

@media (max-width: 1079.98px) {
  .home-pledges { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}


/* --------------------------------------------------------------------------
   5. Modal del wizard de IA — chasis de Bootstrap repintado con tokens lt-*
      (la estructura de pasos/ids no cambia: la usa static/js/ai-wizard.js)
   -------------------------------------------------------------------------- */

#aiWizardModal .modal-content {
  background: var(--lt-surface);
  border: 1px solid var(--lt-border);
  border-radius: var(--lt-r-xl);
  font-family: var(--lt-font-body);
  color: var(--lt-text);
}
#aiWizardModal .modal-header,
#aiWizardModal .modal-footer { padding: var(--lt-s-10) var(--lt-s-11); }
#aiWizardModal .modal-footer { gap: var(--lt-s-4); }

#aiWizardModal .modal-title,
#aiWizardModal h5 {
  font-family: var(--lt-font-head);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--lt-ink);
}
#aiWizardModal .modal-title { font-size: var(--lt-fs-h2-card); }
#aiWizardModal h5 { font-size: var(--lt-fs-h3); }

#aiWizardModal p,
#aiWizardModal .text-muted,
#aiWizardModal .form-text {
  color: var(--lt-text-muted);
  font-size: var(--lt-fs-body);
}
#aiWizardModal .form-text { font-size: var(--lt-fs-xs); }

#aiWizardModal .form-label {
  font-family: var(--lt-font-body);
  font-size: var(--lt-fs-sm);
  font-weight: 700;
  color: var(--lt-ink);
}

#aiWizardModal .form-control {
  background: var(--lt-canvas);
  border: 1px solid var(--lt-border);
  border-radius: var(--lt-r-ctl);
  padding: 12px 14px;
  font-family: var(--lt-font-body);
  font-size: 14px;
  color: var(--lt-ink);
  box-shadow: none;
}
#aiWizardModal .form-control:focus {
  border-color: var(--lt-primary);
  box-shadow: none;
}

/* Barras de progreso (paso del wizard + progreso del análisis) */
#aiWizardModal .progress {
  background: var(--lt-divider);
  border-radius: var(--lt-r-bar);
  overflow: hidden;
}
#aiWizardModal div.progress-bar { background-color: var(--lt-primary); }

/* Cuenta atrás circular (usa currentColor) */
#aiWizardModal .circular-progress { color: var(--lt-primary); }

/* Botón "Anterior": outline neutro sobre superficie clara */
button.lt-btn--ghost-light {
  background: var(--lt-surface);
  border: 1px solid var(--lt-border);
  color: var(--lt-text-muted);
  font-weight: 600;
  border-radius: var(--lt-r-ctl);
  padding: 12px 22px;
  font-size: 14px;
}
button.lt-btn--ghost-light:hover { border-color: var(--lt-primary); color: var(--lt-primary); }
button.lt-btn--ghost-light:disabled { opacity: 0.45; cursor: default; }

/* Chips de fichero seleccionado (los pinta ai-wizard.js con clases de Bootstrap) */
#aiWizardModal .file-preview-list .badge {
  font-family: var(--lt-font-body);
  border-radius: var(--lt-r-pill);
}


/* --------------------------------------------------------------------------
   7. Bloque "Herramientas gratis" (services/home_herramientas.py)
      Toda la tarjeta es el enlace. Escritorio: 4 en fila; tableta: 2x2;
      móvil: una por fila, icono a la izquierda y flecha a la derecha.
      El sprite de iconos lo esconde herramientas-sitio.css, que base.html
      carga siempre que el país tiene herramientas (y si no, no hay bloque).
   -------------------------------------------------------------------------- */

.home-herr__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--lt-s-10);
  margin-bottom: 28px;
}
.home-herr__eyebrow { display: block; color: var(--lt-primary); }
.home-herr__h { margin: 8px 0 8px 0; text-wrap: balance; }
.home-herr__sub {
  margin: 0;
  max-width: 62ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--lt-text-muted);
}
a.home-herr__todas { flex-shrink: 0; white-space: nowrap; }
.home-herr__todas > span { margin-left: .3em; }
a.home-herr__todas--abajo { display: none; }

.home-herr__lista {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.home-herr__lista > li { display: flex; }

a.home-herr__card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  padding: 20px;
  background: var(--lt-surface);
  border: 1px solid var(--lt-border);
  border-radius: var(--lt-r-md);
  color: var(--lt-ink);
  text-decoration: none;
  transition: border-color .15s ease, transform .15s ease;
}
a.home-herr__card:hover { border-color: var(--lt-primary); color: var(--lt-ink); transform: translateY(-1px); }
a.home-herr__card:focus-visible { outline: 3px solid var(--lt-primary); outline-offset: 2px; }

.home-herr__icono {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #FBEDEB;
  color: var(--lt-primary);
}
.home-herr__icono svg { width: 22px; height: 22px; }

.home-herr__cuerpo { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.home-herr__problema {
  font-family: var(--lt-font-head);
  font-weight: 600;
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--lt-ink);
}
.home-herr__accion { font-size: 14px; line-height: 1.45; color: var(--lt-text-2); }
.home-herr__flecha {
  position: absolute;
  top: 29px;                               /* centrada con el icono */
  right: 20px;
  line-height: 1;
  font-weight: 700;
  color: var(--lt-primary);
  transition: transform .15s ease;
}
a.home-herr__card:hover .home-herr__flecha { transform: translateX(3px); }

@media (max-width: 1079.98px) {
  .home-herr__lista { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  a.home-herr__card, .home-herr__flecha { transition: none; }
  a.home-herr__card:hover,
  a.home-herr__card:hover .home-herr__flecha { transform: none; }
}


/* ==========================================================================
   OVERRIDES MÓVILES — max-width: 768px
   ========================================================================== */

@media (max-width: 768px) {

  /* Subtítulo de cabecera */
  .home-head-sub { font-size: 14px; }

  /* El hero móvil es flex-column y `.lt-search { margin: 0 auto }` (design system)
     mete márgenes automáticos en el eje transversal: eso ANULA el stretch y deja
     el buscador a su ancho intrínseco (~200px). Debe ocupar el ancho completo. */
  .lt-hero__inner .lt-search {
    margin: 0;
    width: 100%;
    align-self: stretch;
  }

  /* --- Raíles: la sección pierde el padding lateral y el raíl lo recupera --- */
  .home-section--rail {
    padding-left: 0;
    padding-right: 0;
  }
  .home-section--rail .lt-section-head { padding: 0 var(--lt-gutter); }

  .home-rail {
    display: flex;
    overflow-x: auto;
    padding: 0 var(--lt-gutter) 8px var(--lt-gutter);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .home-rail > * { flex-shrink: 0; }
  .home-rail--cities  { gap: 10px; }
  .home-rail--lawyers { gap: 14px; }

  /* --- Panel "¿Eres abogado?": foto entre el párrafo y los botones --- */
  .lt-panel--split {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }
  .lt-panel--split .lt-panel__body    { display: contents; }
  .lt-panel--split .lt-panel__img     { order: 1; }
  .lt-panel--split .lt-panel__actions { order: 2; margin-top: 6px; }

  /* --- Bloque "Sin letra pequeña" --- */
  .home-trust__head { margin-bottom: 22px; }
  .home-trust__h {
    font-size: var(--lt-fs-h2);            /* 22px */
    margin-bottom: 8px;
  }
  /* El subtítulo se queda: es el que explica el título, que solo no se entiende. */
  .home-trust__sub { font-size: 14px; }

  /* Las tres cifras caben en una fila a 24px; con 2x2 la tercera quedaba sola. */
  .home-stats {
    gap: 10px;
    margin-bottom: 24px;
  }
  .home-stats .lt-stat__num   { font-size: 24px; }
  .home-stats .lt-stat__label { font-size: 12px; line-height: 1.35; }

  .home-pledges { grid-template-columns: 1fr; gap: 10px; }
  .home-pledge { padding: 16px 16px 14px 16px; gap: 6px; }
  .home-pledge__mark { margin-bottom: 2px; }
  .home-pledge__h { font-size: 16px; }
  .home-pledge__p { font-size: 13.5px; }
  a.home-pledge__src {
    display: inline-block;
    min-height: 44px;                      /* objetivo táctil */
    line-height: 44px;
    padding-top: 0;
    margin-bottom: -10px;
  }
  .home-trust__note { margin-top: 20px; font-size: 12.5px; }

  /* --- Herramientas: una tarjeta por fila, en horizontal --- */
  .home-herr__head { display: block; margin-bottom: 16px; }
  .home-herr__h { margin: 6px 0; }
  .home-herr__sub { font-size: 14px; }
  a.home-herr__todas--arriba { display: none; }
  a.home-herr__todas--abajo {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin-top: 6px;
  }
  .home-herr__lista { grid-template-columns: 1fr; gap: 10px; }
  a.home-herr__card {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    min-height: 72px;
    padding: 14px 16px;
  }
  .home-herr__icono { width: 40px; height: 40px; }
  .home-herr__problema { font-size: 16px; }
  .home-herr__accion { font-size: 13.5px; }
  .home-herr__flecha { position: static; margin: 0 0 0 auto; padding-left: 4px; }

  /* --- Modal --- */
  #aiWizardModal .modal-header,
  #aiWizardModal .modal-footer { padding: var(--lt-s-9); }
  #aiWizardModal .modal-footer .lt-btn { flex: 1; }
}


/* --------------------------------------------------------------------------
   HERO: texto rotativo + partículas
   -------------------------------------------------------------------------- */

/* Envoltorio de la palabra + el cursor. El JS le fija el min-width al ancho de
   la palabra más larga (más el cursor), para que el H1 —que está centrado— no
   se recentre en cada pulsación. Al reservar el ancho AQUÍ y no en la palabra,
   el cursor queda siempre pegado a la última letra. */
.home-typed-wrap {
  display: inline-block;
  text-align: left;
  white-space: pre;
}

/* La palabra que se escribe. */
.home-typed {
  white-space: pre;
}

/* Cursor. Va pegado a la palabra, sin el espacio que dejaría un inline-block. */
.home-caret {
  display: inline-block;
  width: 3px;
  height: 0.82em;
  margin-left: 2px;
  vertical-align: baseline;
  background: var(--lt-primary);
  border-radius: 1px;
  animation: home-caret-blink 1s steps(1, end) infinite;
}

@keyframes home-caret-blink {
  0%, 50%   { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* Partículas: capa decorativa detrás del contenido del hero.
   El contenedor no captura clics; el canvas sí, para que funcione el enlazado
   al pasar el ratón por el fondo. No hay riesgo para el buscador: vive en
   .lt-hero__inner (z-index 1), por encima del canvas (z-index 0), así que
   recibe sus propios clics. */
.home-particles {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.home-particles canvas {
  display: block;
  pointer-events: auto;
}

/* El contenido del hero ya es position:relative en el DS; solo hay que
   levantarlo por encima del lienzo de partículas. */
.lt-hero .lt-hero__inner {
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .home-caret { animation: none; opacity: 0; }
}


/* --------------------------------------------------------------------------
   Títulos y enlaces: variante larga (desktop) / corta (móvil)
   --------------------------------------------------------------------------
   El diseño móvil acorta los rótulos ("Busca abogados por especialidad" ->
   "Por especialidad", "Ver más especialidades" -> "Ver más"). Con los largos,
   el título y el enlace se parten en dos líneas cada uno y se atropellan.
   -------------------------------------------------------------------------- */

.home-t-short { display: none; }

@media (max-width: 768px) {
  .home-t-long  { display: none; }
  .home-t-short { display: inline; }

  /* El enlace nunca debe partirse ni encogerse contra el título. */
  .lt-section-head .lt-link-action {
    flex-shrink: 0;
    white-space: nowrap;
  }
}


/* --------------------------------------------------------------------------
   Ajustes finales al diseño móvil
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  /* El diseño móvil enseña 8 tiles de especialidad (2x4), no los 12 de desktop. */
  .home-tiles .lt-tile:nth-child(n + 9) { display: none; }
}


/* ==========================================================================
   COMPOSITOR A PANTALLA COMPLETA (solo móvil)
   ==========================================================================
   Al enfocar el textarea, el buscador del hero se abre a pantalla completa: el
   texto ocupa todo el alto y el botón queda pegado encima del teclado. Con el
   teclado desplegado, una caja de 3 líneas dentro del hero se quedaba sin sitio.

   El alto lo fija home-composer.js desde visualViewport (es lo único que refleja
   el hueco real que deja el teclado; en iOS innerHeight no cambia al abrirse).
   ========================================================================== */

/* La barra superior solo existe en el modo compositor. */
.home-composer__bar { display: none; }

@media (max-width: 768px) {

  .home-composer__bar {
    align-items: center;
    gap: 10px;
    padding: 2px 2px 10px 2px;
    border-bottom: 1px solid var(--lt-divider);
    margin-bottom: 10px;
    flex-shrink: 0;
  }
  .lt-search.is-composing .home-composer__bar { display: flex; }

  button.home-composer__close {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--lt-canvas);
    border: none;
    border-radius: var(--lt-r-ctl-sm);
    color: var(--lt-text-2);
    cursor: pointer;
  }
  button.home-composer__close:hover { color: var(--lt-ink); }

  .home-composer__title {
    flex: 1;
    min-width: 0;
    font-family: var(--lt-font-head);
    font-weight: 600;
    font-size: 15px;
    color: var(--lt-ink);
  }
  .home-composer__count {
    font-size: 12px;
    font-weight: 600;
    color: var(--lt-text-muted);
    flex-shrink: 0;
  }

  /* --- El formulario, a pantalla completa ---------------------------------
     `position: fixed` NO funciona dentro de un elemento con `transform`: se
     posicionaría respecto a él y no respecto a la ventana. Y .lt-search lleva la
     animación `lt-rise`, que deja un transform puesto (`both`). Por eso hay que
     anular animación y transform al entrar en modo compositor. */
  .lt-search.is-composing {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    z-index: 60;                       /* por encima del header (50) */
    margin: 0;
    width: 100%;
    max-width: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--lt-surface);
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom)) 16px;
    display: flex;
    flex-direction: column;
    animation: none;
    transform: none;
    opacity: 1;
  }

  /* El texto se come todo el hueco que sobra. */
  .lt-search.is-composing .lt-search__input {
    flex: 1;
    height: auto;
    min-height: 0;
    max-height: none;
    font-size: 16px;                   /* < 16px y iOS hace zoom al enfocar */
    line-height: 1.5;
    padding: 4px 2px;
    resize: none;
  }

  /* El pie se queda abajo, pegado al teclado. El botón, a ancho completo. */
  .lt-search.is-composing .lt-search__foot {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--lt-divider);
  }
  .lt-search.is-composing .lt-search__hint {
    text-align: center;
    font-size: 12px;
  }
  .lt-search.is-composing .lt-search__foot .lt-btn {
    width: 100%;
    justify-content: center;
    padding: 15px;
    font-size: 15px;
  }

  /* El fondo no debe poder desplazarse detrás del compositor. */
  body.is-composing {
    overflow: hidden;
  }

  /* CRÍTICO: .lt-hero__inner tiene `z-index: 1` (puesto para que el contenido
     quede por encima del lienzo de partículas), y eso crea un CONTEXTO DE
     APILAMIENTO. El z-index:60 del compositor quedaba atrapado dentro de ese
     contexto —cuyo z-index es 1— y el header (z-index 50) se pintaba ENCIMA del
     compositor a pantalla completa. Mientras se escribe, el contexto se
     desactiva; las partículas siguen debajo porque el contenido va después en
     el DOM. */
  body.is-composing .lt-hero__inner {
    z-index: auto;
  }
}


/* --------------------------------------------------------------------------
   8. «Analizar caso» de la cabecera en contorno
   --------------------------------------------------------------------------
   En la portada el botón rojo es el del hero («Analizar mi situación»), que es
   la misma acción: un solo rojo por pantalla. La cabecera es sticky, así que el
   contorno sigue a mano al bajar. Mismo selector y mismos valores que en las
   herramientas (herramientas.css, spec A12.3); en móvil el CTA ya está oculto. */
a.lt-btn--primary.lt-header__cta, a.lt-btn--primary.lt-header__cta:hover {
  background: transparent; color: var(--lt-primary, #C54343); box-shadow: inset 0 0 0 1.5px var(--lt-primary, #C54343);
}
