*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f1f5f9; --s: #fff; --s2: #f8fafc; --s3: #f1f5f9;
  --bd: #e2e8f0; --bd2: #cbd5e1; --tx: #1e293b; --tx2: #475569; --tx3: #94a3b8;
  --bl: #3b82f6; --blh: #2563eb; --blb: #eff6ff; --blbd: #bfdbfe;
  --gr: #10b981; --grb: #ecfdf5; --rd: #ef4444; --rdb: #fef2f2;
  --r: 8px; --r-lg: 12px;
  --sh: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shm: 0 4px 12px rgba(0,0,0,.08);
  --shl: 0 10px 40px rgba(0,0,0,.1);
  --f: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --m: ui-monospace, "SFMono-Regular", "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  --sw: 260px;
  --fs-xs: 12px; --fs-sm: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 28px;
}
html, body { height: 100%; font-family: var(--f); font-size: var(--fs-md); color: var(--tx); background: var(--bg); line-height: 1.6; overflow: hidden; }

/* LAYOUT & SIDEBAR */
.app { display: flex; height: 100vh; overflow: hidden; position: relative; }
.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 90; opacity: 0; transition: opacity .3s; backdrop-filter: blur(2px); }
.sb-overlay.show { display: block; opacity: 1; }
.sb { width: var(--sw); min-width: var(--sw); background: var(--s); border-right: 1px solid var(--bd); display: flex; flex-direction: column; height: 100%; overflow: hidden; flex-shrink: 0; transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 100; }
.sb-h { padding: 20px 16px; border-bottom: 1px solid var(--bd); flex-shrink: 0; }
.sb-brand { display: flex; align-items: center; gap: 10px; cursor: pointer; text-decoration: none; }
.sb-icon { width: 32px; height: 32px; background: var(--bl); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: var(--fs-md); flex-shrink: 0; }
.sb-name { font-size: var(--fs-md); font-weight: 700; color: var(--tx); line-height: 1.2; }
.sb-sub { font-size: var(--fs-xs); color: var(--tx3); margin-top: 2px;}
.sb-new { margin: 12px 16px; padding: 10px; background: var(--blb); border: 1px solid var(--blbd); border-radius: var(--r); color: var(--bl); font-size: var(--fs-sm); font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; font-family: var(--f); transition: background .15s; width: calc(100% - 32px); }
.sb-new:hover { background: #dbeafe; }
.sb-list { flex: 1; overflow-y: auto; padding: 8px 12px; }
.sb-list::-webkit-scrollbar { width: 4px; }
.sb-list::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 4px; }
.sb-foot { padding: 12px 16px; border-top: 1px solid var(--bd); flex-shrink: 0; }
.sb-foot-lbl { font-size: var(--fs-xs); color: var(--tx3); text-align: center; margin-bottom: 8px; }
.sb-file { display: flex; flex-wrap: wrap; gap: 8px; }
.sb-file-btn { flex: 1 1 45%; padding: 6px 0; background: var(--s3); border: 1px solid var(--bd); border-radius: var(--r); color: var(--tx2); font-size: var(--fs-xs); cursor: pointer; text-align: center; transition: all .12s; font-family: var(--f); display: flex; align-items: center; justify-content: center; gap: 4px; }
.sb-file-btn:hover { background: var(--s); border-color: var(--bd2); color: var(--tx); }
.sb-file-btn.cloud { background: #f0f9ff; border-color: #bae6fd; color: #0369a1; display: none; }
.sb-file-btn.cloud:hover { background: #e0f2fe; border-color: #7dd3fc; }
.ch-item { display: flex; align-items: center; padding: 10px 12px; border-radius: var(--r); cursor: pointer; gap: 8px; font-size: var(--fs-sm); color: var(--tx2); transition: background .1s; margin-bottom: 2px;}
.ch-item:hover { background: var(--s3); }
.ch-item.on { background: var(--blb); color: var(--bl); font-weight: 500;}
.ch-t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.ch-del { opacity: 0; background: none; border: none; color: var(--tx3); cursor: pointer; font-size: var(--fs-sm); padding: 2px 6px; border-radius: 4px; transition: all .1s; flex-shrink: 0; }
.ch-item:hover .ch-del { opacity: 1; }
.ch-del:hover { color: var(--rd); }
.emp { text-align: center; padding: 16px; font-size: var(--fs-sm); color: var(--tx3); }

/* MAIN & TOPBAR */
.mn { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; overflow: hidden; }
.tb { padding: 14px 24px; background: var(--s); border-bottom: 1px solid var(--bd); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.tb-l { display: flex; flex-direction: row; align-items: center; min-width: 0; flex: 1; gap: 12px; }
.menu-btn { display: none; background: none; border: none; font-size: 24px; color: var(--tx2); cursor: pointer; padding: 4px; border-radius: 6px; line-height: 1; }
.menu-btn:hover { background: var(--s3); color: var(--tx); }
.tb-title { font-size: var(--fs-md); font-weight: 700; color: var(--tx); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tb-r { display: flex; gap: 8px; align-items: center; }
.tb-btn { width: 36px; height: 36px; background: var(--s3); border: 1px solid var(--bd); border-radius: var(--r); color: var(--tx2); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: var(--fs-md); transition: all .12s; }
.tb-btn:hover { background: var(--s); border-color: var(--bd2); color: var(--tx); }

/* CHAT CONTROLS (BOTTOM BAR) */
.chat-ctrls { display: flex; align-items: center; gap: 12px; padding: 10px 16px 0; border-bottom: 1px solid transparent; }
.cur-api-select { background: var(--s); border: 1px solid var(--bd); border-radius: 6px; font-size: 12px; color: var(--tx2); padding: 4px 8px; cursor: pointer; outline: none; max-width: 180px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; font-family: var(--f); transition: all .2s; }
.cur-api-select:hover, .cur-api-select:focus { border-color: var(--bl); color: var(--bl); background: var(--s); box-shadow: 0 0 0 2px rgba(59,130,246,.1); }
.think-toggle-label { font-size: 12px; color: var(--tx2); display: flex; align-items: center; gap: 4px; cursor: pointer; user-select: none; transition: color .2s; }
.think-toggle-label:hover { color: var(--bl); }
.think-toggle-label input { cursor: pointer; accent-color: var(--bl); margin: 0; width: 14px; height: 14px; }
.ctrl-btn { background: var(--s); border: 1px solid var(--bd); border-radius: 6px; padding: 4px 10px; font-size: 12px; font-weight: 600; color: var(--tx2); cursor: pointer; transition: all .15s; font-family: var(--f); display: flex; align-items: center; gap: 4px; }
.ctrl-btn:hover { border-color: var(--blbd); color: var(--bl); background: var(--s2); }
.ctrl-btn.on { background: var(--blb); color: var(--bl); border-color: var(--blbd); }

/* MODERN BUTTONS */
.btn-icon { display:flex; align-items:center; gap:6px; padding:8px 14px; border-radius:var(--r); font-size:var(--fs-sm); cursor:pointer; font-family:var(--f); transition:all .15s; border: 1px solid transparent; font-weight: 500;}
.btn-icon.default { background: var(--s); border-color: var(--bd); color: var(--tx2); }
.btn-icon.default:hover { border-color: var(--bd2); color: var(--tx); background: var(--s2); }
.btn-icon.danger { background: var(--rdb); border-color: #fca5a5; color: var(--rd); }
.btn-icon.danger:hover { background: #fee2e2; }

/* CHAT AREA */
.ca { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.ca::-webkit-scrollbar { width: 6px; }
.ca::-webkit-scrollbar-track { background: transparent; }
.ca::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 6px; }

/* WELCOME */
.wl { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 24px; text-align: center; animation: fu .3s ease; }
@keyframes fu { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.wl-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 16px; background: var(--blb); border: 1px solid var(--blbd); border-radius: 24px; font-size: var(--fs-sm); color: var(--bl); font-weight: 600; margin-bottom: 24px; }
.wl-t { font-size: var(--fs-xl); font-weight: 700; color: var(--tx); margin-bottom: 12px; letter-spacing: -.5px; }
.wl-d { font-size: var(--fs-md); color: var(--tx3); max-width: 460px; line-height: 1.7; margin-bottom: 32px; }

/* MESSAGES */
.ml { flex: 1; padding: 16px 24px 24px; display: flex; flex-direction: column; gap: 16px;}
/* 修复 1：align-items: flex-start 解决长文本时头像飘到中间的问题 */
.msg { display: flex; gap: 16px; animation: mi .2s ease; position: relative; align-items: flex-start; }
@keyframes mi { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.msg.u { justify-content: flex-end; }
.msg-av { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.msg.u .msg-av { background: var(--grb); border: 1px solid #a7f3d0; }
.msg.a .msg-av { background: var(--blb); border: 1px solid var(--blbd); }
.msg-bd { max-width: 80%; min-width: 0; display: flex; flex-direction: column; }
.msg.u .msg-bd { text-align: right; align-items: flex-end; }
.msg-n { font-size: var(--fs-xs); font-weight: 600; color: var(--tx3); margin-bottom: 6px; padding: 0; }
.msg-row { display: flex; gap: 8px; align-items: flex-end; }
.msg.u .msg-row { flex-direction: row-reverse; }

.msg-b, .msg-b * { user-select: text !important; -webkit-user-select: text !important; cursor: text !important; }
.msg-b { background: var(--s); border: 1px solid var(--bd); border-radius: var(--r-lg); padding: 12px 18px; font-size: var(--fs-md); line-height: 1.7; color: var(--tx); word-break: break-word; box-shadow: var(--sh); max-width: 100%; display: inline-block; text-align: left; }
.msg.u .msg-b { background: var(--bl); border-color: var(--bl); color: #fff; box-shadow: 0 4px 12px rgba(59,130,246,.2); border-top-right-radius: 4px;}
.msg.a .msg-b { border-top-left-radius: 4px;}

::selection { background: #93c5fd !important; color: #000 !important; }
::-moz-selection { background: #93c5fd !important; color: #000 !important; }

.msg-ops { display: flex; margin-top: 6px; padding: 0 4px; }
.msg.u .msg-ops { justify-content: flex-end; }
.msg.a .msg-ops { justify-content: flex-start; }
.msg-cpy { background: transparent; border: none; color: var(--tx3); font-size: var(--fs-xs); cursor: pointer; display: flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 6px; font-family: var(--f); transition: all 0.2s; font-weight: 500; user-select: none !important; }
.msg-cpy:hover { background: var(--s3); color: var(--bl); }

/* THINKING BLOCK */
.th { background: #fffbeb; border: 1px solid #fde68a; border-left: 4px solid #f59e0b; border-radius: 8px; margin-bottom: 8px; overflow: hidden; transition: all 0.2s ease; }
.th-h { padding: 8px 12px; font-size: 12px; font-weight: 700; color: #b45309; display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; background: #fffdf5; }
.th-h:hover { background: #fef3c7; }
.th-c { padding: 10px 12px; font-size: 13px; color: #92400e; line-height: 1.6; font-family: var(--m); border-top: 1px dashed #fde68a; overflow-x: auto; }
.th.collapsed .th-c { display: none; }
.th-toggle-icon { transition: transform 0.2s; font-size: 10px; }
.th.collapsed .th-toggle-icon { transform: rotate(-90deg); }

/* TYPING INDICATOR */
.ty { display: flex; gap: 4px; align-items: center; padding: 2px 0; cursor: default !important; }
.ty-d { width: 5px; height: 5px; background: var(--bl); border-radius: 50%; animation: tb 1.2s ease-in-out infinite; opacity: 0.6; }
.ty-d:nth-child(2) { animation-delay: .15s; }
.ty-d:nth-child(3) { animation-delay: .3s; }
@keyframes tb { 0%, 60%, 100% { opacity: .4; transform: scale(1); } 30% { opacity: 1; transform: scale(1.3); } }

/* FILE ATTACHMENTS PREVIEW & MESSAGE BLOCKS */
.attach-bar { display: none; padding: 12px 16px 0; gap: 10px; flex-wrap: wrap; }
.attach-bar.o { display: flex; }
.atch-img { position: relative; width: 64px; height: 64px; border-radius: 8px; border: 1px solid var(--bd); background-size: cover; background-position: center; }
.atch-file { display: flex; align-items: center; gap: 6px; background: var(--s); border: 1px solid var(--bd); padding: 6px 12px; border-radius: 8px; font-size: 12px; color: var(--tx); position: relative; max-width: 200px; box-shadow: var(--sh); font-family: var(--f); }
.atch-file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.atch-rm { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; background: var(--rd); color: #fff; border-radius: 50%; border: none; font-size: 14px; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: var(--sh); line-height: 1; transition: transform .1s; z-index: 10;}
.atch-rm:hover { transform: scale(1.1); background: #dc2626; }

.msg-file-details { background: rgba(0,0,0,0.04); border: 1px solid rgba(0,0,0,0.1); border-radius: 8px; margin-bottom: 8px; overflow: hidden; text-align: left; }
.msg.u .msg-file-details { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.2); }
.msg-file-details summary { padding: 8px 12px; font-size: 12px; font-weight: 600; cursor: pointer; user-select: none; outline: none; display: flex; align-items: center; gap: 6px; }
.msg-file-details summary::-webkit-details-marker { display: none; }
.msg-file-details pre { margin: 0; padding: 12px; font-size: 11px; max-height: 250px; overflow-y: auto; border-top: 1px solid rgba(0,0,0,0.1); background: rgba(0,0,0,0.02); white-space: pre-wrap; word-break: break-all; }
.msg.u .msg-file-details pre { border-top-color: rgba(255,255,255,0.2); background: rgba(0,0,0,0.1); }

/* ========================================================= */
/* 📝 Markdown 排版增强优化 & 间距修复                     */
/* ========================================================= */
/* 修复 2：优化 Markdown 的间距，防止大空行 */
.msg-b p { margin-top: 0; margin-bottom: 8px; }
.msg-b p:last-child { margin-bottom: 0; }
.msg-b br { display: block; content: ""; margin-top: 4px; }
.msg-b code { font-family: var(--m); font-size: .9em; background: rgba(59,130,246,.08); border: 1px solid rgba(59,130,246,.15); border-radius: 4px; padding: 2px 6px; color: var(--bl); }
.msg.u .msg-b code { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.2); color: #fff; }
.msg-b pre { background: var(--s3); border: 1px solid var(--bd); border-radius: 8px; padding: 12px 16px; overflow-x: auto; margin: 8px 0; }
.msg-b pre code { background: none; border: none; padding: 0; color: var(--tx); font-size: var(--fs-sm); }
.msg-b strong { color: var(--bl); }
.msg.u .msg-b strong { color: #dbeafe; }

.msg-b h1, .msg-b h2, .msg-b h3, .msg-b h4, .msg-b h5 { margin: 16px 0 8px; font-weight: 700; line-height: 1.4; color: var(--tx); }
.msg-b h1 { font-size: 1.4em; border-bottom: 1px solid var(--bd); padding-bottom: 4px; }
.msg-b h2 { font-size: 1.25em; border-bottom: 1px solid var(--bd); padding-bottom: 4px; }
.msg-b h3 { font-size: 1.1em; }
.msg-b hr { border: 0; border-top: 1px solid var(--bd2); margin: 16px 0; opacity: 0.5; }
.msg-b ul, .msg-b ol { margin: 8px 0 8px 24px; padding: 0; }
.msg-b li { margin-bottom: 4px; }
.msg-b blockquote { border-left: 4px solid var(--blbd); padding-left: 12px; margin: 8px 0; color: var(--tx2); background: rgba(59,130,246,0.05); padding-top: 4px; padding-bottom: 4px; border-radius: 0 4px 4px 0; }
.msg-b a { color: var(--bl); text-decoration: none; border-bottom: 1px dashed var(--bl); }
.msg-b a:hover { text-decoration: solid; }
.msg-b table { border-collapse: collapse; margin: 12px 0; width: 100%; font-size: 0.9em; }
.msg-b th, .msg-b td { border: 1px solid var(--bd); padding: 8px 12px; text-align: left; }
.msg-b th { background: var(--s2); font-weight: 600; }
/* 适配用户气泡内的反色样式 */
.msg.u .msg-b h1, .msg.u .msg-b h2, .msg.u .msg-b h3, .msg.u .msg-b h4, .msg.u .msg-b hr, .msg.u .msg-b th, .msg.u .msg-b td, .msg.u .msg-b blockquote { color: #fff; border-color: rgba(255,255,255,0.2); }
.msg.u .msg-b th, .msg.u .msg-b blockquote { background: rgba(255,255,255,0.1); }

/* CLEAN INPUT AREA */
.ia { padding: 16px 24px 24px; background: var(--s); border-top: 1px solid var(--bd); flex-shrink: 0; }
.ib { background: var(--s2); border: 1px solid var(--bd); border-radius: var(--r-lg); display: flex; flex-direction: column; transition: border-color .2s, box-shadow .2s; }
.ib:focus-within { border-color: var(--bl); box-shadow: 0 0 0 3px rgba(59,130,246,.1); background: var(--s); }
.ir { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px 14px; }
.tx { flex: 1; background: none; border: none; color: var(--tx); font-family: var(--f); font-size: var(--fs-md); line-height: 1.6; resize: none; outline: none; max-height: 200px; min-height: 24px; overflow-y: auto; }
.tx::placeholder { color: var(--tx3); }
.tx::-webkit-scrollbar { width: 4px; }
.tx::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 4px; }
.sb2 { width: 38px; height: 38px; background: var(--bl); border: none; border-radius: 8px; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: var(--fs-lg); flex-shrink: 0; transition: all .15s; }
.sb2:hover { background: var(--blh); transform: translateY(-1px); }
.sb2:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.sb2.sec { background: transparent; border: 1px solid transparent; color: var(--tx3); font-size: 20px; width: 34px;}
.sb2.sec:hover { color: var(--rd); transform: none; background: var(--rdb);}
.sb2.sec.attach { font-size: 22px; }
.sb2.sec.attach:hover { color: var(--bl); background: var(--blb); }
.if { font-size: var(--fs-xs); color: var(--tx3); padding: 0 16px 10px; display: flex; align-items: center; gap: 12px; }

/* PRESET INJECTED NOTICE */
.pn { background: #fef9c3; border: 1px solid #fde68a; border-radius: 8px; padding: 10px 16px; margin: 8px 24px; font-size: var(--fs-sm); color: #854d0e; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pn-txt { display: flex; align-items: center; gap: 8px; }
.pn-dismiss { background: none; border: none; color: #b45309; cursor: pointer; font-size: var(--fs-xs); font-family: var(--f); padding: 4px 8px; border-radius: 6px; transition: all .1s; }
.pn-dismiss:hover { background: #fef08a; }

/* MODAL TABS */
.mbg { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.4); backdrop-filter: blur(4px); z-index: 1000; align-items: center; justify-content: center; animation: bi .2s ease; }
.mbg.o { display: flex; }
@keyframes bi { from { opacity: 0; } to { opacity: 1; } }
.mo { background: var(--s); border: 1px solid var(--bd); border-radius: 16px; width: 560px; max-width: calc(100vw - 32px); height: 85vh; max-height: 800px; display: flex; flex-direction: column; box-shadow: var(--shl); animation: mi2 .22s ease; }
@keyframes mi2 { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.mo::-webkit-scrollbar { width: 6px; }
.mo::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 6px; }
.mh { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 16px; flex-shrink: 0; }
.mt { font-size: var(--fs-lg); font-weight: 700; color: var(--tx); }
.tabs { display: flex; gap: 24px; padding: 0 24px; border-bottom: 1px solid var(--bd); flex-shrink: 0; background: var(--s); }
.tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 0 4px 12px; font-size: var(--fs-sm); font-weight: 600; color: var(--tx3); cursor: pointer; transition: all .15s; font-family: var(--f); }
.tab:hover { color: var(--tx2); }
.tab.on { color: var(--bl); border-bottom-color: var(--bl); }
.mc { display: none; padding: 20px 24px; flex: 1; overflow-y: auto; }
.mc.o { display: block; }

.sg { margin-bottom: 24px; }
.sg-l { font-size: var(--fs-xs); font-weight: 700; color: var(--tx3); text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.sg-l::after { content: ""; flex: 1; height: 1px; background: var(--bd); }
.sf { margin-bottom: 12px; }
.sl { display: block; font-size: var(--fs-sm); color: var(--tx2); margin-bottom: 6px; font-weight: 500; }
.si, .sta { width: 100%; background: var(--s2); border: 1px solid var(--bd); border-radius: var(--r); color: var(--tx); font-family: var(--f); font-size: var(--fs-sm); padding: 10px 14px; outline: none; transition: border-color .15s, box-shadow .15s; }
.si:focus, .sta:focus { border-color: var(--bl); box-shadow: 0 0 0 3px rgba(59,130,246,.1); background: var(--s); }
.si::placeholder, .sta::placeholder { color: var(--tx3); }
.sta { resize: vertical; min-height: 80px; }
.btns { display: flex; gap: 10px; margin-top: 10px; }

/* PRESET LIST IN SETTINGS */
.pr-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; background: var(--s2); border: 1px solid var(--bd); border-radius: var(--r); margin-bottom: 8px; transition: border-color .1s; }
.pr-row:hover { border-color: var(--bd2); }
.pr-chk { width: 16px; height: 16px; accent-color: var(--bl); cursor: pointer; flex-shrink: 0; margin-top: 2px; }
.pr-info { flex: 1; min-width: 0; }
.pr-n { font-size: var(--fs-sm); font-weight: 600; color: var(--tx); margin-bottom: 4px; }
.pr-d { font-size: var(--fs-xs); color: var(--tx3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pr-ops { display: flex; gap: 4px; flex-shrink: 0; }
.ob { background: none; border: none; color: var(--tx3); cursor: pointer; font-size: var(--fs-sm); padding: 4px 8px; border-radius: 6px; transition: all .1s; font-family: var(--f); }
.ob:hover { color: var(--tx2); background: var(--s3); }
.ob.d:hover { color: var(--rd); background: var(--rdb); }
.apb { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px; background: transparent; border: 1px dashed var(--bd2); border-radius: var(--r); color: var(--tx3); font-size: var(--fs-sm); cursor: pointer; width: 100%; transition: all .15s; font-family: var(--f); margin-top: 10px; }
.apb:hover { border-color: var(--bl); color: var(--bl); background: var(--blb); }

/* PRESET EDITOR */
.pf { display: none; margin-top: 12px; padding: 16px; background: var(--s3); border: 1px solid var(--bd); border-radius: var(--r); }
.pf.o { display: block; }
.pf-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pf-ttl { font-size: var(--fs-sm); font-weight: 700; color: var(--tx); }
.pf-close { background: none; border: none; color: var(--tx3); cursor: pointer; font-size: var(--fs-xs); padding: 4px 10px; border-radius: 6px; font-family: var(--f); }
.pf-close:hover { background: var(--s2); color: var(--tx); }
.msg-line { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.msg-role { width: 80px; flex-shrink: 0; font-size: var(--fs-xs); font-family: var(--f); padding: 6px 8px; border: 1px solid var(--bd); border-radius: 6px; background: var(--s2); color: var(--tx); cursor: pointer; }
.msg-role:focus { outline: none; border-color: var(--bl); }
.msg-line textarea { width: 100%; background: var(--s); border: 1px solid var(--bd); border-radius: 8px; padding: 8px 12px; font-size: var(--fs-sm); font-family: var(--f); color: var(--tx); resize: vertical; min-height: 50px; line-height: 1.5; outline: none; transition: border-color .15s; }
.msg-line textarea:focus { border-color: var(--bl); }
.rm-line { background: none; border: none; color: var(--rd); cursor: pointer; font-size: var(--fs-md); padding: 6px; flex-shrink: 0; opacity: .5; transition: opacity .1s; }
.rm-line:hover { opacity: 1; }
.add-line { background: none; border: 1px dashed var(--bd2); border-radius: 8px; color: var(--tx3); cursor: pointer; font-size: var(--fs-xs); padding: 8px 12px; width: 100%; font-family: var(--f); transition: all .1s; margin-top: 8px; }
.add-line:hover { border-color: var(--bl); color: var(--bl); }

/* JSON IMPORT/EXPORT */
.json-ops { display: flex; gap: 8px; margin-bottom: 12px; }
.json-btn { flex: 1; padding: 8px 12px; background: var(--s2); border: 1px solid var(--bd); border-radius: var(--r); color: var(--tx2); font-size: var(--fs-sm); cursor: pointer; font-family: var(--f); transition: all .12s; display: flex; align-items: center; justify-content: center; gap: 6px; }
.json-btn:hover { background: var(--s); border-color: var(--bd2); }

.savebtn { width: 100%; padding: 12px; background: var(--bl); border: none; border-radius: var(--r); color: #fff; font-size: var(--fs-sm); font-weight: 600; cursor: pointer; font-family: var(--f); transition: background .15s; }
.savebtn:hover { background: var(--blh); }
.cb { background: none; border: none; color: var(--tx3); font-size: var(--fs-xl); cursor: pointer; padding: 4px; border-radius: 6px; transition: all .1s; line-height: 1; }
.cb:hover { background: var(--s3); color: var(--tx); }

/* PRESET SELECTOR MODAL */
.psm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .psm-grid { grid-template-columns: 1fr; } }
.psm-card { border: 1px solid var(--bd); border-radius: var(--r); padding: 14px; cursor: pointer; transition: all .15s; background: var(--s); text-align: left; }
.psm-card:hover { border-color: var(--bl); box-shadow: var(--sh); transform: translateY(-2px); }
.psm-card.on { border-color: var(--bl); background: var(--blb); box-shadow: 0 0 0 1px var(--bl); }
.psm-name { font-size: var(--fs-sm); font-weight: 600; color: var(--tx); margin-bottom: 4px; }
.psm-desc { font-size: var(--fs-xs); color: var(--tx3); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.4; }

/* TOAST */
.tw { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.to { padding: 10px 18px; background: var(--s); border: 1px solid var(--bd); border-radius: 10px; font-size: var(--fs-sm); color: var(--tx); box-shadow: var(--shm); animation: ti .25s ease; max-width: 300px; }
.to.ok { border-color: #86efac; color: #16a34a; background: var(--grb); }
.to.er { border-color: #fca5a5; color: #dc2626; background: var(--rdb); }
@keyframes ti { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: translateX(0); } }

/* CONFIRM */
.cbg { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 2000; align-items: center; justify-content: center; }
.cbg.o { display: flex; }
.cb2 { background: var(--s); border: 1px solid var(--bd); border-radius: 16px; padding: 32px; width: 340px; text-align: center; box-shadow: var(--shl); }
.cb2 h3 { font-size: var(--fs-lg); font-weight: 700; margin-bottom: 8px; }
.cb2 p { font-size: var(--fs-sm); color: var(--tx3); margin-bottom: 24px; }
.cbs { display: flex; gap: 10px; }
.cbs button { flex: 1; padding: 10px; border-radius: 8px; font-size: var(--fs-sm); cursor: pointer; font-family: var(--f); font-weight: 500; transition: all .12s; }
.cncl { background: var(--s3); border: 1px solid var(--bd); color: var(--tx2); }
.cncl:hover { background: var(--s2); }
.cok { background: var(--rdb); border: 1px solid #fca5a5; color: var(--rd); }
.cok:hover { background: #fee2e2; }

/* ========================================================= */
/* 📱 移动端自适应适配                     */
/* ========================================================= */
@media (max-width: 768px) {
  .menu-btn { display: block; }
  .sb { position: fixed; left: -280px; top: 0; bottom: 0; width: 280px; z-index: 100; box-shadow: var(--shl); }
  .sb.show { left: 0; }
  .tb { padding: 12px 16px; }
  .chat-ctrls { flex-wrap: wrap; gap: 10px 8px; padding: 10px 12px 0; }
  .cur-api-select { flex: 1 1 100%; max-width: none; }
  .think-toggle-label { flex: 1 1 auto; justify-content: flex-start; }
  .ctrl-btn { flex: 0 0 auto; }
  .ia { padding: 12px 16px 16px; }
  .msg { gap: 10px; }
  .msg-bd { max-width: 88%; }
  .msg-av { width: 34px; height: 34px; font-size: 16px; }
  .msg-b { padding: 10px 14px; font-size: 15px; }
  .mo { width: 92%; max-height: 88vh; border-radius: 12px; }
  .mh { padding: 16px 20px 12px; }
  .mc { padding: 16px 20px; }
  .tabs { padding: 0 20px; gap: 16px; }
  .psm-grid { grid-template-columns: 1fr; }
}

/* ========================================================= */
/* 🛠️ 新增操作按钮与防溢出样式                     */
/* ========================================================= */
.cursor { display:inline-block; width:6px; height:14px; background:var(--bl); vertical-align:middle; animation:bi .8s infinite; margin-left:4px; }
.sb2.stop-mode { background: var(--rd); color: #fff; animation: pulse 2s infinite; font-size: 14px;}
.sb2.stop-mode:hover { background: #dc2626; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(239,68,68, 0.4); } 70% { box-shadow: 0 0 0 8px rgba(239,68,68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239,68,68, 0); } }

/* 强制打断长英文与无空格长文本撑爆页面 */
.msg-b { word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; max-width: 100%; }
.msg-b pre { max-width: 100%; overflow-x: auto; background: var(--s3); border: 1px solid var(--bd); border-radius: 8px; padding: 12px 16px; margin: 8px 0; }
.msg.u .msg-b pre { background: rgba(0,0,0,0.15); border: 1px solid rgba(255,255,255,0.2); }