/* ShafAI Widget v1.3 - Icon Toggle Fix */

/* 1. Import Font Spectral */
@import url('https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

/* 2. Main Container - POINTER EVENTS FIX */
#shafai-widget,
#shafai-widget * {
    font-family: 'Spectral', serif !important;
    box-sizing: border-box;
}

#shafai-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999999;
    line-height: 1.4;
    font-size: 15px;
    pointer-events: none; /* Agar tidak menghalangi klik di website */
    width: auto;
    height: auto;
}

#shafai-widget.shafai-position-bottom-left {
    left: 20px;
    right: auto;
}

#shafai-widget .shafai-toggle,
#shafai-widget .shafai-container {
    pointer-events: auto;
}

/* 3. Toggle Button */
#shafai-widget .shafai-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #009688, #00796b);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    padding: 0;
    margin: 0;
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 20;
}

#shafai-widget .shafai-toggle:hover {
    transform: scale(1.1);
}

#shafai-widget .shafai-toggle svg {
    width: 28px;
    height: 28px;
    fill: #fff;
    /* Hapus display: block default disini agar tidak menimpa logika toggle */
}

/* FIX: Gunakan !important agar icon toggle benar-benar berganti */
#shafai-widget .shafai-icon-close { display: none !important; }
#shafai-widget.shafai-open .shafai-icon-chat { display: none !important; }
#shafai-widget.shafai-open .shafai-icon-close { display: block !important; }

/* 4. Chatbox Container */
#shafai-widget .shafai-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #d1d5db;
    z-index: 10;
}

#shafai-widget.shafai-open .shafai-container {
    display: flex;
    animation: shafaiAppear 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}

@keyframes shafaiAppear {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* 5. Header */
#shafai-widget .shafai-header {
    background: linear-gradient(135deg, #009688, #00796b);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

#shafai-widget .shafai-logo {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
    padding: 2px;
    border: 1px solid rgba(255,255,255,0.3);
}

#shafai-widget .shafai-header-info { flex: 1; }

#shafai-widget .shafai-title {
    margin: 0;
    padding: 0;
    font-size: 20px !important;
    font-weight: 700 !important;
    color: #fff !important;
    line-height: 1.2;
}

#shafai-widget .shafai-status {
    font-size: 13px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    color: #e0f2f1;
    font-style: italic;
}

#shafai-widget .shafai-status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    display: block;
    box-shadow: 0 0 4px rgba(74, 222, 128, 0.5);
}

#shafai-widget .shafai-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s;
}

#shafai-widget .shafai-close:hover { background: rgba(255, 255, 255, 0.25); }
#shafai-widget .shafai-close svg { width: 18px; height: 18px; fill: #fff; }

/* 6. Messages Area */
#shafai-widget .shafai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8fafc;
    -webkit-overflow-scrolling: touch;
}

#shafai-widget .shafai-message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

#shafai-widget .shafai-avatar {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #e2e8f0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#shafai-widget .shafai-bot .shafai-avatar img { width: 100%; height: 100%; object-fit: cover; }
#shafai-widget .shafai-user .shafai-avatar { background: #00796b; }
#shafai-widget .shafai-user .shafai-avatar svg { width: 18px; height: 18px; fill: #fff; }

#shafai-widget .shafai-content { flex: 1; max-width: 85%; }

#shafai-widget .shafai-bubble {
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 16px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

#shafai-widget .shafai-bot .shafai-bubble {
    background: #fff;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-top-left-radius: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

#shafai-widget .shafai-user { flex-direction: row-reverse; }
#shafai-widget .shafai-user .shafai-bubble {
    background: linear-gradient(135deg, #009688, #00796b);
    color: #fff;
    border-top-right-radius: 2px;
    box-shadow: 0 2px 5px rgba(0, 150, 136, 0.3);
}

#shafai-widget .shafai-time {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 6px;
    padding: 0 2px;
    font-style: italic;
}

