:root {
  --bg: #f4f2ee; --panel: #fffdf9; --ink: #1d1f1c; --muted: #6d7069; --line: #e3dfd6;
  --brand: #0f6b4f; --brand-ink: #fff; --brand-soft: #e3f1ea; --admin: #e6eefb; --ai: #dcf3e6;
  --danger: #b23a2b; --warn: #fff4d6; --warn-ink: #7a5a00; --top: #17201c;
  --l-baru: #8a8f86; --l-retail: #2f6fb3; --l-custom: #9a5bc4; --l-deal: #0f8a4f; --l-spam: #b23a2b; --l-perlu_admin: #c27c0e;
  --radius: 10px; font-synthesis: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; --bg: #121614; --panel: #1a201d; --ink: #e8ebe6; --muted: #98a096; --line: #2b332f; --brand-soft: #1d3a2e;
    --admin: #1f2b3d; --ai: #1c3529; --warn: #3a3018; --warn-ink: #f0d58a; --top: #0c100e; }
}
:root[data-theme="dark"] { color-scheme: dark; --bg: #121614; --panel: #1a201d; --ink: #e8ebe6; --muted: #98a096; --line: #2b332f; --brand-soft: #1d3a2e;
  --admin: #1f2b3d; --ai: #1c3529; --warn: #3a3018; --warn-ink: #f0d58a; --top: #0c100e; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); display: flex; flex-direction: column; }
h1, h2, h3 { margin: 0 0 .6em; letter-spacing: -.01em; }
h2 { font-size: 20px; } h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; } .mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; }
label.check input { width: auto; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--brand); } .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); } .btn.ghost { background: transparent; } .btn.sm { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: wait; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.muted { color: var(--muted); } .sm { font-size: 12px; } .r { text-align: right; } .mt { margin-top: 18px; }
.row { display: flex; align-items: flex-end; } .row.gap { gap: 10px; } .between { justify-content: space-between; align-items: center; gap: 10px; } .wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* Header */
.top { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--top); color: #e8ebe6; flex-wrap: wrap; }
.top select { width: auto; min-width: 180px; background: #232c27; border-color: #33403a; color: #fff; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand-mark { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--brand); color: #fff; font-size: 22px; }
.brand-mark.sm { width: 26px; height: 26px; font-size: 13px; border-radius: 7px; }
nav { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }
nav button { background: none; border: 0; color: #b7c0b9; padding: 7px 11px; border-radius: 7px; cursor: pointer; font: inherit; }
nav button.active, nav button:hover { background: #26302b; color: #fff; }
.top .btn.ghost { color: #b7c0b9; border-color: #33403a; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: #2a332e; color: #c9d1cb; }
.pill.connected { background: #164d35; color: #b8f0d3; } .pill.qr, .pill.connecting, .pill.reconnecting { background: #4d3d12; color: #f6dc93; }
.pill.logged_out, .pill.disconnected { background: #4a2420; color: #f3b9b0; }
.banner { background: var(--warn); color: var(--warn-ink); padding: 8px 16px; font-size: 13px; }

main { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-height: 0; } .view.pad { padding: 20px 24px; overflow: auto; }

/* Inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr 290px; }
.list-pane, .info-pane { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.info-pane { border-right: 0; border-left: 1px solid var(--line); padding: 14px; gap: 10px; overflow: auto; }
.search { margin: 10px; width: calc(100% - 20px); }
.view.pad .search { margin: 0; width: 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 10px 8px; }
.chip { border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 99px; padding: 3px 9px; font-size: 12px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }
.chip.active { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.contact-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.contact-list li { padding: 10px 12px; border-top: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.contact-list li:hover { background: var(--bg); } .contact-list li.active { background: var(--brand-soft); }
.contact-list .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-list .pv { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-list .tm { font-size: 11px; color: var(--muted); text-align: right; }
.badge { font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: 99px; color: #fff; text-transform: uppercase; letter-spacing: .03em; justify-self: end; }
.unread { background: var(--brand); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; margin-left: 4px; }
.flag { color: var(--l-perlu_admin); font-size: 11px; font-weight: 600; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-pane > div { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.empty { display: grid; place-items: center; color: var(--muted); }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); gap: 10px; }
.back { display: none; } .grow { flex: 1; min-width: 0; }
.chat-actions { display: flex; gap: 10px; align-items: center; } .chat-actions select { width: auto; }
.needs { background: var(--warn); color: var(--warn-ink); padding: 7px 16px; font-size: 13px; display: flex !important; flex-direction: row !important; justify-content: space-between; align-items: center; flex: none !important; }
.messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 72%; padding: 7px 11px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 0 rgba(0,0,0,.05); background: var(--panel); align-self: flex-start; }
.msg.out { align-self: flex-end; background: var(--ai); } .msg.admin { background: var(--admin); }
.msg.system { align-self: center; background: transparent; box-shadow: none; color: var(--muted); font-size: 12px; font-style: italic; }
.msg .meta { font-size: 10.5px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg img { max-width: 240px; border-radius: 8px; display: block; margin-bottom: 4px; }
.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--panel); align-items: flex-end; flex: none; }
.composer textarea { max-height: 140px; }
.switch { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; cursor: pointer; flex: none; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 99px; background: var(--line); position: relative; transition: .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--brand); } .switch input:checked + span::after { left: 16px; }
.doc-mini { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.doc-mini li { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; cursor: pointer; font-size: 12px; display: flex; justify-content: space-between; gap: 6px; }
.doc-mini li:hover { border-color: var(--brand); }

/* Tables & panels */
.tbl { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; margin-top: 12px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.tbl tbody tr:hover { background: var(--bg); cursor: pointer; }
.tbl.items td { padding: 4px; } .tbl.items input { padding: 5px 7px; } .tbl.items tbody tr:hover { cursor: default; }
.status { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); }
.status.paid, .status.accepted { background: var(--brand-soft); border-color: transparent; } .status.draft { background: var(--warn); color: var(--warn-ink); border-color: transparent; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; align-items: start; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; } .card .k { color: var(--muted); font-size: 12px; }
.bar { display: grid; grid-template-columns: 90px 1fr 40px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.bar i { height: 10px; border-radius: 99px; display: block; }
.daily { display: flex; align-items: flex-end; gap: 4px; height: 140px; }
.daily div { flex: 1; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.daily div span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); }
.qr-box { display: grid; place-items: center; min-height: 120px; margin: 10px 0; border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px; color: var(--muted); }
.qr-box img { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 8px; }
.calc { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pre { background: var(--bg); border-radius: 8px; padding: 10px; font-size: 12px; white-space: pre-wrap; max-height: 260px; overflow: auto; }

.modal { border: 0; border-radius: 14px; padding: 18px; width: min(920px, 96vw); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.sm { width: min(520px, 96vw); } .modal::backdrop { background: rgba(10,15,12,.45); }
.modal form { display: flex; flex-direction: column; gap: 10px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--top); color: #fff; padding: 9px 16px; border-radius: 9px; transition: .25s; z-index: 50; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }

/* Login */
.login-body { display: grid; place-items: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); padding: 32px; border-radius: 16px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 6px 0 0; } .err { color: var(--danger); min-height: 1em; margin: 0; }

@media (max-width: 1100px) { .inbox { grid-template-columns: 280px 1fr; } .info-pane { display: none !important; } }
@media (max-width: 760px) {
  .inbox { grid-template-columns: 1fr; } .back { display: inline-flex; } .inbox.chat-open .list-pane { display: none; } .inbox:not(.chat-open) .chat-pane { display: none; }
  .grid2 { grid-template-columns: 1fr; } .msg { max-width: 88%; } .view.pad { padding: 14px; } nav { margin-left: 0; }
}

/* hidden selalu menang */
[hidden] { display: none !important; }
.pre:empty { display: none; }
@media (max-width: 760px) { .top { gap: 8px; } .top nav { order: 5; width: 100%; flex-wrap: nowrap; overflow-x: auto; } .top nav button { flex: none; } }
