:root {
  --bg: #f0f2f5; --panel: #fff; --line: #e5e7eb; --text: #111b21; --muted: #667781;
  --green: #00a884; --green-dark: #008069; --bubble-out: #d9fdd3; --bubble-in: #fff;
  --chat-bg: #efeae2; --danger: #dc2626; --hover: #f5f6f6; --active: #f0f2f5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a; --panel: #111b21; --line: #222d34; --text: #e9edef; --muted: #8696a0;
    --bubble-out: #005c4b; --bubble-in: #202c33; --chat-bg: #0b141a; --hover: #202c33; --active: #2a3942;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1em; margin: 0; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { margin: 0; color: var(--green); }

/* Layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.nav { width: 72px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: stretch; padding: 8px 0; }
.brand { font-weight: 700; color: var(--green); text-align: center; font-size: 12px; padding: 8px 0 12px; }
.navbtn { background: none; border: 0; padding: 10px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 18px; border-radius: 8px; margin: 0 6px; }
.navbtn span { font-size: 11px; color: var(--muted); }
.navbtn:hover, .navbtn.active { background: var(--active); }
.nav-spacer { flex: 1; }
.me { text-align: center; font-size: 11px; padding: 6px 2px; word-break: break-word; }
.me small { display: block; color: var(--muted); }
.view { flex: 1; min-width: 0; }
.page { overflow: auto; padding: 24px; }
.page h2 { margin-top: 0; }

/* Inbox */
.inbox { display: flex; height: 100vh; }
.list-pane { width: 360px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.filters { padding: 10px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--line); }
.filter-row { display: flex; gap: 6px; }
.filter-row select { flex: 1; }
.contact-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.contact { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 10px; }
.contact:hover { background: var(--hover); }
.contact.active { background: var(--active); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: #dfe5e7; color: #54656f; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }
.contact-main { flex: 1; min-width: 0; }
.contact-top { display: flex; justify-content: space-between; gap: 6px; }
.contact-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.contact-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; justify-content: space-between; gap: 6px; }
.contact-preview .txt { overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--green); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; flex-shrink: 0; }
.acct-chip { font-size: 11px; color: var(--green-dark); }
.tags-inline { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 8px; border-radius: 10px; color: #fff; }
.tag button { background: none; border: 0; color: #fff; cursor: pointer; padding: 0; font-size: 12px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.chat-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); }
.empty-state { margin: auto; color: var(--muted); }
.chat-head { background: var(--panel); padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.chat-head .info { flex: 1; min-width: 0; }
.chat-head .sub { font-size: 12px; color: var(--muted); }
.back-btn { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 3px 10px; border-radius: 8px; margin: 8px 0; }
.bubble { max-width: 70%; padding: 6px 10px 4px; border-radius: 8px; background: var(--bubble-in); box-shadow: 0 1px .5px rgba(0,0,0,.13); white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); }
.bubble .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.composer { background: var(--panel); padding: 10px; display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 140px; border-radius: 20px; padding: 10px 14px; }
.composer .btn { border-radius: 20px; }
.quick { display: flex; gap: 6px; padding: 6px 10px 0; background: var(--panel); flex-wrap: wrap; }
.quick button { font-size: 12px; }

.detail-pane { width: 300px; flex-shrink: 0; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; }
.detail-pane h4 { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.detail-pane input, .detail-pane select, .detail-pane textarea { width: 100%; }
.detail-pane textarea { min-height: 120px; resize: vertical; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-picker .tag { cursor: pointer; opacity: .35; border: 0; }
.tag-picker .tag.on { opacity: 1; }
.saved { font-size: 12px; color: var(--green); height: 1em; }

/* Settings / dashboard */
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.inline-form input:not([type=color]), .inline-form select { flex: 1 1 160px; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 180px; }
.status { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--active); }
.status.connected { background: #dcfce7; color: #166534; }
.status.qr, .status.connecting { background: #fef9c3; color: #854d0e; }
.status.disconnected, .status.stopped { background: #fee2e2; color: #991b1b; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-cloud .tag { font-size: 13px; padding: 3px 10px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat b { display: block; font-size: 26px; }
.stat > span { color: var(--muted); font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-top: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 500; border-top: 0; }
.warn { color: var(--danger); font-weight: 600; }
.bar { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.bar .label { width: 110px; font-size: 13px; }
.bar .track { flex: 1; background: var(--active); border-radius: 4px; height: 10px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--green); }
.bar .n { width: 36px; text-align: right; font-size: 13px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-card { width: 100%; max-width: 380px; text-align: center; }
.qr-body { min-height: 260px; display: grid; place-items: center; }
.qr-body img { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111b21; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: calc(100% - 32px); }

/* Mobile */
@media (max-width: 900px) {
  .detail-pane { position: fixed; inset: 0 0 0 auto; width: min(320px, 100%); z-index: 5; box-shadow: -4px 0 16px rgba(0,0,0,.2); }
}
@media (max-width: 700px) {
  .app { flex-direction: column-reverse; }
  /* Menu sentiasa melekat di bawah skrin, tak perlu scroll untuk jumpa */
  .nav { width: 100%; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 4px; flex-shrink: 0; position: sticky; bottom: 0; z-index: 4; }
  .brand, .me, .nav-spacer { display: none; }
  .navbtn { flex: 1; margin: 0 2px; }
  .inbox, .page { height: auto; flex: 1; min-height: 0; }
  .list-pane { width: 100%; }
  .inbox.chat-open .list-pane { display: none; }
  .inbox:not(.chat-open) .chat-pane { display: none; }
  .back-btn { display: inline-block; }
  .messages { padding: 12px; }
  .bubble { max-width: 85%; }
  .page { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
}

/* Composer: quick reply & lampiran */
.composer-wrap { position: relative; }
.icon-btn { background: none; border: 0; font-size: 20px; cursor: pointer; padding: 6px 4px; border-radius: 8px; }
.icon-btn:hover { background: var(--hover); }
.qr-menu { position: absolute; bottom: 100%; left: 10px; right: 10px; max-height: 260px; overflow-y: auto; list-style: none; margin: 0 0 6px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); z-index: 4; }
.qr-menu li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.qr-menu li span { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-menu li.sel, .qr-menu li:hover { background: var(--active); }
.qr-menu li.none { cursor: default; color: var(--muted); }
.qr-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.qr-form button { align-self: flex-start; }
.qr-body-text { white-space: pre-wrap; font-size: 13px; }
.attach-preview { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); }
.attach-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.attach-preview .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-ico { font-size: 28px; }
.chat-pane.dragging { outline: 3px dashed var(--green); outline-offset: -6px; }

/* Media dalam bubble */
.media-img { display: block; max-width: min(320px, 100%); max-height: 360px; border-radius: 6px; margin-bottom: 4px; background: var(--active); min-height: 60px; }
.media-sticker { width: 140px; height: 140px; object-fit: contain; }
.bubble.sticker { background: none; box-shadow: none; }
.bubble audio { max-width: 260px; display: block; }
.media-doc { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 6px; background: rgba(0,0,0,.05); color: inherit; text-decoration: none; margin-bottom: 4px; }
.media-missing { font-size: 13px; color: var(--muted); padding: 6px 0; }

/* Follow-up */
.fu-chip { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--active); color: var(--muted); }
.fu-chip.due { background: #fee2e2; color: #991b1b; }
.fu-banner { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fef3c7; color: #78350f; padding: 10px 12px; cursor: pointer; font: inherit; }
.fu-box { background: var(--active); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.fu-box .when { font-weight: 600; }
.fu-box .when.due { color: var(--danger); }
.fu-quick { display: flex; flex-wrap: wrap; gap: 4px; }

/* Banyak nombor */
.acct-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.acct-toolbar input { flex: 1 1 220px; }
.client-group h4 { margin: 14px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--green-dark); }
.assign { position: relative; }
.assign summary { list-style: none; }
.assign summary::-webkit-details-marker { display: none; }
.assign-menu { position: absolute; right: 0; top: 110%; z-index: 6; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-width: 180px; max-height: 260px; overflow-y: auto; box-shadow: 0 6px 20px rgba(0,0,0,.18); display: flex; flex-direction: column; gap: 6px; }
.assign-menu label { display: flex; gap: 8px; align-items: center; cursor: pointer; white-space: nowrap; }
.contact-list .more { padding: 12px; text-align: center; }

/* Laporan masa respons */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h2 { margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-head h3 { margin: 0; }
.small-note { font-size: 12px; margin: 6px 0 12px; }
.sub-h { margin: 16px 0 4px; font-size: 13px; }
.fast { color: #16a34a; }
.ok { color: #ca8a04; }
.slow { color: var(--danger); }
.daily { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 18px; overflow-x: auto; }
.day-col { flex: 1 0 28px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; }
.day-col .col { width: 70%; max-width: 36px; border-radius: 4px 4px 0 0; background: var(--green); }
.day-col .col.ok { background: #eab308; }
.day-col .col.slow { background: var(--danger); }
.day-col .v, .day-col .d { font-size: 10px; color: var(--muted); white-space: nowrap; }
