/* style.css - DeepSeek 官方 APP 风格克隆（浅色/深色双主题） */
:root {
  --blue: #4D6BFE;
  --blue-deep: #3B5BFD;
  --bg: #FFFFFF;
  --bg2: #F7F8FA;         /* 输入框/卡片 */
  --bg3: #EFF2F6;         /* 气泡背景 */
  --text: #1B1C1F;
  --text2: #5F6368;
  --text3: #9AA0A6;
  --line: #E8EAED;
  --pill-bg: #E8EFFE;
  --pill-on: #4D6BFE;
  --danger: #D93025;
  --ok: #1E8E3E;
  --shadow: 0 1px 6px rgba(0,0,0,.08);
  --radius: 14px;
}
html[data-theme="dark"] {
  --bg: #121316;
  --bg2: #1C1D22;
  --bg3: #24262C;
  --text: #E6E7EA;
  --text2: #A6ABB3;
  --text3: #6B7078;
  --line: #2C2E35;
  --pill-bg: #232A45;
  --pill-on: #7C93FF;
  --shadow: 0 1px 6px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
}
button { font-family: inherit; border: none; background: none; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
svg { display: block; }

#app { height: 100%; display: flex; overflow: hidden; position: relative; }

/* ================= 侧栏抽屉 ================= */
#scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
#scrim.show { opacity: 1; pointer-events: auto; }
#sidebar {
  position: fixed; z-index: 41; top: 0; bottom: 0; left: 0;
  width: min(82vw, 340px); background: var(--bg2);
  display: flex; flex-direction: column;
  transform: translateX(-102%); transition: transform .26s cubic-bezier(.4,0,.2,1);
  box-shadow: 2px 0 12px rgba(0,0,0,.10);
}
#sidebar.open { transform: none; }
.sb-head { padding: 18px 20px 12px; font-size: 17px; font-weight: 700; color: var(--blue); display: flex; align-items: center; gap: 8px; }
.sb-list { flex: 1; overflow-y: auto; padding: 4px 10px; }
.sess-item {
  display: flex; align-items: center; gap: 6px;
  padding: 11px 12px; border-radius: 12px; margin-bottom: 2px;
  cursor: pointer; transition: background .15s;
}
.sess-item:active, .sess-item.active { background: var(--pill-bg); }
.sess-item .s-main { flex: 1; min-width: 0; }
.sess-item .s-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.sess-item .s-time { font-size: 12px; color: var(--text3); margin-top: 1px; }
.sess-item .s-more { flex-shrink: 0; color: var(--text3); padding: 6px; border-radius: 50%; }
.sess-item .s-more:active { background: rgba(0,0,0,.08); }
.sb-empty { padding: 40px 16px; text-align: center; color: var(--text3); font-size: 14px; }
.sb-foot { padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.sb-btn {
  display: flex; align-items: center; gap: 12px; padding: 12px 10px;
  border-radius: 12px; font-size: 15px; color: var(--text);
}
.sb-btn:active { background: rgba(0,0,0,.06); }
html[data-theme="dark"] .sb-btn:active { background: rgba(255,255,255,.08); }

/* ================= 主区 ================= */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  z-index: 5; border-bottom: 1px solid transparent;
}
.icon-btn { padding: 8px; border-radius: 50%; color: var(--text); display: flex; }
.icon-btn:active { background: rgba(0,0,0,.08); }
html[data-theme="dark"] .icon-btn:active { background: rgba(255,255,255,.1); }

