:root {
  --bg: #f7f6f2; --panel: #ffffff; --side: #efede6; --text: #1f1e1c; --muted: #6d6a63; --line: #e2dfd6;
  --accent: #c96442; --accent-text: #fff; --user: #e9e5da; --code: #f1efe9; --ok: #2f7d4f; --bad: #b3261e; --warn-bg: #fff6e5; --warn-line: #e8c77a;
  --radius: 10px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1c1a; --panel: #262523; --side: #181816; --text: #ecebe7; --muted: #a09d95; --line: #3a3935;
    --accent: #d97757; --user: #34322e; --code: #151513; --ok: #6cc28f; --bad: #f08a80; --warn-bg: #33291a; --warn-line: #7a6232;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.muted { color: var(--muted); }
.err { color: var(--bad); font-size: 14px; min-height: 1.2em; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* login */
.login { max-width: 360px; margin: 12vh auto; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login .btn { width: 100%; margin-top: 16px; }

/* layout */
.layout { display: grid; grid-template-columns: 270px 1fr; height: 100vh; height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 14px; display: flex; gap: 8px; }
.side-head .btn { flex: 1; }
.convs { flex: 1; overflow-y: auto; padding: 0 8px; }
.conv { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text); margin-bottom: 2px; }
.conv:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.conv.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.conv .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv .m { font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 5px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.side-foot { border-top: 1px solid var(--line); padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: none; padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: center; gap: 10px; }

/* chat */
.chat-head { padding: 12px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.chat-head h2 { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .meta { font-size: 12px; color: var(--muted); }
.msgs { flex: 1; overflow-y: auto; padding: 20px 16px 8px; }
.msgs-inner { max-width: 820px; margin: 0 auto; }
.msg { margin: 0 0 14px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user); padding: 9px 14px; border-radius: 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.md { overflow-wrap: anywhere; }
.md p { margin: 0 0 10px; }
.md pre { background: var(--code); border: 1px solid var(--line); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md :not(pre) > code { background: var(--code); padding: 1px 5px; border-radius: 4px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; }
.tool { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 13px; }
.tool summary { padding: 6px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: '▸'; color: var(--muted); }
.tool[open] summary::before { content: '▾'; }
.tool .name { font-weight: 600; }
.tool .arg { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--line); max-height: 360px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.tool .out.error { color: var(--bad); }
.perm { border: 1px solid var(--warn-line); background: var(--warn-bg); border-radius: 10px; padding: 12px 14px; }
.perm h4 { margin: 0 0 6px; font-size: 14px; }
.perm pre { background: var(--code); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }
.perm .del { color: var(--bad); } .perm .add { color: var(--ok); }
.perm .actions { margin-top: 10px; }
.perm .actions input { flex: 1; min-width: 160px; }
.perm.done { background: transparent; border-color: var(--line); padding: 8px 12px; }
.status-ok { color: var(--ok); } .status-bad { color: var(--bad); }
.result { font-size: 12px; color: var(--muted); text-align: center; }
.errbox { color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); padding: 8px 12px; border-radius: 8px; }
.composer { padding: 10px 16px 16px; }
.composer-inner { max-width: 820px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px; }
.composer textarea { border: 0; resize: none; min-height: 44px; max-height: 40vh; outline: none; padding: 6px 8px; }
.composer textarea:focus { outline: none; }
.composer .row { justify-content: space-between; }
.thinking { color: var(--muted); font-size: 14px; }

/* halaman form */
.page { flex: 1; overflow-y: auto; padding: 24px 16px; }
.page-inner { max-width: 820px; margin: 0 auto; }
.page h2 { margin: 0 0 4px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0; overflow-x: auto; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--accent); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0; font-size: 16px; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill.on { color: var(--ok); border-color: currentColor; }
.pill.off { color: var(--bad); border-color: currentColor; }
.kv { font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
.kv code { font-size: 12px; }
.loginbox { margin-top: 10px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.new-chat { max-width: 720px; margin: 8vh auto 0; }
.new-chat h2 { font-size: 24px; margin-bottom: 16px; }
.new-chat textarea { min-height: 110px; resize: vertical; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users td, table.users th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 25% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .layout.nav-open .side { transform: none; box-shadow: 0 0 0 100vw rgba(0,0,0,.35); }
  .topbar { display: flex; }
  .grid2 { grid-template-columns: 1fr; }
  .chat-head { padding: 10px 16px; }
}
