* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --green: #25d366; --green-d: #1da851; --teal: #075e54;
    --bg: #eae6df; --panel: #fff; --side: #fff; --line: #e9edef;
    --txt: #111b21; --sub: #667781; --in: #fff; --out: #d9fdd3;
    --head: #f0f2f5;
}
@media (prefers-color-scheme: dark) {
    :root { --bg:#0b141a; --panel:#111b21; --side:#111b21; --line:#222d34;
        --txt:#e9edef; --sub:#8696a0; --in:#202c33; --out:#005c4b; --head:#202c33; }
}
body { font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; color: var(--txt); background: var(--bg); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }

/* Login */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--teal); }
.login-card { background: var(--panel); padding: 36px 32px; border-radius: 16px; width: 320px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-logo { font-size: 44px; color: var(--green); }
.login-card h1 { font-size: 20px; margin: 8px 0 2px; }
.login-card p { color: var(--sub); font-size: 13px; margin-bottom: 18px; }
.login-card input { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 11px; font-size: 14px; background: var(--panel); color: var(--txt); }
.login-card button { width: 100%; padding: 11px; background: var(--green); color: #fff; border: 0; border-radius: 9px; font-weight: 600; cursor: pointer; }
.login-err { color: #e53935; font-size: 12px; margin-top: 10px; min-height: 16px; }

/* Layout */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 380px; min-width: 300px; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg);
    background-image: linear-gradient(rgba(0,0,0,.02),rgba(0,0,0,.02)); }

/* Sidebar head */
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--head); }
.brand { font-weight: 700; color: var(--teal); display: flex; gap: 8px; align-items: center; }
@media (prefers-color-scheme: dark){ .brand{ color: var(--green);} }
.side-actions button, .conv-actions button { background: transparent; border: 0; color: var(--sub); font-size: 16px; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; }
.side-actions button:hover, .conv-actions button:hover { background: rgba(0,0,0,.06); }

