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

/* Toggle button */
.chaddi-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--chaddi-primary, #1955a6);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(25,85,166,0.38), 0 1px 4px rgba(0,0,0,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.22s cubic-bezier(0.4,0,0.2,1), box-shadow 0.22s;
    animation: chaddi-appear 0.5s cubic-bezier(0.4,0,0.2,1) both;
}

@keyframes chaddi-appear {
    from { transform: scale(0.5) translateY(20px); opacity: 0; }
    to   { transform: scale(1) translateY(0); opacity: 1; }
}

.chaddi-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 28px rgba(25,85,166,0.48), 0 2px 8px rgba(0,0,0,0.14);
}

.chaddi-toggle:active { transform: scale(0.96); }

/* Unread badge */
.chaddi-unread-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: var(--chaddi-accent, #f067a6);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    border-radius: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: chaddi-badge-pop 0.3s cubic-bezier(0.4,0,0.2,1);
}

@keyframes chaddi-badge-pop {
    0%   { transform: scale(0); }
    70%  { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Chat window */
.chaddi-window {
    position: fixed;
    bottom: 94px;
    right: 24px;
    z-index: 99998;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
    animation: chaddi-slide-up 0.28s cubic-bezier(0.4,0,0.2,1);
}

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

/* Header */
.chaddi-header {
    background: linear-gradient(135deg, var(--chaddi-primary, #1955a6) 0%, #2266c4 100%);
    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: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1.5px solid rgba(255,255,255,0.3);
}

.chaddi-header-title {
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 0.02em;
}

.chaddi-header-status {
    font-size: 11px;
    opacity: 0.88;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.chaddi-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(74,222,128,0.3);
}

.chaddi-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chaddi-clear-btn,
.chaddi-minimize {
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chaddi-clear-btn:hover,
.chaddi-minimize:hover { background: rgba(255,255,255,0.25); }

/* Messages area */
.chaddi-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f5f7fb;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}

.chaddi-messages::-webkit-scrollbar { width: 5px; }
.chaddi-messages::-webkit-scrollbar-track { background: transparent; }
.chaddi-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.chaddi-msg {
    display: flex;
    max-width: 88%;
    animation: chaddi-fade-in 0.22s 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: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-wrap: break-word;
}

.chaddi-msg-bot .chaddi-msg-content {
    background: #fff;
    color: var(--chaddi-primary, #1955a6);
    border: 1px solid #e8eaf2;
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--chaddi-primary, #1955a6);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.chaddi-msg-user .chaddi-msg-content {
    background: var(--chaddi-primary, #1955a6);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 6px rgba(25,85,166,0.28);
}

/* Links in bot messages */
.chaddi-msg-bot .chaddi-msg-content a {
    color: var(--chaddi-primary, #1955a6);
    text-decoration: underline;
    font-weight: 600;
}

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

.chaddi-quick-btn {
    background: #fff;
    color: var(--chaddi-primary, #1955a6);
    border: 1.5px solid var(--chaddi-primary, #1955a6);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    font-family: inherit;
}

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

/* Follow-up chips */
.chaddi-followup-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
    padding-left: 2px;
}

.chaddi-followup-chip {
    background: rgba(25,85,166,0.07);
    color: var(--chaddi-primary, #1955a6);
    border: 1px solid rgba(25,85,166,0.2);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.chaddi-followup-chip:hover {
    background: var(--chaddi-primary, #1955a6);
    color: #fff;
    border-color: var(--chaddi-primary, #1955a6);
}

/* Typing indicator */
.chaddi-typing {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #e8eaf2;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    border-left: 3px solid var(--chaddi-primary, #1955a6);
    align-self: flex-start;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.chaddi-typing span {
    width: 7px;
    height: 7px;
    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(-7px); }
}

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

.chaddi-input {
    flex: 1;
    border: 1.5px solid #e0e4eb;
    border-radius: 24px;
    padding: 9px 16px;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    color: #231f20;
    background: #f8f9fc;
}

.chaddi-input:focus {
    border-color: var(--chaddi-primary, #1955a6);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(25,85,166,0.1);
}

.chaddi-send {
    background: var(--chaddi-primary, #1955a6);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.18s, transform 0.15s;
    flex-shrink: 0;
}

.chaddi-send:hover { background: #134080; transform: scale(1.06); }
.chaddi-send:active { transform: scale(0.94); }
.chaddi-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

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

.chaddi-wa-btn:hover { background: #1da851; transform: scale(1.06); }

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

.chaddi-lang-label {
    font-size: 14px;
    margin-right: 2px;
}

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

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

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

/* Mic Button */
.chaddi-mic {
    background: none;
    border: 1.5px solid #d0d5dd;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    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, #1955a6);
    color: var(--chaddi-primary, #1955a6);
}

.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); }
}

.chaddi-input.listening-active {
    border-color: #ef4444;
    background: #fef2f2;
}

/* 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: 18px; right: 18px;
        z-index: 999998;
        width: 54px; height: 54px;
        transition: transform 0.22s cubic-bezier(0.4,0,0.2,1), box-shadow 0.22s, opacity 0.18s ease, bottom 0.22s ease;
    }

    /* On checkout page the sticky bar is ~64px — push button above it */
    .checkout-body .chaddi-toggle { bottom: 86px; }

    /* Fade out smoothly instead of display:none snap */
    .chaddi-widget-open .chaddi-toggle {
        opacity: 0;
        pointer-events: none;
        transform: scale(0.7) translateY(8px);
    }

    .chaddi-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .chaddi-lang-bar { padding: 4px 12px; }
    .chaddi-lang-label { display: none; }

    .chaddi-send, .chaddi-mic { width: 36px; height: 36px; }
    .chaddi-wa-btn { width: 34px; height: 34px; }
    .chaddi-input { padding: 8px 14px; font-size: 16px; }

    .chaddi-quick-actions {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
}
