/* ============================================================
   Knowledge Hub — iOS 风格设计系统
   基于 iOS HIG：系统色、SF 字体栈、圆角、毛玻璃、深浅色模式
   ============================================================ */

/* ---------- 设计令牌 ---------- */
:root {
  /* 浅色模式（iOS 系统色） */
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --card2: #F9F9FB;
  --separator: rgba(60, 60, 67, 0.12);
  --label: #000000;
  --label2: rgba(60, 60, 67, 0.6);
  --label3: rgba(60, 60, 67, 0.3);
  --tint: #007AFF;
  --tint-pressed: #0063D9;
  --tint-soft: rgba(0, 122, 255, 0.12);
  --fill: rgba(120, 120, 128, 0.12);
  --nav-bg: rgba(249, 249, 249, 0.82);
  --green: #34C759;
  --red: #FF3B30;
  --orange: #FF9500;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px rgba(0, 0, 0, 0.05);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.08);
  --radius-card: 14px;
  --radius-btn: 12px;
  --radius-field: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1C1C1E;
    --card2: #2C2C2E;
    --separator: rgba(84, 84, 88, 0.6);
    --label: #FFFFFF;
    --label2: rgba(235, 235, 245, 0.6);
    --label3: rgba(235, 235, 245, 0.3);
    --tint: #0A84FF;
    --tint-pressed: #409CFF;
    --tint-soft: rgba(10, 132, 255, 0.22);
    --fill: rgba(120, 120, 128, 0.24);
    --nav-bg: rgba(18, 18, 20, 0.82);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lift: 0 2px 8px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1C1C1E;
  --card2: #2C2C2E;
  --separator: rgba(84, 84, 88, 0.6);
  --label: #FFFFFF;
  --label2: rgba(235, 235, 245, 0.6);
  --label3: rgba(235, 235, 245, 0.3);
  --tint: #0A84FF;
  --tint-pressed: #409CFF;
  --tint-soft: rgba(10, 132, 255, 0.22);
  --fill: rgba(120, 120, 128, 0.24);
  --nav-bg: rgba(18, 18, 20, 0.82);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lift: 0 2px 8px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--label);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; color: var(--label); }

/* ---------- 导航栏（毛玻璃） ---------- */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--nav-bg);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--separator);
  position: relative;
  z-index: 10;
}
.nav-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.nav-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-count { font-size: 13px; color: var(--label3); font-weight: 400; }
.nav-actions { display: flex; gap: 4px; align-items: center; flex: none; }

/* 返回按钮：仅手机编辑态显示 */
.back-btn { display: none; }

/* 手机端悬浮新建按钮（FAB）：仅列表页显示 */
.fab {
  display: none;
  position: fixed; right: 22px; bottom: 28px;
  width: 56px; height: 56px;
  border: none; border-radius: 50%;
  background: var(--tint);
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 122, 255, 0.45);
  align-items: center; justify-content: center;
  z-index: 40;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.fab:active { transform: scale(0.92); }

/* 版本号：桌面左下角 / 手机右下角（FAB 左侧垂直居中） */
.version-tag {
  position: fixed; left: 16px; bottom: 12px;
  font-size: 11px;
  color: var(--label3);
  opacity: 0.75;
  user-select: none;
  z-index: 30;
  pointer-events: none;
}

/* ---------- 图标按钮（iOS 风格） ---------- */
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%;
  background: transparent;
  color: var(--tint);
  transition: background 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { background: var(--tint-soft); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.tint { color: var(--tint); }
.icon-btn:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; }

/* ---------- 布局 ---------- */
.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 330px;
  display: flex; flex-direction: column;
  gap: 10px;
  padding: 14px 14px 10px;
  border-right: 0.5px solid var(--separator);
  background: transparent;
}

/* ---------- 搜索栏（iOS search bar） ---------- */
.search-bar {
  display: flex; align-items: center; gap: 6px;
  height: 36px;
  padding: 0 10px;
  background: var(--fill);
  border-radius: var(--radius-field);
  color: var(--label3);
}
.search-bar svg { flex: none; }
#searchInput {
  flex: 1;
  border: none; background: transparent; outline: none;
  font-size: 16px;
  color: var(--label);
}
#searchInput::placeholder { color: var(--label3); }
#searchInput::-webkit-search-cancel-button { display: none; }

