/* ===========================
   Chatbot Serindit Styling
   Balai Bahasa Provinsi Riau
   =========================== */

/* --- RESET & FIX OVERFLOW --- */
#icak-chatbot-container,
#icak-chatbot-container * {
    box-sizing: border-box;
}

#icak-chatbot-container {
    font-family: "Plus Jakarta Sans", sans-serif;
    z-index: 9999;
    position: fixed;
    bottom: 0;
    right: 0;
    pointer-events: none;
    overflow: clip;
    max-width: 100vw;
}

/* Aktifkan klik hanya untuk elemen chatbot */
#icak-chatbot-container #icak-trigger-btn,
#icak-chatbot-container #icak-chat-window {
    pointer-events: auto;
}

/* Pastikan HANYA icon FontAwesome yang menggunakan font Font Awesome */
#icak-chatbot-container [class*="fa-"],
#icak-chatbot-container .fa-solid,
#icak-chatbot-container .fa-regular,
#icak-chatbot-container .fa {
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900;
}

/* Pastikan semua elemen bubble pesan chat (teks, italic, bold, dsb) memakai font normal */
#icak-chatbot-container .chat-bubble,
#icak-chatbot-container .chat-bubble *:not([class*="fa-"]) {
    font-family: "Plus Jakarta Sans", sans-serif !important;
    letter-spacing: normal;
}

#icak-chatbot-container .chat-bubble i:not([class*="fa-"]),
#icak-chatbot-container .chat-bubble em {
    font-style: italic !important;
    font-weight: normal !important;
}

/* =========================================
   1. STICKY TRIGGER BUTTON: CLEAN MASCOT PILL
   ========================================= */
#icak-trigger-btn,
.chat-toggle-btn {
    position: fixed;
    bottom: 56px; /* Diturunkan sedikit agar lebih rileks & proporsional */
    right: 24px;
    z-index: 10000;
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 0;
    width: 48px;
    max-width: 48px;
    height: 48px;
    border-radius: 9999px;
    background: #ffffff;
    border: 1.5px solid rgba(56, 189, 248, 0.45);
    color: #0f172a;
    box-shadow: 0 10px 25px -4px rgba(14, 165, 233, 0.25), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    text-decoration: none;
    outline: none;
    overflow: visible !important;
    transition: width 0.32s cubic-bezier(0.16, 1, 0.3, 1),
                max-width 0.32s cubic-bezier(0.16, 1, 0.3, 1),
                padding 0.28s ease,
                gap 0.28s ease,
                background-color 0.2s ease,
                border-color 0.2s ease,
                box-shadow 0.2s ease;
}

