/* kantor-web — mobile-first (target ~360px), rapi di desktop.
   Indikator risiko: abu = baca, kuning = tulis, merah = destruktif/eksternal. */

:root {
  --bg: #0f1115;
  --bg2: #161a21;
  --bg3: #1e242d;
  --fg: #e6e9ef;
  --muted: #8b94a3;
  --line: #262d38;
  --accent: #4a9eff;
  --read: #6b7280;   /* abu   */
  --write: #e0a80d;  /* kuning*/
  --destr: #ef4444;  /* merah */
  --ok: #34d399;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--destr); min-height: 1.2em; margin: 8px 0 0; font-size: 13px; }

/* ── Login ─────────────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 340px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card input {
  width: 100%; margin: 14px 0 10px; padding: 12px;
  background: var(--bg3); border: 1px solid var(--line);
  border-radius: 10px; color: var(--fg); font-size: 16px;
}
.btn {
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg3); color: var(--fg); font-size: 15px; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; width: 100%; }

/* ── Rangka aplikasi ────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: var(--bg2); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.tb-left { display: flex; align-items: center; gap: 8px; }
.tb-right { display: flex; align-items: center; gap: 8px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--read); }
.dot.on { background: var(--ok); }
.dot.off { background: var(--destr); }

.chip {
  background: var(--bg3); border: 1px solid var(--line); color: var(--fg);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.chip .count {
  display: inline-block; min-width: 20px; text-align: center;
  background: var(--accent); color: #06121f; border-radius: 999px;
  padding: 0 6px; font-weight: 700; font-size: 12px;
}
.chip .count.zero { background: var(--line); color: var(--muted); }

/* ── Panel subagen ──────────────────────────────────────────────────── */
.subpanel {
  background: var(--bg2); border-bottom: 1px solid var(--line);
  padding: 10px 12px; flex: 0 0 auto; max-height: 45dvh; overflow-y: auto;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }

.sub-card {
  background: var(--bg3); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 9px 11px; margin-bottom: 8px;
}
.sub-goal { font-size: 14px; font-weight: 600; word-break: break-word; }
.sub-line { color: var(--muted); font-size: 12.5px; margin-top: 3px; word-break: break-word; }
.sub-time { color: var(--ok); font-variant-numeric: tabular-nums; font-weight: 600; }
.sub-recent { margin-top: 6px; font-size: 13px; color: var(--muted); }
.sub-recent summary { cursor: pointer; padding: 4px 0; }
.sub-card.done { border-left-color: var(--ok); opacity: .75; }
.sub-card.failed { border-left-color: var(--destr); }

/* ── Kartu approval ─────────────────────────────────────────────────── */
.approvals { flex: 0 0 auto; }
.approvals:not(:empty) { padding: 10px 12px; background: var(--bg2); border-bottom: 1px solid var(--line); }

.appr {
  border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
  border: 1px solid var(--line); background: var(--bg3);
  border-left: 4px solid var(--read);
}
.appr[data-risk="write"]     { border-left-color: var(--write); background: #241f10; }
.appr[data-risk="destructive"] { border-left-color: var(--destr); background: #2a1416; }
.appr h3 { margin: 0 0 6px; font-size: 13px; display: flex; align-items: center; gap: 7px; }

.pill {
  display: inline-block; border-radius: 999px; padding: 2px 9px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em; color: #0b0e12;
}
.pill.read        { background: var(--read);  color: #e6e9ef; }
.pill.write       { background: var(--write); }
.pill.destructive { background: var(--destr);  color: #fff; }

.appr pre {
  background: #0b0e12; border: 1px solid var(--line); border-radius: 8px;
  padding: 9px; margin: 0 0 8px; font-size: 13px; white-space: pre-wrap;
  word-break: break-word; max-height: 34dvh; overflow-y: auto;
}
.appr .why { color: var(--muted); font-size: 12.5px; margin-bottom: 9px; }
.appr .why ul { margin: 3px 0; padding-left: 17px; }
.appr-row { display: flex; gap: 8px; }
.appr-row .btn { flex: 1; }
.btn.deny { border-color: var(--destr); color: var(--destr); }
.btn.approve { background: var(--ok); border-color: var(--ok); color: #06251a; font-weight: 700; }

.appr-choices { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ── Log percakapan ─────────────────────────────────────────────────── */
.log {
  flex: 1 1 auto; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg { max-width: 92%; padding: 9px 12px; border-radius: var(--radius); word-break: break-word; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: #1c3a5c; }
.msg.assistant { align-self: flex-start; background: var(--bg2); border: 1px solid var(--line); }
.msg.notice {
  align-self: center; max-width: 100%; background: var(--bg3);
  color: var(--muted); font-size: 12.5px; border: 1px dashed var(--line);
}
.msg.approval {
  align-self: stretch; max-width: 100%; font-size: 13px;
  background: var(--bg3); border: 1px solid var(--line); border-left: 4px solid var(--read);
}
.msg.approval[data-risk="write"] { border-left-color: var(--write); }
.msg.approval[data-risk="destructive"] { border-left-color: var(--destr); }
.msg .role { font-size: 11px; color: var(--muted); display: block; margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.msg.streaming { opacity: .95; }
.msg.streaming::after {
  content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Pthinking ──────────────────────────────────────────────────────── */
.thinking {
  display: flex; align-items: center; gap: 8px; padding: 4px 14px 8px;
  color: var(--muted); font-size: 12.5px; flex: 0 0 auto;
}
.spin {
  width: 11px; height: 11px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: rot .8s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

/* ── Composer ───────────────────────────────────────────────────────── */
.composer {
  flex: 0 0 auto; background: var(--bg2); border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + var(--safe-b));
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#input {
  flex: 1; resize: none; max-height: 34dvh; min-height: 42px;
  padding: 10px 12px; background: var(--bg3); color: var(--fg);
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 16px; /* cegah zoom otomatis iOS */
}
.btn.send { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 700; min-width: 46px; height: 42px; }

.composer-meta { display: flex; align-items: center; gap: 10px; margin-top: 5px; min-height: 18px; }
.risk-hint { font-size: 11.5px; color: var(--muted); flex: 1; }
.linkish { background: none; border: 0; color: var(--muted); font-size: 12px; cursor: pointer; padding: 2px; text-decoration: underline; }

.risk-preview {
  font-size: 11.5px; padding: 4px 8px; border-radius: 8px; margin-bottom: 7px;
  border: 1px solid var(--line); background: var(--bg3);
}
.risk-preview .pill { margin-right: 6px; }

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--line); color: var(--fg);
  padding: 9px 15px; border-radius: 999px; font-size: 13px; z-index: 50;
  max-width: 90vw; text-align: center;
}

/* ── Desktop: kolom chat dibatasi, panel jadi kolom samping ─────────── */
@media (min-width: 800px) {
  .app { max-width: 980px; margin: 0 auto; }
  .msg { max-width: 72%; }
  .log { padding: 18px; }
  .topbar { border-radius: 0; }
}

/* ── markdown dasar ─────────────────────────────────────────────── */
.msg .body > * { margin: 0 0 6px; }
.msg .body > *:last-child { margin-bottom: 0; }
.md-p { line-height: 1.5; }
.md-h { display: block; font-weight: 700; margin-top: 4px; }
.msg .body strong { font-weight: 700; }
.msg .body em { font-style: italic; }
.msg .body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em; background: rgba(127,127,127,0.18);
  padding: 1px 5px; border-radius: 5px; word-break: break-word;
}
.md-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em; background: rgba(127,127,127,0.14);
  border-left: 3px solid rgba(127,127,127,0.45);
  padding: 8px 10px; border-radius: 6px; margin: 6px 0;
  overflow-x: auto; white-space: pre; line-height: 1.45;
}
.md-li { padding-left: 14px; position: relative; line-height: 1.5; }
.md-li::before {
  content: "\2022"; position: absolute; left: 4px; opacity: 0.65;
}
.md-li.num::before { content: none; }
.msg .body hr {
  border: 0; border-top: 1px solid rgba(127,127,127,0.3); margin: 8px 0;
}
