/* ===== 配色变量 ===== */
:root {
  --bg: #faf6f1;
  --bg-chat: #faf6f1;
  --text: #3d3029;
  --text-light: #8a7d74;
  --user-bubble:#faebd7;
  --user-text: #cd853f;
  --bot-text: #3d3029;
  --accent: #e36b37;
  --border: #e8e0d8;
  --card: #ffffff;
  --input-bg: #ffffff;
  --header-bg: #faf6f1;
  --nav-bg: #faf6f1;
  --shadow: rgba(0,0,0,0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* ===== 顶部标题栏 ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: env(safe-area-inset-top, 16px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.header-badge {
  font-size: 11px;
  color: var(--accent);
  background: rgba(227, 107, 55, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.gear {
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

/* ===== 背景图支持 ===== */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  background: var(--bg-chat);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  -webkit-overflow-scrolling: touch;
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== 欢迎页 ===== */
.welcome {
  text-align: center;
  color: var(--text-light);
  padding: 60px 20px;
  font-size: 15px;
  line-height: 1.8;
}

：
/* ===== 消息气泡 ===== */
.msg-wrap {
  display: flex;
  margin-bottom: 24px;
  align-items: flex-start;
  gap: 10px;
}

.msg-wrap.user {
  flex-direction: row-reverse;
}

.msg-wrap .avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  margin-top: 2px;
}

.msg-content-wrap {
  max-width: 80%;
  display: flex;
  flex-direction: column;
}

.msg-wrap.user .msg {
  background: var(--user-bubble);
  color: var(--user-text);
  padding: 12px 16px;
  border-radius: 20px 20px 4px 20px;
  line-height: 1.7;
  font-size: 15px;
  word-break: break-word;
}

.msg-wrap.bot .msg {
  background: transparent;
  color: var(--bot-text);
  padding: 4px 0;
  line-height: 1.7;
  font-size: 15px;
  word-break: break-word;
}

.msg-wrap.bot .msg p {
  margin-bottom: 8px;
}

.msg-wrap.bot .msg p:last-child {
  margin-bottom: 0;
}

/* ===== 思维链折叠 ===== */
.thinking-block {
  margin-bottom: 8px;
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-light);
  transition: all 0.2s;
}

.thinking-header:hover {
  background: rgba(227, 107, 55, 0.05);
}

.thinking-block.expanded .thinking-header {
  border-radius: 12px 12px 0 0;
  border-bottom: none;
}

.thinking-content {
  display: none;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 12px 12px;
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.7;
  white-space: pre-wrap;
}

.thinking-block.expanded .thinking-content {
  display: block;
}

/* ===== 聊天工具栏 ===== */
.chat-tools {
  display: flex;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.chat-tools button {
  flex: 1;
  padding: 6px;
  font-size: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-light);
  cursor: pointer;
}

/* ===== 图片预览 ===== */
.img-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg);
}

.img-preview img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}

.img-preview .remove {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 18px;
  cursor: pointer;
}

/* ===== 输入框 ===== */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--bg);
}

.input-area textarea {
  flex: 1;
  padding: 10px 16px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--input-bg);
  color: var(--text);
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  outline: none;
  font-family: inherit;
}

.input-area textarea:focus {
  border-color: var(--accent);
}

.input-area textarea::placeholder {
  color: var(--text-light);
}

.img-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
}

.send-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.send-btn:disabled {
  opacity: 0.4;
}

/* ===== Keepalive消息样式 ===== */
.keepalive-msg {
  border-left: 3px solid var(--accent);
  background: rgba(227, 107, 55, 0.06);
  border-radius: 8px;
  padding-left: 12px;
  position: relative;
}

.keepalive-msg::before {
  content: '⏰';
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 14px;
}

/* ===== 底部导航 ===== */
.nav {
  display: flex;
  background: var(--nav-bg);
  border-top: 1px solid var(--border);
  padding: 6px 0;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  font-size: 10px;
  color: var(--text-light);
  cursor: pointer;
  transition: color 0.2s;
}

.nav-item .icon {
  font-size: 20px;
}

.nav-item.active {
  color: var(--accent);
}

/* ===== 页面切换 ===== */
.page {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}

.page.active {
  display: flex;
}

