/* ==========================================================================
   Chatbot publik (Craft)
   Widget mengambang kiri bawah; panel desktop 390px, layar kecil full screen.
   ========================================================================== */

.ccbot {
    font-family: var(--font-sans);
    color: var(--ink);
}

.ccbot-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.ccbot-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* --- Tombol buka --------------------------------------------------------- */
.ccbot-launcher {
    position: fixed;
    left: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 44;
    display: flex;
    align-items: center;
}

.ccbot-launch {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    padding: 0;
    border: 1px solid rgba(251, 250, 245, 0.16);
    border-radius: 50%;
    background: var(--ink);
    box-shadow: 0 18px 40px -16px rgba(11, 31, 31, 0.62);
    color: var(--paper);
    cursor: pointer;
    transition: transform 220ms ease, background 220ms ease;
}

.ccbot-launch::after {
    /* Titik "online" kecil di pojok, penanda asisten aktif. */
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border: 2px solid var(--paper);
    border-radius: 50%;
    background: var(--yellow);
    box-shadow: 0 0 0 3px rgba(11, 31, 31, 0.12);
}

.ccbot-launch:hover {
    transform: translateY(-2px) scale(1.03);
    background: var(--ink-soft);
}

.ccbot-launch:active { transform: scale(0.97); }

.ccbot.is-open .ccbot-launcher { visibility: hidden; }

/* Wajah bbot: bulatan kepala digambar pustaka di dalam tombol. */
.ccbot-face {
    display: block;
    pointer-events: none;
    --face-skin: var(--teal);
    --face-ink: var(--paper);
    --face-ring: rgba(251, 250, 245, 0.42);
}

.ccbot-face svg {
    display: block;
    width: 100%;
    height: 100%;
}

.ccbot-face--launch {
    width: 46px;
    height: 46px;
}

.ccbot-tip {
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translate(-6px, -50%);
    padding: 7px 11px;
    border-radius: 8px;
    background: var(--ink);
    color: var(--paper);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
}

.ccbot-launcher:hover .ccbot-tip,
.ccbot-launch:focus-visible + .ccbot-tip {
    opacity: 1;
    transform: translate(0, -50%);
}

/* --- Panel -------------------------------------------------------------- */
.ccbot-panel {
    position: fixed;
    left: 18px;
    bottom: calc(88px + env(safe-area-inset-bottom));
    z-index: 76;
    display: flex;
    flex-direction: column;
    width: min(392px, calc(100vw - 36px));
    height: min(620px, calc(100dvh - 110px));
    overflow: hidden;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 34px 80px -34px rgba(11, 31, 31, 0.5), 0 10px 24px -18px rgba(11, 31, 31, 0.4);
    opacity: 0;
    transform: translateY(14px) scale(0.985);
    transition: opacity 180ms ease, transform 220ms ease;
}

.ccbot-panel.is-open {
    opacity: 1;
    transform: none;
}

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

.ccbot-head {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 14px 14px 16px;
    background: var(--ink);
    color: var(--paper);
}

.ccbot-head::before {
    /* Garis tipis kuning di atas header, senada aksen situs. */
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--yellow), transparent);
    opacity: 0.7;
}

.ccbot-face--head {
    position: relative;
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    --face-skin: var(--teal);
    --face-ink: var(--paper);
    --face-ring: rgba(251, 250, 245, 0.3);
}

.ccbot-face--head::after {
    /* Halo samar di belakang kepala; berdenyut saat Craft sibuk. */
    content: "";
    position: absolute;
    inset: 5px;
    z-index: 0;
    border-radius: 50%;
    background: var(--teal);
    filter: blur(11px);
    opacity: 0.55;
}

.ccbot-face--head svg { position: relative; z-index: 1; }

.ccbot[data-phase="thinking"] .ccbot-face--head::after,
.ccbot[data-phase="answering"] .ccbot-face--head::after {
    animation: ccbot-halo 2.4s ease-in-out infinite;
}

@keyframes ccbot-halo {
    0%, 100% { transform: scale(0.86); opacity: 0.4; }
    50% { transform: scale(1.16); opacity: 0.85; }
}

.ccbot-id {
    flex: 1;
    min-width: 0;
}

.ccbot-id h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.2;
}

.ccbot-id p {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0 0;
    font-size: 11.5px;
    color: rgba(251, 250, 245, 0.72);
}

.ccbot-online {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #5ee0a0;
    box-shadow: 0 0 0 3px rgba(94, 224, 160, 0.16);
}

