/* ====== Cemato AI Widget (shared by portal, CMC, COA) ====== */
#aiw-root {
    --aiw-accent: #667eea;
    --aiw-accent-rgb: 102, 126, 234;
    --aiw-card: #ffffff;
    --aiw-ink: #1f2937;
    --aiw-muted: #6b7280;
    --aiw-faint: #9ca3af;
    --aiw-line: #e5e7eb;
    --aiw-paper: #f8f9fc;
    --aiw-hair: #eef0f4;
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
}
[data-theme="dark"] #aiw-root,
html.dark #aiw-root {
    --aiw-card: #1b1e26;
    --aiw-ink: #e8eaf0;
    --aiw-muted: #9aa1b2;
    --aiw-faint: #6b7280;
    --aiw-line: #2b303c;
    --aiw-paper: #12141a;
    --aiw-hair: #232833;
}

#aiw-root .aiw-btn {
    position: fixed; right: 24px; bottom: 24px; z-index: 1050;
    width: 78px; height: 78px; border: none; padding: 0;
    border-radius: 50%; cursor: grab;
    background: var(--aiw-accent);
    box-shadow: 0 10px 26px rgba(var(--aiw-accent-rgb), 0.45);
    transition: transform .2s ease, box-shadow .2s ease;
    display: grid; place-items: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
#aiw-root .aiw-btn:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 14px 32px rgba(var(--aiw-accent-rgb), .55); }
#aiw-root .aiw-btn:active { cursor: grabbing; }
#aiw-root .aiw-btn.dragging { transition: none; cursor: grabbing; }
#aiw-root .aiw-btn.dragging:hover { transform: none; }
#aiw-root .aiw-btn.wandering { transition: left 1.25s cubic-bezier(.45,.05,.25,1), top 1.25s cubic-bezier(.45,.05,.25,1), box-shadow .2s ease; }
#aiw-root .aiw-svg.spinning { animation: aiw-spin 1s cubic-bezier(.4,.1,.3,1); }
@keyframes aiw-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
#aiw-root .aiw-btn.open { filter: brightness(.92); }

/* robot (SVG mascot — idle float, blink, antenna pulse) */
#aiw-root .aiw-btn .aiw-svg { animation: aiw-float 3.4s ease-in-out infinite; }
@keyframes aiw-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
#aiw-root .rw-ant { fill: #ffd166; transform-box: fill-box; transform-origin: center; animation: aiw-ant 2.2s ease-in-out infinite; }
@keyframes aiw-ant { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
#aiw-root .rw-glow { fill: none; stroke: #ffd166; opacity: .45; animation: aiw-ant 2.2s ease-in-out infinite; }
#aiw-root .rw-brow { fill: none; stroke: #ffffff; stroke-width: 1.8; stroke-linecap: round; opacity: .9; }
#aiw-root .rw-shine { fill: #ffffff; opacity: .35; }
#aiw-root .rw-eye-dot { fill: var(--aiw-accent); transform-box: fill-box; transform-origin: center; animation: aiw-blink 4.4s infinite; }
@keyframes aiw-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.12); } }
#aiw-root .rw-eyes { transition: transform .15s ease-out; }
#aiw-root .rw-eye-happy { display: none; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; }
#aiw-root .rw-cheek { fill: #f9a8d4; opacity: .55; }
#aiw-root .rw-mouth-smile { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; }
#aiw-root .rw-mouth-sad { display: none; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; }
#aiw-root .rw-tear { display: none; fill: #7dd3fc; opacity: 0; }

/* hover = happy (launcher only) */
#aiw-root .aiw-btn:hover .rw-eye-dot { display: none; }
#aiw-root .aiw-btn:hover .rw-eye-happy { display: block; }
#aiw-root .aiw-btn:hover .rw-cheek { opacity: .9; }

/* cheer on reply */
#aiw-root .aiw-svg.cheer { animation: aiw-cheer .6s ease; }
@keyframes aiw-cheer {
    0% { transform: translateY(0) scale(1, 1); }
    30% { transform: translateY(-8px) scale(.94, 1.08); }
    55% { transform: translateY(0) scale(1.08, .9); }
    75% { transform: translateY(-3px) scale(.98, 1.03); }
    100% { transform: none; }
}
#aiw-root .aiw-svg.cheer .rw-eye-dot { display: none; }
#aiw-root .aiw-svg.cheer .rw-eye-happy { display: block; }

