/* ============================================
   CHAT WIDGET - Theme Variables
   Change --chat-primary to recolor everything
   ============================================ */
:root {
    --chat-primary: #3182ce;
    --chat-primary-dark: #2c5282;
    --chat-primary-light: #ebf8ff;
    --chat-bg: #ffffff;
    --chat-text: #1a202c;
    --chat-muted: #718096;
    --chat-border: #e2e8f0;
    --chat-bubble-size: 60px;
    --chat-radius: 12px;
}

/* Floating Bubble */
#chatWidgetBubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: var(--chat-bubble-size);
    height: var(--chat-bubble-size);
    border-radius: 50%;
    background: var(--chat-primary);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    transition: transform 0.2s, background 0.2s;
    font-size: 28px;
    border: none;
}
#chatWidgetBubble:hover {
    transform: scale(1.08);
    background: var(--chat-primary-dark);
}
#chatWidgetBubble svg {
    width: 32px;
    height: 32px;
    fill: #fff;
}

/* Unread badge */
#chatWidgetBadge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    background: #e53e3e;
    color: #fff;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    border: 2px solid #fff;
    padding: 0 6px;
    display: none;
}

/* Chat Window */
#chatWidgetWindow {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 560px;
    max-height: calc(100vh - 130px);
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--chat-text);
}
#chatWidgetWindow.open {
    display: flex;
    animation: chatSlideUp 0.25s ease-out;
}
@keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.chatWindowHeader {
    background: var(--chat-primary);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chatWindowHeader h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.chatWindowHeader .status {
    font-size: 12px;
    opacity: 0.9;
    margin-top: 2px;
}
.chatWindowHeader .close-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chatWindowHeader .close-btn:hover {
    background: rgba(255,255,255,0.3);
}

/* Body */
.chatWindowBody {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f7fafc;
}

/* Welcome / Info */
.chatWelcome {
    background: #fff;
    padding: 14px;
    border-radius: 10px;
    margin-bottom: 12px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--chat-text);
    border: 1px solid var(--chat-border);
}

/* Form (offline) */
.chatForm {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chatForm input,
.chatForm textarea {
    padding: 10px 12px;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    width: 100%;
    box-sizing: border-box;
}
.chatForm input:focus,
.chatForm textarea:focus {
    border-color: var(--chat-primary);
}
.chatForm textarea {
    resize: none;
    min-height: 80px;
}
.chatForm button {
    background: var(--chat-primary);
    color: #fff;
    border: none;
    padding: 11px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.chatForm button:hover {
    background: var(--chat-primary-dark);
}
.chatForm button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================
   MESSAGE GROUPING - Sender Dividers
   ============================================ */
.chatSenderDivider {
    display: flex;
    align-items: center;
    margin: 20px 0 12px 0;
    gap: 12px;
}
.chatSenderDivider::before,
.chatSenderDivider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--chat-border);
}
.chatSenderDivider span {
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.chatSenderDivider.visitor span {
    color: var(--chat-primary);
}
.chatSenderDivider.admin span {
    color: #2f855a;
}

/* Messages - Improved Styling */
.chatMsg {
    margin-bottom: 4px;
    display: flex;
}
.chatMsg.visitor {
    justify-content: flex-start;
}
.chatMsg.admin {
    justify-content: flex-end;
}

/* First message in a group (after divider) */
.chatMsg.group-start.visitor {
    margin-top: 0;
}
.chatMsg.group-start.admin {
    margin-top: 0;
}

/* Consecutive messages from same sender */
.chatMsg.group-continue {
    margin-top: 2px;
}
.chatMsg.group-continue.visitor .chatMsgBubble {
    border-top-left-radius: 4px;
}
.chatMsg.group-continue.admin .chatMsgBubble {
    border-top-right-radius: 4px;
}

.chatMsgBubble {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.45;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.chatMsg.visitor .chatMsgBubble {
    background: #fff;
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 4px;
    color: var(--chat-text);
}
.chatMsg.admin .chatMsgBubble {
    background: var(--chat-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Footer input */
.chatWindowFooter {
    padding: 12px;
    border-top: 1px solid var(--chat-border);
    background: #fff;
    display: flex;
    gap: 8px;
}
.chatWindowFooter input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--chat-border);
    border-radius: 22px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
}
.chatWindowFooter input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}
.chatWindowFooter button {
    background: var(--chat-primary);
    color: #fff;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chatWindowFooter button:hover {
    background: var(--chat-primary-dark);
}
.chatWindowFooter button svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}
.chatWindowFooter button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Mobile */
@media (max-width: 480px) {
    #chatWidgetWindow {
        bottom: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    #chatWidgetBubble {
        bottom: 16px;
        right: 16px;
    }
}