:root{--bg:#1a1915;--surface:#232019;--surface2:#2b2822;--border:#33302a;--text:#e8e6df;--muted:#8b887f;--accent:#d97757;--ok:#7bb08a;--warn:#e0b15a;--danger:#e0715f;--add:rgba(123,176,138,.16);--del:rgba(224,113,95,.16);--mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;--sat:env(safe-area-inset-top);--sab:env(safe-area-inset-bottom)}
@media (prefers-color-scheme:light){:root{--bg:#faf9f5;--surface:#f2f0e8;--surface2:#e9e6db;--border:#ddd9cc;--text:#2b2a26;--muted:#76736a;--accent:#c4603f;--ok:#3f8a57;--warn:#b8822a;--danger:#c0432f}}
*{box-sizing:border-box}
html,body{height:100%;margin:0;background:var(--bg);color:var(--text);font:15px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif;-webkit-text-size-adjust:100%;overscroll-behavior:none}
button,input,select,textarea{font:inherit;color:inherit}
button{cursor:pointer;background:none;border:0;padding:0}
input,select,textarea{background:var(--surface);border:1px solid var(--border);border-radius:8px;padding:8px 10px;font-size:16px;min-width:0}
input:focus,select:focus,textarea:focus,button:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
.btn{background:var(--surface2);border:1px solid var(--border);border-radius:8px;padding:7px 12px;font-size:14px;transition:background .15s}
.btn:hover{background:var(--border)}.btn.primary{background:var(--accent);border-color:var(--accent);color:#fff}.btn.primary:hover{filter:brightness(1.08)}.btn.danger{color:var(--danger)}.btn:disabled{opacity:.5;cursor:default}
.icon{width:20px;height:20px;stroke:currentColor;fill:none;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;flex:none}
.muted{color:var(--muted)}.mono{font-family:var(--mono)}.row{display:flex;align-items:center;gap:8px}.grow{flex:1;min-width:0}

#app{display:flex;height:100dvh;overflow:hidden}
#sidebar{width:288px;flex:none;background:var(--surface);border-right:1px solid var(--border);display:flex;flex-direction:column;padding-top:var(--sat);z-index:30;transition:transform .22s}
.sb-top{display:flex;align-items:center;gap:8px;padding:12px}
.brand{font-weight:600;letter-spacing:.2px;display:flex;align-items:center;gap:8px}.brand i{color:var(--accent);font-style:normal;font-size:18px}
.chatlist{flex:1;overflow:auto;padding:0 8px 8px}
.grp{font-size:12px;text-transform:uppercase;letter-spacing:.6px;color:var(--muted);padding:12px 8px 4px}
.chatitem{display:flex;align-items:center;gap:8px;width:100%;text-align:left;padding:8px;border-radius:8px;color:var(--text)}
.chatitem:hover{background:var(--surface2)}.chatitem.active{background:var(--surface2);box-shadow:inset 2px 0 var(--accent)}
.chatitem .t{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.spin{width:12px;height:12px;border:2px solid var(--border);border-top-color:var(--accent);border-radius:50%;animation:sp .8s linear infinite;flex:none;display:inline-block}@keyframes sp{to{transform:rotate(360deg)}}
.sb-bottom{border-top:1px solid var(--border);padding:10px 12px calc(10px + var(--sab));display:flex;flex-direction:column;gap:8px}
.navbtn{display:flex;align-items:center;gap:10px;padding:7px 6px;border-radius:8px;width:100%;text-align:left}.navbtn:hover{background:var(--surface2)}
.dot{width:8px;height:8px;border-radius:50%;background:var(--muted);flex:none}.dot.on{background:var(--ok)}
#scrim{display:none}

.bal{display:block;width:100%;text-align:left;background:var(--bg);border:1px solid var(--border);border-radius:10px;padding:8px 10px}
.bal .r1{display:flex;justify-content:space-between;align-items:baseline;gap:8px}.bal .amt{font-weight:600;font-variant-numeric:tabular-nums}.bal .cap{font-size:12px;color:var(--muted)}
.bar{height:4px;border-radius:2px;background:var(--border);margin:6px 0 4px;overflow:hidden}.bar>i{display:block;height:100%;width:0;background:var(--ok);border-radius:2px;transition:width .5s}
.bal.warn .bar>i{background:var(--warn)}.bal.danger .bar>i{background:var(--danger)}.bal.danger .amt{color:var(--danger)}.bal.off .amt{font-weight:500;color:var(--muted);font-size:13px}
.pill{display:none;flex-direction:column;gap:3px;min-width:64px;background:var(--surface);border:1px solid var(--border);border-radius:999px;padding:3px 10px 5px;font-size:12px;font-weight:600;font-variant-numeric:tabular-nums}
.pill .bar{margin:0;height:3px}.pill.warn .bar>i{background:var(--warn)}.pill.danger .bar>i{background:var(--danger)}.pill.danger{color:var(--danger)}

#main{flex:1;min-width:0;display:flex;flex-direction:column;position:relative}
#hdr{display:flex;align-items:center;gap:8px;padding:calc(8px + var(--sat)) 12px 8px;border-bottom:1px solid var(--border);min-height:52px;flex-wrap:wrap}
#hdr .title{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:text;max-width:40ch}
#hdr select{padding:5px 8px;font-size:14px}.menu{display:none}
.cwd{font:12px var(--mono);color:var(--muted);background:var(--surface);border:1px solid var(--border);border-radius:999px;padding:3px 10px;max-width:28ch;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#banner{display:none;background:var(--warn);color:#1a1915;font-size:13px;text-align:center;padding:5px}#banner.show{display:block}
#msgs{flex:1;overflow:auto;padding:16px 0 8px;scroll-behavior:auto;-webkit-overflow-scrolling:touch}
.col{max-width:820px;margin:0 auto;padding:0 16px}
.empty{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--muted);text-align:center;padding:24px}.empty b{color:var(--text);font-size:20px}
.msg{margin:0 0 18px}
.user .bubble{background:var(--surface2);border:1px solid var(--border);border-radius:12px;padding:8px 12px;white-space:pre-wrap;word-break:break-word;display:inline-block;max-width:100%}
.user{display:flex;flex-direction:column;align-items:flex-end;gap:6px}
.atts{display:flex;flex-wrap:wrap;gap:6px;justify-content:flex-end}.atts img{max-height:160px;max-width:100%;border-radius:8px;border:1px solid var(--border)}
.chip{display:inline-flex;align-items:center;gap:6px;background:var(--surface);border:1px solid var(--border);border-radius:999px;padding:2px 10px;font-size:13px}
.asst{position:relative;padding-left:20px}.asst:before{content:"●";position:absolute;left:0;top:0;color:var(--accent);font-size:12px;line-height:23px}
.note{color:var(--muted);font-size:13px;text-align:center;margin:0 0 14px}
.err{border:1px solid var(--danger);color:var(--danger);border-radius:8px;padding:8px 12px;font-size:14px;white-space:pre-wrap;word-break:break-word}
.md>*:first-child{margin-top:0}.md>*:last-child{margin-bottom:0}.md p{margin:.5em 0;word-break:break-word}.md h1,.md h2,.md h3,.md h4{margin:1em 0 .4em;line-height:1.3}.md h1{font-size:1.4em}.md h2{font-size:1.2em}.md h3,.md h4{font-size:1.05em}
.md ul,.md ol{margin:.4em 0;padding-left:1.4em}.md li{margin:.15em 0}.md blockquote{margin:.6em 0;padding:0 12px;border-left:3px solid var(--border);color:var(--muted)}.md hr{border:0;border-top:1px solid var(--border);margin:1em 0}
.md a{color:var(--accent)}.md code{font-family:var(--mono);font-size:.9em;background:var(--surface2);padding:1px 5px;border-radius:5px}
.md pre{position:relative;margin:.6em 0;background:var(--surface);border:1px solid var(--border);border-radius:8px;padding:10px 12px;overflow:auto}.md pre code{background:none;padding:0;font-size:13px;line-height:1.5}
.copy{position:absolute;top:6px;right:6px;font-size:12px;color:var(--muted);background:var(--surface2);border:1px solid var(--border);border-radius:6px;padding:1px 7px}
.tablew{overflow:auto;margin:.6em 0}.md table{border-collapse:collapse;font-size:14px}.md th,.md td{border:1px solid var(--border);padding:4px 10px;text-align:left}.md th{background:var(--surface)}

.tool{margin:6px 0 6px 20px;font-size:14px}
.tool summary{list-style:none;cursor:pointer;display:flex;align-items:baseline;gap:8px;font-family:var(--mono);font-size:13px}.tool summary::-webkit-details-marker{display:none}
.tool .bul{color:var(--ok)}.tool.error .bul,.tool.denied .bul{color:var(--danger)}.tool.run .bul{color:var(--warn)}
.tool .nm{font-weight:600}.tool .arg{color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.tool .res{font:12px var(--mono);color:var(--muted);padding-left:14px;margin-top:2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.tool .res:before{content:"⎿  "}
.tool.error .res,.tool.denied .res{color:var(--danger)}
.tbody{margin:6px 0 4px 14px;background:var(--surface);border:1px solid var(--border);border-radius:8px;overflow:hidden}
.tbody pre{margin:0;padding:8px 10px;font:12px/1.5 var(--mono);overflow:auto;max-height:420px;white-space:pre-wrap;word-break:break-word}
.tbody .cmd{border-bottom:1px solid var(--border);color:var(--accent)}
.diff{font:12px/1.5 var(--mono);overflow:auto;max-height:420px}.diff div{padding:0 10px;white-space:pre-wrap;word-break:break-all}.diff .add{background:var(--add)}.diff .del{background:var(--del)}.diff .ctx{color:var(--muted)}
.more{font-size:12px;color:var(--accent);padding:4px 10px}
.approval{margin:8px 0 8px 20px;border:1px solid var(--warn);border-radius:10px;padding:10px 12px;background:var(--surface)}
.approval .q{font-weight:600;margin-bottom:2px}.approval .why{font-size:13px;color:var(--muted);margin-bottom:8px;word-break:break-word}.approval .acts{display:flex;flex-wrap:wrap;gap:8px}

#composer{padding:8px 12px calc(10px + var(--sab));background:linear-gradient(transparent,var(--bg) 20%)}
.cbox{max-width:820px;margin:0 auto;background:var(--surface);border:1px solid var(--border);border-radius:14px;padding:8px}
.cbox:focus-within{border-color:var(--accent)}.cbox textarea{width:100%;border:0;background:none;resize:none;max-height:220px;padding:6px 6px;display:block;outline:0}
.cbar{display:flex;align-items:center;gap:6px;justify-content:space-between}
.iconbtn{width:36px;height:36px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;color:var(--muted)}.iconbtn:hover{background:var(--surface2);color:var(--text)}.iconbtn.del:hover{color:var(--danger)}
.send{background:var(--accent);color:#fff}.send:hover{background:var(--accent);filter:brightness(1.1)}.send:disabled{background:var(--surface2);color:var(--muted)}
.cchips{display:flex;flex-wrap:wrap;gap:6px;padding:2px 4px 6px}.cchips .chip button{color:var(--muted)}
.dropping{outline:2px dashed var(--accent);outline-offset:-8px}
.jump{position:absolute;right:16px;bottom:120px;width:36px;height:36px;border-radius:50%;background:var(--surface2);border:1px solid var(--border);display:none;align-items:center;justify-content:center;z-index:5}.jump.show{display:flex}

.auth{min-height:100dvh;display:flex;align-items:center;justify-content:center;padding:24px}
.card{width:100%;max-width:380px;background:var(--surface);border:1px solid var(--border);border-radius:16px;padding:28px 24px;display:flex;flex-direction:column;gap:14px;text-align:center}
.card h1{margin:0;font-size:22px}.card .logo{font-size:34px;color:var(--accent);line-height:1}.card p{margin:0}.card .errtxt{color:var(--danger);font-size:14px;min-height:1.2em}

#sheets{position:fixed;inset:0;pointer-events:none;z-index:50}
.sheetwrap{position:absolute;inset:0;background:rgba(0,0,0,.5);display:flex;align-items:flex-end;justify-content:center;pointer-events:auto}
.sheet{background:var(--bg);border:1px solid var(--border);width:100%;max-width:640px;max-height:92dvh;border-radius:16px 16px 0 0;display:flex;flex-direction:column;animation:up .2s}
@keyframes up{from{transform:translateY(30px);opacity:0}}
@media (min-width:700px){.sheetwrap{align-items:center}.sheet{border-radius:16px;max-height:86dvh}}
.sheet header{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid var(--border);font-weight:600}
.sheet .body{overflow:auto;padding:4px 16px calc(16px + var(--sab));display:flex;flex-direction:column;gap:6px}
.sec{border-bottom:1px solid var(--border);padding:12px 0;display:flex;flex-direction:column;gap:10px}.sec:last-child{border:0}.sec h3{margin:0;font-size:13px;text-transform:uppercase;letter-spacing:.6px;color:var(--muted)}
.field{display:flex;flex-direction:column;gap:4px}.field label{font-size:13px;color:var(--muted)}.field .hint{font-size:12px;color:var(--muted)}.field textarea{min-height:80px;resize:vertical}
.kv{display:flex;gap:6px}.kv input:first-child{width:36%}.kv input:last-child{flex:1}
.pre{font:12px/1.5 var(--mono);background:var(--surface);border:1px solid var(--border);border-radius:8px;padding:10px;word-break:break-all;white-space:pre-wrap;user-select:all}
.item{display:flex;align-items:center;gap:10px;padding:8px 0;border-bottom:1px solid var(--border)}.item:last-child{border:0}
.days{display:flex;gap:4px;flex-wrap:wrap}.days button{border:1px solid var(--border);border-radius:8px;padding:4px 9px;font-size:13px}.days button.on{background:var(--accent);border-color:var(--accent);color:#fff}
.sw{appearance:none;width:38px;height:22px;border-radius:11px;background:var(--border);position:relative;padding:0;border:0;flex:none;cursor:pointer}.sw:before{content:"";position:absolute;left:2px;top:2px;width:18px;height:18px;border-radius:50%;background:#fff;transition:transform .15s}.sw:checked{background:var(--ok)}.sw:checked:before{transform:translateX(16px)}
#toasts{position:fixed;left:0;right:0;bottom:calc(90px + var(--sab));display:flex;flex-direction:column;align-items:center;gap:6px;z-index:60;pointer-events:none}
.toast{background:var(--surface2);border:1px solid var(--border);border-radius:10px;padding:8px 14px;font-size:14px;max-width:90vw;box-shadow:0 6px 20px rgba(0,0,0,.35)}.toast.bad{border-color:var(--danger);color:var(--danger)}

@media (max-width:820px){
  #sidebar{position:fixed;left:0;top:0;bottom:0;transform:translateX(-102%);box-shadow:0 0 30px rgba(0,0,0,.5)}
  body.sb-open #sidebar{transform:none}body.sb-open #scrim{display:block;position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:20}
  .menu{display:inline-flex}.pill{display:flex}.cwd{display:none}
  #hdr{row-gap:6px;padding-bottom:6px}#hdr .title{flex:1 1 50%;max-width:none;order:1}#hdr .pill{order:2}#hdr .del{order:3}
  #hdr .hsel{order:4;flex:1 1 40%;min-width:0}
}
