/* Memos Lite — CodeXXN 极简黑白灰设计规范 */

:root {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --bg-secondary: #fafafa;
  --text-primary: #1a1a1a;
  --text-secondary: #555555;
  --text-tertiary: #888888;
  --border: #e0e0e0;
  --border-light: #eeeeee;
  /* 日历「有记录日期」的浅灰底：需明显区别于侧栏底 #f5f5f5 与次级背景 #fafafa */
  --bg-soft: #e2e2e2;
  --bg-soft-hover: #d6d6d6;
  --accent: #1a1a1a;
  --accent-inverse: #ffffff;
  --error: #c62828;
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;
  --radius-xl: 0;
  --radius-pill: 0;
}

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

/* 全站直角化：统一清除所有组件圆角（含第三方编辑器注入的样式） */
*,
*::before,
*::after { border-radius: 0 !important; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.7;
}

.hidden { display: none !important; }

code {
  font-family: "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
  font-size: 13px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}

/* ---------- 通用组件 ---------- */

.btn-primary {
  background: var(--accent);
  color: var(--accent-inverse);
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 32px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary.btn-sm { padding: 8px 24px; font-size: 14px; }
.btn-block { width: 100%; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--text-secondary); background: var(--bg-card); }

.btn-text {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 8px;
}
.btn-text:hover { color: var(--text-primary); }

.input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
}
.input::placeholder { color: var(--text-tertiary); }
.input:focus { border-color: var(--text-secondary); }

.icon { width: 18px; height: 18px; display: block; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text-primary); background: var(--bg-card); border-color: var(--border); }

/* 移动端菜单按钮：桌面隐藏 */
.menu-btn { display: none; }

/* 移动端抽屉遮罩：桌面隐藏，移动端配合 .hidden 切换 */
.nav-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26, 26, 26, 0.4);
  z-index: 55;
  display: none;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.logo-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: var(--accent-inverse);
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ---------- 登录页 ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 32px;
}

.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.login-title { font-size: 20px; font-weight: 700; }
.login-desc { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }

#login-form { display: flex; flex-direction: column; gap: 16px; }
.login-error { color: var(--error); font-size: 13px; margin-top: 12px; min-height: 20px; }

/* ---------- 品牌 / 搜索 ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
}
.brand:hover { background: var(--bg-secondary); }
.brand-name { font-weight: 700; font-size: 16px; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px;
  color: var(--text-tertiary);
}
.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  width: 100%;
  min-width: 0;
  height: 36px;
}
.search-box input::placeholder { color: var(--text-tertiary); }

/* 搜索框已移入侧栏，位于日历与标签之前 */
.sidebar-search {
  flex-shrink: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

/* ---------- 全屏左右分栏布局（ChatGPT 式） ---------- */

.app-shell {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.sidebar {
  width: 264px;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
}

.sidebar-head { flex-shrink: 0; padding: 14px 16px 10px; }

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar-foot {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.login-status {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 0;
}
.side-foot-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

/* 侧栏分区：通栏铺满，仅以发丝线分隔，不再套卡片框 */
.side-section { padding: 14px 16px; }
.side-section + .side-section { border-top: 1px solid var(--border-light); }

.side-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.tag-list { display: flex; flex-direction: column; gap: 2px; }

.tag-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: inherit;
  text-align: left;
  width: 100%;
}
.tag-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.tag-item.active { background: var(--bg-secondary); color: var(--text-primary); font-weight: 600; }
.tag-item .tag-count { font-size: 12px; color: var(--text-tertiary); }
.side-link { display: inline-flex; align-items: center; gap: 8px; }
.side-link .icon { width: 16px; height: 16px; flex-shrink: 0; }
.tag-empty { font-size: 13px; color: var(--text-tertiary); }

.content {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.panel-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg);
}

/* 笔记页头部：搜索移入侧栏后桌面端已无内容，仅移动端保留汉堡按钮 */
.notes-head { display: none; }

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- 编辑器 ---------- */

.editor-card { padding: 20px 24px 16px; }

.editor {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  min-height: 72px;
  max-height: 80vh;
  overflow-y: auto;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  background: transparent;
}
.editor::placeholder { color: var(--text-tertiary); }

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
  margin-top: 8px;
}

.editor-tools { display: flex; align-items: center; gap: 8px; }
.char-count { font-size: 12px; color: var(--text-tertiary); }

/* ---------- 筛选条 ---------- */

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---------- 笔记卡片 ---------- */

.memo-list { display: flex; flex-direction: column; gap: 16px; }

