/* ==========================================================================
   AI CHATBOT WIDGET
   ========================================================================== */
:root {
    --chat-primary: #047d78;
    --chat-primary-dark: #035f5b;
    --chat-primary-light: #e6f5f4;
}

.ai-chatbot-button {
    position: fixed;
    right: 24px;
    bottom: 100px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 0;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: #fff;
    box-shadow: 0 10px 28px rgba(4, 125, 120, 0.35);
    z-index: 9999;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-chatbot-button:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 14px 34px rgba(4, 125, 120, 0.45);
}

.ai-chatbot-button:active {
    transform: scale(0.96);
}

.ai-chatbot-button .ai-btn-icon-close {
    display: none;
}

.ai-chatbot-button.is-open .ai-btn-icon-chat {
    display: none;
}

.ai-chatbot-button.is-open .ai-btn-icon-close {
    display: block;
}

.ai-chatbot-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ff5a5f;
    border: 2px solid #fff;
}

.ai-chatbot-box {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22), 0 4px 14px rgba(0, 0, 0, 0.08);
    z-index: 9999999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #eceff1;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
    transform-origin: bottom right;
}

.ai-chatbot-box.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---- Header ---- */
.ai-chatbot-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: #fff;
    flex-shrink: 0;
}

.ai-chatbot-avatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.ai-chatbot-status-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ade80;
    border: 2px solid var(--chat-primary);
}

.ai-chatbot-header-text {
    flex: 1;
    min-width: 0;
}

.ai-chatbot-header-text strong {
    display: block;
    font-size: 14.5px;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chatbot-header-text span {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 5px;
}

.ai-chatbot-header-text span::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}

.ai-chatbot-close {
    background: rgba(255, 255, 255, 0.16);
    border: none;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.ai-chatbot-close:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* ---- Messages ---- */
.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f7f9fa;
    scroll-behavior: smooth;
}

.ai-chatbot-messages::-webkit-scrollbar {
    width: 5px;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

.ai-msg {
    margin-bottom: 12px;
    padding: 11px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    max-width: 88%;
    animation: aiMsgIn 0.18s ease;
}

@keyframes aiMsgIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-msg.user {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: #fff;
    margin-left: auto;
    border-bottom-right-radius: 4px;
    box-shadow: 0 3px 10px rgba(4, 125, 120, 0.25);
}

.ai-msg.assistant {
    background: #fff;
    color: #111827;
    margin-right: auto;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.04));
}

.ai-msg-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 12px;
}

.ai-msg-row .ai-msg {
    margin-bottom: 0;
}

.ai-msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--chat-primary-light);
    color: var(--chat-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    flex-shrink: 0;
}

/* ---- Typing indicator ---- */
.ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 2px;
}

.ai-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: aiTypingBounce 1.1s infinite ease-in-out;
}

.ai-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.ai-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes aiTypingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ---- Rich content inside assistant message ---- */
.ai-msg.assistant p {
    margin: 6px 0;
    line-height: 1.55;
    margin-top: 0px;
}

.ai-msg.assistant h3,
.ai-msg.assistant h4,
.ai-msg.assistant h5 {
    margin: 8px 0 6px;
    font-weight: 700;
    line-height: 1.3;
}

.ai-msg.assistant ol.ai-list,
.ai-msg.assistant ul.ai-list {
    padding-left: 18px;
    margin: 8px 0;
    list-style-position: outside;
}

.ai-msg.assistant ol.ai-list {
    list-style-type: decimal;
}

.ai-msg.assistant ul.ai-list {
    list-style-type: disc;
}

.ai-msg.assistant li {
    display: list-item;
    margin: 3px 0;
    line-height: 1.55;
}

.ai-msg.assistant strong {
    font-weight: 700;
}

.ai-msg.assistant em {
    font-style: italic;
}

.ai-msg.assistant a {
    color: var(--chat-primary);
    text-decoration: none;
    word-break: break-word;
    font-weight: 600;
}

.ai-msg.assistant a:hover {
    text-decoration: underline;
}

/* ---- Sources / source buttons ---- */
.ai-sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #e5e7eb;
}

.ai-sources-title {
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #6b7280;
    margin-bottom: 8px;
}

.ai-source-button {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-bottom: 6px;
    padding: 8px 10px;
    border-radius: 10px;
    background: #eef6ff;
    color: #0d6efd;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    line-height: 1.35;
    transition: background 0.15s ease;
}

.ai-source-button:hover {
    background: #dbeafe;
    text-decoration: none;
}

