/* =============================================================
   BPOM AI Chat Widget — Frontend Floating UI
   ============================================================= */

/* ── CSS Variables (inherit dari BPOM plugin bila tersedia) ── */
:root {
    --bpom-ai-primary:   var(--bpom-primary, #2563eb);
    --bpom-ai-accent:    var(--bpom-accent,  #7c3aed);
    --bpom-ai-bg:        #0f172a;
    --bpom-ai-surface:   #1e293b;
    --bpom-ai-surface2:  #273549;
    --bpom-ai-border:    rgba(255,255,255,0.08);
    --bpom-ai-text:      #f1f5f9;
    --bpom-ai-text-muted:#94a3b8;
    --bpom-ai-radius:    16px;
    --bpom-ai-shadow:    0 24px 64px rgba(0,0,0,0.5), 0 4px 16px rgba(0,0,0,0.3);
    --bpom-ai-z:         99999;
    --bpom-ai-toggle-size: 56px;
    --bpom-ai-panel-w:   360px;
    --bpom-ai-panel-h:   520px;
}

/* ── Widget Container ── */
.bpom-ai-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--bpom-ai-z);
    font-family: -apple-system, 'Inter', 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    /* Toggle button tetap di pojok kanan bawah */
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
}

/* ── Toggle Button ── */
.bpom-ai-toggle {
    width: var(--bpom-ai-toggle-size);
    height: var(--bpom-ai-toggle-size);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--bpom-ai-primary) 0%, var(--bpom-ai-accent) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(37,99,235,0.45), 0 0 0 0 rgba(37,99,235,0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    animation: bpom-ai-pulse 2.5s ease-in-out infinite;
}

.bpom-ai-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(37,99,235,0.6), 0 0 0 8px rgba(37,99,235,0.12);
    animation: none;
}

.bpom-ai-toggle.is-open {
    animation: none;
    box-shadow: 0 4px 20px rgba(37,99,235,0.4);
}

@keyframes bpom-ai-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(37,99,235,0.45), 0 0 0 0 rgba(37,99,235,0.4); }
    50%       { box-shadow: 0 4px 20px rgba(37,99,235,0.45), 0 0 0 10px rgba(37,99,235,0); }
}

.bpom-ai-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

/* Badge notifikasi */
.bpom-ai-toggle-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    animation: bpom-ai-bounce 0.4s ease;
}

@keyframes bpom-ai-bounce {
    0%   { transform: scale(0); }
    70%  { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* ── Chat Panel ── */
.bpom-ai-panel {
    position: absolute;
    bottom: calc(var(--bpom-ai-toggle-size) + 12px); /* tepat di atas toggle + gap */
    right: 0;
    width: var(--bpom-ai-panel-w);
    height: var(--bpom-ai-panel-h);
    background: var(--bpom-ai-bg);
    border: 1px solid var(--bpom-ai-border);
    border-radius: var(--bpom-ai-radius);
    box-shadow: var(--bpom-ai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.bpom-ai-panel.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Header ── */
.bpom-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--bpom-ai-primary) 0%, var(--bpom-ai-accent) 100%);
    flex-shrink: 0;
}

.bpom-ai-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bpom-ai-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.bpom-ai-header-name {
    font-weight: 700;
    font-size: 13px;
    color: #fff;
    letter-spacing: 0.01em;
}

.bpom-ai-header-status {
    font-size: 11px;
    color: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    gap: 5px;
}

.bpom-ai-status-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    animation: bpom-ai-status-pulse 2s ease-in-out infinite;
}

@keyframes bpom-ai-status-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

.bpom-ai-clear-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    border-radius: 8px;
    padding: 5px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.15s ease;
}

.bpom-ai-clear-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ── Messages Area ── */
.bpom-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.bpom-ai-messages::-webkit-scrollbar {
    width: 4px;
}
.bpom-ai-messages::-webkit-scrollbar-track {
    background: transparent;
}
.bpom-ai-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 4px;
}

/* Message bubbles */
.bpom-ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.55;
    word-break: break-word;
    animation: bpom-ai-msg-in 0.2s ease;
}

