/* ============================================================
   LIVE CHAT WIDGET
   ============================================================ */
#chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

#chat-toggle {
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(43, 142, 240, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    flex-shrink: 0;
}

#chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(43, 142, 240, 0.5);
}

#chat-unread-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #EF4444;
    color: white;
    font-family: 'DM Sans', sans-serif;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--bg);
}

#chat-unread-badge.visible {
    display: flex;
}

#chat-online-badge {
    position: absolute;
    bottom: -3px;
    left: -3px;
    background: #4ADE80;
    color: #064E3B;
    font-family: 'DM Sans', sans-serif;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--bg);
    letter-spacing: -0.2px;
}

#chat-panel {
    width: 320px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.14);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: panelIn 0.25s ease;
    max-height: 480px;
}

#chat-panel.open {
    display: flex;
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#chat-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

#chat-header-icon {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-title {
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: white;
}

#chat-subtitle {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 1px;
}

.online-dot {
    width: 6px;
    height: 6px;
    background: #4ADE80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

#chat-user-id-display {
    font-family: 'DM Sans', sans-serif;
    font-size: 10px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    padding: 3px 8px;
    letter-spacing: 0.3px;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar {
    width: 4px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 85%;
    animation: msgIn 0.2s ease;
}

.chat-msg.continuation {
    margin-top: -3px;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg.own {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-msg.other {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-msg.system {
    align-self: center;
    align-items: center;
    max-width: 100%;
}

.chat-msg-meta {
    font-size: 9px;
    font-weight: 600;
    color: var(--muted);
    padding: 0 4px;
}

.chat-msg.own .chat-msg-meta {
    color: var(--primary);
}

.chat-bubble {
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 11.5px;
    font-weight: 400;
    line-height: 1.5;
    word-break: break-word;
}

.chat-msg.own .chat-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 3px;
}

.chat-msg.other .chat-bubble {
    background: var(--bg);
    color: var(--slate);
    border: 1px solid var(--border);
    border-bottom-left-radius: 3px;
}

.chat-msg.system .chat-bubble {
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-style: italic;
    border: none;
    padding: 2px 4px;
}

.chat-msg-time {
    font-size: 9px;
    font-weight: 400;
    color: var(--muted);
    padding: 0 4px;
    opacity: 0.7;
}

#chat-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: white;
}

#chat-input {
    flex: 1;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 400;
    color: var(--midnight);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    outline: none;
    transition: border-color 0.2s;
}

#chat-input:focus {
    border-color: var(--primary);
}

#chat-input::placeholder {
    color: var(--muted);
}

#chat-send {
    width: 34px;
    height: 34px;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}

#chat-send:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

#chat-send:active {
    transform: scale(0.97);
}

/* ── Responsive ── */
@media (max-width: 600px) {
    #chat-panel {
        width: calc(100vw - 48px);
    }
}