/* ============================================================
   BU Chatbot — Floating Chat Widget Styles
   All classes prefixed with "buchat-" to avoid conflicts.
   ============================================================ */

/* ── Wrapper ──────────────────────────────────────────── */
#buchat-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
                 Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* ── Floating Bubble Button ───────────────────────────── */
#buchat-bubble {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: #B2040E;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

#buchat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.3);
}

#buchat-bubble:active {
    transform: scale(0.96);
}

/* pulse ring on initial load */
#buchat-bubble::after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid #B2040E;
    animation: buchat-pulse 2s ease-out 3;
}

@keyframes buchat-pulse {
    0%   { transform: scale(1);   opacity: 0.7; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* ── Chat Panel ───────────────────────────────────────── */
#buchat-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 380px;
    max-height: 540px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.25s ease, transform 0.25s ease;
    transform-origin: bottom right;
}

#buchat-panel.buchat-hidden {
    opacity: 0;
    transform: scale(0.9) translateY(12px);
    pointer-events: none;
    visibility: hidden;
}

/* ── Header ───────────────────────────────────────────── */
#buchat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: #B2040E;
    color: #fff;
    flex-shrink: 0;
}

.buchat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.buchat-header-avatar {
    font-size: 28px;
    line-height: 1;
}

.buchat-header-info strong {
    display: block;
    font-size: 15px;
}

.buchat-header-info small {
    opacity: 0.85;
    font-size: 12px;
}

.buchat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

#buchat-minimize,
#buchat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.15s, background 0.15s;
}

#buchat-minimize:hover,
#buchat-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

#buchat-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ── Messages Area ────────────────────────────────────── */
#buchat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 320px;
    background: #f9f9fb;
}

/* Scrollbar */
#buchat-messages::-webkit-scrollbar {
    width: 5px;
}
#buchat-messages::-webkit-scrollbar-track {
    background: transparent;
}
#buchat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* ── Message Bubbles ──────────────────────────────────── */
.buchat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    word-wrap: break-word;
    animation: buchat-fade-in 0.25s ease;
}

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

/* Bot bubble — left */
.buchat-msg.buchat-bot {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
}

/* ── Bot message typography ──────────────────────────── */
.buchat-msg.buchat-bot p {
    margin: 0 0 10px;
    line-height: 1.55;
}
.buchat-msg.buchat-bot p:last-child {
    margin-bottom: 0;
}

/* Section headings (bold paragraphs used as labels) */
.buchat-msg.buchat-bot p > strong:only-child {
    display: block;
    font-size: 13.5px;
    color: #B2040E;
    margin-top: 4px;
    padding-bottom: 3px;
    border-bottom: 1px solid #f0e0e0;
}

.buchat-msg.buchat-bot ul {
    margin: 6px 0 10px 4px;
    padding: 0 0 0 16px;
    list-style: none;
}
.buchat-msg.buchat-bot ul:last-child {
    margin-bottom: 0;
}

.buchat-msg.buchat-bot li {
    margin-bottom: 6px;
    padding: 4px 0;
    line-height: 1.5;
    position: relative;
    padding-left: 14px;
}
.buchat-msg.buchat-bot li::before {
    content: "\2022";
    color: #B2040E;
    font-weight: bold;
    font-size: 14px;
    position: absolute;
    left: 0;
    top: 4px;
}
.buchat-msg.buchat-bot li:last-child {
    margin-bottom: 0;
}

/* Key-value inside list items */
.buchat-msg.buchat-bot li strong {
    color: #333;
    margin-right: 3px;
}

.buchat-msg.buchat-bot a {
    color: #B2040E;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.buchat-msg.buchat-bot a:hover {
    color: #8e0310;
}

.buchat-msg.buchat-bot strong {
    color: #222;
}

.buchat-msg.buchat-bot small {
    color: #777;
}

.buchat-msg.buchat-bot br + br {
    display: block;
    content: "";
    margin-top: 6px;
}

