:root {
  --bg: #f6f1ea; --panel: #fffaf4; --panel-2: #f1eae1; --text: #26222b; --muted: #7a7380;
  --line: #e4dbd0; --accent: #b4552d; --accent-ink: #fff; --bubble-user: #26222b; --bubble-user-ink: #fff;
  --bubble-ai: #fffaf4; --code: #efe7dc; --danger: #b43a2d; --shadow: 0 8px 30px rgba(40,30,20,.08);
  --radius: 16px; --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a22; --panel: #23222b; --panel-2: #2b2a34; --text: #ece7e1; --muted: #9a93a3;
    --line: #35333f; --accent: #e07a4e; --accent-ink: #1b1a22; --bubble-user: #e9e2d8; --bubble-user-ink: #1b1a22;
    --bubble-ai: #23222b; --code: #15141a; --danger: #ff7b6b; --shadow: 0 8px 30px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15.5px; line-height: 1.55; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 12.5px; }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }

.app { display: grid; grid-template-columns: 290px 1fr; height: 100dvh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.brand { font-weight: 700; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.brand.big { font-size: 22px; justify-content: center; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent); }

.agent-tabs { display: flex; gap: 6px; padding: 6px 12px 10px; overflow-x: auto; scrollbar-width: none; }
.sidebar .agent-tabs { flex-direction: column; }
.sidebar .agent-tab { flex: none; }
.agent-tabs::-webkit-scrollbar { display: none; }
.agent-tab { flex: 1 0 auto; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: transparent; cursor: pointer; text-align: left; min-width: 0; }
.agent-tab.active { background: color-mix(in srgb, var(--agent) 14%, var(--panel)); border-color: color-mix(in srgb, var(--agent) 50%, var(--line)); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--agent, var(--accent)); color: #fff; font-weight: 700; font-size: 14px; flex: none; }
.agent-tab .name { font-weight: 600; font-size: 14px; white-space: nowrap; }
.agent-tab .model { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }

.side-actions { display: flex; gap: 8px; padding: 0 12px 10px; }
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; padding: 9px 14px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; flex: 1; font-weight: 600; }
.icon-btn { border: 1px solid var(--line); background: transparent; border-radius: 10px; width: 38px; height: 38px; cursor: pointer; display: grid; place-items: center; }
.link-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 12.5px; }
.link-btn:hover { color: var(--text); }

.conv-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.conv-item { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: color-mix(in srgb, var(--agent) 14%, var(--panel)); }
.conv-item .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv-item .d { font-size: 11px; color: var(--muted); flex: none; }
.conv-item .x { opacity: 0; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; }
.conv-item:hover .x { opacity: 1; }
.side-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); padding-top: calc(10px + env(safe-area-inset-top)); }
.agent-head { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.agent-head .name { font-weight: 700; }
.agent-head .title { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 12px; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.msg { display: flex; gap: 10px; max-width: 820px; width: 100%; margin: 0 auto; }
.msg.user { justify-content: flex-end; }
.bubble { padding: 10px 14px; border-radius: var(--radius); max-width: min(78%, 680px); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--bubble-user); color: var(--bubble-user-ink); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--bubble-ai); border: 1px solid var(--line); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.msg.assistant .avatar { margin-top: 4px; }
.bubble p { margin: 0 0 .6em; } .bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: .6em 0 .3em; font-size: 1.05em; }
.bubble ul, .bubble ol { margin: .3em 0 .6em; padding-left: 1.4em; }
.bubble pre { background: var(--code); border-radius: 10px; padding: 10px 12px; overflow-x: auto; font-family: var(--mono); font-size: 13px; }
.bubble code { font-family: var(--mono); font-size: .92em; background: var(--code); padding: 1px 5px; border-radius: 6px; }
.bubble pre code { background: none; padding: 0; }
.bubble blockquote { margin: .4em 0; padding-left: .8em; border-left: 3px solid var(--line); color: var(--muted); }
.bubble a { color: var(--accent); }
.bubble table { border-collapse: collapse; font-size: .92em; } .bubble td, .bubble th { border: 1px solid var(--line); padding: 3px 8px; }
.meta { font-size: 11px; color: var(--muted); margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.tools { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.tool { font-size: 12px; color: var(--muted); background: var(--panel-2); border-radius: 8px; padding: 4px 8px; cursor: pointer; }
.tool summary { list-style: none; } .tool summary::-webkit-details-marker { display: none; }
.tool pre { margin: 6px 0 0; white-space: pre-wrap; font-size: 11.5px; max-height: 240px; overflow: auto; }
.thinking { font-size: 12px; color: var(--muted); font-style: italic; margin-bottom: 6px; max-height: 80px; overflow: hidden; }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; }
.empty .avatar { width: 56px; height: 56px; font-size: 24px; margin: 0 auto 12px; }
.empty h2 { margin: 0 0 6px; color: var(--text); }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); border-radius: 14px; padding: 10px 14px; max-height: 40vh; outline: none; line-height: 1.45; }
.composer textarea:focus { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer; font-size: 16px; flex: none; }
.send:disabled { opacity: .45; cursor: default; }

.login { height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px 24px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); text-align: center; }
.login-card input { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 14px; text-align: center; letter-spacing: 2px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 18px; width: min(960px, 100%); height: min(80vh, 720px); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.files-body { display: grid; grid-template-columns: 240px 1fr; flex: 1; min-height: 0; }
.files-list { border-right: 1px solid var(--line); overflow: auto; padding: 8px; }
.files-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.files-list button:hover { background: var(--panel-2); }
.files-view { margin: 0; padding: 14px 16px; overflow: auto; white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; }

.scrim { display: none; }
.only-mobile { display: none; }
.agent-strip { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 340px); z-index: 40; transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); padding-top: env(safe-area-inset-top); }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .bubble { max-width: 88%; }
  .sidebar .agent-tabs { display: none; }
  .agent-strip { display: flex; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
  .agent-strip .agent-tab { padding: 6px 10px; }
  .agent-strip .model { display: none; }
  .files-body { grid-template-columns: 1fr; grid-template-rows: 140px 1fr; }
  .files-list { border-right: 0; border-bottom: 1px solid var(--line); }
}