.session-bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.session-bar select { flex: 1; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--txt); font-size: 13px; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: #eee; color: #555; white-space: nowrap; }
.badge.on { background: #d9fdd3; color: #1da851; }
.badge.off { background: #ffe0e0; color: #d33; }
.badge.qr { background: #fff3cd; color: #a67c00; }
.mini { background: var(--green); color:#fff; border:0; width:32px; height:32px; border-radius:8px; cursor:pointer; }

.search { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.search i { color: var(--sub); font-size: 13px; }
.search input { flex: 1; border: 0; background: var(--head); padding: 8px 12px; border-radius: 8px; color: var(--txt); font-size: 13px; }

/* Chat list */
.chat-list { list-style: none; overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 12px; padding: 11px 16px; cursor: pointer; border-bottom: 1px solid var(--line); }
.chat-item:hover { background: var(--head); }
.chat-item.active { background: var(--head); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--teal); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; flex-shrink: 0; }
.ci-body { flex: 1; min-width: 0; }
.ci-top { display: flex; justify-content: space-between; }
.ci-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 11px; color: var(--sub); }
.ci-last { font-size: 13px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-unread { background: var(--green); color: #fff; font-size: 11px; min-width: 19px; height: 19px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }

/* Conversation */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--sub); gap: 12px; }
.empty i { font-size: 72px; opacity: .25; }
.conv { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.conv-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; background: var(--head); }
.conv-name { font-weight: 600; }
.conv-number { font-size: 12px; color: var(--sub); }
.messages { flex: 1; min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden; padding: 18px 8%; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 65%; padding: 7px 11px; border-radius: 9px; font-size: 14px; line-height: 1.4; word-wrap: break-word; position: relative; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.msg.in { align-self: flex-start; background: var(--in); border-top-left-radius: 2px; }
.msg.out { align-self: flex-end; background: var(--out); border-top-right-radius: 2px; }
.msg img { max-width: 240px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg .meta { font-size: 10px; color: var(--sub); text-align: right; margin-top: 3px; }
.msg .ai-tag { font-size: 9px; background: #6366f1; color:#fff; padding: 1px 5px; border-radius: 6px; margin-left: 5px; }

.compose { display: flex; gap: 10px; padding: 12px 16px; background: var(--head); align-items: flex-end; flex-shrink: 0; }
.reply-bar, .emoji-panel { flex-shrink: 0; }
.conv-head { flex-shrink: 0; }
.compose textarea { flex: 1; border: 0; border-radius: 10px; padding: 11px 14px; font-size: 14px; resize: none; max-height: 120px; background: var(--panel); color: var(--txt); font-family: inherit; }
.compose button { background: var(--green); color: #fff; border: 0; width: 44px; height: 44px; border-radius: 50%; font-size: 16px; cursor: pointer; flex-shrink: 0; }
.compose button:disabled { opacity: .5; cursor: not-allowed; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 14px; width: 380px; max-width: 100%; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; }
.x { background: 0; border: 0; color: var(--sub); font-size: 16px; cursor: pointer; }
.modal-body { padding: 18px; }
.modal-body label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 5px; }
.modal-body label:first-child { margin-top: 0; }
.modal-body input[type=text], .modal-body input:not([type]) { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--txt); font-size: 14px; }
.modal-body .chk { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.modal-body .chk input { width: auto; }
.hint { font-size: 11px; color: var(--sub); margin-top: 5px; }
.info { margin-top: 16px; font-size: 12px; color: var(--sub); background: var(--head); padding: 10px; border-radius: 8px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); text-align: right; }
.modal-foot button { padding: 9px 18px; border: 0; border-radius: 8px; font-weight: 600; cursor: pointer; }
.primary { background: var(--green); color: #fff; }
.danger { background: #fde8e8; color: #d33; }
.qr-body { padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; min-height: 260px; justify-content: center; color: var(--sub); }
.qr-body img { width: 220px; height: 220px; border: 3px solid var(--green); border-radius: 12px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111b21; color: #fff; padding: 11px 20px; border-radius: 10px; font-size: 13px; z-index: 200; }

@media (max-width: 720px) {
    .sidebar { width: 100%; position: absolute; inset: 0; z-index: 10; }
    .app.show-conv .sidebar { display: none; }
    .messages { padding: 14px 4%; }
}

/* ── Media, reply, emoji, tabs (fitur lanjutan) ── */
.messages-wrap { flex: 1; min-height: 0; position: relative; display: flex; overflow: hidden; }
.messages-wrap .messages { flex: 1; }
.scroll-down { position: absolute; right: 18px; bottom: 14px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--panel); color: var(--sub); box-shadow: 0 2px 8px rgba(0,0,0,.2); cursor: pointer; font-size: 15px; }

/* Media dalam bubble */
.msg img.media { max-width: 260px; border-radius: 8px; display: block; cursor: pointer; }
.msg video.media { max-width: 260px; border-radius: 8px; display: block; }
.msg audio.media { max-width: 240px; display: block; }
.msg .doc { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.05); padding: 10px 12px; border-radius: 8px; text-decoration: none; color: inherit; min-width: 200px; }
.msg .doc i { font-size: 24px; color: var(--teal); }
.msg .doc .dname { font-size: 13px; font-weight: 600; word-break: break-all; }
.msg .doc .dsub { font-size: 11px; color: var(--sub); }

/* Quoted / reply di dalam bubble */
.msg .quoted { border-left: 3px solid var(--green); background: rgba(0,0,0,.05); padding: 4px 8px; border-radius: 5px; margin-bottom: 4px; font-size: 12.5px; color: var(--sub); max-height: 48px; overflow: hidden; }
.msg .quoted b { color: var(--teal); display: block; font-size: 11px; }

/* Hover action (reply) */
.msg .msg-actions { position: absolute; top: 2px; right: 4px; opacity: 0; transition: .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg .msg-actions button { background: rgba(0,0,0,.08); border: 0; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; color: var(--sub); font-size: 11px; }

/* Reply bar (preview di atas compose) */
.reply-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--head); padding: 8px 16px; border-left: 4px solid var(--green); }
.reply-info { font-size: 13px; color: var(--sub); overflow: hidden; }
.reply-dir { display: block; font-size: 11px; font-weight: 700; color: var(--teal); }
#reply-text { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 80vw; }

/* Compose buttons */
.compose .cbtn { background: transparent; border: 0; color: var(--sub); font-size: 20px; width: 40px; height: 44px; cursor: pointer; flex-shrink: 0; }
.compose .cbtn:hover { color: var(--teal); }

/* Emoji panel */
.emoji-panel { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px; max-height: 210px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 2px; }
.emoji-panel span { font-size: 22px; cursor: pointer; padding: 4px 5px; border-radius: 6px; line-height: 1; }
.emoji-panel span:hover { background: var(--head); }
.emoji-cat { width: 100%; font-size: 11px; color: var(--sub); text-transform: uppercase; margin: 6px 2px 2px; font-weight: 700; }

/* Tabs settings */
.modal-card.lg { width: 560px; max-width: 100%; max-height: 92vh; display: flex; flex-direction: column; }
.tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { flex: 1; min-width: 110px; background: transparent; border: 0; padding: 12px 10px; font-size: 13px; font-weight: 600; color: var(--sub); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab.active { color: var(--teal); border-bottom-color: var(--green); }
.tab-pane { display: none; overflow-y: auto; }
.tab-pane.active { display: block; }

/* Device list */
.device-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.device-item { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; }
.device-item .di-body { flex: 1; min-width: 0; }
.device-item .di-name { font-weight: 600; font-size: 14px; }
.device-item .di-sub { font-size: 12px; color: var(--sub); }
.device-item .di-actions { display: flex; gap: 4px; }
.device-item .di-actions button { background: var(--head); border: 0; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; color: var(--sub); }
.device-item .di-actions button:hover { color: var(--teal); }

/* ── Halaman Pengaturan (full page) ── */
.settings-view { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: flex; justify-content: center; overflow-y: auto; }
.settings-card { background: var(--panel); width: 100%; max-width: 760px; min-height: 100%; display: flex; flex-direction: column; box-shadow: 0 0 40px rgba(0,0,0,.08); }
.settings-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px; background: var(--teal); color: #fff; position: sticky; top: 0; z-index: 2; }
.settings-head h2 { font-size: 18px; font-weight: 700; }
.settings-head .back { background: rgba(255,255,255,.15); border: 0; color: #fff; width: 38px; height: 38px; border-radius: 50%; cursor: pointer; font-size: 16px; }
.settings-head .back:hover { background: rgba(255,255,255,.28); }
.settings-view .tabs { position: sticky; top: 70px; background: var(--panel); z-index: 1; }
.settings-view .tab-pane .modal-body { padding: 22px 24px; max-width: 640px; }
.settings-view .modal-foot { position: sticky; bottom: 0; background: var(--panel); }

/* ── Ticket status (open/solved) ── */
.ticket-filter { display: flex; gap: 6px; padding: 0 12px 8px; }
.ticket-filter .tf { flex: 1; padding: 6px; border: 0; border-radius: 8px; background: var(--head); color: var(--sub); font-size: 12px; font-weight: 600; cursor: pointer; }
.ticket-filter .tf.active { background: var(--green); color: #fff; }
.tkt-badge { font-size: 9px; font-weight: 700; padding: 1px 6px; border-radius: 10px; margin-left: 4px; }
.tkt-badge.open { background: #fff3cd; color: #a67c00; }
.tkt-badge.solved { background: #d9fdd3; color: #1da851; }
.conv-actions #btn-ticket.solved { color: var(--green); }

/* ── Label custom ── */
.chat-labels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.chat-label { font-size: 9px; font-weight: 700; color: #fff; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.lbl-pick { padding: 6px 12px; border-radius: 16px; font-size: 13px; font-weight: 600; cursor: pointer; }

/* ── Pemisah sistem (tiket close/open) di room chat ── */
.msg-sys { align-self: center; background: rgba(0,0,0,.06); color: var(--sub); font-size: 11.5px; font-weight: 600; padding: 4px 14px; border-radius: 12px; margin: 8px auto; text-align: center; max-width: 80%; }
@media (prefers-color-scheme: dark){ .msg-sys { background: rgba(255,255,255,.08); } }
