/* ===========================
   岐黄问道 · 中医药工作台
   主题：朱红 + 金色 + 米黄宣纸
   =========================== */

:root {
  --color-bg: #f4ead5;
  --color-bg-warm: #faf2e0;
  --color-bg-card: #fffaf0;
  --color-paper: #f7eed5;

  --color-primary: #a8322c;
  --color-primary-dark: #5c1a17;
  --color-primary-light: #d96a64;
  --color-accent: #c9a14b;
  --color-accent-light: #e8c97a;

  --color-text: #3d2817;
  --color-text-muted: #7a6757;
  --color-text-light: #a89989;
  --color-border: #d9c9a3;
  --color-border-light: #e7d9b8;

  --color-success: #2e7d5b;
  --color-warn: #d4823a;
  --color-info: #4a6c8a;

  --shadow-sm: 0 2px 6px rgba(60, 30, 15, 0.06);
  --shadow-md: 0 6px 18px rgba(60, 30, 15, 0.1);
  --shadow-lg: 0 16px 40px rgba(60, 30, 15, 0.14);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", "FangSong", serif;
  --font-sans: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  background-image:
    radial-gradient(at 20% 0%, rgba(232, 201, 122, 0.18) 0%, transparent 45%),
    radial-gradient(at 90% 100%, rgba(168, 50, 44, 0.08) 0%, transparent 50%),
    repeating-linear-gradient(45deg, transparent 0, transparent 40px, rgba(168, 50, 44, 0.018) 40px, rgba(168, 50, 44, 0.018) 41px);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

/* ========== 顶部导航 ========== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 32px;
  /* iOS 全面屏安全区：避开灵动岛与圆角 */
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  padding-left: calc(32px + env(safe-area-inset-left, 0px));
  padding-right: calc(32px + env(safe-area-inset-right, 0px));
  background: linear-gradient(180deg, #5c1a17 0%, #7a2018 100%);
  color: #f7eed5;
  box-shadow: 0 4px 20px rgba(60, 20, 15, 0.25);
  border-bottom: 2px solid var(--color-accent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-text h1 {
  font-size: 22px;
  color: #f7eed5;
  letter-spacing: 2px;
  margin: 0;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.brand-sub {
  font-size: 11px;
  color: var(--color-accent-light);
  letter-spacing: 4px;
  opacity: 0.9;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  margin-left: 20px;
  flex-wrap: wrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  color: rgba(247, 238, 213, 0.75);
  border-radius: 8px;
  transition: all 0.18s;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: rgba(232, 201, 122, 0.12);
  color: #f7eed5;
}

.nav-item.active {
  background: var(--color-accent-light);
  color: var(--color-primary-dark);
  font-weight: 600;
  border-color: var(--color-accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.nav-item.nav-ai {
  background: linear-gradient(135deg, rgba(232, 201, 122, 0.15), rgba(232, 201, 122, 0.05));
  color: var(--color-accent-light);
  border: 1px solid rgba(232, 201, 122, 0.3);
}

.nav-item.nav-ai.active {
  background: var(--color-accent);
  color: var(--color-primary-dark);
  border-color: var(--color-accent-light);
}

.nav-icon {
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border-radius: 8px;
  background: rgba(247, 238, 213, 0.1);
  color: #f7eed5;
  transition: all 0.18s;
  border: 1px solid rgba(247, 238, 213, 0.2);
}

.icon-btn:hover {
  background: var(--color-accent-light);
  color: var(--color-primary-dark);
}

/* ========== 主体 ========== */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 32px 60px;
  /* iOS 底部横条安全区 */
  padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
}

.view {
  display: none;
  animation: fadeIn 0.3s ease-out;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px dashed var(--color-border);
  position: relative;
}

.view-header::before {
  content: "❖";
  position: absolute;
  left: 50%;
  bottom: -10px;
  transform: translateX(-50%);
  color: var(--color-accent);
  background: var(--color-bg);
  padding: 0 10px;
  font-size: 12px;
}

.view-title {
  font-size: 26px;
  letter-spacing: 2px;
  color: var(--color-primary-dark);
  position: relative;
  padding-left: 14px;
}

.view-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 4px;
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-accent) 100%);
  border-radius: 2px;
}

.view-desc {
  margin: 6px 0 0 14px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.view-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ========== 按钮 ========== */
.primary-btn {
  padding: 8px 18px;
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #f7eed5;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1px;
  border: 1px solid var(--color-primary-dark);
  transition: all 0.18s;
  box-shadow: 0 2px 6px rgba(168, 50, 44, 0.25);
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(168, 50, 44, 0.35);
}

.ghost-btn {
  padding: 8px 16px;
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: all 0.18s;
}

.ghost-btn:hover {
  background: var(--color-paper);
  border-color: var(--color-accent);
}

.link-btn {
  font-size: 12px;
  color: var(--color-primary);
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s;
}

.link-btn:hover {
  background: rgba(168, 50, 44, 0.08);
}

.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.full { width: 100%; }
.muted { color: var(--color-text-muted); font-size: 13px; }

/* ========== 输入控件 ========== */
.select-input {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 13px;
  min-width: 120px;
  transition: border-color 0.18s;
}

.select-input:focus {
  border-color: var(--color-primary);
}

input[type=text], input[type=number], input[type=date], textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  transition: border-color 0.18s;
  font-family: inherit;
}

input[type=text]:focus, input[type=number]:focus, input[type=date]:focus, textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(168, 50, 44, 0.1);
}

textarea {
  resize: vertical;
  font-family: var(--font-sans);
  line-height: 1.6;
}

/* ========== 仪表盘 ========== */
.date-badge {
  padding: 6px 14px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  background: linear-gradient(160deg, var(--color-bg-card) 0%, var(--color-paper) 100%);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--color-primary);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card--book::before { background: var(--color-info); }
.stat-card--done::before { background: var(--color-success); }
.stat-card--chapter::before { background: var(--color-primary); }
.stat-card--week::before { background: var(--color-accent); }

/* 图标底色按类型着色，与左侧色条呼应 */
.stat-card--book .stat-icon { background: #e8f0f8; }
.stat-card--done .stat-icon { background: #e5f0e9; }
.stat-card--chapter .stat-icon { background: #f8e6e4; }
.stat-card--week .stat-icon { background: #f6eed9; }

.stat-icon {
  font-size: 26px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-paper);
  border-radius: 12px;
  flex-shrink: 0;
}

.stat-label {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 700;
  color: var(--color-primary-dark);
  line-height: 1;
}

.stat-extra {
  font-size: 11px;
  color: var(--color-text-light);
  margin-top: 4px;
}

/* 双栏 */
.dash-cols {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.dash-panel {
  background: linear-gradient(170deg, var(--color-bg-card) 0%, #fdfaf3 100%);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.dash-panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-accent), transparent);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--color-border);
}

.panel-head h3 {
  font-size: 16px;
  color: var(--color-primary-dark);
  letter-spacing: 1px;
}

.panel-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  background: var(--color-paper);
  padding: 3px 10px;
  border-radius: 10px;
}

.panel-tip {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: 0 0 12px;
  padding: 8px 12px;
  background: var(--color-paper);
  border-left: 3px solid var(--color-accent);
  border-radius: 4px;
}

/* AI Quick */
.ai-quick {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.ai-quick input {
  flex: 1;
}

.quick-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.suggest-chip {
  padding: 4px 10px;
  background: var(--color-paper);
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  font-size: 12px;
  color: var(--color-primary);
  cursor: pointer;
  transition: all 0.15s;
}

.suggest-chip:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
}

.ai-answer {
  background: linear-gradient(180deg, var(--color-paper), var(--color-bg-warm));
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 13px;
  line-height: 1.7;
  border: 1px solid var(--color-border-light);
  min-height: 60px;
  white-space: pre-wrap;
}

.ai-answer:empty::before {
  content: "AI 回答将显示在此...";
  color: var(--color-text-light);
  font-style: italic;
}

/* Today list */
.today-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.today-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--color-paper);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-primary);
  transition: all 0.15s;
  cursor: pointer;
}

.today-item:hover {
  background: var(--color-accent-light);
}

.today-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.today-item-title {
  font-weight: 500;
  font-size: 13px;
}

.today-item-book {
  font-size: 11px;
  color: var(--color-text-muted);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.empty-state-icon {
  font-size: 40px;
  display: block;
  margin-bottom: 8px;
  opacity: 0.5;
}

/* Progress list */
.progress-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.progress-row {
  display: grid;
  grid-template-columns: 200px 1fr 80px;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
}

.progress-name {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.progress-cover {
  font-size: 20px;
}

.progress-bar-wrap {
  height: 10px;
  background: var(--color-paper);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: 6px;
  transition: width 0.5s;
}

.progress-status {
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: right;
}

.brief-content {
  padding: 16px;
  background: linear-gradient(180deg, var(--color-paper), var(--color-bg-warm));
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.8;
  border: 1px solid var(--color-border-light);
}

.brief-content strong {
  color: var(--color-primary-dark);
}

/* ========== 书籍卡片 ========== */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.book-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.book-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-accent);
}

.book-cover {
  height: 110px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 50px;
  color: var(--color-accent-light);
  position: relative;
  border-bottom: 2px solid var(--color-accent);
}

.book-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(45deg, transparent 0, transparent 20px, rgba(232, 201, 122, 0.06) 20px, rgba(232, 201, 122, 0.06) 21px);
}

.book-cover-emoji {
  position: relative;
  z-index: 1;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.book-status-pill {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 11px;
  background: rgba(247, 238, 213, 0.9);
  color: var(--color-primary-dark);
  font-weight: 500;
}

.book-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.book-name {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--color-primary-dark);
  margin: 0 0 4px;
  letter-spacing: 1px;
}

.book-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 10px;
  display: flex;
  gap: 8px;
}