/* ---------- 分段控件（iOS Segmented Control） ---------- */
.segmented {
  display: flex;
  padding: 2px;
  background: var(--fill);
  border-radius: 9px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: 1;
  min-width: 52px;
  height: 30px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--label2);
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.segmented button:hover { color: var(--label); }
.segmented button.active {
  background: var(--card);
  color: var(--label);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ---------- 笔记列表（inset grouped 卡片） ---------- */
.note-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px 2px 12px;
  scrollbar-width: thin;
}
.note-list li {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 12px 14px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  border: 0.5px solid transparent;
  animation: cardIn 0.35s ease-out backwards;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.note-list li:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lift);
}
.note-list li.active {
  border-color: var(--tint);
  background: var(--tint-soft);
}
.note-list li .title {
  font-size: 16px; font-weight: 600;
  display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.note-list li .summary {
  font-size: 13px; color: var(--label2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 3px;
  line-height: 1.45;
}
.note-list li .meta {
  display: flex; align-items: center; gap: 6px;
  margin-top: 7px;
}
.note-list li .time { font-size: 12px; color: var(--label3); margin-left: auto; }
.note-list li .star { color: var(--orange); font-size: 13px; }
.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--label2);
  white-space: nowrap;
}
.note-list .empty {
  text-align: center;
  color: var(--label3);
  padding: 40px 12px;
  font-size: 14px;
  background: transparent;
  box-shadow: none; cursor: default; animation: none;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 编辑区（iOS 卡片） ---------- */
.editor {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 16px 20px;
  min-width: 0;
}
.editor-card {
  flex: 1;
  display: flex; flex-direction: column;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  min-height: 0;
}
.editor-head {
  display: flex; align-items: center; gap: 8px;
  border-bottom: 0.5px solid var(--separator);
  padding-bottom: 10px;
}
.title-input {
  flex: 1;
  border: none; outline: none; background: transparent;
  font-size: 26px; font-weight: 700;
  letter-spacing: -0.02em;
  min-width: 0;
}
.title-input::placeholder { color: var(--label3); }
.meta-row {
  display: flex; gap: 8px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--separator);
}
.meta-input {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius-field);
  background: var(--fill);
  font-size: 14px;
  outline: none;
  min-width: 0;
}
.meta-input::placeholder { color: var(--label3); }
.meta-input:focus { background: var(--card2); }

/* ---------- 分类快速选择 chips ---------- */
.cat-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 0 8px;   /* 顶部留白，避免与 meta-row 分割线贴住 */
}
.cat-chips .chip {
  padding: 5px 12px;
  border: none; border-radius: 999px;
  background: var(--fill);
  color: var(--label2);
  font-size: 12.5px;
  transition: background 0.15s ease, color 0.15s ease;
}
.cat-chips .chip.active { background: var(--tint); color: #fff; font-weight: 600; }
.cat-chips .chip:hover { color: var(--label); }
#contentInput {
  flex: 1;
  border: none; outline: none; background: transparent;
  resize: none;
  font-size: 15px; line-height: 1.7;
  padding: 12px 2px;
  min-height: 0;
}
#contentInput::placeholder { color: var(--label3); }

/* ---------- 内容总结（可折叠/删除/调位置） ---------- */
.summary-block {
  margin-top: 12px;
  margin-bottom: 16px; /* 与下方工具栏分隔线拉开距离 */
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--card2);
  border: 0.5px solid var(--separator);
}
.summary-block.collapsed .summary-text { display: none; }
.summary-block.collapsed { padding-bottom: 8px; }
.summary-block.compact .summary-text { font-size: 12.5px; line-height: 1.5; }
.summary-block.compact { padding: 8px 10px; }
.summary-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.summary-title {
  font-size: 13px; font-weight: 700;
  color: var(--tint);
}
.summary-actions { display: flex; align-items: center; gap: 6px; position: relative; }
.summary-btn {
  width: 26px; height: 26px;
  border: none; border-radius: 8px;
  background: transparent;
  color: var(--label2);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.12s ease;
}
.summary-btn:hover { background: var(--card2); }
.summary-menu-wrap { position: relative; }
.summary-menu {
  position: absolute; right: 0; top: 30px; z-index: 60;
  min-width: 132px;
  background: var(--card);
  border: 0.5px solid var(--separator);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  padding: 6px;
  display: flex; flex-direction: column;
}
.summary-menu.hidden { display: none; }
.summary-menu button {
  border: none; background: transparent;
  text-align: left; padding: 9px 10px;
  font-size: 13.5px; color: var(--label);
  border-radius: 8px;
  cursor: pointer;
}
.summary-menu button:hover { background: var(--card2); }
.summary-menu button.danger { color: #ff3b30; }
.summary-text {
  font-size: 14px; line-height: 1.7;
  color: var(--label2);
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 6px;
}
.summary-block.hidden { display: none; }

.editor-toolbar {
  display: flex; gap: 8px;
  padding-top: 10px;
  border-top: 0.5px solid var(--separator);
}
/* 工具栏按钮图标统一规格（智能整理/图片/保存/删除一致） */
.editor-toolbar .btn svg { width: 15px; height: 15px; flex: none; }

/* ---------- 按钮（iOS） ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-btn);
  background: var(--fill);
  white-space: nowrap;   /* 文字不换行 */
  overflow: hidden;
  color: var(--label);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--card2); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--tint); color: #FFFFFF; }
.btn.primary:hover { background: var(--tint-pressed); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: rgba(255, 59, 48, 0.1); }
.btn:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; }