.memo-card { padding: 16px; position: relative; }
.memo-card.pinned { border-color: var(--text-tertiary); }

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

.memo-time { font-size: 12px; color: var(--text-tertiary); display: flex; align-items: center; gap: 8px; }

.pin-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 1px 10px;
}
.pin-badge .icon { width: 12px; height: 12px; }

.memo-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.memo-card:hover .memo-actions { opacity: 1; }
.memo-actions .icon-btn { width: 30px; height: 30px; }
.memo-actions .icon { width: 15px; height: 15px; }
.memo-actions .danger:hover { color: var(--error); border-color: var(--error); }

.memo-content { font-size: 15px; color: var(--text-primary); word-break: break-word; }
.memo-content.collapsed { max-height: 320px; overflow: hidden; }
.memo-content p { margin: 0 0 4px; }
.memo-content img {
  max-width: 240px;
  max-height: 180px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  margin: 8px 8px 0 0;
  display: inline-block;
  cursor: zoom-in;
}
.memo-content a { color: var(--text-primary); text-decoration: underline; text-underline-offset: 3px; }
.memo-content video {
  max-width: 100%;
  max-height: 360px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: #000;
  margin: 8px 0 0;
  display: block;
}
.memo-content audio { width: 100%; max-width: 420px; margin: 8px 0 0; display: block; }

.expand-toggle {
  display: inline-block;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  padding: 4px 14px;
  cursor: pointer;
}
.expand-toggle:hover { border-color: var(--text-secondary); color: var(--text-primary); }

/* 图片灯箱 */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(26, 26, 26, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-md);
}
.memo-content .memo-tag {
  display: inline-block;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}
.memo-content .memo-tag:hover { color: var(--text-primary); border-color: var(--text-tertiary); }

.memo-edit-area { width: 100%; }

.memo-edit-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  padding: 12px 16px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  outline: none;
  resize: none;
  min-height: 200px;
  max-height: 60vh;
  overflow-y: auto;
}
.memo-edit-textarea:focus { border-color: var(--text-secondary); }

.memo-edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.empty-state {
  text-align: center;
  padding: 80px 0;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* ---------- 日历 ---------- */

.calendar-panel { padding: 12px 16px; }

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 10px;
}
.cal-title { font-size: 13px; font-weight: 700; color: var(--text-primary); white-space: nowrap; }
.cal-head-right { display: flex; align-items: center; gap: 2px; }
.calendar-panel .icon-btn { width: 24px; height: 24px; border-radius: var(--radius-sm); }
.calendar-panel .icon { width: 14px; height: 14px; }
.calendar-panel .btn-text { padding: 2px 6px; font-size: 12px; }

.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-wd { text-align: center; font-size: 11px; color: var(--text-tertiary); padding: 2px 0; }

.cal-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}
.cal-cell.placeholder { cursor: default; }
.cal-cell:not(.placeholder):hover { background: var(--bg-secondary); color: var(--text-primary); }
/* 有记录的日期：整格浅灰底（不再用下方小点标记） */
.cal-cell.has-memo { background: var(--bg-soft); color: var(--text-primary); font-weight: 600; }
.cal-cell.has-memo:hover { background: var(--bg-soft-hover); color: var(--text-primary); }
.cal-cell.today { border-color: var(--text-tertiary); }
.cal-cell.selected { background: var(--accent); color: var(--accent-inverse); border-color: var(--accent); }
.cal-cell.selected:hover { background: var(--accent); color: var(--accent-inverse); }

/* ---------- 弹窗 ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
}
.modal-wide { max-width: 720px; }

/* 选项卡 */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-light);
}
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom-color: var(--accent);
}
.tab-panel { padding-top: 4px; }

/* TOTP 密钥展示 */
.totp-secret {
  font-family: "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
  font-size: 15px;
  letter-spacing: 0.1em;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 8px;
  user-select: all;
  word-break: break-all;
}
.totp-url { word-break: break-all; }