.book-meta-item {
  padding: 2px 8px;
  background: var(--color-paper);
  border-radius: 8px;
}

.book-desc {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: 8px 0 12px;
  line-height: 1.5;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}

.book-progress-text {
  font-size: 12px;
  color: var(--color-text-muted);
}

.book-progress-text strong {
  color: var(--color-primary);
  font-size: 14px;
}

.book-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--color-border);
}

.book-actions button {
  flex: 1;
  padding: 6px 8px;
  font-size: 11px;
  border-radius: 4px;
  border: 1px solid var(--color-border-light);
  background: var(--color-paper);
  transition: all 0.15s;
}

.book-actions button:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
}

.book-actions button.danger:hover {
  background: #f5d6d3;
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
}

/* ========== 章节列表 ========== */
.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.chapter-group {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.chapter-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: linear-gradient(180deg, var(--color-paper), var(--color-bg-warm));
  border-bottom: 1px solid var(--color-border-light);
}

.chapter-group-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--color-primary-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chapter-group-stats {
  font-size: 12px;
  color: var(--color-text-muted);
}

.chapter-group-body {
  padding: 8px;
}

.chapter-row {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.chapter-row:hover {
  background: var(--color-paper);
}

.chapter-row + .chapter-row {
  border-top: 1px dashed var(--color-border-light);
}

.chapter-num {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--color-accent);
  text-align: center;
  width: 40px;
  height: 40px;
  line-height: 40px;
  border-radius: 50%;
  background: var(--color-paper);
}

