/* ==========================================================================
   AI ASSISTANT WIDGET — JC-KOK Portal
   Premium chat widget with glassmorphism & dark mode support
   ========================================================================== */

/* ── Mobile Mini Robot FAB (melayang di sudut avatar navbar) ──────────── */
.ai-mobile-avatar-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* Tombol robot kecil di pojok kanan-bawah foto profil */
.ai-mobile-mini-fab {
    position: absolute;
    bottom: -5px;
    right: -7px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #A0522D, #C8702E);
    border: 2px solid rgba(255,255,255,0.85);
    color: #fff;
    font-size: 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(160,82,45,0.55);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
    padding: 0;
    animation: ai-mini-pulse 3s infinite 3s;
}
@keyframes ai-mini-pulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(160,82,45,0.55), 0 0 0 0 rgba(160,82,45,0.5); }
    50%       { box-shadow: 0 2px 8px rgba(160,82,45,0.55), 0 0 0 6px rgba(160,82,45,0); }
}
.ai-mobile-mini-fab:hover, .ai-mobile-mini-fab:active {
    transform: scale(1.25);
    box-shadow: 0 4px 14px rgba(160,82,45,0.7);
    animation: none;
}

/* Guest variant: standalone (tanpa avatar) */
.ai-mobile-mini-fab--guest {
    position: static;
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
    border: 1.5px solid rgba(255,255,255,0.45);
    border-radius: 50%;
    flex-shrink: 0;
}

/* Desktop: sembunyikan avatar-wrap mini fab */
@media (min-width: 992px) {
    .ai-mobile-mini-fab { display: none !important; }
    .ai-mobile-avatar-wrap .ai-mobile-mini-fab { display: none !important; }
}


.ai-fab {
    position: fixed;
    bottom: 100px;      /* above the Bible FAB */
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #A0522D 0%, #C8702E 100%);
    color: #fff;
    border: none;
    box-shadow: 0 6px 24px rgba(160, 82, 45, 0.45), 0 0 0 0 rgba(160, 82, 45, 0.4);
    cursor: pointer;
    z-index: 1045;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.3s ease,
                background 0.3s ease;
    animation: ai-pulse 3s infinite 2s;
}
@keyframes ai-pulse {
    0%, 100% { box-shadow: 0 6px 24px rgba(160,82,45,0.45), 0 0 0 0 rgba(160,82,45,0.4); }
    50%       { box-shadow: 0 6px 24px rgba(160,82,45,0.45), 0 0 0 12px rgba(160,82,45,0); }
}
.ai-fab:hover {
    transform: scale(1.12);
    background: linear-gradient(135deg, #8B4513 0%, #A0522D 100%);
    box-shadow: 0 10px 32px rgba(160, 82, 45, 0.55);
    animation: none;
}
.ai-fab.open {
    transform: rotate(45deg) scale(1.05);
    animation: none;
    background: linear-gradient(135deg, #5A2D0C 0%, #8B4513 100%);
}

/* Badge unread */
.ai-fab-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #e74c3c;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    display: none;
}
.ai-fab-badge.show { display: flex; }

/* Mobile: hide desktop FAB, show sidebar button only */
@media (max-width: 991.98px) {
    .ai-fab {
        display: none !important;
    }
}

/* ── Chat Panel ────────────────────────────────────────────────────────── */
.ai-chat-panel {
    position: fixed;
    bottom: 168px;      /* above the fab */
    right: 20px;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 200px);
    background: rgba(253, 251, 247, 0.97);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 4px 20px rgba(160,82,45,0.12);
    border: 1px solid rgba(160, 82, 45, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1044;
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.3s ease;
}
.ai-chat-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* Panel header */
.ai-panel-header {
    background: linear-gradient(135deg, #A0522D 0%, #C8702E 100%);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.ai-avatar-circle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #fff;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.35);
}
.ai-panel-title {
    flex: 1;
}
.ai-panel-title .name {
    font-weight: 700;
    color: #fff;
    font-size: 0.95rem;
    line-height: 1.2;
}
.ai-panel-title .status {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    gap: 5px;
}
.ai-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #2ecc71;
    box-shadow: 0 0 6px rgba(46,204,113,0.8);
    animation: blink 2s infinite;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}
.ai-close-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}
.ai-close-btn:hover {
    background: rgba(255,255,255,0.28);
    transform: rotate(90deg);
}

/* Messages area */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}
.ai-messages::-webkit-scrollbar { width: 4px; }
.ai-messages::-webkit-scrollbar-track { background: transparent; }
.ai-messages::-webkit-scrollbar-thumb {
    background: rgba(160,82,45,0.25);
    border-radius: 4px;
}

/* Message bubble */
.ai-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: break-word;
}
.ai-bubble.ai {
    background: #fff;
    color: #2c1810;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid rgba(160,82,45,0.1);
}
.ai-bubble.user {
    background: linear-gradient(135deg, #A0522D, #8B4513);
    color: #fff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
    box-shadow: 0 2px 12px rgba(160,82,45,0.3);
}
.ai-bubble .ai-bubble-time {
    font-size: 0.68rem;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}
.ai-bubble.ai .ai-bubble-time { text-align: left; }

/* Links inside AI responses */
.ai-bubble.ai a {
    color: #A0522D;
    font-weight: 600;
    text-decoration: underline;
    word-break: break-all;
}
.ai-bubble.ai a:hover { color: #5A2D0C; }

/* Loading dots */
.ai-loading {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid rgba(160,82,45,0.1);
}
.ai-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #A0522D;
    animation: bounce-dot 1.2s infinite ease-in-out;
}
.ai-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce-dot {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%            { transform: translateY(-8px); opacity: 1; }
}

/* Suggestion chips */
.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0 8px;
}
.ai-chip {
    background: rgba(160, 82, 45, 0.08);
    border: 1px solid rgba(160, 82, 45, 0.2);
    color: #8B4513;
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}
.ai-chip:hover {
    background: rgba(160, 82, 45, 0.15);
    color: #5A2D0C;
}

