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

[hidden] { display: none !important; }

:root {
  --bg: #f6f7f9;
  --sidebar-bg: #1e2430;
  --sidebar-fg: #cbd3e1;
  --accent: #4f7cff;
  --accent-soft: #e8eeff;
  --border: #e3e6ec;
  --text: #22272e;
  --text-dim: #6b7280;
  --radius: 12px;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

#app { display: flex; height: 100vh; }

/* ---------- 侧边栏 ---------- */
#sidebar {
  width: 290px; min-width: 290px;
  background: var(--sidebar-bg); color: var(--sidebar-fg);
  display: flex; flex-direction: column;
  padding: 18px 14px;
}
.sidebar-header { padding: 4px 6px 16px; }
.brand-mark {
  font-size: 15px; font-weight: 700; letter-spacing: 3px;
  color: var(--accent); margin-bottom: 8px;
}
.logo { font-size: 17px; font-weight: 700; color: #fff; letter-spacing: .5px; }

.upload-btn {
  display: block; text-align: center;
  background: var(--accent); color: #fff;
  padding: 11px; border-radius: var(--radius);
  cursor: pointer; font-size: 14px; font-weight: 600;
  transition: background .15s;
}
.upload-btn:hover { background: #3d68e8; }

#compare-entry {
  display: block; width: 100%; text-align: center;
  margin-top: 10px; padding: 10px;
  background: rgba(255,255,255,.06); color: var(--sidebar-fg);
  border: 1px dashed rgba(255,255,255,.25); border-radius: var(--radius);
  cursor: pointer; font-size: 13.5px; font-weight: 600;
  transition: background .15s, border-color .15s;
}
#compare-entry:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.45); }

.library-toolbar { display: flex; gap: 8px; margin-top: 10px; }
#book-search {
  flex: 1; min-width: 0;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px; padding: 8px 10px;
  color: #fff; font-size: 13px; outline: none;
}
#book-search::placeholder { color: #8b93a5; }
#book-search:focus { border-color: var(--accent); }
#new-folder-btn {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px; color: var(--sidebar-fg);
  cursor: pointer; padding: 0 10px; font-size: 13px; white-space: nowrap;
}
#new-folder-btn:hover { background: rgba(255,255,255,.15); }

#book-list { flex: 1; overflow-y: auto; margin-top: 10px; }

