/* 方圓珍珠學院 學習系統 — 視覺依吃茶三千品牌（茶葉綠 × 蜂蜜金 × 米白） */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&family=Amiri:ital,wght@1,400;1,700&display=swap');

:root {
  --bg: #fffcf5;            /* 品牌米白 */
  --card: #ffffff;
  --ink: #231f20;           /* 品牌墨黑 */
  --ink-soft: #666567;
  --brand: #7d942c;         /* 茶葉綠（#9bba3b 調深以確保按鈕對比） */
  --brand-dark: #5f7220;
  --leaf: #9bba3b;          /* 品牌原色茶葉綠（裝飾用） */
  --accent: #c4922e;        /* 蜂蜜金 */
  --accent-soft: #f7efdc;
  --line: #e9e2d3;
  --danger: #b34a3c;
  --ok: #2e7d4f;
  --warn: #b07a1e;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(35, 31, 32, .07);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Noto Sans TC", "微軟正黑體", "PingFang TC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
.en-accent {
  font-family: Amiri, Georgia, serif;
  font-style: italic;
  letter-spacing: 3px;
  color: var(--accent);
}

/* 頂部導覽 */
header.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  padding: 10px 0;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.topbar .logo .logo-en {
  font-family: Amiri, Georgia, serif;
  font-style: italic;
  font-weight: 400;
  font-size: 10.5px;
  letter-spacing: 3px;
  color: var(--accent);
}
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  padding: 16px 14px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 15px;
  border-bottom: 3px solid transparent;
}
.topbar nav a.active, .topbar nav a:hover {
  color: var(--brand-dark);
  border-bottom-color: var(--brand);
}
.topbar .tools { display: flex; gap: 8px; }

main { max-width: 1100px; margin: 0 auto; padding: 28px 24px 60px; }
h1 { font-size: 24px; margin: 0 0 4px; }
.subtitle { color: var(--ink-soft); margin: 0 0 24px; font-size: 14px; }

/* 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); }

/* 按鈕 */
.btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--brand); color: var(--brand-dark); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 10px; font-size: 13px; }

