/*
 * YesSME AI robot — launcher, animations, speech bubble.
 *
 * Shared by the storefront (orange robot) and the admin panel (white robot),
 * which is why it is NOT part of style.css: the storefront does not load the
 * admin stylesheet. The admin chat PANEL styling lives at the bottom of
 * style.css as usual. Flat colors only, every color is a token below (the only
 * place hex is allowed), transform/opacity-only animation.
 */

:root {
    --bp-robot-offset-x: 20px;
    --bp-robot-offset-y: 20px;
    --bp-robot-size: 72px;
    --bp-robot-z: 1035;

    --bp-robot-visor: #36566F;
    --bp-robot-visor-rim: #213A4E;
    --bp-robot-stem: #39546F;
    --bp-robot-badge: #213A4E;
    --bp-robot-ear: #4486BA;
    --bp-robot-antenna: #F7C608;
    --bp-robot-alert: #E5484D;
    --bp-robot-focus: #4486BA;
    --bp-robot-shadow: rgba(15, 23, 42, 0.2);
    --bp-robot-bubble-bg: #FFFFFF;
    --bp-robot-bubble-ink: #1F2937;
    --bp-robot-bubble-border: #E2E8F0;
}

[data-theme="dark"] {
    --bp-robot-visor: #2F4C64;
    --bp-robot-visor-rim: #1A3144;
    --bp-robot-stem: #5D7C98;
    --bp-robot-badge: #1A3144;
    --bp-robot-ear: #5B9BD1;
    --bp-robot-antenna: #FFD21F;
    --bp-robot-alert: #FF6B70;
    --bp-robot-focus: #8AB8E0;
    --bp-robot-shadow: rgba(0, 0, 0, 0.5);
    --bp-robot-bubble-bg: #1E293B;
    --bp-robot-bubble-ink: #E2E8F0;
    --bp-robot-bubble-border: #334155;
}

/* Variants: body + eye/mouth/plus colour swap. */
.bp-robot--orange {
    --bp-robot-body: #D76A0F;
    --bp-robot-eye: #FFFFFF;
    --bp-robot-outline: transparent;
    --bp-robot-z: 9998; /* storefront panel (ai-chat.css) sits at 9999 */
}

.bp-robot--white {
    --bp-robot-body: #FFFFFF;
    --bp-robot-eye: #D76A0F;
    --bp-robot-outline: #CBD5E1;
}

[data-theme="dark"] .bp-robot--orange {
    --bp-robot-body: #E57A14;
}

[data-theme="dark"] .bp-robot--white {
    --bp-robot-body: #F8FAFC;
    --bp-robot-eye: #E57A14;
    --bp-robot-outline: #475569;
}

/* ── Placement ─────────────────────────────────────────────────────────── */
.bp-robot {
    position: fixed;
    right: calc(var(--bp-robot-offset-x) + env(safe-area-inset-right, 0px));
    bottom: calc(var(--bp-robot-offset-y) + env(safe-area-inset-bottom, 0px));
    z-index: var(--bp-robot-z);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    pointer-events: none; /* only the launcher + bubble catch clicks */
}

.bp-robot[hidden] {
    display: none;
}

.bp-robot--compact {
    --bp-robot-size: 52px;
}

.bp-robot-launcher,
.bp-robot-bubble {
    pointer-events: auto;
}

