/* ============================================================
   Conductor 資助成效儀表板 (KPI Dashboard) — 真實資料版
   供 /mk3/sponsorship/kpi-dashboard.html 使用。沿用 .spon-live
   的卡片樣式，並補上學習成果、趨勢圖、學生／課程卡與列印樣式。
   ============================================================ */

/* 摘要卡：綜合影響力評分強調色 */
.kpi-dash .wallet-card.accent-impact {
  background: linear-gradient(135deg, #f5f3ff, #ffffff);
  border-color: #ddd6fe;
}
.kpi-dash .wallet-card.accent-impact .wc-value {
  color: #6d28d9;
}
.kpi-dash .wallet-card.accent-students {
  background: linear-gradient(135deg, #ecfdf5, #ffffff);
  border-color: #bbf7d0;
}

/* 學習成果比率卡 */
.kpi-dash .rate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.kpi-dash .rate-card {
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 22px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
}
.kpi-dash .rate-card .rate-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.kpi-dash .rate-card .rate-name {
  font-weight: 700;
  color: #0f172a;
}
.kpi-dash .rate-card .rate-pct {
  font-size: 1.8rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1;
}
.kpi-dash .rate-track {
  height: 12px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
}
.kpi-dash .rate-track > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #22c55e);
}
.kpi-dash .rate-card .rate-sub {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 8px;
}

/* 趨勢圖卡 */
.kpi-dash .kpi-chart-card {
  padding: 24px;
}
.kpi-dash .chart-legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: #475569;
  margin-bottom: 12px;
}
.kpi-dash .chart-legend .lg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.kpi-dash .chart-legend .sw {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  display: inline-block;
}
.kpi-dash .sw.sw-enrol {
  background: #6366f1;
}
.kpi-dash .sw.sw-comp {
  background: #22c55e;
}
.kpi-dash .trend-svg {
  width: 100%;
  height: auto;
  display: block;
}
.kpi-dash .trend-svg .bar-enrol {
  fill: #6366f1;
}
.kpi-dash .trend-svg .bar-comp {
  fill: #22c55e;
}
.kpi-dash .trend-svg .axis-label {
  fill: #64748b;
  font-size: 12px;
}
.kpi-dash .trend-svg .bar-val {
  fill: #334155;
  font-size: 11px;
  font-weight: 600;
}
.kpi-dash .trend-svg .grid-line {
  stroke: #eef2f7;
  stroke-width: 1;
}

/* 課程成效卡 */
.kpi-dash .course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.kpi-dash .course-card {
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 20px 22px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
}
.kpi-dash .course-card h4 {
  margin: 0 0 4px;
  font-size: 1.1rem;
  color: #0f172a;
}
.kpi-dash .course-card .course-meta {
  font-size: 0.82rem;
  color: #64748b;
  margin-bottom: 14px;
}
.kpi-dash .course-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.kpi-dash .course-stats .cs {
  background: #f8fafc;
  border-radius: 10px;
  padding: 10px 12px;
}
.kpi-dash .course-stats .cs-val {
  font-size: 1.25rem;
  font-weight: 800;
  color: #0f172a;
}
.kpi-dash .course-stats .cs-label {
  font-size: 0.74rem;
  color: #64748b;
}
.kpi-dash .mini-track {
  height: 8px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
  margin: 6px 0 10px;
}
.kpi-dash .mini-track > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6366f1, #22c55e);
}
.kpi-dash .mini-label {
  font-size: 0.78rem;
  color: #475569;
  display: flex;
  justify-content: space-between;
}