/* 表格 */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-soft); font-weight: 600; font-size: 13px; white-space: nowrap; }
tr:hover td { background: #fdfaf5; }
.card { overflow-x: auto; }   /* 寬表格在卡片內橫向捲動，不擠壓欄位 */

/* 範本項目表：長階段名不得壓縮「培訓項目」欄 */
#tplDetail table { min-width: 900px; }
#tplDetail th:nth-child(4), #tplDetail td:nth-child(4) { min-width: 220px; }
#tplDetail td:nth-child(2) { white-space: nowrap; }

/* 徽章 */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  white-space: nowrap;
}
.badge.gray  { background: #efe9e1; color: var(--ink-soft); }
.badge.blue  { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: #e2f2e8; color: var(--ok); }
.badge.red   { background: #f7e5e2; color: var(--danger); }
.badge.amber { background: #f6edda; color: var(--warn); }

/* 表單 */
label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 120px; resize: vertical; }
.form-row { display: flex; gap: 12px; margin-bottom: 12px; }
.form-row > div { flex: 1; }

/* 版面：側欄＋內容 */
.layout { display: flex; gap: 20px; align-items: flex-start; }
.sidebar { width: 260px; flex-shrink: 0; }
.sidebar .item {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14.5px;
  color: var(--ink);
  border: 1px solid transparent;
}
.sidebar .item:hover { background: #f4ede3; }
.sidebar .item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar .item .count { float: right; color: var(--ink-soft); font-size: 12.5px; }
.content { flex: 1; min-width: 0; }

/* 對話框 */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,.18);
  padding: 24px;
  width: min(560px, 92vw);
}
dialog::backdrop { background: rgba(58,46,38,.35); }
dialog h3 { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* 進度條 */
.progress { background: #efe9e1; border-radius: 999px; height: 8px; overflow: hidden; }
.progress > div { background: var(--accent); height: 100%; border-radius: 999px; }

/* 其他 */
.muted { color: var(--ink-soft); font-size: 13.5px; }
.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 20px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
}
.section-block { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; background: #fff; }
.section-block h4 { margin: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.section-block .chev { color: var(--ink-soft); font-size: 12px; margin-right: 6px; display: inline-block; transition: transform .15s; }
.section-block.open .chev { transform: rotate(90deg); }
.section-block .sec-body { display: none; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.section-block.open .sec-body { display: block; }
.section-block .sec-meta { font-size: 12px; color: var(--ink-soft); font-weight: 400; }
.kb-hit { cursor: pointer; }
.kb-hit:hover { border-color: var(--accent); }
mark { background: var(--accent-soft); color: var(--warn); padding: 0 2px; border-radius: 3px; }
.section-content { white-space: pre-wrap; font-size: 14.5px; line-height: 1.85; max-width: 720px; }  /* 限制閱讀行寬（約 40 個中文字），降低眼球移動負荷 */
.section-content.rich { white-space: normal; }
.section-content.rich img { max-width: 100%; height: auto; border-radius: 8px; }
.section-content.rich table { border-collapse: collapse; max-width: 100%; margin: .5em 0; }
.section-content.rich table td, .section-content.rich table th { border: 1px solid var(--line); padding: 6px 10px; }
.section-content.rich p { margin: 0 0 .6em; }
.section-content.rich ul, .section-content.rich ol { margin: 0 0 .6em; padding-left: 1.6em; }

/* 富文字編輯器覆蓋層（不用原生 dialog，避免編輯器彈出選單被蓋住） */
.editor-overlay {
  position: fixed; inset: 0;
  background: rgba(58, 46, 38, .45);
  z-index: 9000;
  display: none;
  align-items: flex-start; justify-content: center;
  padding: 4vh 16px;
  overflow: auto;
}
.editor-overlay.open { display: flex; }
.editor-panel {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  width: min(940px, 100%);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.editor-panel h3 { margin-top: 0; }

/* 學習地圖時間軸 */
.map-stage {
  border-left: 3px solid var(--accent);
  margin-left: 10px;
  padding: 0 0 22px 22px;
  position: relative;
}
.map-stage::before {
  content: '';
  position: absolute;
  left: -10px; top: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 3px solid var(--accent);
}
.map-stage.done::before { background: var(--accent); }
.stage-toggle { cursor: pointer; user-select: none; }
.stage-toggle:hover { color: var(--brand-dark); }
.task-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  background: #fff;
}
.task-row.done { background: #f3faf5; border-color: #cfe8d8; }
.task-check { font-size: 17px; line-height: 1.4; }

/* 里程碑徽章 */
.medal-row { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }
.medal { text-align: center; width: 84px; }
.medal .medal-icon {
  width: 58px; height: 58px; margin: 0 auto 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(196, 146, 46, .25);
}
.medal .medal-name { font-size: 13px; font-weight: 600; }
.medal .medal-pct { font-size: 11.5px; color: var(--ink-soft); }
.medal.locked .medal-icon {
  background: #f1efe9; border-color: var(--line);
  filter: grayscale(1); opacity: .45; box-shadow: none;
}
.medal.locked .medal-name { color: var(--ink-soft); font-weight: 400; }

/* 完訓慶祝 */
.celebrate {
  background: linear-gradient(135deg, #f7efdc, #fffcf5);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  text-align: center;
  padding: 26px 20px;
  margin-bottom: 18px;
}
.celebrate h2 { margin: 0 0 6px; color: var(--brand-dark); }
.confetti {
  position: fixed; top: -12px;
  width: 9px; height: 9px;
  border-radius: 2px;
  z-index: 30000;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: .2; }
}

/* ============ 行動版（手機優先適配） ============ */
@media (max-width: 768px) {
  main { padding: 16px 12px 48px; }
  h1 { font-size: 20px; }
  .subtitle { font-size: 13px; }

  /* 導覽列：Logo＋工具列一排，選單變成可左右滑動的第二排 */
  .topbar { flex-wrap: wrap; padding: 0 12px; gap: 0 10px; }
  .topbar .logo { padding: 8px 0; font-size: 16px; }
  .topbar .tools { margin-left: auto; padding: 8px 0; flex-wrap: wrap; justify-content: flex-end; }
  .topbar nav {
    order: 3; width: 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav a { padding: 11px 10px; white-space: nowrap; font-size: 14px; }

  /* 側欄改為堆疊在內容上方 */
  .layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 250px; overflow-y: auto; }

  /* 表單直排、觸控目標加大 */
  .form-row { flex-direction: column; gap: 10px; }
  .btn { padding: 10px 16px; }
  .btn.small { padding: 7px 12px; }
  input, select, textarea { font-size: 16px; }  /* 避免 iOS 自動放大 */

  /* 寬表格在卡片內橫向捲動 */
  .card { overflow-x: auto; }
  th, td { padding: 8px 8px; font-size: 13.5px; }

  /* 學習地圖 */
  .map-stage { margin-left: 4px; padding: 0 0 16px 16px; }
  .task-row { flex-wrap: wrap; }
  .medal-row { gap: 10px; }
  .medal { width: 72px; }
  .medal .medal-icon { width: 50px; height: 50px; font-size: 22px; }

  /* 對話框與編輯器 */
  dialog { padding: 16px; width: min(560px, 96vw); }
  .editor-overlay { padding: 8px; }
  .editor-panel { padding: 14px; }

  /* 統計卡與證書 */
  .stat .num { font-size: 22px; }
  .cert { padding: 44px 18px 60px; }
  .cert .cert-title { font-size: 28px; letter-spacing: 8px; }
  .cert .stu-name { font-size: 24px; }
  .cert .meta { flex-direction: column; gap: 6px; }
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  border: none; background: none; padding: 10px 16px; font-size: 14.5px;
  color: var(--ink-soft); cursor: pointer; border-bottom: 3px solid transparent; font-family: inherit;
}
.tabs button.active { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 600; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stat { text-align: center; }
.stat .num { font-size: 28px; font-weight: 700; color: var(--brand-dark); }
.stat .label { font-size: 13px; color: var(--ink-soft); }