.chapter-info {
  min-width: 0;
}

.chapter-title {
  font-weight: 500;
  font-size: 14px;
  color: var(--color-text);
  margin-bottom: 4px;
  cursor: pointer;
}

.chapter-title:hover {
  color: var(--color-primary);
}

.chapter-sub {
  font-size: 11px;
  color: var(--color-text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.chapter-tag {
  padding: 1px 8px;
  background: var(--color-paper);
  border: 1px solid var(--color-border-light);
  border-radius: 8px;
  color: var(--color-text-muted);
  font-size: 10px;
}

.chapter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chapter-actions select {
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  border-radius: 4px;
}

.chapter-action-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--color-paper);
  font-size: 13px;
  transition: all 0.15s;
}

.chapter-action-btn:hover {
  background: var(--color-accent-light);
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.status-pill--未学习 { background: #efe2c9; color: #806b40; }
.status-pill--学习中 { background: #cce4d4; color: #2e7d5b; }
.status-pill--已打卡完成 { background: #f3c8c5; color: #a8322c; }

.mastery-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}

.mastery-pill--不熟悉 { background: #f5d6d3; color: #a8322c; }
.mastery-pill--了解 { background: #efe2c9; color: #806b40; }
.mastery-pill--熟悉 { background: #cce4d4; color: #2e7d5b; }
.mastery-pill--精通 { background: #f0d8a8; color: #806020; }

/* ========== 今日打卡 ========== */
.today-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.today-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: all 0.18s;
  cursor: pointer;
  border-left: 4px solid var(--color-primary);
}

.today-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.today-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.today-card-num {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--color-accent);
}

.today-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
}

.today-card-book {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}

.today-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--color-border-light);
}

.counter {
  padding: 6px 14px;
  background: var(--color-paper);
  border-radius: 12px;
  font-size: 12px;
  color: var(--color-primary-dark);
}

/* ========== 知识库 看板 ========== */
.kanban {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.kanban-col {
  flex: 0 0 280px;
  background: var(--color-paper);
  border-radius: var(--radius-md);
  padding: 12px;
  border: 1px solid var(--color-border-light);
  min-height: 200px;
}

.kanban-col-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px 12px;
  border-bottom: 2px solid var(--color-accent);
  margin-bottom: 10px;
}

.kanban-col-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 14px;
  color: var(--color-primary-dark);
}

.kanban-col-count {
  padding: 2px 8px;
  background: var(--color-accent-light);
  border-radius: 10px;
  font-size: 11px;
  color: var(--color-primary-dark);
}

.kb-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  border-left: 3px solid var(--color-accent);
}

