/* ==========================================================================
   De Crown Chatbot — widget asisten virtual (menggantikan tombol Tanya Admin)
   ========================================================================== */

.dc-chatbot {
    --dc-primary: #f5a623;
    --dc-primary-dark: #e0941a;
    --dc-dark: #1a1a1a;
    --dc-bot-bg: #f1f3f5;
    --dc-user-bg: #f5a623;
    font-family: inherit;
}

/* Tombol mengambang */
.dc-chat-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--dc-primary);
    color: #fff;
    box-shadow: 0 8px 24px rgba(245, 166, 35, 0.45);
    cursor: grab;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
.dc-chat-fab:hover {
    transform: scale(1.06);
    background: var(--dc-primary-dark);
}
.dc-chat-fab.dragging {
    cursor: grabbing;
    transition: none;
    transform: scale(1.08);
}
.dc-chat-fab-icon {
    font-size: 1.6rem;
    display: block;
}
.dc-chat-fab-close {
    font-size: 1.4rem;
    display: none;
}
.dc-chat-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #e03131;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* State terbuka: tampilkan ikon close, sembunyikan ikon chat & badge */
.dc-chatbot.open .dc-chat-fab-icon,
.dc-chatbot.open .dc-chat-fab-badge {
    display: none;
}
.dc-chatbot.open .dc-chat-fab-close {
    display: block;
}

/* Panel obrolan */
.dc-chat-panel {
    position: fixed;
    right: 22px;
    bottom: 94px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
}
.dc-chatbot.open .dc-chat-panel {
    display: flex;
    animation: dc-pop 0.18s ease-out;
}
@keyframes dc-pop {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Header */
.dc-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--dc-dark);
    color: #fff;
}
.dc-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--dc-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.dc-chat-title {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    flex: 1;
}
.dc-chat-title strong {
    font-size: 0.95rem;
}
.dc-chat-title small {
    font-size: 0.72rem;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 5px;
}
.dc-chat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #51cf66;
    display: inline-block;
}
.dc-chat-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    opacity: 0.8;
}
.dc-chat-close:hover { opacity: 1; }

/* Tombol buka halaman chatbot di header */
.dc-chat-fs {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.15rem;
    cursor: pointer;
    opacity: 0.8;
    padding: 0 4px;
}
.dc-chat-fs:hover { opacity: 1; }

/* Area pesan */
.dc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.dc-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
}
.dc-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--dc-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}
.dc-msg-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Balasan asisten dirender menjadi HTML terstruktur,
   sehingga white-space normal dan aturan paragraf/daftar berlaku. */
.dc-msg-bot .dc-msg-bubble {
    white-space: normal;
}
.dc-msg-bubble p {
    margin: 0 0 7px;
}
.dc-msg-bubble p:last-child {
    margin-bottom: 0;
}
.dc-msg-bubble ul,
.dc-msg-bubble ol {
    margin: 4px 0 7px;
    padding-left: 19px;
}
.dc-msg-bubble li {
    margin: 3px 0;
}
.dc-msg-bubble li::marker {
    color: #8a93a0;
}
.dc-msg-bubble .dc-md-title {
    margin-top: 2px;
}
.dc-msg-bubble strong {
    font-weight: 700;
}
.dc-msg-bubble code {
    font-family: SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.9em;
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 4px;
}
.dc-msg-bot {
    align-self: flex-start;
}
.dc-msg-bot .dc-msg-bubble {
    background: var(--dc-bot-bg);
    color: #222;
    border-bottom-left-radius: 4px;
}
.dc-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.dc-msg-user .dc-msg-avatar {
    background: #495057;
}
.dc-msg-user .dc-msg-bubble {
    background: var(--dc-user-bg);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Indikator mengetik */
.dc-chat-typing {
    display: flex;
    gap: 4px;
    padding: 4px 16px 10px;
    background: #fafafa;
}
.dc-chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #adb5bd;
    animation: dc-blink 1.2s infinite ease-in-out;
}
.dc-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.dc-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dc-blink {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* Input */
.dc-chat-input {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #eee;
    background: #fff;
}
.dc-chat-input .form-control {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 22px;
    padding: 9px 14px;
    font-size: 0.88rem;
    outline: none;
}
.dc-chat-input .form-control:focus {
    border-color: var(--dc-primary);
}
.dc-chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--dc-primary);
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.2s ease;
}
.dc-chat-send:hover { background: var(--dc-primary-dark); }
.dc-chat-send:disabled { opacity: 0.6; cursor: not-allowed; }

@media (max-width: 480px) {
    .dc-chat-panel {
        right: 8px;
        bottom: 84px;
        width: calc(100vw - 16px);
    }
    .dc-chat-fab { right: 14px; bottom: 14px; }
}
