:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #161a20;
  --muted: #69717d;
  --border: #dfe3e8;
  --accent: #e8553d;
  --accent-text: #ffffff;
  --user: #2f6fed;
  --ok: #1f9d55;
  --bad: #d64545;
  --warn: #c98a0c;
  --shadow: 0 6px 24px rgba(15, 18, 22, 0.08);
  --radius: 16px;
  --tabbar-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --text: #e8ebef;
    --muted: #8b94a1;
    --border: #2a3039;
    --accent: #ff6a4d;
    --user: #4c86f5;
    --ok: #3cc57a;
    --bad: #f06a6a;
    --warn: #e0a93a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 14px; cursor: pointer; }
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--bad); }
button.wide { width: 100%; }
button:disabled { opacity: 0.6; }
input, textarea, select { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
h1, h2 { margin: 0 0 6px; }
h2 { font-size: 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--bad); min-height: 1.4em; margin: 0; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); background: var(--surface); border-radius: 24px; padding: 28px 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.logo { font-size: 52px; line-height: 1; }

/* kerangka aplikasi */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 6px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.pill.online::before { background: var(--ok); }
.pill.busy::before { background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
main { flex: 1; overflow-y: auto; padding: 12px 14px calc(var(--tabbar-h) + 86px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-between select { width: auto; max-width: 60%; }

/* chat */
.log { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 3px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.bubble { background: var(--surface); border: 1px solid var(--border); padding: 10px 13px; border-radius: 18px 18px 18px 6px; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); }
.msg.user .bubble { background: var(--user); color: #fff; border-color: var(--user); border-radius: 18px 18px 6px 18px; }
.bubble a { color: inherit; text-decoration: underline; word-break: break-all; }
.meta { font-size: 11px; color: var(--muted); padding: 0 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .logo { margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chip { font-size: 13px; padding: 8px 12px; border-radius: 999px; background: var(--surface); }
.working { margin-top: 12px; padding: 12px; border: 1px dashed var(--border); border-radius: var(--radius); font-size: 13px; display: flex; flex-direction: column; gap: 5px; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* kartu izin & pertanyaan */
.prompts { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.prompt { background: var(--surface); border: 2px solid var(--warn); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.prompt.question { border-color: var(--user); }
.prompt pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 12px; background: var(--surface-2); border-radius: 10px; padding: 8px; max-height: 180px; overflow: auto; }
.prompt label { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.prompt label input { width: auto; margin-top: 4px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* siap kirim */
.send-group { margin: 14px 0 6px; font-weight: 600; }
.send-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.send-item.done { opacity: 0.55; }
.send-item .text { font-size: 14px; white-space: pre-wrap; max-height: 140px; overflow: auto; background: var(--surface-2); border-radius: 10px; padding: 8px; }
.send-item a.button { display: block; text-align: center; text-decoration: none; background: #25d366; color: #fff; border-radius: 12px; padding: 10px; font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; margin-left: 2px; }

/* input & tab bawah */
.composer { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--border); }
.composer textarea { resize: none; max-height: 140px; border-radius: 22px; padding: 11px 16px; }
.composer .send { width: 46px; height: 46px; flex: none; border-radius: 50%; background: var(--accent); color: #fff; border: 0; font-size: 18px; padding: 0; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--surface); border-top: 1px solid var(--border); }
.tabbar button { flex: 1; border: 0; border-radius: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 12px; color: var(--muted); }
.tabbar button span { font-size: 19px; }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.app.no-composer .composer { display: none; }
.app.no-composer main { padding-bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 90px); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: 0.2s; max-width: 90vw; z-index: 20; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--bad); color: #fff; }

@media (min-width: 760px) {
  main, .composer { max-width: 760px; margin: 0 auto; width: 100%; }
  .composer { left: 50%; transform: translateX(-50%); }
}
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }
.msg.user code { background: rgba(255, 255, 255, 0.18); }