/* thinking (header mini robot while AI replies) */
#aiw-root .aiw-svg.thinking { animation: aiw-think-tilt 1.6s ease-in-out infinite; }
@keyframes aiw-think-tilt { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
#aiw-root .aiw-svg.thinking .rw-eyes { transform: translate(-2px, -3px); }

/* crying while dragging */
#aiw-root .aiw-btn.dragging .rw-mouth-smile { display: none; }
#aiw-root .aiw-btn.dragging .rw-mouth-sad { display: block; }
#aiw-root .aiw-btn.dragging .rw-eye-dot { animation: none; transform: scaleY(.55); }
#aiw-root .aiw-btn.dragging .rw-eye-happy { display: none !important; }
#aiw-root .aiw-btn.dragging .rw-tear { display: block; animation: aiw-tear-fall 1s ease-in infinite; }
#aiw-root .aiw-btn.dragging .rw-tear.t2 { animation-delay: .45s; }
@keyframes aiw-tear-fall { 0% { transform: translateY(0) scale(.5); opacity: 0; } 25% { opacity: 1; } 100% { transform: translateY(10px) scale(1); opacity: 0; } }
#aiw-root .aiw-btn.dragging .aiw-svg { animation: aiw-tremble .5s ease-in-out infinite; }
@keyframes aiw-tremble { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }

/* ===== cute pack: sleep, quirks, hearts, sad ===== */
/* sleeping (local, sebelum AI nudge) */
#aiw-root .aiw-btn .aiw-zzz {
    position: absolute; top: 0; right: 8px; z-index: 2;
    font-weight: 800; font-size: 10px; line-height: .95; text-align: left;
    color: var(--aiw-muted); opacity: 0; pointer-events: none;
    transition: opacity .5s ease;
}
#aiw-root .aiw-btn .aiw-zzz b { display: block; font-size: 13px; }
#aiw-root .aiw-btn .aiw-zzz b:nth-child(2) { font-size: 15px; margin-left: 5px; }
#aiw-root .aiw-btn.sleeping .aiw-zzz { opacity: 1; animation: aiw-zzz-float 2.6s ease-in-out infinite; }
@keyframes aiw-zzz-float { 0%, 100% { transform: translateY(0); opacity: .55; } 50% { transform: translateY(-4px); opacity: 1; } }
#aiw-root .aiw-btn.sleeping .aiw-svg { animation: aiw-float 6.5s ease-in-out infinite; filter: saturate(.45) brightness(.95); }
#aiw-root .aiw-btn.sleeping .rw-eye-dot { transform: scaleY(.12); animation: none; }
#aiw-root .aiw-btn.sleeping .rw-mouth-smile { opacity: .35; }
#aiw-root .aiw-btn.sleeping .rw-ant, #aiw-root .aiw-btn.sleeping .rw-glow { animation-duration: 4.5s; }

/* sad on error */
#aiw-root .aiw-svg.sad .rw-mouth-smile { display: none; }
#aiw-root .aiw-svg.sad .rw-mouth-sad { display: block; }
#aiw-root .aiw-svg.sad .rw-eye-dot { animation: none; transform: translateY(1px); }
#aiw-root .aiw-svg.sad .rw-brow { transform: rotate(8deg); transform-box: fill-box; transform-origin: center; }

/* quirk motions */
#aiw-root .aiw-svg.wiggle { animation: aiw-wiggle .7s ease; }
@keyframes aiw-wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg); } 75% { transform: rotate(9deg); } }
#aiw-root .aiw-svg.hop { animation: aiw-hop .65s cubic-bezier(.34,1.56,.64,1); }
@keyframes aiw-hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-10px) scale(1.05, .94); } 70% { transform: translateY(0) scale(.96, 1.05); } }

/* hearts / sparkles saat dipeluk */
#aiw-root .aiw-heart {
    position: absolute; z-index: 3; font-size: 14px; pointer-events: none;
    animation: aiw-heart-rise 1.15s ease-out forwards;
}
@keyframes aiw-heart-rise {
    0% { opacity: 0; transform: translateY(4px) scale(.4) rotate(0); }
    22% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-38px) scale(1.2) rotate(14deg); }
}

