/* ====================== 完整样式（深色适配·开关最终修复版） ====================== */
:root {
    --chat-page-bg: transparent;
    --chat-messages-bg: transparent;
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f7;
    --text-primary: #1d1d1f;
    --text-secondary: #8e8e93;
    --card-bg: #ffffff;
    --border-color: #e5e5e5;
    --nav-bg: #ffffff;
    --nav-border: #d1d1d6;
    --input-bg: rgba(255, 255, 255, 0.75);
    --overlay: rgba(0,0,0,0.5);
    --accent: #007aff;
    --btn-send-bg: transparent;
}

.dark {
    --bg-primary: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --text-primary: #f5f5f7;
    --text-secondary: #98989d;
    --card-bg: #2c2c2e;
    --border-color: #3a3a3c;
    --nav-bg: #1c1c1e;
    --nav-border: #3a3a3c;
    --input-bg: rgba(255, 255, 255, 0.08);
    --overlay: rgba(0,0,0,0.7);
    --accent: #0a84ff;
    --btn-send-bg: transparent;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: system-ui, sans-serif;
  touch-action: manipulation;
}
body {
  height: 100vh;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
}
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pages {
  flex: 1 1 0%;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.page {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  padding: 12px;
  overflow-y: auto;
  background: var(--bg-primary);
  display: none;
}
#page-chat-detail {
  display: none;
  flex-direction: column;
  padding: 0;
  background: var(--chat-page-bg);
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  margin-bottom: 8px;
}
.header-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}
.btn {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}
.btn-green { background: #34c759; }
.btn-red { background: #ff3b30; }
.btn-back {
  background: transparent;
  color: var(--accent);
  border: none;
  font-size: 20px;
  cursor: pointer;
}
.btn-close {
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #ff3b30;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.btn-close:hover {
  color: #c00;
  background: #ffe5e5;
  transform: scale(1.05);
}
.search-box {
  margin-bottom: 12px;
  padding: 8px;
  background: var(--card-bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-color);
}
.search-box input {
  flex: 1;
  border: none;
  padding: 8px;
  font-size: 16px;
  outline: none;
  background: transparent;
  color: var(--text-primary);
}
.item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 14px;
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 2px #00000008;
  position: relative;
  cursor: pointer;
}
.item-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: var(--bg-secondary);
  overflow: hidden;
  flex-shrink: 0;
}
.item-icon img { width: 100%; height: 100%; object-fit: cover; }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 17px; font-weight: 600; margin-bottom: 2px; color: var(--text-primary); }
#chat-list .item .item-title { text-align: center; }
.item-desc {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-actions {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
}
.menu-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}
.menu-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--overlay);
  min-width: 140px;
  z-index: 20;
  display: none;
}
.menu-dropdown a {
  display: block;
  padding: 10px 16px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.menu-dropdown a:hover { background: var(--bg-secondary); }
.nav {
  height: 60px;
  background: var(--nav-bg);
  border-top: 1px solid var(--nav-border);
  display: flex;
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 22px; margin-bottom: 2px; }
.nav-text { font-size: 12px; }
.chat-header {
  padding: 12px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.chat-back {
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  z-index: 1;
  color: var(--text-primary);
}
.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  overflow: hidden;
  z-index: 1;
  flex-shrink: 0;
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
  margin-left: 10px;
  margin-right: 8px;
  color: var(--text-primary);
}
.chat-messages {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--chat-messages-bg, transparent);
}
.msg {
  position: relative;
  max-width: 85%;
  display: flex;
  flex-direction: column;
  margin-bottom: 4px;
  overflow: visible;
}
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg .bubble {
  display: inline-block;
  padding: 10px 12px;
  border-radius: 16px;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
  position: relative;
}

/* ===== 用户气泡：蓝底黑字（不变） ===== */
.msg.user .bubble {
  background: #007aff;
  color: #000000;
}