.kb-card:hover {
  transform: translateX(2px);
  box-shadow: var(--shadow-sm);
}

.kb-card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--color-text);
}

.kb-card-summary {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.kb-card-source {
  font-size: 10px;
  color: var(--color-text-light);
  font-style: italic;
}

/* ========== 日历 ========== */
.calendar {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.cal-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--color-primary-dark);
  min-width: 140px;
  text-align: center;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-head {
  padding: 8px;
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 600;
}

.cal-cell {
  aspect-ratio: 1;
  background: var(--color-paper);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 70px;
}

.cal-cell:hover {
  background: var(--color-accent-light);
}

.cal-cell.empty {
  background: transparent;
  cursor: default;
  border-color: transparent;
}

.cal-cell.today {
  border-color: var(--color-primary);
  background: var(--color-bg-warm);
}

.cal-cell.today .cal-date {
  background: var(--color-primary);
  color: #f7eed5;
}

.cal-date {
  font-size: 12px;
  font-weight: 600;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.cal-dots {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-top: auto;
}

.cal-dot {
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 50%;
}

.cal-dot-tag {
  font-size: 9px;
  padding: 1px 4px;
  background: var(--color-accent-light);
  border-radius: 4px;
  color: var(--color-primary-dark);
}

/* ========== AI 视图 ========== */
.ai-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
}

.ai-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-mode-card, .ai-context-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.ai-mode-card h4, .ai-context-card h4 {
  font-size: 13px;
  color: var(--color-primary-dark);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--color-border);
}

.ai-mode-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-mode {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  background: var(--color-paper);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: all 0.15s;
}

.ai-mode:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
}

.ai-mode.active {
  background: var(--color-primary);
  color: #f7eed5;
  border-color: var(--color-primary-dark);
}

.ai-mode.active .mode-desc {
  color: rgba(247, 238, 213, 0.8);
}

.mode-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}

.mode-desc {
  font-size: 11px;
  color: var(--color-text-muted);
}

.context-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.context-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--color-paper);
  border-radius: 4px;
}

.ctx-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.ctx-dot--book { background: var(--color-info); }
.ctx-dot--chapter { background: var(--color-primary); }
.ctx-dot--kb { background: var(--color-accent); }

.ctx-tip {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 10px;
  padding: 6px 8px;
  background: var(--color-bg-warm);
  border-radius: 4px;
  border-left: 2px solid var(--color-success);
}