/* User bubble — right */
.buchat-msg.buchat-user {
    align-self: flex-end;
    background: #B2040E;
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Brief highlight when the pre-processor rewrites a user bubble in place.
   The class is added on AJAX success and removed ~1.5s later. */
.buchat-msg.buchat-user.buchat-corrected {
    animation: buchat-correct-flash 1.5s ease-out;
    box-shadow: 0 0 0 2px #ffd54f, 0 0 12px rgba(255, 213, 79, 0.6);
}
@keyframes buchat-correct-flash {
    0%   { background: #ffd54f; color: #222; }
    40%  { background: #ffd54f; color: #222; }
    100% { background: #B2040E; color: #fff; }
}

/* ── Typing Indicator ─────────────────────────────────── */
.buchat-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 12px 18px;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

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

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

@keyframes buchat-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* ── Suggestion Chips ─────────────────────────────────── */
#buchat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px;
    background: #f9f9fb;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.buchat-chip {
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 12px;
    color: #444;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.buchat-chip:hover {
    background: #B2040E;
    color: #fff;
    border-color: #B2040E;
}

/* ── Input Area ───────────────────────────────────────── */
#buchat-form {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-top: 1px solid #e8e8e8;
    background: #fff;
    flex-shrink: 0;
    gap: 8px;
}

#buchat-input {
    flex: 1 1 0;
    min-width: 0;          /* critical — stops the input's implicit min-width from pushing siblings out */
    border: 1px solid #ddd;
    border-radius: 24px;
    padding: 9px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

#buchat-input:focus {
    border-color: #B2040E;
}

#buchat-send {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: #B2040E;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

#buchat-send:hover {
    background: #8e0310;
}

/* ── Bot message links (program detail pages) ─────────── */
.buchat-msg.buchat-bot a {
    color: #B2040E;
    text-decoration: underline;
    word-break: break-word;
}
.buchat-msg.buchat-bot a:hover {
    color: #8e0310;
}

/* ── Voice Language Toggle ────────────────────────────── */
#buchat-lang {
    min-width: 40px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid #d9d9d9;
    border-radius: 19px;
    background: #f0f0f0;
    color: #444;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.3px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

#buchat-lang:hover {
    background: #e0e0e0;
    color: #111;
}

#buchat-lang.is-bn {
    background: #fff4f5;
    color: #B2040E;
    border-color: #f2c3c6;
}

#buchat-lang:focus-visible {
    outline: 2px solid #B2040E;
    outline-offset: 2px;
}

/* ── Mic Button ───────────────────────────────────────── */
#buchat-mic {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: #f0f0f0;
    color: #555;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

#buchat-mic:hover {
    background: #e0e0e0;
    color: #222;
}

/* Recording state — pulsing red ring */
#buchat-mic.recording {
    background: #B2040E;
    color: #fff;
    animation: buchat-mic-pulse 1s ease-in-out infinite;
}

@keyframes buchat-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0   rgba(178, 4, 14, 0.55); }
    50%       { box-shadow: 0 0 0 8px rgba(178, 4, 14, 0);    }
}

/* ── Mobile Responsive ────────────────────────────────── */
@media (max-width: 480px) {
    #buchat-wrap {
        bottom: 12px;
        right: 12px;
    }

    #buchat-panel {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 100px);
        bottom: 68px;
        right: 0;
        border-radius: 12px;
    }

    #buchat-messages {
        max-height: calc(100vh - 300px);
    }

    #buchat-bubble {
        width: 52px;
        height: 52px;
    }

    /* Tighten the input row on narrow phones so lang + mic + send all fit without clipping */
    #buchat-form {
        padding: 10px;
        gap: 6px;
    }
    #buchat-input {
        padding: 9px 14px;
        font-size: 16px;    /* iOS: 16px prevents zoom on focus */
    }
    #buchat-lang {
        min-width: 36px;
        height: 36px;
        padding: 0 8px;
        font-size: 11px;
    }
    #buchat-mic,
    #buchat-send {
        width: 36px;
        height: 36px;
    }
}
