:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --border: #dde2dd;
  --text: #17201b;
  --muted: #66716a;
  --accent: #1f9d6a;
  --accent-ink: #ffffff;
  --accent-soft: #dff3ea;
  --mine: #dcf5e6;
  --danger: #c43d3d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #161d1a;
    --surface-2: #1e2723;
    --border: #2a3530;
    --text: #e6ece8;
    --muted: #93a099;
    --accent: #2fbf84;
    --accent-ink: #062016;
    --accent-soft: #173a2b;
    --mine: #193a2b;
    --danger: #ef6b6b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }

button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.05); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.small { padding: 5px 10px; font-size: 13px; }
button.block { width: 100%; }

input, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); margin: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.01em; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: url(/favicon.svg) center/cover; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); padding: 28px; display: grid; gap: 14px; }
.login-card .brand { font-size: 20px; margin-bottom: 6px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

/* Kerangka */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 4px; flex: 1; justify-content: center; }
.tab { border: none; background: transparent; color: var(--muted); padding: 7px 12px; display: flex; align-items: center; gap: 6px; }
.tab.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--accent); }
.dot.wait { background: #e0a526; }

.panel { flex: 1; min-height: 0; }
.panel.center { display: grid; place-items: start center; padding: 24px 16px; overflow: auto; }
.split { display: grid; grid-template-columns: 290px 1fr; }
.sidebar {
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0;
}
.list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.list li {
  padding: 9px 10px; border-radius: 9px; cursor: pointer; display: flex; gap: 8px; align-items: center;
}
.list li:hover { background: var(--surface-2); }
.list li.active { background: var(--accent-soft); }
.list .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.list .x { opacity: 0; border: none; background: none; padding: 0 4px; color: var(--muted); }
.list li:hover .x { opacity: 1; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }

.chatpane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread { flex: 1; overflow: auto; padding: 20px max(16px, calc((100% - 760px) / 2)); display: flex; flex-direction: column; gap: 14px; }
.empty { margin: auto; text-align: center; max-width: 520px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 20px; margin-bottom: 6px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.chip { border-radius: 999px; font-size: 13.5px; }

.msg { max-width: 100%; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); padding: 9px 14px; border-radius: 14px 14px 4px 14px; max-width: 85%; white-space: pre-wrap; }
.msg.assistant { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; }
.msg.assistant > :first-child { margin-top: 0; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg.assistant p, .msg.assistant ul, .msg.assistant ol { margin: .5em 0; }
.msg.assistant ul, .msg.assistant ol { padding-left: 1.3em; }
.msg.assistant h3, .msg.assistant h4 { margin: .9em 0 .3em; font-size: 15.5px; }
.msg.assistant code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg.assistant blockquote { margin: .5em 0; padding: 2px 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.trace { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.trace summary { cursor: pointer; }
.trace .step::before { content: "› "; color: var(--accent); }
.thinking { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13.5px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 12px max(16px, calc((100% - 760px) / 2)) 16px;
  border-top: 1px solid var(--border); background: var(--bg);
}
.composer textarea { resize: none; max-height: 200px; }

/* Jelajah chat */
.bubble { max-width: 75%; padding: 7px 11px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); white-space: pre-wrap; word-wrap: break-word; }
.bubble.mine { align-self: flex-end; background: var(--mine); }
.bubble .who { font-size: 12px; font-weight: 600; color: var(--accent); }
.bubble .time { font-size: 11px; color: var(--muted); text-align: right; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 2px 10px; border-radius: 999px; }
.thread .more { align-self: center; }

/* WhatsApp */
.wa-card { width: min(480px, 100%); padding: 24px; display: grid; gap: 14px; text-align: center; }
.wa-card h2 { margin: 0; }
.qr { width: 260px; height: 260px; margin: 0 auto; background: #fff; padding: 10px; border-radius: 12px; }
.qr svg { width: 100%; height: 100%; display: block; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; text-align: left; }
.stats div { background: var(--surface-2); border-radius: 9px; padding: 8px 12px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 0; font-weight: 600; }
.progress { grid-column: 1 / -1; }
.bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--accent); }

@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 8px 12px; flex-wrap: wrap; }
  .topbar .brand { font-size: 0; gap: 0; }
  .tabs { justify-content: flex-start; }
  .split { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 34vh; }
  .split.focus .sidebar { display: none; }
  .bubble { max-width: 90%; }
}
