:root {
  --bg: #f0f2f5; --panel: #fff; --border: #e3e6ea; --text: #1f2328; --muted: #667085;
  --green: #0f9d58; --green-dark: #0b7a44; --green-soft: #dcf8c6; --red: #d93025; --amber: #b26a00;
  --blue: #1a73e8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
textarea { resize: vertical; }
label { display: block; margin: 10px 0; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
.muted { color: var(--muted); } .small { font-size: 12px; } .error { color: var(--red); }
.btn { padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; }
.btn:hover { background: #f6f7f9; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--red); border-color: #f3c3bf; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--green); color: #fff; }

/* Login */
.login-page { align-items: center; justify-content: center; }
.login-card { background: var(--panel); padding: 28px; border-radius: 14px; width: min(360px, calc(100% - 32px)); box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.login-card .brand { margin-bottom: 12px; }
.login-card .btn { width: 100%; margin-top: 6px; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
#tabs { display: flex; gap: 4px; }
#tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
#tabs button.active { background: #e7f5ee; color: var(--green-dark); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.me { font-weight: 500; }
.switch { display: inline-flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }
.switch input { width: auto; margin: 0; }
.switch.row { margin: 12px 0; }
.wa-badge { border: 0; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer; background: #eee; }
.wa-badge.terhubung { background: #e7f5ee; color: var(--green-dark); }
.wa-badge.scan_qr, .wa-badge.memuat, .wa-badge.memulai { background: #fff4e0; color: var(--amber); }
.wa-badge.terputus, .wa-badge.gagal { background: #fde8e7; color: var(--red); }
body.not-admin .admin-only { display: none !important; }

/* Chat layout */
.tab { flex: 1; min-height: 0; }
.tab[hidden] { display: none !important; }
.page { overflow-y: auto; }
.chat-layout { display: grid; grid-template-columns: 320px 1fr 290px; }
.contacts { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.filters { padding: 10px; border-bottom: 1px solid var(--border); }
.filter-row { display: flex; gap: 6px; margin-top: 6px; }
#contactList { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#contactList li { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #f1f2f4; cursor: pointer; }
#contactList li:hover { background: #f7f8fa; }
#contactList li.active { background: #eaf6f0; }
.empty-list { justify-content: center; cursor: default !important; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; background: #d7e3dc; display: grid; place-items: center; font-weight: 700; color: var(--green-dark); }
.c-main { min-width: 0; flex: 1; }
.c-top { display: flex; justify-content: space-between; gap: 8px; }
.c-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.c-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #eef0f3; color: #4b5563; }
.tag.ai { background: #e8f0fe; color: var(--blue); }
.tag.manual { background: #fff4e0; color: var(--amber); }
.tag.owner { background: #f3e8ff; color: #7e22ce; }
.tag.st-baru { background: #e8f0fe; color: var(--blue); }
.tag.st-prospek { background: #fff4e0; color: var(--amber); }
.tag.st-butuh-admin { background: #fde8e7; color: var(--red); }
.tag.st-deal { background: #e7f5ee; color: var(--green-dark); }
.status-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.status-chips:empty { display: none; }
.chip { border: 1px solid transparent; cursor: pointer; font-size: 12px; padding: 2px 8px; }
.chip.on { border-color: currentColor; font-weight: 700; }
.unread { margin-left: auto; background: var(--green); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; }

.conversation { display: flex; flex-direction: column; min-height: 0; background: #efeae2; }
.empty { margin: auto; color: var(--muted); }
#chatView { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#chatView[hidden] { display: none; }
.chat-header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.chat-name { font-weight: 600; }
.back, .info-toggle { display: none; }
.info-toggle { margin-left: auto; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 70%; padding: 6px 10px 4px; border-radius: 10px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--green-soft); }
.msg.out.ai { background: #e3eefe; }
.msg.out.broadcast { background: #fdf3d8; }
.msg.system { align-self: center; background: #fff8e1; color: var(--amber); font-size: 12px; max-width: 90%; text-align: center; }
.msg .who { font-size: 11px; font-weight: 600; color: var(--muted); }
.msg .time { font-size: 10px; color: var(--muted); text-align: right; }
.composer { display: flex; gap: 8px; padding: 10px; background: var(--panel); border-top: 1px solid var(--border); align-items: flex-end; }
.composer textarea { min-height: 40px; max-height: 160px; }
.composer { position: relative; }
.qr-suggest { position: absolute; left: 10px; right: 10px; bottom: 100%; margin: 0 0 4px; padding: 4px; list-style: none; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 -4px 16px rgba(0,0,0,.08); max-height: 260px; overflow-y: auto; }
.qr-suggest li { padding: 6px 8px; border-radius: 6px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-suggest li.active, .qr-suggest li:hover { background: #eaf6f0; }

.details { background: var(--panel); border-left: 1px solid var(--border); padding: 12px 16px; overflow-y: auto; }
.details[hidden] { display: none; }
.details h3 { margin: 4px 0 8px; display: flex; align-items: center; justify-content: space-between; }
#dSave { width: 100%; }

/* Halaman biasa */
.page { overflow-y: auto; padding: 20px max(16px, calc((100% - 860px) / 2)); }
.page h2 { margin-top: 8px; }
.warn { background: #fff4e0; color: #7a4a00; padding: 10px 14px; border-radius: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.actions { display: flex; gap: 8px; margin: 10px 0; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin: 16px 0; }
.card h3 { margin-top: 0; }
.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table th { background: #f7f8fa; font-weight: 600; font-size: 13px; }
.ellipsis { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.qr { width: 260px; max-width: 100%; image-rendering: pixelated; }

.page.wide { padding: 20px max(16px, calc((100% - 1200px) / 2)); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.img-preview { max-width: 220px; max-height: 220px; border-radius: 8px; display: block; margin: 6px 0; object-fit: cover; }
.msg-img { display: block; max-width: 260px; width: 100%; border-radius: 8px; margin: 4px 0; }

/* Katalog */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 14px; }
.product { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.product.sold-out .p-img { opacity: .5; }
.p-img { aspect-ratio: 1; background: #f1f3f5; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.p-img img { width: 100%; height: 100%; object-fit: cover; }
.p-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.p-name { font-weight: 600; }
.p-price { color: var(--green-dark); font-weight: 700; }
.p-desc { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

dialog { border: 0; border-radius: 14px; padding: 18px 20px; width: min(520px, calc(100% - 32px)); max-height: calc(100% - 32px); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin: 0 0 8px; }
.pick-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.pick-list li { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer; }
.pick-list li:hover { background: #f1f7f4; }
.pick-list img, .pick-list .noimg { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; background: #eee; flex: none; }

/* Status */
.status-list { display: flex; flex-direction: column; gap: 8px; }
.status-item { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.status-item img, .st-text-only { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; }
.st-text-only { background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 700; }
.st-body { flex: 1; min-width: 0; white-space: pre-wrap; word-wrap: break-word; }

/* Catatan internal */
.composer-tabs { display: flex; gap: 4px; padding: 6px 10px 0; background: var(--panel); border-top: 1px solid var(--border); }
.composer-tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 8px 8px 0 0; cursor: pointer; color: var(--muted); font-weight: 500; }
.composer-tabs button.active { background: #eaf6f0; color: var(--green-dark); }
.composer-tabs button#modeNote.active { background: #fff4c2; color: #7a5c00; }
.composer.note-mode { background: #fff9dc; }
.composer.note-mode textarea { background: #fffdf0; border-color: #ecd77a; }
.msg.note { align-self: stretch; max-width: 100%; background: #fff4c2; border: 1px dashed #d9b93b; }
.mention { background: #ffe58a; border-radius: 4px; padding: 0 3px; font-weight: 600; }

/* Online & tabel */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #c5c9cf; margin-right: 6px; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px #d5f0e1; }
.inline-check { width: auto; }
.click-row { cursor: pointer; }
.click-row:hover { background: #f1f7f4; }

/* Lonceng */
.bell-wrap { position: relative; }
.bell { position: relative; }
.bell-count { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; border-radius: 999px; font-size: 10px; font-weight: 700; padding: 1px 5px; }
.bell-panel { position: absolute; right: 0; top: calc(100% + 6px); width: min(340px, 90vw); max-height: 60vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.18); z-index: 40; }
.bell-item { padding: 10px 12px; border-bottom: 1px solid #f1f2f4; cursor: pointer; }
.bell-item:hover { background: #f7f8fa; }
.bell-item.unread-item { background: #eaf6f0; }
.bell-empty { padding: 16px; text-align: center; }

/* Pipeline */
.pipeline-page { display: flex; flex-direction: column; padding: 16px; overflow: hidden; }
.pipeline-page[hidden] { display: none !important; }
.pipe-board { display: flex; gap: 12px; flex: 1; overflow-x: auto; align-items: flex-start; padding-bottom: 8px; min-height: 0; }
.pipe-col { flex: 0 0 270px; background: #e9ecef; border-radius: 12px; padding: 8px; display: flex; flex-direction: column; max-height: 100%; border: 2px solid transparent; }
.pipe-col.over { border-color: var(--green); background: #e0f2e9; }
.pipe-col header { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 8px; }
.pipe-cards { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 40px; }
.pipe-card { background: var(--panel); border-radius: 10px; padding: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.08); cursor: grab; display: flex; flex-direction: column; gap: 4px; }
.pipe-card.dragging { opacity: .4; }
.pipe-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pipe-move { padding: 3px 6px; font-size: 12px; margin-top: 2px; }
.pipe-empty { text-align: center; padding: 10px; }

/* Laporan */
.rep-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0 20px; }
.rep-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.rep-val { font-size: 28px; font-weight: 700; color: var(--green-dark); }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
.bar-label { width: 56px; flex: none; font-size: 12px; color: var(--muted); }
.bar { flex: 1; height: 14px; background: #e9ecef; border-radius: 7px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--green); border-radius: 7px; }
.bar-num { width: 150px; flex: none; font-size: 12px; color: var(--muted); }

.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: #1f2328; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 320px; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast.error { background: var(--red); }
.toast.warn { background: var(--amber); }

/* Layar kecil (HP) */
@media (max-width: 1100px) {
  .chat-layout { grid-template-columns: 300px 1fr; }
  .details { position: fixed; right: 0; top: 0; bottom: 0; width: min(320px, 100%); z-index: 20; box-shadow: -4px 0 16px rgba(0,0,0,.1); display: none; }
  body.details-open .details:not([hidden]) { display: block; }
  .info-toggle { display: inline-block; }
}
@media (max-width: 720px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
  #tabs { overflow-x: auto; }
  .chat-layout { grid-template-columns: 1fr; }
  .conversation { display: none; }
  body.chat-open .contacts { display: none; }
  body.chat-open .conversation { display: flex; }
  .back { display: inline-block; }
  .messages { padding: 12px; }
  .msg { max-width: 85%; }
  .grid2 { grid-template-columns: 1fr; }
}
