/* ═══════════════════════════════════════════════════════════════════════════
   CHAT MINI WIDGET  (prefix: cmw-)
   ---------------------------------------------------------------------------
   Messenger-style shortcut yang nempel di ikon Chat navbar — HADIR di SEMUA
   halaman (di-@import dari style.css), bukan cuma halaman Chat.

   Dua bagian:
     1. Panel dropdown  — daftar percakapan di bawah ikon navbar (ala lonceng
        notifikasi), TANPA pindah halaman.
     2. Dock + popup     — jendela chat kecil yang nempel di pojok kanan-bawah,
        bisa balas langsung tanpa keluar dari halaman yang lagi dibuka.

   Semua warna lewat token var(--...) (assets/css/variables.css) supaya mode
   gelap ikut otomatis. Prefix cmw- sengaja beda dari cw- (halaman Chat penuh)
   biar gak tabrakan — dua-duanya bisa hidup bareng di halaman Chat, jadi widget
   ini di-nonaktifkan sendiri di sana lewat chat-widget.js.
   ═════════════════════════════════════════════════════════════════════════ */

/* ── Anchor ikon navbar ─────────────────────────────────────────────────── */
.cmw-wrap { position: relative; display: inline-flex; }

/* Atribut/properti `hidden` HARUS menang atas base display:flex di bawah.
   Jebakan CSS origin: aturan author `display:flex` mengalahkan UA
   `[hidden]{display:none}`. chat-widget.js men-toggle beberapa kontrol
   (search-×, mode-label, chip file, baris ketik AI, input file) lewat
   el.hidden — tanpa reset ini semuanya kelihatan terus. (Pola sama dgn
   chat.css: `.cw [hidden]{display:none!important}`.) */
.cmw-panel [hidden],
.cmw-dock  [hidden] { display: none !important; }

/* ══ 1. PANEL DROPDOWN ═══════════════════════════════════════════════════ */
.cmw-panel {
    position: absolute;
    top: calc(100% + 14px);
    right: 0;
    width: 372px;
    max-width: calc(100vw - 32px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .18), 0 4px 14px rgba(15, 23, 42, .08);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(.98);
    transform-origin: top right;
    transition: opacity .18s ease, transform .18s ease, visibility .18s;
    z-index: 260;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.cmw-panel.show { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

.cmw-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.cmw-panel-title { display: flex; align-items: center; gap: 8px; }
.cmw-panel-title strong { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -.1px; }
.cmw-head-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}
.cmw-panel-head-act { display: flex; align-items: center; gap: 4px; }
.cmw-panel-head-act button,
.cmw-panel-head-act a {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 9px;
    color: var(--text-light);
    font-size: 18px;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.cmw-panel-head-act button:hover,
.cmw-panel-head-act a:hover { background: var(--surface-3); color: var(--primary); }
.cmw-panel-head-act .is-on { background: rgba(37,99,235,.12); color: var(--primary); }

/* Search */
.cmw-search {
    position: relative;
    display: flex;
    align-items: center;
    margin: 10px 12px 4px;
    flex-shrink: 0;
}
.cmw-search > i {
    position: absolute;
    left: 12px;
    font-size: 16px;
    color: var(--text-light);
    pointer-events: none;
}
.cmw-search input {
    width: 100%;
    height: 38px;
    padding: 0 34px 0 36px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    font-family: "Poppins", sans-serif;
    font-size: 13px;
    outline: none;
    transition: border-color .15s, background .15s;
}
.cmw-search input:focus { border-color: var(--primary); background: var(--surface); }
.cmw-search-x {
    position: absolute;
    right: 8px;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    border-radius: 6px;
    color: var(--text-light);
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cmw-search-x:hover { background: var(--surface-3); color: var(--text); }

/* Sub-label ("Mulai chat baru") saat mode daftar orang */
.cmw-mode-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 18px 2px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-light);
}

/* List */
.cmw-list {
    max-height: 60vh;
    min-height: 120px;
    overflow-y: auto;
    padding: 6px 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cmw-list::-webkit-scrollbar { width: 6px; }
.cmw-list::-webkit-scrollbar-track { background: transparent; }
.cmw-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.cmw-list::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

.cmw-grp {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 10px 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-light);
}
.cmw-grp i { font-size: 13px; }

/* Baris percakapan / orang */
.cmw-conv {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s;
}
.cmw-conv:hover { background: var(--surface-2); }
.cmw-conv.has-unread { background: rgba(37,99,235,.05); }
.cmw-conv.has-unread:hover { background: rgba(37,99,235,.09); }

.cmw-conv-body { min-width: 0; flex: 1; }
.cmw-conv-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.cmw-conv-nama {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}
.cmw-conv.has-unread .cmw-conv-nama { font-weight: 700; }
.cmw-conv-time { font-size: 10.5px; color: var(--text-light); white-space: nowrap; flex-shrink: 0; }
.cmw-conv-bot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 2px;
}
.cmw-conv-prev {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
.cmw-conv.has-unread .cmw-conv-prev { color: var(--text); font-weight: 500; }
.cmw-conv-prev i { font-size: 13px; vertical-align: -1px; }
.cmw-conv-role { font-size: 11px; color: var(--text-light); white-space: nowrap; flex-shrink: 0; }

.cmw-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}

