:root {
  --bg: #1b1b1f;
  --bg-2: #232329;
  --bg-3: #2c2c34;
  --panel: #26262e;
  --border: #383842;
  --text: #e6e6ea;
  --text-dim: #9a9aa6;
  --accent: #4ea1ff;
  --accent-2: #7c5cff;
  --green: #57c98a;
  --red: #ff6b6b;
  --yellow: #f5c451;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px; line-height: 1.7;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }

/* ---------- Auth ---------- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-card .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.auth-card label { display: block; font-size: 13px; color: var(--text-dim); margin: 12px 0 6px; }
.auth-card .btn { width: 100%; margin-top: 16px; }
.auth-toggle { text-align: center; margin-top: 14px; font-size: 13px; color: var(--text-dim); }
.auth-toggle a { color: var(--accent); cursor: pointer; }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- Layout ---------- */
#main { display: flex; height: 100vh; }
.sidebar { width: 220px; background: var(--bg-2); border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-size: 18px; font-weight: 700; margin-bottom: 18px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg,var(--accent),var(--accent-2)); }
.nav-btn { text-align: left; background: transparent; border: none; color: var(--text-dim); padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.nav-btn:hover { background: var(--bg-3); color: var(--text); }
.nav-btn.active { background: var(--bg-3); color: var(--accent); font-weight: 600; }
.sidebar .spacer { flex: 1; }
.meta-box { font-size: 12px; color: var(--text-dim); background: var(--bg-3); border-radius: 8px; padding: 10px; }
.meta-box b { color: var(--text); }
.user-box { font-size: 13px; color: var(--text-dim); margin-top: 10px; display: flex; justify-content: space-between; align-items: center; }
.user-box a { color: var(--red); cursor: pointer; }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; gap: 10px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--bg); }
.topbar .search { flex: 1; }
.topbar .search input { width: 100%; }
.btn { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 9px 14px; font-size: 14px; font-weight: 600; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--bg-3); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.view { padding: 20px; overflow-y: auto; flex: 1; }
.view h2 { margin: 0 0 14px; font-size: 20px; }

/* ---------- Cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card .title { font-weight: 600; font-size: 15px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--bg-3); color: var(--text-dim); white-space: nowrap; }
.badge.idea { background: rgba(124,92,255,.18); color: #b9a6ff; }
.badge.material { background: rgba(78,161,255,.18); color: #8fc4ff; }
.badge.todo { background: rgba(245,196,81,.18); color: var(--yellow); }
.badge.auto { background: rgba(87,201,138,.18); color: var(--green); }
.card .summary { font-size: 13px; color: var(--text-dim); margin: 6px 0; }
.card .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--bg-3); color: var(--text-dim); }
.card .foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-top: 10px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal-box { width: 720px; max-width: 100%; max-height: 90vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.modal-box h3 { margin: 0 0 14px; font-size: 18px; }
.modal-box .row { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.modal-box .row > * { flex: 1; min-width: 120px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.kp { background: var(--bg-3); border-radius: 8px; padding: 12px; margin-top: 10px; }
.kp li { margin: 4px 0; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* ---------- QA / Summary ---------- */
.qa-answer { background: var(--bg-3); border-radius: var(--radius); padding: 16px; white-space: pre-wrap; line-height: 1.8; }
.source-chip { display: inline-block; font-size: 12px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; margin: 4px 4px 0 0; color: var(--text-dim); }
.summary-block { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.summary-block h4 { margin: 0 0 8px; color: var(--accent); }
.summary-block ul { margin: 6px 0; padding-left: 20px; }

/* ---------- Todos ---------- */
.todo-item { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 11px 14px; margin-bottom: 8px; }
.todo-item input { width: 18px; height: 18px; }
.todo-item.done .text { text-decoration: line-through; color: var(--text-dim); }
.todo-item .from { font-size: 12px; color: var(--text-dim); margin-left: auto; }
.group-title { font-weight: 600; margin: 16px 0 8px; color: var(--accent-2); }

/* ---------- misc ---------- */
.empty { color: var(--text-dim); text-align: center; padding: 50px 0; }
.loading { color: var(--text-dim); padding: 20px; }
.range-row { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--bg-3); border: 1px solid var(--border); color: var(--text); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 99; }

/* ---------- 站点返回条 ---------- */
.site-bar {
  height: 40px; background: var(--bg-2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  font-size: 13px; color: var(--text-dim); position: sticky; top: 0; z-index: 60;
}
.site-bar__back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); transition: color .15s; }
.site-bar__back:hover { color: var(--accent); }
.site-bar__sep { width: 1px; height: 14px; background: var(--border); }
.site-bar__now { color: var(--text-dim); }