#modeSwitch {
  display: flex; background: var(--bg2); border-radius: 20px; padding: 3px; gap: 2px;
}
.mode-btn {
  padding: 6px 22px; border-radius: 17px; font-size: 14px; font-weight: 600; color: var(--text2);
  transition: all .18s;
}
.mode-btn.active { background: var(--bg); color: var(--blue); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
html[data-theme="dark"] .mode-btn.active { background: #34363E; }

/* ================= 聊天区 ================= */
#chat { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; position: relative; }
#welcome { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding-bottom: 60px; }
.welcome-title { font-size: 20px; font-weight: 600; color: var(--text); }
.welcome-hints { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; padding: 0 24px; max-width: 480px; }
.hint-chip {
  padding: 8px 16px; border-radius: 20px; background: var(--bg2); color: var(--text2);
  font-size: 14px; border: 1px solid var(--line);
}
.hint-chip:active { background: var(--pill-bg); }

#messages { padding: 12px 14px 20px; max-width: 820px; margin: 0 auto; }

/* ---- 消息 ---- */
.msg { margin-bottom: 20px; position: relative; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  background: var(--pill-bg); color: var(--text);
  padding: 10px 14px; border-radius: 16px 16px 4px 16px;
  max-width: 86%; word-break: break-word; white-space: pre-wrap;
}
.msg-user .bubble img { max-width: 220px; border-radius: 10px; display: block; margin-top: 4px; }
.msg-user .bubble .file-chip {
  display: flex; align-items: center; gap: 8px; background: rgba(77,107,254,.12);
  padding: 6px 10px; border-radius: 8px; font-size: 14px; margin-top: 4px;
}
.msg-user .bubble .file-chip svg { flex-shrink: 0; color: var(--blue); }

.msg-ai { display: flex; flex-direction: column; }
.think-box { margin-bottom: 8px; }
.think-head {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg2); border: 1px solid var(--line);
  color: var(--text2); font-size: 13px;
  padding: 6px 12px; border-radius: 14px; cursor: pointer;
}
.think-head .spin {
  width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--blue);
  border-radius: 50%; animation: rot 0.8s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }
.think-body {
  background: var(--bg2); border-radius: 0 12px 12px 12px;
  font-size: 14px; color: var(--text2); line-height: 1.65;
  padding: 10px 14px; margin-top: -4px; margin-left: 0;
  max-height: 300px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.ai-content { font-size: 16px; word-break: break-word; }
.ai-content.err { color: var(--danger); font-size: 14px; }

/* markdown 渲染 */
.md p { margin: 0.5em 0; } .md p:first-child { margin-top: 0; } .md p:last-child { margin-bottom: 0; }
.md h1,.md h2,.md h3,.md h4 { margin: 0.8em 0 0.4em; font-size: 1.08em; font-weight: 700; }
.md ul,.md ol { padding-left: 1.4em; margin: 0.4em 0; }
.md li { margin: 0.15em 0; }
.md code:not(pre code) {
  background: rgba(77,107,254,.09); color: #B93C00; padding: 1px 6px; border-radius: 5px; font-size: 0.88em;
  font-family: ui-monospace, "JetBrains Mono", Consolas, monospace;
}
.md pre {
  background: #1E1F24; color: #E3E5EA; border-radius: 10px; padding: 12px 14px;
  overflow-x: auto; margin: 0.6em 0; position: relative;
}
.md pre code { font-family: ui-monospace, "JetBrains Mono", Consolas, monospace; font-size: 13.5px; line-height: 1.55; white-space: pre; }
.md blockquote { border-left: 3px solid var(--blue); padding-left: 10px; color: var(--text2); margin: 0.5em 0; }
.md a { color: var(--blue); text-decoration: none; } .md a:active { opacity: .7; }
.md table { border-collapse: collapse; margin: 0.6em 0; font-size: 14px; max-width: 100%; display: block; overflow-x: auto; }
.md th,.md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 0.8em 0; }

/* 工具卡（Agent） */
.tool-card {
  border: 1px solid var(--line); border-radius: 12px; margin: 6px 0; overflow: hidden; background: var(--bg);
}
.tool-head {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; font-size: 13.5px; color: var(--text2); cursor: pointer;
}
.tool-head svg { flex-shrink: 0; color: var(--blue); }
.tool-head .t-spin { width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: rot .8s linear infinite; }
.tool-body { border-top: 1px dashed var(--line); padding: 10px 12px; font-size: 12.5px; color: var(--text2); max-height: 240px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, monospace; }

/* 版本切换器 + 消息工具栏 */
.msg-tools { display: flex; align-items: center; gap: 2px; margin-top: 6px; color: var(--text3); flex-wrap: wrap; }
.ver-switch {
  display: inline-flex; align-items: center; gap: 0;
  background: var(--bg2); border-radius: 14px; overflow: hidden; margin-right: 6px;
}
.ver-switch button { padding: 4px 9px; display: flex; color: var(--text2); font-size: 13px; }
.ver-switch button:disabled { opacity: .3; }
.ver-switch .ver-num { font-size: 13px; color: var(--text2); padding: 0 2px; font-variant-numeric: tabular-nums; user-select: none; }
.msg-user .msg-tools { justify-content: flex-end; }
.mt-btn { padding: 5px 7px; border-radius: 8px; display: flex; color: var(--text3); }
.mt-btn:active { background: rgba(0,0,0,.07); }
html[data-theme="dark"] .mt-btn:active { background: rgba(255,255,255,.08); }
.mt-btn svg { width: 17px; height: 17px; }

