:root {
    /* --- Paleta corporativa Devir --------------------------------------- */
    --devir-blue-dark: #1f2447;
    --devir-blue: #3b3c8f;
    --devir-blue-light: #499ccb;
    --devir-violet: #9c3878;
    --devir-pink: #cf3d65;
    --devir-pink-dark: #b32f53;
    --devir-orange: #f27227;
    --devir-green: #60b790;

    /* --- Superficies (se mantienen) ------------------------------------- */
    --paper-50: #faf7f2;
    --paper-100: #f3eee6;
    --paper-200: #ebe4d8;
    --surface: #ffffff;
    --line: #e2dacd;
    --line-strong: #8c8174;

    /* --- Texto: familia azul oscuro corporativa ------------------------- */
    --ink-900: var(--devir-blue-dark);
    --ink-700: #3d4266;
    --ink-500: #5a5f80;

    /* --- Semánticos ------------------------------------------------------ */
    --danger-700: #a50d26;
    --felt-700: #2e5e4e;
    --amber-800: #8a5a00;
    --amber-50: #fff4db;

    /* --- Tipografía: máximo dos familias -------------------------------- */
    --font-ui: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-script: Caveat, "Segoe Script", cursive;

    /* --- Movimiento ------------------------------------------------------ */
    --ease-standard: cubic-bezier(0.2, 0, 0, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    min-width: 320px;
    min-height: 100dvh;
    margin: 0;
    color: var(--ink-900);
    background: var(--paper-50);
    font-family: var(--font-ui);
    line-height: 1.55;
}

button, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: var(--devir-pink-dark); text-underline-offset: 0.15em; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.site-header {
    position: sticky;
    z-index: 20;
    top: 0;
    border-bottom: 1px solid var(--line);
    background: var(--paper-50);
}

.header-inner {
    width: min(100% - 32px, 1120px);
    min-height: 68px;
    margin-inline: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink-900);
    text-decoration: none;
}

.brand-mark, .amauta-token {
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    color: #fff;
    background: var(--felt-700);
    font-family: var(--font-ui);
    font-weight: 800;
}

.brand-mark { width: 38px; height: 38px; border-radius: 50%; background: var(--devir-blue-dark); }
.brand strong { display: block; font-family: var(--font-ui); font-weight: 800; font-size: 1.2rem; line-height: 1; letter-spacing: -0.02em; }
.brand small { display: block; margin-top: 4px; color: var(--ink-500); font-size: 0.72rem; }

.secondary-button, .thread-button, .criteria-chip, .starter-chips button, .quick-replies button {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 15px;
    background: var(--surface);
    cursor: pointer;
    font-weight: 600;
}

.secondary-button:hover, .thread-button:hover, .criteria-chip:hover, .starter-chips button:hover, .quick-replies button:hover {
    border-color: var(--devir-pink);
    color: var(--devir-pink-dark);
}

.app-layout {
    width: min(100% - 32px, 1120px);
    min-height: calc(100dvh - 68px);
    margin-inline: auto;
    padding: clamp(44px, 8vw, 92px) 0 170px;
}

.welcome { max-width: 760px; margin-inline: auto; text-align: center; }

/* --- Marca Devir -------------------------------------------------------
   Geometría copiada de public/assets/img/branding/devir-logo-animado.svg
   (viewBox 190 15 820 1170). El <style> interno del asset no se inlinea:
   declara :root{--color:#ffffff} y filtraría el color al documento.
   La animación vive aquí, en CSS, sin JS. */
.devir-mark {
    display: block;
    width: auto;
    height: 96px;
    margin: 0 auto 12px;
    color: var(--devir-blue-dark);
    overflow: visible;
}

.devir-mark .trazo {
    fill: currentColor;
    fill-opacity: 0;
    stroke: currentColor;
    /* 4 es el valor del preview; se engrosa porque aquí se renderiza mucho
       más pequeño y el trazo quedaría por debajo de 1 px. */
    stroke-width: 10;
    stroke-linejoin: round;
    stroke-linecap: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    animation:
        devir-mark-draw 550ms cubic-bezier(.65, 0, .35, 1) forwards,
        devir-mark-fill 350ms ease-out forwards;
}