/* ===== AI气泡：跟随深色 ===== */
.msg.assistant .bubble {
  background: var(--card-bg, #ffffff);
  color: var(--text-primary, #000000);
}

.msg-info-bar {
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.msg-info-menu-btn {
  background: none;
  border: none;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  margin-left: 4px;
}
.msg-menu-dropdown {
  position: fixed;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--overlay);
  z-index: 1000;
  min-width: 160px;
}
.msg-menu-dropdown a {
  display: block;
  padding: 10px 16px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.msg-menu-dropdown a:hover { background: var(--bg-secondary); }

/* ===== 输入区域 ===== */
.input-area {
  padding: 8px 12px;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.global-menu-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  border-radius: 12px;
  color: var(--accent);
}
.input-bar { flex: 1; display: flex; gap: 8px; align-items: flex-end; }

.input-bar textarea {
  flex: 1;
  padding: 0 44px 0 14px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  resize: none;
  font-family: system-ui, sans-serif;
  font-size: 16px;
  line-height: 40px;
  max-height: 200px;
  overflow-y: hidden;
  min-height: 40px;
  height: 40px;
  background: var(--input-bg, #ffffff);
  color: var(--text-primary);
}

.global-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 0;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--overlay);
  z-index: 999;
  display: none;
  width: 200px;
}
.global-menu a {
  display: block;
  padding: 12px 16px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.global-menu a:hover { background: var(--bg-secondary); }

/* ===== 表单和弹窗组件 ===== */
.form {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
  display: none;
}
.form-item { margin-bottom: 16px; }
.form-item label { display: block; margin-bottom: 8px; font-size: 15px; color: var(--text-primary); }
.form-item input,
.form-item textarea,
.form-item select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-secondary);
  font-size: 16px;
  color: var(--text-primary);
}
.form-item textarea { resize: vertical; height: 100px; }
.modal {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay);
  display: none;
  place-items: center;
  z-index: 999;
}
.modal-box {
  background: var(--card-bg);
  border-radius: 16px;
  width: 95vw;
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  color: var(--text-primary);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-title { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.modal-body { flex: 1; overflow-y: auto; }
.modal-footer { margin-top: 16px; display: flex; justify-content: flex-end; gap: 12px; }
.modal-footer button { padding: 8px 16px; border-radius: 8px; }

.debug-ball {
  position: fixed;
  right: 20px;
  bottom: 80px;
  width: 50px;
  height: 50px;
  background: #ff3b30;
  color: white;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 22px;
  cursor: pointer;
  z-index: 9999;
}
.debug-panel {
  position: fixed;
  right: 20px;
  bottom: 150px;
  width: 320px;
  height: 400px;
  background: #1c1c1e;
  color: #00ff00;
  border-radius: 12px;
  padding: 10px;
  font-size: 12px;
  font-family: monospace;
  overflow-y: auto;
  z-index: 9998;
  display: none;
}
.debug-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #333;
}
.debug-copy-btn {
  background: #2c2c2e;
  border: none;
  color: #0f0;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}
.preset-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
}
.preset-top-bar h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.preset-btn-group { display: flex; gap: 12px; }
.preset-item-row {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.preset-drag {
  color: #c7c7cc;
  font-size: 20px;
  cursor: grab;
  min-width: 24px;
  text-align: center;
}
.preset-item-name {
  flex: 1;
  font-size: 16px;
  word-break: break-word;
  min-width: 0;
  color: var(--text-primary);
}
.preset-item-edit {
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
  min-width: 24px;
  text-align: center;
}
.preset-item-delete {
  color: #ff3b30;
  font-size: 20px;
  cursor: pointer;
  min-width: 24px;
  text-align: center;
}
.preset-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}
#preset-items-container {
  max-height: calc(95vh - 180px);
  overflow-y: auto;
  padding-right: 4px;
  width: 100%;
}
.import-upload-area {
  margin: 16px 0;
  padding: 24px;
  border: 2px dashed #ccc;
  border-radius: 12px;
  text-align: center;
  display: none;
}
.upload-icon {
  font-size: 48px;
  color: var(--accent);
  margin-bottom: 12px;
}
.upload-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.upload-desc {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}
.upload-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.upload-btn {
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 500;
  color: white;
  cursor: pointer;
}
.upload-btn.file { background: var(--accent); }
.upload-btn.album { background: #34c759; }
.upload-format { font-size: 14px; color: #999; }
.single-preview { display: none; margin-top: 20px; }
.function-tip {
  background: #fff9cc;
  color: #b88200;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  margin: 12px 0;
  display: inline-block;
}
.avatar-container { text-align: center; margin: 16px 0; }
.avatar {
  width: 180px;
  height: 180px;
  border-radius: 16px;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px #00000008;
}
.card-worldbook { background: #f8f0fc; border: 1px solid #e9d5ff; }
.card-script { background: #eff6ff; border: 1px solid #bfdbfe; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text-primary); }
.card-subtitle { font-size: 14px; color: var(--text-secondary); margin-bottom: 8px; }
.card-action { font-size: 14px; color: var(--accent); cursor: pointer; }
.preview-footer { display: flex; gap: 12px; margin-top: 20px; }
.btn-save { flex: 2; padding: 14px; background: var(--accent); border: none; border-radius: 12px; color: white; font-size: 18px; font-weight: 500; cursor: pointer; }
.btn-clear { flex: 1; padding: 14px; background: var(--bg-secondary); border: none; border-radius: 12px; color: var(--text-primary); font-size: 18px; font-weight: 500; cursor: pointer; }
.batch-item { padding: 12px; border-radius: 12px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.batch-item.success { background: #e8f5e9; border: 1px solid #c8e6c9; }
.batch-item.error { background: #ffebee; border: 1px solid #ffcdd2; }
.batch-dot { width: 10px; height: 10px; border-radius: 50%; }
.batch-dot.success { background: #4caf50; }
.batch-dot.error { background: #f44336; }
.batch-info { flex: 1; }
.batch-name { font-size: 16px; font-weight: 500; margin-bottom: 4px; color: var(--text-primary); }
.batch-error { font-size: 14px; color: #d32f2f; }
.batch-tags { display: flex; gap: 6px; margin-top: 4px; }
.batch-tag { padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.tag-world { background: #f3e5f5; color: #9c27b0; }
.tag-script { background: #e3f2fd; color: #1976d2; }
.batch-check { color: #4caf50; font-size: 20px; }
.batch-close { color: #f44330; font-size: 20px; cursor: pointer; }
.modal-buttons { display: flex; gap: 12px; margin-top: 20px; }
.modal-buttons .btn { flex: 1; padding: 12px; border-radius: 12px; font-size: 16px; }
.empty-state { text-align: center; padding: 40px 12px; color: var(--text-secondary); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 17px; margin-bottom: 16px; }
.expandable-content { margin-top: 12px; padding: 12px; background: var(--card-bg); border-radius: 8px; border: 1px solid var(--border-color); max-height: 300px; overflow-y: auto; }
.entry-item { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f0; }
.entry-item:last-child { border-bottom: none; }
.entry-title { font-weight: 600; color: #7e22ce; margin-bottom: 4px; }
.entry-keywords { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.entry-content { font-size: 13px; color: var(--text-primary); line-height: 1.4; }
.rule-item { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #e0e7ff; }
.rule-item:last-child { border-bottom: none; }
.rule-name { font-weight: 600; color: #1d4ed8; margin-bottom: 4px; }
.rule-pattern { font-size: 12px; color: var(--text-secondary); font-family: monospace; margin-bottom: 4px; }
.rule-replace { font-size: 12px; color: var(--text-primary); font-family: monospace; }
.item-right { display: flex; flex-direction: column; align-items: flex-end; margin-left: auto; font-size: 12px; color: var(--text-secondary); }
.item-time { margin-bottom: 4px; }
.item-info { display: flex; align-items: center; gap: 6px; }
.item-menu-btn { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-secondary); padding: 0 4px; }
.chat-menu-dropdown { position: absolute; right: 0; top: 100%; background: var(--card-bg); border-radius: 12px; box-shadow: 0 4px 12px var(--overlay); display: none; z-index: 20; min-width: 100px; }
.chat-menu-dropdown a { display: block; padding: 8px 16px; color: var(--text-primary); text-decoration: none; font-size: 14px; cursor: pointer; }
.chat-menu-dropdown a:hover { background: var(--bg-secondary); }
.inline-edit-area { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.inline-edit-textarea { width: 100%; padding: 8px; border-radius: 12px; border: 1px solid #ccc; font-size: 14px; font-family: inherit; resize: vertical; background: var(--card-bg); color: var(--text-primary); }
.inline-edit-buttons { display: flex; gap: 8px; justify-content: flex-end; }
.inline-edit-buttons button { padding: 4px 12px; border-radius: 16px; border: none; cursor: pointer; font-size: 14px; }
.inline-edit-save { background: #34c759; color: white; }
.inline-edit-cancel { background: var(--bg-secondary); color: var(--text-primary); }
.import-settings-panel { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border-color); text-align: left; }
.import-settings-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; color: var(--text-primary); }
.import-setting-row { margin-bottom: 12px; }
.import-setting-label { font-size: 14px; font-weight: 500; display: block; margin-bottom: 6px; color: var(--text-primary); }
.import-setting-select { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--card-bg); font-size: 14px; color: var(--text-primary); }
.import-setting-checkbox { display: flex; align-items: center; gap: 8px; color: var(--text-primary); }
.import-setting-checkbox input { width: 18px; height: 18px; }
.import-setting-desc { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.editable-list-panel { width: 90%; max-width: 600px; background: var(--card-bg); border-radius: 16px; padding: 20px; max-height: 85vh; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.panel-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.collection-name { font-size: 24px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.panel-actions { display: flex; gap: 8px; flex-wrap: nowrap; align-items: center; }
.panel-tip { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 14px; }
.tip-icon { font-size: 18px; }
.editable-list { display: flex; flex-direction: column; gap: 12px; max-height: 50vh; overflow-y: auto; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--bg-secondary); }
.drag-handle { font-size: 20px; color: #ccc; cursor: grab; }
.item-name { flex: 1; font-size: 16px; color: var(--text-primary); word-break: break-word; }
.toggle-small { position: relative; width: 48px; height: 24px; flex-shrink: 0; }
.toggle-small input { opacity: 0; width: 0; height: 0; }
.toggle-slider-small { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 24px; transition: 0.4s; }
.toggle-slider-small:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: 0.4s; }
input:checked + .toggle-slider-small { background-color: var(--accent); }
input:checked + .toggle-slider-small:before { transform: translateX(24px); }
.item-edit-btn, .item-delete-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-secondary); padding: 4px; }
.item-edit-btn:hover { color: var(--accent); }
.item-delete-btn:hover { color: #ff3b30; }
.checkbox-group, .radio-group { display: flex; gap: 16px; margin-top: 8px; }
.checkbox-item, .radio-item { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text-primary); }
.checkbox-item input, .radio-item input { width: 18px; height: 18px; margin: 0; cursor: pointer; }
.checkbox-item span, .radio-item span { font-size: 16px; color: var(--text-primary); }
.form-input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 16px; background: var(--card-bg); box-sizing: border-box; color: var(--text-primary); }
.form-input:focus { outline: none; border-color: var(--accent); }
.form-tip { margin-top: 6px; font-size: 12px; color: var(--text-secondary); }
.btn-cancel { background: var(--bg-secondary); color: var(--text-primary); }
.btn-cancel:hover { background: #e5e5ea; }
.btn-lock { background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px; margin-left: 8px; color: var(--text-primary); }
.btn-lock:hover { opacity: 0.7; }
.drag-handle { cursor: default; }
.list-item[draggable="true"] .drag-handle { cursor: grab; }
.preset-item-row[draggable="true"] .preset-drag { cursor: grab; }
.list-item.dragging, .preset-item-row.dragging { opacity: 0.5; }
.panel-actions .btn-lock { margin-left: auto; }
.list-item, .preset-item-row { padding: 8px 12px; margin: 0; min-height: 40px; box-sizing: border-box; border-bottom: 1px solid var(--border-color); }
.drop-placeholder { background: transparent; margin: 3px 0; padding: 0; border: none; box-sizing: border-box; transition: all 0.2s ease; }
.sortable-ghost { opacity: 0; background: transparent; }
.sortable-chosen { cursor: grabbing; }
.sortable-drag { opacity: 0.5; cursor: grabbing; }
.sortable-fallback { cursor: grabbing; }
.msg-delete-checkbox { margin-right: 8px; width: 20px; height: 20px; cursor: pointer; flex-shrink: 0; }
.msg { display: flex; align-items: flex-start; }
.msg.user .msg-delete-checkbox { order: -1; }
.msg.assistant .msg-delete-checkbox { order: 1; }
.edit-bubble { padding: 0; background: transparent; }
.edit-textarea { width: 100%; border: none; outline: none; resize: none; font-family: inherit; font-size: inherit; line-height: inherit; background: transparent; color: inherit; overflow-y: auto; box-sizing: border-box; }
.edit-textarea:focus { outline: none; }
.custom-dialog { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; z-index: 10000; }
.dialog-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: var(--overlay); }
.dialog-container { position: relative; background: var(--card-bg); border-radius: 12px; width: 280px; max-width: 90%; padding: 20px; box-shadow: 0 4px 20px var(--overlay); text-align: center; }
.dialog-header { margin-bottom: 12px; }
.dialog-title { font-size: 18px; font-weight: 600; color: var(--text-primary); }
.dialog-content { font-size: 15px; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.4; word-break: break-word; }
.dialog-input-wrapper { margin-bottom: 20px; }
.dialog-input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: 8px; font-size: 16px; background: var(--bg-secondary); box-sizing: border-box; color: var(--text-primary); }
.dialog-input:focus { outline: none; border-color: var(--accent); }
.dialog-buttons { display: flex; gap: 12px; justify-content: center; }
.dialog-btn { flex: 1; padding: 10px 0; border: none; border-radius: 8px; font-size: 16px; font-weight: 500; cursor: pointer; transition: opacity 0.2s; }
.dialog-btn-cancel { background: var(--bg-secondary); color: var(--text-primary); }
.dialog-btn-confirm { background: var(--accent); color: white; }
.dialog-btn:hover { opacity: 0.8; }

/* ===== 气泡内容防溢出 ===== */
#chat-messages .bubble > * {
  max-width: 100%;
  word-break: break-word;
  box-sizing: border-box;
}
#chat-messages .bubble > iframe {
  max-width: 100%;
  box-sizing: border-box;
}
#chat-messages .msg .bubble {
  overflow-wrap: anywhere;
  word-wrap: break-word;
  max-width: 100%;
}

.inline-edit-textarea { width: 100%; padding: 10px 12px; border: none; border-radius: 16px; font-size: inherit; font-family: inherit; resize: vertical; background-color: #007aff; color: white; min-height: 80px; max-height: 300px; overflow-y: hidden; box-sizing: border-box; }
.msg.assistant .inline-edit-textarea { background-color: var(--card-bg); color: var(--text-primary); }
.inline-edit-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.inline-edit-save { background: #34c759; color: white; border: none; border-radius: 16px; padding: 4px 12px; cursor: pointer; font-size: 14px; }
.inline-edit-cancel { background: var(--bg-secondary); color: var(--text-primary); border: none; border-radius: 16px; padding: 4px 12px; cursor: pointer; font-size: 14px; }
.msg.assistant .thinking-text { color: var(--text-secondary); font-style: italic; }
#chat-messages iframe { width: 100%; border: none; background: var(--card-bg); }
#chat-messages .msg .bubble { overflow-wrap: anywhere; word-wrap: break-word; max-width: 100%; }
.color-picker-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--overlay); display: none; align-items: center; justify-content: center; z-index: 10000; }
.color-picker { background: var(--card-bg); padding: 20px; border-radius: 16px; width: 320px; }
.color-preview { width: 100%; height: 40px; border-radius: 8px; margin-bottom: 12px; background: #1a73e8; }
.hue-slider { width: 100%; height: 12px; border-radius: 6px; background: linear-gradient(to right, red, yellow, lime, cyan, blue, magenta, red); margin: 12px 0; position: relative; }
.hue-dot { position: absolute; top: -4px; width: 20px; height: 20px; border-radius: 50%; background: white; border: 2px solid #333; }
.sv-panel { width: 100%; height: 200px; border-radius: 8px; background: linear-gradient(to bottom, transparent, black), linear-gradient(to right, white, red); position: relative; }
.sv-dot { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: white; border: 2px solid #333; transform: translate(-50%, -50%); }
.color-inputs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0; }
.input-group { text-align: center; }
.input-group input { width: 100%; padding: 4px; border: 1px solid var(--border-color); border-radius: 4px; text-align: center; font-size: 12px; color: var(--text-primary); }
.input-group label { font-size: 10px; color: var(--text-secondary); }
.picker-buttons { display: flex; gap: 12px; margin-top: 16px; }
.picker-buttons button { flex: 1; padding: 10px; border: none; border-radius: 8px; cursor: pointer; }
.picker-confirm { background: var(--accent); color: white; }
.picker-cancel { background: var(--bg-secondary); color: var(--text-primary); }
.color-trigger { width: 60px; height: 36px; border-radius: 6px; border: 1px solid var(--border-color); cursor: pointer; }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 6px; background: var(--bg-secondary); border-radius: 3px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); }
.setting-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-primary); }
.setting-tip { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }
.css-textarea { width: 100%; height: 120px; border: 1px solid var(--border-color); border-radius: 8px; padding: 8px; font-size: 12px; resize: none; font-family: monospace; background: var(--bg-secondary); color: var(--text-primary); }
.css-select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border-color); margin-bottom: 8px; background: var(--card-bg); color: var(--text-primary); }
.apply-css-btn, .preview-btn { background: var(--accent); color: white; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; margin-top: 4px; }
.css-preview-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--overlay); display: none; align-items: center; justify-content: center; z-index: 99999; }
.css-preview-modal { width: 420px; height: 320px; padding: 24px; border-radius: 16px; position: relative; box-shadow: 0 8px 24px var(--overlay); overflow-y: auto; background: var(--card-bg); }
.preview-close { position: absolute; top: 12px; right: 16px; width: 30px; height: 30px; background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; cursor: pointer; z-index: 999999; color: var(--text-primary); }
.chat-settings-btn { background: none; border: none; font-size: 20px; cursor: pointer; margin-left: auto; margin-right: 8px; z-index: 2; padding: 4px 6px; line-height: 1; color: var(--accent); }
.char-virtual-item { box-sizing: border-box; padding: 0; }
.gallery-char-card { width: 100%; height: 100%; border-radius: 12px; overflow: hidden; position: relative; background: #1c1c1e; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.gallery-char-card:active { background-color: transparent; }
.gallery-char-img-wrap { width: 100%; height: 100%; position: relative; pointer-events: none; }
.gallery-char-img { width: 100%; height: 100%; background-size: cover; background-position: center top; background-repeat: no-repeat; }
.gallery-char-placeholder { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 48px; color: #8e8e93; }
.gallery-char-img-wrap::after { content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 65%; background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%); pointer-events: none; z-index: 2; }
.gallery-char-name { position: absolute; bottom: 113px; left: 10px; right: 10px; font-size: 14px; font-weight: 600; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; z-index: 3; pointer-events: none; }
.gallery-char-desc { position: absolute; left: 10px; right: 10px; top: calc(100% - 111px); bottom: 10px; overflow: hidden; white-space: normal; line-height: 1.5; font-size: 11px; color: rgba(255,255,255,0.9); text-shadow: 0 1px 2px rgba(0,0,0,0.6); z-index: 3; pointer-events: none; }
.gallery-char-menu-btn { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); border: none; color: #fff; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 5; pointer-events: auto; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.item { -webkit-tap-highlight-color: transparent; }
.item:active { background-color: transparent; }
#globalCharMenu { z-index: 9999; }
#char-items { position: relative; width: 100%; }
.char-virtual-item { width: 100%; box-sizing: border-box; }

/* ★ 角色卡搜索栏——透明底 */
.char-search-area { display: flex; align-items: center; gap: 0; background: transparent; border: none; border-radius: 0; padding: 0; margin: 4px 12px; }
.char-search-area .search-box { flex: 1; min-width: 0; padding: 6px 8px; display: flex; align-items: center; background: var(--card-bg, #fff); border: 1px solid var(--border-color, #e5e5e5); border-radius: 8px; margin-bottom: 0; }
#char-view-toggle { width: 36px; height: 36px; flex-shrink: 0; border: none; background: transparent; font-size: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-primary, #333); margin-left: 4px; }

.chat-list-inner > .header, .char-page-inner > .header, .char-page-inner > .char-search-area, .setting-inner > .header, .preset-inner > .preset-top-bar, .regex-inner > .header, .world-inner > .header { flex-shrink: 0; }
.chat-list-inner > .scroll-area, .char-page-inner > .scroll-area, .setting-inner > .scroll-area, .preset-inner > .scroll-area, .regex-inner > .scroll-area, .world-inner > .scroll-area { flex: 1; overflow-y: auto; min-height: 0; }
.preview-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 9999; display: flex; align-items: center; justify-content: center; }
.preview-content { background: var(--card-bg); width: 90%; max-width: 400px; max-height: 80vh; border-radius: 16px; display: flex; flex-direction: column; overflow: hidden; }
.preview-scroll { flex: 1 1 auto; overflow-y: auto; padding: 24px 24px 0 24px; min-height: 0; }
.preview-buttons { flex-shrink: 0; display: flex; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--border-color); background: var(--card-bg); }
.preview-buttons button { flex: 1; padding: 14px; border: none; border-radius: 12px; font-size: 16px; cursor: pointer; }
.preview-btn-cancel { background: var(--bg-secondary); color: var(--text-primary); }
.preview-btn-chat { background: var(--accent); color: white; font-weight: 500; }
.preview-avatar-wrap { display: flex; justify-content: center; margin-bottom: 16px; }
.preview-modal-avatar { width: 120px; height: 160px; border-radius: 12px; object-fit: cover; display: inline-block; }
.preview-alt-section { margin-bottom: 16px; background: var(--bg-secondary); border-radius: 12px; padding: 12px; }
.preview-alt-toggle { font-size: 14px; color: var(--accent); cursor: pointer; font-weight: 500; margin-bottom: 8px; }
.preview-alt-list { display: flex; flex-direction: column; gap: 8px; }
.preview-alt-item { display: flex; gap: 8px; font-size: 13px; color: var(--text-primary); line-height: 1.5; }
.preview-alt-index { color: var(--text-secondary); flex-shrink: 0; font-weight: 500; }
.preview-alt-text { word-break: break-word; }

/* ===== 输入包裹层（按钮居中） ===== */
.input-wrapper { position: relative; flex: 1; display: flex; align-items: center; }

#msg-input { padding-right: 44px; }

.send-icon, .pause-icon {
  display: none;
  pointer-events: none;
  max-width: 100%;
  max-height: 100%;
  background-color: transparent;
}

#send-btn:active, #send-btn:focus-visible {
  background: transparent;
  transform: scale(0.95);
}

#send-btn {
    background-color: var(--btn-send-bg);
}

.send-icon { color: #fff; font-size: 22px; line-height: 1; }
.pause-icon { width: 14px; height: 14px; background: #fff; border-radius: 2px; }
#send-btn.btn-send .send-icon { display: block; }
#send-btn.btn-pause .pause-icon { display: block; }
#model-btn.btn-ai-model { height: 40px; padding: 0 16px; border: none; border-radius: 24px; background: #1677ff; box-shadow: 0 2px 6px rgba(22,119,255,0.3); color: #fff; font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.import-header { position: relative; }
.import-header .btn-close { position: absolute; top: 0; right: 0; }
.msg .bubble .get-card-btn { display: inline-block; margin-top: 8px; padding: 6px 14px; background: var(--accent); color: #fff; border-radius: 16px; cursor: pointer; font-size: 13px; }

/* ========== 移动端全屏适配 ========== */
html, body { height: 100dvh; overscroll-behavior: none; }
.app { height: 100%; overflow: hidden; }
.page { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
@supports not (padding-bottom: env(safe-area-inset-bottom)) { .page { padding-bottom: 60px; } }

/* ========== 气泡自适应宽度 ========== */
.msg.assistant .bubble {
    max-width: 85%;
    width: fit-content;
    margin: 0 auto;
}
@media (min-width: 600px) { .msg.assistant .bubble { max-width: 85%; } }
@media (min-width: 900px) { .msg.assistant .bubble { max-width: 75%; } }
@media (min-width: 1200px) { .msg.assistant .bubble { max-width: 700px; } }

/* ========== 气泡内文字自适应 ========== */
.msg-text-content {
    font-size: var(--chat-font-size, 15px);
    line-height: 1.6;
}
@media (min-width: 768px) {
    .msg-text-content {
        font-size: var(--chat-font-size, 0.9rem);
        line-height: 1.65;
    }
}
@media (min-width: 1024px) {
    .msg-text-content {
        font-size: var(--chat-font-size, 1rem);
        line-height: 1.7;
    }
}

/* ========== 角色卡背景图（修复背景挤压） ========== */
#page-chat-detail.has-char-bg {
    background-size: cover;
    background-position: bottom center;
    background-repeat: no-repeat;
}

/* ========== 三端适配：大屏自动放大 UI ========== */
@media (min-width: 768px) {
  :root { font-size: 18px; }
  .btn { padding: 12px 18px; }
  .search-box input { font-size: 18px; }
  .item { padding: 18px; }
  .item-icon { width: 48px; height: 48px; font-size: 22px; }
  .item-title { font-size: 18px; }
  .item-desc { font-size: 14px; }
  .nav { height: 70px; }
  .nav-icon { font-size: 26px; }
  .nav-text { font-size: 14px; }
  .chat-messages { padding: 16px; }
  .msg .bubble { padding: 12px 16px; }
  .input-bar textarea { font-size: 1rem; padding: 12px 16px; min-height: 48px; }
  .input-bar button { height: 48px; }
  .modal-box { padding: 24px; }
  .modal-title { font-size: 22px; }
}

@media (min-width: 1024px) {
  :root { font-size: 20px; }
  .page { padding: 20px; }
  .header { margin-bottom: 16px; }
  .btn { padding: 14px 22px; }
  .item { padding: 22px; }
  .item-icon { width: 56px; height: 56px; font-size: 26px; }
  .item-title { font-size: 20px; }
  .item-desc { font-size: 15px; }
  .msg .bubble { padding: 14px 20px; }
  .input-area { padding: 12px 20px; }
  .input-bar textarea { font-size: 1.1rem; padding: 14px 18px; }
  .input-bar button { height: 52px; }
  .modal-box { max-width: 500px; padding: 28px; }
  .modal-title { font-size: 24px; }
  .nav { height: 80px; }
  .nav-icon { font-size: 30px; }
  .nav-text { font-size: 16px; }
}

/* ========== 聊天气泡内折叠面板美化 ========== */
.msg-text-content details {
    margin: 8px 0;
    border: 1px solid rgba(128,128,128,0.2);
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0,0,0,0.015);
}
.msg-text-content summary {
    padding: 10px 14px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    background: rgba(0,0,0,0.03);
    border-bottom: 1px solid rgba(128,128,128,0.12);
    color: var(--text-primary);
}
.msg-text-content summary:hover {
    background: rgba(0,0,0,0.06);
}
.msg-text-content pre,
.msg-text-content code {
    background: rgba(0,0,0,0.03);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
}

/* ========== 快捷格式按钮 {} ========== */
#page-chat-detail .input-bar .input-wrapper #quickBtn,
#page-chat-detail .input-bar .input-wrapper .quick-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}
#page-chat-detail .input-bar .input-wrapper #quickBtn:hover,
#page-chat-detail .input-bar .input-wrapper .quick-btn:hover {
  color: #ff477e;
  background: transparent;
}

/* 弹出菜单 */
.popup-menu {
    position: absolute;
    bottom: 75px;
    width: 160px;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 -2px 10px var(--overlay);
    display: none;
    z-index: 999;
    max-height: 300px;
    overflow-y: auto;
}
.popup-menu.show {
    display: block;
}
.popup-menu .menu-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-primary);
}
.popup-menu .menu-item span {
    color: var(--text-secondary);
    font-size: 13px;
}
.popup-menu .menu-item:hover {
    background: var(--bg-secondary);
}

/* ===== 设置页样式 ===== */
.setting-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.setting-item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.setting-item:active {
  opacity: 0.6;
}

.setting-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.setting-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.setting-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.setting-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.section-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 16px 0 8px 4px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.more-section {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  margin-top: 12px;
}
.more-section .section-label {
  margin-top: 0;
  margin-bottom: 12px;
}

.setting-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.setting-card {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 12px;
  background: transparent;
}
.setting-card .setting-icon {
  margin-right: 0;
  margin-bottom: 8px;
}
.setting-card .setting-body {
  text-align: center;
}

/* ==================== 开关样式（全局最终版） ==================== */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 48px;
  height: 24px;
  flex-shrink: 0;
  vertical-align: middle;
  cursor: pointer;
  overflow: hidden;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.switch .slider {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #ccc;
  border-radius: 24px;
  transition: background 0.2s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  height: 24px;
  width: 24px;
  left: 0;
  top: 0;
  background: #fff;
  border-radius: 50%;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  box-sizing: border-box;
}
.switch input:checked + .slider {
  background: var(--accent);
}
.switch input:checked + .slider::before {
  left: 24px;
}

/* 深色模式下设置卡保持透明 */
.dark .setting-card {
    background: transparent;
}

/* 深色模式下去除按钮图标白底 */
.dark #send-btn .pause-icon,
.dark #send-btn .send-icon {
    background-color: transparent;
    mix-blend-mode: multiply;
    filter: brightness(1.15);
}