/*
 * 王大头AI 私域在线学习平台 · M1 新增组件样式（ui.css）
 * 依赖同目录 course.css（mkpage.py 基线视觉）。本文件只做「叠加」，不覆盖基线选择器的原有含义。
 *
 * 约定：
 *   - 无外链资源，无 webfont，无构建工具。
 *   - 所有 grid / flex 子项显式 min-width: 0，避免长文本撑破容器。
 *   - [hidden] 一律 display:none !important，避免被组件的 display 规则顶掉。
 *   - 不出现任何与后端相关的行为；交互逻辑在 learn.js / admin.js。
 */

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── 防止 grid / flex 子项被内容撑破 ── */
.layout > *, .chapters > *, .course-grid > *, .kpi-grid > *, .list > *,
.field-row > *, .admin-wrap > *, .admin-main > *, .bn-top-in > *,
.err-actions > *, .card-actions > *, .confirm-actions > *, .subnav > *,
.buybar > * { min-width: 0; }

.stage { max-width: 100%; }

/* ── 课程详情页两栏布局 ── */
.layout--single { grid-template-columns: minmax(0, 1fr); }

.layout--course {
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  align-items: start;
  gap: 32px 48px;
}
.layout--course > header { grid-column: 1; grid-row: 1; }
.layout--course > .stage { grid-column: 1; grid-row: 2; justify-self: start; }
.layout--course > .buy { grid-column: 2; grid-row: 1 / span 2; }
.layout--course > .chapters { grid-column: 1 / -1; grid-row: 3; }
.layout--course > .note { grid-column: 1 / -1; grid-row: 4; }

