:root {
  --brand: #0f4a33; --brand-dark: #0b3b2a; --brand-50: #eef8f2; --brand-100: #d6efe0; --brand-500: #2a8f62;
  --ink: #0f1f1a; --muted: #5b6b65; --line: #dfe6e2; --canvas: #f6f8f7; --white: #fff;
  --warn-bg: #fff4e5; --warn: #9a4a07; --err-bg: #fdecec; --err: #a11d1d; --info-bg: #eaf4fb; --info: #0b5577;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--canvas); color: var(--ink); }
body { -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 40px; padding: .5rem 1rem; border-radius: 10px;
  border: 1px solid transparent; font-weight: 600; font-size: .9rem; cursor: pointer; background: var(--brand); color: #fff; }
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--brand); border-color: var(--brand); }
.btn.secondary:hover { background: var(--brand-50); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--brand-50); }
.btn.danger { background: #fff; color: var(--err); border-color: #f0b4b4; }
.btn.small { min-height: 32px; padding: .3rem .7rem; font-size: .8rem; }
.input { width: 100%; min-height: 42px; padding: .55rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--brand-100); }
label.lbl { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.chip { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--brand-50); color: var(--brand); }
.chip.work { background: var(--warn-bg); color: var(--warn); }
.alert { padding: .6rem .8rem; border-radius: 10px; font-size: .88rem; margin: .5rem 0; }
.alert.err { background: var(--err-bg); color: var(--err); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--info-bg); color: var(--info); }

/* ---------- login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand-dark), #134d37 60%, #0d3a29); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card h1 { margin: 0 0 4px; font-size: 1.5rem; }
.login-card form > * + * { margin-top: 14px; }
.qr { display: grid; place-items: center; gap: 8px; padding: 12px; border: 1px dashed var(--line); border-radius: 12px; }
.qr img { width: 200px; height: 200px; }
.qr code { font-size: .75rem; word-break: break-all; text-align: center; }

/* ---------- layout aplikasi */
.app { display: grid; grid-template-columns: 290px 1fr; grid-template-rows: 56px 1fr; height: 100vh; height: 100dvh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--brand-dark); color: #fff; }
.topbar .brand { font-weight: 800; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin-left: 12px; overflow-x: auto; }
.tab { background: transparent; border: 0; color: rgba(255,255,255,.8); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.tab.active, .tab:hover { background: rgba(255,255,255,.14); color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .85rem; opacity: .85; }
.menu-btn { display: none; background: transparent; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }

.sidebar { background: #fff; border-right: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.side-section { padding: 12px; border-bottom: 1px solid var(--line); }
.side-section h3 { margin: 0 0 8px; font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.list { list-style: none; margin: 6px 0 0; padding: 0; }
.list button { width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--ink); display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.list button:hover { background: var(--brand-50); }
.list button.active { background: var(--brand-100); font-weight: 700; }
.list .meta { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #e0a100; display: inline-block; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- chat */
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fff; flex-wrap: wrap; }
.chat-head .title { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 160px; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 920px; width: 100%; margin: 0 auto; }
.bubble { border-radius: 14px; padding: 10px 14px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--brand); color: #fff; margin-left: auto; max-width: 85%; white-space: pre-wrap; }
.msg.user .tag { text-align: right; margin-bottom: 4px; }
.msg.assistant .bubble { background: #fff; border: 1px solid var(--line); }
.bubble :is(h1,h2,h3) { margin: .6em 0 .3em; font-size: 1.05rem; }
.bubble p { margin: .4em 0; }
.bubble pre { background: #0f1f1a; color: #e6f3ec; padding: 10px 12px; border-radius: 10px; overflow-x: auto; font-size: .82rem; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }
.bubble :not(pre) > code { background: var(--brand-50); padding: .1em .35em; border-radius: 5px; }
.bubble table { border-collapse: collapse; font-size: .85rem; display: block; overflow-x: auto; }
.bubble td, .bubble th { border: 1px solid var(--line); padding: 4px 8px; }
.tool { border: 1px solid var(--line); border-radius: 10px; background: #fbfcfb; font-size: .85rem; }
.tool summary { cursor: pointer; padding: 6px 10px; display: flex; gap: 8px; align-items: center; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary .tname { font-weight: 700; color: var(--brand); }
.tool summary .tsum { font-family: ui-monospace, monospace; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--line); max-height: 320px; overflow: auto; font-size: .78rem; white-space: pre-wrap; background: #fff; }
.tool .out.err { color: var(--err); }
.status-line { text-align: center; font-size: .78rem; color: var(--muted); }
.live { white-space: pre-wrap; }
.composer { border-top: 1px solid var(--line); background: #fff; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer .row { display: flex; gap: 8px; align-items: flex-end; max-width: 920px; margin: 0 auto; }
.composer textarea { flex: 1; resize: vertical; min-height: 48px; max-height: 40vh; }
.modes { display: flex; gap: 6px; max-width: 920px; margin: 0 auto 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: .82rem; color: var(--muted); }
.seg button.on { background: var(--brand); color: #fff; }
.seg button.on.work { background: #b45309; }
.approve { max-width: 920px; margin: 0 auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 520px; padding: 24px; }
.empty h2 { color: var(--ink); }

/* ---------- terminal */
.term-bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: #fff; flex-wrap: wrap; }
.term-wrap { flex: 1; min-height: 0; background: #0f1f1a; padding: 6px; }
.term-wrap .xterm { height: 100%; }
.keys { display: none; gap: 4px; padding: 6px; background: #0b1712; overflow-x: auto; }
.keys button { background: #1d3a2e; color: #e6f3ec; border: 0; border-radius: 6px; padding: 6px 10px; font-family: ui-monospace, monospace; font-size: .8rem; }

/* ---------- audit */
.audit { overflow: auto; padding: 16px; }
.audit table { width: 100%; border-collapse: collapse; font-size: .82rem; background: #fff; }
.audit th, .audit td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.audit td.detail { font-family: ui-monospace, monospace; word-break: break-all; color: var(--muted); }

/* ---------- HP */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .topbar .who { display: none; }
  .tabs { margin-left: 0; }
  .sidebar { position: fixed; inset: 56px 0 0 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; width: min(320px, 88vw); box-shadow: 0 10px 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .msg.user .bubble { max-width: 95%; }
  .keys { display: flex; }
}
