:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e6e9f2;
  --text: #1f2430;
  --muted: #7a8296;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-soft: #eef0ff;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --shadow: 0 1px 2px rgba(20, 24, 40, .04), 0 6px 24px rgba(20, 24, 40, .06);
  --radius: 14px;
  --sidebar-w: 236px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #1f2430 0%, #161a24 100%);
  color: #cdd2e0;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 22px 20px; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand-logo { font-size: 26px; }
.brand-title { color: #fff; font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: #7b8398; letter-spacing: .5px; }
.nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; margin: 3px 0;
  border-radius: 10px; color: #aeb6ca;
  cursor: pointer; text-decoration: none; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 4px 14px rgba(99,102,241,.35); }
.nav-item .ico { font-size: 18px; width: 22px; text-align: center; }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.06); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { color: #fff; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: #7b8398; }

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }
.view { padding: 30px 36px 60px; max-width: 1180px; }

/* ---------- 通用组件 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 800; margin: 0; letter-spacing: .3px; }
.page-desc { color: var(--muted); margin: 6px 0 0; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: none; border-radius: 10px; cursor: pointer;
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); transition: all .15s;
}
.btn:hover { border-color: #cdd3e4; background: #fafbfe; }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border: none; box-shadow: 0 4px 14px rgba(99,102,241,.28); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--red); border-color: #f6cdcd; }
.btn.danger:hover { background: #fef1f1; }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: #f1f3f8; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.grid { display: grid; gap: 18px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } .view { padding: 24px 18px 48px; } }
@media (max-width: 600px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

input, textarea, select {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--text); font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
textarea { resize: vertical; min-height: 90px; }
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 44px; margin-bottom: 8px; }

/* ---------- 进度条 ---------- */
.progress { height: 8px; background: #edf0f7; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .3s; }

/* ---------- 课程卡片 ---------- */
.course-card { display: flex; flex-direction: column; gap: 12px; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.course-card:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(20,24,40,.1); }
.course-card .top { display: flex; justify-content: space-between; align-items: flex-start; }
.course-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; color: #fff; }
.course-cat { font-size: 12px; color: var(--primary); background: var(--primary-soft); padding: 3px 9px; border-radius: 99px; font-weight: 600; }
.course-title { font-size: 16.5px; font-weight: 700; margin: 2px 0 4px; }
.course-desc { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 40px; }
.course-meta { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.course-foot { display: flex; align-items: center; gap: 10px; }
.course-foot .progress { flex: 1; }
.course-foot .pct { font-size: 12.5px; font-weight: 700; color: var(--primary); }
.tag { display: inline-block; font-size: 12px; background: #f1f3f8; color: #5b6478; padding: 2px 8px; border-radius: 6px; margin: 0 4px 4px 0; }

/* ---------- 统计卡片 ---------- */
.stat-card { display: flex; align-items: center; gap: 14px; }
.stat-ico { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.stat-val { font-size: 24px; font-weight: 800; line-height: 1.2; }
.stat-label { font-size: 12.5px; color: var(--muted); }

/* ---------- 列表 ---------- */
.list-item { display: flex; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.check {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid #cbd2e0;
  cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: all .15s; background: #fff;
}
.check.done { background: var(--green); border-color: var(--green); color: #fff; }
.check.done::after { content: "✓"; font-size: 13px; font-weight: 700; }

/* ---------- 计时器 ---------- */
.timer-ring { width: 240px; height: 240px; border-radius: 50%; position: relative; margin: 0 auto; }
.timer-ring svg { transform: rotate(-90deg); }
.timer-inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.timer-time { font-size: 48px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer-label { color: var(--muted); font-size: 13px; }

/* ---------- 图表 ---------- */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 10px 6px 0; }
.chart .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bar { width: 100%; max-width: 42px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, var(--primary), var(--primary-2)); min-height: 3px; transition: height .4s; }
.chart .bar.zero { background: #e8ecf5; min-height: 3px; }
.chart .bar-val { font-size: 11px; color: var(--muted); }
.chart .bar-day { font-size: 11.5px; color: var(--muted); }

/* ---------- 弹窗 ---------- */
.modal-root { position: fixed; inset: 0; background: rgba(20,24,40,.45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- 提示 ---------- */
.toast-root { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1f2430; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: toast-in .2s ease; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 认证页 ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { text-align: center; font-size: 42px; margin-bottom: 4px; }
.auth-title { text-align: center; font-size: 22px; font-weight: 800; margin: 0 0 4px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 24px; }
.tab-switch { display: flex; background: #f1f3f8; border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tab-switch button { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); font-size: 14px; }
.tab-switch button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* ---------- markdown 内容 ---------- */
.lesson-content { line-height: 1.75; font-size: 15px; }
.lesson-content h1, .lesson-content h2, .lesson-content h3 { margin: 1.4em 0 .5em; line-height: 1.4; }
.lesson-content h1 { font-size: 1.5em; } .lesson-content h2 { font-size: 1.25em; } .lesson-content h3 { font-size: 1.1em; }
.lesson-content p { margin: .7em 0; }
.lesson-content ul, .lesson-content ol { padding-left: 1.5em; margin: .7em 0; }
.lesson-content code { background: #f1f3f8; padding: 2px 6px; border-radius: 5px; font-family: "SF Mono", Consolas, monospace; font-size: .9em; }
.lesson-content pre { background: #1f2430; color: #e7ecf6; padding: 16px; border-radius: 10px; overflow-x: auto; margin: 1em 0; }
.lesson-content pre code { background: transparent; padding: 0; color: inherit; }
.lesson-content blockquote { border-left: 3px solid var(--primary); margin: 1em 0; padding: 4px 16px; color: var(--muted); background: var(--primary-soft); border-radius: 0 8px 8px 0; }
.lesson-content a { color: var(--primary); }
.lesson-content img { max-width: 100%; border-radius: 8px; }

/* ---------- 笔记卡片 ---------- */
.note-card { white-space: pre-wrap; word-break: break-word; }
.note-card .note-meta { font-size: 12px; color: var(--muted); margin-top: 8px; display: flex; justify-content: space-between; }

/* ---------- 资料项 ---------- */
.mat-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.mat-item:last-child { border-bottom: none; }
.mat-ico { width: 40px; height: 40px; border-radius: 9px; background: var(--primary-soft); display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0; }
.mat-name { font-weight: 600; font-size: 14px; word-break: break-all; }
.mat-size { font-size: 12px; color: var(--muted); }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border-radius: 99px; border: 1px solid var(--border); cursor: pointer; font-size: 13px; background: #fff; color: var(--muted); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.danger-zone { border: 1px dashed #f3c2c2; border-radius: 10px; padding: 12px 16px; }