/* 回到顶部 */
.back-to-top {
  position: fixed;
  right: 32px;
  bottom: 32px;
  z-index: 90;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-inverse);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
}
.back-to-top:hover { opacity: 0.85; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-body { padding: 8px 24px 24px; }

.setting-group { padding: 20px 0; border-bottom: 1px solid var(--border-light); }
.setting-group:last-child { border-bottom: none; }
.setting-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.setting-hint { font-size: 13px; color: var(--text-tertiary); margin-bottom: 10px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.form-fields { display: flex; flex-direction: column; gap: 12px; }

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] {
  margin: 2px 0 0;
  width: 15px;
  height: 15px;
  flex: none;
  cursor: pointer;
  accent-color: var(--text-primary);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--text-tertiary);
  margin-right: 8px;
}
.status-dot.ok { background: #1a1a1a; }
.status-dot.err { background: var(--error); }

.backup-list { margin-top: 14px; display: flex; flex-direction: column; }
.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 0;
  border-top: 1px solid var(--border-light);
  font-size: 13px;
  color: var(--text-secondary);
}
.backup-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.backup-key {
  font-family: "JetBrains Mono", "Cascadia Code", "Fira Code", "Consolas", monospace;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.backup-size { font-size: 12px; color: var(--text-tertiary); }
.backup-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.backup-actions .btn-text {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  text-decoration: none;
}
.backup-actions .btn-text:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.backup-actions .danger-text:hover { color: var(--error); border-color: var(--error); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-inverse);
  border-radius: var(--radius-md);
  padding: 10px 24px;
  font-size: 14px;
  z-index: 200;
}
.toast.error { background: var(--accent-inverse); color: var(--error); border: 1px solid var(--error); }

/* ---------- 侧栏导航（笔记 / AI） ---------- */

.side-nav { padding: 8px; margin: 0; flex-shrink: 0; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--border); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.nav-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: var(--accent-inverse); font-weight: 600; }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }

/* 导航右侧计数（如归档条数） */
.nav-count { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--text-tertiary); }
.nav-item:hover .nav-count { color: var(--text-secondary); }
.nav-item.active .nav-count { color: var(--accent-inverse); }

/* ---------- 主面板 ---------- */

.panel { height: 100%; display: flex; flex-direction: column; min-width: 0; }

/* ---------- AI 问答 ---------- */

.ai-head { gap: 10px; }
.ai-conv-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.ai-context-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin: 12px 24px 0;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
}
.ai-context-label { color: var(--text-tertiary); flex-shrink: 0; }
.ai-context-text {
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 24px 8px;
}

.ai-empty {
  max-width: 820px;
  margin: 0 auto;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
  padding: 60px 20px;
  line-height: 1.8;
}

/* 消息行铺满对话区宽度（全屏自适应），不再固定 820px 居中 */
.ai-msg { display: flex; gap: 12px; margin: 0 0 18px; }
.ai-msg:last-child { margin-bottom: 0; }
.ai-msg-user { flex-direction: row-reverse; }

.ai-avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
}
.ai-msg-ai .ai-avatar { background: var(--accent); color: var(--accent-inverse); }
.ai-msg-user .ai-avatar { background: var(--bg-secondary); color: var(--text-secondary); border: 1px solid var(--border); }

.ai-msg-body { display: flex; flex-direction: column; gap: 6px; max-width: 80%; min-width: 0; }
.ai-msg-user .ai-msg-body { align-items: flex-end; }