.bp-robot-launcher {
    position: relative;
    display: block;
    width: var(--bp-robot-size);
    height: calc(var(--bp-robot-size) * 577 / 584);
    padding: 0;
    margin: 0;
    background: none;
    border: 0;
    border-radius: 18px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.bp-robot-launcher:focus-visible {
    outline: 3px solid var(--bp-robot-focus);
    outline-offset: 4px;
}

.bp-robot-float,
.bp-robot-hop {
    display: block;
    width: 100%;
    height: 100%;
}

.bp-robot-hop {
    transform-origin: 50% 90%;
    transition: transform 0.18s ease-out;
}

.bp-robot-svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.bp-robot-shadow {
    display: block;
    width: calc(var(--bp-robot-size) * 0.6);
    height: 8px;
    margin: 6px calc(var(--bp-robot-size) * 0.2) 0 auto;
    border-radius: 50%;
    background: var(--bp-robot-shadow);
    transform-origin: 50% 50%;
}

/* ── Parts ─────────────────────────────────────────────────────────────── */
.bp-robot-head,
.bp-robot-base {
    fill: var(--bp-robot-body);
    stroke: var(--bp-robot-outline);
    stroke-width: 6;
}

.bp-robot-visor { fill: var(--bp-robot-visor); }
.bp-robot-visor-rim { fill: var(--bp-robot-visor-rim); }
.bp-robot-ear { fill: var(--bp-robot-ear); }
.bp-robot-stem { fill: var(--bp-robot-stem); }
.bp-robot-ball { fill: var(--bp-robot-antenna); }
.bp-robot-badge { fill: var(--bp-robot-badge); }
.bp-robot-eye { fill: var(--bp-robot-eye); }
.bp-robot-dot { fill: var(--bp-robot-eye); }
.bp-robot-orbit { fill: var(--bp-robot-antenna); }
.bp-robot-ball-ring { fill: none; stroke: var(--bp-robot-antenna); stroke-width: 6; opacity: 0; }

.bp-robot-mouth,
.bp-robot-plus {
    fill: none;
    stroke: var(--bp-robot-eye);
    stroke-linecap: round;
}

.bp-robot-mouth { stroke-width: 12; }
.bp-robot-plus { stroke-width: 9; }

.bp-robot-eyes,
.bp-robot-mouth,
.bp-robot-antenna,
.bp-robot-ear,
.bp-robot-eye,
.bp-robot-dot,
.bp-robot-ball-ring,
.bp-robot-spin {
    transform-box: fill-box;
    transform-origin: center;
}

.bp-robot-antenna { transform-origin: 50% 100%; }
.bp-robot-ear-l { transform-origin: 100% 50%; }
.bp-robot-ear-r { transform-origin: 0% 50%; }
.bp-robot-mouth { transform-origin: 50% 0%; transition: transform 0.2s ease-out; }
.bp-robot-eyes { transform: translate(var(--bp-robot-look-x, 0px), var(--bp-robot-look-y, 0px)); transition: transform 0.12s ease-out; }
.bp-robot-eye { transition: transform 0.08s ease-in; }
.bp-robot-dots,
.bp-robot-spin { opacity: 0; }
.bp-robot-spin { transform-box: view-box; transform-origin: 292px 33px; }

/* ── Idle loops ────────────────────────────────────────────────────────── */
.bp-robot-float { animation: bp-robot-float 3.2s ease-in-out infinite; }
.bp-robot-shadow { animation: bp-robot-shadow 3.2s ease-in-out infinite; }
.bp-robot-antenna { animation: bp-robot-wobble 2.6s ease-in-out infinite; }
.bp-robot-ball-ring { animation: bp-robot-ring 2.4s ease-out infinite; }
.bp-robot-ear { animation: bp-robot-listen 3.6s ease-in-out infinite; }

.bp-robot.is-blinking .bp-robot-eye { transform: scaleY(0.1); }

@keyframes bp-robot-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@keyframes bp-robot-shadow {
    0%, 100% { transform: scaleX(1); opacity: 1; }
    50% { transform: scaleX(0.82); opacity: 0.6; }
}

@keyframes bp-robot-wobble {
    0%, 100% { transform: rotate(-6deg); }
    50% { transform: rotate(6deg); }
}

@keyframes bp-robot-ring {
    0% { transform: scale(1); opacity: 0.55; }
    100% { transform: scale(1.7); opacity: 0; }
}

@keyframes bp-robot-listen {
    0%, 100% { transform: scaleY(1); opacity: 0.9; }
    50% { transform: scaleY(1.06); opacity: 1; }
}

/* ── Entrance / exit ───────────────────────────────────────────────────── */
.bp-robot.bp-robot--in .bp-robot-launcher { animation: bp-robot-enter 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

@keyframes bp-robot-enter {
    0% { transform: translateY(48px) scale(0.5); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.bp-robot.bp-robot--out {
    opacity: 0;
    transform: translateY(12px) scale(0.6);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.bp-robot.bp-robot--offline { display: none; }

/* ── Attention hop + wave ──────────────────────────────────────────────── */
.bp-robot.is-attention .bp-robot-hop { animation: bp-robot-hop 0.95s ease-in-out 1; }
.bp-robot.is-attention .bp-robot-ear-r { animation: bp-robot-wave 0.95s ease-in-out 1; }

@keyframes bp-robot-hop {
    0% { transform: translateY(0) rotate(0); }
    25% { transform: translateY(-18px) rotate(-7deg); }
    50% { transform: translateY(0) rotate(0); }
    70% { transform: translateY(-9px) rotate(7deg); }
    100% { transform: translateY(0) rotate(0); }
}

@keyframes bp-robot-wave {
    0%, 100% { transform: rotate(0); }
    25%, 65% { transform: rotate(18deg); }
    45%, 85% { transform: rotate(-10deg); }
}

/* ── Hover (pointer devices) ───────────────────────────────────────────── */
@media (hover: hover) and (pointer: fine) {
    .bp-robot-launcher:hover .bp-robot-hop { transform: scale(1.08); }
    .bp-robot-launcher:hover .bp-robot-mouth { transform: scaleX(1.25) scaleY(1.2); }
}

/* ── Click squish ──────────────────────────────────────────────────────── */
.bp-robot.is-popping .bp-robot-hop { animation: bp-robot-pop 0.32s ease-out 1; }

@keyframes bp-robot-pop {
    0% { transform: scale(1, 1); }
    35% { transform: scale(1.14, 0.84); }
    70% { transform: scale(0.94, 1.08); }
    100% { transform: scale(1, 1); }
}

/* ── States ────────────────────────────────────────────────────────────── */
.bp-robot[data-state="thinking"] .bp-robot-eyes { opacity: 0; }
.bp-robot[data-state="thinking"] .bp-robot-dots { opacity: 1; }
.bp-robot[data-state="thinking"] .bp-robot-dot { animation: bp-robot-dot 0.9s ease-in-out infinite; }
.bp-robot[data-state="thinking"] .bp-robot-dot:nth-child(2) { animation-delay: 0.15s; }
.bp-robot[data-state="thinking"] .bp-robot-dot:nth-child(3) { animation-delay: 0.3s; }
.bp-robot[data-state="thinking"] .bp-robot-spin { opacity: 1; animation: bp-robot-orbit 0.9s linear infinite; }
.bp-robot[data-state="thinking"] .bp-robot-ball-ring { animation-duration: 0.9s; }
.bp-robot[data-state="thinking"] .bp-robot-antenna { animation-duration: 1.2s; }

.bp-robot[data-state="error"] .bp-robot-ball,
.bp-robot[data-state="error"] .bp-robot-orbit { fill: var(--bp-robot-alert); }
.bp-robot[data-state="error"] .bp-robot-ball-ring { stroke: var(--bp-robot-alert); }
.bp-robot[data-state="error"] .bp-robot-mouth { transform: scaleY(-0.7); }

.bp-robot[data-state="happy"] .bp-robot-mouth { transform: scaleX(1.3) scaleY(1.3); }
.bp-robot[data-state="happy"] .bp-robot-hop { animation: bp-robot-happy 0.6s ease-out 1; }

@keyframes bp-robot-dot {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-14px); }
}

@keyframes bp-robot-orbit {
    to { transform: rotate(360deg); }
}

@keyframes bp-robot-happy {
    0% { transform: translateY(0); }
    30% { transform: translateY(-12px) scale(1.06); }
    60% { transform: translateY(0) scale(0.97); }
    100% { transform: translateY(0) scale(1); }
}

/* ── Speech bubble ─────────────────────────────────────────────────────── */
.bp-robot-bubble {
    position: relative;
    display: flex;
    align-items: stretch;
    max-width: 230px;
    margin-bottom: 12px;
    background: var(--bp-robot-bubble-bg);
    color: var(--bp-robot-bubble-ink);
    border: 1px solid var(--bp-robot-bubble-border);
    border-radius: 14px;
    box-shadow: 0 4px 14px var(--bp-robot-shadow);
    transform-origin: 85% 100%;
}

.bp-robot-bubble[hidden] { display: none; }
.bp-robot-bubble.is-showing { animation: bp-robot-bubble-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

.bp-robot-bubble::after {
    content: "";
    position: absolute;
    right: 26px;
    bottom: -7px;
    width: 12px;
    height: 12px;
    background: var(--bp-robot-bubble-bg);
    border-right: 1px solid var(--bp-robot-bubble-border);
    border-bottom: 1px solid var(--bp-robot-bubble-border);
    transform: rotate(45deg);
}

.bp-robot-bubble-text,
.bp-robot-bubble-close {
    margin: 0;
    background: none;
    border: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.bp-robot-bubble-text { padding: 9px 4px 9px 14px; font-size: 14px; line-height: 1.35; text-align: left; }
.bp-robot-bubble-close { padding: 0 11px 0 6px; font-size: 18px; line-height: 1; opacity: 0.55; }
.bp-robot-bubble-close:hover { opacity: 1; }

.bp-robot-bubble-text:focus-visible,
.bp-robot-bubble-close:focus-visible {
    outline: 2px solid var(--bp-robot-focus);
    outline-offset: 2px;
    border-radius: 8px;
}

@keyframes bp-robot-bubble-in {
    0% { transform: scale(0.4); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ── Small screens ─────────────────────────────────────────────────────── */
@media (max-width: 560px) {
    :root {
        --bp-robot-size: 56px;
        --bp-robot-offset-x: 12px;
        --bp-robot-offset-y: 12px;
    }

    .bp-robot--compact { --bp-robot-size: 46px; }
    .bp-robot-bubble { max-width: 200px; }
}

/* ── Paused when the tab is hidden; calm for reduced-motion users ──────── */
.bp-robot.is-paused *,
.bp-robot.is-paused { animation-play-state: paused !important; }

@media (prefers-reduced-motion: reduce) {
    .bp-robot *,
    .bp-robot *::before,
    .bp-robot *::after {
        animation: none !important;
        transition: none !important;
    }

    .bp-robot-ball-ring { opacity: 0; }
}

@media print {
    .bp-robot { display: none !important; }
}

/* Storefront: clear the mobile bottom-nav (~60px) like the old chat FAB did. */
@media (max-width: 991px) {
    .bp-robot--orange { --bp-robot-offset-y: 80px; }
}

/* Small robot head used as the chat-panel avatar (inherits the variant tokens). */
.bp-robot-avatar {
    display: inline-block;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
}

.bp-robot-avatar .bp-robot-svg { width: 100%; height: 100%; }
.bp-robot-avatar *,
.bp-robot-avatar *::before { animation: none !important; }
