:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2129;
  --muted: #86909c;
  --line: #e5e6eb;
  --primary: #2b6cf0;
  --primary-soft: #e8f0fe;
  --ok: #18a058;
  --ok-soft: #e7f6ee;
  --warn: #d48806;
  --warn-soft: #fff7e6;
  --bad: #d03050;
  --bad-soft: #fdecef;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --card: #1b1e24; --text: #e6e8eb; --muted: #8b929c; --line: #2a2e36;
    --primary: #5b8ef7; --primary-soft: #1d2a45; --ok: #3cc47c; --ok-soft: #16302a;
    --warn: #e8a93a; --warn-soft: #33290f; --bad: #f0607a; --bad-soft: #3a1a22;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }

/* 按钮 / 表单 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; white-space: nowrap; transition: .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; height: 44px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); outline: none; transition: .15s;
}
textarea.input { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field { margin-bottom: 14px; }
.field > label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.pad { padding: 20px; }

.tag { display: inline-block; padding: 0 8px; border-radius: 999px; font-size: 12px; line-height: 22px; white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.gray { background: var(--bg); color: var(--muted); }
.tag.blue { background: var(--primary-soft); color: var(--primary); }

/* 登录页 */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 380px; }
.login-box h1 { font-size: 22px; margin: 0 0 4px; text-align: center; }
.login-box .sub { text-align: center; color: var(--muted); margin-bottom: 24px; }
.logo { width: 52px; height: 52px; border-radius: 14px; background: var(--primary); color: #fff; display: grid; place-items: center; margin: 0 auto 14px; }
.err { color: var(--bad); font-size: 13px; min-height: 20px; margin: -4px 0 8px; }

/* 顶栏 */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar .inner { max-width: 1100px; margin: 0 auto; height: 56px; padding: 0 16px; display: flex; align-items: center; gap: 12px; }
.topbar .brand { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand .dot { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; flex: none; }
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }

/* 课程卡片 */
.notice { padding: 12px 16px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); margin-bottom: 16px; font-size: 14px; white-space: pre-wrap; }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.course-card { padding: 18px; cursor: pointer; transition: .15s; display: flex; flex-direction: column; gap: 8px; }
.course-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.course-card h3 { margin: 0; font-size: 16px; }
.course-card .desc { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.course-card .foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.course-card.expired { opacity: .6; cursor: default; }
.course-card.expired:hover { border-color: var(--line); transform: none; }
.section-title { font-size: 18px; font-weight: 600; margin: 0 0 14px; display: flex; align-items: center; gap: 10px; }

/* 文件列表 */
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 14px; margin-bottom: 12px; }
.crumbs a { padding: 2px 4px; border-radius: 4px; }
.crumbs .sep { color: var(--muted); }
.file-list { list-style: none; margin: 0; padding: 0; }
.file-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.file-item:last-child { border-bottom: 0; }
.file-item.folder { cursor: pointer; }
.file-item.folder:hover { background: var(--bg); }
.file-ico { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--bg); color: var(--muted); }
.file-ico.folder { background: var(--warn-soft); color: var(--warn); }
.file-ico.video { background: var(--primary-soft); color: var(--primary); }
.file-ico.audio { background: var(--ok-soft); color: var(--ok); }
.file-name { word-break: break-all; line-height: 1.4; }
.file-meta { font-size: 12px; color: var(--muted); }
.fbtn { flex: none; }
@media (max-width: 520px) {
  .file-item { padding: 12px; gap: 10px; }
  .fbtn { width: 36px; height: 36px; padding: 0; }
  .fbtn .lbl { display: none; }
}
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* 后台布局 */
.admin-layout { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar { width: 220px; flex: none; background: var(--card); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; height: 100dvh; }
.sidebar .brand { font-weight: 600; padding: 6px 10px 18px; display: flex; gap: 8px; align-items: center; }
.sidebar .brand .dot { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.admin-main { flex: 1; min-width: 0; }
.admin-main .head { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
.admin-main .head h2 { font-size: 17px; margin: 0; }
.admin-main .body { padding: 20px; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .admin-main .body { padding: 14px; }
  .admin-main .head { padding: 0 14px; }
}
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 16px; }
.stat .n { font-size: 26px; font-weight: 600; line-height: 1.2; }
.stat .l { color: var(--muted); font-size: 13px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar .input { width: auto; min-width: 140px; }
.toolbar .search { flex: 1; min-width: 180px; }

/* 表格（窄屏转卡片） */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 500; font-size: 13px; background: var(--bg); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.actions { white-space: nowrap; text-align: right; }
.tbl .chk { width: 36px; }
@media (max-width: 760px) {
  .tbl.responsive thead { display: none; }
  .tbl.responsive tr { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line); position: relative; }
  .tbl.responsive td { display: flex; border: 0; padding: 3px 0; gap: 10px; }
  .tbl.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12px; width: 70px; flex: none; padding-top: 1px; }
  .tbl.responsive td.chk { position: absolute; right: 12px; top: 12px; width: auto; }
  .tbl.responsive td.chk::before, .tbl.responsive td.actions::before { display: none; }
  .tbl.responsive td.actions { justify-content: flex-start; padding-top: 8px; flex-wrap: wrap; }
}

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.modal.wide { max-width: 720px; }
.modal .mh { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; font-weight: 600; }
.modal .mb { padding: 20px; overflow-y: auto; }
.modal .mf { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.x { border: 0; background: none; cursor: pointer; margin-left: auto; color: var(--muted); font-size: 22px; line-height: 1; padding: 4px; }
@media (max-width: 560px) {
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal { max-height: 92dvh; border-radius: 16px 16px 0 0; }
}

.course-pick { border: 1px solid var(--line); border-radius: 8px; max-height: 260px; overflow-y: auto; }
.course-pick .it { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.course-pick .it:last-child { border-bottom: 0; }
.course-pick .it input[type=datetime-local] { height: 32px; width: auto; font-size: 13px; }

.toast { position: fixed; left: 50%; top: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; z-index: 200; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 4px 20px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); color: #fff; }

.pager { display: flex; gap: 8px; justify-content: center; align-items: center; padding: 14px; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.loading { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 40px; color: var(--muted); }
code.k { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 13px; }
