:root {
  color-scheme: light;
  --paper: #f8f9fa;
  --white: #fff;
  --ink: #202a2d;
  --muted: #758083;
  --line: #e7eaeb;
  --soft: #f1f4f3;
  --teal: #117b72;
  --teal-dark: #0d625b;
  --teal-pale: #e4f3ef;
  --coral: #da674f;
  --shadow: 0 16px 48px rgba(22, 42, 40, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid #38a79b; outline-offset: 2px; }
button:disabled { opacity: .48; cursor: not-allowed; }
.app-shell { display: grid; grid-template-columns: 64px 284px minmax(0, 1fr); height: 100dvh; overflow: hidden; background: var(--white); }
.portal-rail { z-index: 4; display: flex; flex-direction: column; align-items: center; gap: 34px; padding: 17px 8px; background: #f5f7f6; border-right: 1px solid var(--line); }
.rail-logo { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid #cbe1dc; border-radius: 12px; color: var(--teal-dark); background: #e5f0ed; font-size: 19px; font-weight: 750; }
.rail-nav { display: grid; gap: 9px; }
.rail-button, .icon-button { display: grid; place-items: center; border: 0; background: transparent; color: #697578; cursor: pointer; }
.rail-button { width: 42px; height: 42px; border-radius: 8px; font-size: 21px; }
.rail-button.is-active { color: var(--teal-dark); background: #e3eeeb; }
.rail-button:hover, .icon-button:hover { color: var(--teal-dark); background: #edf4f2; }
.rail-bottom { margin-top: auto; }
.local-indicator, .status-dot, .model-dot { display: inline-block; flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: #c3cbcc; }
.session-sidebar { position: relative; display: flex; flex-direction: column; min-height: 0; padding: 23px 16px 13px; background: #fff; border-right: 1px solid var(--line); }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 0 23px; padding: 0 4px; }
.sidebar-heading h1 { margin: 5px 0 0; font-size: 19px; line-height: 1.2; font-weight: 690; }
.eyebrow { color: #98a3a4; font-size: 9px; font-weight: 740; letter-spacing: .08em; }
.icon-button { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 8px; font-size: 18px; }
.add-button { border: 1px solid #cde1dd; color: var(--teal-dark); background: #eff7f4; font-size: 22px; }
.character-card { display: grid; grid-template-columns: 42px minmax(0, 1fr); align-items: center; gap: 11px; padding: 0 4px 20px; border-bottom: 1px solid var(--line); }
.character-avatar { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid #ecd2c9; border-radius: 13px; color: #9e503c; background: #f9ebe5; font-size: 18px; font-weight: 750; }
.character-copy { min-width: 0; }
.character-copy .eyebrow { font-size: 8px; }
.character-copy h2 { margin: 4px 0 2px; overflow: hidden; font-size: 13px; line-height: 1.45; font-weight: 690; text-overflow: ellipsis; }
.character-copy p { margin: 0; color: var(--muted); font-size: 11px; }
.character-edit { grid-column: 1 / -1; justify-self: start; margin-left: 51px; }
.text-button { padding: 5px 8px; border: 0; border-radius: 6px; color: var(--teal-dark); background: transparent; font-size: 11px; cursor: pointer; }
.text-button:hover { background: var(--teal-pale); }
.conversation-heading { position: relative; display: flex; align-items: center; justify-content: space-between; margin: 19px 0 9px; padding: 0 5px; }
.conversation-heading h2 { margin: 0; color: #788486; font-size: 12px; font-weight: 690; }
.small-icon-button { width: 28px; height: 28px; font-size: 19px; }
.conversation-list { min-height: 0; flex: 1; overflow: auto; scrollbar-width: thin; scrollbar-color: #d7dedd transparent; }
.conversation-row { display: grid; grid-template-columns: minmax(0, 1fr) 29px; gap: 3px; align-items: center; min-height: 39px; margin-bottom: 3px; padding: 2px 3px 2px 9px; border: 1px solid transparent; border-radius: 7px; }
.conversation-row:hover { background: #f5f7f7; }
.conversation-row.is-active { border-color: #96cfc4; background: #f0f8f6; }
.conversation-select { min-width: 0; overflow: hidden; padding: 6px 0; border: 0; color: #465255; background: transparent; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; font-size: 11px; }
.conversation-row.is-active .conversation-select { color: var(--teal-dark); font-weight: 680; }
.conversation-actions { position: relative; }
.conversation-actions > button { width: 25px; height: 25px; }
.menu-popover { position: absolute; z-index: 8; top: 31px; right: 0; width: 146px; padding: 5px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.menu-popover button { display: block; width: 100%; padding: 9px 8px; border: 0; border-radius: 5px; background: transparent; text-align: left; font-size: 11px; cursor: pointer; }
.menu-popover button:hover { background: var(--soft); }
.menu-popover .danger-action { color: #b34739; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 11px; padding: 11px 6px 1px; border-top: 1px solid var(--line); }
.api-status { display: flex; min-width: 0; align-items: center; gap: 8px; color: #778284; font-size: 10px; }
.api-status span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot.is-ready { background: #2d9b76; box-shadow: 0 0 0 3px #e5f5ef; }
.chat-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; background: #fff; }
.chat-header { z-index: 2; display: flex; min-height: 66px; align-items: center; justify-content: space-between; gap: 16px; padding: 0 27px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.chat-title-group, .header-actions { display: flex; align-items: center; gap: 11px; }
.chat-title-copy h2 { max-width: min(46vw, 470px); margin: 3px 0 0; overflow: hidden; font-size: 15px; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { position: relative; gap: 9px; }
.model-select { display: flex; max-width: 230px; align-items: center; gap: 8px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 7px; color: #455255; background: #fff; font-size: 11px; cursor: pointer; }
.model-select:hover { border-color: #b9d8d1; background: #f7fbf9; }
.model-select > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-menu { position: absolute; z-index: 9; top: calc(100% + 8px); right: 74px; width: min(280px, calc(100vw - 28px)); max-height: min(360px, 65dvh); overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.model-menu p { margin: 3px 7px 7px; color: var(--muted); font-size: 10px; }
.model-option, .model-settings-action { display: block; width: 100%; padding: 9px 8px; overflow-wrap: anywhere; border: 0; border-radius: 5px; background: transparent; text-align: left; font-size: 11px; cursor: pointer; }
.model-option:hover, .model-option[aria-selected="true"] { color: var(--teal-dark); background: var(--teal-pale); }
.model-settings-action { margin-top: 5px; border-top: 1px solid var(--line); border-radius: 0 0 5px 5px; color: var(--teal-dark); }
.model-settings-action:hover { background: var(--soft); }
.model-dot { width: 7px; height: 7px; background: #d0a052; }
.select-chevron { margin-left: 2px; color: #879293; font-size: 14px; }
.settings-button { border: 1px solid transparent; }
.account-button { border: 1px solid #dce8e5; color: var(--teal-dark); background: #f5f9f8; font-size: 12px; font-weight: 700; }
.mobile-menu-button { display: none; }
.message-region { min-height: 0; flex: 1; overflow: auto; overscroll-behavior: contain; background: #fff; scrollbar-color: #d3dcda transparent; scrollbar-width: thin; }
.message-list { width: min(100%, 980px); min-height: 100%; margin: 0 auto; padding: 35px 46px 45px; }
.empty-state { display: grid; min-height: 100%; place-content: center; justify-items: center; padding: 60px 20px; text-align: center; }
.empty-mark { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 15px; border: 1px solid #dce9e6; border-radius: 16px; color: var(--teal); background: #f1f7f5; font-size: 23px; }
.empty-state h3 { max-width: 420px; margin: 0 0 8px; font-size: 19px; font-weight: 680; }
.empty-state p { max-width: 440px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.8; }
.empty-state .text-button { margin-top: 14px; }
.message { margin: 0 0 27px; }
.message-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.message-avatar { display: grid; width: 25px; height: 25px; flex: 0 0 auto; place-items: center; border: 1px solid #e8d2ca; border-radius: 9px; color: #a25240; background: #fbefe9; font-size: 11px; font-weight: 750; }
.message[data-role="user"] .message-avatar { border-color: #c9ddd9; color: var(--teal-dark); background: #eaf3f0; }
.message-speaker { color: #536062; font-size: 11px; font-weight: 700; }
.message-time { color: #a0aaab; font-size: 10px; }
.message-content { color: #273235; font-size: 13px; line-height: 1.9; overflow-wrap: anywhere; }
.message-content p { margin: 0 0 11px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content pre { max-width: 100%; overflow: auto; padding: 12px; border: 1px solid #e6ebe9; border-radius: 6px; color: #354244; background: #f5f7f6; font: 12px/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; }
.message-content code:not(pre code) { padding: 1px 4px; border-radius: 4px; background: #f0f3f2; font: .92em ui-monospace, SFMono-Regular, Consolas, monospace; }
.message-content blockquote { margin: 7px 0; padding: 2px 0 2px 11px; border-left: 2px solid #a5cfc4; color: #657173; }
.message-image { display: block; max-width: min(100%, 440px); max-height: 360px; margin: 10px 0; border: 1px solid var(--line); border-radius: 7px; object-fit: contain; }
.message[data-role="user"] .message-content { max-width: min(88%, 720px); margin-left: auto; padding: 10px 13px; border: 1px solid #dce8e5; border-radius: 9px 3px 9px 9px; background: #f4f8f7; }
.message[data-role="user"] .message-head { justify-content: flex-end; }
.message[data-role="user"] .message-head .message-avatar { order: 3; }
.message[data-role="user"] .message-actions { justify-content: flex-end; }
.message-actions { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 9px; opacity: .82; }
.message-action { display: inline-flex; align-items: center; gap: 4px; min-height: 27px; padding: 4px 6px; border: 0; border-radius: 5px; color: #778184; background: transparent; font-size: 10px; cursor: pointer; }
.message-action:hover, .message-action.is-selected { color: var(--teal-dark); background: #edf6f3; }
.message-action.is-danger:hover { color: #b34739; background: #fff0eb; }
.message-spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid #cbd8d5; border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
.message-error { margin: 7px 0 0; color: #a34f40; font-size: 10px; line-height: 1.6; overflow-wrap: anywhere; }
.conversation-empty { margin: 12px 8px; color: #9ba5a6; font-size: 11px; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer-wrap { z-index: 2; width: min(100%, 1010px); align-self: center; padding: 10px 34px 16px; background: #fff; }
.composer-tools { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.tool-chip { display: inline-flex; min-height: 28px; align-items: center; gap: 5px; padding: 4px 8px; border: 1px solid transparent; border-radius: 6px; color: #707d80; background: transparent; font-size: 10px; cursor: pointer; }
.tool-chip:hover, .tool-chip[aria-pressed="true"] { border-color: #e3eae8; color: var(--teal-dark); background: #f5f8f7; }
.composer-tool-spacer { flex: 1; }
.token-estimate { color: #9ba5a6; font-size: 10px; }
.attachment-preview { position: relative; display: inline-block; margin: 0 0 8px 6px; }
.attachment-preview img { display: block; width: auto; max-width: 140px; max-height: 96px; border: 1px solid var(--line); border-radius: 6px; object-fit: cover; }
.attachment-preview > button { position: absolute; top: -8px; right: -8px; width: 23px; height: 23px; border: 1px solid #fff; border-radius: 50%; color: #fff; background: #445153; font-size: 16px; }
.composer { display: flex; min-height: 51px; align-items: flex-end; gap: 7px; padding: 6px 7px 6px 5px; border: 1px solid #dce3e2; border-radius: 9px; background: #fff; transition: border-color .16s, box-shadow .16s; }
.composer:focus-within { border-color: #8ac5b9; box-shadow: 0 0 0 3px rgba(32, 147, 126, .08); }
.attach-button { margin-bottom: 1px; font-size: 22px; }
.composer textarea { width: 100%; min-width: 0; max-height: 190px; min-height: 35px; resize: none; padding: 8px 3px 7px; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 12px; line-height: 1.65; }
.composer textarea::placeholder { color: #a0aaac; }
.send-button { display: grid; width: 36px; height: 36px; flex: 0 0 auto; place-items: center; border: 0; border-radius: 7px; color: #fff; background: var(--teal); cursor: pointer; }
.send-button:hover { background: var(--teal-dark); }
.send-button.is-stop { color: #a94838; background: #fbede8; }
.send-glyph { font-size: 15px; }
.composer-caption { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; padding: 0 3px; color: #a1aaab; font-size: 9px; }
.sidebar-backdrop { display: none; }
.settings-dialog { width: min(540px, calc(100vw - 24px)); max-height: min(92dvh, 790px); overflow: auto; padding: 0; border: 1px solid #e3e9e7; border-radius: 10px; color: var(--ink); background: #fff; box-shadow: var(--shadow); }
.settings-dialog::backdrop { background: rgba(22, 34, 34, .37); backdrop-filter: blur(2px); }
.auth-dialog { width: min(430px, calc(100vw - 24px)); }
.auth-description { margin: -8px 0 18px; color: var(--muted); font-size: 11px; line-height: 1.7; }
.auth-error { margin: 12px 0 0; color: #a34f40; font-size: 11px; line-height: 1.6; overflow-wrap: anywhere; }
.auth-actions { margin-top: 18px; }
.settings-form { padding: 23px 24px 20px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.dialog-header h2 { margin: 5px 0 0; font-size: 19px; font-weight: 690; }
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.field { display: grid; min-width: 0; gap: 6px; color: #536062; font-size: 11px; }
.field > span { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 640; }
.field small, .field output { color: #96a1a1; font-size: 10px; font-weight: 400; }
.field input:not([type="range"]), .field textarea { width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid #dfe6e4; border-radius: 6px; color: var(--ink); background: #fff; font-size: 12px; }
.field textarea { resize: vertical; line-height: 1.65; }
.field input::placeholder, .field textarea::placeholder { color: #a4adae; }
.field input[type="range"] { width: 100%; height: 5px; accent-color: var(--teal); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.channel-list { display: grid; gap: 8px; }
.channel-row { display: grid; grid-template-columns: 1fr 1.6fr 1.2fr auto; gap: 6px; align-items: center; padding: 8px; border: 1px solid #e5efec; border-radius: 6px; background: #fbfdfc; }
.channel-row input { width: 100%; min-width: 0; padding: 7px 8px; border: 1px solid #dfe6e4; border-radius: 5px; color: var(--ink); background: #fff; font-size: 11px; }
.channel-row input::placeholder { color: #a4adae; }
.channel-remove { flex: none; color: #b4544a; }
.add-channel-button { justify-self: start; padding: 4px 0; color: var(--teal-dark); font-size: 11px; }
.model-group { margin-top: 6px; }
.model-group:first-child { margin-top: 0; }
.model-group-title { margin: 0; padding: 3px 7px; color: #96a1a1; font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
.model-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.model-option-name { overflow-wrap: anywhere; }
.model-option-channel { flex: none; padding: 1px 5px; border-radius: 999px; color: #6d7a7c; background: #eef3f1; font-size: 9px; }
.settings-note { display: flex; align-items: flex-start; gap: 8px; margin: 16px 0; padding: 10px; border: 1px solid #e5efec; border-radius: 6px; color: #6d7a7c; background: #f7faf9; }
.settings-note p { margin: 0; font-size: 10px; line-height: 1.65; }
.note-mark { display: grid; width: 15px; height: 15px; flex: 0 0 auto; place-items: center; border: 1px solid #add0c7; border-radius: 50%; color: var(--teal); font-size: 9px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; }
.dialog-action-spacer { flex: 1; }
.clear-key-button { color: #a34f40; }
.primary-button { padding: 8px 13px; border: 1px solid var(--teal); border-radius: 6px; color: #fff; background: var(--teal); font-size: 11px; cursor: pointer; }
.primary-button:hover { background: var(--teal-dark); }
.export-button { border-color: #e3eae8; }
.export-button:hover { color: var(--teal-dark); background: #f5f8f7; }
.toast { position: fixed; z-index: 10; right: 20px; bottom: 18px; max-width: min(420px, calc(100vw - 32px)); padding: 10px 13px; border: 1px solid #dfe7e5; border-radius: 7px; color: #e9f2ef; background: #263638; box-shadow: var(--shadow); font-size: 11px; opacity: 0; pointer-events: none; transform: translateY(8px); transition: .18s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 56px 250px minmax(0, 1fr); }
  .session-sidebar { padding-inline: 13px; }
  .chat-header { padding-inline: 18px; }
  .message-list { padding-inline: 28px; }
  .composer-wrap { padding-inline: 21px; }
}
@media (max-width: 680px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .portal-rail { display: none; }
  .session-sidebar { position: fixed; z-index: 6; inset: 0 auto 0 0; width: min(304px, calc(100vw - 52px)); padding: 20px 15px 14px; box-shadow: var(--shadow); transform: translateX(-105%); transition: transform .2s ease; }
  .app-shell.is-sidebar-open .session-sidebar { transform: translateX(0); }
  .sidebar-backdrop:not([hidden]) { position: fixed; z-index: 5; inset: 0; display: block; width: 100%; height: 100%; border: 0; background: rgba(22, 34, 34, .28); }
  .mobile-menu-button { display: grid; }
  .chat-header { min-height: 60px; padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right)); }
  .chat-title-group { gap: 8px; }
  .chat-title-group, .chat-title-copy { min-width: 0; }
  .chat-title-group { flex: 1 1 auto; }
  .chat-title-copy .eyebrow { font-size: 8px; }
  .chat-title-copy h2 { max-width: 39vw; font-size: 13px; }
  .header-actions { flex: 0 0 auto; gap: 4px; }
  .model-select { min-width: 0; max-width: 142px; gap: 6px; padding: 7px; font-size: 10px; }
  .settings-button, .account-button { width: 31px; height: 31px; }
  .message-list { padding: 23px 16px 30px; }
  .message-content { font-size: 12px; }
  .message[data-role="user"] .message-content { max-width: 94%; }
  .composer-wrap { padding: 8px max(11px, env(safe-area-inset-left)) calc(11px + env(safe-area-inset-bottom)); }
  .composer-tools { gap: 2px; }
  .tool-chip { min-height: 30px; gap: 3px; padding-inline: 6px; font-size: 10px; }
  #memoryToggle span, #editPromptButton span, .export-button span { display: none; }
  .export-button { width: 30px; justify-content: center; padding-inline: 0; }
  .token-estimate { font-size: 9px; }
  .composer-caption { font-size: 8px; }
  .settings-form { padding: 19px 17px 15px; }
  .settings-dialog { max-height: 90dvh; margin-block: auto; }
}
@media (max-width: 560px) {
  .channel-row { grid-template-columns: 1fr 1fr; }
  .channel-row .channel-name { grid-column: 1 / -1; }
}
@media (max-width: 380px) {
  .chat-title-copy h2 { max-width: 25vw; }
  .model-select { max-width: 94px; }
  .field-pair { grid-template-columns: 1fr; gap: 13px; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-action-spacer { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── 会话搜索：侧边栏会话列表上方的搜索框 ── */
.conversation-search { width: 100%; min-height: 30px; flex: 0 0 auto; margin: 0 0 9px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--soft); font-size: 11px; }
.conversation-search::placeholder { color: #9aa5a6; }
.conversation-search:focus { border-color: #8ac5b9; background: #fff; }

/* ── 消息分页条：吸在消息滚动区底部 ── */
.message-pager { position: sticky; bottom: 0; z-index: 3; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 5px; padding: 7px 16px; border-top: 1px solid var(--line); background: rgba(255, 255, 255, .86); backdrop-filter: blur(6px); font-size: 11px; }
.pager-page, .pager-step, .pager-jump input { height: 26px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: #fff; font-size: 11px; cursor: pointer; }
.pager-page, .pager-step { padding: 0 8px; }
.pager-page.is-active { background: var(--teal); border-color: var(--teal); color: #fff; }
.pager-step:disabled { opacity: .4; cursor: not-allowed; }
.pager-dots { padding: 0 3px; color: var(--muted); letter-spacing: .06em; }
.pager-jump { display: inline-flex; align-items: center; gap: 5px; margin-left: 8px; color: var(--muted); }
.pager-jump input { width: 52px; padding: 0 4px; text-align: center; cursor: text; }

/* ── 浮动工具：聊天面板右下角两个小圆钮 ── */
.chat-panel { position: relative; }
.floating-tools { position: absolute; right: 18px; bottom: 132px; z-index: 4; display: flex; flex-direction: column; gap: 8px; }
.floating-button { display: grid; width: 32px; height: 32px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: #fff; box-shadow: 0 4px 12px rgba(22, 42, 40, .1); font-size: 14px; cursor: pointer; }
.floating-button:hover { border-color: var(--teal); color: var(--teal-dark); background: #f7fbf9; }
/* hidden 守卫：上面的 display 会覆盖 UA 的 [hidden] 规则，需显式还原 */
.message-pager[hidden], .floating-button[hidden] { display: none; }

/* ── 变体切换：助手消息下方的 ‹ 1 / 3 › ── */
.variant-pager { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.variant-step { width: 22px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: #fff; font-size: 11px; cursor: pointer; }
.variant-step:disabled { opacity: .4; cursor: not-allowed; }
.variant-step:hover:not(:disabled) { border-color: var(--teal); color: var(--teal-dark); }

/* ── 消息元信息：模型 + token 估算 ── */
.message-meta { margin-top: 7px; color: #9aa5a6; font-size: 10px; }

/* ── 阅读模式：隐藏消息操作行 ── */
.message-list.is-actions-hidden .message-actions { display: none; }

/* ── 角色卡 ── */
.character-actions { display: flex; grid-column: 1 / -1; gap: 4px; margin-left: 51px; }
.character-dialog .settings-form { width: min(560px, 92vw); }
.character-card-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 16px; max-height: 156px; overflow: auto; }
.character-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 180px; padding: 5px 9px 5px 5px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-size: 11px; cursor: pointer; }
.character-chip:hover { border-color: #bcd9d3; }
.character-chip.is-active { border-color: var(--teal); background: var(--teal-pale); color: var(--teal-dark); }
.character-chip-avatar { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: #eef5f3; color: var(--teal-dark); font-size: 12px; font-weight: 700; }
.character-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 提示词预设 ── */
.preset-dialog .settings-form { width: min(600px, 94vw); }
.preset-hint { margin: 0 0 12px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.preset-list { display: flex; flex-direction: column; gap: 10px; max-height: 54vh; overflow: auto; margin-bottom: 4px; }
.preset-row { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fcfdfd; }
.preset-head { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.preset-head input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--teal); cursor: pointer; }
.preset-name { flex: 1; min-width: 0; padding: 4px 7px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--ink); font-size: 12px; font-weight: 650; }
.preset-name:hover, .preset-name:focus { border-color: var(--line); background: #fff; }
.preset-remove { width: 22px; height: 22px; border: 0; border-radius: 5px; background: transparent; color: #a34f40; font-size: 14px; cursor: pointer; }
.preset-remove:hover { background: #f7e9e6; }
.preset-row textarea { width: 100%; padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: #fff; font-size: 11px; line-height: 1.6; resize: vertical; }

/* ── 对话内搜索 ── */
.search-bar { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.search-bar input { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 11px; }
.search-count { color: var(--muted); font-size: 10px; white-space: nowrap; }
.message.is-search-hit { outline: 2px solid var(--teal); outline-offset: 4px; border-radius: 6px; background: #f4fbf9; }

/* ── 记忆面板 ── */
.memory-dialog .settings-form { width: min(620px, 94vw); }
.memory-dialog select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; }

/* ── 消息渲染升级 ── */
.dialogue { color: #0d625b; }
.status-fold { margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; background: #fafcfc; }
.status-fold summary { padding: 7px 10px; color: var(--muted); font-size: 11px; cursor: pointer; }
.status-fold summary:hover { color: var(--teal-dark); }
.status-fold blockquote { margin: 0; padding: 2px 12px 10px; border-left: 2px solid var(--line); color: #5b6668; }
.code-block { position: relative; margin: 8px 0; }
.code-copy { position: absolute; top: 6px; right: 6px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--muted); font-size: 10px; cursor: pointer; opacity: 0; transition: opacity .15s ease; }
.code-block:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
.code-copy:hover { color: var(--teal-dark); border-color: #bcd9d3; }

/* ── 世界书条目列表 ── */
.worldbook-entries { display: flex; flex-direction: column; gap: 4px; margin: -6px 0 14px; }
.worldbook-row { display: flex; align-items: center; gap: 7px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fcfdfd; font-size: 11px; }
.worldbook-row.is-disabled { opacity: .55; }
.worldbook-row input[type="checkbox"] { width: 13px; height: 13px; accent-color: var(--teal); cursor: pointer; }
.worldbook-name { flex: 0 0 auto; max-width: 46%; overflow: hidden; color: var(--teal-dark); text-overflow: ellipsis; white-space: nowrap; }
.worldbook-preview { min-width: 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.worldbook-empty { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }

/* ── 预设排序按钮 ── */
.preset-move { width: 20px; height: 20px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--muted); font-size: 11px; line-height: 1; cursor: pointer; }
.preset-move:hover { border-color: var(--teal); color: var(--teal-dark); }

/* ── 音色选择 ── */
.field select { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; }

/* ── 分支树 ── */
.branch-dialog .settings-form { width: min(560px, 94vw); }
.branch-tree { display: flex; flex-direction: column; gap: 3px; max-height: 56vh; overflow: auto; }
.branch-row { display: flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--ink); font-size: 12px; text-align: left; cursor: pointer; }
.branch-row:hover { border-color: var(--line); background: var(--soft); }
.branch-mark { color: var(--teal); font-size: 10px; }
.branch-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch-meta { color: var(--muted); font-size: 10px; }

/* ── 移动端修正 ── */
[hidden] { display: none !important; }
@media (max-width: 680px) {
  .settings-dialog { width: calc(100vw - 24px); max-width: calc(100vw - 24px); }
  .model-select { max-width: 104px; }
  .chat-title-copy h2 { max-width: 24vw; }
  .chat-header { gap: 6px; }
  .header-actions { min-width: 0; }
}

@media (max-width: 680px) {
  .tool-chip { min-height: 38px; font-size: 11px; padding-inline: 8px; }
  .composer-tools { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .composer-tools::-webkit-scrollbar { display: none; }
  .token-estimate, .composer-caption { display: none; }
  .message-content { font-size: 14px; line-height: 1.8; }
  .icon-button { width: 38px; height: 38px; }
  .message-actions .message-action { min-height: 32px; }
  .floating-tools { bottom: 118px; }
  .chat-title-copy h2 { font-size: 15px; }
}

/* ── 手机端工具栏收纳 ── */
.tools-toggle, .tools-menu { display: none; }
.composer-tools { position: relative; }
@media (max-width: 680px) {
  .composer-tools > .tool-chip:not(.tools-toggle) { display: none; }
  .tools-toggle { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; font-size: 16px; }
  .tools-menu:not([hidden]) {
    position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 6;
    display: flex; flex-direction: column; min-width: 148px; padding: 5px;
    border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow);
  }
  .tools-menu button { padding: 10px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); font-size: 12px; text-align: left; }
  .tools-menu button:active { background: var(--teal-pale); }
  .message-action span { display: none; }
  .message-action { min-width: 34px; justify-content: center; padding-inline: 6px; }
  .composer-wrap { padding: 8px max(11px, env(safe-area-inset-right)) calc(11px + env(safe-area-inset-bottom)) max(11px, env(safe-area-inset-left)); }
  .message-list { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .chat-header { min-height: 46px; padding-block: 4px; }
  .composer-wrap { padding-top: 4px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .tool-chip { min-height: 32px; }
  .empty-state { margin-block: 10px; }
  .settings-dialog { max-height: 96dvh; }
  .message-list { padding-block: 14px 18px; }
}

/* ── 手机端工具栏收纳（底部弹层，避免被 overflow 裁剪） ── */
@media (max-width: 680px), (max-height: 520px) and (orientation: landscape) {
  .composer-tools { overflow: visible; }
  .composer-tools > .tool-chip:not(.tools-toggle) { display: none; }
  .tools-toggle { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; font-size: 16px; }
  .tools-menu:not([hidden]) {
    position: fixed; left: 10px; right: 10px; bottom: calc(84px + env(safe-area-inset-bottom));
    z-index: 30; display: flex; flex-direction: column; padding: 6px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: var(--shadow);
  }
  .tools-menu button { padding: 11px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); font-size: 13px; text-align: left; }
  .tools-menu button:active { background: var(--teal-pale); }
}

/* ── 战斗/感官/环境面板折叠 ── */
.panel-fold { margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; background: #fafcfc; }
.panel-fold summary { padding: 7px 10px; color: var(--muted); font-size: 11px; cursor: pointer; }
.panel-fold summary:hover { color: var(--teal-dark); }
.panel-fold .panel-body { padding: 2px 12px 10px; color: #5b6668; font-size: 12px; line-height: 1.75; }

/* ── 模型菜单里的思考开关 ── */
.model-thinking { display: flex; align-items: center; gap: 7px; padding: 7px 10px; margin: 0 4px 4px; border-bottom: 1px solid var(--line); color: var(--ink); font-size: 11px; cursor: pointer; }
.model-thinking input { width: 13px; height: 13px; accent-color: var(--teal); cursor: pointer; }
