/* ==========================================================================
   购课协议样式（h5 静态样式，不走 px2rem）
   - 桌面：表格布局，A4 打印
   - 移动端：字号放大、表格转卡片（td[data-label]）、吸底操作栏
   - PDF：.contract-pdf-root 强制桌面表格布局（PDF 由协议页端上生成）
   模板 HTML 只有结构与语义 class，样式全部在这里，四端共用同一份结构。
   ========================================================================== */

.contract-body {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 40px;
  color: #1f2329;
  font-size: 14px;
  line-height: 1.9;
  background: #fff;
  font-family: 'PingFang SC', sans-serif;
}

.contract-body h1 {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 1px;
}

.contract-body h2 {
  margin: 22px 0 10px;
  font-size: 15px;
  font-weight: 700;
}

.contract-body p {
  margin: 0 0 8px;
  text-align: justify;
}

.contract-body p.sub {
  margin-top: 14px;
  font-weight: 700;
}

.contract-body p.indent {
  padding-left: 1.6em;
}

.contract-body p.meta {
  margin-bottom: 4px;
}

/* 红色加粗提示条款：法务要求必须醒目，打印不能丢 */
.contract-body .warn {
  color: #d83931;
  font-weight: 700;
}

/* 待填内容占位（行内） */
.contract-body .fill {
  display: inline-block;
  min-width: 6em;
  padding: 0 4px;
  border-bottom: 1px solid #1f2329;
  text-align: center;
}