.context-target {
  font-size: 12px;
  padding: 8px;
  background: var(--color-paper);
  border-radius: 4px;
  min-height: 30px;
}

.ai-main {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.ai-panel h4 {
  font-size: 15px;
  color: var(--color-primary-dark);
  margin-bottom: 12px;
}

.ai-output {
  margin-top: 16px;
  padding: 16px;
  background: linear-gradient(180deg, var(--color-paper), var(--color-bg-warm));
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-light);
  min-height: 200px;
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-wrap;
}

.ai-output:empty::before {
  content: "⏳ 等待 AI 输出...";
  color: var(--color-text-light);
  font-style: italic;
}

.ai-output.loading::before {
  content: "🤔 AI 正在检索知识库...";
  color: var(--color-primary);
}

.ai-output strong { color: var(--color-primary-dark); }
.ai-output em { color: var(--color-accent); font-style: normal; font-weight: 500; }
.ai-output .source {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 2px 8px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  font-size: 11px;
  color: var(--color-primary);
}

/* ========== 弹窗 ========== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(60, 30, 15, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  /* iOS 全面屏安全区 */
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  border: 2px solid var(--color-accent);
  overflow: hidden;
}

.modal-wide { max-width: 720px; }
.modal-sm { max-width: 380px; }

.modal-head {
  padding: 14px 20px;
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #f7eed5;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h3 {
  color: #f7eed5;
  font-size: 16px;
  letter-spacing: 1px;
}

.modal-close {
  color: rgba(247, 238, 213, 0.8);
  font-size: 22px;
  padding: 0;
  width: 44px;
  height: 44px;
  margin-right: -12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.15s;
}

.modal-close:hover {
  background: rgba(247, 238, 213, 0.15);
  color: #f7eed5;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  padding: 12px 20px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--color-paper);
}

.form-row {
  margin-bottom: 14px;
}

.form-row label {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.checkbox-group label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: var(--color-paper);
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.checkbox-group label:has(input:checked) {
  background: var(--color-primary);
  color: #f7eed5;
  border-color: var(--color-primary-dark);
}

.checkbox-group input { display: none; }

/* 侧滑面板 */
.side-panel-mask {
  position: fixed;
  inset: 0;
  background: rgba(60, 30, 15, 0.5);
  z-index: 1000;
  display: flex;
  justify-content: flex-end;
  backdrop-filter: blur(2px);
}

.side-panel {
  background: var(--color-bg-card);
  width: 100%;
  max-width: 640px;
  height: 100%;
  overflow-y: auto;
  box-shadow: -8px 0 24px rgba(0,0,0,0.2);
  position: relative;
  padding: 30px;
}

.side-close {
  position: sticky;
  top: calc(10px + env(safe-area-inset-top, 0px));
  margin-left: auto;
  margin-right: calc(10px + env(safe-area-inset-right, 0px));
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  background: var(--color-paper);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  font-size: 20px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  color: var(--color-primary-dark);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(60, 30, 15, 0.25);
}

.side-close:active {
  background: var(--color-primary);
  color: #f7eed5;
}

.side-content h3 {
  font-size: 22px;
  color: var(--color-primary-dark);
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.side-book {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.side-section {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--color-border);
}

.side-section-label {
  font-size: 11px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  font-weight: 600;
}

.side-text {
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-wrap;
}

.side-text.original {
  font-family: var(--font-serif);
  background: var(--color-paper);
  padding: 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-accent);
  font-size: 14px;
  max-height: 340px;
  overflow-y: auto;
}

.side-text.ai {
  background: linear-gradient(180deg, var(--color-paper), var(--color-bg-warm));
  padding: 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-primary);
}

