/* ===== 全局变量 ===== */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f6f6f8;
  --text: #262626;
  --text-secondary: #8e8e8e;
  --text-tertiary: #b8b8b8;
  --border: #efefef;
  --border-strong: #dbdbdb;
  --accent: #ff5c8a;
  --accent-soft: #ffe4ec;
  --accent-gradient: linear-gradient(135deg, #f5858a 0%, #ff6b9d 100%);
  --success: #34c759;
  --success-soft: #e3f8ea;
  --warning: #ff9f0a;
  --danger: #ff3b30;
  --danger-soft: #ffe3e1;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.04);
  --shadow: 0 2px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.1);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --sidebar-w: 240px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ===== 重置 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
svg { width: 22px; height: 22px; flex-shrink: 0; }

/* ===== 布局 ===== */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }

/* ===== 侧边栏 ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.sidebar-header { padding: 24px 20px 16px; }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-gradient);
  color: #fff; font-size: 18px; border-radius: 10px;
  box-shadow: 0 4px 12px rgba(255,92,138,.35);
}
.logo-text { font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 15px; font-weight: 500;
  transition: all .18s ease;
}
.nav-item svg { width: 20px; height: 20px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); }
.version { font-size: 12px; color: var(--text-tertiary); }

.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 99;
  opacity: 0; pointer-events: none;
  transition: opacity .28s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }

/* ===== 主内容 ===== */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  min-width: 0;
}
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  padding-top: calc(14px + var(--safe-top));
  padding-left: calc(20px + var(--safe-left));
  padding-right: calc(20px + var(--safe-right));
  background: rgba(250,250,250,.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; padding: 6px; color: var(--text); }
.menu-btn svg { width: 24px; height: 24px; }
.page-title { font-size: 19px; font-weight: 700; }
.content { padding: 20px; padding-bottom: calc(24px + var(--safe-bottom)); padding-left: calc(20px + var(--safe-left)); padding-right: calc(20px + var(--safe-right)); max-width: 860px; width: 100%; }

/* ===== 通用组件 ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.section-title { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 18px 0 10px; letter-spacing: .3px; }
.section-title:first-child { margin-top: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  transition: all .18s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--accent-gradient); color: #fff; box-shadow: 0 4px 12px rgba(255,92,138,.3); }
.btn-primary:active { transform: scale(.97); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost:active { transform: scale(.97); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { padding: 8px; border-radius: 8px; color: var(--text-secondary); }
.btn-icon:active { background: var(--surface-2); }

.input, .textarea, .select {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: border-color .18s ease;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.field { margin-bottom: 14px; }

.empty-state {
  text-align: center; padding: 48px 20px;
  color: var(--text-tertiary);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* ===== 任务模块 ===== */
