:root { --bg:#f6f7f9; --card:#fff; --text:#1a1d21; --muted:#667085; --line:#e3e6ea; --accent:#3b5bdb; --on-accent:#fff; --accent-soft:color-mix(in srgb, var(--accent) 10%, var(--card)); --danger:#c92a2a; --ok:#2b8a3e; --code:#f1f3f5; }
@media (prefers-color-scheme: dark) {
  :root { --bg:#111317; --card:#1a1d23; --text:#e6e8eb; --muted:#98a2b3; --line:#2a2f37; --accent:#748ffc; --on-accent:#111317; --danger:#ff8787; --ok:#69db7c; --code:#22262d; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin:0; background:var(--bg); color:var(--text); font:15px/1.5 system-ui, sans-serif; }
h1 { font-size:20px; margin:0 0 8px; } h2 { font-size:16px; margin:0 0 12px; } h3 { font-size:14px; margin:18px 0 4px; }
.hidden { display:none !important; }
.muted { color:var(--muted); font-size:13px; } .small { font-size:12px; }
.card { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:18px; margin-bottom:16px; }
.narrow { max-width:400px; margin:60px auto; }
label { display:block; font-size:13px; color:var(--muted); margin:10px 0 4px; }
label.inline { display:inline; margin:0; }
input[type=text], input[type=email], input[type=password], select, textarea { width:100%; padding:9px 10px; border:1px solid var(--line); border-radius:7px; background:var(--bg); color:var(--text); font:inherit; }
button { padding:8px 14px; border:1px solid var(--accent); border-radius:7px; background:var(--accent); color:var(--on-accent); font:inherit; cursor:pointer; white-space:nowrap; }
button.ghost { background:transparent; color:var(--accent); }
button.danger { background:transparent; border-color:var(--danger); color:var(--danger); }
button.mini { padding:3px 10px; font-size:13px; }
button:disabled { opacity:.5; cursor:default; }
.row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; } .row.between { justify-content:space-between; }
.row > input { flex:1; min-width:180px; }
.grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(220px, 1fr)); gap:0 14px; }
table { width:100%; border-collapse:collapse; }
td, th { text-align:left; padding:8px 6px; border-top:1px solid var(--line); font-size:14px; vertical-align:middle; }
th { color:var(--muted); font-weight:500; font-size:12px; border-top:none; }
td.name { word-break:break-all; } td.num { white-space:nowrap; color:var(--muted); } td.actions { white-space:nowrap; text-align:right; }
td.actions button { margin-left:4px; }
code, pre { background:var(--code); border-radius:6px; font:12.5px/1.5 ui-monospace, monospace; }
code { padding:1px 5px; } pre { padding:10px; white-space:pre-wrap; word-break:break-word; margin:8px 0; overflow:auto; }
.drop { border:2px dashed var(--line); border-radius:10px; padding:22px; text-align:center; color:var(--muted); cursor:pointer; }
.drop.over { border-color:var(--accent); color:var(--accent); }
progress { width:100%; height:8px; margin-top:10px; }
.error { color:var(--danger); font-size:14px; margin-top:10px; min-height:1em; }

#app { display:flex; height:100vh; }
#nav { width:190px; flex:none; display:flex; flex-direction:column; gap:2px; padding:16px 10px; border-right:1px solid var(--line); background:var(--card); }
#nav .brand { font-weight:600; font-size:17px; padding:0 8px 14px; display:flex; align-items:center; gap:8px; }
.brand-logo { height:26px; width:auto; max-width:120px; flex:none; } .brand-head { display:flex; align-items:center; gap:10px; }
#nav a { padding:8px 10px; border-radius:7px; color:var(--text); text-decoration:none; }
#nav a.active { background:var(--accent-soft); color:var(--accent); font-weight:500; }
#nav .spacer { flex:1; } #nav .small { padding:2px 8px; word-break:break-all; } #nav button { margin-top:8px; }
main { flex:1; min-width:0; overflow:auto; }
.tab.page { max-width:920px; margin:0 auto; padding:24px 16px 64px; }

