/* ── 重置 & 基础 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a6b9e;
  --primary-light: #e8f4fb;
  --primary-dark: #0f4a72;
  --accent: #27ae60;
  --accent-light: #eafaf1;
  --warn: #e67e22;
  --warn-light: #fef5ec;
  --purple: #8e44ad;
  --purple-light: #f5eef8;
  --red: #c0392b;
  --gray-50: #f8f9fa;
  --gray-100: #f0f2f5;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

html {
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: "PingFang SC", "Microsoft YaHei", "微软雅黑", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  color: var(--gray-800);
  background: var(--gray-100);
}

/* ── 加载遮罩 ── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.95);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.loading-box { text-align: center; }
.loading-spinner {
  width: 52px; height: 52px;
  border: 5px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-box p { font-size: 15px; color: var(--gray-600); }

/* ── 错误遮罩 ── */
.error-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.error-box {
  background: #fff; border-radius: var(--radius);
  padding: 36px 44px; max-width: 460px; text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.error-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: #fee2e2; color: var(--red);
  font-size: 24px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
}
.error-box h3 { color: var(--red); margin-bottom: 10px; }
.error-box p { color: var(--gray-600); font-size: 13px; line-height: 1.7; margin-bottom: 18px; }
.error-box button {
  padding: 7px 24px; background: var(--primary); color: #fff;
  border: none; border-radius: 6px; cursor: pointer; font-size: 14px;
}

/* ── 页面布局 ── */
.page-wrapper {
  display: flex; justify-content: center;
  padding: 12px 12px 32px;
}
.doc-container {
  width: 860px; max-width: 100%;
}

/* ── 文档头部 ── */
.doc-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: #fff; border-radius: var(--radius);
  padding: 20px 24px 18px; margin-bottom: 12px;
  position: relative; overflow: hidden;
}
.doc-header::after {
  content: '';
  position: absolute; right: -40px; top: -40px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
}
.doc-header-badge {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 11px;
  margin-bottom: 4px;
  letter-spacing: 1px;
}
.doc-title {
  font-size: 26px; font-weight: 700;
  letter-spacing: 3px; margin-bottom: 2px;
}
.doc-subtitle {
  font-size: 12px; opacity: 0.7;
  letter-spacing: 1px; margin-bottom: 10px;
}
.doc-meta {
  display: flex; gap: 20px;
  font-size: 12px; opacity: 0.85;
}
.doc-meta strong { opacity: 1; }

/* ── 通用卡片 ── */
.section-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
}

.section-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
}
.section-icon { font-size: 18px; }
.section-header h2 {
  font-size: 15px; font-weight: 700;
  color: var(--primary-dark);
  letter-spacing: 1px;
}

/* ── 基本信息网格 ── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  padding: 12px 18px;
}
.info-item {
  padding: 8px 12px;
  border-right: 1px solid var(--gray-200);
  border-bottom: 1px solid var(--gray-200);
}
.info-item:nth-child(4n) { border-right: none; }
.info-item--wide {
  grid-column: span 2;
}
.info-label {
  font-size: 10px; color: var(--gray-400);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 2px;
}
.info-value {
  font-size: 13px; font-weight: 600; color: var(--gray-800);
}

/* ── 子区块 ── */
.sub-section { padding: 12px 18px; border-bottom: 1px solid var(--gray-200); }
.sub-section:last-child { border-bottom: none; }
.sub-title {
  font-size: 13px; font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
  padding-left: 8px;
  border-left: 3px solid var(--primary);
}

/* ── 总体原则卡片 ── */
.principle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.principle-card {
  background: var(--primary-light);
  border-radius: 6px;
  padding: 10px 12px;
  border-left: 4px solid var(--primary);
}
.principle-card .p-label {
  font-size: 11px; color: var(--primary);
  font-weight: 600; margin-bottom: 2px;
}
.principle-card .p-value {
  font-size: 13px; color: var(--gray-800); font-weight: 500;
}

/* 嵌套对象/数组格式化显示（避免 [object Object]） */
.format-obj { margin-top: 2px; }
.format-kv { margin-bottom: 3px; }
.format-kv:last-child { margin-bottom: 0; }
.format-key { color: var(--gray-600); font-weight: 500; }
.format-val { color: var(--gray-800); }
.format-list { list-style: disc; }

