/* ===== Chatbox Widget ===== */
.chatbox {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Lato', sans-serif;
}

/* Toggle Button */
.chatbox__toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.chatbox__toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5);
}

.chatbox__toggle-icon {
    transition: opacity 0.2s, transform 0.2s;
}

.chatbox__toggle-icon--close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.chatbox[data-state="open"] .chatbox__toggle-icon:not(.chatbox__toggle-icon--close) {
    opacity: 0;
    transform: rotate(90deg);
}

.chatbox[data-state="open"] .chatbox__toggle-icon--close {
    opacity: 1;
    transform: rotate(0);
}

.chatbox__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Chat Window */
.chatbox__window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 480px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
}

.chatbox[data-state="open"] .chatbox__window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.chatbox__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
}

.chatbox__header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chatbox__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.chatbox__title {
    display: block;
    font-size: 0.9rem;
    font-weight: 700;
}

.chatbox__status {
    display: block;
    font-size: 0.72rem;
    opacity: 0.85;
}

.chatbox__close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}

.chatbox__close:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Messages */
.chatbox__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8fafc;
}

.chatbox__msg {
    display: flex;
    max-width: 85%;
}

.chatbox__msg--user {
    align-self: flex-end;
}

.chatbox__msg--bot {
    align-self: flex-start;
}

.chatbox__msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.85rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chatbox__msg--user .chatbox__msg-bubble {
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chatbox__msg--bot .chatbox__msg-bubble {
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.chatbox__typing {
    padding: 8px 16px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.chatbox__typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    animation: chatTyping 1.2s infinite;
}

.chatbox__typing span:nth-child(2) { animation-delay: 0.2s; }
.chatbox__typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatTyping {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* Input */
.chatbox__input {
    display: flex;
    align-items: center;
    padding: 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    gap: 8px;
}

.chatbox__input-field {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.chatbox__input-field:focus {
    border-color: #2563eb;
}

.chatbox__input-field:disabled {
    background: #f1f5f9;
    cursor: not-allowed;
}

.chatbox__send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: #2563eb;
    color: #fff;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
}

.chatbox__send:hover {
    background: #1d4ed8;
    transform: scale(1.05);
}

/* Responsive */
@media (max-width: 480px) {
    .chatbox {
        bottom: 16px;
        right: 16px;
    }

    .chatbox__window {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        bottom: 64px;
        right: -8px;
    }

    .chatbox__toggle {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
}

/* Dark mode support (if applicable) */
@media (prefers-color-scheme: dark) {
    .chatbox__window {
        background: #1e293b;
    }

    .chatbox__messages {
        background: #0f172a;
    }

    .chatbox__msg--bot .chatbox__msg-bubble {
        background: #334155;
        color: #f1f5f9;
        border-color: #475569;
    }

    .chatbox__input {
        background: #1e293b;
        border-color: #334155;
    }

    .chatbox__input-field {
        background: #0f172a;
        border-color: #334155;
        color: #f1f5f9;
    }

    .chatbox__input-field:focus {
        border-color: #3b82f6;
    }
}

/* Adjust position when WhatsApp button is present */
.whatsapp-floating ~ .chatbox {
    bottom: 90px;
}

@media (max-width: 480px) {
    .whatsapp-floating ~ .chatbox {
        bottom: 80px;
    }
}
