/* ==========================================================
   ai-chat.css
   Cloudz AI: tombol melayang dan popup chat (tema neon gelap Kurniapedia).
   Semua nama kelas diawali "cz-" supaya tidak bentrok dengan CSS lain.
   ========================================================== */

/* Ukuran elemen sudah termasuk padding & border (konsisten dengan Tailwind) */
.cz-fab, .cz-panel, .cz-panel *, .cz-panel *::before, .cz-panel *::after { box-sizing: border-box; }

/* ===== Tombol melayang ===== */
.cz-fab {
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 45;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 16px 11px 13px;
    border: 1px solid rgba(0, 243, 255, 0.45);
    border-radius: 999px;
    color: #fff;
    font: 700 12px/1 'Outfit', 'Inter', sans-serif;
    letter-spacing: 0.04em;
    cursor: pointer;
    background: linear-gradient(135deg, rgba(0, 243, 255, 0.22), rgba(176, 38, 255, 0.3)), rgba(10, 12, 20, 0.92);
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.5), 0 0 18px rgba(0, 243, 255, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    animation: cz-glow 3.2s ease-in-out infinite;
    white-space: nowrap;           /* teks tombol selalu satu baris */
    width: max-content;
    cursor: grab;
    touch-action: none;            /* agar bisa digeser di HP tanpa halaman ikut tergulir */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.cz-fab:hover { transform: translateY(-2px); box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55), 0 0 26px rgba(0, 243, 255, 0.45); }