.ccbot[data-phase="error"] .ccbot-online {
    background: #f08a78;
    box-shadow: 0 0 0 3px rgba(240, 138, 120, 0.18);
}

.ccbot[data-phase="thinking"] .ccbot-online,
.ccbot[data-phase="answering"] .ccbot-online {
    animation: ccbot-halo 1.8s ease-in-out infinite;
}

.ccbot-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: rgba(251, 250, 245, 0.78);
    cursor: pointer;
    transition: background 160ms ease, color 160ms ease;
}

.ccbot-icon svg {
    width: 17px;
    height: 17px;
}

.ccbot-icon:hover {
    background: rgba(251, 250, 245, 0.12);
    color: var(--paper);
}

/* --- Percakapan --------------------------------------------------------- */
.ccbot-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 14px 6px;
    background:
        radial-gradient(120% 80% at 0% 0%, rgba(12, 122, 122, 0.05), transparent 55%),
        var(--paper);
    scrollbar-width: thin;
    scrollbar-color: rgba(11, 31, 31, 0.24) transparent;
}

.ccbot-log::-webkit-scrollbar { width: 6px; }
.ccbot-log::-webkit-scrollbar-thumb {
    background: rgba(11, 31, 31, 0.2);
    border-radius: 999px;
}

/* --- Wajah hero --------------------------------------------------------- */
.ccbot-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 2px 14px;
    text-align: center;
}

.ccbot-hero[hidden] { display: none; }

.ccbot-hero-face {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 94px;
    height: 94px;
    margin-bottom: 12px;
}

.ccbot-halo {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--teal-100);
    animation: ccbot-halo 4.4s ease-in-out infinite;
}

.ccbot-halo-ring {
    position: absolute;
    inset: 7px;
    border: 1px dashed rgba(12, 122, 122, 0.34);
    border-radius: 50%;
}

.ccbot-face--hero {
    position: relative;
    z-index: 1;
    width: 70px;
    height: 70px;
    --face-skin: var(--teal);
    --face-ink: var(--paper);
    --face-ring: rgba(251, 250, 245, 0.34);
}

.ccbot-greeting {
    max-width: 30ch;
    margin: 0 0 12px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.55;
}

.ccbot-modes {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
    margin-bottom: 10px;
}

.ccbot-mode {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 32px;
    padding: 6px 4px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--white);
    color: var(--muted);
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}

.ccbot-mode:hover { border-color: var(--teal); color: var(--teal-700); }

.ccbot-mode[aria-pressed="true"] {
    border-color: rgba(12, 122, 122, 0.42);
    background: var(--teal-050);
    color: var(--teal-700);
}

.ccbot-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--teal);
    flex: 0 0 auto;
}

.ccbot-suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
}

.ccbot-suggestion {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    min-height: 44px;
    padding: 8px 9px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--white);
    color: var(--ink);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
    transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.ccbot-suggestion:hover {
    transform: translateY(-1px);
    border-color: rgba(12, 122, 122, 0.42);
    box-shadow: 0 8px 18px -12px rgba(11, 31, 31, 0.35);
}

.ccbot-suggestion .ccbot-dot { margin-top: 5px; }

.ccbot-thread { display: flex; flex-direction: column; }

.ccbot-msg {
    display: flex;
    margin-bottom: 10px;
}

.ccbot-msg--user { justify-content: flex-end; }

.ccbot-bubble {
    max-width: 86%;
    padding: 10px 13px;
    border: 1px solid var(--line);
    border-radius: 16px;
    border-bottom-left-radius: 6px;
    background: var(--white);
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.ccbot-msg--user .ccbot-bubble {
    border-color: transparent;
    border-radius: 16px;
    border-bottom-right-radius: 6px;
    background: var(--teal-700);
    color: var(--paper);
    white-space: pre-wrap;
}

.ccbot-bubble p { margin: 0 0 8px; }
.ccbot-bubble p:last-child { margin-bottom: 0; }
.ccbot-bubble ul,
.ccbot-bubble ol {
    margin: 4px 0 8px;
    padding-left: 19px;
}
.ccbot-bubble li { margin: 3px 0; }
.ccbot-bubble li::marker { color: var(--teal); }
.ccbot-bubble a {
    color: var(--teal-700);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.ccbot-msg--user .ccbot-bubble a { color: var(--paper); }
.ccbot-bubble strong { font-weight: 700; }
.ccbot-bubble code {
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--teal-050);
    font-family: var(--font-mono);
    font-size: 0.88em;
}
.ccbot-bubble .ccbot-h {
    font-weight: 700;
    margin-bottom: 4px;
}
.ccbot-bubble--typing { padding: 12px 14px; }

.ccbot-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.ccbot-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--teal);
    opacity: 0.4;
    animation: ccbot-blip 1.1s infinite ease-in-out;
}