/* Avatar (dipakai di panel & popup) */
.cmw-av {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--primary), #1d4ed8);
    overflow: visible;
}
.cmw-av.sm { width: 30px; height: 30px; font-size: 12px; }
.cmw-av.lg { width: 48px; height: 48px; font-size: 19px; }
.cmw-av.is-ai { background: linear-gradient(135deg, #7c3aed, #4f46e5); }
.cmw-av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.cmw-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #94a3b8;
    border: 2.5px solid var(--surface);
}
.cmw-dot.on { background: var(--success); }

.cmw-tag-ai {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(124,58,237,.14);
    color: #7c3aed;
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: .3px;
    flex-shrink: 0;
}
html[data-theme="dark"] .cmw-tag-ai { color: #c4b5fd; }

/* Loading / empty */
.cmw-load, .cmw-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: auto 0;
}
.cmw-load i { font-size: 22px; color: var(--primary); }
.cmw-empty i {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface-3);
    font-size: 24px;
    color: var(--text-light);
}
.cmw-empty b { color: var(--text); }

.cmw-panel-foot {
    border-top: 1px solid var(--border);
    padding: 8px;
    flex-shrink: 0;
}
.cmw-panel-foot a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    padding: 9px 12px;
    border-radius: 10px;
    transition: background .15s, color .15s;
}
.cmw-panel-foot a:hover { background: var(--surface-2); color: var(--primary); }

/* ══ 2. DOCK + POPUP ═════════════════════════════════════════════════════ */
.cmw-dock {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 250;
    display: flex;
    align-items: flex-end;
    gap: 14px;
    pointer-events: none;   /* dock itu sendiri transparan buat klik; popup-nya yg aktif */
}
.cmw-dock .cmw-pop { pointer-events: auto; }