.ai-msg-content {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
}
.ai-msg-ai .ai-msg-content { background: var(--bg-secondary); border: 1px solid var(--border-light); }
.ai-msg-user .ai-msg-content { background: var(--accent); color: var(--accent-inverse); }
.ai-msg-user .ai-msg-content a { color: var(--accent-inverse); }
.ai-msg-user .ai-msg-content code { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.24); color: #fff; }
.ai-msg-user .ai-msg-content mark { background: rgba(255, 255, 255, 0.3); color: #fff; }

.ai-msg-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.ai-msg:hover .ai-msg-actions { opacity: 1; }
.ai-msg-actions .btn-text { font-size: 12px; padding: 2px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.ai-msg-actions .btn-text:hover { border-color: var(--text-secondary); color: var(--text-primary); }

.ai-typing { color: var(--text-tertiary); font-size: 14px; animation: ai-pulse 1.4s ease-in-out infinite; }
@keyframes ai-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

.ai-error { color: var(--error); font-size: 13px; margin-top: 8px; }
.ai-stopped { color: var(--text-tertiary); font-size: 13px; margin-top: 6px; }

/* 思考过程（推理模型）：折叠块 + 左侧竖线，弱于正文 */
.ai-reasoning {
  align-self: stretch;
  border-left: 2px solid var(--border);
  font-size: 13px;
  color: var(--text-tertiary);
}
.ai-reasoning summary {
  cursor: pointer;
  padding: 2px 0 2px 10px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  user-select: none;
  list-style: none;
}
.ai-reasoning summary::-webkit-details-marker { display: none; }
.ai-reasoning summary::before { content: '▸ '; }
.ai-reasoning[open] summary::before { content: '▾ '; }
.ai-reasoning summary:hover { color: var(--text-secondary); }
.ai-reasoning-body {
  margin-top: 4px;
  padding: 6px 10px 8px;
  border-top: 1px solid var(--border-light);
  line-height: 1.65;
  word-break: break-word;
}
.ai-reasoning-body p { margin: 4px 0; }
.ai-reasoning-body ul, .ai-reasoning-body ol { margin: 4px 0; padding-left: 20px; }
.ai-reasoning-body ul { list-style: disc; }
.ai-reasoning-body ol { list-style: decimal; }
.ai-reasoning-body pre {
  margin: 6px 0;
  padding: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  overflow-x: auto;
}
.ai-reasoning-body code { font-size: 12px; }

.ai-composer { flex-shrink: 0; padding: 8px 24px 20px; }

.ai-attach-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 820px;
  margin: 0 auto 8px;
}
.ai-attach-item {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  overflow: hidden;
}
.ai-attach-item img { width: 52px; height: 52px; object-fit: cover; display: block; }
.ai-attach-name {
  padding: 8px 26px 8px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-attach-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(26, 26, 26, 0.72);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
.ai-attach-remove:hover { background: rgba(26, 26, 26, 0.9); }

.ai-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.ai-upload-btn { flex-shrink: 0; }
.ai-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  max-height: 40vh;
  min-height: 24px;
  padding: 6px 0;
}
.ai-input::placeholder { color: var(--text-tertiary); }

/* AI 会话列表（侧栏） */
.ai-session-list { margin-top: 6px; }
.ai-session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}
.ai-session-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.ai-session-item.active { background: var(--bg-secondary); color: var(--text-primary); font-weight: 600; }
.ai-session-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-session-del {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  opacity: 0;
}
.ai-session-item:hover .ai-session-del { opacity: 1; }
.ai-session-del:hover { color: var(--error); }
.ai-session-del .icon { width: 14px; height: 14px; }

/* ---------- Markdown 块级渲染 ---------- */

.memo-content .md-h { font-weight: 700; line-height: 1.4; margin: 12px 0 6px; color: var(--text-primary); }
.memo-content .md-h:first-child { margin-top: 0; }
.memo-content h1.md-h { font-size: 22px; }
.memo-content h2.md-h { font-size: 19px; }
.memo-content h3.md-h { font-size: 17px; }
.memo-content h4.md-h, .memo-content h5.md-h, .memo-content h6.md-h { font-size: 15px; }

.memo-content .md-quote {
  border-left: 3px solid var(--border);
  padding: 2px 0 2px 14px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.memo-content .md-ul, .memo-content .md-ol { margin: 6px 0; padding-left: 22px; }
.memo-content .md-ul { list-style: disc; }
.memo-content .md-ol { list-style: decimal; }
.memo-content .md-ul li, .memo-content .md-ol li { margin: 2px 0; }

.memo-content .md-task { list-style: none; margin-left: -18px; display: flex; align-items: baseline; gap: 6px; }
.memo-content .md-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  font-size: 11px;
  line-height: 1;
  color: var(--accent-inverse);
}
.memo-content .md-task.done .md-check { background: var(--accent); border-color: var(--accent); }
.memo-content .md-task.done { color: var(--text-tertiary); text-decoration: line-through; }

.memo-content .md-hr { border: none; border-top: 1px solid var(--border-light); margin: 12px 0; }

.memo-content .md-pre {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin: 8px 0;
  overflow-x: auto;
}
.memo-content .md-pre code {
  display: block;
  background: transparent;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  color: var(--text-primary);
}
.memo-content .md-pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 11px;
  color: var(--text-tertiary);
}