/* Secuencia del preview comprimida: caja → llama → interior → estrellas → relleno. */
.devir-mark #caja { animation-delay: 0ms, 550ms; }
.devir-mark #llama { animation-delay: 180ms, 730ms; }
.devir-mark #llama-interior { animation-delay: 380ms, 930ms; }
.devir-mark #estrella-izq { animation-delay: 520ms, 1070ms; }
.devir-mark #estrella-centro { animation-delay: 600ms, 1150ms; }
.devir-mark #estrella-der { animation-delay: 670ms, 1220ms; }

@keyframes devir-mark-draw { to { stroke-dashoffset: 0; } }
@keyframes devir-mark-fill { to { fill-opacity: 1; } }

/* El hero entra como un único bloque, sin escalonar elementos. */
.welcome-intro { animation: devir-hero-in 320ms var(--ease-standard) 850ms both; }

@keyframes devir-hero-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}
.eyebrow {
    display: inline-block;
    color: var(--devir-blue);
    font-family: var(--font-script);
    font-size: clamp(1.6rem, 3.4vw, 2.15rem);
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: 0;
    text-transform: none;
}
.welcome h1 { margin: 6px 0 18px; color: var(--devir-blue-dark); font-family: var(--font-ui); font-weight: 800; font-size: clamp(2.5rem, 8vw, 5.25rem); line-height: 0.98; letter-spacing: -0.045em; }
.welcome-intro > p { max-width: 620px; margin: 0 auto; color: var(--ink-700); font-size: clamp(1.05rem, 2vw, 1.25rem); }

.starter-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 30px; }
.starter-chips button { box-shadow: 0 2px 0 var(--paper-200); }

.consent-note {
    max-width: 620px;
    margin: 34px auto 0;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--ink-700);
    background: var(--paper-100);
    text-align: center;
    font-size: 0.86rem;
}
.consent-note > span { width: 22px; height: 22px; flex: 0 0 auto; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; font-weight: 700; }
.consent-note p { margin: 0; }

.chat-area { max-width: 1120px; margin-inline: auto; }
.chat-area.is-active { margin-top: 0; }
.conversation { display: flex; flex-direction: column; align-items: center; gap: 28px; min-width: 0; }

.message-row { width: 100%; max-width: 720px; min-width: 0; display: flex; align-items: flex-start; gap: 11px; }
.message-row-user { justify-content: flex-end; }
.message { overflow-wrap: anywhere; white-space: pre-wrap; }
.message-user {
    width: fit-content;
    max-width: 80%;
    padding: 11px 16px;
    border-radius: 18px 18px 5px 18px;
    color: var(--paper-50);
    background: var(--ink-900);
}
.message-assistant { max-width: 100%; padding-top: 2px; color: var(--ink-700); font-size: 1.02rem; }
.amauta-token { width: 30px; height: 30px; border-radius: 50%; font-size: 0.84rem; }

.thinking { align-items: center; color: var(--ink-500); }
.thinking-content { display: flex; align-items: center; gap: 8px; }
.thinking-dots { display: inline-flex; gap: 4px; }
.thinking-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--felt-700); animation: thinking 900ms infinite alternate; }
.thinking-dots i:nth-child(2) { animation-delay: 150ms; }
.thinking-dots i:nth-child(3) { animation-delay: 300ms; }
@keyframes thinking { to { transform: translateY(-4px); opacity: 0.45; } }

.recommendation-block { width: 100%; max-width: 1120px; min-width: 0; margin-top: -10px; animation: recommendation-in 260ms var(--ease-standard) both; }

