/* ===== 橘子互动 样式（纯聊天版） ===== */

* { box-sizing: border-box; }
html, body { height: 100%; }

:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #98a0aa;
  --border: #e4e6ea;
  --hover: #f0f2f5;
  --accent: #ff7a00;
  --accent-soft: #fff1e2;
  --user-bubble: #e8f0fe;
  --code-bg: #f6f6f7;
  --code-text: #c7254e;
  --shadow: rgba(31, 35, 41, 0.08);
}
:root[data-theme="dark"] {
  --bg: #1b1d22;
  --panel: #212327;
  --text: #e8eaed;
  --text-2: #b0b6bd;
  --text-3: #7f858d;
  --border: #33363d;
  --hover: #2a2d33;
  --accent: #ff9432;
  --accent-soft: rgba(255, 148, 50, 0.13);
  --user-bubble: #2f3b52;
  --code-bg: #2a2d33;
  --code-text: #f0a35e;
  --shadow: rgba(0, 0, 0, 0.35);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

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

#app { display: flex; height: 100vh; }

/* ===== 侧边栏 ===== */
#sidebar {
  width: 264px; flex: none;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 2px 8px; }
.brand .logo { font-size: 24px; line-height: 1; }
.brand-name { font-size: 17px; font-weight: 700; }

.new-chat {
  width: 100%; padding: 10px;
  background: var(--accent-soft); color: var(--accent);
  border: none; border-radius: 12px;
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer;
}
.new-chat:hover { filter: brightness(0.97); }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; border-radius: 10px;
  font-size: 14px; color: var(--text-2);
  cursor: pointer; user-select: none;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.chat-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { flex: none; font-size: 11px; color: var(--text-3); }
.chat-del {
  flex: none; opacity: 0;
  background: none; border: none; font-size: 13px;
  cursor: pointer; padding: 2px;
}
.chat-item:hover .chat-del { opacity: 0.75; }
.chat-del:hover { opacity: 1 !important; }
.chat-del.confirm {
  opacity: 1 !important;
  background: #e5484d; color: #fff;
  border-radius: 6px; padding: 3px 9px;
  font-size: 12px; font-family: inherit;
}
@media (hover: none) { .chat-del { opacity: 0.65; } }
.empty-hint { color: var(--text-3); font-size: 13px; text-align: center; padding: 24px 8px; }

.sidebar-footer {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--border); padding-top: 10px;
}
.account-btn {
  flex: 1; min-width: 0; text-align: left;
  background: none; border: none; cursor: pointer;
  font-size: 14px; color: var(--text-2); padding: 8px 10px; border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: inherit;
}
.account-btn:hover { background: var(--hover); }
.account-btn.logged { color: var(--accent); font-weight: 600; }
.footer-actions { display: flex; flex: none; }

.login-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text-2); cursor: pointer;
  font-size: 14px; font-family: inherit;
}
.tab.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.icon-btn {
  background: none; border: none; cursor: pointer;
  font-size: 16px; padding: 8px; border-radius: 8px;
  color: var(--text-2); line-height: 1;
}
.icon-btn:hover { background: var(--hover); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== 主区域 ===== */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

#topbar {
  height: 56px; flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; position: relative; z-index: 5;
}
.topbar-spacer { flex: 1; }

