:root { --bg:#fff; --side:#f4f5f7; --text:#1d2129; --muted:#6b7280; --line:#e2e5ea; --accent:#2563eb; --bubble:#eef3ff; --code:#f6f8fa; --danger:#c62828; color-scheme:light; }
@media (prefers-color-scheme: dark) { :root { --bg:#17181c; --side:#101114; --text:#e6e7ea; --muted:#9aa0aa; --line:#2c2f36; --accent:#5b8cff; --bubble:#24304a; --code:#202228; --danger:#ff7b72; color-scheme:dark; } }
* { box-sizing:border-box; }
[hidden] { display:none !important; }
body { margin:0; background:var(--bg); color:var(--text); font:15px/1.65 system-ui, "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
button, input, textarea, select { font:inherit; color:inherit; background:var(--bg); border:1px solid var(--line); border-radius:8px; padding:7px 12px; }
button { cursor:pointer; }
button:disabled { opacity:.5; cursor:default; }
button.primary { background:var(--accent); border-color:var(--accent); color:#fff; }
label { display:block; margin:8px 0; color:var(--muted); font-size:13px; }
label input:not([type=checkbox]), label textarea { display:block; width:100%; margin-top:3px; color:var(--text); font-size:15px; }
.check { display:flex; gap:4px; align-items:center; white-space:nowrap; }
.error { color:var(--danger); margin:4px 0; white-space:pre-wrap; }
.error:empty { display:none; }
.row { display:flex; gap:8px; align-items:flex-end; flex-wrap:wrap; }
.card.center { width:min(340px, calc(100% - 32px)); margin:14vh auto; border:1px solid var(--line); border-radius:12px; padding:24px; }
.card button { width:100%; margin-top:8px; }
#app { display:flex; height:100vh; height:100dvh; }
#sidebar { width:260px; flex:none; background:var(--side); border-right:1px solid var(--line); display:flex; flex-direction:column; padding:12px; gap:10px; }
#conversations { flex:1; overflow-y:auto; }
.conversation { display:flex; align-items:center; border-radius:8px; }
.conversation:hover, .conversation.current { background:var(--bubble); }
.conversation button { border:0; background:transparent; }
.conversation .open { flex:1; text-align:left; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
.conversation .remove { color:var(--muted); padding:7px 9px; }
.account { border-top:1px solid var(--line); padding-top:10px; display:flex; flex-wrap:wrap; gap:6px; font-size:13px; }
.account span { width:100%; color:var(--muted); }
.account button { padding:4px 9px; }
main { flex:1; min-width:0; display:flex; flex-direction:column; }
header { display:flex; gap:10px; align-items:center; padding:10px 16px; border-bottom:1px solid var(--line); }
#title { overflow:hidden; white-space:nowrap; text-overflow:ellipsis; font-weight:600; }
#menu { display:none; }
#messages { flex:1; overflow-y:auto; padding:16px; }
.message { max-width:880px; margin:0 auto 18px; }
.message.user { display:flex; flex-direction:column; align-items:flex-end; }
.message.user .body { background:var(--bubble); border-radius:14px; padding:9px 14px; max-width:85%; white-space:pre-wrap; overflow-wrap:anywhere; }
.message.assistant .body { overflow-wrap:anywhere; }
.message.error-state .body { border-left:3px solid var(--danger); padding-left:10px; }
.body pre { background:var(--code); border:1px solid var(--line); border-radius:8px; padding:10px 12px; overflow-x:auto; }
.body code { background:var(--code); border-radius:4px; padding:1px 4px; font-size:13px; }
.body pre code { padding:0; }
.body table { border-collapse:collapse; display:block; overflow-x:auto; }
.body th, .body td, #users th, #users td { border:1px solid var(--line); padding:4px 10px; text-align:left; }
.body a { color:var(--accent); }
.images { display:flex; flex-wrap:wrap; gap:8px; justify-content:flex-end; margin-bottom:6px; }
.images img { max-height:140px; max-width:220px; border-radius:8px; border:1px solid var(--line); }
.activity { color:var(--muted); font-size:12px; font-family:ui-monospace, monospace; margin:6px 0; }
.activity div { overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
.empty { color:var(--muted); text-align:center; margin-top:20vh; }
#composer { border-top:1px solid var(--line); padding:10px 16px; width:100%; }
#composer > * { max-width:880px; margin-left:auto; margin-right:auto; }
#composer .row { flex-wrap:nowrap; }
#text { flex:1; min-width:0; resize:none; max-height:200px; }
#composer.dragging { background:var(--bubble); }
#attachments { display:flex; gap:8px; flex-wrap:wrap; }
.thumb { position:relative; margin-bottom:8px; }
.thumb img { height:64px; border-radius:8px; border:1px solid var(--line); display:block; }
.thumb button { position:absolute; top:-6px; right:-6px; padding:0 7px; border-radius:50%; }
dialog { border:1px solid var(--line); border-radius:12px; background:var(--bg); color:var(--text); width:min(380px, calc(100% - 24px)); padding:20px; }
dialog.wide { width:min(720px, calc(100% - 24px)); }
dialog::backdrop { background:rgba(0,0,0,.45); }
dialog h2 { margin-top:0; font-size:18px; }
#users table { width:100%; border-collapse:collapse; }
#users td button { padding:2px 8px; margin:2px; font-size:13px; }
#settings-form .row label { flex:1; min-width:130px; }
.buttons { display:flex; justify-content:flex-end; align-items:center; gap:8px; margin-top:12px; }
.buttons span { margin-right:auto; color:var(--muted); font-size:12px; }
dialog.huge { width:min(1100px, calc(100% - 24px)); }
#log-form { align-items:center; }
#log-form input[name=q] { flex:1; min-width:160px; }
#log-rows { height:55vh; overflow:auto; margin-top:8px; border:1px solid var(--line); border-radius:8px; font:12px/1.6 ui-monospace, monospace; }
#log-rows div { padding:3px 10px; border-bottom:1px solid var(--line); white-space:pre-wrap; overflow-wrap:anywhere; }
#log-rows .problem { color:var(--danger); }
@media (max-width: 700px) {
  #menu { display:block; }
  #sidebar { position:fixed; inset:0 auto 0 0; z-index:5; transform:translateX(-100%); transition:transform .2s; }
  #app.menu-open #sidebar { transform:none; box-shadow:0 0 30px rgba(0,0,0,.35); }
}