@keyframes recommendation-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}
.recommendation-heading { margin: 0 0 6px; color: var(--devir-blue-dark); font-family: var(--font-ui); font-weight: 800; font-size: clamp(1.35rem, 2.4vw, 1.75rem); line-height: 1.15; letter-spacing: -0.02em; }
.recommendation-common { margin: 0 0 18px; color: var(--ink-700); font-size: 0.95rem; }
.recommendation-grid { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: stretch; }
.recommendation-footer { margin-top: 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.recommendation-footer p { width: 100%; margin: 0; color: var(--ink-700); }
.thread-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.product-card {
    position: relative;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 8px 26px rgb(31 36 71 / 8%);
}

/* La primera recomendación se destaca con un halo muy suave, sin cambiar layout. */
.product-card-featured {
    border-color: var(--devir-pink);
    box-shadow: 0 8px 26px rgb(31 36 71 / 8%), 0 0 0 3px rgb(207 61 101 / 12%);
}
.product-media { position: relative; aspect-ratio: 4 / 3; padding: 18px; display: grid; place-items: center; background: var(--paper-200); }
.product-image { width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; }
.product-overlays { position: absolute; inset: 10px 10px auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.product-overlay { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; line-height: 1.2; }
.product-overlay-choice { color: #fff; background: var(--devir-pink); }
.product-overlay-stock { color: var(--amber-800); background: var(--amber-50); border: 1px solid #f0d9a8; }
.product-placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: var(--ink-500); text-align: center; font-weight: 600; }
.product-body { flex: 1; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.product-card h3 { margin: 0; color: var(--devir-blue-dark); font-family: var(--font-ui); font-weight: 700; font-size: 1.35rem; line-height: 1.12; letter-spacing: -0.015em; }
.product-badge { width: fit-content; padding: 4px 8px; border-radius: 999px; color: var(--ink-700); background: var(--paper-100); font-size: 0.72rem; font-weight: 700; }
.product-facts { margin: 0; display: flex; flex-wrap: wrap; gap: 7px 14px; color: var(--ink-700); font-size: 0.82rem; }
.product-facts span { display: inline-flex; align-items: center; gap: 5px; }
.product-price { margin: 0; color: var(--devir-blue-dark); font-family: var(--font-ui); font-size: 1.35rem; font-weight: 700; }
.product-reasons-block { margin: 0; }
.product-reasons-title { margin: 0 0 6px; color: var(--ink-500); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.product-reasons { margin: 0; padding-left: 20px; color: var(--ink-700); font-size: 0.88rem; }
.product-reasons li + li { margin-top: 5px; }
.product-link {
    min-height: 46px;
    margin-top: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: #fff;
    background: var(--devir-pink);
    text-decoration: none;
    font-weight: 700;
}
.product-link:hover { background: var(--devir-pink-dark); }

.no-match-card, .error-card, .closing-card {
    width: 100%;
    max-width: 720px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
}
.no-match-card h3, .error-card h3, .closing-card h3 { margin: 0 0 10px; color: var(--devir-blue-dark); font-family: var(--font-ui); font-weight: 800; letter-spacing: -0.015em; }
.closing-card p { margin: 0 0 14px; color: var(--ink-700); }
.closing-contact { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 0.88rem; color: var(--ink-700); }
.closing-contact p { margin: 0 0 4px; }
.criteria-list { display: flex; flex-wrap: wrap; gap: 8px; }
.criteria-tag { padding: 6px 10px; border-radius: 999px; color: var(--felt-700); background: #e6f0eb; font-size: 0.82rem; font-weight: 600; }
.criteria-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.guided-block { max-width: 680px; margin: 28px auto 0; }
.guided-block h2 { color: var(--devir-blue-dark); font-family: var(--font-ui); font-weight: 700; font-size: 1.2rem; }
.quick-replies, .thread-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.thread-actions { max-width: 680px; margin: 24px auto 0; }
.thread-button-primary { border-color: var(--devir-pink); color: #fff; background: var(--devir-pink); }
.thread-button-primary:hover { border-color: var(--devir-pink-dark); color: #fff; background: var(--devir-pink-dark); }

.composer-dock {
    position: fixed;
    z-index: 30;
    right: 0;
    bottom: 0;
    left: 0;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--paper-50);
    pointer-events: none;
}
.composer {
    width: min(100%, 680px);
    min-height: 58px;
    margin-inline: auto;
    padding: 7px 7px 7px 17px;
    display: flex;
    align-items: flex-end;
    gap: 9px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: 0 12px 38px rgb(31 36 71 / 14%);
    pointer-events: auto;
}
.composer:focus-within { border-color: var(--devir-pink); box-shadow: 0 0 0 3px rgb(207 61 101 / 18%), 0 12px 38px rgb(31 36 71 / 14%); }
.composer textarea { min-width: 0; max-height: 7.5em; flex: 1; resize: none; overflow-y: auto; border: 0; outline: 0; padding: 10px 0; color: var(--ink-900); background: transparent; font-size: 16px; line-height: 1.45; }
.composer textarea::placeholder { color: var(--ink-500); }
.composer button { width: 44px; height: 44px; flex: 0 0 auto; border: 0; border-radius: 50%; color: #fff; background: var(--devir-pink); cursor: pointer; font-size: 1.35rem; font-weight: 700; }
.composer button:hover:not(:disabled) { background: var(--devir-pink-dark); }
.composer button:disabled { cursor: wait; opacity: 0.65; }
.composer-error { width: min(100%, 680px); margin: 7px auto 0; color: var(--danger-700); font-size: 0.82rem; pointer-events: auto; }
.composer-note { width: min(100%, 680px); margin: 8px auto 0; color: var(--ink-500); font-size: 0.72rem; line-height: 1.4; text-align: center; pointer-events: auto; }
.composer-note p { margin: 0; }
.composer-note-version { color: var(--ink-700); font-weight: 600; }
.composer-note-detail { margin-top: 2px !important; font-size: 0.68rem; }
.composer-note a { color: inherit; text-decoration: underline; }

.noscript { margin: 20px; padding: 16px; border: 1px solid var(--line); background: var(--amber-50); }

:focus-visible { outline: 3px solid var(--devir-pink); outline-offset: 3px; }

@media (min-width: 768px) {
    .recommendation-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
    .recommendation-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 767px) {
    .devir-mark { height: 72px; }
    .product-card-compact { display: grid; grid-template-columns: 100px minmax(0, 1fr); align-items: stretch; }
    .product-card-compact .product-media { aspect-ratio: auto; height: 100%; min-height: 100px; padding: 8px; }
    .product-card-compact .product-overlays { inset: 6px 6px auto; }
    .product-card-compact .product-overlay { padding: 3px 6px; font-size: 0.62rem; }
    .product-card-compact .product-body { padding: 12px; gap: 6px; }
    .product-card-compact h3 { font-size: 1.05rem; }
    .product-card-compact .product-badge { font-size: 0.64rem; padding: 2px 6px; }
    .product-card-compact .product-facts { font-size: 0.75rem; gap: 4px 10px; }
    .product-card-compact .product-price { font-size: 1.05rem; }
    .product-card-compact .product-reasons-title { display: none; }
    .product-card-compact .product-reasons { font-size: 0.8rem; padding-left: 16px; }
    .product-card-compact .product-reasons li:nth-child(n + 2) { display: none; }
    .product-card-compact .product-link { min-height: 44px; font-size: 0.85rem; }
}

@media (max-width: 520px) {
    .header-inner, .app-layout { width: min(100% - 24px, 1120px); }
    .header-inner { min-height: 62px; }
    .secondary-button { padding-inline: 12px; font-size: 0.82rem; }
    .app-layout { padding-top: 38px; padding-bottom: 150px; }
    .welcome h1 { font-size: clamp(2.45rem, 14vw, 3.4rem); }
    .starter-chips { align-items: stretch; flex-direction: column; }
    .starter-chips button { width: 100%; }
    .message-user { max-width: 88%; }
    .product-body { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
    .thinking-dots i { animation: none; }
    /* La marca y el hero aparecen completos, sin trazo, sin desplazamiento y sin espera. */
    .devir-mark .trazo { animation: none; fill-opacity: 1; stroke-dashoffset: 0; }
    .welcome-intro { animation: none; opacity: 1; transform: none; }
    .recommendation-block { animation: none; opacity: 1; transform: none; }
}