/* ---------- 登录页增强 ---------- */
.auth-logo {
  width: 44px; height: 44px; border-radius: 13px; margin-bottom: 14px;
  background: linear-gradient(135deg, rgba(78,161,255,.18), rgba(124,92,255,.18));
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.auth-foot {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim); text-align: center; line-height: 1.6;
}
.sidebar-home {
  display: block; margin-top: 10px; font-size: 12.5px; color: var(--text-dim);
  text-decoration: none; transition: color .15s;
}
.sidebar-home:hover { color: var(--accent); }

/* ===============================================================
   移动端优化（≤720px）
   =============================================================== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; top: 0; left: 0; width: 260px; height: 100%; z-index: 1000; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar .search { flex: 1; min-width: 0; }
  .content { padding: 12px; }
  .card { padding: 14px; }
  .card h3 { font-size: 15px; }
  .modal { max-width: 100%; }
  .modal-content { padding: 16px; max-height: 90vh; overflow-y: auto; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  #mobile-menu-btn { display: flex !important; }
}

#mobile-menu-btn { display: none; background: var(--accent); color: white; border: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }

@media (max-width: 720px) {
  /* ---- 顶部返回条：文字挤了就只留返回按钮 ---- */
  .site-bar { height: 44px; padding: 0 12px; gap: 8px; }
  .site-bar__back { font-size: 14px; min-height: 44px; }
  .site-bar__now { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ---- 登录页：卡片不再超宽，输入框加大到适合手指 ---- */
  .auth-screen { min-height: calc(100vh - 44px); padding: 16px 14px 28px; align-items: flex-start; }
  .auth-card { width: 100%; max-width: 420px; padding: 24px 20px; }
  .auth-card h1 { font-size: 21px; }
  .auth-card .sub { font-size: 14px; margin-bottom: 18px; }
  .auth-card label { font-size: 13.5px; margin: 14px 0 6px; }
  .auth-card input { width: 100%; min-height: 46px; font-size: 16px; padding: 12px 13px; }
  .auth-card .btn { min-height: 48px; font-size: 16px; margin-top: 18px; }
  .auth-logo { width: 42px; height: 42px; margin-bottom: 12px; }
  .auth-foot { font-size: 12px; margin-top: 18px; }

  /* ---- 主界面：顶栏按钮与输入 ---- */
  .topbar { padding: 12px 14px; gap: 10px; }
  .topbar .search input { min-height: 46px; font-size: 16px; }   /* 16px 防 iOS 聚焦缩放 */
  #new-btn { min-height: 46px; padding: 12px 18px; font-size: 15px; white-space: nowrap; }
  #mobile-menu-btn { min-height: 44px; padding: 10px 14px; font-size: 15px; }

  /* ---- 侧栏抽屉：加安全区内边距（刘海屏） ---- */
  .sidebar.open {
    width: min(84vw, 300px); padding-top: calc(18px + env(safe-area-inset-top));
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  .sidebar .nav-btn { min-height: 46px; font-size: 15px; }
  .sidebar-home { min-height: 40px; display: flex; align-items: center; }

  /* ---- 内容区 ---- */
  .view { padding: 14px; }
  .view h2 { font-size: 18px; margin-bottom: 12px; }
  .card-grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 14px; }
  .card .title { font-size: 16px; }
  .card .summary { font-size: 14px; }
  .badge { font-size: 12px; padding: 3px 9px; }

  /* ---- 弹窗：手机上全屏，避免小窗难操作 ---- */
  .modal { padding: 0; align-items: flex-end; }
  .modal-box {
    width: 100%; max-width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .modal-box h3 { font-size: 17px; }
  .modal-box .row { flex-direction: column; gap: 10px; }
  .modal-box .row > * { width: 100%; }
  .modal-box input, .modal-box textarea, .modal-box select { width: 100%; min-height: 44px; font-size: 16px; }
  .modal-box .btn { min-height: 46px; flex: 1 1 100%; }

  /* ---- 待办 / 检索 / 总结 ---- */
  .todo-item { padding: 12px; gap: 12px; }
  .todo-item input { width: 22px; height: 22px; }
  .qa-answer { padding: 14px; font-size: 15px; }
  .summary-block { padding: 14px; }
  .range-row { flex-direction: column; align-items: stretch; }
  .range-row input, .range-row .btn { width: 100%; min-height: 44px; }

  /* ---- toast 适配刘海屏 ---- */
  .toast { bottom: calc(20px + env(safe-area-inset-bottom)); font-size: 14px; max-width: calc(100vw - 32px); }
}

/* 挂到子路径 /app/ 时，登录页需要为顶部返回条让位 */
body { padding-top: 0; }
.auth-screen { min-height: calc(100vh - 40px); }