/* 學生進度卡 */
.kpi-dash .student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.kpi-dash .student-card {
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 20px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
}
.kpi-dash .student-card .st-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.kpi-dash .student-card .st-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #22c55e);
  color: #fff;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.kpi-dash .student-card .st-name {
  font-weight: 700;
  color: #0f172a;
}
.kpi-dash .student-card .st-tier {
  font-size: 0.76rem;
  color: #94a3b8;
}
.kpi-dash .st-row {
  margin-bottom: 10px;
}
.kpi-dash .st-row .st-label {
  font-size: 0.8rem;
  color: #475569;
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

/* 一鍵列印全部學員按鈕列 */
.kpi-dash .student-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

/* 全部學員報告容器：僅列印模式顯示 */
.kpi-dash .all-students-report {
  display: none;
}

/* 可點擊的學生卡 */
.kpi-dash .student-card.is-clickable {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.kpi-dash .student-card.is-clickable:hover,
.kpi-dash .student-card.is-clickable:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px rgba(99, 102, 241, 0.18);
  border-color: #c7d2fe;
  outline: none;
}
.kpi-dash .student-card.is-clickable:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}
.kpi-dash .student-card .st-cta {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed #e2e8f0;
  font-size: 0.78rem;
  font-weight: 600;
  color: #6366f1;
  text-align: center;
}

/* ── 學生學習詳情彈窗 ─────────────────────────────────────── */
body.modal-open {
  overflow: hidden;
}
.kpi-dash .student-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
}
.kpi-dash .student-modal.show {
  display: block;
}
.kpi-dash .student-modal .sm-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  animation: smFade 0.2s ease;
}
.kpi-dash .student-modal .sm-dialog {
  position: relative;
  max-width: 640px;
  width: calc(100% - 32px);
  max-height: calc(100vh - 64px);
  margin: 32px auto;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.35);
  overflow-y: auto;
  padding: 28px;
  animation: smRise 0.22s ease;
}
@keyframes smFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes smRise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.kpi-dash .student-modal .sm-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #f1f5f9;
  color: #475569;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}
.kpi-dash .student-modal .sm-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}
.kpi-dash .student-modal .sm-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  padding-right: 36px;
}
.kpi-dash .student-modal .sm-head h3 {
  margin: 0;
  font-size: 1.35rem;
  color: #0f172a;
}
/* 單一學生報告列印標頭（僅列印模式顯示） */
.kpi-dash .student-modal .sm-print-header {
  display: none;
}
/* 列印 / 匯出此學生報告按鈕 */
.kpi-dash .student-modal .sm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin: -8px 0 20px;
}
/* 下載 CSV 按鈕（外框樣式，與列印按鈕並列） */
.kpi-dash .student-modal .sm-csv-btn {
  border: 1.5px solid #6366f1;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  color: #4338ca;
  background: #fff;
}
.kpi-dash .student-modal .sm-csv-btn:hover {
  background: #eef2ff;
}
.kpi-dash .student-modal .sm-csv-btn:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}
.kpi-dash .student-modal .sm-print-btn {
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #22c55e);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.25);
}
.kpi-dash .student-modal .sm-print-btn:hover {
  filter: brightness(1.05);
}
.kpi-dash .student-modal .sm-print-btn:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 2px;
}
.kpi-dash .student-modal .sm-tier {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-top: 2px;
}
.kpi-dash .student-modal .sm-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.kpi-dash .student-modal .sm-stat {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px 10px;
  text-align: center;
}
.kpi-dash .student-modal .sm-stat-val {
  font-size: 1.3rem;
  font-weight: 800;
  color: #0f172a;
}
.kpi-dash .student-modal .sm-stat-label {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 2px;
}
.kpi-dash .student-modal .sm-section-title {
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 12px;
  font-size: 1rem;
}
.kpi-dash .student-modal .enr-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.kpi-dash .student-modal .enr-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px 16px;
  background: #fff;
}
.kpi-dash .student-modal .enr-name {
  font-weight: 700;
  color: #0f172a;
}
.kpi-dash .student-modal .enr-meta {
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 3px;
}
.kpi-dash .student-modal .enr-date {
  font-size: 0.74rem;
  color: #94a3b8;
  margin-top: 3px;
}
.kpi-dash .student-modal .enr-tags {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex: 0 0 auto;
}
.kpi-dash .student-modal .enr-status,
.kpi-dash .student-modal .enr-att {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}
.kpi-dash .student-modal .enr-status.ok {
  background: var(--success-soft);
  color: var(--success-strong);
}
.kpi-dash .student-modal .enr-status.live {
  background: #e0e7ff;
  color: #3730a3;
}
.kpi-dash .student-modal .enr-status.off {
  background: #f1f5f9;
  color: #64748b;
}
.kpi-dash .student-modal .enr-att.yes {
  background: var(--success-soft);
  color: var(--success-strong);
}
.kpi-dash .student-modal .enr-att.no {
  background: var(--error-soft);
  color: var(--error-strong);
}
.kpi-dash .student-modal .enr-att.none {
  background: #f1f5f9;
  color: #94a3b8;
}
@media (max-width: 480px) {
  .kpi-dash .student-modal .sm-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 願景指標（待追蹤） */
.kpi-dash .aspir-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.kpi-dash .aspir-card {
  border: 1.5px dashed #cbd5e1;
  border-radius: 16px;
  padding: 20px;
  background: #f8fafc;
}
.kpi-dash .aspir-card .ar-name {
  font-weight: 700;
  color: #475569;
  margin-bottom: 8px;
}
.kpi-dash .aspir-card .ar-badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--warning-soft);
  color: var(--warning-strong);
}