/* ---------- 下拉菜单 ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute; right: 0; top: 42px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow-lift);
  border: 0.5px solid var(--separator);
  min-width: 200px;
  z-index: 30;
  padding: 6px;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}
.dropdown-menu.show { display: block; animation: cardIn 0.18s ease-out; }
.dropdown-menu a {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--label);
  font-size: 14px;
}
.dropdown-menu a svg { flex: none; opacity: 0.75; }
.dropdown-menu a span { white-space: nowrap; }
.dropdown-menu a:hover { background: var(--fill); }

/* ---------- 状态栏 / Toast ---------- */
.statusbar {
  padding: 8px 4px 0;
  color: var(--label3);
  font-size: 12px;
  height: 26px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast {
  position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%);
  background: rgba(28, 28, 30, 0.92);
  color: #FFFFFF;
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  transition: opacity 0.25s ease, transform 0.25s ease;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(8px); pointer-events: none; }

/* ---------- 模态框（iOS 风格） ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card);
  border-radius: 20px;
  padding: 24px 26px;
  width: 420px;
  max-width: 92vw;
  box-shadow: var(--shadow-lift);
}
.modal-card h3 { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.modal-card label { display: block; font-size: 14px; margin-bottom: 12px; }
.modal-card input {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-field);
  background: var(--fill);
  font-size: 14px;
  outline: none;
}
.modal-card input:focus { background: var(--card2); }
.modal-card .hint { color: var(--label2); font-size: 12px; margin: 10px 0 16px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- 响应式（375 / 768 / 1024 / 1440） ---------- */
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 0.5px solid var(--separator); max-height: 42%; }
  .note-list { max-height: none; }
  .nav-title { font-size: 24px; }
  .editor { padding: 12px; }
  .title-input { font-size: 22px; }
}
/* 手机端适配（≤480px，覆盖 OPPO Find X7 Ultra ~411px 视口宽） */
@media (max-width: 480px) {
  .nav { padding: 8px 12px; }
  .nav-left { flex: 1; min-width: 0; gap: 6px; }
  /* 手机版隐藏导航标题：窄屏下“我的知识库”被省略号截断（如“我的知…”），直接去掉为操作按钮让位 */
  .nav-title { display: none; }
  .nav-count { display: none; }
  .icon-btn { width: 40px; height: 40px; }
  .nav-actions { flex: none; gap: 2px; }
  /* 编辑态隐藏“返回智汇台”按钮为标题让位（返回列表即可） */
  body.editing #btnHome { display: none; }

  .sidebar { max-height: none; height: 100%; padding: 10px 10px 8px; gap: 8px; }
  .search-bar { height: 40px; }
  .segmented button { height: 32px; min-width: 48px; font-size: 12.5px; }

  /* 手机端：默认仅显示笔记列表（占满全屏），新建/点卡片才进入编辑界面（占满全屏） */
  body.editing .back-btn { display: inline-flex; }
  .editor { display: none; }
  body.editing .editor { display: flex; height: 100%; }
  body.editing .sidebar { display: none; }
  /* 编辑卡片可整体滚动：正文/总结/工具栏超长时完整可见（修复总结显示不全） */
  .editor-card { overflow-y: auto; }
  .fab { display: inline-flex; }
  body.editing .fab { display: none; }

  /* 手机端版本号：列表态左下角（右下为 FAB）；编辑态右下角（FAB 隐藏，避开左下状态栏文字） */
  .version-tag { left: 12px; right: auto; bottom: 8px; }
  body.editing .version-tag { left: auto; right: 12px; }
  /* 编辑态状态栏文字右侧让位，避免长文本延伸到右下角版本号 */
  body.editing .statusbar { padding-right: 64px; }

  /* 手机端总结菜单：固定在视口右下上方（不随编辑器滚动/布局漂移，避免遮挡正文） */
  .summary-menu {
    position: fixed;
    right: 14px;
    top: auto;
    bottom: 96px;
    z-index: 300;
    min-width: 150px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
  }

  /* 手机端工具栏紧凑：4 按钮均分不溢出 */
  .editor-toolbar .btn { flex: 1; height: 44px; padding: 0 4px; font-size: 13px; }
  .editor-toolbar .btn svg { width: 14px; height: 14px; flex: none; }

  .note-list { gap: 6px; }
  .note-list li { padding: 10px 12px; }
  .note-list li .title { font-size: 15px; }
  .note-list li .summary { font-size: 12px; }
  .note-list li .time { font-size: 11px; }

  .editor { padding: 8px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .editor-card { padding: 14px; border-radius: 16px; }
  .title-input { font-size: 20px; }
  .meta-input { font-size: 13px; padding: 8px 10px; }
  #contentInput { font-size: 14.5px; padding: 10px 2px; }

  /* 工具栏按钮均分 + 加大触控区（≥44px，iOS 触控标准） */
  .editor-toolbar { gap: 6px; }

  .statusbar { font-size: 11px; }
  .modal-card { padding: 20px 18px; border-radius: 18px; }
  .dropdown-menu { min-width: 180px; }
  .toast { bottom: 24px; font-size: 13px; padding: 10px 18px; }
}
@media (min-width: 1440px) {
  .sidebar { width: 380px; }
  .editor { padding: 24px 32px; }
}

/* ---------- 减少动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