/* ── 训练计划 ── */
.training-block { margin-bottom: 12px; }
.training-block:last-child { margin-bottom: 0; }
.training-block-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700;
  color: var(--gray-800); margin-bottom: 6px;
}
.training-freq-badge {
  font-size: 10px; background: var(--accent-light);
  color: var(--accent); border-radius: 10px;
  padding: 2px 8px; font-weight: 600;
}
.training-items { display: flex; flex-direction: column; gap: 6px; }
.training-item {
  background: var(--gray-50);
  border-radius: 6px;
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
}
.training-item-name {
  font-size: 12px; font-weight: 700;
  color: var(--accent); margin-bottom: 4px;
}
.training-detail-list { padding-left: 0; list-style: none; }
.training-detail-list li {
  padding: 2px 0 2px 14px;
  position: relative;
  font-size: 12px; color: var(--gray-600);
  line-height: 1.45;
}
.training-detail-list li::before {
  content: '▸';
  position: absolute; left: 0;
  color: var(--accent);
}

/* 专项改善 */
.special-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.special-card {
  background: var(--accent-light);
  border-radius: 6px; padding: 10px 12px;
  border-left: 4px solid var(--accent);
}
.special-card .s-project {
  font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 4px;
}
.special-card .s-row { font-size: 11px; color: var(--gray-600); margin-bottom: 2px; }
.special-card .s-row strong { color: var(--gray-800); }

/* ── 安全注意事项 ── */
.safety-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.safety-item {
  background: var(--warn-light);
  border-radius: 6px; padding: 8px 10px;
  border-left: 4px solid var(--warn);
}
.safety-item .sa-key {
  font-size: 11px; font-weight: 700;
  color: var(--warn); margin-bottom: 2px;
}
.safety-item .sa-val {
  font-size: 12px; color: var(--gray-700); line-height: 1.45;
}

/* ── 营养需求 ── */
.nutrition-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.nutrition-item {
  text-align: center;
  background: var(--primary-light);
  border-radius: 6px;
  padding: 8px 6px;
}
.nutrition-item .n-label {
  font-size: 10px; color: var(--gray-400); margin-bottom: 4px;
}
.nutrition-item .n-value {
  font-size: 12px; font-weight: 700; color: var(--primary-dark);
  line-height: 1.25;
}

/* ── 膳食安排 ── */
.meal-plan {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.meal-card {
  border-radius: 6px; overflow: hidden;
  border: 1px solid var(--gray-200);
}
.meal-card-header {
  background: var(--primary);
  color: #fff; padding: 6px 10px;
  font-size: 12px; font-weight: 700;
}
.meal-card-time {
  font-size: 10px; opacity: 0.8; font-weight: normal;
}
.meal-card-body { padding: 8px 10px; background: var(--gray-50); }
.meal-suggest { font-size: 12px; color: var(--gray-800); margin-bottom: 4px; }
.meal-focus {
  font-size: 11px; color: var(--primary);
  background: var(--primary-light); border-radius: 4px;
  padding: 2px 8px; display: inline-block;
}
.meal-snacks {
  background: var(--gray-50); border-radius: 8px;
  padding: 12px 16px; margin-top: 12px;
  border: 1px dashed var(--gray-200);
}
.meal-snacks h5 { font-size: 11px; color: var(--gray-400); margin-bottom: 4px; }
.meal-snacks ul { list-style: none; padding: 0; }
.meal-snacks li {
  font-size: 12px; color: var(--gray-600);
  padding: 1px 0 1px 12px; position: relative;
}
.meal-snacks li::before { content: '•'; position: absolute; left: 0; color: var(--primary); }

/* ── 饮食禁忌 ── */
.forbid-list { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; }
.forbid-list li {
  background: #fee2e2; color: var(--red);
  border-radius: 20px; padding: 4px 14px;
  font-size: 13px; font-weight: 500;
  border: 1px solid #fecaca;
}
.forbid-list li::before { content: '✕ '; font-size: 11px; }

/* ── 心理支持 ── */
.psy-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 0;
}
.psy-block {
  padding: 12px 16px;
  border-right: 1px solid var(--gray-200);
}
.psy-block:last-child { border-right: none; }
.psy-block-title {
  font-size: 12px; font-weight: 700;
  color: var(--purple); margin-bottom: 6px;
  padding-bottom: 4px; border-bottom: 2px solid var(--purple-light);
}
.psy-items { display: flex; flex-direction: column; gap: 4px; }
.psy-item {}
.psy-item .pi-key {
  font-size: 11px; font-weight: 700; color: var(--gray-600); margin-bottom: 1px;
}
.psy-item .pi-val {
  font-size: 12px; color: var(--gray-700); line-height: 1.45;
}

