/* =====================================================================
 * styles.css — 响应式：桌面顶部导航，手机底部导航
 * ===================================================================*/
:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #23201c;
  --muted: #7a7267;
  --line: #e6e0d6;
  --brand: #1f6f5c;
  --brand-soft: #e6f1ed;
  --warn: #b4531f;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(35, 32, 28, .06), 0 6px 18px rgba(35, 32, 28, .05);
  --nav-h: 58px;
  --safe: 0px;   /* iPhone 底部安全区，见下方 @supports */
}

/* 支持安全区的浏览器（iPhone 刘海/指示条）才启用，老浏览器保持 0px 不会算崩 */
@supports (padding: env(safe-area-inset-bottom)) {
  :root { --safe: env(safe-area-inset-bottom, 0px); }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 20px; margin: 4px 0 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }
h4 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); }
p { margin: 6px 0; }
code { background: #f0ece4; padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px;
  background: rgba(246, 244, 239, .92);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .3px; }
.brand .logo { font-size: 18px; }
.tabs-top { display: flex; gap: 4px; margin-left: auto; }
.tab-top {
  padding: 6px 14px; border-radius: 999px; color: var(--ink);
  font-size: 14px; white-space: nowrap;
}
.tab-top:hover { background: #eee9df; text-decoration: none; }
.tab-top.active { background: var(--brand); color: #fff; }

/* ---------- 主体 ---------- */
.view {
  max-width: 900px;
  margin: 0 auto;
  padding: 18px 18px calc(var(--nav-h) + var(--safe) + 28px);
}
.tabs-bottom { display: none; }

/* ---------- 卡片与布局 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 0 14px;
}
.row { display: flex; align-items: center; gap: 8px; }
.row.gap { gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.list { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace; }
.hidden { display: none; }
.tight { margin: 6px 0; padding-left: 20px; }
.tight li { margin: 6px 0; }
.err { color: var(--danger); }
.warn { color: var(--warn); margin: 8px 0; padding-left: 20px; font-size: 13px; }
.pre {
  background: #f4f1ea; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; overflow: auto; max-height: 260px; font-size: 12px; white-space: pre-wrap;
}
.stars { color: #d9a13b; letter-spacing: 1px; font-size: 12px; }
.empty { text-align: center; padding: 26px 18px; }
.empty h3 { margin-bottom: 6px; }
.empty-inline { padding: 18px; text-align: center; font-size: 13.5px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-size: 14px; font-family: inherit; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f2eee6; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1a5f4f; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eee9df; color: var(--ink); }
.btn.ghost.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { border-color: #e8c9c6; color: var(--danger); }
.btn.danger:hover { background: #fbeeed; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: #efeae1; color: var(--muted); font-size: 12px;
}
.badge.ok { background: var(--brand-soft); color: var(--brand); }

/* ---------- 表单 ---------- */
.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font: inherit; font-size: 14px;
}
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea.input { resize: vertical; line-height: 1.6; }
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 14px; }
.check input { width: 16px; height: 16px; }
.search { margin: 12px 0; }

/* ---------- 书架 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 4px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; text-align: center; box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.book-card { display: flex; gap: 12px; align-items: flex-start; }
.book-main { flex: 1; min-width: 0; }
.book-title { font-size: 16px; font-weight: 600; display: block; margin-bottom: 2px; }
.book-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.progress { height: 6px; background: #ece7dd; border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .25s; }
.meta { font-size: 13px; }

/* ---------- 书详情 ---------- */
.book-head { margin-bottom: 6px; }
.book-head h2 { margin: 8px 0 2px; }
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 4px 0 10px;
  border-bottom: 1px solid var(--line); margin-bottom: 14px;
  -webkit-overflow-scrolling: touch;
}
.tab { padding: 6px 12px; border-radius: 999px; color: var(--muted); white-space: nowrap; font-size: 14px; }
.tab:hover { background: #eee9df; text-decoration: none; }
.tab.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.chapter-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 320px; overflow: auto; }
.chapter-list li { border-top: 1px dashed var(--line); padding: 6px 0; font-size: 13.5px; }
.chapter-list li:first-child { border-top: 0; }
.check span { line-height: 1.5; }

