:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-ink: #0b1220;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }

button {
  font: inherit; cursor: pointer; border: none; border-radius: 10px;
  padding: 10px 14px; background: var(--panel-2); color: var(--text);
  transition: opacity .15s, transform .05s;
}
button:active { transform: scale(.97); }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { background: var(--red); color: #fff; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: not-allowed; }

input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
textarea { resize: vertical; min-height: 72px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; }
.login-card { background: var(--panel); border-radius: 16px; padding: 28px 22px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.pin-grid { display: flex; gap: 10px; justify-content: center; margin: 8px 0 20px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); }
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }
.pin-dot.err { border-color: var(--red); }

/* ── Header ── */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.topbar .title { font-weight: 700; font-size: 17px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 12px; color: var(--muted); text-align: right; }

/* ── Lists ── */
.list-head { padding: 16px 16px 8px; display: flex; align-items: center; gap: 10px; }
.list-head h2 { margin: 0; font-size: 18px; }
.search { margin: 0 16px 12px; }
.filters { display: flex; gap: 8px; padding: 0 16px 12px; overflow-x: auto; }
.filters select { width: auto; flex-shrink: 0; }
.chip { flex-shrink: 0; padding: 8px 12px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

.lead-card { background: var(--panel); border-radius: 14px; margin: 0 16px 10px; padding: 14px 16px; }
.lead-card .top { display: flex; align-items: flex-start; gap: 10px; }
.lead-card .avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--panel-2); display: grid; place-items: center; font-weight: 700; font-size: 16px; color: var(--accent); flex-shrink: 0; }
.lead-card .name { font-weight: 600; font-size: 16px; }
.lead-card .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.lead-card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.badge { font-size: 11.5px; padding: 3px 8px; border-radius: 6px; font-weight: 600; }
.badge.unit { background: #0e2a3a; color: var(--accent); }
.badge.s-baru { background: #1e3a2a; color: var(--green); }
.badge.s-prospek { background: #3a2f10; color: var(--amber); }
.badge.s-nego { background: #3a2f10; color: var(--amber); }
.badge.s-deal { background: #1e3a2a; color: var(--green); }
.badge.s-gagal { background: #3a1e1e; color: var(--red); }
.badge.owner { background: var(--panel-2); color: var(--muted); }
.badge.fu { background: #3a2f10; color: var(--amber); }
.lead-card .last { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ── Thread ── */
.thread-head { background: var(--panel); border-radius: 14px; margin: 16px; padding: 16px; }
.thread-head .name { font-size: 19px; font-weight: 700; }
.thread-head .contact { color: var(--muted); font-size: 13px; margin-top: 4px; }
.thread-head .edit { margin-top: 12px; }

.tabs { display: flex; margin: 0 16px; border-bottom: 1px solid var(--line); }
.tab { padding: 10px 14px; font-size: 14px; color: var(--muted); background: none; border-bottom: 2px solid transparent; border-radius: 0; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.pane { padding: 16px; }
.timeline { display: flex; flex-direction: column; gap: 12px; }
.msg { background: var(--panel); border-radius: 12px; padding: 12px 14px; }
.msg .head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.msg .kind { font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.kind-wa { color: #25d366; }
.kind-telp { color: var(--amber); }
.kind-email { color: var(--accent); }
.kind-ketemu { color: #a78bfa; }
.kind-catatan { color: var(--muted); }
.msg .body { white-space: pre-wrap; word-break: break-word; }

.item-row { background: var(--panel); border-radius: 12px; padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }
.item-row .grow { flex: 1; }
.item-row .t { font-weight: 600; }
.item-row .d { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.item-row .amount { font-weight: 700; white-space: nowrap; }
.due-over { color: var(--red); }

.check { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line); display: grid; place-items: center; flex-shrink: 0; margin-top: 2px; }
.check.done { background: var(--green); border-color: var(--green); color: #fff; }

.composer { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer .row { display: flex; gap: 8px; margin-bottom: 8px; }
.composer select { width: auto; flex-shrink: 0; }
.composer textarea { min-height: 52px; }

/* ── Modal ── */
.modal-back { position: fixed; inset: 0; background: rgba(2,6,23,.7); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--panel); width: 100%; max-width: 720px; border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto; }
.modal h3 { margin: 0 0 4px; }
.modal .actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .actions button { flex: 1; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel-2); color: var(--text); padding: 12px 18px; border-radius: 999px; font-size: 14px; z-index: 99; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 14px; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.fab { position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 28px; font-weight: 700; box-shadow: 0 8px 20px rgba(0,0,0,.4); z-index: 40; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