/* ── 进展监测 ── */
.monitor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr;
  gap: 0;
  padding: 0;
}
.monitor-col {
  padding: 12px 16px;
  border-right: 1px solid var(--gray-200);
}
.monitor-col:last-child { border-right: none; }
.monitor-col--wide {}
.monitor-col h4 {
  font-size: 12px; font-weight: 700;
  color: var(--gray-600); margin-bottom: 6px;
}
.monitor-list { list-style: none; padding: 0; }
.monitor-list li {
  font-size: 12px; color: var(--gray-700);
  padding: 3px 0 3px 14px; position: relative;
  border-bottom: 1px solid var(--gray-200);
}
.monitor-list li:last-child { border-bottom: none; }
.monitor-list li::before {
  content: '✓';
  position: absolute; left: 0;
  color: var(--accent); font-size: 12px;
}
.monitor-text {
  font-size: 12px; color: var(--gray-700);
  line-height: 1.5;
  background: var(--accent-light);
  border-radius: 6px; padding: 10px 12px;
  border-left: 4px solid var(--accent);
}

/* ── 预期效果时间轴 ── */
.effect-timeline {
  display: flex;
  padding: 14px 16px;
  gap: 0;
  position: relative;
}
/* 横线固定在圆点中心，避免与下方文字重叠 */
.effect-timeline::before {
  content: '';
  position: absolute;
  top: 36px; left: 60px; right: 60px;
  height: 2px;
  background: var(--gray-200);
  transform: translateY(-50%);
  z-index: 0;
}
.effect-stage {
  flex: 1; text-align: center; position: relative; z-index: 1;
  min-width: 0;
}
.effect-dot {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800;
  margin: 0 auto 8px;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.effect-stage:nth-child(1) .effect-dot { background: #fef3c7; color: #d97706; }
.effect-stage:nth-child(2) .effect-dot { background: #dbeafe; color: #2563eb; }
.effect-stage:nth-child(3) .effect-dot { background: #d1fae5; color: #059669; }
.effect-label {
  font-size: 11px; font-weight: 700;
  color: var(--gray-400); margin-bottom: 4px;
}
.effect-text {
  font-size: 12px; color: var(--gray-700); line-height: 1.45;
  padding: 0 6px;
  overflow-wrap: break-word;
  word-break: break-word;
}
.effect-text .format-list {
  text-align: left;
  margin: 4px 0 0 0;
  padding-left: 16px;
  line-height: 1.5;
}
.effect-text .format-list li {
  margin-bottom: 2px;
}
.effect-text .format-list li:last-child {
  margin-bottom: 0;
}

/* ── 科学依据 ── */
.science-list {
  display: flex; flex-direction: column; gap: 0;
  padding: 0;
}
.science-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--gray-200);
}
.science-item:last-child { border-bottom: none; }
.science-tag {
  flex-shrink: 0;
  font-size: 11px; font-weight: 700;
  background: var(--primary-light); color: var(--primary);
  border-radius: 4px; padding: 3px 10px;
  margin-top: 1px;
}
.science-item p { font-size: 12px; color: var(--gray-700); line-height: 1.5; }

/* ── 附表 ── */
.table-wrap { overflow-x: auto; padding: 0 18px 10px; }
.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 12px;
}
.data-table th {
  background: var(--gray-50);
  padding: 6px 8px; text-align: center;
  border: 1px solid var(--gray-200);
  font-weight: 700; color: var(--gray-600);
  white-space: nowrap;
  font-size: 11px;
}
.data-table td {
  padding: 5px 8px; text-align: center;
  border: 1px solid var(--gray-200);
  color: var(--gray-700);
}
.data-table tbody tr:nth-child(even) { background: var(--gray-50); }
.sub-data-title {
  font-size: 12px; font-weight: 700;
  color: var(--gray-600);
  padding: 8px 18px 6px;
  margin-top: 4px;
}

/* ── 底部 ── */
.doc-footer {
  text-align: center; padding: 8px 0 4px;
}
.footnote {
  font-size: 11px; color: var(--gray-400);
  margin-bottom: 8px; line-height: 1.5;
}
.print-btn {
  padding: 8px 28px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 6px;
  font-size: 14px; cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px rgba(26,107,158,0.3);
  transition: background 0.2s;
}
.print-btn:hover { background: var(--primary-dark); }

/* ── 移动端适配 ── */
@media (max-width: 768px) {
  .page-wrapper {
    padding: 12px 12px 40px;
  }
  .doc-header {
    padding: 24px 20px 20px;
  }
  .doc-title {
    font-size: 24px;
    letter-spacing: 2px;
  }
  .doc-subtitle {
    font-size: 12px;
  }
  .doc-meta {
    flex-direction: column;
    gap: 6px;
  }
  .section-header {
    padding: 12px 16px;
  }
  .section-header h2 {
    font-size: 15px;
  }
  .section-icon { font-size: 18px; }
  .sub-section {
    padding: 14px 16px;
  }
  .sub-title {
    font-size: 13px;
  }
  .info-grid {
    grid-template-columns: repeat(2, 1fr);
    padding: 14px 16px;
  }
  .info-item:nth-child(4n) { border-right: 1px solid var(--gray-200); }
  .info-item:nth-child(2n) { border-right: none; }
  .info-item { padding: 8px 10px; }
  .principle-grid {
    grid-template-columns: 1fr;
  }
  .principle-card {
    padding: 12px 14px;
  }
  .safety-grid {
    grid-template-columns: 1fr;
  }
  .special-grid {
    grid-template-columns: 1fr;
  }
  .psy-grid {
    grid-template-columns: 1fr;
    padding: 0;
  }
  .psy-block {
    padding: 14px 16px;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
  }
  .psy-block:last-child { border-bottom: none; }
  .effect-timeline {
    flex-direction: column;
    padding: 16px;
    gap: 20px;
  }
  .effect-timeline::before {
    top: 34px;
    bottom: 16px;
    left: 17px;
    right: auto;
    width: 2px;
    height: auto;
  }
  .effect-stage {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    text-align: left;
  }
  .effect-dot {
    flex-shrink: 0;
    width: 34px; height: 34px;
    font-size: 12px;
  }
  .effect-label {
    flex-shrink: 0;
    width: 90px;
    margin-bottom: 0;
  }
  .effect-text {
    flex: 1;
    min-width: 0;
    padding: 0;
  }
  .error-box {
    margin: 16px;
    padding: 24px 20px;
    max-width: calc(100% - 32px);
  }
  .table-wrap {
    padding: 0 16px 12px;
    -webkit-overflow-scrolling: touch;
  }
  .data-table {
    font-size: 11px;
  }
  .data-table th,
  .data-table td {
    padding: 6px 6px;
  }
  .sub-data-title {
    padding: 8px 16px 6px;
  }
  .print-btn {
    padding: 12px 28px;
    font-size: 14px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .error-box button {
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }
  .meal-plan {
    grid-template-columns: 1fr;
  }
  .monitor-layout {
    grid-template-columns: 1fr;
  }
  .monitor-col {
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
  }
  .monitor-col:last-child { border-bottom: none; }
  .nutrition-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 小屏手机优化 */
@media (max-width: 480px) {
  .page-wrapper { padding: 8px 8px 32px; }
  .doc-header { padding: 20px 16px 16px; }
  .doc-title { font-size: 20px; letter-spacing: 1px; }
  .info-grid {
    grid-template-columns: 1fr;
  }
  .info-item:nth-child(2n) { border-right: 1px solid var(--gray-200); }
  .info-item:last-child { border-right: none; }
  .nutrition-grid { grid-template-columns: 1fr; }
  body { font-size: 13px; }
}

/* ── 打印 ── */
@media print {
  body { background: #fff; }
  .page-wrapper { padding: 0; }
  .doc-container { width: 100%; }
  .doc-header { border-radius: 0; }
  .section-card { box-shadow: none; border: 1px solid #ddd; }
  .loading-overlay, .error-overlay, .doc-footer { display: none !important; }
  .section-card { page-break-inside: avoid; }
}
