:root {
  --bg: #f6f5f1;
  --side: #efede7;
  --surface: #ffffff;
  --surface-2: #f2f0eb;
  --hover: rgba(40, 36, 28, .055);
  --active: rgba(40, 36, 28, .09);
  --text: #1d1c1a;
  --text-2: #4a4843;
  --muted: #8b877e;
  --line: #e4e1d9;
  --line-2: #d6d2c8;
  --accent: #1f6f63;
  --accent-2: #2a8a7b;
  --accent-soft: rgba(31, 111, 99, .1);
  --on-accent: #fff;
  --user-bubble: #ebe8e0;
  --danger: #c2453a;
  --code-bg: #f3f1ec;
  --shadow: 0 1px 2px rgba(30, 25, 15, .05), 0 8px 28px rgba(30, 25, 15, .07);
  --shadow-lg: 0 24px 70px rgba(25, 20, 10, .18), 0 2px 8px rgba(25, 20, 10, .06);
  --r: 14px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "vivo Sans", "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", "Noto Sans SC", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --side-w: 276px;
  --params-w: 344px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #171716;
  --side: #121211;
  --surface: #20201e;
  --surface-2: #262624;
  --hover: rgba(255, 252, 240, .06);
  --active: rgba(255, 252, 240, .1);
  --text: #ecebe6;
  --text-2: #c4c1b9;
  --muted: #8a877f;
  --line: #2d2d2a;
  --line-2: #3a3a36;
  --accent: #4cb8a5;
  --accent-2: #63c9b6;
  --accent-soft: rgba(76, 184, 165, .13);
  --on-accent: #0d1f1b;
  --user-bubble: #2a2a27;
  --danger: #ef7468;
  --code-bg: #1c1c1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .25);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body { overflow: hidden; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 20px; height: 20px; flex: none; }
.hidden { display: none !important; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.4em; font-size: 13px; margin: 8px 0 0; }
kbd { font-family: var(--mono); font-size: 10.5px; color: var(--muted); border: 1px solid var(--line-2); border-radius: 5px; padding: 0 5px; line-height: 17px; }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ----------------------------------------------------------- buttons/inputs */
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--text-2); transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { background: var(--active); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.btn { height: 38px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--surface); font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s, border-color .15s, transform .1s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 550; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.wide { width: 100%; }
.btn svg { width: 17px; height: 17px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s; }
textarea.field { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.55; min-height: 80px; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.mono, textarea.mono { font-family: var(--mono); font-size: 12.5px; }
.field.bad { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 15%, transparent); }
select.field { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px; background-size: 5px 5px; background-repeat: no-repeat; }

/* ----------------------------------------------------------- login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg); }
.login-card { width: min(360px, 100%); text-align: center; background: var(--surface); padding: 36px 28px 26px; border-radius: 22px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); }
.login-card h1 { margin: 14px 0 2px; font-size: 21px; font-weight: 650; letter-spacing: .02em; }
.login-card p { margin: 0 0 20px; font-size: 14px; }
.login-card input[type=password] { width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--bg); outline: none; font-size: 16px; margin-bottom: 12px; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .btn { height: 46px; font-size: 15px; border-radius: 12px; }
.brand-mark { width: 56px; height: 56px; margin: 0 auto; color: var(--accent); }
.brand-mark svg { width: 56px; height: 56px; }

/* ----------------------------------------------------------- layout */
.app { display: flex; height: 100%; height: 100dvh; }
.sidebar { width: var(--side-w); flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 12px 10px 10px; gap: 8px; z-index: 30; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 4px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 15.5px; letter-spacing: .02em; }
.brand .logo { width: 26px; height: 26px; color: var(--accent); }
.new-chat { display: flex; align-items: center; gap: 9px; height: 40px; padding: 0 12px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(0,0,0,.03); font-weight: 550; font-size: 14px; transition: border-color .15s, background .15s; }
.new-chat:hover { border-color: var(--line-2); }
.new-chat svg { width: 18px; height: 18px; color: var(--accent); }
.new-chat kbd { margin-left: auto; }
.search { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 11px; border-radius: 10px; color: var(--muted); transition: background .15s; }
.search:focus-within, .search:hover { background: var(--hover); }
.search svg { width: 16px; height: 16px; }
.search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 14px; color: var(--text); min-width: 0; }
.search input::-webkit-search-cancel-button { filter: grayscale(1); opacity: .5; }
.conv-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.conv-group { font-size: 11.5px; color: var(--muted); padding: 14px 10px 4px; font-weight: 550; letter-spacing: .04em; }
.conv { position: relative; display: flex; align-items: center; height: 36px; padding: 0 6px 0 10px; border-radius: 9px; font-size: 14px; color: var(--text-2); cursor: pointer; transition: background .12s; }
.conv.snip { height: auto; padding-top: 6px; padding-bottom: 6px; flex-wrap: wrap; }
.conv:hover { background: var(--hover); }
.conv.active { background: var(--active); color: var(--text); }
.conv .ct { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .cs { flex-basis: 100%; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .cm { opacity: 0; width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; color: var(--muted); }
.conv .cm svg { width: 17px; height: 17px; }
.conv:hover .cm, .conv.active .cm { opacity: 1; }
.conv .cm:hover { background: var(--active); color: var(--text); }
.conv input { flex: 1; min-width: 0; height: 28px; border: 1px solid var(--accent); border-radius: 7px; padding: 0 7px; background: var(--surface); outline: none; font-size: 14px; }
.conv-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 10px; }
.side-foot { display: flex; align-items: center; gap: 4px; border-top: 1px solid var(--line); padding-top: 8px; }
.side-item { flex: 1; display: flex; align-items: center; gap: 9px; height: 38px; padding: 0 10px; border-radius: 10px; font-size: 14px; color: var(--text-2); }
.side-item:hover { background: var(--hover); color: var(--text); }
.side-item svg { width: 18px; height: 18px; }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 6px; padding: 0 12px; position: relative; z-index: 5; }
.model-btn { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px 0 12px; border-radius: 11px; max-width: min(520px, 62vw); transition: background .15s; }
.model-btn:hover { background: var(--hover); }
.mp-proto { font-size: 10.5px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 6px; line-height: 18px; white-space: nowrap; }
.mp-proto:empty { display: none; }
.mp-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.model-btn .chev { width: 16px; height: 16px; color: var(--muted); }
.body-row { flex: 1; min-height: 0; display: flex; }
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scroll-padding-bottom: 20px; }
.messages { max-width: 780px; margin: 0 auto; padding: 8px 24px 0; }
.bottom-pad { height: 28px; }

