/* Alma · asistente de Flooty — mismos colores que la web */
:root {
  --alma-crema: #f5f1e6;
  --alma-papel: #fffcf4;
  --alma-verde: #3f9a25;
  --alma-verde-2: #226a15;
  --alma-verde-suave: #CBDDB5;
  --alma-verde-hielo: #F7FEEF;
  --alma-verde-profundo: #2c7f1c;
  --alma-texto: #222;
  --alma-gris: #6b6f66;
  --alma-borde: rgba(0, 0, 0, .08);
  --alma-sombra: 0 10px 30px rgba(0, 0, 0, .10);
  --alma-ambar: #e8a93a;
  --alma-azul: #4d8fd6;
  --alma-estado: var(--alma-gris);
  --alma-grad: var(--flooty-grad, linear-gradient(135deg, #4caf2c 0%, #2c7f1c 100%));
  --alma-grad-hover: var(--flooty-grad-hover, linear-gradient(135deg, #43a126 0%, #226a15 100%));
  --alma-boton-sombra: var(--flooty-sombra, 0 6px 16px rgba(44, 127, 28, .28));
}

.alma, .alma *, .alma *::before, .alma *::after { box-sizing: border-box; }
.alma-body { margin: 0; background: var(--alma-crema); color: var(--alma-texto); font-family: Arial, Helvetica, sans-serif; min-height: 100vh; display: flex; flex-direction: column; }

.alma {
  width: 100%; max-width: 1240px; margin: 28px auto 40px; padding: 0 18px; flex: 1;
  display: grid; grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); gap: 24px; align-items: start;
}
.alma[data-state="listening"] { --alma-estado: var(--alma-verde); }
.alma[data-state="thinking"], .alma[data-state="connecting"], .alma[data-state="searching"] { --alma-estado: var(--alma-ambar); }
.alma[data-state="speaking"] { --alma-estado: var(--alma-azul); }

/* ── Columna de Alma ─────────────────────── */
.alma-col-avatar { position: sticky; top: 112px; display: flex; flex-direction: column; gap: 12px; }

.alma-stage {
  position: relative; width: 100%; height: clamp(260px, calc(100vh - 330px), 520px); border-radius: 22px; overflow: hidden; isolation: isolate;
  background: #e9e4d6; box-shadow: var(--alma-sombra); border: 1px solid var(--alma-borde);
}
.alma-stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--alma-estado) 70%, transparent);
  opacity: 0; transition: opacity .3s, box-shadow .3s;
}
.alma:not([data-state="idle"]) .alma-stage::after { opacity: 1; }

.alma-poster, .alma-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 25%; }
.alma-poster { animation: alma-respira 9s ease-in-out infinite alternate; transition: opacity .8s, filter .5s; }
.alma-video { opacity: 0; transition: opacity .8s; }
.alma-stage.en-vivo .alma-video { opacity: 1; }
.alma-stage.en-vivo .alma-poster { opacity: 0; animation: none; }
.alma-stage.conectando .alma-poster { filter: brightness(.85); }

.alma-cargando { position: absolute; left: 50%; top: 50%; translate: -50% -50%; z-index: 2; display: none; gap: 7px; padding: 12px 16px; border-radius: 999px; background: rgba(0,0,0,.45); backdrop-filter: blur(6px); }
.alma-stage.conectando .alma-cargando { display: flex; }
.alma-cargando span { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: alma-punto 1.1s infinite; }
.alma-cargando span:nth-child(2) { animation-delay: .15s; }
.alma-cargando span:nth-child(3) { animation-delay: .3s; }

.alma-pill {
  position: absolute; top: 12px; left: 12px; z-index: 2; display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px; background: rgba(255, 252, 244, .9); backdrop-filter: blur(8px);
  font-size: 13px; font-weight: bold; color: #333; box-shadow: 0 2px 10px rgba(0,0,0,.08);
}
.alma-pill-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--alma-estado); }
.alma:not([data-state="idle"]) .alma-pill-dot { animation: alma-pulso 1.3s infinite; }

