/* ─── Chaddi Chat Widget ─── */

.chaddi-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chaddi-primary, #0052CC);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 82, 204, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chaddi-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 82, 204, 0.5);
}

/* Window */
.chaddi-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    z-index: 99998;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    animation: chaddi-slide-up 0.3s ease;
}

@keyframes chaddi-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Header */
.chaddi-header {
    background: var(--chaddi-primary, #0052CC);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chaddi-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chaddi-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chaddi-header-title {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 0.5px;
}

.chaddi-header-status {
    font-size: 12px;
    opacity: 0.85;
}

.chaddi-minimize {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.chaddi-minimize:hover { opacity: 1; }

/* Messages */
.chaddi-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fb;
}

.chaddi-msg {
    display: flex;
    max-width: 85%;
    animation: chaddi-fade-in 0.2s ease;
}

@keyframes chaddi-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chaddi-msg-bot { align-self: flex-start; }
.chaddi-msg-user { align-self: flex-end; }

.chaddi-msg-content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chaddi-msg-bot .chaddi-msg-content {
    background: #fff;
    color: #1a1a2e;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.chaddi-msg-user .chaddi-msg-content {
    background: var(--chaddi-primary, #0052CC);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Quick Actions */
.chaddi-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
}

.chaddi-quick-btn {
    background: #fff;
    color: var(--chaddi-primary, #0052CC);
    border: 1.5px solid var(--chaddi-primary, #0052CC);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.chaddi-quick-btn:hover {
    background: var(--chaddi-primary, #0052CC);
    color: #fff;
}

/* Typing indicator */
.chaddi-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.chaddi-typing span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: chaddi-bounce 1.4s infinite;
}

.chaddi-typing span:nth-child(2) { animation-delay: 0.2s; }
.chaddi-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chaddi-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Input Area */
.chaddi-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}

.chaddi-input {
    flex: 1;
    border: 1.5px solid #e0e0e0;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.chaddi-input:focus {
    border-color: var(--chaddi-primary, #0052CC);
}

.chaddi-send {
    background: var(--chaddi-primary, #0052CC);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chaddi-send:hover { background: #003d99; }
.chaddi-send:disabled { opacity: 0.5; cursor: not-allowed; }

.chaddi-wa-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #25D366;
    color: #fff;
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.2s;
}

.chaddi-wa-btn:hover { background: #1da851; }

/* Mobile */
@media (max-width: 480px) {
    .chaddi-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        z-index: 999999;
    }

    .chaddi-toggle {
        bottom: 16px;
        right: 16px;
        z-index: 999998;
    }

    /* Hide the toggle button when chat window is open */
    .chaddi-widget-open .chaddi-toggle {
        display: none !important;
    }

    /* Make input area safe from soft keyboard */
    .chaddi-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    /* Compact language bar on mobile */
    .chaddi-lang-bar {
        padding: 4px 12px;
    }

    .chaddi-lang-label {
        display: none;
    }

    /* Slightly smaller buttons on mobile */
    .chaddi-send,
    .chaddi-mic {
        width: 38px;
        height: 38px;
    }

    .chaddi-wa-btn {
        width: 36px;
        height: 36px;
    }

    .chaddi-input {
        padding: 8px 14px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    /* Quick actions scroll horizontally on mobile */
    .chaddi-quick-actions {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
}

/* Links in bot messages */
.chaddi-msg-bot .chaddi-msg-content a {
    color: var(--chaddi-primary, #0052CC);
    text-decoration: underline;
}

/* Scrollbar */
.chaddi-messages::-webkit-scrollbar { width: 6px; }
.chaddi-messages::-webkit-scrollbar-track { background: transparent; }
.chaddi-messages::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 3px; }

/* ─── Language Bar ─── */
.chaddi-lang-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #f0f4f8;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.chaddi-lang-label {
    font-size: 12px;
    color: #666;
    margin-right: 2px;
}

.chaddi-lang-btn {
    background: #fff;
    border: 1.5px solid #d0d5dd;
    border-radius: 14px;
    padding: 3px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-weight: 500;
    line-height: 1.4;
}

.chaddi-lang-btn:hover {
    border-color: var(--chaddi-primary, #0052CC);
    color: var(--chaddi-primary, #0052CC);
}

.chaddi-lang-btn.active {
    background: var(--chaddi-primary, #0052CC);
    color: #fff;
    border-color: var(--chaddi-primary, #0052CC);
}

/* ─── Mic Button ─── */
.chaddi-mic {
    background: none;
    border: 1.5px solid #d0d5dd;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    color: #555;
}

.chaddi-mic:hover {
    border-color: var(--chaddi-primary, #0052CC);
    color: var(--chaddi-primary, #0052CC);
}

/* Listening state */
.chaddi-mic.listening {
    background: #fee2e2;
    border-color: #ef4444;
    color: #ef4444;
    animation: chaddi-pulse 1.5s ease infinite;
}

@keyframes chaddi-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* Listening status in input placeholder — handled via JS */
.chaddi-input.listening-active {
    border-color: #ef4444;
    background: #fef2f2;
}