.empty { max-width: 780px; margin: 0 auto; padding: 18vh 24px 0; text-align: center; color: var(--muted); }
.empty-logo { width: 54px; height: 54px; color: var(--accent); opacity: .9; }
.empty-title { font-size: 22px; color: var(--text); font-weight: 600; margin-top: 14px; letter-spacing: .02em; }
.empty-sub { margin-top: 6px; font-size: 14px; }
.empty-sub .btn { margin-top: 14px; }

/* ----------------------------------------------------------- messages */
.msg { padding: 14px 0; position: relative; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); padding: 10px 15px; border-radius: 18px 18px 6px 18px; max-width: min(85%, 640px); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .files { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-bottom: 8px; max-width: 85%; }
.msg .files img { max-width: 220px; max-height: 220px; border-radius: 12px; display: block; border: 1px solid var(--line); cursor: zoom-in; object-fit: cover; }
.fchip { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px 0 9px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; max-width: 260px; }
.fchip svg { width: 18px; height: 18px; color: var(--accent); }
.fchip .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fchip .fs { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.msg.assistant .content { overflow-wrap: anywhere; }
.msg-meta { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.msg.assistant .msg-meta { margin-bottom: 4px; }
.msg-meta .m-model { font-weight: 550; color: var(--text-2); }
.actions { display: flex; gap: 2px; margin-top: 6px; color: var(--muted); align-items: center; flex-wrap: wrap; }
.msg.user .actions { justify-content: flex-end; opacity: 0; transition: opacity .15s; }
.msg.user:hover .actions, .msg.user:focus-within .actions { opacity: 1; }
.actions button { height: 30px; min-width: 30px; padding: 0 7px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); }
.actions button:hover { background: var(--hover); color: var(--text); }
.actions svg { width: 16px; height: 16px; }
.actions .stat { font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; }

.think { margin: 2px 0 10px; border-left: 2px solid var(--line-2); padding-left: 12px; }
.think-head { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; height: 28px; border-radius: 8px; padding-right: 6px; }
.think-head:hover { color: var(--text-2); }
.think-head svg { width: 16px; height: 16px; }
.think-head .chev { width: 14px; height: 14px; transition: transform .2s; }
.think.open .think-head .chev { transform: rotate(180deg); }
.think-body { display: none; color: var(--text-2); font-size: 13.5px; line-height: 1.65; padding: 2px 0 6px; }
.think.open .think-body { display: block; }
.think.live .think-head span { background: linear-gradient(90deg, var(--muted) 30%, var(--text) 50%, var(--muted) 70%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shine 1.6s linear infinite; }
@keyframes shine { from { background-position: 100% 0 } to { background-position: -100% 0 } }

.errbox { border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 7%, transparent); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; margin-top: 6px; }
.errbox b { color: var(--danger); display: flex; align-items: center; gap: 6px; font-weight: 600; }
.errbox b svg { width: 17px; height: 17px; }
.errbox pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-all; font-family: var(--mono); font-size: 12px; color: var(--text-2); max-height: 260px; overflow: auto; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s } .typing i:nth-child(3) { animation-delay: .3s }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0) } 40% { opacity: 1; transform: translateY(-2px) } }
.caret::after { content: ""; display: inline-block; width: 7px; height: 1.05em; background: var(--accent); margin-left: 2px; vertical-align: -2px; border-radius: 2px; animation: caret 1s steps(2) infinite; }
@keyframes caret { 50% { opacity: 0 } }