/* Content Formatting */
#shafai-widget .shafai-bubble h1, h2, h3, h4, h5, h6 { margin: 10px 0 6px 0 !important; font-weight: 700 !important; color: #1e293b !important; line-height: 1.3 !important; }
#shafai-widget .shafai-bubble h3 { font-size: 16px !important; text-decoration: underline; text-decoration-color: #009688; }
#shafai-widget .shafai-bubble p { margin: 0 0 10px 0 !important; }
#shafai-widget .shafai-bubble p:last-child { margin: 0 !important; }
#shafai-widget .shafai-bubble ul, ol { margin: 6px 0 10px 0 !important; padding-left: 20px !important; }
#shafai-widget .shafai-bubble a { color: #00796b !important; text-decoration: underline !important; font-weight: 600 !important; }
#shafai-widget .shafai-user .shafai-bubble a { color: #fff !important; }
#shafai-widget .shafai-bubble pre { background: #1e293b; color: #f1f5f9; padding: 12px; border-radius: 8px; overflow-x: auto; font-family: 'Consolas', monospace !important; font-size: 13px !important; margin: 10px 0; white-space: pre-wrap; }
#shafai-widget .shafai-bubble code { font-family: 'Consolas', monospace !important; font-size: 13px !important; background: rgba(0,0,0,0.06); padding: 2px 5px; border-radius: 4px; color: #c026d3; }
#shafai-widget .shafai-bubble table { width: 100%; border-collapse: collapse; margin: 10px 0 !important; font-size: 14px !important; border: 1px solid #cbd5e1; background: #fff; }
#shafai-widget .shafai-bubble th, td { border: 1px solid #cbd5e1; padding: 8px 12px !important; text-align: left; color: #334155 !important; }
#shafai-widget .shafai-bubble th { background: #f1f5f9; font-weight: 700 !important; }

/* 10. Input Area & Footer */
#shafai-widget .shafai-input-area {
    background: #fff;
    padding: 16px;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

#shafai-widget .shafai-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#shafai-widget .shafai-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 24px;
    font-size: 15px;
    font-family: 'Spectral', serif !important;
    resize: none;
    outline: none;
    max-height: 120px;
    background: #fff;
    color: #333;
    transition: border-color 0.2s;
}

#shafai-widget .shafai-input:focus {
    border-color: #009688;
}

#shafai-widget .shafai-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #009688, #00796b);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.2s;
    flex-shrink: 0;
}

#shafai-widget .shafai-send:hover { transform: scale(1.05); }
#shafai-widget .shafai-send svg { width: 20px; height: 20px; fill: #fff; }

#shafai-widget .shafai-footer {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #94a3b8;
    margin-top: 10px;
    padding: 0 4px;
}

#shafai-widget .shafai-credits strong { color: #009688; }

/* 11. Typing Indicator */
#shafai-widget .shafai-typing {
    display: none;
    margin-left: 46px;
    margin-bottom: 20px;
}
#shafai-widget .shafai-typing-dots {
    background: #f1f3f5;
    padding: 12px 16px;
    border-radius: 12px;
    border-top-left-radius: 2px;
    display: flex;
    gap: 5px;
}
#shafai-widget .shafai-typing-dots span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: shafaiBounce 1.4s infinite ease-in-out;
}
#shafai-widget .shafai-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
#shafai-widget .shafai-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes shafaiBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* =========================================
   MOBILE RESPONSIVE FIX
   ========================================= */
@media (max-width: 480px) {
    #shafai-widget {
        bottom: 0; right: 0; left: 0;
        width: 100%; height: 0;
        pointer-events: none;
    }

    #shafai-widget .shafai-toggle {
        position: fixed; bottom: 20px; right: 20px;
        pointer-events: auto;
    }

    #shafai-widget.shafai-open { height: 100%; }

    #shafai-widget .shafai-container {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: none !important;
        border-radius: 0;
        margin: 0;
        z-index: 999999999;
    }

    #shafai-widget .shafai-header { padding: 12px 16px; }
    #shafai-widget .shafai-messages { padding: 15px; }
    #shafai-widget .shafai-bubble { font-size: 15px; padding: 10px 14px; }
}