.folder-header {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 8px 6px; margin-top: 4px;
  color: #aab3c5; font-size: 13px; font-weight: 600;
  cursor: pointer; border-radius: 8px; user-select: none;
}
.folder-header:hover { background: rgba(255,255,255,.05); }
.folder-caret { width: 12px; font-size: 11px; color: #8b93a5; }
.folder-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-count {
  font-size: 11px; color: #8b93a5;
  background: rgba(255,255,255,.08); border-radius: 8px; padding: 1px 7px;
}
.folder-actions { display: none; gap: 2px; }
.folder-header:hover .folder-actions { display: flex; }
.folder-actions button {
  background: none; border: none; cursor: pointer;
  font-size: 12px; color: #8b93a5; padding: 0 3px;
}
.folder-actions button:hover { color: #fff; }
.folder-books { margin-left: 6px; }

.list-empty { color: #8b93a5; font-size: 13px; text-align: center; padding: 24px 0; }

.book-item {
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  margin-bottom: 6px; position: relative;
  transition: background .12s;
}
.book-item:hover { background: rgba(255,255,255,.07); }
.book-item.active { background: rgba(79,124,255,.25); }
.book-title {
  font-size: 14px; color: #fff; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-right: 22px;
}
.book-meta { font-size: 12px; color: #8b93a5; margin-top: 3px; }
.book-meta.error { color: #ff8a8a; }

.progress-bar {
  height: 4px; background: rgba(255,255,255,.12);
  border-radius: 2px; margin-top: 7px; overflow: hidden;
}
.progress-bar > div { height: 100%; background: var(--accent); transition: width .3s; }

.book-actions {
  position: absolute; right: 8px; top: 10px;
  display: none; gap: 2px;
}
.book-item:hover .book-actions { display: flex; }
.book-actions button {
  background: none; border: none; color: #8b93a5;
  cursor: pointer; font-size: 14px; padding: 0 2px;
}
.book-actions .book-delete:hover { color: #ff8a8a; }
.book-actions .book-move:hover { color: #fff; }

.sidebar-footer { padding-top: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer .ghost-btn { color: var(--sidebar-fg); width: 100%; text-align: left; }

/* ---------- 主区域 ---------- */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 14px;
}

#chat-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 26px; background: #fff; border-bottom: 1px solid var(--border);
}
#chat-title { font-size: 16px; font-weight: 700; }
#chat-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

#messages { flex: 1; overflow-y: auto; padding: 26px 0; }

.msg { max-width: 960px; margin: 0 auto 20px; padding: 0 26px; display: flex; gap: 12px; }
.msg .avatar {
  width: 34px; height: 34px; min-width: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.msg.user .avatar { background: var(--accent); color: #fff; }
.msg.assistant .avatar { background: #fff; border: 1px solid var(--border); }
.msg .bubble {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  font-size: 14px; line-height: 1.75; overflow-wrap: break-word; min-width: 0;
}
.msg.user .bubble { background: var(--accent-soft); border-color: transparent; }

.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; font-size: 15px; }
.bubble p { margin: 6px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble pre { background: #f0f2f5; padding: 10px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.bubble strong { font-weight: 700; }

.sources {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border);
  font-size: 12px; color: var(--text-dim);
}
.sources summary { cursor: pointer; font-weight: 600; }
.source-item { margin: 6px 0 0; padding: 7px 10px; background: #f7f8fa; border-radius: 8px; }
.source-page { color: var(--accent); font-weight: 600; margin-right: 6px; }

.typing { color: var(--text-dim); font-style: italic; }

/* ---------- 多书对比 ---------- */
#compare-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#compare-title { font-size: 16px; font-weight: 700; }
#compare-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

#compare-picker {
  padding: 8px 26px 12px; background: #fff; border-bottom: 1px solid var(--border);
}
.cmp-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 8px 4px; margin: 0;
  background: none; border: none; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--text); text-align: left;
}
.cmp-toggle:hover { color: var(--accent); }
#cmp-toggle-arrow { color: var(--text-dim); font-size: 12px; transition: transform .15s; }
#compare-picker.collapsed #cmp-toggle-arrow { transform: rotate(-90deg); }
#compare-picker.collapsed #cmp-body { display: none; }
#cmp-body { margin-top: 4px; }
.picker-hint { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }

#cmp-selected {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-bottom: 10px;
}
.sel-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 3px 6px 3px 12px;
  max-width: 240px; overflow: hidden;
}
.sel-chip button {
  background: none; border: none; color: var(--accent);
  font-size: 14px; cursor: pointer; line-height: 1; padding: 0 3px;
}
.sel-chip button:hover { color: #d33; }

.cmp-controls { display: flex; gap: 8px; }
#cmp-folder {
  border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 10px; font-size: 13px; background: #fff;
  outline: none; max-width: 190px; cursor: pointer;
}
#cmp-search {
  flex: 1; border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 12px; font-size: 13px; outline: none;
}
#cmp-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,124,255,.12); }

#cmp-results {
  max-height: 180px; overflow-y: auto; margin-top: 8px;
  border: 1px solid var(--border); border-radius: 10px; padding: 4px;
}
.cmp-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; user-select: none;
}
.cmp-item:hover { background: #f4f6fa; }
.cmp-item.on { background: var(--accent-soft); }
.cmp-item input { accent-color: var(--accent); }
.cmp-item-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmp-item-folder {
  font-size: 11.5px; color: var(--text-dim);
  background: #f0f2f5; padding: 1px 8px; border-radius: 8px; white-space: nowrap;
}

#folder-options { max-height: 260px; overflow-y: auto; margin: 6px 0 4px; }
.folder-option {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 9px; cursor: pointer;
  font-size: 14px; border: 1px solid transparent; margin-bottom: 2px;
}
.folder-option:hover { background: #f4f6fa; }
.folder-option.on {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--accent); font-weight: 600;
}

#compare-messages { flex: 1; overflow-y: auto; padding: 26px 0; }

.compare-asked-books {
  font-size: 12px; font-weight: 700; color: var(--accent);
  margin-bottom: 6px;
}

.source-group { margin-top: 10px; }
.source-group-title { font-weight: 700; color: var(--text); margin-bottom: 2px; }

.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.bubble th { background: #f0f2f5; }

/* ---------- 输入框 ---------- */
.composer {
  display: flex; gap: 10px; align-items: flex-end;
  max-width: 960px; width: 100%; margin: 0 auto;
  padding: 14px 26px 22px;
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 16px;
  font-size: 14px; font-family: inherit; line-height: 1.5;
  background: #fff; outline: none; max-height: 200px; min-height: 48px;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,124,255,.12); }
.composer button {
  width: 44px; height: 44px; border: none; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 17px;
  cursor: pointer; transition: background .15s;
}
.composer button:hover { background: #3d68e8; }
.composer button:disabled { background: #b9c4dd; cursor: not-allowed; }

/* ---------- 按钮 / 弹窗 ---------- */
.ghost-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 13px; padding: 8px 10px; border-radius: 8px;
}
.ghost-btn:hover { background: rgba(127,127,127,.12); }

.primary-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 9px 22px; border-radius: 9px; font-size: 14px; cursor: pointer;
}
.primary-btn:hover { background: #3d68e8; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(15,18,25,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: #fff; border-radius: 16px; padding: 26px 28px;
  width: 420px; max-width: 92vw;
}
.modal h3 { margin-bottom: 6px; }
.modal .hint { font-size: 12.5px; color: var(--text-dim); margin-bottom: 16px; line-height: 1.6; }
.modal label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.modal input {
  display: block; width: 100%; margin-top: 5px;
  border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 12px; font-size: 14px; outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- 登录 / 注册页 ---------- */
.auth-body {
  background: linear-gradient(135deg, #1e2430 0%, #2a3550 50%, #1e2430 100%);
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.auth-wrap { width: 100%; max-width: 420px; padding: 20px; }
.auth-card {
  background: #fff; border-radius: 20px; padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.auth-brand {
  font-size: 18px; font-weight: 700; letter-spacing: 4px;
  color: var(--accent); margin-bottom: 8px;
}
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-sub { font-size: 13.5px; color: var(--text-dim); margin-bottom: 24px; line-height: 1.6; }
.auth-tabs { display: flex; gap: 0; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.auth-tab {
  flex: 1; padding: 10px; background: none; border: none;
  font-size: 14px; font-weight: 600; color: var(--text-dim);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.auth-tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.auth-card label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 14px; }
.auth-card input {
  display: block; width: 100%; margin-top: 5px;
  border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 12px; font-size: 14px; outline: none;
}
.auth-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,124,255,.12); }
.auth-submit { width: 100%; padding: 12px; font-size: 15px; margin-top: 6px; }
.auth-error {
  margin-top: 14px; padding: 10px 12px; border-radius: 9px;
  background: #fff0f0; color: #d33; font-size: 13px;
}

.user-info {
  font-size: 12.5px; color: #aab3c5; padding: 6px 10px 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