.ccbot-typing i:nth-child(2) { animation-delay: 0.15s; }
.ccbot-typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes ccbot-blip {
    0%, 80%, 100% { opacity: 0.28; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.ccbot-note {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 12.5px;
}

/* --- Suggested prompts -------------------------------------------------- */
.ccbot-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 14px 10px;
    background: var(--paper);
}

.ccbot-chips[hidden] { display: none; }

.ccbot-chip {
    padding: 7px 11px;
    border: 1px solid rgba(12, 122, 122, 0.22);
    border-radius: 999px;
    background: var(--teal-050);
    color: var(--teal-700);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.ccbot-chip:hover {
    background: var(--teal-100);
    border-color: rgba(12, 122, 122, 0.34);
}

.ccbot-chip:active { transform: scale(0.97); }

/* --- Kartu ajakan ------------------------------------------------------- */
.ccbot-cta {
    margin: 4px 0 10px;
    padding: 12px;
    border: 1px dashed rgba(11, 31, 31, 0.2);
    border-radius: 14px;
    background: #fbf7d8;
}

.ccbot-cta p {
    margin: 0 0 9px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
}

.ccbot-cta-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.ccbot-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--white);
    color: var(--ink);
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    transition: background 150ms ease, transform 150ms ease;
}

.ccbot-btn:hover { background: var(--paper-2); }
.ccbot-btn:active { transform: scale(0.97); }

.ccbot-btn--primary {
    border-color: var(--ink);
    background: var(--ink);
    color: var(--paper);
}

.ccbot-btn--primary:hover { background: var(--ink-soft); }

/* --- Komposer ----------------------------------------------------------- */
.ccbot-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--line);
    background: var(--paper);
}

.ccbot-form textarea {
    flex: 1;
    min-height: 42px;
    max-height: 96px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--white);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    resize: none;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.ccbot-form textarea::placeholder { color: var(--muted); }

.ccbot-form textarea:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(12, 122, 122, 0.13);
}

.ccbot-form textarea:disabled { opacity: 0.65; }

.ccbot-send {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--teal);
    color: var(--paper);
    cursor: pointer;
    transition: background 160ms ease, transform 160ms ease;
}

.ccbot-send svg {
    width: 19px;
    height: 19px;
    margin-left: -1px;
}

.ccbot-send:hover { background: var(--teal-600); }
.ccbot-send:active { transform: scale(0.95); }

.ccbot-send.is-stop { background: var(--ink); }
.ccbot-send.is-stop svg { display: none; }
.ccbot-send.is-stop::after {
    content: "";
    width: 11px;
    height: 11px;
    border-radius: 2px;
    background: currentColor;
}

.ccbot-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 14px 10px;
    color: var(--muted);
    font-size: 10.5px;
    line-height: 1.4;
}

.ccbot-foot a {
    color: var(--teal-700);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.ccbot-foot a:hover { text-decoration: underline; }

/* --- Layar kecil -------------------------------------------------------- */
@media (max-width: 640px) {
    html.ccbot-lock { overflow: hidden; }

    .ccbot-launcher {
        left: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom));
    }

    .ccbot-launch {
        width: 54px;
        height: 54px;
    }

    .ccbot-face--launch { width: 43px; height: 43px; }
    .ccbot-tip { display: none; }
    .ccbot-hero-face { width: 84px; height: 84px; margin-bottom: 10px; }
    .ccbot-face--hero { width: 62px; height: 62px; }

    .ccbot-panel {
        inset: 0;
        width: 100%;
        height: 100dvh;
        max-height: none;
        border: 0;
        border-radius: 0;
        z-index: 95;
    }

    .ccbot.is-open .ccbot-launch { visibility: hidden; }

    .ccbot-head {
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    .ccbot-log { padding: 16px 14px 8px; }
    .ccbot-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

/* --- Aksesibilitas dan preferensi -------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .ccbot-launch,
    .ccbot-panel,
    .ccbot-chip,
    .ccbot-btn,
    .ccbot-send,
    .ccbot-tip,
    .ccbot-mode,
    .ccbot-suggestion {
        transition: none;
    }

    .ccbot-halo,
    .ccbot-face--head::after { animation: none; }

    .ccbot-log { scroll-behavior: auto; }
    .ccbot-typing i { animation: none; opacity: 0.6; }
}
