/* ==========================================================================
   Floating Live Chat button & drawer (signed-in history + AI-ready)
   Uses global cerulean + gold tokens from style.css and Poppins + Rubik fonts.
   ========================================================================== */

.fab-chat {
    position: relative;
    background: var(--ink);
    color: #FFFFFF;
    border: none;
}
.fab-chat svg { width: 24px; height: 24px; }
.fab-chat:hover,
.fab-chat:focus-visible {
    background: var(--accent-dark);
    color: #FFFFFF;
    gap: 0.5rem;
    padding-inline: 15px 18px;
}
.fab-chat:hover .fab-label,
.fab-chat:focus-visible .fab-label {
    max-width: 8rem;
    opacity: 1;
}
.chat-fab-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding-inline: 5px;
    border-radius: 999px;
    border: 2px solid #FFFFFF;
    background: var(--gold);
    color: var(--ink);
    font-family: var(--font-display);
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.chat-drawer {
    position: fixed;
    right: 1.15rem;
    bottom: 5.4rem;
    z-index: 160;
    display: flex;
    flex-direction: column;
    width: min(392px, calc(100vw - 1.5rem));
    height: min(560px, calc(100dvh - 7rem));
    border: 1px solid rgba(13, 53, 84, 0.12);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: 0 12px 36px rgba(13, 53, 84, 0.16), 0 2px 8px rgba(13, 53, 84, 0.08);
    overflow: hidden;
    animation: chat-drawer-in 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
.chat-drawer[hidden] { display: none; }
@keyframes chat-drawer-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

.chat-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.9rem 1.05rem;
    background: var(--ink);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: #FFFFFF;
}
.chat-drawer-brand { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.chat-drawer-avatar {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    padding: 5px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.chat-drawer-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.chat-drawer-head h2 {
    margin: 0;
    color: #FFFFFF;
    font-family: var(--font-display);
    font-size: 0.98rem;
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.2px;
}
.chat-drawer-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.15rem 0 0;
    font-size: 0.74rem;
    color: #C7DDF0;
    line-height: 1.2;
}
.chat-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22C55E;
    flex-shrink: 0;
}
.chat-drawer-close {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: #FFFFFF;
    cursor: pointer;
    transition: background-color 0.18s ease;
}
.chat-drawer-close:hover { background: rgba(255, 255, 255, 0.24); }
.chat-drawer-close svg { width: 18px; height: 18px; }

/* Signed-out gate */
.chat-gate {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.75rem;
    flex: 1;
    padding: 1.75rem 1.5rem;
    background: var(--paper);
}
.chat-gate h3 {
    margin: 0;
    font-size: 1.22rem;
    line-height: 1.3;
    letter-spacing: -0.25px;
    color: var(--ink);
}
.chat-gate p { font-size: 0.92rem; line-height: 1.55; color: var(--ink-soft); margin: 0; }
.chat-gate-actions { display: grid; gap: 0.6rem; margin-top: 0.35rem; }
.chat-gate-alt { margin-top: 0.4rem !important; font-size: 0.82rem !important; }
.chat-gate-alt a { font-size: inherit; }

/* Messages log */
.chat-drawer-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--paper);
}
.chat-loading { text-align: center; color: var(--ink-soft); font-size: 0.86rem; margin: auto; }

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 86%;
    gap: 0.2rem;
}
.chat-msg.is-customer { align-self: flex-end; align-items: flex-end; }
.chat-msg.is-staff,
.chat-msg.is-ai,
.chat-msg.is-system { align-self: flex-start; align-items: flex-start; }

.chat-msg-meta {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    color: var(--ink-soft);
    padding-inline: 0.2rem;
}
.chat-ai-pill {
    padding: 0.08rem 0.38rem;
    border-radius: 4px;
    background: var(--ink);
    color: var(--gold-light);
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.chat-msg-bubble {
    padding: 0.68rem 0.9rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.chat-msg.is-customer .chat-msg-bubble {
    background: var(--ink);
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}
.chat-msg.is-staff .chat-msg-bubble,
.chat-msg.is-ai .chat-msg-bubble {
    background: #FFFFFF;
    color: var(--ink);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
}
.chat-msg.is-ai .chat-msg-bubble {
    border-left: 3px solid var(--brand-blue);
}
.chat-msg.is-system .chat-msg-bubble {
    background: var(--accent-tint);
    color: var(--ink);
    border: 1px solid #C8E3F2;
    font-size: 0.84rem;
}

/* Quick prompts */
.chat-quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.6rem 0.9rem;
    background: var(--panel);
    border-top: 1px solid var(--line);
}
.chat-quick-prompts[hidden] { display: none; }
.chat-prompt-chip {
    padding: 0.32rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 0.76rem;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.16s ease, background-color 0.16s ease;
}
.chat-prompt-chip:hover { border-color: var(--accent); background: var(--accent-tint); }

/* Composer */
.chat-composer {
    padding: 0.75rem 0.9rem;
    background: var(--panel);
    border-top: 1px solid var(--line);
}
.chat-composer textarea {
    width: 100%;
    resize: none;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 0.9rem;
    line-height: 1.45;
}
.chat-composer textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(20, 125, 178, 0.16);
}
.chat-composer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-top: 0.5rem;
}
.chat-composer-hint { font-size: 0.74rem; color: var(--ink-soft); }
.chat-composer-hint.is-error { color: #B42318; font-weight: 500; }

@media (max-width: 700px) {
    .chat-drawer {
        right: 0.75rem;
        left: 0.75rem;
        bottom: 4.8rem;
        width: auto;
        height: min(74dvh, 520px);
    }
}
@media (prefers-reduced-motion: reduce) {
    .chat-drawer { animation: none; }
}
@media print {
    .chat-drawer, .fab-chat { display: none !important; }
}