.ai-source-buttons {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.ai-source-detail-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 11px;
    border-radius: 10px;
    background: var(--chat-primary);
    color: #ffffff !important;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
    text-decoration: none !important;
    transition: background 0.15s ease;
}

.ai-source-detail-btn:hover {
    background: var(--chat-primary-dark);
}

/* ---- Quick reply chips ---- */
.ai-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 0 16px 12px;
    background: #f7f9fa;
}

.ai-quick-chip {
    border: 1px solid #d7e4e3;
    background: #fff;
    color: var(--chat-primary-dark);
    font-size: 12px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}

.ai-quick-chip:hover {
    background: var(--chat-primary-light);
    border-color: var(--chat-primary);
}

/* ---- Input form ---- */
.ai-chatbot-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #eceff1;
    background: #fff;
    flex-shrink: 0;
}

.ai-chatbot-form input {
    flex: 1;
    border: 1px solid #dfe3e6;
    border-radius: 999px;
    padding: 11px 16px;
    outline: none;
    font-size: 13.5px;
    background: #f7f9fa;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.ai-chatbot-form input:focus {
    border-color: var(--chat-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(4, 125, 120, 0.12);
}

.ai-chatbot-form input::placeholder {
    color: #9ca3af;
}

.ai-chatbot-form button {
    border: 0;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.ai-chatbot-form button:hover {
    transform: scale(1.06);
}

.ai-chatbot-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

@media (max-width: 480px) {
    .ai-chatbot-box {
        right: 12px;
        bottom: 84px;
        width: calc(100vw - 24px);
    }

    .ai-chatbot-button {
        right: 16px;
        bottom: 16px;
    }
}
/* ==========================================================================
   AI CHATBOT - SVG ICON SIZING
   ========================================================================== */
.ai-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: block;
}

.ai-chatbot-avatar .ai-icon {
    width: 20px;
    height: 20px;
}

.ai-msg-avatar .ai-icon {
    width: 15px;
    height: 15px;
}

.ai-chatbot-form button .ai-icon {
    width: 17px;
    height: 17px;
    margin-left: 1px;
}

/* ==========================================================================
   AI CHATBOT - SOURCE DETAIL CARD (hasil pencarian koleksi)
   ========================================================================== */
.ai-sources {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.ai-source-card {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

.ai-source-card > p {
    margin: 0;
    padding: 12px 14px;
    background: var(--chat-primary-light);
    border-bottom: 1px solid #e5e7eb;
}

.ai-source-card > p strong {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--chat-primary-dark);
    line-height: 1.4;
}

.ai-source-item {
    padding: 9px 14px;
    border-bottom: 1px solid #f1f3f5;
    font-size: 12.5px;
}

.ai-source-item:last-child {
    border-bottom: none;
}

.ai-source-item strong {
    display: block;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #9ca3af;
    margin-bottom: 3px;
}

.ai-source-item > div {
    color: #374151;
    line-height: 1.5;
    word-break: break-word;
}

.ai-source-card .ai-source-detail-btn {
    margin: 10px 14px 12px;
    width: calc(100% - 28px);
}
.ai-example-chips {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}

.ai-example-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
    width: 100%;
    border: 1px solid #e5e7eb;
    background: #f7f9fa;
    color: var(--chat-primary-dark);
    font-size: 12.5px;
    font-weight: 600;
    padding: 9px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.ai-example-chip::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--chat-primary);
    flex-shrink: 0;
}

.ai-example-chip:hover {
    background: var(--chat-primary-light);
    border-color: var(--chat-primary);
    transform: translateX(2px);
}

.ai-chatbot-box {
    position: fixed; /* pastikan tetap ada dari sebelumnya, konteks buat posisi absolute anak */
}

.ai-scroll-bottom-btn {
    position: absolute;
    right: 16px;
    bottom: 78px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: var(--chat-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
    cursor: pointer;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease, background 0.15s ease;
    z-index: 5;
}

.ai-scroll-bottom-btn.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.ai-scroll-bottom-btn:hover {
    background: var(--chat-primary-light);
}

.ai-scroll-bottom-btn .ai-icon {
    width: 16px;
    height: 16px;
}

/* ==========================================================================
   AI CHATBOT - REKOMENDASI KATA KUNCI (saat pencarian tidak ditemukan)
   ========================================================================== */
.ai-recommendations {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 8px;
}

.ai-recommendation-btn {
    border: 1px solid var(--chat-primary);
    background: #fff;
    color: var(--chat-primary-dark);
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 13px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.ai-recommendation-btn:hover {
    background: var(--chat-primary);
    color: #fff;
    transform: translateY(-1px);
}

.ai-recommendation-btn:active {
    transform: translateY(0);
}