/* 生成中光标 */
.caret::after { content: "▍"; color: var(--blue); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

#scrollBottom {
  position: fixed; right: 18px; bottom: 190px; z-index: 6;
  width: 38px; height: 38px; border-radius: 50%; background: var(--bg); color: var(--text2);
  box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#scrollBottom.show { opacity: 1; pointer-events: auto; }

/* ================= 输入区 ================= */
#composer { background: var(--bg); padding: 4px 12px 6px; border-top: 1px solid var(--line); }
#attachPanel {
  display: flex; gap: 10px; padding: 12px 6px 6px;
}
.attach-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px;
  background: var(--bg2); border-radius: 14px; padding: 13px 0 10px; color: var(--text2); font-size: 13px;
}
.attach-btn:active { background: var(--pill-bg); }
.attach-btn svg { color: var(--blue); }

#filePreviews { display: flex; gap: 8px; padding: 8px 2px 2px; overflow-x: auto; }
.fp {
  position: relative; flex-shrink: 0; width: 58px; height: 58px;
  border-radius: 10px; background: var(--bg2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.fp img { width: 100%; height: 100%; object-fit: cover; }
.fp .fp-doc { font-size: 10px; color: var(--text2); text-align: center; padding: 4px; word-break: break-all; }
.fp .fp-x {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: #3C4043; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px;
}

#composerBox {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg2); border-radius: 24px; padding: 7px 8px 7px 14px;
}
#input {
  flex: 1; border: none; outline: none; background: transparent; color: var(--text);
  font-size: 16px; line-height: 1.45; max-height: 132px; resize: none; font-family: inherit; padding: 6px 0;
}
#input::placeholder { color: var(--text3); }
#btnPlus { color: var(--text2); align-self: flex-end; }
#btnPlus.on { transform: rotate(45deg); color: var(--blue); transition: transform .2s; }
#btnSend {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--pill-bg); color: var(--pill-on); display: flex; align-items: center; justify-content: center;
  align-self: flex-end; transition: all .15s;
}
#btnSend.ready { background: var(--blue); color: #fff; }
#btnSend.stop { background: var(--text); color: #fff; }

#pillRow { display: flex; gap: 8px; padding: 8px 4px 2px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg2); color: var(--text2); font-size: 13px;
  border-radius: 16px; padding: 6px 13px; font-weight: 500;
}
.pill.on { background: var(--pill-bg); color: var(--pill-on); }
.pill.dim { opacity: .42; }
.pill:active { filter: brightness(.95); }
#footNote { text-align: center; font-size: 11px; color: var(--text3); padding: 2px 0 6px; }

/* ================= 弹层 ================= */
.overlay { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.overlay.d-center { align-items: center; }
.overlay-bg { position: absolute; inset: 0; background: rgba(0,0,0,.45); }

.sheet {
  position: relative; width: 100%; max-width: 560px;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 0 calc(10px + env(safe-area-inset-bottom));
  animation: up .22s cubic-bezier(.4,0,.2,1);
  max-height: 75vh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(60px); opacity: .5; } }
.sheet-grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 8px; }
.sheet-item {
  display: flex; align-items: center; gap: 16px; padding: 15px 24px; font-size: 16px; color: var(--text);
}
.sheet-item svg { color: var(--text2); width: 21px; height: 21px; }
.sheet-item:active { background: var(--bg2); }
.sheet-item.danger { color: var(--danger); } .sheet-item.danger svg { color: var(--danger); }
.sheet-title { text-align: center; font-size: 13px; color: var(--text3); padding: 2px 24px 10px; }
.sheet-cancel { border-top: 8px solid color-mix(in srgb, var(--bg2) 70%, transparent); }

