/* ════════════════════════════════════════════════════════════════
   FRAGRANCE BOX — "Ask Fragrance AI" concierge widget
   Minimal white/black premium. BOTTOM-CENTER app-dock placement (safe-area
   aware). The bottom-right cart dock is raised above the pill on mobile via the
   shared floating-layer vars below. Loaded by includes/fragrance_ai_widget.php.
   ════════════════════════════════════════════════════════════════ */
/* Shared floating-layer vars (consumed here + by cart-dock.css). */
:root {
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --fai-bottom: calc(16px + var(--safe-bottom));
    --fai-pill-h: 46px;
    --fai-z: 8000;
}
/* Full-width centered layer; only the pill/panel capture pointer events so the
   empty sides never block the page underneath. */
.fai {
    position: fixed;
    left: 0; right: 0;
    bottom: var(--fai-bottom);
    z-index: var(--fai-z);
    display: flex; justify-content: center;
    pointer-events: none;
    font-family: inherit;
    -webkit-font-smoothing: antialiased;
}
.fai-pill, .fai-panel { pointer-events: auto; }
/* While the launcher is being dragged, suppress page text selection. */
body.fai-dragging { -webkit-user-select: none; user-select: none; }
.fai-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ── Collapsed pill ── */
.fai-pill {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.6rem 1rem 0.6rem 0.85rem;
    background: #fff; color: #111;
    border: 1px solid rgba(0,0,0,0.14);
    border-radius: 999px;
    box-shadow: 0 6px 22px rgba(0,0,0,0.12);
    font-size: 0.8125rem; font-weight: 500; letter-spacing: 0.01em;
    cursor: pointer; font-family: inherit;
    transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
    max-width: min(calc(100vw - 28px), 420px);
    min-height: var(--fai-pill-h);
}
.fai-pill:hover { border-color: rgba(0,0,0,0.45); box-shadow: 0 10px 28px rgba(0,0,0,0.16); transform: translateY(-1px); }
.fai-pill:focus-visible { outline: 2px solid #000; outline-offset: 2px; }
.fai-pill-ico { width: 16px; height: 16px; flex: 0 0 auto; color: rgba(0,0,0,0.55); }
.fai-pill-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fai[data-state="open"] .fai-pill { display: none; }

/* ── Draggable launcher ───────────────────────────────────────────
   Once the user drags the pill, it leaves the centered flex layer and
   anchors to explicit viewport coords via an inline translate3d (set by
   fragrance-ai.js). Inline transform always beats the :hover translate. */
.fai-pill { touch-action: none; cursor: pointer; }
@media (hover: hover) and (pointer: fine) {
    .fai[data-pos="custom"] .fai-pill { cursor: grab; }
    .fai-pill.is-dragging { cursor: grabbing; }
}
.fai[data-pos="custom"] .fai-pill {
    position: fixed; left: 0; top: 0; margin: 0;
    will-change: transform;
    transition: box-shadow 0.2s ease, border-color 0.18s ease, transform 0.24s cubic-bezier(.22,1,.36,1);
}
.fai[data-pos="custom"] .fai-pill:hover { transform: var(--fai-tf); } /* keep position on hover */
.fai-pill.is-dragging {
    transition: box-shadow 0.12s ease;       /* no transform transition while dragging */
    box-shadow: 0 18px 44px rgba(0,0,0,0.28);
    border-color: rgba(0,0,0,0.5);
    user-select: none; -webkit-user-select: none;
}
/* Smoothly lift above an open panel's bottom action bar, settle back on close. */
.fai-pill.is-dodging {
    transition: transform 0.34s cubic-bezier(.22,1,.36,1), box-shadow 0.2s ease, border-color 0.18s ease;
}
/* small hint that the launcher can be moved (pointer devices only) */
.fai[data-pos="custom"] .fai-pill::after {
    content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
}

/* ── Status dot ── */
.fai-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: rgba(0,0,0,0.25); }
.fai-dot[data-dot="green"] { background: #1f9d55; box-shadow: 0 0 0 3px rgba(31,157,85,0.15); }
.fai-dot[data-dot="amber"] { background: #c9881f; box-shadow: 0 0 0 3px rgba(201,136,31,0.15); }
.fai-dot[data-dot="grey"]  { background: rgba(0,0,0,0.3); }

/* ── Expanded panel ── */
.fai-panel {
    position: absolute; bottom: 0; left: 50%;
    width: min(calc(100vw - 24px), 408px);
    height: min(600px, calc(100dvh - 7rem));
    max-height: min(600px, calc(100dvh - 7rem));
    background: #fff; color: #111;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: 18px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.30);
    display: flex; flex-direction: column;
    opacity: 0; visibility: hidden;
    transform: translateX(-50%) translateY(12px) scale(0.99);
    transform-origin: bottom center;
    transition: opacity 0.22s cubic-bezier(.22,1,.36,1), transform 0.22s cubic-bezier(.22,1,.36,1), visibility 0.22s;
    overflow: hidden;
}
.fai[data-state="open"] .fai-panel { opacity: 1; visibility: visible; transform: translateX(-50%); }

.fai-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.85rem 0.9rem 0.85rem 1rem; border-bottom: 1px solid rgba(0,0,0,0.07); }
.fai-head-id { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.fai-head-text { min-width: 0; }
.fai-title { margin: 0; font-size: 0.9375rem; font-weight: 500; letter-spacing: 0.01em; }
.fai-status { margin: 0; font-size: 0.6875rem; color: rgba(0,0,0,0.5); letter-spacing: 0.02em; }
.fai-close { appearance: none; border: 0; background: none; color: rgba(0,0,0,0.45); cursor: pointer; padding: 6px; border-radius: 8px; line-height: 0; transition: color 0.15s, background 0.15s; }
.fai-close:hover { color: #000; background: rgba(0,0,0,0.05); }
.fai-close:focus-visible { outline: 2px solid #000; outline-offset: 2px; }
.fai-close svg { width: 18px; height: 18px; }

.fai-msgs { flex: 1 1 auto; overflow-y: auto; padding: 1rem 0.9rem; display: flex; flex-direction: column; gap: 0.7rem; scroll-behavior: smooth; }
.fai-msgs::-webkit-scrollbar { width: 8px; } .fai-msgs::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.14); border-radius: 8px; }

/* Empty state + suggestion chips */
.fai-empty { margin: auto 0; text-align: center; padding: 0.5rem 0.4rem; }
.fai-empty-title { margin: 0 0 0.2rem; font-size: 0.9375rem; font-weight: 500; }
.fai-empty-sub { margin: 0 0 1rem; font-size: 0.8125rem; color: rgba(0,0,0,0.5); line-height: 1.5; }
.fai-suggest { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; }
.fai-chip { appearance: none; border: 1px solid rgba(0,0,0,0.14); background: #fff; color: #111; border-radius: 999px; padding: 0.45rem 0.8rem; font-size: 0.75rem; font-family: inherit; cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.fai-chip:hover { border-color: rgba(0,0,0,0.5); background: rgba(0,0,0,0.02); }
.fai-chip:focus-visible { outline: 2px solid #000; outline-offset: 2px; }

/* Message bubbles */
.fai-msg { max-width: 86%; font-size: 0.8438rem; line-height: 1.55; word-wrap: break-word; }
.fai-msg-user { align-self: flex-end; background: #111; color: #fff; padding: 0.6rem 0.85rem; border-radius: 14px 14px 4px 14px; }
.fai-msg-ai { align-self: flex-start; background: #f6f5f3; color: #111; padding: 0.7rem 0.9rem; border-radius: 14px 14px 14px 4px; border: 1px solid rgba(0,0,0,0.05); }
.fai-msg-ai a { color: #111; text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }
.fai-msg-ai strong { font-weight: 600; }
.fai-msg-links { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.55rem; }
.fai-msg-link { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; border: 1px solid rgba(0,0,0,0.16); border-radius: 999px; padding: 0.3rem 0.65rem; color: #111; text-decoration: none; transition: border-color 0.15s, background 0.15s; }
.fai-msg-link:hover { border-color: #000; background: rgba(0,0,0,0.03); }

/* Typing indicator */
.fai-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: 0.75rem 0.9rem; background: #f6f5f3; border-radius: 14px 14px 14px 4px; border: 1px solid rgba(0,0,0,0.05); }
.fai-typing span { width: 6px; height: 6px; border-radius: 50%; background: rgba(0,0,0,0.35); animation: faiBounce 1.2s infinite ease-in-out; }
.fai-typing span:nth-child(2) { animation-delay: 0.18s; } .fai-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes faiBounce { 0%,60%,100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-4px); opacity: 1; } }

.fai-offline { margin: 0 0.9rem 0.5rem; padding: 0.7rem 0.85rem; font-size: 0.78125rem; line-height: 1.5; color: rgba(0,0,0,0.6); background: #faf9f7; border: 1px solid rgba(0,0,0,0.08); border-radius: 10px; }

/* Sticky input */
.fai-input { display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.7rem 0.7rem 0.6rem; border-top: 1px solid rgba(0,0,0,0.07); }
.fai-text { flex: 1 1 auto; resize: none; max-height: 120px; border: 1px solid rgba(0,0,0,0.14); border-radius: 12px; padding: 0.6rem 0.75rem; font-size: 0.8438rem; font-family: inherit; color: #111; line-height: 1.4; transition: border-color 0.15s; }
.fai-text:focus { outline: none; border-color: #111; }
.fai-send { flex: 0 0 auto; width: 38px; height: 38px; border: 0; border-radius: 11px; background: #111; color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: opacity 0.15s, background 0.15s; }
.fai-send:disabled { opacity: 0.35; cursor: not-allowed; }
.fai-send:not(:disabled):hover { background: #000; }
.fai-send:focus-visible { outline: 2px solid #000; outline-offset: 2px; }
.fai-send svg { width: 18px; height: 18px; }
.fai-foot { margin: 0; padding: 0 0.9rem 0.7rem; font-size: 0.625rem; color: rgba(0,0,0,0.38); line-height: 1.4; text-align: center; }

/* ── Mobile: centered pill + full-width bottom sheet ── */
@media (max-width: 560px) {
    /* pill stays centered via the .fai flex layer; full-width sheet below */
    .fai-panel {
        position: fixed; left: 0; right: 0; bottom: 0;
        width: 100vw; max-width: 100vw;
        height: auto; max-height: min(82dvh, 680px);
        border-radius: 18px 18px 0 0; transform-origin: bottom center;
        transform: translateY(16px);
        padding-bottom: var(--safe-bottom);
    }
    .fai[data-state="open"] .fai-panel { transform: translateY(0); }
    /* lock body scroll behind the sheet */
    body.fai-open { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
    /* Disable motion only — never `transform: none`, which would reset the
       dragged launcher to 0,0. Keep transforms (positioning + centering). */
    .fai-pill { transition: box-shadow 0.12s ease, border-color 0.12s ease; }
    .fai-pill:hover { transform: none; }
    .fai[data-pos="custom"] .fai-pill { transition: box-shadow 0.12s ease; }
    .fai[data-pos="custom"] .fai-pill:hover { transform: var(--fai-tf); }
    .fai-pill.is-dragging, .fai-pill.is-dodging { transition: none; } /* still moves, just no animation */
    .fai-panel { transition: opacity 0.12s ease; }
    .fai-typing span { animation: none; }
    .fai-msgs { scroll-behavior: auto; }
}

/* ── Collision avoidance with the sticky reserve dock ──────────────
   When the pre-order "Reserve My Box" dock is visible (body.has-reserve-dock,
   set by preorder.js), the AI launcher steps aside as a compact icon-only
   circle so it never competes with or overlaps the primary conversion CTA.
   - Desktop: the centered launcher shifts to the bottom-right (dock is centered).
   - Mobile: it lifts above the near-full-width dock using the shared
     --po-dock-h reserved-space token (no hard-coded magic numbers).
   Dragged (custom-positioned) launchers stay where the user put them and are
   kept off the dock by the existing dodge system (the dock is data-fai-dodge). */
body.has-reserve-dock .fai { justify-content: flex-end; padding-left: 14px; padding-right: 14px; }
body.has-reserve-dock .fai-pill-label { display: none; }
body.has-reserve-dock .fai-pill .fai-dot { display: none; }
body.has-reserve-dock .fai-pill {
    width: 48px; min-width: 48px; max-width: 48px;
    height: 48px; min-height: 48px;
    padding: 0; gap: 0; border-radius: 50%; justify-content: center;
}
body.has-reserve-dock .fai-pill-ico { width: 21px; height: 21px; color: #111; }
@media (max-width: 560px) {
    /* lift the compact launcher above the full-width dock */
    body.has-reserve-dock .fai { bottom: calc(var(--fai-bottom) + var(--po-dock-h, 0px)); }
}
