/* =====================================================================
   FrolliAMOci — PAGINA ASSISTENTE AI (Schermata 2)
   Stati: .is-empty (mockup) → .is-active (conversazione), senza cambio pagina.
   ===================================================================== */

.page-assistant {
    --composer-h: 64px;
    --assistant-max: 860px;
}
/* spazio in fondo per composer + bottom nav: nessun contenuto coperto */
.page-assistant .app-main {
    padding-bottom: calc(var(--composer-h) + var(--bottom-nav-h) + var(--safe-bottom) + var(--space-5));
}
.page-assistant .app-content {
    max-width: var(--assistant-max);
    /* nessuna transform sull'antenato: altrimenti il composer "fixed" perde l'ancoraggio al viewport */
    animation: none;
}
.page-assistant.assistant-started .app-footer { display: none; }

.assistant { display: flex; flex-direction: column; gap: var(--space-3); }

/* ---------- HERO (stato iniziale) ---------- */
.assistant-hero {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-xl);
    /* box stilizzato dal CSS: altezza indipendente dal file (1080×936) */
    height: clamp(230px, 40svh, 360px);
    background: radial-gradient(90% 90% at 30% 20%, #FBE7E2 0%, var(--color-bg-deep) 70%);
    transition: height var(--dur-slow) var(--ease-out), opacity var(--dur-slow) ease, margin var(--dur-slow) ease;
}
.assistant-hero__media { position: absolute; inset: 0; }
.assistant-hero__img {
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: 20% 12%;
}
.assistant-bubble {
    position: absolute;
    right: 3%; top: 48%;
    width: min(52%, 280px);
    padding: var(--space-3) var(--space-4);
    background: #fff;
    border-radius: 26px;
    box-shadow: 0 10px 30px -14px rgba(74, 38, 24, 0.35);
    color: var(--color-text);
    animation: bubble-in 420ms var(--ease-out) 150ms both;
}
.assistant-bubble::before {              /* codina del fumetto verso il personaggio */
    content: ""; position: absolute; left: 14px; bottom: -9px;
    width: 22px; height: 22px; background: #fff;
    border-radius: 0 0 0 18px;
    transform: rotate(8deg);
}
.assistant-bubble__title { font-size: var(--fs-xl); font-weight: var(--fw-heavy); line-height: 1.1; margin-bottom: 4px; text-align: center; }
.assistant-bubble__text { font-size: 0.84rem; font-weight: var(--fw-bold); line-height: 1.35; color: #5b3a2d; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(10px) scale(0.95); } }

/* ---------- BARRA ASSISTENTE (stato conversazione) ---------- */
.assistant-bar {
    display: none;
    position: sticky; top: 0; z-index: 5;
    align-items: center; gap: var(--space-3);
    margin: 0 calc(-1 * var(--page-gutter));
    padding: var(--space-2) var(--page-gutter);
    background: var(--color-bg);
    box-shadow: 0 8px 16px -14px rgba(74, 38, 24, 0.35);
    border-bottom: 1px solid var(--color-border);
}
.assistant-bar__text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.assistant-bar__name { font-weight: var(--fw-heavy); line-height: 1.1; }
.assistant-bar__shop { font-size: var(--fs-xs); color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.assistant-bar__new {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: var(--touch-min); padding: 0 var(--space-3);
    border: 0; border-radius: var(--radius-pill);
    background: var(--color-surface); color: var(--color-text);
    box-shadow: inset 0 0 0 1px var(--color-border-strong);
    font-size: var(--fs-sm); font-weight: var(--fw-bold); cursor: pointer;
}
.assistant-bar__new:hover { background: var(--color-surface-alt); }

.assistant-avatar {
    display: block; flex: none;
    width: 32px; height: 32px; border-radius: 50%; overflow: hidden;
    background: var(--tint-rose);
    box-shadow: 0 0 0 2px #fff;
}
.assistant-avatar--bar { width: 40px; height: 40px; }
.assistant-avatar__img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- SUGGERIMENTI ---------- */
.assistant-suggestions { display: grid; gap: var(--space-2); }
.suggestion {
    display: flex; align-items: center; gap: var(--space-3);
    width: 100%; min-height: 48px;
    padding: var(--space-2) var(--space-4);
    border: 0; border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-card), inset 0 0 0 1px var(--color-border);
    color: var(--color-text);
    font-size: 0.95rem; font-weight: var(--fw-bold); text-align: left; line-height: 1.25;
    cursor: pointer;
    transition: transform var(--dur-fast) ease, background-color var(--dur-fast) ease;
    animation: tile-in var(--dur-slow) var(--ease-out) both;
}
.suggestion:nth-child(2) { animation-delay: 40ms; }
.suggestion:nth-child(3) { animation-delay: 80ms; }
.suggestion:nth-child(4) { animation-delay: 120ms; }
.suggestion:hover { background: #fff; }
.suggestion:active { transform: scale(0.98); }
.suggestion__icon {
    display: grid; place-items: center; flex: none;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--tint-rose); color: var(--color-accent-strong);
    font-size: 0.85rem;
}
@keyframes tile-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- CRONOLOGIA ---------- */
.chat-log { display: none; flex-direction: column; gap: var(--space-4); padding-top: var(--space-2); }
.msg { display: flex; gap: var(--space-2); align-items: flex-end; animation: msg-in var(--dur-base) var(--ease-out) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.msg__body { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; max-width: min(86%, 620px); }
.msg__bubble {
    padding: var(--space-3) var(--space-4);
    border-radius: 20px;
    font-size: var(--fs-md); line-height: 1.45;
    overflow-wrap: anywhere;
}
.msg--user { justify-content: flex-end; }
.msg--user .msg__bubble {
    background: var(--color-primary); color: var(--color-primary-contrast);
    border-bottom-right-radius: 6px;
}
.msg--assistant .msg__bubble {
    background: var(--color-surface); color: var(--color-text);
    box-shadow: var(--shadow-card), inset 0 0 0 1px var(--color-border);
    border-bottom-left-radius: 6px;
}
.msg__bubble strong { font-weight: var(--fw-heavy); }
.msg__tools { display: flex; gap: var(--space-2); }
.msg__listen {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 36px; padding: 0 var(--space-3);
    border: 0; border-radius: var(--radius-pill);
    background: transparent; color: var(--color-text-muted);
    font-size: var(--fs-xs); font-weight: var(--fw-bold); cursor: pointer;
}
.msg__listen:hover, .msg__listen.is-playing { background: var(--tint-rose); color: var(--color-accent-strong); }

/* stato "sta pensando" */
.msg--typing .msg__bubble { display: inline-flex; align-items: center; gap: var(--space-3); color: var(--color-text-muted); font-size: var(--fs-sm); font-weight: var(--fw-bold); }
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--color-accent); animation: dot 1.1s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.msg.is-streaming .msg__bubble::after {           /* cursore durante lo streaming */
    content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 2px;
    vertical-align: -2px; border-radius: 2px; background: var(--color-accent); animation: blink 0.9s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* errore + riprova */
.msg--error .msg__bubble { background: #FFF1EF; box-shadow: inset 0 0 0 1px rgba(194, 46, 68, 0.25); }
.msg__retry { align-self: flex-start; min-height: 40px; padding: 0 var(--space-4); }

/* ---------- COMPONENTI STRUTTURATI ---------- */
.msg__components { display: flex; flex-direction: column; gap: var(--space-2); }
.product-row {
    display: flex; gap: var(--space-2);
    overflow-x: auto; scroll-snap-type: x mandatory;
    margin-right: calc(-1 * var(--page-gutter));
    padding: 2px var(--page-gutter) var(--space-2) 2px;
    scrollbar-width: none;
}
.product-row::-webkit-scrollbar { display: none; }
.product-card {
    flex: 0 0 168px; scroll-snap-align: start;
    display: flex; flex-direction: column;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card), inset 0 0 0 1px var(--color-border);
    overflow: hidden;
    text-decoration: none; color: var(--color-text);
}
.product-card__media { aspect-ratio: 4 / 3; background: var(--tint-caramel); } /* box stilizzato */
.product-card__img { width: 100%; height: 100%; object-fit: cover; }
.product-card__body { display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) var(--space-3) var(--space-3); flex: 1; }
.product-card__name { font-size: 0.88rem; font-weight: var(--fw-heavy); line-height: 1.2; }
.product-card__meta { font-size: var(--fs-xs); color: var(--color-text-muted); }
.product-card__price { margin-top: auto; padding-top: var(--space-1); font-weight: var(--fw-heavy); color: var(--color-accent-strong); }
.product-card__cta {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    min-height: 36px; margin-top: var(--space-2);
    border-radius: var(--radius-pill);
    background: var(--tint-rose); color: var(--color-accent-strong);
    font-size: var(--fs-sm); font-weight: var(--fw-bold);
}
.product-card:hover .product-card__cta { background: var(--color-accent); color: #fff; }

.allergen-note {
    display: flex; gap: var(--space-2); align-items: flex-start;
    padding: var(--space-3);
    border-radius: var(--radius-md);
    background: #FFF6E3; color: #6B4A12;
    font-size: var(--fs-sm); line-height: 1.35;
}
.allergen-note .icon { margin-top: 2px; color: #B7791F; }
.action-cta { align-self: flex-start; }

/* ---------- COMPOSER ---------- */
.composer-dock {
    position: fixed; z-index: 35;
    left: 0; right: 0;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding: var(--space-2) var(--page-gutter);
    background: linear-gradient(to top, var(--color-bg) 70%, rgba(251, 243, 234, 0));
}
.composer {
    display: flex; align-items: flex-end; gap: var(--space-2);
    max-width: var(--assistant-max); margin: 0 auto;
}
.composer__mic {
    position: relative; flex: none;
    display: grid; place-items: center;
    width: 52px; height: 52px; border: 0; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #F0667A, var(--color-accent) 55%, #C92E46);
    color: #fff; font-size: 1.25rem; cursor: pointer;
    box-shadow: 0 8px 18px -8px rgba(201, 46, 70, 0.8);
    transition: transform var(--dur-fast) ease;
}
.composer__mic:active { transform: scale(0.94); }
.composer__stop-icon { display: none; }
.composer__mic[data-state="listening"] { animation: mic-pulse 1.4s ease-out infinite; }
.composer__mic[data-state="listening"] .composer__mic-icon { display: none; }
.composer__mic[data-state="listening"] .composer__stop-icon { display: block; }
.composer__mic[data-state="processing"] { opacity: 0.7; cursor: progress; }
.composer__mic[data-state="error"] { background: var(--color-text-muted); }
@keyframes mic-pulse {
    0% { box-shadow: 0 0 0 0 rgba(232, 68, 90, 0.55); }
    100% { box-shadow: 0 0 0 16px rgba(232, 68, 90, 0); }
}
.composer__field {
    flex: 1; display: flex; align-items: flex-end;
    min-height: 52px;
    padding: 4px 4px 4px var(--space-4);
    background: #fff;
    border-radius: 26px;
    box-shadow: var(--shadow-card), inset 0 0 0 1px var(--color-border);
}
.composer__field:focus-within { box-shadow: var(--shadow-card), inset 0 0 0 2px var(--color-accent); }
.composer__input {
    flex: 1; min-width: 0;
    max-height: 132px;            /* ~5 righe, poi scorre */
    padding: 12px 0;
    border: 0; outline: 0; resize: none; background: transparent;
    font: inherit; font-size: 16px; line-height: 1.4; color: var(--color-text);   /* 16px: niente zoom iOS */
}
.composer__input::placeholder { color: #A89088; }
.composer__send {
    flex: none; display: grid; place-items: center;
    width: 44px; height: 44px; border: 0; border-radius: 50%;
    background: transparent; color: var(--color-accent); font-size: 1.3rem; cursor: pointer;
    transition: transform var(--dur-fast) ease, color var(--dur-fast) ease;
}
.composer__send:hover { background: var(--tint-rose); }
.composer__send:active { transform: scale(0.9); }
.composer__send:disabled { color: #CDB8B0; cursor: default; background: transparent; }
.composer__voice-status {
    max-width: var(--assistant-max); margin: var(--space-1) auto 0;
    text-align: center; font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--color-accent-strong);
}

.assistant-noscript { padding: var(--space-4); text-align: center; font-weight: var(--fw-bold); }

/* ---------- STATO CONVERSAZIONE ---------- */
.assistant.is-active .assistant-hero { height: 0; opacity: 0; margin-top: calc(-1 * var(--space-3)); }
.assistant.is-active .assistant-bar { display: flex; animation: msg-in var(--dur-base) var(--ease-out) both; }
.assistant.is-active .chat-log { display: flex; }
.assistant.is-active .assistant-suggestions { display: none; }
.assistant.is-active .assistant-hero__media { display: none; }

/* Tastiera aperta su mobile: la bottom nav si nasconde, il composer scende */
@media (max-width: 1023px) {
    .is-composing .bottom-nav { display: none; }
    .is-composing .composer-dock { bottom: var(--safe-bottom); }
}

/* Schermi bassi: hero più compatta per tenere visibili suggerimenti e composer */
@media (max-width: 767px) and (max-height: 720px) {
    .assistant-hero { height: clamp(200px, 34svh, 280px); }
    .suggestion { min-height: 44px; font-size: 0.9rem; }
    .assistant-bubble { top: 36%; }
}

/* ---------- Tablet ---------- */
@media (min-width: 768px) {
    .assistant-hero { height: clamp(320px, 42svh, 420px); }
    .assistant-bubble { width: min(46%, 320px); top: 36%; right: 6%; padding: var(--space-4) var(--space-5); }
    .assistant-bubble__title { font-size: var(--fs-2xl); }
    .assistant-bubble__text { font-size: 1rem; }
    .assistant-suggestions { grid-template-columns: 1fr 1fr; }
    .product-card { flex-basis: 200px; }
}

/* ---------- Desktop: colonna centrale contenuta, sidebar comune ---------- */
@media (min-width: 1024px) {
    .page-assistant .app-main { padding-bottom: calc(var(--composer-h) + var(--space-7)); }
    .composer-dock { left: var(--sidebar-w); bottom: 0; padding-bottom: var(--space-4); }
    .assistant-bar { top: 0; }
    .product-row { margin-right: 0; padding-right: 2px; }
    .product-card { flex-basis: 190px; }
}

@media (prefers-reduced-motion: reduce) {
    .assistant-hero { transition: none; }
}