.cz-fab:active { transform: scale(0.96); }
.cz-fab:focus-visible, .cz-iconbtn:focus-visible, .cz-send:focus-visible, .cz-chip:focus-visible {
    outline: 2px solid #00f3ff;
    outline-offset: 2px;
}
.cz-fab-icon { color: #00f3ff; font-size: 14px; }
.cz-fab.is-dragging {
    cursor: grabbing;
    transform: scale(1.07);
    transition: none;
    animation: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 30px rgba(0, 243, 255, 0.5);
}
.cz-fab.is-snapping {
    transition: left 0.3s cubic-bezier(0.2, 0.9, 0.3, 1), top 0.3s cubic-bezier(0.2, 0.9, 0.3, 1), transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.cz-fab.is-hidden { opacity: 0; pointer-events: none; transform: scale(0.85); }

@keyframes cz-glow {
    0%, 100% { box-shadow: 0 6px 22px rgba(0, 0, 0, 0.5), 0 0 14px rgba(0, 243, 255, 0.22); }
    50%      { box-shadow: 0 6px 22px rgba(0, 0, 0, 0.5), 0 0 26px rgba(176, 38, 255, 0.4); }
}

/* ===== Popup ===== */
.cz-panel {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 55;
    width: 380px;
    max-width: calc(100vw - 24px);
    height: min(600px, calc(100dvh - 40px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 20px;
    border: 1px solid rgba(0, 243, 255, 0.28);
    background: rgba(9, 11, 19, 0.97);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.65), 0 0 28px rgba(0, 243, 255, 0.12);
    color: #e2e8f0;
    font-family: 'Inter', sans-serif;
    opacity: 0;
    visibility: hidden;
    transform: translateY(18px) scale(0.97);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
}
.cz-panel.open {
    opacity: 1;
    visibility: visible;
    transform: none;
    pointer-events: auto;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s;
}

/* Kepala */
.cz-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px 12px 14px;
    background: linear-gradient(135deg, rgba(0, 243, 255, 0.1), rgba(176, 38, 255, 0.14));
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.cz-avatar {
    width: 36px; height: 36px; flex: none;
    display: grid; place-items: center;
    border-radius: 12px;
    color: #00f3ff; font-size: 15px;
    background: rgba(0, 243, 255, 0.1);
    border: 1px solid rgba(0, 243, 255, 0.35);
}
.cz-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cz-title strong { font: 700 14px/1.1 'Outfit', 'Inter', sans-serif; color: #fff; letter-spacing: 0.03em; }
.cz-title span { font-size: 10.5px; color: #94a3b8; display: flex; align-items: center; gap: 5px; }
.cz-dot { width: 6px; height: 6px; border-radius: 50%; background: #00ff66; box-shadow: 0 0 8px #00ff66; display: inline-block; }
.cz-iconbtn {
    width: 32px; height: 32px; flex: none;
    display: grid; place-items: center;
    border: 0; border-radius: 10px;
    background: transparent; color: #94a3b8; font-size: 13px; cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}
.cz-iconbtn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

/* Daftar pesan */
.cz-messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.cz-row { display: flex; }
.cz-row.cz-user { justify-content: flex-end; }
.cz-bubble {
    max-width: 86%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.55;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.cz-user .cz-bubble {
    white-space: pre-wrap;
    color: #fff;
    border-bottom-right-radius: 4px;
    background: linear-gradient(135deg, #06b6d4, #2563eb);
    box-shadow: 0 4px 14px rgba(6, 182, 212, 0.22);
}
.cz-bot .cz-bubble {
    color: #e2e8f0;
    border-bottom-left-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.cz-bubble p { margin: 0; }
.cz-bubble p + p, .cz-bubble p + ul, .cz-bubble p + ol, .cz-bubble ul + p, .cz-bubble ol + p, .cz-bubble pre + p { margin-top: 7px; }
.cz-bubble ul, .cz-bubble ol { margin: 4px 0 0; padding-left: 18px; }
.cz-bubble ul { list-style: disc; }
.cz-bubble ol { list-style: decimal; }
.cz-bubble li { margin: 2px 0; }
.cz-bubble strong { color: #fff; font-weight: 700; }
.cz-bubble code {
    padding: 1px 5px; border-radius: 5px;
    font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
    background: rgba(0, 0, 0, 0.45); color: #7df9ff;
}
.cz-bubble pre {
    margin: 7px 0 0; padding: 9px 10px; overflow-x: auto;
    border-radius: 10px; background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.cz-bubble pre code { padding: 0; background: none; color: #e2e8f0; white-space: pre; }
.cz-error { color: #ffb4cf !important; background: rgba(255, 0, 127, 0.1) !important; border-color: rgba(255, 0, 127, 0.35) !important; }
.cz-error i { color: #ff007f; }

/* Saran pertanyaan */
.cz-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 2px; }
.cz-chip {
    padding: 7px 11px; border-radius: 999px; cursor: pointer;
    font-size: 11.5px; color: #cffafe;
    background: rgba(0, 243, 255, 0.07);
    border: 1px solid rgba(0, 243, 255, 0.28);
    transition: background 0.2s ease, border-color 0.2s ease;
}
.cz-chip:hover { background: rgba(0, 243, 255, 0.16); border-color: rgba(0, 243, 255, 0.55); }

/* Animasi mengetik */
.cz-typing { display: inline-flex; gap: 4px; align-items: center; padding: 13px 14px; }
.cz-typing i {
    width: 6px; height: 6px; border-radius: 50%;
    background: #00f3ff; opacity: 0.35;
    animation: cz-bounce 1.1s infinite ease-in-out;
}
.cz-typing i:nth-child(2) { animation-delay: 0.15s; }
.cz-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes cz-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
    40%           { transform: translateY(-4px); opacity: 1; }
}

/* Kotak input */
.cz-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.cz-input {
    flex: 1;
    min-width: 0;
    max-height: 110px;
    resize: none;
    padding: 9px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font: 13px/1.45 'Inter', sans-serif;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
.cz-input::placeholder { color: #64748b; }
.cz-input:focus { outline: none; border-color: #00f3ff; box-shadow: 0 0 12px rgba(0, 243, 255, 0.22); }
.cz-send {
    width: 38px; height: 38px; flex: none;
    display: grid; place-items: center;
    border: 0; border-radius: 12px; cursor: pointer;
    color: #fff; font-size: 14px;
    background: linear-gradient(135deg, #06b6d4, #2563eb);
    box-shadow: 0 4px 14px rgba(6, 182, 212, 0.3);
    transition: transform 0.15s ease, opacity 0.2s ease;
}
.cz-send:active { transform: scale(0.92); }
.cz-send:disabled { opacity: 0.45; cursor: not-allowed; }
.cz-note { margin: 0; padding: 0 14px 9px; text-align: center; font-size: 9.5px; color: #64748b; }

/* ===== Layar kecil (HP): popup menjadi lembar dari bawah ===== */
@media (max-width: 480px) {
    .cz-panel {
        right: 8px; left: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        width: auto; max-width: none;
        height: min(82dvh, 640px);
        border-radius: 18px;
    }
}
/* Di layar sentuh, font 16px agar iPhone tidak memperbesar halaman saat mengetik */
@media (pointer: coarse) {
    .cz-input { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
    .cz-fab, .cz-panel, .cz-typing i { animation: none; transition: none; }
}

/* ===== Tombol link di jawaban AI ===== */
.cz-bubble a.cz-linkbtn {
    display: inline-flex; align-items: center; gap: 7px;
    margin: 4px 0 2px; padding: 8px 13px;
    max-width: 100%;
    border-radius: 999px;
    border: 1px solid rgba(0, 243, 255, 0.5);
    background: linear-gradient(135deg, rgba(0, 243, 255, 0.18), rgba(138, 43, 226, 0.22));
    color: #fff; font: 700 12px/1.2 'Outfit', 'Inter', sans-serif;
    text-decoration: none; cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}
.cz-bubble a.cz-linkbtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cz-bubble a.cz-linkbtn i { font-size: 11px; color: #7df9ff; flex-shrink: 0; }
.cz-bubble a.cz-linkbtn:hover, .cz-bubble a.cz-linkbtn:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 0 14px rgba(0, 243, 255, 0.35);
    outline: none;
}

/* Tombol untuk aplikasi terkunci (nuansa amber) */
.cz-bubble a.cz-linkbtn.cz-locked {
    border-color: rgba(251, 191, 36, 0.55);
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.14), rgba(138, 43, 226, 0.18));
}
.cz-bubble a.cz-linkbtn.cz-locked i { color: #fbbf24; }
.cz-bubble a.cz-linkbtn.cz-locked:hover, .cz-bubble a.cz-linkbtn.cz-locked:focus-visible {
    box-shadow: 0 0 14px rgba(251, 191, 36, 0.35);
}


/* ==========================================================
   EFEK FUTURISTIK Cloudz AI (versi halus)
   Sengaja dibuat pelan dan transparan supaya tidak mengganggu.
   Mau lebih samar/jelas? Ubah angka opacity (alpha) pada rgba(...) di bawah.
   ========================================================== */

@property --cz-angle { syntax: '<angle>'; initial-value: 0deg; inherits: false; }

/* ----- Tombol melayang: cincin sonar tipis + ikon berkilau halus ----- */
.cz-fab::before {
    content: '';
    position: absolute; inset: -1px;
    border-radius: 999px;
    border: 1px solid rgba(0, 243, 255, 0.5);
    pointer-events: none;
    animation: cz-ping 4s ease-out infinite;
}
.cz-fab.is-dragging::before { animation: none; opacity: 0; }
.cz-fab-icon { animation: cz-twinkle 4s ease-in-out infinite; }
@keyframes cz-ping {
    0%   { transform: scale(1);          opacity: 0.5; }
    60%  { transform: scale(1.25, 1.55); opacity: 0; }
    100% { transform: scale(1.25, 1.55); opacity: 0; }
}
@keyframes cz-twinkle {
    0%, 100% { transform: scale(1);    filter: drop-shadow(0 0 0 rgba(0, 243, 255, 0)); }
    50%      { transform: scale(1.1);  filter: drop-shadow(0 0 5px rgba(0, 243, 255, 0.65)); }
}

/* Isi popup berada di atas lapisan efek */
.cz-head, .cz-messages, .cz-form, .cz-note { position: relative; z-index: 1; }

/* ----- Garis tepi neon tipis yang berputar pelan ----- */
.cz-panel::before {
    content: '';
    position: absolute; inset: 0;
    z-index: 3;
    padding: 1px;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0.8;
    background: conic-gradient(from var(--cz-angle), transparent 0 60%, rgba(0, 243, 255, 0.7) 78%, rgba(176, 38, 255, 0.6) 90%, transparent 100%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
    animation: cz-spin 12s linear infinite;
}
@keyframes cz-spin { to { --cz-angle: 360deg; } }

/* ----- Lapisan latar: grid sangat samar + sudut HUD ----- */
.cz-fx { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; border-radius: inherit; }
.cz-fx::before {
    content: '';
    position: absolute; left: 0; right: 0; top: -28px; height: calc(100% + 28px);
    background:
        linear-gradient(rgba(0, 243, 255, 0.04) 1px, transparent 1px) 0 0 / 28px 28px,
        linear-gradient(90deg, rgba(0, 243, 255, 0.04) 1px, transparent 1px) 0 0 / 28px 28px;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 40%, #000 100%);
            mask-image: linear-gradient(to bottom, transparent 0%, #000 40%, #000 100%);
    animation: cz-grid 10s linear infinite;
}
@keyframes cz-grid { to { transform: translateY(28px); } }
.cz-fx::after {
    content: '';
    position: absolute; inset: 7px;
    background:
        linear-gradient(rgba(0, 243, 255, 0.7), rgba(0, 243, 255, 0.7)) left bottom / 10px 1px no-repeat,
        linear-gradient(rgba(0, 243, 255, 0.7), rgba(0, 243, 255, 0.7)) left bottom / 1px 10px no-repeat,
        linear-gradient(rgba(176, 38, 255, 0.7), rgba(176, 38, 255, 0.7)) right bottom / 10px 1px no-repeat,
        linear-gradient(rgba(176, 38, 255, 0.7), rgba(176, 38, 255, 0.7)) right bottom / 1px 10px no-repeat;
    animation: cz-hud 5s ease-in-out infinite;
}
@keyframes cz-hud { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.75; } }

/* ----- Kepala: garis energi tipis, avatar, judul ----- */
.cz-head { overflow: hidden; }
.cz-head::after {
    content: '';
    position: absolute; left: 0; bottom: 0; width: 100%; height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(0, 243, 255, 0.75) 40%, rgba(176, 38, 255, 0.65) 60%, transparent 100%);
    background-size: 50% 100%; background-repeat: no-repeat;
    animation: cz-flow 5s ease-in-out infinite;
}
@keyframes cz-flow { from { background-position: -50% 0; } to { background-position: 150% 0; } }

.cz-avatar { position: relative; animation: cz-avatar-glow 4s ease-in-out infinite; }
.cz-avatar::before {
    content: '';
    position: absolute; inset: -4px;
    border-radius: 14px;
    border: 1px dashed rgba(0, 243, 255, 0.35);
    animation: cz-orbit 18s linear infinite;
}
.cz-avatar i { animation: cz-twinkle 4s ease-in-out infinite; }
@keyframes cz-orbit { to { transform: rotate(360deg); } }
@keyframes cz-avatar-glow {
    0%, 100% { box-shadow: 0 0 5px rgba(0, 243, 255, 0.2); }
    50%      { box-shadow: 0 0 12px rgba(0, 243, 255, 0.4); }
}

.cz-title strong {
    background: linear-gradient(90deg, #fff 0%, #fff 40%, #9ff3ff 50%, #fff 60%, #fff 100%);
    background-size: 250% 100%;
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
    animation: cz-shimmer 8s linear infinite;
}
@keyframes cz-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
.cz-status { font-weight: 400; }
.cz-dot { animation: cz-dot 2.4s ease-in-out infinite; }
@keyframes cz-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ----- Pesan: muncul lembut ----- */
.cz-row { animation: cz-in 0.3s ease-out both; }
@keyframes cz-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}
.cz-bot .cz-bubble { position: relative; }
.cz-bot .cz-bubble::after {
    content: '';
    position: absolute; inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(110deg, transparent 35%, rgba(125, 249, 255, 0.13) 50%, transparent 65%) no-repeat;
    background-size: 250% 100%;
    background-position: 160% 0;
    animation: cz-sweep 1.2s ease-out 0.1s 1 both;
}
@keyframes cz-sweep { from { background-position: 160% 0; } to { background-position: -60% 0; } }

/* Saran pertanyaan muncul bergantian */
.cz-chip { animation: cz-chip-in 0.35s ease-out both; }
.cz-chip:nth-child(1) { animation-delay: 0.15s; }
.cz-chip:nth-child(2) { animation-delay: 0.22s; }
.cz-chip:nth-child(3) { animation-delay: 0.29s; }
.cz-chip:nth-child(4) { animation-delay: 0.36s; }
.cz-chip:nth-child(n+5) { animation-delay: 0.43s; }
@keyframes cz-chip-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* ----- Saat AI berpikir: efek sedikit lebih cepat ----- */
.cz-panel.is-busy::before { animation-duration: 3.5s; }
.cz-panel.is-busy .cz-head::after { animation-duration: 1.8s; }
.cz-panel.is-busy .cz-dot { background: #00f3ff; box-shadow: 0 0 8px #00f3ff; animation-duration: 1s; }
.cz-panel.is-busy .cz-input { border-color: rgba(176, 38, 255, 0.6); }

/* ----- Tombol kirim: kilap tipis hanya saat disentuh ----- */
.cz-send { position: relative; overflow: hidden; }
.cz-send::after {
    content: '';
    position: absolute; top: 0; bottom: 0; left: -60%; width: 50%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transform: skewX(-20deg);
    transition: left 0.5s ease;
    pointer-events: none;
}
.cz-send:not(:disabled):hover::after { left: 120%; }

/* ----- Hemat baterai: animasi berhenti saat popup tertutup ----- */
.cz-panel:not(.open)::before, .cz-panel:not(.open)::after,
.cz-panel:not(.open) *, .cz-panel:not(.open) *::before, .cz-panel:not(.open) *::after {
    animation-play-state: paused !important;
}

/* ----- Jika perangkat memilih "kurangi gerakan": matikan hanya gerakan besar,
         efek samar (kilau, garis tepi) tetap jalan ----- */
@media (prefers-reduced-motion: reduce) {
    .cz-fab::before,
    .cz-row, .cz-chip,
    .cz-avatar::before, .cz-fx::before, .cz-fab-icon, .cz-avatar i {
        animation: none !important;
    }
}