.memo-content mark { background: #fff3bf; color: var(--text-primary); padding: 0 3px; }

/* AI 对话代码块：浅色渲染（与笔记区一致）。
   白底 + 中性边框 + 深色文字，在浅色气泡（--bg-secondary）中以白底形成层次对比。
   选择器 specificity 高于 .memo-content .md-pre，不依赖书写顺序。 */
.ai-msg .ai-msg-content .md-pre {
  background: #ffffff;
  border-color: var(--border);
}
.ai-msg .ai-msg-content .md-pre code { color: var(--text-primary); }
.ai-msg .ai-msg-content .md-pre[data-lang]::before { color: var(--text-tertiary); }
.ai-msg .ai-msg-content .md-pre ::selection { background: rgba(0, 0, 0, 0.12); }
/* 用户气泡本身是深色，代码块用半透明白覆盖以保证在深底上可读 */
.ai-msg-user .ai-msg-content .md-pre { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.2); }
.ai-msg-user .ai-msg-content .md-pre code { color: #fff; }
.ai-msg-user .ai-msg-content .md-pre[data-lang]::before { color: rgba(255, 255, 255, 0.6); }

/* ---------- Vditor 编辑器（黑白灰覆盖） ---------- */

.editor-mount { width: 100%; }
.editor-mount.vditor { border: none !important; border-radius: 0 !important; background: transparent !important; }

.edit-vditor {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  overflow: hidden;
}

.editor-mount .vditor-toolbar,
.edit-vditor .vditor-toolbar {
  background: transparent !important;
  border-bottom: 1px solid var(--border-light) !important;
  padding: 0 0 8px !important;
  margin: 0 0 8px !important;
}
.edit-vditor .vditor-toolbar { padding: 8px 10px !important; margin: 0 !important; background: var(--bg-secondary) !important; }

.editor-mount .vditor-content,
.edit-vditor .vditor-content { background: transparent !important; }

.editor-mount .vditor-reset,
.edit-vditor .vditor-reset {
  background: transparent !important;
  color: var(--text-primary) !important;
  font-family: inherit !important;
  font-size: 15px !important;
  line-height: 1.7 !important;
  caret-color: var(--accent);
}
.editor-mount .vditor-reset { padding: 2px 0 !important; min-height: 72px !important; }
.edit-vditor .vditor-reset { padding: 12px 16px !important; min-height: 180px !important; }

.editor-mount .vditor-reset img,
.edit-vditor .vditor-reset img { max-width: 240px; border-radius: var(--radius-md); }

.editor-mount .vditor-toolbar__item,
.edit-vditor .vditor-toolbar__item { color: var(--text-secondary); }

/* Vditor 全屏修正：
   Vditor 自带的 .vditor--fullscreen 只设了 position/z-index，并未设背景，
   而上方 .editor-mount.vditor 为了融入卡片把背景改成了 transparent !important。
   全屏后编辑器脱离卡片，整块变透明 → 透出底下页面，表现为“丢失样式”。
   此处补回不透明底、层级与居中排版（specificity 0,3,0 高于上方覆盖规则）。 */
.editor-mount.vditor--fullscreen,
.edit-vditor.vditor--fullscreen {
  z-index: 150 !important;
  background: var(--bg-card) !important;
  border: none !important;
  padding: 10px 20px 20px !important;
}
.editor-mount.vditor--fullscreen .vditor-toolbar,
.edit-vditor.vditor--fullscreen .vditor-toolbar {
  width: 100%;
  max-width: 900px;
  margin: 0 auto 8px !important;
  padding: 4px 0 10px !important;
  background: var(--bg-card) !important;
  border-bottom: 1px solid var(--border) !important;
}
.editor-mount.vditor--fullscreen .vditor-content,
.edit-vditor.vditor--fullscreen .vditor-content { background: var(--bg-card) !important; }
.editor-mount.vditor--fullscreen .vditor-reset,
.edit-vditor.vditor--fullscreen .vditor-reset {
  max-width: 900px;
  margin: 0 auto !important;
  padding: 16px 0 !important;
  min-height: 0 !important;
  background: var(--bg-card) !important;
  font-size: 16px !important;
}
.editor-mount.vditor--fullscreen .vditor-reset img,
.edit-vditor.vditor--fullscreen .vditor-reset img { max-width: 100%; }

/* ---------- 响应式 ---------- */

@media (max-width: 768px) {
  .menu-btn { display: inline-flex; }
  .notes-head { display: flex; }
  .nav-backdrop { display: block; top: 0; }
  /* 侧边栏改为全高离屏抽屉，通过汉堡按钮开关 */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 84vw;
    background: var(--bg);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 60;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .panel-head { padding: 0 12px; }
  .panel-scroll { padding: 16px 14px 24px; }
  .ai-messages { padding: 16px 14px 4px; }
  .ai-composer { padding: 6px 14px 14px; }
  .ai-context-bar { margin: 10px 14px 0; }
  .tag-list { flex-direction: column; flex-wrap: nowrap; }
  .tag-item { width: 100%; }
  .memo-actions { opacity: 1; }
  .ai-msg-actions { opacity: 1; }
  .memo-content video { max-height: 240px; }
  .ai-msg-body { max-width: 88%; }
}