/* HOVER & SAAT DIBUKA (EXPAND & COLLAPSE SUTRA HALUS SIMETRIS) */
#icak-trigger-btn:hover,
.chat-toggle-btn:hover,
#icak-trigger-btn.chat-open,
.chat-toggle-btn.chat-open {
    width: 252px !important; /* Fit to text penuh tanpa terpotong */
    max-width: calc(100vw - 32px) !important;
    padding: 0 12px 0 6px;
    gap: 8px;
    justify-content: flex-start;
    background: linear-gradient(135deg, #ffffff 0%, #f0f9ff 30%, #e0f2fe 70%, #d1fae5 100%);
    border-color: #0284c7;
    box-shadow: 0 14px 34px -4px rgba(14, 165, 233, 0.32), 0 0 0 1px rgba(2, 132, 199, 0.25);
}

/* Avatar with Online Dot */
.chat-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.chat-avatar-circle {
    width: 34px;
    height: 34px;
    border-radius: 9999px;
    overflow: hidden;
    padding: 2px;
    background: #ffffff;
    border: 1.5px solid rgba(56, 189, 248, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 9999px;
}

.chat-online-badge {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    border-radius: 9999px;
    background: #10b981;
    box-shadow: 0 0 0 2px #ffffff;
}

/* Badge 99+ Unread: Posisi melayang DI LUAR lingkaran avatar */
.chat-unread-badge {
    position: absolute;
    top: -6px;
    right: -8px;
    background: #ef4444;
    color: #ffffff;
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
    padding: 2.5px 5.5px;
    border-radius: 999px;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    z-index: 30;
    letter-spacing: -0.2px;
    pointer-events: none;
    white-space: nowrap;
}
/* Text Column */
.chat-text-col {
    display: flex;
    flex-direction: column;
    text-align: left;
    line-height: 1;
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transform: translateX(8px);
    transition: opacity 0.24s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), max-width 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

#icak-trigger-btn:hover .chat-text-col,
.chat-toggle-btn:hover .chat-text-col,
#icak-trigger-btn.chat-open .chat-text-col,
.chat-toggle-btn.chat-open .chat-text-col {
    opacity: 1;
    max-width: 260px !important;
    transform: translateX(0);
    pointer-events: auto;
}
.chat-title-row {
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1;
}

.chat-title {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #0f172a;
    white-space: nowrap;
    font-family: "Plus Jakarta Sans", sans-serif;
}

.chat-badge-pro {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 9px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-weight: 700;
    text-transform: uppercase;
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
    line-height: 1;
}

.chat-subtitle {
    display: inline-block;
    font-size: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    color: #334155;
    font-weight: 500;
    line-height: 1.25;
    margin-top: 3px;
    white-space: nowrap;
    transition: color 0.2s ease;
}

.chat-toggle-btn:hover .chat-subtitle,
#icak-trigger-btn:hover .chat-subtitle {
    color: #0284c7;
}

/* Live Pulse Radar */
.chat-pulse-wrap {
    display: flex;
    height: 8px;
    width: 8px;
    position: relative;
    margin-left: 2px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    transition: opacity 0.2s ease, max-width 0.35s ease;
}

#icak-trigger-btn:hover .chat-pulse-wrap,
.chat-toggle-btn:hover .chat-pulse-wrap,
#icak-trigger-btn.chat-open .chat-pulse-wrap,
.chat-toggle-btn.chat-open .chat-pulse-wrap {
    opacity: 1;
    max-width: 20px;
}
.chat-pulse-ping {
    position: absolute;
    display: inline-flex;
    height: 100%;
    width: 100%;
    background: #10b981;
    opacity: 0.75;
    animation: chatPulsePing 1.2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.chat-pulse-dot {
    position: relative;
    display: inline-flex;
    border-radius: 9999px;
    height: 8px;
    width: 8px;
    background: #10b981;
}

@keyframes chatPulsePing {
    75%, 100% {
        transform: scale(2.2);
        opacity: 0;
    }
}
/* =========================================
   2. JENDELA CHAT DESKTOP
   ========================================= */
#icak-chat-window {
    position: fixed;
    bottom: 120px; /* Selaras dengan posisi tombol */
    right: 28px;
    width: 370px;
    max-width: calc(100vw - 56px);
    height: 500px;
    max-height: calc(100vh - 170px);
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
    border: 1px solid #cbd5e1;
    animation: slideUpChat 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideUpChat {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.icak-header {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
    color: white;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

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

.header-avatar-circle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.header-serindit-img {
    width: 38px;
    height: 38px;
    object-fit: contain;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15));
}

.chat-header-title {
    font-size: 16px;
    margin: 0;
    font-weight: 700;
    color: white;
    line-height: 1.2;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
}

.status-container {
    font-size: 11.5px;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
}

.close-chat {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.close-chat:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* =========================================
   3. BODY & BUBBLES
   ========================================= */
.icak-body {
    flex: 1;
    background: #f8fafc;
    padding: 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    animation: fadeInChat 0.25s ease;
}

.bot-msg {
    align-self: flex-start;
    background: #ffffff;
    color: #1e293b;
    border-bottom-left-radius: 3px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
}

.user-msg {
    align-self: flex-end;
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 3px;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
}

/* =========================================
   4. OPTIONS & MENU CEPAT
   ========================================= */
.icak-options {
    padding: 10px 12px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 140px;
    overflow-y: auto;
    flex-shrink: 0;
}

.option-card {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    padding: 9px 12px;
    border-radius: 8px;
    text-align: left;
    font-size: 12px;
    color: #1e293b;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.option-card:hover {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #1d4ed8;
    transform: translateX(2px);
}

/* =========================================
   5. INPUT FORM
   ========================================= */
.icak-input-wrapper {
    padding: 10px 12px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.icak-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

#icak-chat-input {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f8fafc;
    color: #1e293b;
}

#icak-chat-input:focus {
    border-color: #3b82f6;
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

#icak-send-btn {
    background: #1e3a8a;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.15s;
    flex-shrink: 0;
}

#icak-send-btn:hover {
    background: #2563eb;
    transform: scale(1.06);
}

#icak-send-btn:active {
    transform: scale(0.94);
}

.chat-action-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 6px 12px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.chat-action-link:hover {
    background: #1d4ed8;
    color: #ffffff;
    border-color: #1d4ed8;
}

@keyframes fadeInChat {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
   6. FULL RESPONSIVE MOBILE (NATIVE APP FEEL)
   ========================================= */
@media (max-width: 640px) {
    #icak-trigger-btn,
    .chat-toggle-btn {
        bottom: 42px;
        right: 16px;
        padding: 0;
        width: 44px;
        min-width: 44px;
        height: 44px;
        gap: 0;
    }
    #icak-trigger-btn:hover,
    .chat-toggle-btn:hover,
    #icak-trigger-btn.chat-open,
    .chat-toggle-btn.chat-open {
        width: 236px !important;
        max-width: calc(100vw - 24px) !important;
        padding: 0 10px 0 5px;
        gap: 6px;
    }
    .chat-avatar-circle {
        width: 28px;
        height: 28px;
    }

    .chat-title {
        font-size: 11px;
    }

    .chat-subtitle {
        font-size: 9px;
    }
    /* FULL SCREEN NATIVE CHAT DI MOBILE */
    #icak-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        border: none !important;
        margin: 0 !important;
        z-index: 100000 !important;
        box-shadow: none !important;
    }

    .icak-header {
        padding: 14px 16px;
        border-radius: 0;
    }

    .close-chat {
        width: 38px;
        height: 38px;
        font-size: 18px;
        background: rgba(255, 255, 255, 0.2);
    }

    .icak-body {
        padding: 14px 16px;
        -webkit-overflow-scrolling: touch;
    }

    .chat-bubble {
        max-width: 88%;
        font-size: 14px;
    }

    .icak-options {
        max-height: 150px;
        padding: 8px 12px;
    }

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

    #icak-chat-input {
        font-size: 14px;
        padding: 10px 14px;
    }

    #icak-send-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}