/* KPI 進度（campaignKpis） */
.kpi-dash .camp-block {
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  padding: 24px;
  background: #fff;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.05);
  margin-bottom: 16px;
}
.kpi-dash .camp-block h3 {
  margin: 0 0 4px;
  font-size: 1.2rem;
}
.kpi-dash .camp-block .camp-sub {
  font-size: 0.85rem;
  color: #64748b;
  margin-bottom: 16px;
}

/* 列印報告標頭 */
.kpi-dash .print-header {
  display: none;
}

/* ── 列印樣式（匯出 PDF）──────────────────────────────────── */
@media print {
  .kpi-dash .no-print,
  .kpi-dash .skip-link,
  .kpi-dash .fab,
  .kpi-dash .toast,
  .kpi-dash .student-modal {
    display: none !important;
  }
  body.kpi-dash {
    background: #fff;
  }
  .kpi-dash .print-header {
    display: block;
    padding: 0 0 16px;
    margin-bottom: 16px;
    border-bottom: 2px solid #0f172a;
  }
  .kpi-dash .print-header h1 {
    margin: 0 0 4px;
    font-size: 1.6rem;
    color: #0f172a;
  }
  .kpi-dash .print-header .ph-meta {
    font-size: 0.85rem;
    color: #475569;
  }
  .kpi-dash main {
    padding: 0 !important;
  }
  .kpi-dash section {
    break-inside: avoid;
    padding: 8px 0 !important;
  }
  .kpi-dash .wallet-card,
  .kpi-dash .rate-card,
  .kpi-dash .course-card,
  .kpi-dash .student-card,
  .kpi-dash .camp-block,
  .kpi-dash .aspir-card,
  .kpi-dash .kpi-chart-card {
    break-inside: avoid;
    box-shadow: none !important;
  }
  .kpi-dash .wrap {
    max-width: 100% !important;
    padding: 0 12px !important;
  }
  /* 確保漸層／顏色於列印時保留 */
  .kpi-dash * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ── 單一學生報告列印模式：只輸出該學生的學習詳情 ─────────── */
  /* 隱藏儀表板其餘所有內容，僅保留學生彈窗。 */
  body.kpi-dash.student-print-mode > *:not(.student-modal) {
    display: none !important;
  }
  /* 覆蓋上方「@media print 隱藏 .student-modal」的規則（特異度較高）。 */
  .kpi-dash.student-print-mode .student-modal {
    display: block !important;
    position: static !important;
    inset: auto !important;
  }
  .kpi-dash.student-print-mode .student-modal .sm-overlay {
    display: none !important;
  }
  /* 將彈窗攤平成乾淨的文件（無對話框外框／陰影／捲動）。 */
  .kpi-dash.student-print-mode .student-modal .sm-dialog {
    position: static !important;
    max-width: 100% !important;
    width: 100% !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
    animation: none !important;
  }
  /* 顯示並沿用儀表板列印標頭樣式。 */
  .kpi-dash.student-print-mode .student-modal .sm-print-header {
    display: block !important;
    padding: 0 0 16px;
    margin-bottom: 16px;
    border-bottom: 2px solid #0f172a;
  }
  .kpi-dash.student-print-mode .student-modal .sm-print-header h1 {
    margin: 0 0 4px;
    font-size: 1.6rem;
    color: #0f172a;
  }
  .kpi-dash.student-print-mode .student-modal .sm-print-header .ph-meta {
    font-size: 0.85rem;
    color: #475569;
  }
  .kpi-dash.student-print-mode .student-modal .enr-row,
  .kpi-dash.student-print-mode .student-modal .sm-stats {
    break-inside: avoid;
  }

  /* ── 一鍵列印全部學員模式：只輸出全部學員報告 ───────────────── */
  /* 隱藏儀表板其餘所有內容，僅保留全部學員報告容器。 */
  body.kpi-dash.all-students-print-mode > *:not(main),
  body.kpi-dash.all-students-print-mode main > *:not(.all-students-report) {
    display: none !important;
  }
  .kpi-dash.all-students-print-mode main {
    display: block !important;
    padding: 0 !important;
  }
  .kpi-dash.all-students-print-mode .all-students-report {
    display: block !important;
  }
  /* 每位學員一頁：學員之間強制分頁。 */
  .kpi-dash.all-students-print-mode .asr-student {
    break-after: page;
    break-inside: avoid-page;
  }
  .kpi-dash.all-students-print-mode .asr-student:last-child {
    break-after: auto;
  }
  /* 沿用儀表板列印標頭樣式。 */
  .kpi-dash.all-students-print-mode .asr-student .sm-print-header {
    display: block !important;
    padding: 0 0 16px;
    margin-bottom: 16px;
    border-bottom: 2px solid #0f172a;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-print-header h1 {
    margin: 0 0 4px;
    font-size: 1.6rem;
    color: #0f172a;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-print-header .ph-meta {
    font-size: 0.85rem;
    color: #475569;
  }
  /* 報告區塊排版（沿用彈窗詳情的視覺）。 */
  .kpi-dash.all-students-print-mode .asr-student .sm-head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-head h3 {
    margin: 0;
    font-size: 1.35rem;
    color: #0f172a;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-head .st-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #22c55e);
    color: #fff;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-tier {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-top: 2px;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
    break-inside: avoid;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-stat {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 10px;
    text-align: center;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-stat-val {
    font-size: 1.3rem;
    font-weight: 800;
    color: #0f172a;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-stat-label {
    font-size: 0.72rem;
    color: #64748b;
    margin-top: 2px;
  }
  .kpi-dash.all-students-print-mode .asr-student .sm-section-title {
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 12px;
    font-size: 1rem;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 16px;
    background: #fff;
    break-inside: avoid;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-name {
    font-weight: 700;
    color: #0f172a;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-meta {
    font-size: 0.78rem;
    color: #64748b;
    margin-top: 3px;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-date {
    font-size: 0.74rem;
    color: #94a3b8;
    margin-top: 3px;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-tags {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex: 0 0 auto;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-status,
  .kpi-dash.all-students-print-mode .asr-student .enr-att {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    white-space: nowrap;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-status.ok {
    background: var(--success-soft);
    color: var(--success-strong);
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-status.live {
    background: #e0e7ff;
    color: #3730a3;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-status.off {
    background: #f1f5f9;
    color: #64748b;
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-att.yes {
    background: var(--success-soft);
    color: var(--success-strong);
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-att.no {
    background: var(--error-soft);
    color: var(--error-strong);
  }
  .kpi-dash.all-students-print-mode .asr-student .enr-att.none {
    background: #f1f5f9;
    color: #94a3b8;
  }
}