/* Guest limit banner */
.ai-guest-banner {
    background: linear-gradient(135deg, #fff8f0, #ffeedd);
    border-top: 1px solid rgba(160,82,45,0.15);
    padding: 14px 16px;
    text-align: center;
    flex-shrink: 0;
}
.ai-guest-banner p {
    font-size: 0.82rem;
    color: #6d3a1a;
    margin-bottom: 10px;
    font-weight: 500;
}
.ai-guest-banner .btn { font-size: 0.82rem; padding: 6px 16px; border-radius: 20px; }

/* Input area */
.ai-input-area {
    padding: 12px 14px;
    background: rgba(253,251,247,0.95);
    border-top: 1px solid rgba(160,82,45,0.1);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}
.ai-input {
    flex: 1;
    border: 1.5px solid rgba(160,82,45,0.25);
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 0.875rem;
    resize: none;
    max-height: 100px;
    background: #fff;
    color: #2c1810;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    line-height: 1.4;
}
.ai-input:focus {
    border-color: #A0522D;
    box-shadow: 0 0 0 3px rgba(160,82,45,0.12);
}
.ai-input::placeholder { color: #b09080; font-size: 0.83rem; }
.ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #A0522D, #8B4513);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
    transition: transform 0.2s, background 0.2s;
    align-self: flex-end;
}
.ai-send-btn:hover { transform: scale(1.1); background: linear-gradient(135deg, #8B4513, #5A2D0C); }
.ai-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Char counter */
.ai-char-count {
    font-size: 0.68rem;
    color: rgba(160,82,45,0.5);
    text-align: right;
    padding: 0 16px 6px;
    flex-shrink: 0;
}
.ai-char-count.warn { color: #e74c3c; }

/* ── Mobile Sidebar Button (inside offcanvas .oc-user-block) ────────────── */
.ai-sidebar-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #A0522D, #C8702E);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 7px 15px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
    width: 100%;
    justify-content: center;
    box-shadow: 0 3px 10px rgba(160,82,45,0.3);
}
.ai-sidebar-btn:hover {
    background: linear-gradient(135deg, #8B4513, #A0522D);
    transform: translateY(-1px);
}
.ai-sidebar-btn i { font-size: 0.9rem; }

/* Mobile chat panel: full-width slide from bottom */
@media (max-width: 991.98px) {
    .ai-chat-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        height: 72vh;
        max-height: 72vh;
        transform: translateY(100%);
        z-index: 1070;
    }
    .ai-chat-panel.open {
        transform: translateY(0);
    }
    /* Overlay behind mobile panel */
    .ai-mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0);
        z-index: 1069;
        pointer-events: none;
        transition: background 0.35s ease;
    }
    .ai-mobile-overlay.show {
        background: rgba(0,0,0,0.5);
        pointer-events: all;
    }
}

/* ── Dark Mode ──────────────────────────────────────────────────────────── */
html.dark-mode .ai-chat-panel, body.dark-mode .ai-chat-panel {
    background: rgba(20, 20, 20, 0.97);
    border-color: rgba(240,192,144,0.12);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
html.dark-mode .ai-bubble.ai, body.dark-mode .ai-bubble.ai {
    background: #2a2a2a;
    color: #e0e0e0;
    border-color: rgba(240,192,144,0.1);
}
html.dark-mode .ai-bubble.ai a, body.dark-mode .ai-bubble.ai a {
    color: #E8A87C;
}
html.dark-mode .ai-loading, body.dark-mode .ai-loading {
    background: #2a2a2a;
    border-color: rgba(240,192,144,0.1);
}
html.dark-mode .ai-dot, body.dark-mode .ai-dot { background: #E8A87C; }
html.dark-mode .ai-chip, body.dark-mode .ai-chip {
    background: rgba(240,192,144,0.08);
    border-color: rgba(240,192,144,0.2);
    color: #E8A87C;
}
html.dark-mode .ai-chip:hover, body.dark-mode .ai-chip:hover {
    background: rgba(240,192,144,0.15);
    color: #F0C090;
}
html.dark-mode .ai-input-area, body.dark-mode .ai-input-area {
    background: rgba(20,20,20,0.95);
    border-top-color: rgba(240,192,144,0.1);
}
html.dark-mode .ai-input, body.dark-mode .ai-input {
    background: #2a2a2a;
    border-color: rgba(240,192,144,0.2);
    color: #e0e0e0;
}
html.dark-mode .ai-input:focus, body.dark-mode .ai-input:focus {
    border-color: #E8A87C;
    box-shadow: 0 0 0 3px rgba(232,168,124,0.12);
}
html.dark-mode .ai-input::placeholder, body.dark-mode .ai-input::placeholder { color: #666; }
html.dark-mode .ai-guest-banner, body.dark-mode .ai-guest-banner {
    background: linear-gradient(135deg, #1e1200, #2a1800);
    border-top-color: rgba(240,192,144,0.1);
}
html.dark-mode .ai-guest-banner p, body.dark-mode .ai-guest-banner p {
    color: #E8A87C;
}
html.dark-mode #globalBibleContent, body.dark-mode #globalBibleContent {
    background: #1e1e1e;
    border-color: #383838;
}
