/* ============================================================
   ASA Chatbot — Floating Bubble & Chat Window
   Colors: #01A8D6 (accent) | #231F20 (dark)
   Requires: Bootstrap 5+
   ============================================================ */

:root {
    --cb-accent:      #01A8D6;
    --cb-accent-dark: #018CB3;
    --cb-dark:        #231F20;
    --cb-white:       #ffffff;
    --cb-light-bg:    #f5f5f5;
    --cb-border:      #e0e0e0;
    --cb-radius:      16px;
    --cb-shadow:      0 8px 32px rgba(35, 31, 32, 0.18);
    --cb-bubble-size: 60px;
    --cb-width:       420px;
    --cb-height:      620px;
}

/* ── Floating Bubble ──────────────────────────────────────── */
#cb-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--cb-bubble-size);
    height: var(--cb-bubble-size);
    background: var(--cb-accent);
    border-radius: 50%;
    box-shadow: var(--cb-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2147483647;
    transition: background 0.2s ease, transform 0.2s ease;
    border: none;
    outline: none;
}

#cb-bubble:hover {
    background: var(--cb-accent-dark);
    transform: scale(1.08);
}

#cb-bubble svg {
    width: 28px;
    height: 28px;
    fill: var(--cb-white);
    transition: opacity 0.2s ease;
}

#cb-bubble .cb-icon-close {
    display: none;
}

#cb-bubble.is-open .cb-icon-chat {
    display: none;
}

#cb-bubble.is-open .cb-icon-close {
    display: block;
}

/* Notification dot */
#cb-bubble .cb-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid var(--cb-accent);
    border-radius: 50%;
    display: none;
}

#cb-bubble .cb-dot.visible {
    display: block;
}

/* ── Attention pulse (idle & unused) ─────────────────────── */
/* Applied via JS as .cb-attention on #cb-bubble for a few seconds,
   removed, then re-applied on an interval. Two parts:
     1) a gentle scale on the bubble itself
     2) an expanding glow ring via the ::after pseudo-element
   (box-shadow rings don't animate reliably when the list also
    contains a var(), so we use a real element for the ring.) */

/* Expanding glow ring — sits behind the bubble */
#cb-bubble::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--cb-accent);
    z-index: -1;
    opacity: 0;
    transform: scale(1);
    pointer-events: none;
}

@keyframes cb-attention-ring {
    0%   { opacity: 0.275; transform: scale(1); }
    100% { opacity: 0;     transform: scale(1.9); }
}

@keyframes cb-attention-scale {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.10); }
    100% { transform: scale(1); }
}

#cb-bubble.cb-attention {
    animation: cb-attention-scale 1.5s ease-in-out infinite;
}

#cb-bubble.cb-attention::after {
    animation: cb-attention-ring 0.75s ease-out infinite;
}

/* Never pulse while the window is open or the bubble is hovered */
#cb-bubble.is-open.cb-attention,
#cb-bubble.cb-attention:hover {
    animation: none;
}
#cb-bubble.is-open.cb-attention::after,
#cb-bubble.cb-attention:hover::after {
    animation: none;
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    #cb-bubble.cb-attention,
    #cb-bubble.cb-attention::after { animation: none; }
}

/* ── Chat Window ──────────────────────────────────────────── */
#cb-window {
    position: fixed;
    bottom: calc(var(--cb-bubble-size) + 32px);
    right: 24px;
    width: min(var(--cb-width), 94vw);
    height: min(var(--cb-height), 86vh);
    background: var(--cb-white);
    border-radius: var(--cb-radius);
    box-shadow: var(--cb-shadow);
    display: flex;
    flex-direction: column;
    z-index: 2147483646;
    overflow: hidden;
    transform: translateY(20px) scale(0.97);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease,
                width 0.2s ease, height 0.2s ease;
}

#cb-window.is-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* Expanded — roughly half the window (large desktop) */
#cb-window.is-expanded {
    width: min(760px, 94vw);
    height: min(900px, 90vh);
}

/* Fullscreen — fills the viewport */
#cb-window.is-fullscreen {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0;
}

/* ── Mobile: the public chatbot always opens fullscreen ───────────
   On phones the window fills the screen no matter which size state is
   active, so it never opens as a small floating panel. Desktop is
   unaffected (this only applies at <=640px wide). */
@media (max-width: 640px) {
    #cb-window,
    #cb-window.is-expanded,
    #cb-window.is-fullscreen {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        max-height: none;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
    }
    /* The header's close (X) is used on mobile, so hide the floating
       launcher while open (it would overlap the input) and the resize
       button (sizing is fixed to fullscreen here). */
    #cb-bubble.is-open { display: none; }
    #cb-header-expand  { display: none; }
}

/* ── Header ───────────────────────────────────────────────── */
#cb-header {
    background: var(--cb-accent);
    color: var(--cb-white);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#cb-header .cb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cb-white);
    border: solid 5px var(--cb-white);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#cb-header .cb-avatar svg {
    width: 20px;
    height: 20px;
    fill: var(--cb-white);
}

#cb-header .cb-title {
    flex: 1;
}

#cb-header .cb-title strong {
    display: block;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.2;
}