.contract-body table.contract-table {
  width: 100%;
  margin: 10px 0 14px;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

.contract-body table.contract-table th,
.contract-body table.contract-table td {
  border: 1px solid #1f2329;
  padding: 6px 8px;
  text-align: center;
  vertical-align: middle;
  word-break: break-word;
}

/* 赠品行：紧跟在所属套餐行下方（赠送套餐/手工赠品） */
.contract-body table.contract-table tr.gift-sub td {
  color: #666;
  background: #fafafa;
  padding-left: 28px;
  text-align: left;
  font-size: 0.92em;
}

/* 表头换行点：桌面宽度够时单行显示（隐藏 <br>），仅手机窄屏按语义换行 */
@media screen and (min-width: 769px) {
  .contract-body table.contract-table th br.th-br {
    display: none;
  }
}

.contract-body table.contract-table th {
  font-weight: 700;
  background: #f5f6f7;
}

.contract-body table.contract-table td.empty {
  color: #8a9099;
}

/* 签约确认区（替代手写签名） */
.contract-body .confirm-bar {
  margin: 24px 0 10px;
  padding: 14px 16px;
  border: 1px solid #1f2329;
  min-height: 84px;
  line-height: 1.9;
}

.contract-body .confirm-bar .confirm-title {
  font-weight: 700;
}

/* 签约确认声明（放在甲方确认栏框内，红色加粗） */
.contract-body .confirm-bar .sign-statement {
  color: #d83931;
  font-weight: 600;
  margin-top: 8px;
}

.contract-body .confirm-bar .confirm-line {
  margin-top: 8px;
}

.contract-body hr {
  border: none;
  border-top: 1px solid #dcdfe6;
  margin: 18px 0;
}

/* ------------------------- 小程序 web-view 页 ------------------------- */
/* 微信对含 web-view 的页面强制保留原生导航（navigationStyle custom 实测无效），
   小程序端用原生导航（标题自动同步 H5 网页标题），隐藏 H5 导航栏；返回靠原生返回按钮 */
body.in-miniprogram .head-back {
  display: none !important;
}

body.in-miniprogram .contract-page {
  padding-top: 0 !important;
}


/* 阅读进度条贴住返回条下沿 */
body.in-miniprogram .contract-progress {
  top: 0;
}


/* ------------------------- APP WebView（URL 带 isApp=1） ------------------------- */
/* APP 去掉了原生导航，用 H5 导航栏；状态栏高度优先取 APP 传参（--app-statusbar-height），
   未传时 iOS 回落 env(safe-area-inset-top)，H5 导航栏与正文随之下移 */
body.in-app .head-back {
  top: var(--app-statusbar-height, env(safe-area-inset-top, 0px));
}

body.in-app .contract-progress {
  top: calc(2.933rem + var(--app-statusbar-height, env(safe-area-inset-top, 0px)));
}

body.in-app .contract-page {
  padding-top: calc(3.2rem + var(--app-statusbar-height, env(safe-area-inset-top, 0px)));
}

/* ------------------------- APP WebView（URL 带 isApp=1） ------------------------- */
/* APP 去掉了原生导航，WebView 顶到状态栏下。
   顶部高度优先用 APP 通过 URL 参数 statusBarHeight 传入的值（initial.js 落 cookie，App.vue 转成 CSS 变量）；
   APP 没传时 iOS 回落 env(safe-area-inset-top)（需 WebView 全屏铺到状态栏下，Android 该值为 0 只能靠传参），
   H5 导航栏和正文随之下移 */
body.in-app .head-back {
  top: var(--app-statusbar-height, env(safe-area-inset-top, 0px));
}

body.in-app .contract-page {
  padding-top: calc(3.2rem + var(--app-statusbar-height, env(safe-area-inset-top, 0px)));
}

/* ------------------------- 协议页外壳 ------------------------- */
.contract-page {
  min-height: 100vh;
  /* NavBar 高度按设计稿为 2.933rem，这里留 3.2rem 避免覆盖 */
  padding-top: 3.2rem;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: #f5f6f7;
  font-family: 'PingFang SC', sans-serif;
}

.contract-page.has-bar {
  /* 吸底栏：声明抄写区 + 勾选 + 按钮，留足 280px 避免遮住正文 */
  padding-bottom: calc(280px + env(safe-area-inset-bottom));
}

.contract-nav-placeholder {
  height: 44px;
}

/* 我的协议列表 */
.contract-list {
  padding: 12px;
}

.contract-card {
  margin-bottom: 12px;
  padding: 14px;
  background: #fff;
  border-radius: 8px;
}

.contract-card .card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.contract-card .card-title {
  flex: 1;
  color: #1f2329;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}

.contract-card .card-status {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  line-height: 18px;
}

.contract-card .card-status.pending {
  color: #d83931;
  background: #fdecea;
}

.contract-card .card-status.active {
  color: #2f9e44;
  background: #e8f7ed;
}

.contract-card .card-status.ended {
  color: #8a9099;
  background: #f0f2f5;
}

.contract-card .card-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  color: #606266;
  font-size: 13px;
}

.contract-card .card-row .label {
  color: #8a9099;
}

.contract-card .card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f0f2f5;
}

/* 操作按钮：加宽加高（van small 太小气），主色 #0087FF：主操作实心、次操作描边 */
.contract-card .card-actions .van-button {
  min-width: 88px;
  height: 32px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 16px;
}

.contract-card .card-actions .btn-main {
  background: #0087ff;
  border: 1px solid #0087ff;
  color: #fff;
}

.contract-card .card-actions .btn-ghost {
  background: #fff;
  border: 1px solid #0087ff;
  color: #0087ff;
}

/* 协议页主操作按钮（详情/签署吸底栏）：主蓝实心，plain 时主蓝描边（!important 防 van 默认样式按加载顺序覆盖） */
.btn-main {
  background: #0087ff !important;
  border: 1px solid #0087ff !important;
  color: #fff !important;
}

.btn-main.van-button--plain {
  background: #fff !important;
  color: #0087ff !important;
}

.btn-main.van-button--disabled {
  opacity: 0.5;
}

.contract-empty {
  padding: 80px 0;
  color: #8a9099;
  font-size: 14px;
  text-align: center;
}

/* 只读提示 / 加载失败 */
.contract-tip {
  margin: 0px 0 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff7e6;
  color: #b26a00;
  font-size: 13px;
  line-height: 1.6;
}

