:root {
    --chat-width: 380px;
    --chat-height: 600px;
    --chat-shadow: 0 15px 45px rgba(0, 0, 0, 0.2);
    --chat-border-radius: 18px;
}

#moiChatToggle {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(142, 31, 44, 0.4);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#moiChatToggle:hover { transform: scale(1.08) translateY(-4px); }
/* Gentle attention pulse on the launcher */
#moiChatToggle::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(142, 31, 44, 0.45);
    animation: moiChatPulse 2.4s ease-out infinite;
}
@keyframes moiChatPulse {
    0% { box-shadow: 0 0 0 0 rgba(142, 31, 44, 0.45); }
    70% { box-shadow: 0 0 0 16px rgba(142, 31, 44, 0); }
    100% { box-shadow: 0 0 0 0 rgba(142, 31, 44, 0); }
}

#moiChatBadge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background-color: #E74C3C;
    color: #FFFFFF;
    border: 2px solid #FFFFFF;
    border-radius: 11px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.55);
    animation: moiBadgePop 0.25s ease;
    z-index: 1;
}
@keyframes moiBadgePop {
    0% { transform: scale(0.3); }
    60% { transform: scale(1.18); }
    100% { transform: scale(1); }
}

/* Support-scope ban panel (shown in the chat body when the guest is restricted from support) */
.moi-chat-banned { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 34px 22px; height: 100%; }
.moi-chat-banned-ico { font-size: 40px; margin-bottom: 14px; }
.moi-chat-banned h6 { font-weight: 800; color: #1A1A1A; margin: 0 0 8px; font-size: 16px; }
.moi-chat-banned p { font-size: 13.5px; color: #6B6B6B; margin: 0 0 10px; line-height: 1.5; }
.moi-chat-banned-reason { background: #fcf4f4; border: 1px solid #f3d6d3; border-radius: 10px; padding: 10px 14px; color: #7a2b25; }
.moi-chat-banned-reason strong { color: #c0392b; }
.moi-chat-banned-tag { color: #c0392b; font-weight: 700; }

#moiChatWidget {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: var(--chat-width);
    height: var(--chat-height);
    background-color: #FFFFFF;
    border-radius: var(--chat-border-radius);
    box-shadow: var(--chat-shadow);
    z-index: 9998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transform-origin: bottom right;
    animation: moiChatFadeIn 0.3s ease;
}

@keyframes moiChatFadeIn {
    from { opacity: 0; transform: scale(0.95) translateY(15px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.moi-chat-header {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #FFFFFF;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    z-index: 10;
}

#moiChatWidget .header-info { display: flex; flex-direction: row; align-items: center; gap: 12px; }

.header-avatar {
    background: #FFFFFF;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
}

/* Scoped under #moiChatWidget so the navbar's own `.header-actions` mobile rule
   (style.css → flex-direction: column) can never bleed into the chat header. */
#moiChatWidget .header-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 14px;
    align-items: center;
    margin: 0;
    padding: 0;
    border: none;
}

#moiChatWidget .header-actions button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    padding: 6px;
    margin: 0;
    width: auto;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, transform 0.2s;
}

#moiChatWidget .header-actions button:hover { color: #FFFFFF; transform: scale(1.1); }

#moiChatStatusBar {
    background-color: #F8F9FA;
    padding: 12px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
}

#moiChatMessages, #moiChatThreads {
    flex: 1;
    overflow-y: auto;
    background-color: #F4F7F9;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

#moiChatThreads { background-color: #FFFFFF; padding: 0; }

.moi-thread-item {
    padding: 16px 20px;
    border-bottom: 1px solid #F0F0F0;
    cursor: pointer;
    transition: background 0.2s;
}
.moi-thread-item:hover { background-color: #F8F9FA; }
.moi-thread-header { display: flex; justify-content: space-between; margin-bottom: 6px; }
.moi-thread-status { font-size: 0.75rem; font-weight: 600; padding: 3px 10px; border-radius: 12px; }
.moi-thread-status.open { background: #E8F8F5; color: #117A65; }
.moi-thread-status.closed { background: #EBEDEF; color: #5D6D7E; }
.moi-thread-status.agent_requested { background: #FEF5E7; color: #D68910; }
.moi-thread-preview { font-size: 0.85rem; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.moi-chat-row { display: flex; flex-direction: column; margin-bottom: 16px; max-width: 85%; }
.moi-chat-row.sent { align-self: flex-end; align-items: flex-end; }
.moi-chat-row.received { align-self: flex-start; align-items: flex-start; }
.moi-chat-bubble { padding: 12px 16px; font-size: 0.95rem; line-height: 1.4; word-wrap: break-word; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.moi-chat-row.sent .moi-chat-bubble { background-color: var(--accent); color: #FFFFFF; border-radius: 18px 18px 4px 18px; }
.moi-chat-row.received .moi-chat-bubble { background-color: #FFFFFF; color: #333; border: 1px solid #EAEAEA; border-radius: 18px 18px 18px 4px; }
.moi-chat-time { font-size: 0.7rem; color: #999; margin-top: 6px; font-weight: 500; }

/* Agent-style received messages (human agents + the automated assistant) */
.moi-chat-row.with-avatar { flex-direction: row; align-items: flex-start; gap: 9px; }
.moi-chat-avatar {
    flex: 0 0 auto;
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.95rem; font-weight: 700; color: #fff;
    margin-top: 18px; /* drop below the name label */
    box-shadow: 0 2px 6px rgba(0,0,0,.12);
    user-select: none;
}
.moi-chat-avatar.is-ai { background: linear-gradient(135deg, var(--accent, #8E1F2C), #b83d4b); }
/* Human support agents carry the Moi Travel logo so they're clearly not the AI. */
.moi-chat-avatar.is-agent { background: #fff; border: 1px solid var(--accent-soft, #F7EAEC); padding: 2px; overflow: hidden; }
.moi-chat-avatar.is-agent img { width: 100%; height: 100%; object-fit: contain; border-radius: 50%; display: block; }
.moi-chat-col { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; flex: 1; }
.moi-chat-name {
    font-size: 0.72rem; font-weight: 700; color: var(--accent, #8E1F2C);
    margin: 0 0 4px 4px; letter-spacing: .01em;
    display: inline-flex; align-items: center; gap: 6px;
}
.moi-chat-tag {
    font-size: 0.6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: var(--accent, #8E1F2C); background: var(--accent-soft, #F7EAEC);
    padding: 2px 7px; border-radius: 10px;
}
.moi-chat-row.with-avatar .moi-chat-bubble {
    background: #FFFFFF; border: 1px solid #ECECF1;
    border-radius: 4px 16px 16px 16px;
}
/* The automated assistant gets a soft branded bubble so it reads as "ours" */
.moi-chat-avatar.is-ai + .moi-chat-col .moi-chat-bubble {
    background: var(--accent-soft, #F7EAEC);
    border-color: #F0DADE;
    color: #2a2a2a;
}

/* Small centred system notice (e.g. "conversation closed") */
.moi-chat-note { width: 100%; text-align: center; margin: 14px 0; }
.moi-chat-note span {
    display: inline-block;
    background: #EEF0F2; color: #5D6D7E;
    font-size: 0.72rem; font-weight: 600;
    padding: 5px 14px; border-radius: 12px;
}

/* Nicely framed shared images in chat */
.moi-chat-img {
    display: block;
    max-width: 220px;
    margin-bottom: 6px;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
    background: #fff;
    line-height: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.moi-chat-img:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2); }
.moi-chat-img img { width: 100%; max-height: 240px; object-fit: cover; display: block; }
.moi-chat-row.sent .moi-chat-img { margin-left: auto; }

#moiChatQuickReplies {
    padding: 12px 20px;
    background-color: #FFFFFF;
    border-top: 1px solid #F0F0F0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 120px;
    overflow-y: auto;
}

.moi-quick-reply-btn {
    background: #F8F9FA;
    border: 1px solid #EAEAEA;
    color: var(--accent);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.moi-quick-reply-btn:hover { background: var(--accent); color: #FFFFFF; }

.moi-chat-footer {
    padding: 16px 20px;
    background-color: #FFFFFF;
    border-top: 1px solid #F0F0F0;
    display: flex;
    gap: 12px;
    align-items: center;
}

.moi-chat-footer input[type="text"] {
    flex: 1;
    border: 1px solid #EAEAEA;
    background-color: #F8F9FA;
    padding: 12px 18px;
    border-radius: 24px;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s;
}
.moi-chat-footer input[type="text"]:focus { border-color: var(--accent); background-color: #FFFFFF; }

#moiChatAttachBtn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#moiChatSend {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #FFFFFF;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(142, 31, 44, 0.2);
    transition: transform 0.2s;
    padding: 0;
}
#moiChatSend:hover { transform: translateY(-2px); }
#moiChatSend:disabled,
.moi-chat-footer input[type="text"]:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Status bar pills + request-agent action ---------------------------- */
.moi-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}
.moi-status-pill::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}
.moi-status-pill.bot { color: #5D6D7E; }
.moi-status-pill.waiting { color: #C77B14; animation: moiPulse 1.6s ease-in-out infinite; }
.moi-status-pill.live { color: #1E874B; }
.moi-status-pill.closed { color: #8A8A8A; }

@keyframes moiPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.moi-status-action {
    background: var(--accent);
    color: #FFFFFF;
    border: none;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.2s;
}
.moi-status-action:hover { background: var(--accent-hover); }

/* ---- Attach button cap state ------------------------------------------- */
#moiChatAttachBtn.at-cap { opacity: 0.35; cursor: not-allowed; }

/* ---- Extra thread statuses --------------------------------------------- */
.moi-thread-status.bot { background: var(--accent-soft, #F7EAEC); color: var(--accent); }
.moi-thread-status.agent_active { background: #E8F8F0; color: #1E874B; }

/* ---- Post-chat rating card --------------------------------------------- */
.moi-rating-card {
    align-self: center;
    width: 86%;
    margin: 12px auto 4px;
    padding: 16px;
    background: #FFFFFF;
    border: 1px solid #EAEAEA;
    border-radius: 14px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.06);
    text-align: center;
}
.moi-rating-title { font-size: 0.9rem; font-weight: 600; color: #1A1A1A; margin-bottom: 8px; }
.moi-rating-stars { display: flex; justify-content: center; gap: 6px; font-size: 1.6rem; cursor: pointer; }
.moi-rating-stars span { color: #D8D8D8; transition: color 0.15s, transform 0.15s; }
.moi-rating-stars span:hover { transform: scale(1.15); }
.moi-rating-stars span.on { color: #F4B400; }
.moi-rating-comment {
    width: 100%; margin: 12px 0 10px; padding: 9px 11px; border: 1px solid #E3E3E8;
    border-radius: 10px; font: inherit; font-size: 0.85rem; resize: vertical; box-sizing: border-box;
}
.moi-rating-comment:focus { outline: none; border-color: var(--accent, #8E1F2C); }
.moi-rating-submit {
    width: 100%; padding: 10px; border: none; border-radius: 10px; cursor: pointer;
    background: var(--accent, #8E1F2C); color: #fff; font-weight: 700; font-size: 0.85rem; transition: background .15s, opacity .15s;
}
.moi-rating-submit:hover { background: var(--accent-hover, #741923); }
.moi-rating-submit:disabled { opacity: .45; cursor: not-allowed; }
/* "Skip for now" — a quiet secondary action so rating is never a dead-end. */
.moi-rating-skip {
    width: 100%; margin-top: 8px; padding: 8px; border: none; background: none; cursor: pointer;
    color: #8a8a92; font-weight: 600; font-size: 0.8rem; text-decoration: underline; transition: color .15s;
}
.moi-rating-skip:hover { color: var(--accent, #8E1F2C); }
.moi-rating-skip:disabled { opacity: .5; cursor: not-allowed; }
/* Day dividers in the guest widget */
.moi-chat-day { text-align: center; margin: 14px 0 6px; }
.moi-chat-day span {
    background: #EAECEE; color: #5D6D7E; font-size: 0.72rem; font-weight: 700;
    padding: 4px 14px; border-radius: 12px; display: inline-block;
}

/* ===== FAQ popup (toggled by the header FAQ icon) + smaller quick-reply buttons ===== */
#moiChatQuickReplies { position: absolute; left: 12px; right: 12px; bottom: 76px; z-index: 25; display: none;
    flex-direction: column; gap: 6px; max-height: 250px; overflow-y: auto; background: #fff; border: 1px solid #ececec;
    border-radius: 14px; padding: 10px; box-shadow: 0 14px 34px rgba(0,0,0,.18); }
#moiChatQuickReplies.open { display: flex; }
.moi-faq-head { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: #9a9aa3; padding: 2px 4px 4px; }
.moi-quick-reply-btn { text-align: left; font-size: 0.8rem; line-height: 1.35; padding: 8px 12px; border: 1px solid #eee;
    border-radius: 10px; background: #faf7f8; color: #1A1A1A; cursor: pointer; transition: background .12s, border-color .12s; width: 100%; }
.moi-quick-reply-btn:hover { background: var(--accent-soft, #F7EAEC); border-color: #e7c9ce; color: var(--accent, #8E1F2C); }
.moi-typing-bubble { background: var(--accent-soft, #F7EAEC); color: var(--accent, #8E1F2C); font-style: italic; font-size: 0.82rem; padding: 10px 14px; }

/* Phones: the 380px-wide fixed panel overflows a 375px screen (its left edge lands off-screen).
   Make the chat near-fullscreen with safe insets, like most mobile chat widgets. */
@media (max-width: 480px) {
    #moiChatToggle { bottom: 18px; right: 18px; width: 56px; height: 56px; }
    /* Full-screen chat on phones — covers the whole viewport (and the launcher, which sits
       behind it; the chat header has its own close button). */
    #moiChatWidget {
        inset: 0; top: 0; right: 0; bottom: 0; left: 0;
        width: 100%; height: 100%; max-height: none;
        border-radius: 0;
        z-index: 10000;
    }
}