.edit-box { width: min(100%, 680px); }
.edit-box textarea { width: 100%; min-height: 90px; max-height: 50vh; border-radius: 14px; border: 1px solid var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); padding: 11px 14px; outline: none; resize: vertical; line-height: 1.6; }
.edit-box .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }

/* ----------------------------------------------------------- markdown */
.md { line-height: 1.72; }
.md > :first-child { margin-top: 0 !important; }
.md > :last-child { margin-bottom: 0 !important; }
.md p { margin: .55em 0 .75em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.35; margin: 1.3em 0 .5em; font-weight: 650; }
.md h1 { font-size: 1.45em } .md h2 { font-size: 1.27em } .md h3 { font-size: 1.12em } .md h4 { font-size: 1em }
.md ul, .md ol { padding-left: 1.5em; margin: .5em 0 .8em; }
.md li { margin: .25em 0; }
.md li > p { margin: .25em 0; }
.md a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 3px; }
.md blockquote { margin: .8em 0; padding: 2px 0 2px 14px; border-left: 3px solid var(--line-2); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.5em 0; }
.md img { max-width: 100%; border-radius: 10px; }
.md table { border-collapse: collapse; margin: .8em 0; font-size: .93em; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 11px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 600; }
.md :not(pre) > code { font-family: var(--mono); font-size: .86em; background: var(--code-bg); border: 1px solid var(--line); padding: .1em .38em; border-radius: 6px; overflow-wrap: anywhere; }
.codeblock { margin: .9em 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; height: 34px; padding: 0 6px 0 13px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); font-family: var(--mono); }
.code-head button { height: 26px; padding: 0 8px; border-radius: 7px; display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); font-family: var(--font); }
.code-head button:hover { background: var(--hover); color: var(--text); }
.code-head svg { width: 15px; height: 15px; }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 13px; line-height: 1.6; tab-size: 4; }
.codeblock pre code { font-family: inherit; background: none; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* highlight.js theme (light/dark) */
.hljs-comment, .hljs-quote { color: #8f8b80; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-type { color: #8b3fa8; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute { color: #1f7a45; }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-link { color: #b25c12; }
.hljs-title, .hljs-section, .hljs-title.function_ { color: #1f5fb0; }
.hljs-built_in, .hljs-class .hljs-title, .hljs-title.class_ { color: #a04b2c; }
.hljs-variable, .hljs-template-variable, .hljs-attr, .hljs-params { color: #a53a54; }
.hljs-meta, .hljs-selector-id, .hljs-selector-class { color: #2d7c8a; }
.hljs-deletion { color: #c2453a; } .hljs-emphasis { font-style: italic } .hljs-strong { font-weight: 700 }
[data-theme="dark"] .hljs-comment, [data-theme="dark"] .hljs-quote { color: #7d7a72; }
[data-theme="dark"] .hljs-keyword, [data-theme="dark"] .hljs-selector-tag, [data-theme="dark"] .hljs-literal, [data-theme="dark"] .hljs-type { color: #d197e8; }
[data-theme="dark"] .hljs-string, [data-theme="dark"] .hljs-regexp, [data-theme="dark"] .hljs-addition, [data-theme="dark"] .hljs-attribute { color: #9fd18b; }
[data-theme="dark"] .hljs-number, [data-theme="dark"] .hljs-symbol, [data-theme="dark"] .hljs-bullet, [data-theme="dark"] .hljs-link { color: #f0ae6c; }
[data-theme="dark"] .hljs-title, [data-theme="dark"] .hljs-section, [data-theme="dark"] .hljs-title.function_ { color: #7fb4f5; }
[data-theme="dark"] .hljs-built_in, [data-theme="dark"] .hljs-title.class_ { color: #eb9a78; }
[data-theme="dark"] .hljs-variable, [data-theme="dark"] .hljs-template-variable, [data-theme="dark"] .hljs-attr, [data-theme="dark"] .hljs-params { color: #ee8fa5; }
[data-theme="dark"] .hljs-meta, [data-theme="dark"] .hljs-selector-id, [data-theme="dark"] .hljs-selector-class { color: #6fcad6; }

/* ----------------------------------------------------------- composer */
.composer-wrap { flex: none; padding: 0 24px calc(16px + var(--safe-b)); position: relative; }
.composer { max-width: 780px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: 22px; box-shadow: var(--shadow); padding: 8px 8px 8px; transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--line-2)); }
.composer textarea { display: block; width: 100%; border: 0; outline: 0; resize: none; background: transparent; padding: 6px 10px 4px; max-height: 40vh; min-height: 28px; line-height: 1.55; font-size: 15.5px; }
.composer textarea::placeholder { color: var(--muted); }
.composer-bar { display: flex; align-items: center; gap: 4px; margin-top: 2px; min-width: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; flex-shrink: 1; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border-radius: 99px; font-size: 12px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; flex: none; }
.chip svg { width: 14px; height: 14px; }
.chip.acc { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.send-btn { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); transition: background .15s, transform .1s, opacity .15s; flex: none; }
.send-btn:hover { background: var(--accent-2); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn.stop { background: var(--text); color: var(--bg); }
.send-btn svg { width: 19px; height: 19px; }
.attach-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 4px 6px; }
.attach-row:empty { display: none; }
.att { position: relative; height: 56px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); display: flex; align-items: center; overflow: hidden; }
.att img { height: 56px; width: 56px; object-fit: cover; display: block; }
.att .ai { padding: 0 30px 0 10px; display: flex; flex-direction: column; justify-content: center; max-width: 200px; font-size: 12.5px; line-height: 1.35; }
.att .ai b { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .ai span { color: var(--muted); font-size: 11.5px; }
.att .rm { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; }
.att .rm svg { width: 12px; height: 12px; }
.att.loading::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: var(--p, 10%); background: var(--accent); transition: width .2s; }
.att.failed { border-color: var(--danger); }
.drop-hint { position: absolute; inset: -12px 12px 6px; border: 2px dashed var(--accent); border-radius: 24px; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 85%, transparent); color: var(--accent); font-weight: 600; z-index: 5; }
.to-bottom { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(118px + var(--safe-b)); width: 36px; height: 36px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow); display: grid; place-items: center; color: var(--text-2); z-index: 4; }
.to-bottom svg { width: 18px; height: 18px; }

/* ----------------------------------------------------------- params panel */
.params { width: var(--params-w); flex: none; border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; margin-right: calc(-1 * var(--params-w)); transition: margin .25s cubic-bezier(.3,.7,.2,1); }
.app.params-open .params { margin-right: 0; }
.params-head { display: flex; align-items: center; gap: 8px; padding: 12px 10px 8px 18px; }
.ph-title { font-weight: 650; font-size: 15px; }
.ph-sub { flex: 1; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.params-body { flex: 1; overflow-y: auto; padding: 0 18px 24px; }
.p-sec { padding: 14px 0 6px; border-top: 1px solid var(--line); }
.p-sec:first-child { border-top: 0; padding-top: 4px; }
.p-sec-title { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .05em; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.p-sec-title button { font-size: 12px; color: var(--accent); font-weight: 500; letter-spacing: 0; }
.p-row { margin-bottom: 14px; }
.p-row.off .p-ctl { opacity: .4; pointer-events: none; }
.p-top { display: flex; align-items: center; gap: 10px; min-height: 26px; }
.p-label { flex: 1; font-size: 14px; display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.p-label code { font-family: var(--mono); font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-ctl { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.p-ctl input[type=range] { flex: 1; }
.p-num { width: 76px; height: 32px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); padding: 0 8px; text-align: right; font-variant-numeric: tabular-nums; outline: none; font-size: 13.5px; }
.p-num:focus { border-color: var(--accent); }
.p-hint { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.p-sel { height: 32px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); padding: 0 8px; font-size: 13px; outline: none; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { flex: 1; height: 28px; border-radius: 8px; font-size: 12.5px; color: var(--text-2); padding: 0 6px; white-space: nowrap; min-width: 0; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--line); font-weight: 550; }
[data-theme="dark"] .seg button.on { background: var(--line-2); }
.p-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.p-actions .btn { flex: 1; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 20px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--accent) var(--fill, 50%), var(--line-2) var(--fill, 50%)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line-2); box-shadow: 0 1px 4px rgba(0,0,0,.2); margin-top: -7px; }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line-2); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line-2); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 22px; background: var(--line-2); transition: background .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s cubic-bezier(.3,.7,.2,1); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--line-2); border-radius: 10px; padding: 5px; min-height: 40px; background: var(--surface); }
.tags .tag { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 9px; border-radius: 7px; background: var(--surface-2); font-family: var(--mono); font-size: 12px; }
.tags .tag button { width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; color: var(--muted); }
.tags .tag button:hover { background: var(--active); }
.tags .tag svg { width: 12px; height: 12px; }
.tags input { flex: 1; min-width: 80px; border: 0; outline: 0; background: transparent; height: 26px; font-size: 13px; padding: 0 4px; }

/* ----------------------------------------------------------- overlay / modal / popover */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(15, 13, 8, .32); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .18s ease; backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.overlay.pop-mode { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; align-items: flex-start; justify-content: flex-start; padding: 0; }
@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.985) } }
.modal { width: min(760px, 100%); max-height: min(86vh, 900px); background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; animation: rise .22s cubic-bezier(.3,.7,.2,1); border: 1px solid var(--line); }
.modal.sm { width: min(440px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 12px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 650; flex: 1; min-width: 0; }
.modal-body { overflow-y: auto; padding: 18px 20px 20px; flex: 1; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.tabs button { height: 42px; padding: 0 10px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--text); border-color: var(--accent); font-weight: 550; }
.f-row { margin-bottom: 16px; }
.f-row > label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 550; }
.f-row .p-hint { margin-top: 6px; }
.f-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.pv-list { display: flex; flex-direction: column; gap: 8px; }
.pv { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.pv:hover { border-color: var(--line-2); background: var(--surface-2); }
.pv-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--accent); background: var(--accent-soft); flex: none; letter-spacing: .02em; }
.pv-main { flex: 1; min-width: 0; }
.pv-name { font-weight: 600; font-size: 14.5px; }
.pv-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mchip { display: inline-flex; align-items: center; gap: 2px; height: 28px; padding: 0 4px 0 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; font-family: var(--mono); max-width: 100%; }
.mchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mchip button { width: 20px; height: 20px; border-radius: 5px; display: grid; place-items: center; color: var(--muted); flex: none; }
.mchip button:hover { background: var(--active); color: var(--text); }
.mchip svg { width: 12px; height: 12px; }
.inline { display: flex; gap: 8px; }
.inline .field { flex: 1; }
.fetch-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; }
.fetch-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 12.5px; cursor: pointer; }
.fetch-item:last-child { border-bottom: 0; }
.fetch-item:hover { background: var(--hover); }
.fetch-item input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; }
.empty-box { text-align: center; padding: 34px 20px; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 16px; font-size: 14px; }
.empty-box .btn { margin-top: 12px; }
.json-view { margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; background: var(--code-bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.req-url { font-family: var(--mono); font-size: 12.5px; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; word-break: break-all; margin-bottom: 12px; }
.req-url b { color: var(--accent); margin-right: 6px; }
.sub-h { font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; letter-spacing: .04em; }

.popover { position: fixed; z-index: 101; width: 380px; max-height: min(70vh, 560px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; animation: rise .16s cubic-bezier(.3,.7,.2,1); }
.pop-search { padding: 10px 10px 6px; }
.pop-search .field { height: 38px; }
.pop-list { overflow-y: auto; padding: 4px 6px 8px; flex: 1; }
.pop-group { font-size: 11.5px; color: var(--muted); padding: 10px 10px 4px; font-weight: 600; letter-spacing: .04em; display: flex; align-items: center; gap: 6px; }
.pop-group .mp-proto { font-size: 9.5px; padding: 0 5px; line-height: 16px; }
.pop-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; height: 36px; padding: 0 10px; border-radius: 9px; font-size: 13.5px; font-family: var(--mono); }
.pop-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-item:hover, .pop-item.kb { background: var(--hover); }
.pop-item.on { color: var(--accent); }
.pop-item svg { width: 16px; height: 16px; }
.pop-foot { border-top: 1px solid var(--line); padding: 8px; display: flex; gap: 6px; }
.menu { position: fixed; z-index: 101; min-width: 160px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 5px; animation: rise .14s ease; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu svg { width: 17px; height: 17px; }
.toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%) translateY(10px); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 12px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 200; max-width: 86vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.lightbox { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.85); display: grid; place-items: center; padding: 20px; cursor: zoom-out; animation: fade .15s; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.only-mobile { display: none !important; }
.sheet-handle { display: none; }

/* ----------------------------------------------------------- mobile */
@media (max-width: 899px) {
  html, body { font-size: 15.5px; }
  .only-mobile { display: inline-grid !important; }
  .only-desktop { display: none !important; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(84vw, 320px); transform: translateX(-102%); transition: transform .28s cubic-bezier(.3,.7,.2,1); box-shadow: none; padding-top: calc(12px + env(safe-area-inset-top, 0px)); padding-bottom: calc(10px + var(--safe-b)); }
  .app.side-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(10, 8, 4, .35); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 25; }
  .app.side-open .scrim, .app.params-open .scrim { opacity: 1; pointer-events: auto; }
  .conv { height: 42px; font-size: 15px; }
  .conv .cm { opacity: 1; }
  .topbar { height: 52px; padding: 0 6px; padding-top: env(safe-area-inset-top, 0px); height: calc(52px + env(safe-area-inset-top, 0px)); }
  .model-btn { max-width: none; flex: 1; min-width: 0; justify-content: center; padding: 0 8px; }
  .topbar .grow { display: none; }
  .messages { padding: 4px 16px 0; }
  .msg.user .bubble { max-width: 88%; }
  .msg.user .actions { opacity: 1; }
  .msg .files img { max-width: 160px; max-height: 160px; }
  .composer-wrap { padding: 0 10px calc(10px + var(--safe-b)); }
  .composer { border-radius: 20px; }
  .composer textarea { font-size: 16px; }
  .empty { padding-top: 14vh; }
  .params { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; height: min(86dvh, 760px); margin: 0; border: 0; border-radius: 20px 20px 0 0; z-index: 40; transform: translateY(102%); transition: transform .3s cubic-bezier(.3,.7,.2,1); box-shadow: var(--shadow-lg); }
  .app.params-open .params { transform: none; }
  .sheet-handle { display: block; width: 38px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 8px auto 0; }
  .params-head { padding-top: 6px; }
  .params-body { padding-bottom: calc(24px + var(--safe-b)); }
  .overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.sm { width: 100%; max-height: 92dvh; border-radius: 20px 20px 0 0; animation: sheet .28s cubic-bezier(.3,.7,.2,1); border: 0; }
  .modal-foot { padding-bottom: calc(12px + var(--safe-b)); }
  @keyframes sheet { from { transform: translateY(40%); opacity: 0 } }
  .popover { left: 8px !important; right: 8px; top: auto !important; bottom: 8px; width: auto; max-height: 75dvh; padding-bottom: var(--safe-b); }
  .f-grid { grid-template-columns: 1fr; }
  .to-bottom { bottom: calc(104px + var(--safe-b)); }
  .p-num { height: 34px; font-size: 15px; }
  .field { font-size: 16px; }
  .tags input { font-size: 16px; }
}
@media (min-width: 900px) and (max-width: 1180px) {
  .app.params-open .sidebar { width: 236px; }
}
@media (hover: none) {
  .conv .cm { opacity: 1; }
}
@media print {
  .sidebar, .topbar, .composer-wrap, .params, .actions { display: none !important; }
  body { overflow: visible; }
}
