/* ==============================================
   CHATBOT AI WIDGET - Layanan Desa Cijeruk
   ============================================== */

/* Tombol trigger mengambang */
#chatbot-toggle {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0f766e, #059669);
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(15, 118, 110, 0.45);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(15, 118, 110, 0.55);
}
#chatbot-toggle .icon-chat,
#chatbot-toggle .icon-close { transition: opacity 0.2s, transform 0.2s; }
#chatbot-toggle .icon-close { display: none; }
#chatbot-toggle.open .icon-chat { display: none; }
#chatbot-toggle.open .icon-close { display: block; }
#chatbot-toggle .icon-chat {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
#chatbot-toggle .toggle-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: 2px solid white;
    border-radius: 50%;
    box-sizing: border-box;
}

/* Animasi melayang untuk avatar dan badge saat chat ditutup */
#chatbot-toggle:not(.open) .icon-chat,
#chatbot-toggle:not(.open) #chatbot-badge {
    animation: chatbot-float 3s ease-in-out infinite;
}
@keyframes chatbot-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* Balon Sapaan (Greeting Bubble) */
#chatbot-greeting-bubble {
    position: absolute;
    right: 74px;
    top: 50%;
    transform: translateY(-50%) translateX(10px);
    background: #ffffff;
    color: #1e293b;
    padding: 10px 16px;
    border-radius: 16px;
    border-top-right-radius: 16px;
    border-bottom-right-radius: 4px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 9999;
}
#chatbot-greeting-bubble::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 10px;
    height: 10px;
    background: #ffffff;
    box-shadow: 2px -2px 5px rgba(0,0,0,0.03);
}
#chatbot-toggle.show-greeting #chatbot-greeting-bubble {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
    pointer-events: auto;
}
/* Sembunyikan bubble saat chatbot terbuka */
#chatbot-toggle.open #chatbot-greeting-bubble {
    opacity: 0;
    transform: translateY(-50%) translateX(10px);
    pointer-events: none;
}

/* Badge notifikasi */
#chatbot-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
    animation: chatbadge-pulse 2s infinite;
}
@keyframes chatbadge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Window chatbot */
#chatbot-window {
    position: fixed;
    bottom: 160px;
    right: 24px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    transform: scale(0.8) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transform-origin: bottom right;
    transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
}
#chatbot-window.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* Header chatbot */
#chatbot-header {
    background: linear-gradient(135deg, #0f766e, #059669);
    padding: 14px 18px;
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
#chatbot-header .bot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.6);
}
#chatbot-header .bot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
#chatbot-header .bot-info h4 {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}
#chatbot-header .bot-info span {
    font-size: 11px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
}
#chatbot-header .bot-info span::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}

/* Area messages */
#chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
}
#chatbot-messages::-webkit-scrollbar { width: 4px; }
#chatbot-messages::-webkit-scrollbar-track { background: transparent; }
#chatbot-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* Bubble chat */
.chat-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.55;
    word-break: break-word;
    animation: bubble-in 0.2s ease;
}
@keyframes bubble-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.chat-bubble.bot {
    background: #ffffff;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    align-self: flex-start;
}
.chat-bubble.user {
    background: linear-gradient(135deg, #0f766e, #059669);
    color: white;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}
.chat-bubble .bubble-time {
    font-size: 10px;
    opacity: 0.55;
    margin-top: 4px;
    display: block;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #ffffff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typing-bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); background: #94a3b8; }
    40% { transform: translateY(-6px); background: #0f766e; }
}

/* Chip pertanyaan cepat */
#chatbot-quickreplies {
    padding: 8px 14px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    flex-shrink: 0;
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
}
#chatbot-quickreplies::-webkit-scrollbar { display: none; }
.quick-chip {
    white-space: nowrap;
    font-size: 11px;
    padding: 5px 12px;
    border-radius: 20px;
    border: 1.5px solid #0f766e;
    color: #0f766e;
    background: white;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.quick-chip:hover { background: #0f766e; color: white; }

/* Input area */
#chatbot-input-area {
    padding: 12px 14px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    border-top: 1px solid #f1f5f9;
    background: white;
    flex-shrink: 0;
}
#chatbot-input {
    flex: 1;
    border: 1.5px solid #e2e8f0;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 13px;
    outline: none;
    resize: none;
    max-height: 80px;
    overflow-y: auto;
    line-height: 1.4;
    color: #1e293b;
    transition: border-color 0.15s;
    font-family: inherit;
}
#chatbot-input:focus { border-color: #0f766e; }
#chatbot-input::placeholder { color: #94a3b8; }
#chatbot-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0f766e, #059669);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s;
    color: white;
}
#chatbot-send:hover { transform: scale(1.08); }
#chatbot-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Mobile */
@media (max-width: 480px) {
    #chatbot-window {
        right: 12px;
        bottom: 85px;
        width: calc(100vw - 24px);
        height: 450px;
        max-height: calc(100vh - 100px);
    }
    #chatbot-toggle { bottom: 20px; right: 16px; }
}
