/* ============================================================
   Widget Chatbot — Jernih Assist
   Memakai CSS variable template Orisa (--at-*) agar otomatis
   mengikuti tema light/dark (data-bs-theme).
   ============================================================ */

.chatbot {
    /* Warna mengikuti tema JernihNet (navy #101c2d) yang dipakai
       pada navbar, halaman registrasi, dan elemen brand lainnya. */
    --cb-accent: #101c2d;
    --cb-accent-soft: #3795d1;
    --cb-bg: var(--at-neutral-0, #FEFEFE);
    --cb-fg: var(--at-neutral-950, #0F0F0F);
    --cb-muted: var(--at-neutral-900, #1D1D1D);
    --cb-bubble-bg: var(--at-common-white, #FEFEFE);
    --cb-bubble-border: rgba(0, 0, 0, .08);

    position: fixed;
    right: 50px;
    bottom: 24px; /* menempel di pojok kanan bawah sebelum halaman di-scroll */
    z-index: 99999; /* di atas #magic-cursor & back-to-top */
    font-family: inherit;
    line-height: 1.4;
    transition: bottom .4s cubic-bezier(.22, .61, .36, 1);
}

/* Saat tombol back-to-top muncul, ikon chat naik & memberi jarak */
.back-to-top-wrapper.back-to-top-btn-show ~ .chatbot {
    bottom: 110px;
}

/* ---- Bubble ajakan "Butuh bantuan?" ---- */
.chatbot-teaser {
    position: absolute;
    right: calc(100% + 16px);
    top: 50%;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 16px;
    border-radius: 18px 18px 4px 18px;
    background: var(--cb-bg);
    color: var(--cb-fg);
    border: 1px solid var(--cb-bubble-border);
    box-shadow: 0 12px 30px rgba(0, 0, 0, .18);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transform-origin: right bottom;
    opacity: 0;
    transform: translate(18px, -50%) scale(.45);
    transition: opacity .3s ease, transform .5s cubic-bezier(.18, .89, .32, 1.35);
    pointer-events: none;
}

.chatbot-teaser::after {
    content: '';
    position: absolute;
    right: -7px;
    bottom: 12px;
    width: 14px;
    height: 14px;
    background: var(--cb-bg);
    border-right: 1px solid var(--cb-bubble-border);
    border-bottom: 1px solid var(--cb-bubble-border);
    transform: rotate(-45deg);
    border-radius: 0 0 3px 0;
}

.chatbot-teaser.is-visible {
    opacity: 1;
    transform: translate(0, -50%) scale(1);
    pointer-events: auto;
    animation: cb-teaser-float 3s ease-in-out .6s infinite;
}

.chatbot-teaser__wave {
    display: inline-block;
    animation: cb-wave 2.4s ease-in-out infinite;
    transform-origin: 70% 70%;
}

.chatbot.is-open .chatbot-teaser {
    display: none;
}

@keyframes cb-teaser-float {
    0%, 100% { transform: translate(0, -50%) scale(1); }
    50%      { transform: translate(0, calc(-50% - 4px)) scale(1); }
}

@keyframes cb-wave {
    0%, 60%, 100% { transform: rotate(0); }
    10%, 30%      { transform: rotate(16deg); }
    20%, 40%      { transform: rotate(-8deg); }
}

/* ---- Tombol melayang ---- */
.chatbot-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--cb-accent);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .28);
    transition: transform .2s ease, box-shadow .2s ease;
    position: relative;
}

.chatbot-toggle:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 14px 34px rgba(0, 0, 0, .32);
}

.chatbot-toggle:focus-visible {
    outline: 3px solid rgba(16, 28, 45, .35);
    outline-offset: 3px;
}

/* Cincin denyut untuk menarik perhatian */
.chatbot-toggle::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid var(--cb-accent);
    opacity: 0;
    animation: cb-ring 2.6s ease-out infinite;
    pointer-events: none;
}

.chatbot.is-open .chatbot-toggle::before {
    animation: none;
    opacity: 0;
}