/* speech bubble */
#aiw-root .aiw-speech {
    position: fixed; z-index: 1051;
    max-width: 190px;
    background: var(--aiw-card); color: var(--aiw-ink);
    border: 1px solid var(--aiw-line); border-radius: 13px;
    box-shadow: 0 12px 28px -8px rgba(10, 10, 10, 0.3);
    padding: 9px 13px;
    font-size: 12.5px; font-weight: 600; line-height: 1.45; text-align: center;
    opacity: 0; transform: translateY(6px) scale(.92);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none;
}
#aiw-root .aiw-speech.show { opacity: 1; transform: none; }
#aiw-root .aiw-speech::after {
    content: ''; position: absolute; left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 10px; height: 10px; background: var(--aiw-card);
    border-right: 1px solid var(--aiw-line); border-bottom: 1px solid var(--aiw-line);
    bottom: -6px;
}
#aiw-root .aiw-speech.below::after {
    bottom: auto; top: -6px;
    border-right: none; border-bottom: none;
    border-left: 1px solid var(--aiw-line); border-top: 1px solid var(--aiw-line);
}

/* panel */
#aiw-root .aiw-panel {
    position: fixed; right: 24px; bottom: 98px; z-index: 1050;
    width: 380px; max-width: calc(100vw - 32px);
    height: 520px; max-height: calc(100vh - 140px);
    background: var(--aiw-card); border-radius: 18px;
    border: 1px solid var(--aiw-line);
    box-shadow: 0 24px 60px -12px rgba(10, 10, 10, 0.3);
    display: none; flex-direction: column; overflow: hidden;
    font-size: 15px; color: var(--aiw-ink);
}
#aiw-root .aiw-panel.open { display: flex; animation: aiw-pop .32s cubic-bezier(.34,1.45,.44,1); }
@keyframes aiw-pop { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }

#aiw-root .aiw-head-bar {
    background: var(--aiw-accent); color: #fff;
    padding: 13px 16px; display: flex; align-items: center; gap: 11px;
}
#aiw-root .aiw-head-bar .mini-robot { width: 30px; height: 30px; border-radius: 50%; background: rgba(255,255,255,.18); display: grid; place-items: center; position: relative; flex-shrink: 0; }
#aiw-root .aiw-head-bar .t { flex: 1; min-width: 0; }
#aiw-root .aiw-head-bar .t b { font-size: 14.5px; display: block; letter-spacing: -0.01em; }
#aiw-root .aiw-head-bar .t span { font-size: 11px; opacity: .85; }
#aiw-root .aiw-close { border: none; background: rgba(255,255,255,.16); color: inherit; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 15px; line-height: 1; font-family: inherit; flex-shrink: 0; }
#aiw-root .aiw-close:hover { background: rgba(255,255,255,.3); }

#aiw-root .aiw-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 16px 14px; background: var(--aiw-paper); display: flex; flex-direction: column; gap: 10px; }
#aiw-root .aiw-body::-webkit-scrollbar { width: 5px; }
#aiw-root .aiw-body::-webkit-scrollbar-thumb { background: var(--aiw-faint); border-radius: 10px; }

#aiw-root .aiw-msg { display: flex; gap: 8px; max-width: 88%; animation: aiw-in .2s ease; }
@keyframes aiw-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#aiw-root .aiw-msg .av {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    background: var(--aiw-accent); display: grid; place-items: center;
}
#aiw-root .aiw-msg.user { align-self: flex-end; flex-direction: row-reverse; }
#aiw-root .aiw-msg .bubble {
    padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.55;
    white-space: pre-wrap; word-wrap: break-word;
}
#aiw-root .aiw-msg.bot .bubble { background: var(--aiw-card); border: 1px solid var(--aiw-line); color: var(--aiw-ink); border-top-left-radius: 4px; }
#aiw-root .aiw-msg.user .bubble { background: var(--aiw-accent); color: #fff; border-top-right-radius: 4px; }

#aiw-root .aiw-think { font-size: 12px; color: var(--aiw-muted, #8a8178); margin-bottom: 6px; }
#aiw-root .aiw-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
#aiw-root .aiw-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--aiw-accent); animation: aiw-bounce 1.1s infinite; }
#aiw-root .aiw-typing span:nth-child(2) { animation-delay: .15s; }
#aiw-root .aiw-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aiw-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

