:root {
  --bg: #ffffff; --side: #f7f8fa; --panel: #ffffff; --hover: #eef1f5; --line: #e6e8ec; --line2: #d8dce3;
  --text: #1f2328; --muted: #6b7280; --faint: #9aa1ad; --blue: #1876BD; --blue-2: #1468a8; --blue-soft: #e8f1fa;
  --good: #1f9d5c; --good-soft: #e7f6ee; --warn: #b7791f; --warn-soft: #fdf4e3; --bad: #d6455a; --bad-soft: #fcebee;
  --bubble: #f1f3f6; --code: #f6f8fa; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
  --radius: 14px; --font: 'Nunito', system-ui, -apple-system, sans-serif; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f1520; --side: #0b1019; --panel: #121a27; --hover: #1a2433; --line: #222d3d; --line2: #2c394c;
  --text: #e8edf4; --muted: #95a1b3; --faint: #6c788b; --blue: #2f8cdb; --blue-2: #4a9de3; --blue-soft: #15263b;
  --good: #3dcb80; --good-soft: #12291f; --warn: #f5a524; --warn-soft: #2d2412; --bad: #f0616d; --bad-soft: #2e171b;
  --bubble: #1a2332; --code: #0b111b; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3); color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #0f1520; --side: #0b1019; --panel: #121a27; --hover: #1a2433; --line: #222d3d; --line2: #2c394c;
  --text: #e8edf4; --muted: #95a1b3; --faint: #6c788b; --blue: #2f8cdb; --blue-2: #4a9de3; --blue-soft: #15263b;
  --good: #3dcb80; --good-soft: #12291f; --warn: #f5a524; --warn-soft: #2d2412; --bad: #f0616d; --bad-soft: #2e171b;
  --bubble: #1a2332; --code: #0b111b; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.muted { color: var(--muted); } .small { font-size: 13px; } .hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel); font-weight: 600; font-size: 14px; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-2); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; border: 0; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 272px 1fr; height: 100dvh; }
.shell.side-closed { grid-template-columns: 0 1fr; }
.shell.with-panel { grid-template-columns: 272px minmax(380px, 1fr) minmax(420px, 48%); }
.shell.side-closed.with-panel { grid-template-columns: 0 minmax(380px, 1fr) minmax(420px, 52%); }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; font-weight: 800; font-size: 17px; letter-spacing: -0.01em; }
.brand img { width: 22px; height: 28px; }
.brand .core { color: var(--blue); }
.side .new { margin: 6px 12px 10px; justify-content: flex-start; }
.side .search { margin: 0 12px 8px; position: relative; }
.side .search input { width: 100%; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); padding: 0 10px 0 32px; font-size: 14px; outline: none; }
.side .search i { position: absolute; left: 11px; top: 10px; color: var(--faint); font-size: 13px; }
.convos { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.convos h6 { margin: 14px 10px 4px; font-size: 12px; font-weight: 700; color: var(--faint); text-transform: none; }
.convo { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px; color: var(--text); text-decoration: none; font-size: 14px; cursor: pointer; }
.convo:hover { background: var(--hover); }
.convo.active { background: var(--blue-soft); }
.convo span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.convo .del { visibility: hidden; color: var(--faint); border: 0; background: none; padding: 2px 4px; }
.convo:hover .del { visibility: visible; }
.me { border-top: 1px solid var(--line); padding: 10px; position: relative; }
.me-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; background: none; border-radius: 10px; text-align: left; }
.me-btn:hover { background: var(--hover); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: none; }
.me-btn b { display: block; font-size: 14px; } .me-btn small { color: var(--muted); font-size: 12px; }
.menu { position: absolute; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 230px; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 8px; text-align: left; font-size: 14px; }
.menu button:hover { background: var(--hover); }
.menu button i { width: 16px; color: var(--muted); text-align: center; }
.menu button.sel { color: var(--blue); font-weight: 700; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.me .menu { bottom: 62px; left: 10px; right: 10px; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; position: relative; }
.topbar { display: flex; align-items: center; gap: 6px; height: 54px; padding: 0 12px; border-bottom: 1px solid transparent; flex: none; }
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; padding: 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; font-weight: 600; color: var(--text); position: relative; max-width: 260px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { background: var(--hover); }
.chip i.fa-chevron-down { font-size: 10px; color: var(--faint); }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.topbar .menu { top: 40px; right: 0; }

.scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: 780px; margin: 0 auto; padding: 18px 24px 40px; }
.msg { margin: 22px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--bubble); padding: 10px 16px; border-radius: 18px 18px 4px 18px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .att { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-top: 6px; }
.msg.user .att span { font-size: 12px; background: var(--side); border: 1px solid var(--line); border-radius: 7px; padding: 2px 8px; color: var(--muted); }
.msg.bot { display: flex; gap: 14px; }
.msg.bot .mark { width: 26px; height: 26px; flex: none; margin-top: 2px; display: flex; align-items: center; justify-content: center; }
.msg.bot .mark img { width: 18px; }
.msg.bot .body { flex: 1; min-width: 0; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; } .md ul, .md ol { margin: 0 0 12px; padding-left: 22px; } .md li { margin: 3px 0; }
.md h1, .md h2, .md h3 { margin: 18px 0 8px; line-height: 1.3; } .md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--code); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
.md pre { position: relative; background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 0 0 12px; }
.md pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.5; }
.md pre .copy { position: absolute; top: 6px; right: 6px; opacity: 0; }
.md pre:hover .copy { opacity: 1; }
.md table { border-collapse: collapse; margin: 0 0 12px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md th { background: var(--side); }
.md blockquote { margin: 0 0 12px; padding-left: 12px; border-left: 3px solid var(--line2); color: var(--muted); }
.cursor-blink::after { content: ''; display: inline-block; width: 8px; height: 15px; margin-left: 2px; background: var(--blue); border-radius: 2px; vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.thinking .dots i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--blue); margin-right: 3px; animation: bounce 1.2s infinite; }
.thinking .dots i:nth-child(2) { animation-delay: .15s; } .thinking .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- tool cards ---------- */
.tool { border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; background: var(--panel); overflow: hidden; }
.tool-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 14px; cursor: pointer; user-select: none; }
.tool-head .ti { width: 22px; height: 22px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 11px; background: var(--side); color: var(--muted); flex: none; }
.tool-head .tl { font-weight: 600; flex: none; }
.tool-head .ts { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; font-size: 13px; }
.tool-head .st { font-size: 12px; color: var(--muted); flex: none; display: flex; align-items: center; gap: 5px; }
.tool.done .ti { background: var(--good-soft); color: var(--good); }
.tool.failed .ti, .tool.denied .ti { background: var(--bad-soft); color: var(--bad); }
.tool.running .ti { background: var(--blue-soft); color: var(--blue); }
.tool.approval { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.tool.approval .ti { background: var(--blue); color: #fff; }
.tool-body { border-top: 1px solid var(--line); padding: 10px 12px; font-size: 13px; }
.tool-body pre { margin: 0; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; background: var(--code); border-radius: 8px; padding: 8px 10px; }
.approve { padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.approve .why { margin-bottom: 8px; font-size: 14px; }
.approve .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.approve .call { font-family: var(--mono); font-size: 12.5px; background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; margin-bottom: 10px; word-break: break-all; }
.approve .call b { color: var(--blue); }
.approve .call.write b { color: var(--warn); }
.approve-all { display: flex; justify-content: flex-end; gap: 8px; margin: 6px 0 12px; }

/* ---------- reply draft + artifacts + blocks ---------- */
.draft { border: 1px solid var(--line); border-radius: 14px; margin: 10px 0 14px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.draft-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 700; color: var(--muted); }
.draft-head span { flex: 1; }
.draft-body { padding: 14px 16px; white-space: pre-wrap; font-size: 15px; }
.art { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 10px 0; cursor: pointer; background: var(--panel); }
.art:hover { border-color: var(--line2); background: var(--hover); }
.art .ai { width: 38px; height: 38px; border-radius: 10px; background: var(--blue-soft); color: var(--blue); display: flex; align-items: center; justify-content: center; flex: none; }
.art b { display: block; font-size: 14px; } .art small { color: var(--muted); font-size: 12px; }
.art .grow { flex: 1; min-width: 0; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 2px 9px; }
.badge.ok { background: var(--good-soft); color: var(--good); } .badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.s2blocks { margin: 10px 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.s2blocks .s2c-root { height: auto !important; padding: 12px !important; }
.notice-line { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--text); font-size: 14px; margin: 10px 0; }
.notice-line.error { background: var(--bad-soft); }
.notice-line i { margin-top: 3px; color: var(--warn); } .notice-line.error i { color: var(--bad); }

/* ---------- composer ---------- */
.composer-wrap { padding: 0 24px 18px; flex: none; }
.composer { max-width: 780px; margin: 0 auto; border: 1px solid var(--line2); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); padding: 10px 10px 8px 14px; }
.composer:focus-within { border-color: var(--blue); }
.composer textarea { width: 100%; border: 0; outline: none; resize: none; background: transparent; font-size: 15px; line-height: 1.5; max-height: 260px; min-height: 26px; padding: 4px 0; }
.composer .bar { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.composer .bar .grow { flex: 1; }
.send { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--blue); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.send:disabled { background: var(--line2); }
.files { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.files span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; background: var(--side); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; }
.files button { border: 0; background: none; color: var(--faint); padding: 0; }
.foot { max-width: 780px; margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--faint); }

/* ---------- empty state ---------- */
.hello { max-width: 780px; margin: 0 auto; padding: 14vh 24px 0; }
.hello h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; display: flex; align-items: center; gap: 14px; }
.hello h1 img { width: 30px; }
.hello p { color: var(--muted); margin: 0 0 26px; font-size: 16px; }
.suggest { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 18px; }
.suggest button { text-align: left; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.suggest button:hover { background: var(--hover); }
.suggest button i { color: var(--blue); margin-top: 3px; width: 16px; }
.suggest button b { display: block; } .suggest button small { color: var(--muted); }
.nudge { display: flex; align-items: center; gap: 12px; border: 1px dashed var(--line2); border-radius: 12px; padding: 12px 14px; margin-top: 18px; font-size: 14px; }
.nudge i { color: var(--blue); font-size: 18px; }
.nudge div { flex: 1; }

/* ---------- artifact panel ---------- */
.panel { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; height: 100dvh; background: var(--panel); }
.panel-head { display: flex; align-items: center; gap: 8px; height: 54px; padding: 0 10px 0 16px; border-bottom: 1px solid var(--line); flex: none; }
.panel-head .t { flex: 1; min-width: 0; }
.panel-head .t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.panel-head .t small { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); flex: none; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px; font-size: 13px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--blue); }
.panel-body { flex: 1; overflow: auto; position: relative; background: var(--side); }
.panel-body iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.panel-body .pad { padding: 16px 18px; background: var(--panel); min-height: 100%; }
.panel-body pre.code { margin: 0; padding: 14px 16px; font-family: var(--mono); font-size: 12px; line-height: 1.55; white-space: pre; min-height: 100%; background: var(--code); }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.checks li i { margin-top: 3px; width: 16px; }
.checks .pass i { color: var(--good); } .checks .warning i { color: var(--warn); } .checks .error i { color: var(--bad); }
.video-stage { display: flex; align-items: center; justify-content: center; height: 100%; padding: 16px; }
.video-stage iframe { width: 100%; height: 100%; border-radius: 10px; }
.formats { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; align-items: center; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,21,32,.42); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 18px; width: min(620px, 100%); max-height: 88dvh; display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(0,0,0,.25); }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 8px; }
.modal-head h2 { margin: 0; font-size: 19px; flex: 1; }
.modal-body { padding: 6px 20px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field label { font-size: 13px; font-weight: 700; }
.field input, .field textarea { border: 1px solid var(--line2); border-radius: 10px; padding: 9px 12px; background: var(--bg); outline: none; font-size: 14px; }
.field input:focus, .field textarea:focus { border-color: var(--blue); }
.field textarea { min-height: 140px; resize: vertical; }
.field .help { font-size: 12px; color: var(--muted); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .grow small { color: var(--muted); }
.example { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; font-size: 13.5px; white-space: pre-wrap; position: relative; max-height: 140px; overflow: hidden; }
.example button { position: absolute; top: 6px; right: 6px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.metrics div { background: var(--side); border-radius: 10px; padding: 10px; }
.metrics b { display: block; font-size: 18px; } .metrics small { color: var(--muted); font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 7px 12px; font-size: 13px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--blue-soft); color: var(--blue); }
.snippet { position: relative; }
.snippet pre { background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all; margin: 6px 0 12px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--side); }
.login-card { width: min(400px, 100%); background: var(--panel); border-radius: 20px; box-shadow: var(--shadow); padding: 32px 28px 26px; }
.login-card .brand { padding: 0 0 6px; font-size: 22px; }
.login-card .brand img { width: 26px; height: 33px; }
.login-card p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login-card .btn.primary { width: 100%; justify-content: center; height: 42px; margin-top: 8px; font-size: 15px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); }

@media (max-width: 900px) {
  .shell, .shell.with-panel { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 272px; z-index: 60; box-shadow: var(--shadow); }
  .shell.side-closed .side { display: none; }
  .panel { position: fixed; inset: 0; z-index: 70; }
  .thread, .hello { padding-left: 16px; padding-right: 16px; }
  .composer-wrap { padding: 0 16px 14px; }
  .suggest { grid-template-columns: 1fr; }
  .chip { max-width: 140px; }
}