@keyframes cb-ring {
    0%   { transform: scale(.82); opacity: .65; }
    70%  { transform: scale(1.38); opacity: 0; }
    100% { transform: scale(1.38); opacity: 0; }
}

.chatbot-toggle-icon {
    display: inline-flex;
}

.chatbot-toggle-icon--close {
    display: none;
}

/* Panel terbuka -> ganti ikon */
.chatbot.is-open .chatbot-toggle-icon--chat {
    display: none;
}

.chatbot.is-open .chatbot-toggle-icon--close {
    display: inline-flex;
}

/* ---- Panel chat ---- */
.chatbot-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 14px);
    width: min(380px, calc(100vw - 32px));
    background: var(--cb-bg);
    color: var(--cb-fg);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .30);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform-origin: bottom right;
    animation: cb-pop .22s ease;
}

.chatbot-panel[hidden] {
    display: none;
}

@keyframes cb-pop {
    from { opacity: 0; transform: translateY(12px) scale(.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.chatbot-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--cb-accent), var(--cb-accent-soft));
    color: #fff;
}

.chatbot-panel__brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-panel__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .22);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: .5px;
}

.chatbot-panel__title {
    margin: 0;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
    color: #fff;
}

.chatbot-panel__status {
    margin: 2px 0 0;
    font-size: 12px;
    line-height: 1.3;
    color: rgba(255, 255, 255, .85);
}

.chatbot-panel__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .2);
    color: #fff;
    cursor: pointer;
    transition: background .2s ease;
}

.chatbot-panel__close:hover {
    background: rgba(255, 255, 255, .32);
}

/* Body pesan */
.chatbot-body {
    min-height: 260px;
    max-height: 46vh;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    word-break: break-word;
    white-space: pre-wrap;
}

.chatbot-msg--bot {
    align-self: flex-start;
    background: var(--cb-bubble-bg);
    color: var(--cb-fg);
    border: 1px solid var(--cb-bubble-border);
    border-bottom-left-radius: 4px;
}

.chatbot-msg--user {
    align-self: flex-end;
    background: var(--cb-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chatbot-msg--error {
    background: rgba(220, 38, 38, .12);
    color: var(--cb-fg);
    border: 1px solid rgba(220, 38, 38, .3);
}

.chatbot-msg--typing {
    color: var(--cb-muted);
    font-style: italic;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.chatbot-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: cb-blink 1.2s infinite;
}

.chatbot-typing-dot:nth-child(2) { animation-delay: .2s; }
.chatbot-typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes cb-blink {
    0%, 80%, 100% { opacity: .3; }
    40% { opacity: 1; }
}

/* Form kirim */
.chatbot-form {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--cb-bubble-border);
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--cb-bubble-border);
    border-radius: 24px;
    padding: 11px 16px;
    /* Minimal 16px: di iOS, input < 16px membuat halaman auto-zoom
       saat difokuskan sehingga tampilan "lari-lari". */
    font-size: 16px;
    background: var(--cb-bubble-bg);
    color: var(--cb-fg);
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease;
}

.chatbot-input::placeholder {
    color: var(--cb-muted);
    opacity: .6;
}

.chatbot-input:focus {
    border-color: var(--cb-accent);
    box-shadow: 0 0 0 3px rgba(16, 28, 45, .14);
}

.chatbot-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border: none;
    border-radius: 50%;
    background: var(--cb-accent);
    color: #fff;
    cursor: pointer;
    transition: opacity .2s ease, transform .2s ease;
}

.chatbot-send:hover { transform: translateY(-1px); }
.chatbot-send:disabled {
    opacity: .5;
    cursor: not-allowed;
    transform: none;
}

/* ---- Responsif kecil di layar sangat sempit ---- */
@media (max-width: 574.98px) {
    .chatbot { right: 20px; bottom: 40px; }
    .back-to-top-wrapper.back-to-top-btn-show ~ .chatbot { bottom: 104px; }
    .chatbot-toggle { width: 44px; height: 44px; }
    .chatbot-teaser { font-size: 13px; padding: 9px 13px; }
}