/* ============================================================
   BIP on the marketing site (js/bip.js). Sizes, colours and layout
   copied from itfolder-www: the launcher from
   assets/scss/custom/structure/_right-sidebar.scss (.bip-companion,
   .agent-fab, .agent-popover) and the chat from
   components/agent/AgentPanel.vue + AgentMessage.vue, dark theme.
   Left out on purpose: expand-to-side-panel and save-history.
   ============================================================ */
.bip-companion, .bip-popover, .bip-recall {
    --bip-teal: #0e7d97;          /* app header, chips, send icon */
    --bip-teal-hover: #0b6a80;
    --bip-accent: #19b3d7;        /* logo teal */
    --bip-primary: #0759b6;       /* app primary: user bubble */
    --bip-body-bg: var(--bs-body-bg, #0d1117);
    --bip-body-color: var(--bs-body-color, #e6edf3);
    --bip-muted: var(--bs-secondary-color, #8391a2);
    --bip-tertiary: var(--bs-tertiary-bg, #1e2736);
    --bip-border: var(--bs-border-color, #2b3440);
    --bip-accent-text: #19b3d7;   /* teal as text/icons; darker in light mode */
    --bip-heading: var(--bs-heading-color, #fff);
    --bip-popover-border: rgba(255, 255, 255, .15);
    --bip-popover-shadow: 0 8px 32px rgba(0, 0, 0, .4);
}
[data-bs-theme="light"] .bip-companion,
[data-bs-theme="light"] .bip-popover,
[data-bs-theme="light"] .bip-recall {
    --bip-accent-text: #0e7490;   /* 5.4:1 on white */
    --bip-popover-border: #dfe5ec;
    --bip-popover-shadow: 0 8px 32px rgba(15, 23, 42, .18);
}

/* ── Launcher ─────────────────────────────────────────────────── */
.bip-companion {
    --bip-size: 58.4px;
    position: fixed;
    bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 12px));
    right: max(24px, calc(env(safe-area-inset-right, 0px) + 12px));
    width: var(--bip-size);
    height: var(--bip-size);
    z-index: 1047;
    pointer-events: none;
}
.bip-traveller { position: relative; width: 100%; height: 100%; }
.bip-fab {
    position: absolute; inset: 0; width: 100%; height: 100%; padding: 0;
    border: 0; border-radius: 50%; background: transparent; color: #eef5ed;
    pointer-events: auto; isolation: isolate; cursor: pointer; touch-action: manipulation;
}
.bip-fab:focus-visible { outline: 3px solid var(--bip-accent); outline-offset: 5px; }
.bip-fab:hover .bip-hint, .bip-fab:focus-visible .bip-hint { opacity: 1; transform: translateY(-3px); }
/* No greeting while the chat is already open */
.bip-open .bip-hint { display: none; }
.bip-ground {
    position: absolute; width: 65%; height: 10%; bottom: 8%; left: 18%;
    background: #0007; filter: blur(4px); border-radius: 50%;
}
.bip-robot {
    position: absolute; inset: -10% -2% 0;
    transform-origin: center 86%;
    filter: drop-shadow(0 4px 2px #0004);
}
.bip-robot img {
    display: block; width: 100%; height: 100%; object-fit: contain;
    transform-origin: 50% 88%;
    animation: bip-breathe 5.6s ease-in-out infinite;
}
.bip-robot--jumping { animation: bip-jump .85s cubic-bezier(.25,.6,.3,1); }
@keyframes bip-breathe {
    0%, 70%, 100% { transform: translateY(0) rotate(0); }
    78% { transform: translateY(-10px) rotate(-2deg); }
    87% { transform: translateY(0) rotate(1deg); }
    94% { transform: translateY(-4px); }
}
@keyframes bip-jump {
    0%, 100% { transform: translateY(0) scale(1); }
    13% { transform: translateY(4%) scale(1.06, .93); }
    36% { transform: translateY(-24%) scale(.96, 1.04) rotate(-5deg); }
    61% { transform: translateY(0) scale(1.07, .94); }
    79% { transform: translateY(-8%) rotate(3deg); }
    92% { transform: translateY(0) scale(1.02, .98); }
}
.bip-hint {
    position: absolute; right: 0; bottom: calc(100% + 14px); white-space: nowrap;
    padding: 9px 13px; border-radius: 12px 12px 3px 12px;
    background: var(--bip-body-bg); color: var(--bip-body-color);
    border: 1px solid #19b3d74d; font-size: 12px; font-weight: 600;
    opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.bip-dismiss {
    position: absolute; right: -22px; top: -14px;
    display: grid; place-items: center; width: 32px; height: 32px; padding: 0;
    border: 1px solid var(--bip-border); border-radius: 50%;
    background: var(--bip-body-bg); color: var(--bip-body-color); font-size: 20px;
    opacity: .45; pointer-events: auto; transition: opacity .18s;
}
.bip-dismiss:focus-visible { outline: 3px solid var(--bip-accent); outline-offset: 3px; }
.bip-traveller:hover .bip-dismiss, .bip-traveller:focus-within .bip-dismiss { opacity: 1; }
.bip-companion--leaving .bip-traveller { animation: bip-leave 1.18s linear both; }
.bip-companion[hidden] { display: none; }
.bip-companion--leaving .bip-dismiss, .bip-companion--arriving .bip-dismiss { visibility: hidden; }
.bip-companion--leaving .bip-fab, .bip-companion--arriving .bip-fab { pointer-events: none; }
.bip-companion--arriving .bip-traveller { animation: bip-arrive .85s cubic-bezier(.16,.7,.32,1) both; }
@keyframes bip-arrive {
    0% { transform: translateX(240px) rotate(-9deg); }
    77% { transform: translateX(-9px) rotate(-5deg); }
    90% { transform: translateX(3px) rotate(3deg); }
    100% { transform: translateX(0); }
}
@keyframes bip-leave {
    0% { transform: translateX(0); }
    18% { transform: translateX(-10px) rotate(-6deg); }
    28% { transform: translateX(3px) rotate(4deg); }
    70% { transform: translateX(90px) rotate(8deg); }
    100% { transform: translateX(240px) rotate(9deg); }
}
/* Motion toggle off (or reduced motion): BIP stands still */
.bip-still .bip-robot img, .bip-still .bip-robot, .bip-still .bip-traveller { animation: none !important; }

/* Keep BIP clear of the cookie banner while it is showing */
body:has(#itf-cookie-banner:not(.hidden)) .bip-companion { bottom: 96px; }
@media (min-width: 768px) { body:has(#itf-cookie-banner:not(.hidden)) .bip-popover { bottom: 182px; } }
@media (max-width: 600px) { body:has(#itf-cookie-banner:not(.hidden)) .bip-companion { bottom: 150px; } }

/* Top-menu recall button, shown only while BIP is sent away */
.bip-recall {
    display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px 0 6px;
    border: 1px solid var(--bip-border); border-radius: 999px;
    background: rgba(14, 125, 151, .18); color: var(--bip-body-color);
    font-weight: 600; font-size: 14px;
    transition: background .2s ease, border-color .2s ease;
}
.bip-recall:hover, .bip-recall:focus-visible { background: rgba(14, 125, 151, .35); border-color: var(--bip-accent); }
.bip-recall[hidden] { display: none; }
.bip-recall img { width: 26px; height: 26px; border-radius: 50%; background: var(--bip-tertiary); object-fit: contain; }

/* ── Popover (AgentPanel in popover mode) ─────────────────────── */
.bip-popover {
    position: fixed;
    bottom: max(106px, calc(env(safe-area-inset-bottom, 0px) + 98px));
    right: 20px;
    width: min(380px, calc(100vw - 40px));
    height: 520px;
    max-height: calc(100dvh - max(106px, calc(env(safe-area-inset-bottom, 0px) + 98px)) - 78px);
    background: var(--bip-body-bg); color: var(--bip-body-color);
    border: 1px solid var(--bip-popover-border);
    border-radius: 16px;
    box-shadow: var(--bip-popover-shadow);
    z-index: 1048;
    display: flex; flex-direction: column; overflow: hidden;
    contain: paint; isolation: isolate;
    opacity: 0; transform: translateY(12px) scale(.96); transform-origin: bottom right;
    pointer-events: none; visibility: hidden;
    transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
    font-family: var(--itf-font, system-ui, sans-serif);
}
.bip-popover--open {
    opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; visibility: visible;
    transition: opacity .2s ease, transform .2s ease, visibility 0s;
}

.bip-header {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    min-height: 48px; padding: 0 12px; background: var(--bip-teal); color: #fff; flex-shrink: 0;
}
.bip-header-title { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
.bip-header-avatar { width: 38px; height: 38px; flex-shrink: 0; object-fit: contain; }
.bip-header h2 { color: #fff; font-size: 1rem; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: 0; }
.bip-header-tools { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.bip-header-btn {
    width: 28px; height: 30px; padding: 3px; font-size: .875rem; line-height: 1;
    color: #fff; background: transparent;
    border: 1px solid rgba(255, 255, 255, .6); border-radius: var(--bs-border-radius-sm, .25rem);
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, border-color .15s;
}
.bip-header-btn:hover, .bip-header-btn:focus-visible { background: rgba(255, 255, 255, .15); border-color: rgba(255, 255, 255, .5); }
.bip-header-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.bip-header-btn:disabled { color: rgba(255, 255, 255, .4); border-color: rgba(255, 255, 255, .15); }

.bip-messages {
    flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px;
    background: inherit; transform: translateZ(0); backface-visibility: hidden;
}
.bip-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 100%; text-align: center; padding: 8px 4px;
}
.bip-empty[hidden] { display: none; }
.bip-how { display: flex; flex-direction: column; gap: 8px; text-align: left; max-width: 320px; margin-bottom: 1rem; }
.bip-step { display: flex; align-items: flex-start; gap: 10px; font-size: .8rem; color: var(--bip-muted); line-height: 1.4; }
.bip-step-text { flex: 1; min-width: 0; }
.bip-step-num {
    flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%;
    background: var(--bip-teal); color: #fff; font-size: .7rem; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
}

/* Messages (AgentMessage) */
.bip-message { margin-bottom: 12px; }
.bip-message--user { display: flex; flex-direction: column; align-items: flex-end; }
.bip-user-layout { display: flex; align-items: flex-start; gap: 10px; justify-content: flex-end; width: 100%; }
.bip-user-content { display: flex; flex-direction: column; align-items: flex-end; min-width: 0; }
.bip-user-bubble {
    max-width: 100%; border-radius: 12px; border-bottom-right-radius: 4px; padding: 10px 14px;
    font-size: .875rem; line-height: 1.4; background: var(--bip-primary); color: #fff;
    overflow-wrap: anywhere;
}
.bip-time { font-size: .7rem; color: var(--bip-muted); margin-top: 4px; text-align: right; }
.bip-avatar {
    flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
    background: var(--bip-tertiary); display: flex; align-items: center; justify-content: center;
    overflow: hidden; margin-top: 2px;
}
.bip-avatar img { width: 28px; height: 28px; object-fit: contain; }
.bip-avatar--user { color: var(--bip-muted); font-size: 15px; }
.bip-message--assistant { display: flex; align-items: flex-start; gap: 10px; }
.bip-assistant-content { flex: 1; min-width: 0; font-size: .875rem; line-height: 1.4; color: var(--bip-body-color); }
.bip-assistant-content p { margin: 0 0 .5rem; }
.bip-answer-title { font-weight: 600; color: var(--bip-heading); }
.bip-muted { color: var(--bip-muted); font-size: .8rem; }
.bip-steps { margin: 0 0 .5rem; padding-left: 1rem; }
.bip-route-btn {
    display: inline-flex; align-items: center; gap: 4px; margin: 2px 0 .5rem;
    padding: .25rem .5rem; font-size: .8rem; font-weight: 500; line-height: 1.5;
    color: var(--bip-accent-text); background: transparent; text-decoration: none;
    border: 1px solid var(--bip-accent-text); border-radius: var(--bs-border-radius-sm, .25rem);
    transition: background .15s, color .15s;
}
.bip-route-btn:hover, .bip-route-btn:focus-visible { background: var(--bip-accent-text); color: var(--bip-body-bg); }

/* Follow-up / suggestion chips (solid cyan) */
.bip-follow-ups { display: flex; flex-wrap: wrap; gap: .25rem; }
.bip-follow-ups.mt-2 { margin-top: .5rem; }
.bip-follow-up {
    font-size: .75rem; border-radius: 16px; padding: 4px 10px; min-height: 28px;
    white-space: normal; text-align: left; line-height: 1.4;
    background: var(--bip-teal); color: #fff; border: none; transition: background .15s;
}
.bip-follow-up:hover, .bip-follow-up:focus-visible { background: var(--bip-teal-hover); color: #fff; }
.bip-follow-up--ghost { background: transparent; border: 1px dashed var(--bip-teal); color: var(--bip-body-color); }
.bip-follow-up--ghost:hover, .bip-follow-up--ghost:focus-visible { background: rgba(14, 125, 151, .25); }
.bip-group { border-top: 1px solid var(--bip-border); padding: 6px 0; }
.bip-group summary { cursor: pointer; font-weight: 600; font-size: .8rem; color: var(--bip-heading); margin-bottom: 4px; }

/* Typing indicator */
.bip-typing { display: flex; gap: 4px; padding: 4px 0; }
.bip-typing span:not(.bip-typing-text) {
    width: 8px; height: 8px; border-radius: 50%; background: #6c757d;
    animation: bip-typing 1.2s infinite ease-in-out;
}
.bip-typing span:nth-child(2) { animation-delay: .2s; }
.bip-typing span:nth-child(3) { animation-delay: .4s; }
.bip-typing-text { display: none; }
@keyframes bip-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Input with the send button inside it */
.bip-input { display: flex; align-items: flex-end; padding: 12px 16px; flex-shrink: 0; position: relative; }
.bip-input-wrapper { position: relative; flex: 1; min-width: 0; }
.bip-input textarea.form-control {
    display: block; width: 100%; resize: none; min-height: 38px; max-height: 120px; overflow-y: hidden;
    padding: .45rem 44px .45rem .9rem; font-size: .875rem; font-family: inherit; line-height: 1.5;
    color: var(--bip-body-color); background: transparent;
    border: 1px solid var(--bip-border); border-radius: var(--bs-border-radius, .375rem);
}
.bip-input textarea.form-control::placeholder { color: var(--bip-muted); }
.bip-input textarea.form-control:focus {
    outline: none; border-color: var(--bip-accent); box-shadow: 0 0 0 .2rem rgba(25, 179, 215, .25);
}
.bip-send-btn {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 34px; height: 34px; padding: 0; display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; color: var(--bip-accent-text); z-index: 2; cursor: pointer;
    border-radius: 50%; font-size: 1rem; transition: background .15s, color .15s;
}
.bip-send-btn:hover:not(:disabled) { background: rgba(236, 75, 155, .1); }
.bip-send-btn:disabled { color: var(--bip-muted); opacity: .4; cursor: default; }

/* Mobile: launcher shrinks, popover goes full screen (as in the app) */
@media (max-width: 767.98px) {
    .bip-companion { --bip-size: 49.6px; right: max(18px, env(safe-area-inset-right, 0px)); }
    .bip-popover {
        top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100vh; height: 100dvh;
        max-height: none; border-radius: 0; z-index: 1050; transform-origin: center center;
        padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .bip-popover--open { transform: none; }
    /* iOS Safari zooms the page when a focused field is under 16px, which
       breaks the full-screen layout. Keep the composer at 16px on phones. */
    .bip-input textarea.form-control { font-size: 16px; }
}
@media (hover: none) {
    .bip-dismiss { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .bip-companion *, .bip-popover, .bip-popover * { animation: none !important; transition: none !important; }
    .bip-typing span:not(.bip-typing-text) { opacity: 0; }
    .bip-typing-text { display: inline; font-size: .75rem; color: var(--bip-muted); margin-left: 4px; }
}