.cmw-pop {
    width: 336px;
    height: 460px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 18px 44px rgba(15, 23, 42, .24), 0 4px 12px rgba(15, 23, 42, .10);
    overflow: hidden;
    transform-origin: bottom right;
    animation: cmwPopIn .18s ease;
}
@keyframes cmwPopIn {
    from { opacity: 0; transform: translateY(16px) scale(.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* Minimize: sudut bawah ikut membulat — parent overflow:hidden meng-clip head
   yang sudah full-round, jadi parent-nya sendiri harus dibulatkan. */
.cmw-pop.is-min { height: auto !important; border-radius: 14px; }
.cmw-pop.is-min .cmw-pop-body,
.cmw-pop.is-min .cmw-pop-typing,
.cmw-pop.is-min .cmw-pop-compose { display: none; }
.cmw-pop.is-min .cmw-pop-head { border-radius: 14px; }

/* Head */
.cmw-pop-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 8px 9px 12px;
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
    border-bottom: 1px solid var(--border);
    cursor: pointer;   /* klik head = minimize/restore */
    flex-shrink: 0;
}
.cmw-pop-who { min-width: 0; flex: 1; line-height: 1.25; }
.cmw-pop-nama {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}
.cmw-pop-sub {
    font-size: 11px;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cmw-pop-sub.on { color: var(--success); }
.cmw-pop-head-badge {
    display: none;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}
.cmw-pop.is-min.has-unread .cmw-pop-head-badge { display: inline-block; }

.cmw-pop-acts { display: flex; align-items: center; gap: 1px; flex-shrink: 0; }
.cmw-pop-acts button {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--text-light);
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
}
.cmw-pop-acts button:hover { background: var(--surface-3); color: var(--text); }
.cmw-pop-acts .cmw-pop-x:hover { background: rgba(239,68,68,.12); color: var(--danger); }

/* Body / messages */
.cmw-pop-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background:
        radial-gradient(circle at 100% 0, rgba(37,99,235,.04), transparent 240px),
        var(--surface-2);
}
.cmw-pop-body::-webkit-scrollbar { width: 6px; }
.cmw-pop-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.cmw-daysep {
    align-self: center;
    margin: 8px 0;
    padding: 3px 12px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-light);
    background: var(--surface-3);
    border-radius: 10px;
}

.cmw-b-row { display: flex; margin-top: 2px; }
.cmw-b-row.mine { justify-content: flex-end; }
.cmw-b-row.theirs { justify-content: flex-start; }
.cmw-b-wrap { max-width: 82%; display: flex; flex-direction: column; }
.cmw-b-row.mine .cmw-b-wrap { align-items: flex-end; }