#aiw-root .aiw-quick-wrap { background: var(--aiw-paper); transition: opacity .2s ease; }
#aiw-root .aiw-quick-wrap.hidden { display: none; }
#aiw-root .aiw-quick-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 14px 0; font-size: 11px; font-weight: 700; color: var(--aiw-faint);
}
#aiw-root .aiw-quick-close {
    border: none; background: transparent; color: var(--aiw-faint);
    cursor: pointer; font-size: 15px; line-height: 1;
    padding: 2px 7px; border-radius: 6px; font-family: inherit;
}
#aiw-root .aiw-quick-close:hover { color: var(--aiw-ink); background: var(--aiw-hair); }
#aiw-root .aiw-quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 10px; }
#aiw-root .aiw-quick button {
    border: 1px solid var(--aiw-line); background: var(--aiw-card); color: var(--aiw-muted);
    font-size: 11.5px; font-weight: 600; padding: 6px 11px; border-radius: 999px; cursor: pointer;
    transition: all .15s; font-family: inherit;
}
#aiw-root .aiw-quick button:hover { border-color: var(--aiw-accent); color: var(--aiw-accent); }

#aiw-root .aiw-input-bar {
    display: flex; gap: 8px; padding: 12px; background: var(--aiw-card);
    border-top: 1px solid var(--aiw-hair);
}
#aiw-root .aiw-input-bar input {
    flex: 1; border: 1px solid var(--aiw-line); border-radius: 11px;
    padding: 10px 13px; font-size: 13.5px; font-family: inherit; outline: none;
    background: var(--aiw-card); color: var(--aiw-ink);
    transition: border-color .15s, box-shadow .15s;
    min-width: 0;
}
#aiw-root .aiw-input-bar input:focus { border-color: var(--aiw-accent); box-shadow: 0 0 0 3px rgba(var(--aiw-accent-rgb), .15); }
#aiw-root .aiw-idea {
    border: 1px solid var(--aiw-line); background: var(--aiw-card); color: var(--aiw-faint);
    width: 42px; flex-shrink: 0; border-radius: 11px; cursor: pointer;
    font-size: 14px; transition: all .15s; font-family: inherit;
    display: grid; place-items: center;
}
#aiw-root .aiw-idea:hover { color: var(--aiw-accent); border-color: var(--aiw-accent); }
#aiw-root .aiw-idea.active { color: var(--aiw-accent); border-color: var(--aiw-accent); background: rgba(var(--aiw-accent-rgb), .1); }
#aiw-root .aiw-send {
    border: none; background: var(--aiw-accent); color: #fff; width: 42px; flex-shrink: 0; border-radius: 11px;
    cursor: pointer; font-size: 14px; transition: filter .15s; font-family: inherit;
    display: grid; place-items: center;
}
#aiw-root .aiw-send:hover { filter: brightness(1.1); }
#aiw-root .aiw-send:disabled { opacity: .6; cursor: wait; }

@supports (height: 100dvh) {
    #aiw-root .aiw-panel { max-height: calc(100dvh - 140px); }
}
@media (max-width: 640px) {
    #aiw-root .aiw-panel {
        right: 12px; left: 12px; width: auto; bottom: calc(92px + env(safe-area-inset-bottom, 0px));
        height: min(68vh, 520px); height: min(68dvh, 520px);
        max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px);
        border-radius: 16px;
    }
    #aiw-root .aiw-msg { max-width: 92%; }
    #aiw-root .aiw-speech { max-width: 160px; font-size: 12px; }
}
@media (max-width: 480px) {
    #aiw-root .aiw-btn { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); width: 64px; height: 64px; }
    #aiw-root .aiw-panel { bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
    /* cegah auto-zoom iOS saat keyboard muncul */
    #aiw-root .aiw-input-bar input { font-size: 16px; }
    #aiw-root .aiw-input-bar { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
    #aiw-root .aiw-body { padding: 12px 10px; }
}

@media (prefers-reduced-motion: reduce) {
    #aiw-root .aiw-btn .aiw-svg,
    #aiw-root .rw-ant,
    #aiw-root .rw-eye-dot,
    #aiw-root .aiw-svg.cheer,
    #aiw-root .aiw-svg.thinking,
    #aiw-root .aiw-svg.spinning,
    #aiw-root .aiw-svg.wiggle,
    #aiw-root .aiw-svg.hop,
    #aiw-root .aiw-heart,
    #aiw-root .aiw-btn.sleeping .aiw-zzz,
    #aiw-root .aiw-btn.dragging .aiw-svg,
    #aiw-root .aiw-btn.dragging .rw-tear {
        animation: none !important;
    }
}