.task-input-row { display: flex; gap: 10px; margin-bottom: 16px; }
.task-input-row .input { flex: 1; }
.task-filters { display: flex; gap: 8px; margin-bottom: 14px; }
.filter-chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  background: var(--surface-2);
  color: var(--text-secondary);
  transition: all .18s ease;
}
.filter-chip.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.task-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: all .18s ease;
}
.task-item:hover { box-shadow: var(--shadow-sm); }
.task-check {
  width: 22px; height: 22px; flex-shrink: 0;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: all .18s ease;
  margin-top: 1px;
}
.task-check.done { background: var(--success); border-color: var(--success); }
.task-check.done svg { width: 13px; height: 13px; color: #fff; display: block; }
.task-check svg { display: none; }
.task-body { flex: 1; min-width: 0; }
.task-text { font-size: 15px; word-break: break-word; }
.task-item.done .task-text { color: var(--text-tertiary); text-decoration: line-through; }
.task-meta { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }
.task-del { color: var(--text-tertiary); padding: 4px; opacity: 0; transition: opacity .18s; }
.task-item:hover .task-del { opacity: 1; }
.task-stats { display: flex; gap: 16px; margin-bottom: 16px; }
.stat-box { flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ===== 灵感模块 ===== */
.inspiration-form { margin-bottom: 20px; }
.type-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.type-tab {
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: all .18s ease;
}
.type-tab.active { background: #fff; color: var(--accent); border-color: var(--accent); font-weight: 600; }
.search-bar { position: relative; margin-bottom: 16px; }
.search-bar svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-tertiary); }
.search-bar .input { padding-left: 42px; }
.inspiration-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  position: relative;
}
.inspiration-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px; font-weight: 600;
  margin-bottom: 8px;
}
.tag-选题 { background: #e8f0ff; color: #3b82f6; }
.tag-金句 { background: #fff3e0; color: #f59e0b; }
.tag-对标 { background: #f3e8ff; color: #a855f7; }
.inspiration-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.inspiration-content { font-size: 14px; color: var(--text-secondary); white-space: pre-wrap; word-break: break-word; }
.inspiration-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.inspiration-date { font-size: 12px; color: var(--text-tertiary); }

/* ===== 脚本生成 ===== */
.script-platform { display: flex; gap: 10px; margin-bottom: 14px; }
.platform-btn {
  flex: 1; padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-weight: 600;
  transition: all .18s ease;
  background: var(--surface);
}
.platform-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.platform-btn .platform-icon { font-size: 22px; display: block; margin-bottom: 4px; }
.script-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
  white-space: pre-wrap;
  line-height: 1.8;
  font-size: 14px;
}
.script-output .script-h { color: var(--accent); font-weight: 700; }
.script-toolbar { display: flex; gap: 10px; margin-top: 12px; }

/* ===== 热点模块 ===== */
.hot-tabs { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.hot-tab {
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  background: var(--surface-2);
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all .18s ease;
}
.hot-tab.active { background: var(--accent-gradient); color: #fff; font-weight: 600; }
.hot-list { display: flex; flex-direction: column; gap: 8px; }
.hot-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.hot-rank {
  width: 24px; height: 24px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  border-radius: 6px;
  background: var(--surface-2); color: var(--text-secondary);
}
.hot-rank.top1 { background: #ff4d4f; color: #fff; }
.hot-rank.top2 { background: #ff7a45; color: #fff; }
.hot-rank.top3 { background: #ffa940; color: #fff; }
.hot-title { flex: 1; font-size: 14px; word-break: break-word; }
.hot-heat { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; }

/* ===== 复盘模块 ===== */
.review-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.review-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.review-title { font-size: 16px; font-weight: 600; }
.review-date { font-size: 12px; color: var(--text-tertiary); }
.review-metrics { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 12px; }
.metric { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px; text-align: center; }
.metric-num { font-size: 18px; font-weight: 700; }
.metric-label { font-size: 11px; color: var(--text-secondary); }
.review-section { margin-bottom: 8px; }
.review-section-title { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 3px; }
.review-section-text { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.pros { color: var(--success); }
.cons { color: var(--danger); }

/* ===== 备忘模块 ===== */
.memo-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.memo-text { font-size: 14px; white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.memo-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.memo-date { font-size: 12px; color: var(--text-tertiary); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(38,38,38,.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 9999;
  opacity: 0; pointer-events: none;
  transition: all .28s ease;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 模态弹窗 ===== */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .24s ease;
}
.modal-mask.show { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface);
  width: 100%; max-width: 520px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  max-height: 85vh; overflow-y: auto;
}
.modal-mask.show .modal { transform: translateY(0); }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: flex; }
  .content { padding: 16px; padding-bottom: calc(20px + var(--safe-bottom)); padding-left: calc(16px + var(--safe-left)); padding-right: calc(16px + var(--safe-right)); }
  .topbar { padding: 12px 16px; padding-top: calc(12px + var(--safe-top)); padding-left: calc(16px + var(--safe-left)); padding-right: calc(16px + var(--safe-right)); }
  .page-title { font-size: 17px; }
  .task-stats { gap: 10px; }
  .review-metrics { grid-template-columns: repeat(3,1fr); gap: 6px; }
  .task-del { opacity: 1; }
}

/* ===== PWA 独立窗口模式 (standalone) ===== */
@media (display-mode: standalone) {
  /* 独立窗口下隐藏菜单按钮（无地址栏无需侧边栏抽屉切换的视觉提示） */
  .topbar { background: var(--surface); }
  body { user-select: none; -webkit-user-select: none; }
  /* 允许输入框选择文本 */
  input, textarea { user-select: text; -webkit-user-select: text; }
}

/* ===== iOS Safari 独立窗口模式 ===== */
@media all and (display-mode: standalone) {
  .sidebar { padding-top: var(--safe-top); }
  .topbar { padding-top: calc(14px + var(--safe-top)); }
}

@media (min-width: 769px) {
  .modal-mask { align-items: center; }
  .modal { border-radius: var(--radius-lg); transform: translateY(20px) scale(.98); }
  .modal-mask.show .modal { transform: translateY(0) scale(1); }
}

/* ===== 备份模块 ===== */
.backup-total { text-align: center; margin-bottom: 20px; }
.backup-total-num { font-size: 36px; font-weight: 700; color: var(--accent); }
.backup-total-label { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.backup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
}
.backup-stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
}
.backup-stat-num { display: block; font-size: 20px; font-weight: 700; }
.backup-stat-label { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.backup-hint { font-size: 13px; color: var(--text-tertiary); line-height: 1.6; }
.backup-export-btn { gap: 8px; }
.backup-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 8px;
}
.backup-row-info { display: flex; flex-direction: column; gap: 2px; }
.backup-row-label { font-size: 15px; font-weight: 500; }
.backup-row-count { font-size: 12px; color: var(--text-tertiary); }
.btn-danger-clear {
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
  font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius-sm);
  transition: all .18s ease;
}
.btn-danger-clear:active { transform: scale(.97); }

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.nav::-webkit-scrollbar { width: 0; }