/* ===== 弹窗通用 ===== */
.overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.overlay.show {
  display: flex;
}

.modal {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

.modal h2 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--text);
}

.modal label {
  display: block;
  font-size: 12px;
  color: var(--text-light);
  margin: 12px 0 4px;
}

.modal input,
.modal textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-family: inherit;
}

.modal input:focus,
.modal textarea:focus {
  border-color: var(--accent);
}

/* ===== 设置分组 ===== */
.sg {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: 12px;
}

.sg h3 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text);
}

.sr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sr .lb {
  font-size: 13px;
  color: var(--text-light);
}

.sr .vl {
  font-size: 13px;
  color: var(--accent);
  min-width: 40px;
  text-align: right;
}

.sr input[type="range"] {
  flex: 1;
  margin: 0 12px;
  accent-color: var(--accent);
}

.sr input[type="number"] {
  padding: 6px 8px;
  text-align: center;
}

/* ===== 开关 ===== */
.tg { position: relative; display: inline-block; width: 44px; height: 24px; }
.tg input { opacity: 0; width: 0; height: 0; }
.sl { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: var(--border); border-radius: 24px; transition: 0.3s; }
.sl:before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.3s; }
.tg input:checked + .sl { background: var(--accent); }
.tg input:checked + .sl:before { transform: translateX(20px); }

/* ===== 按钮 ===== */
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-save {
  flex: 1;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  cursor: pointer;
  font-weight: 500;
}

.btn-cancel {
  flex: 1;
  padding: 12px;
  background: var(--bg);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  cursor: pointer;
}

/* ===== 头像设置 ===== */
.avatar-row {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.avatar-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-light);
}

.avatar-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  overflow: hidden;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== 预设管理 ===== */
.preset-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ===== 数据管理 ===== */
.data-btns {
  display: flex;
  gap: 8px;
}

.data-btns button {
  flex: 1;
  padding: 10px;
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
}

/* ===== 消息操作菜单 ===== */
.msg-menu-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 300;
}

.msg-menu-overlay.show {
  display: block;
}

.msg-menu {
  display: none;
  position: fixed;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  z-index: 301;
  overflow: hidden;
  min-width: 140px;
}

.msg-menu.show {
  display: block;
}

