/* ===================================================================
   Live chat - shared bubble styles used by BOTH:
   1) the floating widget (public pages, desktop only)
   2) the full-screen /live-chat.php page (linked from the sidebar)
   =================================================================== */

:root {
    --chat-primary: var(--primary, #4f46e5);
    --chat-bg: #f3f4f6;
    --chat-bubble-user: var(--chat-primary);
    --chat-bubble-ai: #ffffff;
}

/* ---------- Floating launcher (desktop-only, per spec) ---------- */
.live-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: #fff;
    border: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1050;
    transition: transform 0.2s ease;
}
.live-chat-fab:hover { transform: scale(1.06); }
.live-chat-fab .unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #fff;
}

/* Proactive "teaser" bubble that pops up near the FAB */
.live-chat-teaser {
    position: fixed;
    bottom: 96px;
    right: 24px;
    max-width: 260px;
    background: #fff;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    padding: 12px 14px;
    font-size: 0.9rem;
    z-index: 1049;
    animation: chatTeaserIn 0.25s ease;
    cursor: pointer;
}
.live-chat-teaser .close-teaser {
    position: absolute;
    top: -8px;
    left: -8px;
    background: #6b7280;
    color: #fff;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    cursor: pointer;
}
@keyframes chatTeaserIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Hide the floating launcher + teaser completely on mobile, per spec -
   mobile users get the full-screen page from the sidebar instead. */
@media (max-width: 768px) {
    .live-chat-fab, .live-chat-teaser, .live-chat-panel { display: none !important; }
}

/* ---------- Floating panel (desktop widget) ---------- */
.live-chat-panel {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 360px;
    height: 520px;
    max-height: 75vh;
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.28);
    z-index: 1050;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.live-chat-panel.open { display: flex; }

/* ---------- Full-screen page layout ---------- */
.live-chat-fullpage {
    /* dvh tracks the *actual* visible viewport on mobile browsers, so the
       header never gets pushed off-screen by the address bar/keyboard the
       way 100vh does. */
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    overflow: hidden;
}

/* ---------- Shared chat header ---------- */
.live-chat-header {
    background: var(--chat-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    /* Sticks to the top of the visible viewport even while the on-screen
       keyboard is up. */
    position: sticky;
    top: 0;
    z-index: 5;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
}
.live-chat-header .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
}
.live-chat-header .title { font-weight: 600; font-size: 0.95rem; line-height: 1.2; }
.live-chat-header .subtitle { font-size: 0.75rem; opacity: 0.85; display: flex; align-items: center; gap: 5px; }
.live-chat-header .status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; }
.live-chat-header .chat-close-btn, .live-chat-header .chat-back-btn {
    background: none; border: none; color: #fff; font-size: 1.1rem; cursor: pointer;
    padding: 6px;
}
/* Only the close button (desktop widget: avatar+title on the left, X on
   the right) should be pushed to the far right. The back button (mobile
   full-page header) must stay in normal flow as the FIRST item, or the
   avatar/title after it get dragged along with it - that was the "back
   arrow and site name pushed to the right" bug. */
.live-chat-header .chat-close-btn {
    margin-left: auto;
}

/* ---------- Message list ---------- */
.live-chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}
.live-chat-body::-webkit-scrollbar { width: 0; height: 0; }

.chat-msg { max-width: 80%; display: flex; flex-direction: column; }
/* align-items must be set explicitly on BOTH sides (not just from-user) -
   without it, .chat-msg.from-ai fell back to the flex default of
   `stretch`, which in a nested column flex layout could collapse the
   bubble to a sliver and force the text to wrap one word (or letter) per
   line - the "vertical message" bug. */
.chat-msg.from-ai { align-self: flex-start; align-items: flex-start; }
.chat-msg.from-user { align-self: flex-end; align-items: flex-end; }

/* Renamed from the generic ".chat-bubble" to ".lc-bubble" - the old name
   collided with an unrelated ".chat-bubble" rule in style.css used by the
   separate ticket/order messaging feature. Both stylesheets load on every
   page, so the two features were fighting over the same class name. */
.lc-bubble {
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 100%;
}
.chat-msg.from-ai .lc-bubble {
    background: var(--chat-bubble-ai);
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.chat-msg.from-user .lc-bubble {
    background: var(--chat-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-meta {
    font-size: 0.68rem;
    color: #9ca3af;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.chat-ticks { font-size: 0.8rem; letter-spacing: -3px; color: #9ca3af; }
.chat-ticks.delivered { color: #9ca3af; }
.chat-ticks.read { color: #3b82f6; }

/* Typing indicator */
.chat-typing { align-self: flex-start; display: flex; gap: 4px; padding: 10px 14px; background: #fff; border-radius: 16px; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.chat-typing span {
    width: 6px; height: 6px; border-radius: 50%; background: #9ca3af;
    animation: chatTypingBounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Composer ---------- */
.live-chat-footer {
    flex: 0 0 auto;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    position: relative;
}
.live-chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    background: #f3f4f6;
    border-radius: 22px;
    padding: 6px 6px 6px 14px;
}
.live-chat-composer textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    max-height: 100px;
    font-size: 0.9rem;
    line-height: 1.4;
    padding: 6px 0;
    outline: none;
    font-family: inherit;
}
.chat-icon-btn {
    border: none;
    background: none;
    color: #6b7280;
    width: 34px; height: 34px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
    font-size: 1.05rem;
}
.chat-icon-btn:hover { background: rgba(0,0,0,0.06); }
.chat-send-btn {
    background: var(--chat-primary);
    color: #fff;
}
.chat-send-btn:hover { background: var(--chat-primary); opacity: 0.9; }

/* Emoji picker popover */
.chat-emoji-picker {
    position: absolute;
    bottom: 100%;
    left: 10px;
    margin-bottom: 8px;
    width: 260px;
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    padding: 10px;
    display: none;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    z-index: 10;
}
.chat-emoji-picker.open { display: grid; }
.chat-emoji-picker button {
    border: none; background: none; font-size: 1.2rem; cursor: pointer;
    border-radius: 6px; padding: 4px 0;
}
.chat-emoji-picker button:hover { background: #f3f4f6; }

.live-chat-empty {
    text-align: center;
    color: #9ca3af;
    font-size: 0.85rem;
    margin: auto;
    padding: 20px;
}

/* ---------- Full-screen page: strip away the normal dashboard chrome
   (mobile topbar, bottom nav, sidebar, body padding) so the chat is a
   true full-screen takeover with nothing fighting it for space. ---------- */
body.live-chat-page {
    padding: 0 !important;
    overflow: hidden;
    height: 100dvh;
}
body.live-chat-page .mobile-topbar,
body.live-chat-page .mobile-bottom-nav,
body.live-chat-page .desktop-sidebar,
body.live-chat-page .sidebar-overlay {
    display: none !important;
}
body.live-chat-page.has-sidebar .main-content {
    margin: 0 !important;
    padding: 0 !important;
    height: 100dvh;
    overflow: hidden;
}