@keyframes bpom-ai-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bpom-ai-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--bpom-ai-primary) 0%, var(--bpom-ai-accent) 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.bpom-ai-msg.ai {
    align-self: flex-start;
    background: var(--bpom-ai-surface);
    color: var(--bpom-ai-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--bpom-ai-border);
}

.bpom-ai-msg.ai strong { color: #93c5fd; }
.bpom-ai-msg.ai em     { color: #c4b5fd; }
.bpom-ai-msg.ai code   {
    background: rgba(255,255,255,0.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}
.bpom-ai-msg.ai pre {
    background: rgba(0,0,0,0.35);
    border-radius: 8px;
    padding: 10px;
    overflow-x: auto;
    position: relative;
    margin: 6px 0;
}
.bpom-ai-msg.ai pre code {
    background: transparent;
    padding: 0;
}

/* Typing dots */
.bpom-ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
}

.bpom-ai-typing span {
    width: 7px;
    height: 7px;
    background: var(--bpom-ai-text-muted);
    border-radius: 50%;
    animation: bpom-ai-dot 1.2s ease-in-out infinite;
}

.bpom-ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.bpom-ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bpom-ai-dot {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%           { transform: translateY(-6px); opacity: 1; }
}

/* Error message */
.bpom-ai-msg.error {
    background: rgba(239,68,68,0.12);
    color: #fca5a5;
    border-color: rgba(239,68,68,0.2);
}

/* ── Input Area ── */
.bpom-ai-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--bpom-ai-border);
    background: var(--bpom-ai-surface);
    flex-shrink: 0;
}

.bpom-ai-input {
    flex: 1;
    background: var(--bpom-ai-surface2);
    border: 1px solid var(--bpom-ai-border);
    border-radius: 12px;
    color: var(--bpom-ai-text);
    font-size: 13px;
    font-family: inherit;
    padding: 9px 12px;
    resize: none;
    min-height: 38px;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.15s ease;
    line-height: 1.5;
}

.bpom-ai-input::placeholder {
    color: var(--bpom-ai-text-muted);
}

.bpom-ai-input:focus {
    outline: none;
    border-color: var(--bpom-ai-primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.2);
}

.bpom-ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--bpom-ai-primary) 0%, var(--bpom-ai-accent) 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease, transform 0.15s ease;
    flex-shrink: 0;
}

.bpom-ai-send-btn:hover:not(:disabled) {
    opacity: 0.9;
    transform: scale(1.05);
}

.bpom-ai-send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Pastikan SVG icon di tombol kirim selalu tampil
   (beberapa tema WordPress menyembunyikan SVG secara global) */
.bpom-ai-send-btn svg,
.bpom-ai-send-btn svg path {
    display: block !important;
    visibility: visible !important;
    width: 20px !important;
    height: 20px !important;
    color: #fff !important;
    fill: currentColor !important;
    pointer-events: none;
}

/* ── Footer Note ── */
.bpom-ai-footer-note {
    text-align: center;
    font-size: 10px;
    color: var(--bpom-ai-text-muted);
    padding: 4px 8px 8px;
    background: var(--bpom-ai-surface);
    flex-shrink: 0;
}

/* ── Context Banner (produk sedang dilihat) ── */
.bpom-ai-context-banner {
    margin: 0 16px;
    padding: 8px 12px;
    background: rgba(37,99,235,0.12);
    border: 1px solid rgba(37,99,235,0.25);
    border-radius: 10px;
    font-size: 11px;
    color: #93c5fd;
    display: flex;
    align-items: center;
    gap: 6px;
}

.bpom-ai-context-banner svg {
    flex-shrink: 0;
}

/* ── Responsive ── */
@media (max-width: 480px) {
    .bpom-ai-widget {
        bottom: 16px;
        right: 16px;
    }

    .bpom-ai-panel {
        width: calc(100vw - 32px);
        height: min(520px, calc(100dvh - 100px));
        right: 0;
        left: auto;
    }
}