#cb-header .cb-title span {
    font-size: 0.72rem;
    opacity: 0.7;
}

/* Language toggle */
#cb-lang-toggle {
    display: flex;
    gap: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 3px;
}

#cb-lang-toggle button {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.6);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s ease;
    letter-spacing: 0.03em;
}

#cb-lang-toggle button.active {
    background: var(--cb-accent);
    color: var(--cb-white);
}

/* ── Messages area ────────────────────────────────────────── */
#cb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#cb-messages::-webkit-scrollbar {
    width: 4px;
}

#cb-messages::-webkit-scrollbar-track {
    background: transparent;
}

#cb-messages::-webkit-scrollbar-thumb {
    background: var(--cb-border);
    border-radius: 4px;
}

/* ── Message bubbles ──────────────────────────────────────── */
.cb-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    animation: cb-fade-in 0.2s ease;
}

@keyframes cb-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.cb-msg.bot {
    align-self: flex-start;
}

.cb-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.cb-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: break-word;
}

.cb-msg.bot .cb-msg-bubble {
    background: var(--cb-light-bg);
    color: var(--cb-dark);
    border-bottom-left-radius: 4px;
}

.cb-msg.user .cb-msg-bubble {
    background: var(--cb-accent);
    color: var(--cb-white);
    border-bottom-right-radius: 4px;
}

/* Bot avatar logo */
.cb-msg.bot .cb-msg-avatar {
    width: 30px;
    height: 30px;
    background: var(--cb-white);
    border: 1px solid var(--cb-border);
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 3px;
}

.cb-msg.bot .cb-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ── Typing indicator ─────────────────────────────────────── */
.cb-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: var(--cb-light-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.cb-typing span {
    width: 7px;
    height: 7px;
    background: #aaa;
    border-radius: 50%;
    animation: cb-bounce 1.2s infinite ease-in-out;
}

.cb-typing span:nth-child(2) { animation-delay: 0.2s; }
.cb-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cb-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-6px); }
}

/* ── Input area ───────────────────────────────────────────── */
#cb-input-area {
    border-top: 1px solid var(--cb-border);
    padding: 12px 14px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--cb-white);
}

#cb-input {
    flex: 1;
    border: 1px solid var(--cb-border);
    border-radius: 22px;
    padding: 9px 16px;
    font-size: 0.875rem;
    resize: none;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.4;
    color: var(--cb-dark);
    transition: border-color 0.15s ease;
    font-family: inherit;
}

#cb-input:focus {
    border-color: var(--cb-accent);
}

#cb-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--cb-accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.15s ease;
    outline: none;
}

#cb-send:hover:not(:disabled) {
    background: var(--cb-accent-dark);
    transform: scale(1.05);
}

#cb-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#cb-send svg {
    width: 18px;
    height: 18px;
    fill: var(--cb-white);
}

/* ── Footer branding ──────────────────────────────────────── */
#cb-footer {
    text-align: center;
    font-size: 0.62rem;
    color: #aaa;
    padding: 6px 0 8px;
    flex-shrink: 0;
    border-top: 1px solid var(--cb-border);
}

#cb-footer a {
    color: var(--cb-accent);
    text-decoration: none;
}

/* Header close button — hidden on desktop, shown on mobile */
#cb-header-close {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    margin-left: 4px;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.15s ease;
    flex-shrink: 0;
}

#cb-header-close:hover {
    opacity: 1;
}

/* Show the close X on desktop too when the window is enlarged */
#cb-window.is-expanded #cb-header-close,
#cb-window.is-fullscreen #cb-header-close {
    display: flex;
}

/* Hide the floating bubble once the window is enlarged (bubble is for the
   smallest window only; closing is done via the header X when enlarged). */
#cb-bubble.cb-hidden {
    display: none !important;
}

#cb-header-close svg {
    width: 22px;
    height: 22px;
    stroke: #fff;
    fill: none;
}

/* Expand / resize button (shown on desktop) */
#cb-header-expand {
    display: flex;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    margin-left: 2px;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.15s ease;
    flex-shrink: 0;
}

#cb-header-expand:hover {
    opacity: 1;
}

#cb-header-expand svg {
    width: 20px;
    height: 20px;
    stroke: #fff;
    fill: none;
}

/* On small screens the window is already fullscreen — hide the resize control */
@media (max-width: 480px) {
    #cb-header-expand {
        display: none;
    }
}

/* ── Mobile responsive ────────────────────────────────────── */
@media (max-width: 480px) {
    :root {
        --cb-width:  100vw;
        --cb-height: 100dvh;
        --cb-radius: 0;
    }

    #cb-window {
        bottom: 0;
        right: 0;
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Hide the floating bubble when chat is open on mobile */
    #cb-bubble.is-open {
        display: none;
    }

    #cb-bubble {
        bottom: 16px;
        right: 16px;
    }

    /* Show X button inside the header instead */
    #cb-header-close {
        display: flex;
    }
}

/* ── Mobile keyboard fixes ────────────────────────────────── */
@media (max-width: 768px) {
    /* 16px is the minimum that stops iOS Safari from auto-zooming
       the whole page when the input is focused (the zoom was pushing
       the send button off the right edge of the screen). */
    #cb-input {
        font-size: 16px;
    }
}