.dialog {
  position: relative; width: min(92vw, 400px); background: var(--bg); border-radius: 18px;
  padding: 20px; animation: pop .18s cubic-bezier(.4,0,.2,1); max-height: 84vh; overflow-y: auto;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.dlg-title { font-size: 17px; font-weight: 700; margin-bottom: 14px; text-align: center; }
.dlg-actions { display: flex; gap: 10px; margin-top: 18px; }
.dlg-actions button {
  flex: 1; padding: 11px 0; border-radius: 12px; font-size: 15px; font-weight: 600;
  background: var(--bg2); color: var(--text);
}
.dlg-actions .primary { background: var(--blue); color: #fff; }
.dlg-actions .danger { background: var(--danger); color: #fff; }

/* 通用表单 */
.f-label { font-size: 13px; color: var(--text2); margin: 14px 0 5px; font-weight: 600; }
.f-input, .f-select, .f-textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; color: var(--text); font-family: inherit; outline: none;
}
.f-textarea { resize: vertical; min-height: 74px; line-height: 1.5; }
.f-input:focus, .f-select:focus, .f-textarea:focus { border-color: var(--blue); }
.f-hint { font-size: 12px; color: var(--text3); margin-top: 4px; }
.f-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 0; gap: 12px; }
.f-row .f-name { font-size: 15px; }
.f-row .f-sub { font-size: 12.5px; color: var(--text3); margin-top: 1px; }
.f-row input[type=range] { width: 150px; accent-color: var(--blue); }
.f-row .rv { font-size: 13px; color: var(--text2); min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; }
.f-switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.f-switch input { opacity: 0; width: 100%; height: 100%; position: absolute; z-index: 2; margin: 0; }
.f-switch .tr { position: absolute; inset: 0; background: #C4C7CC; border-radius: 13px; transition: background .18s; }
.f-switch .th { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: left .18s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.f-switch input:checked ~ .tr { background: var(--blue); }
.f-switch input:checked ~ .th { left: 21px; }
select.f-select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text2) 50%), linear-gradient(135deg, var(--text2) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

/* popover（pill 菜单） */
#popover {
  position: fixed; z-index: 70; background: var(--bg); border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,.18); min-width: 170px; padding: 6px; animation: pop .14s;
}
.pop-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; border-radius: 10px; font-size: 15px; color: var(--text);
}
.pop-item:active { background: var(--bg2); }
.pop-item.sel { color: var(--blue); font-weight: 600; }
.pop-item .pi-sub { font-size: 12px; color: var(--text3); }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%);
  background: #3C4043; color: #fff; font-size: 14px; padding: 10px 20px; border-radius: 20px;
  z-index: 90; max-width: 80vw; text-align: center; animation: pop .18s; opacity: .95;
}

/* ================= 设置页 ================= */
#settingsPage {
  position: fixed; inset: 0; z-index: 55; background: var(--bg);
  display: flex; flex-direction: column; animation: slidein .22s;
}
@keyframes slidein { from { transform: translateX(40px); opacity: .4; } }
.st-head {
  display: flex; align-items: center; gap: 6px; padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line);
}
.st-head .st-title { font-size: 17px; font-weight: 700; flex: 1; text-align: center; margin-right: 44px; }
.st-body { flex: 1; overflow-y: auto; padding: 4px 16px calc(30px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; width: 100%; }
.st-section { margin: 22px 0 8px; font-size: 13px; color: var(--text3); font-weight: 700; letter-spacing: .4px; }
.st-card { background: var(--bg2); border-radius: 14px; padding: 4px 16px; }
.st-link {
  display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line);
  font-size: 15px; color: var(--text); width: 100%; text-align: left;
}
.st-link:last-child { border-bottom: none; }
.st-link svg { color: var(--text2); width: 20px; height: 20px; flex-shrink: 0; }
.st-link .sl-main { flex: 1; }
.st-link .sl-sub { font-size: 12.5px; color: var(--text3); margin-top: 1px; }
.st-link .chev { color: var(--text3); }
.st-link.danger { color: var(--danger); } .st-link.danger svg { color: var(--danger); }

/* 会话消息编辑态 */
.edit-box { width: 100%; }
.edit-box textarea {
  width: 100%; background: var(--bg2); border: 1.5px solid var(--blue); border-radius: 12px;
  padding: 10px 12px; font-size: 15px; color: var(--text); font-family: inherit; min-height: 80px; line-height: 1.5;
}
.edit-box .eb-imgs { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.edit-box .eb-imgs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.edit-actions { display: flex; gap: 10px; margin-top: 8px; justify-content: flex-end; }
.edit-actions button { padding: 8px 18px; border-radius: 10px; font-size: 14px; background: var(--bg2); color: var(--text); }
.edit-actions .primary { background: var(--blue); color: #fff; }

/* 滚动条 */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 2px; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); }

/* user 消息文本可选择（选择文本功能） */
.msg.selecting .bubble, .msg.selecting .ai-content { user-select: text; -webkit-user-select: text; }
.msg .bubble, .msg .ai-content { user-select: none; -webkit-user-select: none; }