.msg-menu-item {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.msg-menu-item:hover {
  background: var(--bg);
}

/* ===== 记忆弹窗 ===== */
.mem-modal {
  max-height: 90vh;
}

.mem-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.mem-top-btns {
  display: flex;
  gap: 8px;
}

.mem-top-btns button {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 8px;
  cursor: pointer;
}

/* ===== 日记页 ===== */
.diary-page {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.diary-write {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.diary-write h3 {
  margin-bottom: 10px;
  font-size: 15px;
  color: var(--text);
}

.diary-write textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  resize: vertical;
  height: 80px;
  outline: none;
  font-family: inherit;
  margin-bottom: 8px;
}

.diary-write button {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}

.mood-picker {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.mood-picker span {
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  transition: background 0.2s;
}

.mood-picker span.active {
  background: rgba(227, 107, 55, 0.15);
}

.diary-empty {
  text-align: center;
  color: var(--text-light);
  padding: 40px;
  font-size: 14px;
}

/* ===== 悄悄话页 ===== */
.whisper-page {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.whisper-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  width: 100%;
  max-width: 340px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px var(--shadow);
}

.whisper-card .emoji {
  font-size: 40px;
  margin-bottom: 12px;
}

.whisper-card .text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}

.whisper-card .from {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-light);
}

.whisper-btn {
  padding: 12px 32px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 24px;
  font-size: 15px;
  cursor: pointer;
  margin-bottom: 8px;
}

.whisper-count {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 24px;
}

.whisper-write {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.whisper-write h3 {
  font-size: 15px;
  margin-bottom: 10px;
  color: var(--text);
}

.whisper-write textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  resize: vertical;
  height: 60px;
  outline: none;
  font-family: inherit;
  margin-bottom: 8px;
}

.whisper-write button {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}

/* ===== 收藏页 ===== */
.fav-page {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

/* ===== Markdown渲染 ===== */
.msg-wrap.bot .msg h1,
.msg-wrap.bot .msg h2,
.msg-wrap.bot .msg h3 {
  margin: 12px 0 6px;
  color: var(--text);
}

.msg-wrap.bot .msg code {
  background: rgba(227, 107, 55, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--accent);
}

.msg-wrap.bot .msg pre {
  background: #2d2017;
  color: #f0e6dc;
  padding: 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
}

.msg-wrap.bot .msg pre code {
  background: none;
  color: inherit;
  padding: 0;
}

.msg-wrap.bot .msg ul,
.msg-wrap.bot .msg ol {
  padding-left: 20px;
  margin: 6px 0;
}

.msg-wrap.bot .msg li {
  margin-bottom: 4px;
}

.msg-wrap.bot .msg hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.msg-wrap.bot .msg strong {
  color: var(--text);
  font-weight: 600;
}

.msg-wrap.bot .msg a {
  color: var(--accent);
  text-decoration: none;
}

/* ===== 小克正在想 ===== */
.typing {
  color: var(--text-light);
  font-size: 13px;
  padding: 8px 0;
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ===== 编辑消息弹窗 ===== */
.edit-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 400;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.edit-overlay.show {
  display: flex;
}

.edit-modal {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 500px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

.edit-modal h3 {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 12px;
}

.edit-modal textarea {
  width: 100%;
  min-height: 200px;
  max-height: 60vh;
  padding: 14px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  outline: none;
  font-family: inherit;
  line-height: 1.7;
}

.edit-modal textarea:focus {
  border-color: var(--accent);
}

.edit-modal .btn-row {
  margin-top: 14px;
}

/* ===== 消息内图片 ===== */
.msg img {
  max-width: 100%;
  max-height: 300px;
  border-radius: 12px;
  object-fit: contain;
}

.msg-wrap.user .msg img {
  max-width: 200px;
  border-radius: 12px;
}

/* ===== 终极布局修复 ===== */
.msg-wrap {
  display: flex !important;
  flex-direction: row !important;
  margin-bottom: 24px !important;
  align-items: flex-start !important;
  gap: 10px !important;
  width: 100% !important;
}

.msg-wrap.user {
  flex-direction: row-reverse !important;
  justify-content: flex-start !important;
}

.msg-wrap.bot {
  flex-direction: row !important;
  justify-content: flex-start !important;
}

.msg-content-wrap {
  max-width: 75% !important;
  display: flex !important;
  flex-direction: column !important;
}

.msg-wrap.user .msg-content-wrap {
  align-items: flex-end !important;
}

.msg-wrap.bot .msg-content-wrap {
  align-items: flex-start !important;
}

.msg-wrap .msg {
  word-break: break-word !important;
  line-height: 1.7 !important;
  font-size: 15px !important;
}

.msg-wrap.user .msg {
  background: var(--user-bubble) !important;
  color: var(--user-text) !important;
  padding: 12px 16px !important;
  border-radius: 20px 20px 4px 20px !important;
  display: inline-block !important;
}

.msg-wrap.bot .msg {
  background: transparent !important;
  color: var(--bot-text) !important;
  padding: 4px 0 !important;
}

.msg-wrap .thinking-block {
  margin-bottom: 8px !important;
  width: 100% !important;
}

/* ===== 记忆条目样式 ===== */
.mem-item {
  padding: 14px 16px;
  margin-bottom: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  word-break: break-word;
}

.mem-id {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 8px;
  font-weight: 500;
}

.mem-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.mem-tag {
  font-size: 11px;
  background: rgba(227, 107, 55, 0.1);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 10px;
}

.mem-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.mem-actions button {
  padding: 4px 12px;
  font-size: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-light);
  cursor: pointer;
}

/* ===== 日记条目样式 ===== */
.diary-entry {
  padding: 16px;
  margin-bottom: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.diary-entry .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--text-light);
}

.diary-entry .author-tag {
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.diary-entry .tag-xiaoke {
  background: rgba(227, 107, 55, 0.12);
  color: var(--accent);
}

.diary-entry .tag-minmin {
  background: rgba(147, 112, 219, 0.12);
  color: #8b5cf6;
}

.diary-entry .body {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== 时间标签 ===== */
.msg-time {
  font-size: 11px !important;
  color: var(--text-light) !important;
  font-weight: 400;
  margin-bottom: 2px;
}