/* Toast */
.toast {
  position: fixed;
  top: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  padding: 10px 20px;
  background: var(--color-primary);
  color: #f7eed5;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-primary-dark); }

.confirm-msg {
  font-size: 14px;
  line-height: 1.7;
  margin: 0;
  color: var(--color-text);
}

/* 响应式 */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-cols { grid-template-columns: 1fr; }
  .ai-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-header { flex-wrap: wrap; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); padding-left: calc(16px + env(safe-area-inset-left, 0px)); padding-right: calc(16px + env(safe-area-inset-right, 0px)); gap: 10px; }
  /* 导航单行横向滑动，整齐不换行 */
  .main-nav { margin-left: 0; width: 100%; order: 3; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  .main-nav::-webkit-scrollbar { display: none; }
  .nav-item { flex: 0 0 auto; white-space: nowrap; padding: 8px 12px; font-size: 13px; min-height: 40px; }
  .header-actions { gap: 4px; }
  .icon-btn { width: 44px; height: 44px; font-size: 19px; }
  .app-main { padding: 18px 16px 40px; padding-left: calc(16px + env(safe-area-inset-left, 0px)); padding-right: calc(16px + env(safe-area-inset-right, 0px)); padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px)); }

  /* 视图标题区允许换行，保持整齐 */
  .view-header { flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; padding-bottom: 14px; }
  .view-title { font-size: 21px; }
  .view-desc { font-size: 12px; }
  .view-actions { flex-wrap: wrap; gap: 8px; }

  /* 统计卡 2×2 紧凑排列 */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
  .stat-card { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px 14px 14px 18px; }
  .stat-icon { width: 38px; height: 38px; font-size: 20px; border-radius: 10px; }
  .stat-value { font-size: 26px; }
  .stat-label { font-size: 12px; margin-bottom: 2px; }
  .stat-extra { font-size: 10px; }

  .form-grid { grid-template-columns: 1fr; }

  /* 学习进度：书名+进度值一行，进度条通栏 */
  .progress-list { gap: 14px; }
  .progress-row { grid-template-columns: 1fr auto; gap: 6px 12px; padding: 4px 0; }
  .progress-bar-wrap { grid-column: 1 / -1; height: 8px; }
  .progress-name { font-size: 13px; }
  .progress-status { font-size: 11px; white-space: nowrap; }

  /* 面板内边距收紧 */
  .dash-panel { padding: 16px; }
  .panel-head { flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

  /* ===== 章节打卡：操作区整行下移，标签横向排列 ===== */
  .chapter-group-head { padding: 10px 14px; }
  .chapter-group-title { font-size: 14px; gap: 8px; }
  .chapter-group-stats { font-size: 11px; white-space: nowrap; }
  .chapter-group-body { padding: 6px; }
  .chapter-row { grid-template-columns: 40px 1fr; gap: 6px 10px; padding: 12px 8px; align-items: start; }
  .chapter-num { width: 34px; height: 34px; line-height: 34px; font-size: 15px; }
  .chapter-title { font-size: 14px; margin-bottom: 5px; }
  .chapter-sub { gap: 4px 5px; font-size: 11px; }
  .chapter-tag { font-size: 10px; padding: 1px 7px; border-radius: 6px; }
  .chapter-actions { grid-column: 1 / -1; display: flex; gap: 6px; margin-top: 8px; padding-left: 50px; }
  .chapter-actions select { flex: 1; min-height: 40px; padding: 6px 4px; font-size: 12px; }
  .chapter-action-btn { width: 40px; height: 40px; font-size: 15px; }

  /* 弹窗在手机上占满可用区域，关闭按钮足够大 */
  .modal-mask { padding: calc(12px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px)); }
  .modal { max-height: 92dvh; max-width: 100%; }
  .modal-head { padding: 10px 14px 10px 18px; }
  .modal-head h3 { font-size: 15px; }
  .modal-close { width: 48px; height: 48px; font-size: 24px; margin-right: -8px; }
  .modal-foot { gap: 8px; }
  .modal-foot .ghost-btn, .modal-foot .primary-btn { min-height: 46px; padding: 10px 20px; font-size: 14px; }

  /* 侧滑阅读面板：关闭按钮常驻可见（sticky），不被灵动岛遮挡 */
  .side-panel { padding: 16px 18px 24px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); padding-left: calc(18px + env(safe-area-inset-left, 0px)); padding-right: calc(18px + env(safe-area-inset-right, 0px)); padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
  .side-close { margin-bottom: 6px; }
  .side-content h3 { font-size: 19px; padding-right: 4px; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--color-paper); }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-accent); }