.alma-timer { position: absolute; top: 12px; right: 12px; z-index: 2; padding: 6px 10px; border-radius: 999px; background: rgba(255,252,244,.9); font-size: 13px; font-variant-numeric: tabular-nums; }
.alma-timer.aviso { background: var(--alma-ambar); color: #231602; }

.alma-subtitulo {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 2; margin: 0; padding: 10px 14px;
  border-radius: 14px; background: rgba(20, 24, 18, .74); color: #fff; font-size: 15px; line-height: 1.4; text-align: center;
  opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s;
  /* Se ve siempre el final de la frase (lo que Alma está diciendo ahora) */
  display: flex; flex-direction: column; justify-content: flex-end;
  max-height: calc(3 * 1.4em + 20px); overflow: hidden;
}
.alma-subtitulo.show { opacity: 1; transform: none; }

.alma-controles { display: grid; gap: 10px; }
.alma-boton {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 15px 18px;
  border: 0; border-radius: 14px; background: var(--alma-grad); color: #fff; font-weight: bold; font-size: 17px;
  cursor: pointer; text-decoration: none; box-shadow: var(--alma-boton-sombra); transition: background .15s, transform .15s, box-shadow .15s;
}
.alma-boton:hover { background: var(--alma-grad-hover); color: #fff; transform: translateY(-1px); box-shadow: 0 8px 20px rgba(44,127,28,.34); }
.alma-boton:active { transform: scale(.98); }
.alma-boton:focus-visible { outline: 3px solid var(--alma-verde-profundo); outline-offset: 3px; }
.alma-boton .ic-stop { display: none; }
.alma-boton[aria-pressed="true"] { background: #fff; color: #333; border: 1px solid var(--alma-borde); box-shadow: none; }
.alma-boton[aria-pressed="true"] .ic-mic { display: none; }
.alma-boton[aria-pressed="true"] .ic-stop { display: block; color: #c0392b; }

.alma-texto { display: flex; gap: 8px; }
.alma-texto[hidden] { display: none; }
.alma-texto input { flex: 1; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--alma-borde); background: var(--alma-papel); font-size: 15px; }
.alma-texto input:focus { outline: 2px solid var(--alma-verde); border-color: transparent; }
.alma-texto button { width: 46px; border: 0; border-radius: 14px; background: var(--alma-grad); color: #fff; font-size: 17px; cursor: pointer; }

.alma-conversacion { background: var(--alma-papel); border: 1px solid var(--alma-borde); border-radius: 16px; padding: 10px 14px; }
.alma-conversacion summary { cursor: pointer; font-size: 14px; font-weight: bold; color: var(--alma-gris); }
.alma-transcripcion { list-style: none; margin: 10px 0 0; padding: 0 4px 0 0; max-height: 260px; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 8px; }
.alma-transcripcion:empty::before { content: "Todavía no habéis hablado."; color: var(--alma-gris); font-size: 14px; }
.alma-msg { display: block; max-width: 90%; padding: 8px 11px; border-radius: 12px; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.alma-msg p { margin: 2px 0 0; }
.alma-msg .quien { font-size: 11px; font-weight: bold; color: var(--alma-gris); }
.alma-msg.msg-agente { align-self: flex-start; background: #fff; border: 1px solid var(--alma-borde); }
.alma-msg.msg-usuario { align-self: flex-end; background: var(--alma-verde-hielo); border: 1px solid var(--alma-verde-suave); }

.alma-legal { margin: 0; font-size: 12px; line-height: 1.5; color: var(--alma-gris); }

/* ── Resultados ──────────────────────────── */
.alma-col-resultados { min-width: 0; }
.alma-resultados-cabecera {
  background: var(--alma-papel); border: 1px solid var(--alma-borde); border-radius: 22px; box-shadow: var(--alma-sombra);
  padding: 26px 30px; margin-bottom: 18px;
}
.alma-etiqueta { display: inline-block; padding: 5px 11px; border-radius: 999px; background: var(--alma-verde-hielo); border: 1px solid var(--alma-verde-suave); color: var(--alma-verde-profundo); font-size: 12px; font-weight: bold; margin-bottom: 10px; }
.alma-resultados-cabecera h1 { font-size: clamp(22px, 2.6vw, 30px); font-weight: bold; margin: 0 0 6px; }
.alma-titulo-verde { color: var(--alma-verde); }
.alma-ubicacion {
  display: inline-flex; align-items: center; gap: 7px; margin-top: 12px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid rgba(44,127,28,.28); background: #fff; color: var(--alma-verde-profundo);
  font-size: 13px; font-weight: bold; cursor: pointer; transition: background .15s, transform .15s;
}
.alma-ubicacion:hover { background: var(--alma-verde-hielo); transform: translateY(-1px); }
.alma-ubicacion svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.alma-ubicacion.activa { background: var(--alma-verde-hielo); border-color: var(--alma-verde); cursor: default; transform: none; }
.alma-card-distancia { margin: 3px 0 0; font-size: 13px; font-weight: bold; color: var(--alma-verde-profundo); }
.alma-resumen { margin: 0; color: var(--alma-gris); line-height: 1.5; }

.alma-sugerencias { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.alma-sugerencias[hidden] { display: none; }
.alma-sugerencias > span { width: 100%; font-size: 14px; color: var(--alma-gris); }
.alma-sugerencias button {
  padding: 10px 14px; border-radius: 999px; border: 1px solid var(--alma-verde-suave); background: #fff;
  font-size: 14px; cursor: pointer; transition: background .2s, border-color .2s;
}
.alma-sugerencias button:hover { background: var(--alma-verde-hielo); border-color: var(--alma-verde); }

.alma-productos { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.alma-card {
  background: #fff; border-radius: 18px; overflow: hidden; border: 2px solid transparent; box-shadow: 0 6px 18px rgba(0,0,0,.08);
  cursor: pointer; transition: transform .2s, border-color .2s, box-shadow .2s; animation: alma-entra .4s ease-out both;
}
.alma-card:hover { transform: translateY(-3px); box-shadow: 0 12px 26px rgba(0,0,0,.12); }
.alma-card.activa { border-color: var(--alma-verde); box-shadow: 0 0 0 4px var(--alma-verde-suave); }
.alma-card:focus-visible { outline: 3px solid var(--alma-verde-profundo); outline-offset: 2px; }
.alma-card-img { position: relative; aspect-ratio: 4 / 3; background: #eee; }
.alma-card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.alma-card-num {
  position: absolute; top: 10px; left: 10px; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--alma-verde-profundo); color: #fff; font-weight: bold; font-size: 15px; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.alma-card-info { padding: 12px 14px 14px; }
.alma-card-info h3 { font-size: 16px; font-weight: bold; margin: 0 0 6px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.alma-card-precio { margin: 0 0 4px; color: var(--alma-verde-profundo); }
.alma-card-precio strong { font-size: 18px; }
.alma-card-meta, .alma-card-rating { margin: 0; font-size: 13px; color: var(--alma-gris); }
.alma-card-rating { color: #b7791f; margin-top: 3px; }

.alma-detalle {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 20px; margin-top: 18px;
  background: var(--alma-papel); border: 1px solid var(--alma-borde); border-radius: 22px; box-shadow: var(--alma-sombra);
  padding: 18px; animation: alma-entra .35s ease-out;
}
.alma-detalle[hidden] { display: none; }
.alma-detalle img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 14px; background: #eee; }
.alma-detalle-cerrar { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: #fff; font-size: 22px; line-height: 1; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.alma-detalle-cat { font-size: 12px; font-weight: bold; color: var(--alma-verde-profundo); text-transform: uppercase; letter-spacing: .05em; }
.alma-detalle h2 { font-size: 22px; font-weight: bold; margin: 6px 0 8px; padding-right: 30px; }
.alma-detalle-precio { font-size: 18px; font-weight: bold; color: var(--alma-verde-profundo); margin: 0 0 10px; }
.alma-detalle-info p { line-height: 1.5; }
.alma-detalle-meta { font-size: 13px; color: var(--alma-gris); }
.alma-detalle-btn { display: inline-block; margin-top: 6px; padding: 12px 20px; border-radius: 14px; background: var(--alma-grad); color: #fff; font-weight: bold; text-decoration: none; box-shadow: var(--alma-boton-sombra); transition: background .15s, transform .15s; }
.alma-detalle-btn:hover { background: var(--alma-grad-hover); color: #fff; transform: translateY(-1px); }

.alma-toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50; translate: -50% 20px; max-width: min(92vw, 520px);
  padding: 12px 16px; border-radius: 12px; background: #3a2a1a; color: #fff; font-size: 14px; box-shadow: var(--alma-sombra);
  opacity: 0; pointer-events: none; transition: opacity .25s, translate .25s;
}
.alma-toast.show { opacity: 1; translate: -50% 0; }

/* ── Móvil ───────────────────────────────── */
@media (max-width: 860px) {
  .alma { grid-template-columns: 1fr; margin-top: 14px; gap: 16px; }
  .alma-col-avatar { position: static; }
  .alma-stage { height: auto; aspect-ratio: 1 / 1; max-height: 46vh; width: 100%; }
  .alma-resultados-cabecera { padding: 18px; }
  .alma-productos { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .alma-card-info h3 { font-size: 14px; }
  .alma-detalle { grid-template-columns: 1fr; }
  /* Con resultados: Alma pasa a una miniatura flotante (tipo videollamada) y las tarjetas mandan */
  .alma.con-resultados .alma-stage {
    position: fixed; height: auto; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 40;
    width: 118px; height: auto; aspect-ratio: 3 / 4; max-height: none; border-radius: 18px;
    box-shadow: 0 10px 28px rgba(0,0,0,.28); border: 2px solid #fff; cursor: pointer;
  }
  .alma.con-resultados .alma-stage .alma-pill,
  .alma.con-resultados .alma-stage .alma-subtitulo { display: none; }
  .alma.con-resultados .alma-stage .alma-timer { top: auto; bottom: 6px; right: 6px; padding: 3px 7px; font-size: 11px; }
  .alma.con-resultados .alma-col-resultados { padding-bottom: 150px; }
  .alma.con-resultados .alma-conversacion, .alma.con-resultados .alma-legal { display: none; }
  #almaTitulo { scroll-margin-top: 100px; }
  .alma-subtitulo { font-size: 13px; padding: 7px 10px; max-height: calc(2 * 1.4em + 14px); }
}

@keyframes alma-respira { from { transform: scale(1); } to { transform: scale(1.035) translateY(-4px); } }
@keyframes alma-punto { 0%, 80%, 100% { opacity: .3; transform: none; } 40% { opacity: 1; transform: translateY(-4px); } }
@keyframes alma-pulso { 50% { opacity: .35; } }
@keyframes alma-entra { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) { .alma *, .alma *::before, .alma *::after { animation: none !important; transition: none !important; } }