.model-select-wrap { position: relative; }
.model-select {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 12px;
  font-size: 14px; font-weight: 500; color: var(--text);
  cursor: pointer; font-family: inherit;
}
.model-select:hover { border-color: var(--text-3); }
.caret { font-size: 10px; color: var(--text-3); }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; width: 250px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 24px var(--shadow);
  padding: 6px; z-index: 50;
}
.menu-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.menu-item:hover { background: var(--hover); }
.menu-item.selected .mi-title::after { content: "✓"; float: right; color: var(--accent); }
.mi-title { font-size: 14px; font-weight: 600; }
.mi-desc { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ===== 消息区 ===== */
#messages { flex: 1; overflow-y: auto; padding: 8px 16px 12px; }
.msg, .welcome { max-width: 768px; margin: 0 auto; }

.msg { display: flex; gap: 12px; padding: 14px 0; }
.avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  background: var(--accent-soft); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.msg .body { flex: 1; min-width: 0; }

.msg.user { flex-direction: column; align-items: flex-end; gap: 4px; }
.bubble {
  max-width: 78%;
  background: var(--user-bubble); color: var(--text);
  padding: 10px 14px; border-radius: 14px 14px 4px 14px;
  white-space: pre-wrap; word-break: break-word;
  font-size: 15px; line-height: 1.6;
}

/* Markdown 正文 */
.md-body { font-size: 15px; line-height: 1.75; word-break: break-word; }
.md-body p { margin: 0 0 10px; }
.md-body p:last-child { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 { margin: 18px 0 8px; line-height: 1.4; }
.md-body h1 { font-size: 20px; } .md-body h2 { font-size: 18px; } .md-body h3 { font-size: 16px; }
.md-body ul, .md-body ol { padding-left: 22px; margin: 0 0 10px; }
.md-body li { margin: 4px 0; }
.md-body code {
  background: var(--code-bg); color: var(--code-text);
  padding: 2px 6px; border-radius: 4px;
  font-size: 13px; font-family: ui-monospace, Consolas, "Courier New", monospace;
}
.md-body pre.code-block {
  margin: 12px 0; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: #0d1117;
}
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  background: #24292e; color: #8b949e; font-size: 12px;
  padding: 6px 12px; border-bottom: 1px solid #3a3f46;
  font-family: ui-monospace, Consolas, "Courier New", monospace;
}
.code-copy {
  background: none; border: 1px solid #8b949e; color: #c9d1d9;
  border-radius: 6px; padding: 2px 10px; cursor: pointer; font-size: 12px;
}
.code-copy:hover { background: #33383f; }
.md-body pre code {
  display: block; background: transparent; color: #e6edf3;
  padding: 12px 14px; overflow-x: auto;
  font-size: 13px; line-height: 1.6;
}
.md-body table { border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 6px 12px; }
.md-body th { background: var(--hover); }
.md-body blockquote {
  border-left: 3px solid var(--accent); margin: 10px 0;
  padding: 2px 14px; color: var(--text-2);
  background: var(--accent-soft); border-radius: 0 8px 8px 0;
}
.md-body a { color: #4d6bfe; text-decoration: none; }
.md-body a:hover { text-decoration: underline; }
.md-body img { max-width: 100%; border-radius: 8px; }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* 思考过程 */
.reason {
  border: 1px dashed var(--border); border-radius: 10px;
  padding: 8px 12px; margin-bottom: 10px; background: var(--panel);
}
.reason summary { cursor: pointer; font-size: 13px; color: var(--text-2); user-select: none; }
.reason-body {
  font-size: 13px; line-height: 1.7; color: var(--text-2);
  white-space: pre-wrap; word-break: break-word;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--border);
  max-height: 260px; overflow-y: auto;
}

/* 操作栏与状态 */
.actions { display: flex; gap: 10px; margin-top: 6px; min-height: 22px; }
.user-actions { justify-content: flex-end; }
.act-btn {
  background: none; border: none; color: var(--text-3);
  font-size: 12px; cursor: pointer; padding: 2px 4px; border-radius: 6px;
}
.act-btn:hover { background: var(--hover); color: var(--text-2); }
.gen-status { font-size: 12px; color: var(--text-3); }
.cursor { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.usage { font-size: 11px; color: var(--text-3); margin-top: 4px; }
.err { color: #e5484d; font-size: 13px; margin-bottom: 8px; }

/* ===== 输入区 ===== */
#composer-wrap {
  flex: none; padding: 8px 16px 16px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
#composer {
  max-width: 768px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px; padding: 10px 14px 8px;
  box-shadow: 0 2px 12px var(--shadow);
}
#composer:focus-within { border-color: var(--accent); }
#input {
  width: 100%; border: none; outline: none; background: transparent;
  resize: none; font: inherit; font-size: 15px; line-height: 1.6;
  color: var(--text); max-height: 200px;
}
.composer-row { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.hint { font-size: 11px; color: var(--text-3); }
.send-group { display: flex; gap: 6px; }
.send-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { filter: brightness(1.1); }
.send-btn.stop { background: #e5484d; }

/* ===== 欢迎页 ===== */
.welcome { text-align: center; padding-top: 9vh; }
.welcome-logo { font-size: 64px; line-height: 1; animation: float 3s ease-in-out infinite; display: inline-block; }
@keyframes float { 50% { transform: translateY(-8px); } }
.welcome h1 { font-size: 26px; margin: 14px 0 8px; }
.welcome p { color: var(--text-2); font-size: 15px; margin: 0 0 22px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 520px; margin: 0 auto; }
.chip {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; font-size: 14px; color: var(--text); font-family: inherit;
  cursor: pointer; text-align: left; line-height: 1.5;
}
.chip:hover { border-color: var(--accent); }
@media (max-width: 560px) { .suggestions { grid-template-columns: 1fr; } }

/* ===== 设置弹窗 ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal-box {
  background: var(--panel); border-radius: 14px;
  width: min(480px, 100%); max-height: 90vh; overflow-y: auto;
  padding: 20px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.field { display: block; margin-bottom: 14px; font-size: 14px; }
.field > span:first-child { display: block; margin-bottom: 6px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px;
  color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; }
.key-row { display: flex; align-items: center; gap: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.key-row:focus-within { border-color: var(--accent); }
.key-row input { flex: 1; border: none; background: transparent; }
.field-hint { font-size: 12px; color: var(--text-3); margin-top: 6px; display: inline-block; }
.field-hint a { color: #4d6bfe; text-decoration: none; }
.field-hint a:hover { text-decoration: underline; }
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; }
.modal-btns { display: flex; gap: 8px; flex: none; }
.btn {
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 14px; font-family: inherit;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* 关键词变色设置 */
.color-rules { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.color-rule { display: flex; align-items: center; gap: 8px; }
.color-rule input[type="text"] {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px;
  color: var(--text); outline: none;
}
.color-rule input[type="text"]:focus { border-color: var(--accent); }
.color-rule input[type="color"] {
  width: 46px; height: 36px; flex: none; padding: 2px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); cursor: pointer;
}
.color-rule .rule-del {
  flex: none; background: none; border: none; cursor: pointer;
  color: var(--text-3); font-size: 14px; padding: 4px 8px; border-radius: 6px;
}
.color-rule .rule-del:hover { background: var(--hover); color: var(--text-2); }
.add-rule-btn { width: 100%; margin-top: 2px; border-style: dashed; color: var(--accent); }
.add-rule-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

/* 对话设置 / 思考程度 */
.tool-btn {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 12px; font-size: 13px; color: var(--text-2); cursor: pointer; font-family: inherit;
  white-space: nowrap;
}
.tool-btn:hover { border-color: var(--text-3); }
.tool-btn.disabled { opacity: 0.5; cursor: not-allowed; }
.effort-wrap { position: relative; }
.effort-wrap .menu { left: 0; width: 160px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field-value { font-size: 13px; color: var(--text-3); }
#set-max-tokens { width: 110px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 13px; color: var(--text); outline: none; }
#set-max-tokens:focus { border-color: var(--accent); }
input[type="range"] {
  width: 100%; margin: 10px 0 2px; accent-color: var(--accent);
  height: 4px; cursor: pointer;
}
.switch { position: relative; width: 44px; height: 24px; flex: none; cursor: pointer; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: 0.2s; }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track + .thumb { left: 23px; }
.bg-actions { display: flex; gap: 8px; }
.bg-actions .btn { padding: 6px 12px; font-size: 13px; }
.bg-preview {
  margin-top: 10px; height: 90px; border-radius: 10px;
  border: 1px solid var(--border); background-size: cover; background-position: center;
}

/* 消息操作菜单 */
#msg-menu {
  position: fixed; z-index: 300; min-width: 150px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px var(--shadow); padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.ctx-item {
  text-align: left; background: none; border: none; cursor: pointer;
  font-size: 14px; color: var(--text); padding: 8px 12px; border-radius: 8px;
  font-family: inherit; white-space: nowrap;
}
.ctx-item:hover { background: var(--hover); }
.ctx-item.danger { color: #e5484d; }
.ctx-item.confirm { background: #e5484d; color: #fff; }
#edit-text {
  width: 100%; min-height: 160px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font: inherit; font-size: 14px; line-height: 1.7;
  color: var(--text); outline: none; resize: vertical;
}
#edit-text:focus { border-color: var(--accent); }

/* ===== 提示浮层 ===== */
#toast {
  position: fixed; left: 50%; bottom: 40px;
  transform: translateX(-50%) translateY(20px);
  background: #323232; color: #fff; padding: 9px 18px;
  border-radius: 999px; font-size: 13px;
  opacity: 0; transition: 0.25s; pointer-events: none; z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 移动端 ===== */
@media (max-width: 820px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 60;
    width: 280px; transform: translateX(-105%); transition: transform 0.25s;
  }
  #sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.25); }
  #scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 55; }
  .only-mobile { display: inline-flex; }
  .bubble { max-width: 88%; }
  #messages { padding: 8px 10px 12px; }
  #composer-wrap { padding: 8px 10px 12px; }
}
