:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --bg: #f5f6fa;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e6e8ef;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0ea5e9;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); text-decoration: none; }

/* ---------- 欢迎页（卡通活泼风格） ---------- */
.welcome {
  min-height: 100vh; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(160deg, #eef2ff 0%, #e0f2fe 45%, #fce7f3 100%);
  color: var(--text);
}
/* 漂浮的卡通色块装饰 */
.welcome::before, .welcome::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(4px); opacity: .55; z-index: 0;
}
.welcome::before { width: 280px; height: 280px; background: #c4b5fd; top: -80px; left: -60px; animation: float1 9s ease-in-out infinite; }
.welcome::after  { width: 240px; height: 240px; background: #fbcfe8; bottom: -70px; right: -50px; animation: float1 11s ease-in-out infinite reverse; }
@keyframes float1 { 0%,100%{transform:translateY(0)} 50%{transform:translateY(22px)} }
.blob { position: absolute; border-radius: 50%; z-index: 0; opacity: .5; }
.blob.b1 { width: 90px; height: 90px; background: #fde68a; top: 14%; right: 18%; animation: float1 7s ease-in-out infinite; }
.blob.b2 { width: 60px; height: 60px; background: #6ee7b7; bottom: 16%; left: 12%; animation: float1 8s ease-in-out infinite reverse; }

.welcome-card {
  position: relative; z-index: 1;
  width: 960px; max-width: 96vw;
  display: grid; grid-template-columns: 1.05fr .95fr; gap: 0;
  background: #ffffff;
  border: 3px solid #fff;
  border-radius: 28px; overflow: hidden;
  box-shadow: 0 30px 90px rgba(79,70,229,.22);
}
.welcome-hero {
  padding: 40px 36px; position: relative;
  background: linear-gradient(150deg, #6366f1 0%, #7c3aed 60%, #9333ea 100%);
  color: #fff;
}
.welcome-hero .logo { font-size: 30px; font-weight: 800; letter-spacing: .5px; display:flex; align-items:center; gap:10px; }
.welcome-hero .logo span { color: #fde68a; }
.welcome-hero .logo .badge-mascot { font-size: 26px; }
.welcome-hero h1 { font-size: 30px; margin: 16px 0 10px; line-height: 1.25; }
.welcome-hero p { color: rgba(255,255,255,.9); line-height: 1.7; margin: 0 0 14px; }
.hero-art { display:flex; justify-content:center; margin: 6px 0 4px; }
.hero-art img { width: 100%; max-width: 360px; border-radius: 18px; background: rgba(255,255,255,.14); padding: 8px; }
.hero-points { display:flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.hero-points .chip {
  background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.28);
  padding: 6px 12px; border-radius: 999px; font-size: 12px;
}
.welcome-login {
  background: #fff; color: var(--text);
  padding: 36px 34px; display: flex; flex-direction: column; justify-content: center; position: relative;
}
.welcome-login .mascot-mini {
  position: absolute; top: -42px; right: 26px; width: 96px; height: 96px;
  filter: drop-shadow(0 10px 18px rgba(79,70,229,.25));
  animation: bob 3.5s ease-in-out infinite;
}
@keyframes bob { 0%,100%{transform:translateY(0) rotate(-2deg)} 50%{transform:translateY(-8px) rotate(2deg)} }
.welcome-login h2 { margin: 0 0 4px; font-size: 24px; }
.welcome-login .sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display:block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 9px; font-size: 14px; background: #fff; color: var(--text);
}
.field textarea { resize: vertical; min-height: 72px; }
.role-pills { display:flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 18px; }
.role-pill {
  border: 2px solid var(--border); background:#fff; padding: 8px 14px; cursor: pointer;
  border-radius: 999px; font-size: 13px; color: var(--text); transition: all .15s; font-weight: 600;
}
.role-pill:hover { border-color: #c7d2fe; transform: translateY(-1px); }
.role-pill.active { background: var(--primary); border-color: var(--primary); color:#fff; box-shadow: 0 6px 16px rgba(79,70,229,.3); }
.welcome-login .field input { border-radius: 12px; border-width: 2px; }
.welcome-login #loginBtn { border-radius: 14px; padding: 13px; font-size: 15px; box-shadow: 0 10px 24px rgba(79,70,229,.28); }
.welcome-login #loginBtn:hover { transform: translateY(-1px); }

/* ---------- 顶栏 ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 22px; font-weight: 800; color: var(--primary); }
.logo span { color: var(--text); }
.product-name { font-weight: 600; }
.env-tag {
  font-size: 12px; background: var(--primary-soft); color: var(--primary-dark);
  padding: 3px 8px; border-radius: 6px;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.role-switch { display:flex; align-items:center; gap:8px; font-size: 13px; color: var(--muted); }
.role-switch select { padding: 7px 10px; border:1px solid var(--border); border-radius: 8px; font-size: 13px; }
.user-chip {
  display:flex; align-items:center; gap:8px; font-size: 13px;
  background: var(--bg); padding: 5px 10px 5px 5px; border-radius: 999px;
}
.user-chip .avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--primary);
  color:#fff; display:flex; align-items:center; justify-content:center; font-size: 12px; font-weight: 700;
}

/* ---------- 布局 ---------- */
.body { flex: 1; display: flex; }
.sidebar {
  width: 248px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px;
  position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto;
}
.nav-group-title { font-size: 11px; color: var(--muted); padding: 12px 12px 6px; letter-spacing: .04em; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--text); font-size: 14px; cursor: pointer; margin-bottom: 2px; user-select: none;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-item .ic { width: 18px; text-align:center; }
.nav-item .code { margin-left:auto; font-size: 10px; color: var(--muted); }
.sidebar-foot { margin-top: auto; padding: 12px; }
.main { flex: 1; padding: 24px 28px; overflow-x: hidden; }

/* ---------- 通用组件 ---------- */
.page-head { display:flex; align-items:flex-start; justify-content:space-between; margin-bottom: 18px; gap: 16px; }
.page-head h1 { font-size: 22px; margin: 0 0 6px; }
.page-head .desc { color: var(--muted); font-size: 13px; max-width: 760px; line-height: 1.6; }
.toolbar { display:flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.spacer { flex: 1; }

.btn {
  border: 1px solid transparent; background: var(--primary); color:#fff;
  padding: 9px 14px; border-radius: 9px; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-soft { background: var(--primary-soft); color: var(--primary-dark); }
.btn-soft:hover { background: #e0e7ff; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity:.5; cursor: not-allowed; }

.input, select.input, textarea.input {
  padding: 9px 12px; border:1px solid var(--border); border-radius: 9px; font-size: 13px; background:#fff;
}
.search { position: relative; }
.search input { padding-left: 32px; min-width: 240px; }
.search::before { content:"🔍"; position:absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; }

.cards { display:grid; grid-template-columns: repeat(auto-fill,minmax(280px,1fr)); gap: 16px; }
.card {
  background: var(--panel); border:1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-pad { padding: 16px; }
.card .cover, .cover {
  height: 128px; position: relative; overflow: hidden; background: linear-gradient(135deg,#6366f1,#8b5cf6);
}
.cover svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cover .cover-title {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 14px 10px; color: #fff;
  font-weight: 700; font-size: 15px; z-index: 1;
  background: linear-gradient(transparent, rgba(15,23,42,.42));
  text-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card .meta { color: var(--muted); font-size: 12px; line-height: 1.7; }
.card-actions { display:flex; gap:8px; padding: 0 16px 16px; flex-wrap: wrap; }

.grid-stats { display:grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 26px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat .trend { font-size: 12px; margin-top: 6px; }

.panel { background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600; display:flex; align-items:center; gap: 10px; }
.panel-body { padding: 16px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--muted); font-weight: 600; background: #fafbff; }
.tbl tr:hover td { background: #fafbff; }

.badge { display:inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.gray { background:#f1f3f7; color:#64748b; }
.badge.green { background:#dcfce7; color:#15803d; }
.badge.amber { background:#fef3c7; color:#b45309; }
.badge.red { background:#fee2e2; color:#b91c1c; }
.badge.blue { background:#dbeafe; color:#1d4ed8; }
.badge.purple { background:#ede9fe; color:#6d28d9; }

.tabs { display:flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 9px 14px; font-size: 13px; color: var(--muted); cursor:pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 600; }

.flow {
  display:flex; align-items:center; gap: 6px; flex-wrap: wrap;
  background: var(--primary-soft); border-radius: 10px; padding: 12px 14px; margin-bottom: 18px;
}
.flow .step { background:#fff; border:1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
.flow .arrow { color: var(--primary); font-weight: 700; }

/* 章节树 + 节点编辑 (A3/A4) */
.editor { display:grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
.tree { list-style: none; padding: 0; margin: 0; }
.tree li { margin-bottom: 4px; }
.tree-node {
  display:flex; align-items:center; gap:8px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
  border: 1px solid transparent;
}
.tree-node:hover { background: var(--bg); }
.tree-node.active { background: var(--primary-soft); color: var(--primary-dark); border-color:#c7d2fe; font-weight: 600; }
.tree-node .grip { cursor: grab; color: var(--muted); }
.tree-node .toggle { width: 14px; }
.tree-children { list-style:none; padding-left: 20px; margin: 4px 0 0; }
.tree-node.dragging { opacity:.4; }
.tree-node.drop-target { border-top: 2px solid var(--primary); }

.task-item {
  display:flex; align-items:center; gap: 10px; padding: 10px 12px; border:1px solid var(--border);
  border-radius: 9px; margin-bottom: 8px; background:#fff;
}
.task-item.dragging { opacity:.4; }
.task-item .grip { cursor: grab; color: var(--muted); }
.task-item .t-title { font-weight: 600; font-size: 13px; }
.task-item .t-type { font-size: 11px; }

.tool-gallery { display:grid; grid-template-columns: repeat(auto-fill,minmax(150px,1fr)); gap: 12px; }
.tool-tile {
  border:1px solid var(--border); border-radius: 10px; padding: 14px; cursor:pointer; background:#fff; text-align:center;
}
.tool-tile:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.tool-tile.active { border-color: var(--primary); background: var(--primary-soft); }
.tool-tile .ic { font-size: 26px; }
.tool-tile .nm { font-size: 13px; font-weight: 600; margin-top: 6px; }
.tool-tile .tg { font-size: 11px; color: var(--muted); }

.rich { border:1px solid var(--border); border-radius: 9px; }
.rich-toolbar { display:flex; gap: 4px; padding: 6px; border-bottom: 1px solid var(--border); background:#fafbff; }
.rich-toolbar button { border:1px solid var(--border); background:#fff; border-radius: 6px; width: 30px; height: 28px; font-size: 13px; }
.rich-area { min-height: 140px; padding: 12px; outline: none; font-size: 14px; line-height: 1.7; }

/* 进度条 */
.bar { height: 8px; background: var(--bg); border-radius: 999px; overflow:hidden; }
.bar > i { display:block; height: 100%; background: var(--primary); border-radius: 999px; }

/* 弹层 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); display:flex; align-items:center; justify-content:center;
  z-index: 50; padding: 20px;
}
.modal {
  background:#fff; border-radius: 14px; width: 560px; max-width: 96vw; max-height: 90vh; overflow:auto;
  box-shadow: 0 30px 80px rgba(0,0,0,.3);
}
.modal.lg { width: 820px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display:flex; align-items:center; justify-content:space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display:flex; justify-content:flex-end; gap: 10px; }
.modal .x { border:none; background:transparent; font-size: 20px; color: var(--muted); }

.toast-root { position: fixed; top: 18px; right: 18px; z-index: 80; display:flex; flex-direction: column; gap: 10px; }
.toast {
  background:#111827; color:#fff; padding: 11px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: toastIn .2s ease; max-width: 360px;
}
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
@keyframes toastIn { from { opacity:0; transform: translateY(-8px);} to {opacity:1; transform:none;} }

.checklist { list-style:none; padding:0; margin:0; }
.checklist li { display:flex; align-items:center; gap:10px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.dot { width: 9px; height:9px; border-radius:50%; display:inline-block; }
.dot.green{background:var(--success);} .dot.amber{background:var(--warning);} .dot.red{background:var(--danger);}

.kvs { display:grid; grid-template-columns: 140px 1fr; gap: 10px 16px; font-size: 13px; }
.kvs .k { color: var(--muted); }

.timeline { list-style:none; padding-left: 6px; margin: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--border); }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content:""; position:absolute; left: -6px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline .tm { font-size: 11px; color: var(--muted); }

.codebox { background:#0f172a; color:#e2e8f0; border-radius: 10px; padding: 14px; font-family: ui-monospace,Menlo,Consolas,monospace; font-size: 13px; line-height: 1.6; white-space: pre; overflow:auto; }
.notebook-cell { border:1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow:hidden; }
.notebook-cell .nc-in { display:flex; }
.notebook-cell .nc-gutter { background:#f1f5f9; color:#64748b; padding: 8px 8px; font-family: ui-monospace,monospace; font-size: 12px; }
.notebook-cell textarea { flex:1; border:none; padding: 8px; font-family: ui-monospace,monospace; font-size: 13px; resize: vertical; min-height: 60px; outline:none; }
.notebook-cell .nc-out { background:#fafbff; border-top: 1px solid var(--border); padding: 10px; font-family: ui-monospace,monospace; font-size: 12px; white-space: pre-wrap; }

.quiz { border:1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.quiz .q { font-weight: 600; margin-bottom: 10px; font-size: 14px; }
.opt { display:flex; align-items:center; gap: 8px; padding: 7px 10px; border:1px solid var(--border); border-radius: 8px; margin-bottom: 6px; cursor:pointer; font-size: 13px; }
.opt.sel { border-color: var(--primary); background: var(--primary-soft); }

.two-col { display:grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px){ .two-col{grid-template-columns:1fr;} .editor{grid-template-columns:1fr;} .welcome-card{grid-template-columns:1fr;} }

.empty { text-align:center; color: var(--muted); padding: 40px; }
.legend { display:flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.legend span::before { content:""; display:inline-block; width:10px; height:10px; border-radius:3px; margin-right:6px; vertical-align:middle; }