#tab-chat { display:flex; height:100%; }
#chat-side { width:240px; flex:none; border-right:1px solid var(--line); padding:12px; overflow:auto; }
#chat-side > button { width:100%; margin-bottom:10px; }
.chat-item { display:flex; align-items:center; gap:4px; padding:7px 8px; border-radius:7px; cursor:pointer; font-size:14px; }
.chat-item:hover { background:var(--code); } .chat-item.active { background:var(--accent-soft); }
.chat-item .title { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-item .sub { color:var(--muted); font-size:11px; }
.chat-item button { border:none; background:none; color:var(--muted); padding:0 4px; visibility:hidden; }
.chat-item:hover button { visibility:visible; }
#chat-main { flex:1; min-width:0; min-height:0; display:flex; flex-direction:column; }
#chat-head { padding:12px 18px; border-bottom:1px solid var(--line); background:var(--card); }
#chat-title { font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#chat-pick { margin-top:6px; } #chat-pick select { width:auto; min-width:160px; padding:5px 8px; } #chat-pick input { width:220px; flex:none; min-width:0; padding:5px 8px; }
.banner { margin:12px 18px 0; padding:10px 14px; border:1px solid var(--line); border-left:3px solid var(--accent); border-radius:7px; background:var(--card); font-size:14px; }
.banner.err { border-left-color:var(--danger); }
.banner a { color:var(--accent); }
#chat-log { flex:1; overflow:auto; padding:18px; display:flex; flex-direction:column; gap:10px; }
#chat-log > * { max-width:860px; width:100%; margin:0 auto; }
.msg.user { background:var(--accent-soft); border-radius:10px; padding:10px 14px; white-space:pre-wrap; word-break:break-word; }
.msg.assistant { padding:2px 2px; word-break:break-word; }
.msg.live { white-space:pre-wrap; }
.msg.live::after { content:"▍"; color:var(--accent); animation:blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity:0; } }
details.tool { border:1px solid var(--line); border-radius:8px; background:var(--card); font-size:13px; }
details.tool summary { padding:7px 12px; cursor:pointer; display:flex; gap:8px; align-items:center; list-style:none; }
details.tool summary::-webkit-details-marker { display:none; }
details.tool .tname { font:12.5px ui-monospace, monospace; font-weight:600; }
details.tool .tprev { flex:1; color:var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font:12px ui-monospace, monospace; }
details.tool .tstate { font-size:12px; color:var(--muted); } details.tool.ok .tstate { color:var(--ok); } details.tool.err .tstate { color:var(--danger); }
details.tool .tbody { padding:0 12px 10px; } details.tool pre { max-height:320px; }
.turn-end { color:var(--muted); font-size:12px; text-align:center; } .turn-end.err { color:var(--danger); text-align:left; border:1px solid var(--danger); border-radius:8px; padding:8px 12px; font-size:13px; }
.empty { color:var(--muted); text-align:center; margin-top:12vh !important; }
#chat-form { display:flex; gap:8px; padding:12px 18px 16px; border-top:1px solid var(--line); background:var(--card); align-items:flex-end; }
#chat-form textarea { flex:1; resize:vertical; min-height:44px; max-height:40vh; }

#tab-terminal { display:flex; flex-direction:column; height:100%; }
#term-head { padding:12px 18px; border-bottom:1px solid var(--line); background:var(--card); } #term-head p { margin:6px 0 0; max-width:900px; }
#term-wrap { flex:1; min-height:0; background:#111317; padding:8px 4px 8px 10px; } #term { height:100%; }

.md h1, .md h2, .md h3, .md h4 { margin:14px 0 6px; font-size:15px; } .md h1 { font-size:18px; } .md h2 { font-size:16px; }
.md p { margin:6px 0; } .md ul, .md ol { margin:6px 0; padding-left:22px; }
.md table { margin:8px 0; display:block; overflow:auto; } .md th, .md td { border:1px solid var(--line); padding:5px 9px; font-size:13px; } .md th { color:var(--text); font-weight:600; }
.md a { color:var(--accent); }

@media (max-width: 760px) {
  #app { flex-direction:column; height:100dvh; }
  main { min-height:0; }
  #nav { width:auto; flex-direction:row; flex-wrap:wrap; align-items:center; border-right:none; border-bottom:1px solid var(--line); padding:8px; }
  #nav .brand { padding:0 8px; } #term-head { padding:8px 12px; } #nav .spacer, #nav .small { display:none; } #nav button { margin:0 0 0 auto; }
  #tab-chat { flex-direction:column; height:100%; } #chat-side { width:auto; max-height:120px; border-right:none; border-bottom:1px solid var(--line); }
}

.stats { display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:10px; }
.stat { border:1px solid var(--line); border-radius:8px; padding:10px 12px; }
.scroll { overflow-x:auto; } #audit-filter { width:auto; padding:5px 8px; } #audit-more { margin-top:10px; }