/* ── 购买块 ── */
.buy {
  border: 1px solid var(--line); border-radius: 24px; padding: 22px;
  background: rgba(255, 252, 246, 0.82);
  box-shadow: 0 18px 44px rgba(48, 32, 12, 0.1);
}
.buy-price { margin: 0 0 4px; font-size: 30px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.buy-perks { margin: 14px 0 18px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.buy-perks li { font-size: 14px; line-height: 1.5; color: var(--ink-soft); padding-left: 18px; position: relative; }
.buy-perks li::before {
  content: ""; position: absolute; left: 2px; top: 0.62em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--moss);
}
.buy-note { margin: 12px 0 0; font-size: 13px; line-height: 1.6; color: var(--ink-soft); }
.buy-refresh { display: inline-block; margin-top: 10px; font-size: 13px; color: var(--moss-deep); }

/* ── 课时徽章 ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 8px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px; line-height: 1.4;
  border: 1px solid var(--line); background: rgba(255, 252, 246, 0.9);
  color: var(--ink-soft); white-space: nowrap;
}
.badge--trial { color: var(--moss-deep); border-color: rgba(27, 107, 74, 0.35); background: rgba(27, 107, 74, 0.1); }
.badge--locked { color: #8a2e1b; border-color: rgba(138, 46, 27, 0.3); background: rgba(138, 46, 27, 0.08); }
.badge--done { color: #fff; background: var(--moss); border-color: var(--moss); }

/* ── 播放器错误面板（覆盖在 video 之上） ── */
.stage > .error {
  position: absolute; inset: 0; z-index: 3; margin: 0; padding: 24px;
  display: none; flex-direction: column; justify-content: center; align-items: flex-start; gap: 10px;
  background: rgba(18, 16, 14, 0.88); color: #fff; border-radius: inherit; overflow: auto;
}
.stage > .error.show { display: flex; }
.err-title { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.45; color: #fff; }
.err-sub { margin: 0; font-size: 14px; line-height: 1.65; color: rgba(255, 255, 255, 0.8); }
.err-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.err-code { margin: 6px 0 0; font-size: 11px; letter-spacing: 0.08em; color: rgba(255, 255, 255, 0.5); }

/* ── 支付确认中遮罩 ── */
.paymask {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center;
  padding: 24px; text-align: center; font-size: 15px; line-height: 1.6;
  background: rgba(18, 16, 14, 0.82); color: #fff;
}

/* ── 移动端底部固定购买栏（≤860px 才显示） ── */
.buybar {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 9997;
  align-items: center; gap: 12px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(252, 249, 243, 0.96); backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(48, 32, 12, 0.12);
}
.buybar > span { flex: 1 1 auto; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── 按钮 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 12px 20px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform 0.16s, box-shadow 0.16s, background 0.16s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(48, 32, 12, 0.12); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--moss); border-color: var(--moss); color: #fff; box-shadow: 0 10px 26px rgba(27, 107, 74, 0.24); }
.btn-primary:hover { background: #155c3f; }
.btn-danger { background: #8a2e1b; border-color: #8a2e1b; color: #fff; }
.btn-danger:hover { background: #732414; }
.btn-block { display: flex; width: 100%; }

/* ── 卡片 / 面板 ── */
.card { border: 1px solid var(--line); border-radius: 18px; background: rgba(255, 252, 246, 0.72); padding: 20px; }
.panel { border: 1px solid var(--line); border-radius: 20px; background: rgba(255, 252, 246, 0.72); padding: 22px; margin: 0 0 22px; }
.panel-title { margin: 0 0 14px; font-size: 16px; font-weight: 700; line-height: 1.4; }
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* ── 表格 ── */
.table-wrap {
  width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px;
  background: rgba(255, 252, 246, 0.72);
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; letter-spacing: 0.06em; color: var(--ink-soft); font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }

/* ── 表单 ── */
.field { display: block; margin: 0 0 16px; }
.field-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.field-row > .field { flex: 1 1 220px; margin-bottom: 0; }
.field-label { display: block; margin: 0 0 6px; font-size: 13px; font-weight: 600; line-height: 1.4; }
.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  color: var(--ink); font: inherit; font-size: 15px;
}
textarea.input { min-height: 96px; resize: vertical; }
.hint { margin: 8px 0 0; font-size: 13px; line-height: 1.6; color: var(--ink-soft); }

/* ── 空态 ── */
.empty {
  margin: 18px 0 0; padding: 28px 20px; border: 1px dashed var(--line); border-radius: 18px;
  text-align: center; font-size: 14px; line-height: 1.7; color: var(--ink-soft);
  background: rgba(255, 252, 246, 0.5);
}

/* ── 课程卡片网格 ── */
.course-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px; margin: 24px 0 0; padding: 0; list-style: none;
}
.course-card {
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--line); border-radius: 20px; background: rgba(255, 252, 246, 0.72);
}
.course-card-link { display: flex; flex-direction: column; height: 100%; color: inherit; text-decoration: none; }
.course-thumb { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--paper-2); }
.course-card-body { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; padding: 16px 18px 18px; }
.course-card-title { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.45; }
.course-card-lead { margin: 0; font-size: 14px; line-height: 1.6; color: var(--ink-soft); }
.course-card-meta { margin: 0; display: flex; flex-wrap: wrap; gap: 8px; font-size: 12.5px; color: var(--ink-soft); }

/* ── 列表 ── */
.list { margin: 18px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.list-item {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px;
  background: rgba(255, 252, 246, 0.72);
}
.list-item-main { flex: 1 1 240px; }
.list-item-title { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.5; }
.list-item-meta { margin: 4px 0 0; font-size: 13px; line-height: 1.5; color: var(--ink-soft); }
.tag {
  display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; line-height: 1.4; border: 1px solid var(--line); background: #fff; white-space: nowrap;
}

/* ── 二级导航 ── */
.subnav { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 24px 0 0; }
.subnav a, .subnav button {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 16px;
  border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.subnav a[aria-current="page"] { background: var(--moss); border-color: var(--moss); color: #fff; }

/* ── 后台指标卡 ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin: 0 0 22px; }
.kpi { border: 1px solid var(--line); border-radius: 18px; background: rgba(255, 252, 246, 0.72); padding: 16px 18px; }
.kpi-label { margin: 0; font-size: 12.5px; letter-spacing: 0.06em; color: var(--ink-soft); }
.kpi-value { margin: 8px 0 0; font-size: 26px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }

/* ── 后台骨架 ── */
.admin-wrap {
  width: min(1240px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 64px;
  display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 32px; align-items: start;
}
.admin-nav {
  position: sticky; top: 76px; display: flex; flex-direction: column; gap: 4px;
  padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255, 252, 246, 0.72);
}
.admin-nav a { display: block; padding: 9px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; font-size: 14px; line-height: 1.4; }
.admin-nav a:hover { background: rgba(27, 107, 74, 0.08); }
.admin-nav a[aria-current="page"] { background: var(--moss); color: #fff; font-weight: 600; }
.admin-title {
  margin: 0; font-family: "Songti SC", "STSong", "Noto Serif SC", "Palatino Linotype", serif;
  font-size: clamp(24px, 3.2vw, 32px); font-weight: 600; line-height: 1.25; letter-spacing: -0.02em;
}
.admin-sub { margin: 8px 0 22px; font-size: 14px; line-height: 1.6; color: var(--ink-soft); }

/* ── 二次确认（复用 course.css 的 .lightbox 外观） ── */
.confirm { width: min(460px, 92vw); padding: 22px; border-radius: 20px; background: var(--paper); color: var(--ink); }
.confirm h2 { margin: 0 0 10px; font-size: 18px; line-height: 1.4; }
.confirm p { margin: 0 0 12px; font-size: 14px; line-height: 1.65; color: var(--ink-soft); }
.confirm-warn {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid rgba(138, 46, 27, 0.25); background: rgba(138, 46, 27, 0.08);
  color: #8a2e1b; font-size: 13px; line-height: 1.6;
}
.confirm-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ── 顶栏补充 ── */
.bn-spacer { flex: 1 1 auto; }
.bn-user {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 8px 14px;
  border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-size: 13.5px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.bn-top.is-scrolled { box-shadow: 0 4px 18px rgba(48, 32, 12, 0.12); }

/* ── 响应式 ── */
@media (max-width: 860px) {
  .layout--course { grid-template-columns: 1fr; gap: 22px; }
  .layout--course > header,
  .layout--course > .stage,
  .layout--course > .buy,
  .layout--course > .chapters,
  .layout--course > .note { grid-column: 1; grid-row: auto; }
  .layout--course > .stage { justify-self: center; }
  .buybar { display: flex; }
  body.has-buybar { padding-bottom: 84px; }
  .admin-wrap { grid-template-columns: 1fr; gap: 18px; padding-top: 18px; }
  .admin-nav { position: static; flex-direction: row; flex-wrap: wrap; }
  .admin-nav a { flex: 0 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .subnav a, .subnav button, .admin-nav a { transition: none; }
}
/* ── M2a：学员水印容器（内容由 M3 填写）与自动播放被拦提示 ── */
#wm {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  display: flex; align-items: flex-start; justify-content: flex-end;
  padding: 16px; text-align: right;
  color: rgba(255, 255, 255, 0.72); font-size: 12px; line-height: 1.5; letter-spacing: 0.04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); background: none;
  opacity: 0.55; user-select: none; overflow: hidden;
}
.stage > .cover { z-index: 2; }
.play-hint {
  position: absolute; left: 16px; right: 16px; top: 16px; z-index: 2; margin: 0;
  padding: 10px 14px; border-radius: 12px; pointer-events: none;
  background: rgba(18, 16, 14, 0.72); color: #fff; font-size: 13px; line-height: 1.6; text-align: center;
}
.play-hint[hidden] { display: none; }