.cmw-b {
    padding: 8px 11px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.cmw-b-row.theirs .cmw-b {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 5px;
}
.cmw-b-row.mine .cmw-b {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.cmw-b-row.is-ai .cmw-b {
    background: linear-gradient(135deg, rgba(124,58,237,.10), rgba(79,70,229,.08));
    border-color: rgba(124,58,237,.22);
}

.cmw-b-img { padding: 4px; }
.cmw-b-img img {
    display: block;
    max-width: 100%;
    max-height: 220px;
    border-radius: 10px;
    cursor: pointer;
}
.cmw-b-cap { margin-top: 5px; padding: 0 4px 2px; }

.cmw-file {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    color: inherit;
    min-width: 180px;
}
.cmw-file-ico {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: rgba(0,0,0,.10);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.cmw-b-row.theirs .cmw-file-ico { background: var(--surface-3); }
.cmw-file-meta { min-width: 0; }
.cmw-file-nama { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.cmw-file-size { font-size: 10.5px; opacity: .8; }

.cmw-b-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    padding: 0 3px;
    font-size: 10px;
    color: var(--text-light);
}
.cmw-ticks { font-size: 13px; }
.cmw-ticks.read { color: var(--primary); }

/* Typing (AI) */
.cmw-pop-typing {
    padding: 4px 14px 8px;
    flex-shrink: 0;
    background: var(--surface-2);
}
.cmw-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 9px 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    border-bottom-left-radius: 5px;
}
.cmw-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-light);
    animation: cmwTyping 1.2s infinite ease-in-out;
}
.cmw-typing-dots span:nth-child(2) { animation-delay: .18s; }
.cmw-typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes cmwTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Composer */
.cmw-pop-compose {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}
.cmw-pop-compose textarea {
    flex: 1;
    resize: none;
    max-height: 96px;
    min-height: 38px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--text);
    font-family: "Poppins", sans-serif;
    font-size: 13px;
    line-height: 1.4;
    outline: none;
    transition: border-color .15s, background .15s;
}
.cmw-pop-compose textarea:focus { border-color: var(--primary); background: var(--surface); }
.cmw-c-btn {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-light);
    font-size: 19px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, color .15s;
}
.cmw-c-btn:hover { background: var(--surface-3); color: var(--primary); }
.cmw-c-send { background: var(--primary); color: #fff; }
.cmw-c-send:hover { background: var(--primary-hover); color: #fff; }
.cmw-c-send:disabled { opacity: .45; cursor: not-allowed; background: var(--surface-3); color: var(--text-light); }

/* Chip file terlampir (pra-kirim) */
.cmw-c-file {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 10px;
    padding: 7px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 12px;
    color: var(--text);
}
.cmw-c-file i:first-child { color: var(--primary); }
.cmw-c-file .cmw-c-file-nama { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmw-c-file .cmw-c-file-size { color: var(--text-light); font-size: 11px; }
.cmw-c-file-x {
    margin-left: auto;
    width: 22px; height: 22px;
    border: none; background: transparent;
    border-radius: 6px; cursor: pointer;
    color: var(--text-light); font-size: 15px;
    display: flex; align-items: center; justify-content: center;
}
.cmw-c-file-x:hover { background: rgba(239,68,68,.12); color: var(--danger); }

/* ── Tombol salin di gelembung (muncul halus saat hover) ─────────────────── */
.cmw-b-copy {
    border: none;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    padding: 0 1px;
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    opacity: 0;
    transition: opacity .15s, color .15s;
}
.cmw-b-row:hover .cmw-b-copy { opacity: .7; }
.cmw-b-copy:hover { opacity: 1; color: var(--primary); }
.cmw-b-copy.ok { opacity: 1; color: var(--success); }
/* Perangkat sentuh tak punya hover — tampilkan samar biar tetap kejangkau. */
@media (hover: none) { .cmw-b-copy { opacity: .55; } }

/* ── Thumbnail gambar di chip lampiran (paste/attach) ────────────────────── */
.cmw-c-file-thumb {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}

/* ── Saklar suara notifikasi (state mute) ────────────────────────────────── */
#cmw-sound-toggle.is-off { color: var(--text-light); opacity: .7; }
#cmw-sound-toggle.is-off:hover { opacity: 1; color: var(--danger); background: rgba(239,68,68,.10); }

/* ── RESPONSIVE ─────────────────────────────────────────────────────────── */
/* Panel dropdown jadi bottom sheet di layar sempit. Breakpoint 600px
   disamakan dgn ambang popup .navbar-actions di navbar: saat ikon chat dibuka
   dari dalam popup mobile, panel ini ber-anchor ke viewport (bottom sheet),
   bukan nempel ke tombol di dalam popup. */
@media (max-width: 600px) {
    .cmw-panel {
        position: fixed;
        inset: auto 0 0 0;
        top: auto;
        width: 100%;
        max-width: 100%;
        border-radius: 18px 18px 0 0;
        max-height: 84vh;
        transform: translateY(100%);
        transition: opacity .2s ease, transform .22s ease-out, visibility .2s;
    }
    .cmw-panel.show { transform: translateY(0); }
    .cmw-list { max-height: none; flex: 1 1 auto; }
}

/* Popup: satu jendela near-fullscreen di layar kecil (chat head bertumpuk gak
   muat). Dock jadi lapisan penuh, cuma popup TERAKHIR yang tampil. */
@media (max-width: 640px) {
    .cmw-dock {
        right: 0; bottom: 0; left: 0;
        gap: 0;
        justify-content: stretch;
    }
    .cmw-pop {
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }
    /* Cuma popup paling kanan (terakhir dibuka) yang kelihatan; sisanya di
       belakang. Chat head bertumpuk itu pola desktop. */
    .cmw-dock .cmw-pop:not(:last-child) { display: none; }
    .cmw-pop.is-min { height: auto !important; }
    /* Minimize di mobile = bilah nempel di dasar layar: bulatkan sudut ATAS saja. */
    .cmw-pop.is-min { position: fixed; bottom: 0; right: 0; left: 0; border-radius: 14px 14px 0 0; }
}

/* Sembunyikan saat cetak. */
@media print {
    .cmw-panel, .cmw-dock { display: none !important; }
}