/* ---------- 笔记 / 想法 ---------- */
.chapter-block { margin: 0 0 14px; }
.chapter-block h4 { margin: 0 0 8px; color: var(--ink); font-size: 14px; }
.note {
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid #cfd8d4;
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
}
.note.thought { border-left-color: var(--brand); background: #fbfdfc; }
.note-tag { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.note-text { font-size: 14.5px; line-height: 1.7; word-break: break-word; }
.note .row { margin-top: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: #efeae1; color: var(--muted); font-size: 12px;
}
.chip.small { font-size: 11.5px; padding: 2px 7px; }
.btn-chip { border: 1px solid var(--line); cursor: pointer; font-family: inherit; }
.btn-chip:hover { background: var(--brand-soft); color: var(--brand); }
.btn-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.idea-card .note-text { font-size: 14.5px; }
.advice { border-color: #cfe3da; background: #fbfdfc; }

/* ---------- 聊天 ---------- */
.chat-card .chips { margin-bottom: 10px; }
.chat-list { max-height: 52vh; overflow: auto; padding: 4px 2px; }
.msg { max-width: 86%; margin: 10px 0; padding: 10px 12px; border-radius: 12px; }
.msg.me { margin-left: auto; background: var(--brand-soft); }
.msg.ai { background: #fff; border: 1px solid var(--line); }
.msg-body { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; }
.msg-time { font-size: 11px; color: var(--muted); margin-top: 6px; }
.chat-input { align-items: flex-end; margin-top: 10px; }
.chat-input textarea { flex: 1; }
.rec-card p { font-size: 14px; }

/* ---------- 模态 / 提示 / 遮罩 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(30, 27, 24, .42);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px;
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modal.wide { max-width: 720px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 14px 16px; overflow: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
.icon-btn {
  border: 0; background: transparent; font-size: 16px; cursor: pointer;
  color: var(--muted); padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: #eee9df; }

#toast-root {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: #23201c; color: #fff; padding: 9px 14px; border-radius: 10px;
  font-size: 13.5px; box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  opacity: 1; transition: opacity .3s, transform .3s;
}
.toast.error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }

.busy-mask {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(246, 244, 239, .72);
  display: flex; align-items: center; justify-content: center;
}
.busy-box {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 26px; text-align: center; box-shadow: var(--shadow); max-width: 320px;
}
.spinner {
  width: 26px; height: 26px; margin: 0 auto 10px;
  border: 3px solid #e2ded5; border-top-color: var(--brand); border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.preview-chapter { border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 8px; }

/* ---------- 手机 ---------- */
@media (max-width: 760px) {
  .tabs-top { display: none; }
  .view { padding: 14px 14px calc(var(--nav-h) + var(--safe) + 30px); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .msg { max-width: 94%; }

  .tabs-bottom {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; height: calc(var(--nav-h) + var(--safe));
    background: rgba(255, 255, 255, .96);
    border-top: 1px solid var(--line);
    padding-bottom: var(--safe);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  .tab-bottom {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: var(--muted); font-size: 11px;
  }
  .tab-bottom:hover { text-decoration: none; }
  .tab-bottom.active { color: var(--brand); font-weight: 600; }
  .tab-bottom .ico { font-size: 17px; line-height: 1; }
  #toast-root { bottom: calc(var(--nav-h) + var(--safe) + 12px); }
}

/* 桌面端没有底部导航，提示条贴近底部即可 */
@media (min-width: 761px) {
  #toast-root { bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .progress i { transition: none; }
  .toast { transition: none; }
}

/* ---------- V2：封面 / 标签体系 / 归类预览 ---------- */
.cover {
  width: 46px; height: 64px; border-radius: 6px; object-fit: cover;
  flex: 0 0 auto; background: #ece7dd;
}
.cover-empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--muted);
}
.tag-new .input { flex: 1 1 170px; }
.folder-bar { margin: 12px 0 2px; }
.folder-bar .chip { cursor: pointer; font-family: inherit; }
.folder-bar .chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.move-btns { display: inline-flex; gap: 2px; }
.move-btns .btn { padding: 2px 6px; font-size: 11px; line-height: 1.2; }

/* 渲染失败时的兜底面板（不许白屏） */
.fatal {
  max-width: 720px; margin: 40px auto; padding: 20px;
  background: #fff; border: 1px solid #e8c9c6; border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.fatal h3 { color: var(--danger); margin-top: 0; }
.fatal details { margin: 10px 0; }
.fatal summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.tag-new .small-input { flex: 0 1 150px; }
.tag-group { margin: 10px 0; }
.tag-group-name { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.tag-item {
  display: inline-flex; align-items: center; gap: 1px;
  background: #efeae1; border-radius: 999px; padding-right: 3px;
}
.tag-item.on { background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand) inset; }
.tag-item .chip { background: transparent; }
.tag-tool {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 2px 4px; border-radius: 6px; line-height: 1;
}
.tag-tool:hover { background: #fff; color: var(--ink); }
.tag-tool.danger:hover { color: var(--danger); }
.chip.new-tag { background: #fdf1dc; color: #8a5a12; }
.classify-row { border-top: 1px dashed var(--line); padding: 10px 0; }
.classify-row:first-of-type { border-top: 0; }

@media (max-width: 760px) {
  .cover { width: 40px; height: 56px; }
}