/* ------------------------- 吸底操作栏 ------------------------- */
.contract-action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #ebeef5;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
}

.contract-action-bar .agree {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: #606266;
  font-size: 13px;
  line-height: 1.5;
}

.contract-action-bar .agree .warn-link {
  color: #d83931;
}

.contract-action-bar .btn-confirm {
  display: block;
  width: 100%;
  height: 44px;
  margin-top: 10px;
  border: none;
  border-radius: 22px;
  background: #0087ff;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.contract-action-bar .btn-confirm[disabled] {
  background: #c8c9cc;
}

/* 签署声明（抄写确认）：与吸底栏融为一体，浅灰底无边框输入框 + 文字按钮 */
.contract-action-bar .statement-box {
  margin-bottom: 12px;
}

.contract-action-bar .statement-label {
  margin: 0;
  color: #909399;
  font-size: 12px;
  line-height: 1.5;
}

.contract-action-bar .statement-text {
  margin: 4px 0 0;
  color: #d83931;
  font-size: 12px;
  line-height: 1.5;
}

.contract-action-bar .statement-input {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.contract-action-bar .statement-input input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: #f5f6f7;
  color: #303133;
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.contract-action-bar .statement-input input::placeholder {
  color: #c0c4cc;
}

.contract-action-bar .statement-input input:focus {
  background: #eef1f6;
  box-shadow: 0 0 0 1.5px rgba(0, 135, 255, 0.3);
}

.contract-action-bar .statement-input .btn-fill {
  flex-shrink: 0;
  height: 40px;
  padding: 0;
  border: none;
  background: none;
  color: #0087ff;
  font-size: 14px;
  font-weight: 500;
}

.contract-action-bar .statement-input .btn-fill:active {
  opacity: 0.7;
}

.contract-action-bar .statement-hint {
  min-height: 17px;
  margin: 6px 0 0;
  color: #909399;
  font-size: 12px;
  line-height: 1.4;
}

.contract-action-bar .statement-hint.danger {
  color: #d83931;
}
/* 阅读进度：紧贴导航栏底边，盖住导航栏与正文之间的缝隙，避免滚动时漏字 */
/* 阅读进度条：位置跟随导航栏高度（rem，PC 与手机基准不同），高度固定 px 避免安卓过细不可见 */
.contract-progress {
  position: fixed;
  left: 0;
  right: 0;
  top: 2.933rem;
  z-index: 999;
  height: 4px;
  background: #d6ebff;
}

.contract-progress .bar {
  height: 100%;
  background: #0087ff;
  transition: width 0.15s linear;
}

/* ------------------------- 桌面浏览（PC 直接打开 H5） ------------------------- */
@media screen and (min-width: 769px) {
  .contract-list {
    max-width: 820px;
    margin: 0 auto;
  }

  /* 吸底栏内容与协议正文同宽，避免大屏上按钮横跨整个窗口 */
  .contract-action-bar {
    padding-left: max(14px, calc(50% - 410px));
    padding-right: max(14px, calc(50% - 410px));
  }
}

/* ------------------------- 移动端 ------------------------- */
@media screen and (max-width: 768px) {
  .contract-body {
    max-width: none;
    padding: 16px 14px 24px;
    font-size: 15px;
    line-height: 1.75;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .contract-body h1 {
    margin: 0 0 16px;
    font-size: 18px;
    letter-spacing: 0;
  }

  .contract-body h2 {
    margin: 22px 0 8px;
    font-size: 16px;
  }

  .contract-body p {
    margin: 0 0 10px;
    text-align: left;
  }

  .contract-body p.sub {
    margin-top: 16px;
    font-size: 15px;
  }

  .contract-body p.indent {
    padding-left: 0;
    margin-left: 0;
  }

  .contract-body .fill {
    min-width: 4em;
  }

  /* 表格：移动端保持真表格排版（与协议原文一致），仅压缩字号与内边距 */
  .contract-body table.contract-table {
    display: table;
    width: 100%;
    margin: 10px 0 14px;
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 11px;
  }

  .contract-body table.contract-table thead {
    display: table-header-group;
  }

  .contract-body table.contract-table tbody {
    display: table-row-group;
  }

  .contract-body table.contract-table tr {
    display: table-row;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
  }

  .contract-body table.contract-table th,
  .contract-body table.contract-table td {
    display: table-cell;
    padding: 5px 3px;
    border: 1px solid #1f2329;
    text-align: center;
    vertical-align: middle;
    font-size: 11px;
    line-height: 1.45;
    word-break: break-word;
    word-wrap: break-word;
  }

  .contract-body table.contract-table th {
    background: #f2f3f5;
    font-weight: 600;
    white-space: nowrap;
  }


  .contract-body table.contract-table td[data-label]::before {
    content: none;
  }

  /* 赠品行：跨列左对齐、浅底，随主套餐行展示 */
  .contract-body table.contract-table tr.gift-sub td {
    text-align: left;
    padding-left: 10px;
    background: #fafafa;
    font-size: 11px;
  }

  .contract-body .confirm-bar {
    margin: 20px 0 8px;
    padding: 12px 14px;
    min-height: auto;
    border-radius: 6px;
    background: #f7f8fa;
  }

  .contract-body .confirm-bar .confirm-line {
    margin-top: 6px;
  }
}

/* ------------------------- PDF 生成（端上截图） ------------------------- */
/* 截图宿主必须离屏但可测量，宽度按 A4 96dpi = 794px */
.contract-pdf-host {
  position: fixed;
  top: 0;
  left: -10000px;
  z-index: -1;
  width: 794px;
  background: #fff;
}

.contract-pdf-root {
  max-width: none;
  font-size: 12.5px;
  line-height: 1.75;
  color: #1f2329;
}

/* 移动端会把表格变成卡片，PDF 必须是真正的表格；这里同时兜底 */
.contract-pdf-root table.contract-table {
  display: table;
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.contract-pdf-root table.contract-table thead {
  display: table-header-group;
}

.contract-pdf-root table.contract-table tbody {
  display: table-row-group;
}

.contract-pdf-root table.contract-table tr {
  display: table-row;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

.contract-pdf-root table.contract-table th,
.contract-pdf-root table.contract-table td {
  display: table-cell;
  border: 1px solid #1f2329;
  padding: 5px 6px;
  text-align: center;
  vertical-align: middle;
  font-size: 12px;
}

.contract-pdf-root table.contract-table th {
  background: #f5f6f7;
  font-weight: 700;
}

.contract-pdf-root table.contract-table td::before {
  content: none;
}

.contract-pdf-root .warn {
  color: #d83931;
  font-weight: 700;
}

/* ------------------------- A4 打印（PC 浏览器直接打印时用） ------------------------- */
@media print {
  @page {
    size: A4 portrait;
    margin: 12mm 10mm;
  }

  body {
    background: #fff;
  }

  .no-print,
  .contract-action-bar,
  .contract-progress,
  .van-nav-bar,
  .head-back {
    display: none !important;
  }

  .contract-page {
    padding: 0;
    background: #fff;
  }

  .contract-body {
    max-width: none;
    padding: 0;
    font-size: 12px;
    line-height: 1.7;
  }

  .contract-body table.contract-table {
    /* 长表格允许跨页（浏览器会自动重复 thead），但单行不拆开 */
    page-break-inside: auto;
    break-inside: auto;
  }

  .contract-body table.contract-table tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .contract-body .confirm-bar {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .contract-body h2 {
    page-break-after: avoid;
    break-after: avoid;
  }

  .contract-body .warn {
    color: #d83931 !important;
    font-weight: 700 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .contract-body table.contract-table th {
    background: #f5f6f7 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
