/* MikuChat — DeepSeek 风格界面，重点适配 iOS 移动端 */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e6e8eb;
  --text: #1f2328;
  --muted: #8b9198;
  --accent: #4d6bfe;
  --accent-hover: #3f5be0;
  --accent-soft: #eef2ff;
  --user-bubble: #f2f3f5;
  --danger: #ef4444;
  --shadow: 0 2px 12px rgba(16, 24, 40, .08);
  --code-bg: #f6f7f9;
}

[data-theme="dark"] {
  --bg: #212327;
  --panel: #2c2e33;
  --border: #3a3d42;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #6b85ff;
  --accent-hover: #5a76f5;
  --accent-soft: #2a3350;
  --user-bubble: #3a3d42;
  --shadow: 0 2px 12px rgba(0, 0, 0, .4);
  --code-bg: #1b1d21;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
  background: var(--bg);
}
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  width: 264px;
  flex: 0 0 264px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 10px;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 10px 10px;
  font-size: 17px;
  font-weight: 700;
}
.sidebar-logo .logo { font-size: 22px; }
.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  margin: 4px 0 14px;
  font-size: 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  transition: .15s;
}
.new-chat-btn .plus { font-size: 16px; font-weight: 700; }
.new-chat-btn:hover { background: var(--accent); color: #fff; }
.conv-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.conv-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 36px 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
}
.conv-item:hover { background: var(--accent-soft); }
.conv-item.active { background: var(--accent-soft); }
.conv-title {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item.active .conv-title { color: var(--accent); font-weight: 600; }
.conv-meta { font-size: 11px; color: var(--muted); }
.conv-del {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px; height: 24px;
  border: none; background: transparent;
  font-size: 13px; cursor: pointer;
  border-radius: 6px;
  opacity: 0;
  transition: .15s;
}
.conv-item:hover .conv-del { opacity: .7; }
.conv-del:hover { opacity: 1 !important; background: rgba(239, 68, 68, .14); }
.conv-empty { font-size: 13px; color: var(--muted); padding: 16px 12px; text-align: center; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg);
}
.menu-btn {
  display: none;
  width: 36px; height: 36px;
  border: none; background: none;
  font-size: 20px; cursor: pointer;
  border-radius: 10px; color: var(--text);
}
.menu-btn:hover { background: var(--accent-soft); }
.topbar-brand { font-size: 16px; font-weight: 700; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.model-select {
  max-width: 190px;
  font-size: 13px;
  padding: 8px 30px 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b9198' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.theme-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.theme-btn:hover { border-color: var(--accent); }

/* ---------- 聊天区 ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px 12px;
}
.messages {
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: 12px;
}

.welcome {
  max-width: 640px;
  margin: 8vh auto 0;
  text-align: center;
  padding: 24px;
}
.welcome-logo {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: linear-gradient(135deg, #4d6bfe, #7a5cff);
  color: #fff;
  font-size: 32px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(77, 107, 254, .35);
}
.welcome h2 { font-size: 22px; margin-bottom: 10px; }
.welcome p { color: var(--muted); font-size: 14px; line-height: 1.7; margin-bottom: 24px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.sug {
  font-size: 13px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  transition: .15s;
}
.sug:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 消息 ---------- */
.msg { display: flex; gap: 10px; margin-bottom: 24px; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg .avatar {
  width: 30px; height: 30px; flex: 0 0 auto;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  background: linear-gradient(135deg, #4d6bfe, #7a5cff);
  color: #fff;
}
.msg.user .avatar { display: none; }
.msg .body { min-width: 0; flex: 1; }
.msg .bubble {
  font-size: 16px;
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.ai .bubble { padding: 4px 0 0; white-space: normal; }
.msg.user .bubble {
  background: var(--user-bubble);
  border-radius: 16px;
  padding: 10px 14px;
  display: inline-block;
  max-width: 100%;
}
.msg .bubble.thinking { color: var(--muted); font-style: italic; }

.msg .bubble img.msg-img {
  display: block;
  max-width: 240px;
  max-height: 240px;
  border-radius: 10px;
  margin: 4px 0;
}
.msg.user .bubble { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }

/* Markdown */
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: 14px 0 8px; line-height: 1.3; }
.md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md ul, .md ol { margin: 8px 0; padding-left: 24px; }
.md li { margin: 4px 0; }
.md code {
  font-family: "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 14px;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 6px;
}
.md pre {
  background: #1b1d21;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
.md pre code { background: none; padding: 0; font-size: 13.5px; color: inherit; }
.md .code-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: #94a3b8;
  padding: 8px 12px 0;
}
.md .copy-btn {
  background: rgba(255, 255, 255, .1); border: none; color: #cbd5e1;
  font-size: 11px; padding: 3px 9px; border-radius: 6px; cursor: pointer;
}
.md .copy-btn:hover { background: rgba(255, 255, 255, .22); }
.md a { color: var(--accent); }
.md blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--muted); margin: 10px 0; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md th { background: var(--accent-soft); }

/* KaTeX 公式 */
.md .katex { font-size: 1.06em; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 6px 0; margin: 8px 0; }

/* 打字光标 */
.typing-dot::after {
  content: '▋'; animation: blink 1s steps(1) infinite; color: var(--accent); margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- 输入区 ---------- */
.composer {
  max-width: 768px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px calc(10px + env(safe-area-inset-bottom));
}
.model-hint {
  font-size: 13px;
  color: #b45309;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
}
[data-theme="dark"] .model-hint { color: #fbbf24; background: #3a2f14; border-color: #6b5415; }
.model-hint[hidden] { display: none; }

.preview-row { display: flex; gap: 8px; flex-wrap: wrap; padding-bottom: 8px; }
.preview-row:empty { display: none; }
.preview-item { position: relative; width: 64px; height: 64px; }
.preview-item img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.preview-item .rm {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none;
  font-size: 12px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 7px 8px;
  box-shadow: var(--shadow);
}
.icon-btn {
  width: 36px; height: 36px; flex: 0 0 auto;
  border: none; background: transparent;
  border-radius: 50%; cursor: pointer;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: .15s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
#input {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  font-size: 16px;   /* ≥16px 防止 iOS 聚焦自动放大 */
  font-family: inherit;
  line-height: 1.5;
  max-height: 132px;
  padding: 7px 6px;
  outline: none;
  color: var(--text);
  caret-color: var(--accent);
}
#input::placeholder { color: var(--muted); }
.send-btn {
  width: 36px; height: 36px; flex: 0 0 auto;
  border: none; border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: .15s;
}
.send-btn.ready { background: var(--accent); color: #fff; }
.send-btn.ready:hover { background: var(--accent-hover); }
.send-btn.stop { background: var(--danger); color: #fff; }
.ic-stop { display: none; }
.send-btn.stop .ic-send { display: none; }
.send-btn.stop .ic-stop { display: block; }

/* ---------- 拍照弹窗 ---------- */
.camera-modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .72);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.camera-modal[hidden] { display: none; }
.camera-box {
  background: var(--panel); border-radius: 18px;
  width: 100%; max-width: 460px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.camera-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; font-weight: 600;
}
.close-btn { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
#cameraVideo { width: 100%; height: 320px; object-fit: cover; background: #000; display: block; }
.camera-actions { display: flex; gap: 10px; padding: 14px 16px; }
.capture-btn {
  flex: 1; padding: 12px; border: none; border-radius: 12px;
  background: var(--accent); color: #fff;
  font-size: 15px; cursor: pointer;
}
.ghost-btn {
  padding: 12px 20px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 15px;
}
.camera-hint { padding: 0 16px 14px; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: rgba(17, 24, 39, .94); color: #fff;
  padding: 10px 18px; border-radius: 12px; font-size: 14px;
  z-index: 200; max-width: 86vw; text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- 侧栏遮罩 ---------- */
.sidebar-mask { display: none; }

/* ---------- 响应式：移动端抽屉侧栏 ---------- */
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 60;
    width: 280px;
    padding-top: env(safe-area-inset-top);
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: none;
  }
  body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 0 0 30px rgba(0, 0, 0, .3); }
  .sidebar-mask {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .4);
    z-index: 55;
  }
  .sidebar-mask[hidden] { display: none; }
  .menu-btn { display: flex; align-items: center; justify-content: center; }
  .topbar-brand { display: block; }
  .model-select { max-width: 150px; }
  .msg .body { max-width: 92%; }
}

/* 桌面端隐藏顶栏品牌（侧栏已展示） */
@media (min-width: 761px) {
  .topbar-brand { display: none; }
}
