/* ============ ฐาน / ตัวแปรสี ============ */
:root {
  --bg: #ffffff;
  --surface: #f6f7f9;
  --border: #e6e8eb;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --free: #16a34a;
  --paid: #d97706;
  --radius: 14px;
  --maxw: 980px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}
img { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; }
.container { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

/* ============ ปุ่ม ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; border: 1px solid transparent; border-radius: 10px;
  padding: 12px 18px; font-size: 16px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: .15s; line-height: 1.2;
}
.btn-sm { padding: 8px 12px; font-size: 14px; }
.btn-block { display: flex; width: 100%; margin-top: 10px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface); }
.btn-free { background: var(--free); color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ============ header ============ */
#app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 14px; background: rgba(255,255,255,.95);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 17px; color: var(--text); display: inline-flex; align-items: center; gap: 4px; flex: none; }
.nav-ico { line-height: 1; }
.head-nav { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.head-nav a { color: var(--text); font-weight: 700; font-size: 16px; white-space: nowrap; }
.nav-admin { color: var(--primary) !important; }
/* กระดิ่งกล่องข้อความ + จุดแจ้งเตือน */
.head-bell { position: relative; font-size: 20px; line-height: 1; text-decoration: none; }
.bell-badge {
  position: absolute; top: -7px; right: -8px; min-width: 17px; height: 17px; padding: 0 4px;
  background: #dc2626; color: #fff; font-size: 11px; font-weight: 800; line-height: 17px;
  text-align: center; border-radius: 999px; box-shadow: 0 0 0 2px var(--bg);
}
/* ปุ่มสลับภาษา ไทย/EN — คอมแพกต์ ไม่เบียดเมนู */
.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; flex: none; }
.lang-opt { border: 0; background: transparent; color: var(--muted); font-family: inherit; font-weight: 700; font-size: 12px; padding: 3px 6px; cursor: pointer; line-height: 1.4; white-space: nowrap; }
.lang-opt.active { background: var(--primary); color: #fff; }
@media (max-width: 480px) {
  .brand { font-size: 15px; }
  .head-nav { gap: 10px; }
  .head-nav a { font-size: 14px; }
  #app-header { padding: 8px 10px; }
}
/* จอมือถือ: จัด "ไอคอนบน–ข้อความล่าง" — ความกว้างของแต่ละเมนูเหลือเท่าความกว้างข้อความ
   (แนวนอนต้องใช้ ไอคอน+ช่องไฟ+ข้อความ) ⇒ ได้ที่คืนมามาก จนไม่ต้องซ่อนข้อความอีก
   แลกด้วยความสูงหัวเว็บที่เพิ่มเล็กน้อย ซึ่งคุ้มกว่าการให้ผู้ใช้เดาว่าไอคอนคืออะไร */
@media (max-width: 560px) {
  /* มือถือ: ไอคอนบน–ข้อความล่าง
     ใช้ stretch + justify-content:flex-start เพื่อให้ทุกเมนู "เริ่มจากขอบบนเท่ากัน"
     ⇒ ไอคอนทุกตัวอยู่แถวเดียวกัน และข้อความอยู่แถวเดียวกัน
     (ถ้าใช้ flex-end กระดิ่งที่ไม่มีข้อความจะถูกดันลงไปอยู่ระดับบรรทัดข้อความ = เบี้ยว) */
  #app-header { align-items: stretch; }
  .head-nav { gap: 12px; align-items: stretch; }
  .head-nav a, .brand {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
    gap: 3px; font-size: 13px; line-height: 1.2; white-space: nowrap; text-align: center;
  }
  /* กล่องไอคอนสูงคงที่ — กันข้อความยาวไม่เท่ากันทำให้ไอคอนเลื่อนขึ้นลง */
  .nav-ico { font-size: 19px; height: 22px; display: flex; align-items: center; justify-content: center; }
  .brand-text { display: block; font-weight: 700; }
  .lang-toggle { align-self: center; }
  .bell-badge { top: -3px; right: -9px; }
}
/* แอดมินมีเมนู ⚙️ เกินมา จึงมีที่น้อยกว่าผู้เรียน — ลดเฉพาะแอดมิน ไม่กระทบผู้ใช้ทั่วไป
   (วัดจริง: แอดมินที่ 360px รับได้สูงสุด 12px · ผู้เรียนที่ขนาดเดียวกันรับได้ถึง 14px) */
@media (max-width: 400px) {
  .head-nav.is-admin a { font-size: 11.5px; }
}
/* ตาข่ายกันเหนียวจอเล็กสุด (เช่น Galaxy Fold พับ ~280px) — บีบช่องไฟและตัวอักษรลงอีก
   ไม่ซ่อนข้อความแล้ว เพราะแนวตั้งมีที่พอ (วัดจริงที่ 320px ยังไม่ล้น) */
@media (max-width: 330px) {
  .head-nav { gap: 7px; }
  .head-nav a, .head-nav.is-admin a, .brand { font-size: 11px; }
  .nav-ico { font-size: 17px; height: 20px; }
  #app-header { padding: 6px 8px; }
  /* เฉพาะจอเล็กสุด + เป็นแอดมิน (มีเมนู ⚙️ เกินมา) — ซ่อนคำว่า "จัดการ" อย่างเดียว
     เจ้าของเว็บคนเดียวและ ⚙️ สื่อชัดในตัว · เมนูของผู้เรียนยังมีข้อความครบ */
  .head-nav.is-admin .nav-admin .nav-label { display: none; }
}
/* แคบสุดจริง ๆ (Galaxy Fold พับ ~280px) — บีบอีกชั้นเพื่อไม่ให้หน้าเลื่อนแนวนอน */
@media (max-width: 300px) {
  .head-nav { gap: 4px; }
  .head-nav a, .head-nav.is-admin a, .brand { font-size: 10px; }
  .nav-ico { font-size: 15px; height: 18px; }
  #app-header { padding: 6px 6px; }
}

/* ============ หน้าแรก ============ */
.hero-img {
  width: 100%; aspect-ratio: 16 / 9; object-fit: cover;
  border-radius: var(--radius); background: var(--surface); margin-top: 16px;
}
/* สไลด์แนะนำการใช้งาน (วีดีโอแนวตั้ง 9:16 ฝังหน้าแรก) */
.home-reel {
  width: 100%; max-width: 380px; margin: 16px auto 4px;
  aspect-ratio: 3 / 4;   /* ลดความสูงลง ~1/4 จาก 9:16 — ที่ว่างน้อยลง */
  border-radius: var(--radius); overflow: hidden;
  background: #22463d; box-shadow: var(--shadow);
}
.home-reel iframe { width: 100%; height: 100%; border: 0; display: block; }
.hero-text { margin: 18px 0; }
.hero-text h1 { font-size: 26px; margin: 0 0 8px; line-height: 1.3; }
.hero-text p {
  color: var(--text);
  margin: 0;
  white-space: pre-wrap;
  font-size: 24px;
  line-height: 1.7;
}
.video-embed {
  width: 100%; aspect-ratio: 16 / 9; border: 0;
  border-radius: var(--radius); background: #000; margin: 16px 0;
}
/* Player แนวตั้ง 9:16 — ใช้ padding-top trick เพื่อให้ iframe ขยายสูงจริง */
.video-wrap-vertical {
  position: relative; width: 100%; max-width: 420px; margin: 16px auto;
  padding-top: 177.78%; /* 16/9 * 100 = 177.78% */
}
.video-wrap-vertical > .video-embed {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  aspect-ratio: auto; border-radius: var(--radius);
}
.video-wrap-vertical > .video-embed iframe {
  width: 100%; height: 100%; border: 0;
}
@media (max-width: 480px) {
  .video-wrap-vertical {
    max-width: calc(100% + 28px);
    margin-left: -14px; margin-right: -14px;
  }
  .video-wrap-vertical > .video-embed { border-radius: 0; }
}
.cta-center { text-align: center; margin: 24px 0; }

/* ============ Dashboard actions bar ============ */
.dash-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin: 0 0 16px;
}
@media (max-width: 480px) {
  .dash-actions { justify-content: stretch; }
  .dash-actions .btn { width: 100%; }
}

/* ============ Certificate promo card ============ */
/* การ์ดข้อมูลผู้ใช้ (แสดงบนสุดของหน้า dashboard — ให้รู้ว่ากำลัง login ด้วยอีเมลไหน) */
.user-info-card {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; margin: 0 0 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.uic-avatar {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0;
  object-fit: cover; background: #e5e7eb;
}
.uic-avatar-ph {
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: #94a3b8;
}
.uic-body { flex: 1; min-width: 0; font-size: 14px; line-height: 1.5; }
.uic-name { font-weight: 700; font-size: 16px; margin-bottom: 4px; overflow-wrap: anywhere; }
.uic-row { display: flex; gap: 8px; flex-wrap: wrap; }
.uic-label { color: var(--muted); flex-shrink: 0; min-width: 90px; }
.uic-val { color: var(--text); word-break: break-word; overflow-wrap: anywhere; }
/* ปุ่มออกจากระบบย้ายมาอยู่ข้างการ์ดบัญชี (ย้ายออกจาก header) — ชิดขวา ไม่หด ไม่ตัดคำ */
.uic-logout { flex-shrink: 0; align-self: center; white-space: nowrap; }
@media (max-width: 480px) {
  .uic-label { min-width: 80px; font-size: 13px; }
  .uic-val { font-size: 13px; }
}

.cert-promo {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 18px; margin: 0 0 20px;
  background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
  border: 1px solid #93c5fd;
  border-left: 5px solid #2563eb;
  border-radius: 12px;
}
.cert-promo-text { flex: 1; min-width: 0; }
.cert-promo-headline {
  font-weight: 800; font-size: 16px; color: #1e3a8a;
  margin-bottom: 4px; line-height: 1.4;
}
.cert-promo-sub {
  font-size: 13px; color: #1e40af;
  line-height: 1.5; opacity: 0.85;
}
.cert-promo-btn {
  flex-shrink: 0; white-space: nowrap;
}
@media (max-width: 600px) {
  .cert-promo { flex-direction: column; align-items: stretch; text-align: center; }
  .cert-promo-btn { width: 100%; }
}

/* ============ Dashboard: คอร์สของฉัน ============ */
.dash-grid {
  display: grid; grid-template-columns: 1fr; gap: 16px;
  margin: 8px 0 32px;
}
@media (min-width: 720px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
}
.dash-card {
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: 14px;
  background: #fff; box-shadow: var(--shadow);
  overflow: hidden;
}
.dash-cover {
  display: block; width: 100%; aspect-ratio: 16/9;
  background: var(--surface); overflow: hidden;
}
.dash-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dash-cover-ph {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; font-size: 48px; color: var(--muted);
}
.dash-body { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px 16px; }
.dash-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }
.dash-card h3 { margin: 0; font-size: 17px; line-height: 1.35; }
.dash-card h3 a { color: var(--text); text-decoration: none; }
.dash-card h3 a:hover { color: var(--primary); }
.dash-card .progress { margin: 6px 0 2px; }
.dash-card .btn { margin-top: 6px; }
.dash-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; line-height: 1.5;
  min-height: 22px;      /* พิลล์สูงพอ — กันข้อความไทยถูกตัดบน-ล่าง */
  white-space: nowrap;   /* ข้อความในป้ายไม่ขึ้นบรรทัดใหม่ */
  flex-shrink: 0;        /* ในแถว dash-top ป้ายไม่หด (กันถูกบีบจนตัด) */
  box-sizing: border-box;
}
.dash-badge.done { background: #dcfce7; color: #166534; }
.dash-badge.progress { background: #dbeafe; color: #1e40af; }
.dash-badge.new { background: #fef3c7; color: #92400e; }

/* ปุ่ม CTA ใต้รูป hero — เด่นชัด ใหญ่ ติด primary color */
.hero-cta-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin: 14px 0 6px;
}
.btn-hero-cta {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 380px;
  padding: 14px 24px;
  font-size: 17px; font-weight: 700;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .25);
  transition: transform .15s, box-shadow .15s;
}
.btn-hero-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, .35);
}

/* ============ การ์ดคอร์ส (grid) ============ */
.course-grid {
  display: grid; grid-template-columns: 1fr; gap: 16px; margin: 16px 0 40px;
}
.course-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg); box-shadow: var(--shadow);
  transition: transform .12s;
}
.course-card:active { transform: scale(.99); }
.course-card .cover {
  width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface);
}
.course-card .body { padding: 12px 14px 16px; }
.course-card h3 {
  font-size: 17px; margin: 0 0 6px; line-height: 1.4;
  /* >>> แก้ปัญหาเว็บเดิม: ชื่อยาวต้องตัดคำขึ้นบรรทัด ไม่ตกขอบ <<< */
  overflow-wrap: anywhere; word-break: break-word; white-space: normal;
}
.course-card .desc {
  color: var(--muted); font-size: 14px; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }

/* ============ ป้าย ============ */
.badge { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge-free { background: #dcfce7; color: var(--free); }
.badge-paid { background: #fef3c7; color: var(--paid); }
.badge-managed { background: var(--surface); color: var(--muted); }
.badge-old { opacity: .65; font-weight: 500; margin-right: 2px; }
.badge-promo { background: #fef3c7; color: #92400e; }
.badge-discount { background: #fee2e2; color: #b91c1c; }
/* ป้ายจุดขาย "ดูฟรี N บท" — สีเขียวเข้มให้เด่นข้างป้ายราคา (สะดุดตา = ดึงคลิกเข้าคอร์ส) */
.badge-preview { background: #16a34a; color: #fff; }

/* ============ bundle cards (หน้าแรก) ============ */
.bundle-grid {
  display: grid; grid-template-columns: 1fr; gap: 16px; margin: 12px 0 24px;
}
.bundle-card {
  position: relative; display: block;
  border: 2px solid #fcd34d; border-radius: var(--radius);
  background: linear-gradient(135deg, #fffbeb 0%, #fff 60%);
  overflow: hidden; box-shadow: var(--shadow); color: var(--text);
  transition: transform .12s;
}
.bundle-card:hover { transform: translateY(-2px); }
.bundle-card .cover { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: var(--surface); }
.bundle-card .body { padding: 14px 16px 18px; }
.bundle-card h3 { font-size: 18px; margin: 4px 0 6px; overflow-wrap: anywhere; }
.bundle-card .desc {
  color: var(--muted); font-size: 14px; margin: 0 0 10px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.bundle-price { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.bundle-price s { color: var(--muted); font-weight: 500; }
.bundle-price b { color: var(--paid); font-size: 20px; }
.bundle-save { font-size: 13px; color: var(--free); font-weight: 700; }

/* ไอคอน 🎁 บนการ์ดคอร์ส (ที่อยู่ใน bundle) */
.course-card { position: relative; }
.card-promo-flag {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  background: #fef3c7; border: 1px solid #fcd34d;
  font-size: 18px; padding: 4px 8px; border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

/* ============ banner "คอร์สนี้อยู่ในโปร" บนหน้าคอร์ส ============ */
.bundle-promo-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; margin: 12px 0;
  background: linear-gradient(135deg, #fef3c7, #fffbeb);
  border: 1px solid #fcd34d; border-radius: var(--radius);
  color: var(--text); box-shadow: var(--shadow);
}
.bundle-promo-banner:hover { background: linear-gradient(135deg, #fde68a, #fef3c7); }
.bpb-icon { font-size: 24px; flex: none; }
.bpb-body { flex: 1; min-width: 0; }
.bpb-body b { display: block; overflow-wrap: anywhere; }
.bpb-detail { font-size: 13px; color: var(--muted); }
.bpb-arrow { font-size: 20px; color: var(--primary); font-weight: 800; flex: none; }

/* ============ หน้า bundle.html ============ */
.bundle-summary { text-align: center; padding: 18px; }
.bundle-price-big { display: flex; align-items: baseline; gap: 12px; justify-content: center; flex-wrap: wrap; }
.bundle-price-big .big { font-size: 32px; color: var(--paid); }
.bundle-price-big s { font-size: 18px; }
.bundle-save-big { margin-top: 6px; color: var(--free); }
.bundle-save-big b { font-size: 17px; }

.bundle-course-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 24px; }
.bundle-course-item {
  display: flex; gap: 12px; padding: 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); box-shadow: var(--shadow);
}
.bundle-course-item:hover { border-color: var(--primary); }
.bundle-course-item .cover {
  width: 120px; aspect-ratio: 16/9; object-fit: cover; flex: none;
  border-radius: 8px; background: var(--surface);
}
.bci-body { flex: 1; min-width: 0; }
.bci-body h3 { margin: 0 0 4px; font-size: 16px; overflow-wrap: anywhere; }
.bci-body p { font-size: 13px; margin: 0 0 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bci-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
@media (max-width: 480px) {
  .bundle-course-item .cover { width: 90px; }
}

/* ============ progress bar ============ */
.progress { height: 8px; background: var(--surface); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--free); width: 0; }
.progress-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ============ หน้าเรียน: สารบัญบท ============ */
.lesson-list { list-style: none; padding: 0; margin: 0; }
.lesson-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 8px; cursor: pointer; background: var(--bg);
}
.lesson-item.active { border-color: var(--primary); background: #eff6ff; }
.lesson-item .lx-title {
  /* >>> ชื่อบทยาวต้องตัดคำ ไม่โดน ... ตัดหาย <<< */
  flex: 1; min-width: 0; overflow-wrap: anywhere; word-break: break-word; line-height: 1.4;
}
/* ปุ่มสถานะบทเรียน — สีชัดเจน: เขียว=ดูแล้ว / น้ำเงิน=ยังไม่ดู / เทา=ล็อก */
.lesson-item .lx-ico {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary); color: #fff;
  font-weight: 700; font-size: 15px; line-height: 1;
}
.lesson-item.done { background: #f0fdf4; border-color: #86efac; }
.lesson-item.done .lx-ico { background: var(--free); color: #fff; }
.lesson-item.done .lx-title { color: #166534; }
.lesson-item.locked .lx-ico { background: #fde68a; color: #92400e; font-size: 22px; }
.lesson-item.locked { opacity: 1; }
.lesson-item.locked .lx-title { color: var(--muted); }
.lock-hint {
  display: block; margin-top: 3px;
  font-size: inherit; font-weight: 600; color: #b45309;
}
.badge-done {
  font-size: 11px; font-weight: 600; padding: 1px 7px;
  background: #dcfce7; color: #166534; border-radius: 999px;
  margin-left: 6px; white-space: nowrap;
}
/* ป้าย "ใหม่ / อัปเดต" ต่อบท (โผล่/หายเองตามเวลา) */
.lx-fresh {
  display: inline-block; margin-left: 6px; padding: 1px 7px;
  font-size: 11px; font-weight: 700; border-radius: 999px; white-space: nowrap;
  vertical-align: middle;
}
.lx-fresh-new { background: #dc2626; color: #fff; }
.lx-fresh-upd { background: #2563eb; color: #fff; }
/* ป้าย fresh มุมการ์ดคอร์ส */
.card-fresh {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  padding: 3px 10px; font-size: 12px; font-weight: 700;
  border-radius: 999px; color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.card-fresh-new { background: #dc2626; }
.card-fresh-upd { background: #2563eb; }

/* บทสำคัญ — ดาว + ไฮไลต์กรอบทองให้เด่นกว่ารายการอื่น */
.lesson-item.important {
  border-color: #fbbf24; background: #fffbeb;
  box-shadow: 0 0 0 1px #fbbf24 inset;
}
.lesson-item.important.done { background: #f0fdf4; }
/* บทรอง — เด่นน้อยกว่า: กรอบอ่อน + ดาวเล็ก-จาง */
.lesson-item.secondary {
  border-color: #fde68a; background: #fffef8;
}
.lesson-item.secondary.done { background: #f0fdf4; }
.lx-star {
  margin-right: 4px; font-size: 15px;
  filter: drop-shadow(0 1px 1px rgba(180,120,0,.35));
}
.lx-star.sec {
  font-size: 10px; margin-right: 3px; opacity: .45; filter: none;
  position: relative; top: -1px;
}
/* ระยะเวลาวีดีโอต่อบท (ชิดขวาของรายการ) */
.lesson-item .lx-dur {
  flex: none; align-self: center;
  font-size: 13px; font-weight: 600; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* สรุปคอร์ส: จำนวนบท + เวลารวม (ใต้คำอธิบาย / ในการ์ด) */
.course-meta {
  margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.hero-text .course-meta { font-size: 15px; margin-top: 12px; }

/* ===== หน้ารายการคอร์สทั้งหมด (#list) — ตัวหนังสือใหญ่ อ่านง่ายสำหรับสายตาไม่ค่อยดี =====
   ไล่ระดับใต้หัวข้อ "คอร์สทั้งหมด" (22px): ชื่อ 20 → คำอธิบาย 18 → จำนวนบท 17 → ป้ายราคา 16 */
#list .course-card h3 { font-size: 20px; }
#list .course-card .desc { font-size: 18px; -webkit-line-clamp: 4; }
#list .course-card .course-meta { font-size: 17px; }
#list .course-card .badge { font-size: 16px; }

/* หัวข้อหมวด (Section) ในสารบัญบท */
.section-head {
  list-style: none;
  font-weight: 800;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  padding: 10px 14px;
  border-radius: 10px;
  margin: 14px 0 8px;
  overflow-wrap: anywhere;
}
.section-head .muted { font-weight: 500; font-size: 13px; }

/* ============ in-app browser gate ============ */
.inapp-gate {
  position: fixed; inset: 0; z-index: 9999; background: rgba(15,23,42,.6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.inapp-card {
  background: #fff; border-radius: var(--radius); padding: 26px 22px; max-width: 360px; text-align: center;
}
.inapp-card h2 { font-size: 20px; margin: 8px 0 12px; }
.inapp-card p { color: var(--muted); margin: 6px 0; }
.inapp-icon { font-size: 40px; }
.inapp-hint { font-size: 14px; }
.inapp-manual { font-size: 13px; margin-top: 14px; }

/* ============ ปุ่มติดต่อลอย ============ */
#contact-fab { position: fixed; right: 14px; bottom: 14px; z-index: 60; display: flex; flex-direction: column; gap: 10px; }
.fab {
  width: auto; min-width: 52px; height: 52px; padding: 0 14px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
.fab-fb { background: #1877f2; font-size: 22px; }
.fab-line { background: #06c755; font-size: 14px; }

/* ============ ทั่วไป ============ */
/* ============ กล่องข้อความ (inbox) — รายการยุบไว้แบบกล่องอีเมล ============ */
.ib-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 12px 0 8px; font-size: 14px; color: var(--muted);
}
.ib-bar-new {
  background: #dc2626; color: #fff; font-weight: 800; font-size: 12px;
  padding: 2px 10px; border-radius: 999px;
}
.inbox-list {
  border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; margin: 0 0 30px; background: var(--bg);
}
.inbox-item { border-bottom: 1px solid var(--border); }
.inbox-item:last-child { border-bottom: 0; }

/* แถบเลือกหลายรายการ (แอดมิน) */
.ib-selall { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; }
.ib-selall input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.ib-count { margin-right: auto; }
.ib-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: #eff6ff; border: 1px solid #93c5fd; border-radius: 10px;
  padding: 10px 14px; margin: 0 0 10px; font-size: 14px;
}
.ib-actions b { color: var(--primary); font-size: 16px; }
.ib-actions-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* แถวหัวข้อ (ยุบอยู่) — กดได้ทั้งแถว */
.ib-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px 12px 10px; cursor: pointer; list-style: none;
  border-left: 4px solid transparent;      /* แถบซ้าย: โปร่งใสเมื่ออ่านแล้ว */
  background: var(--surface);              /* อ่านแล้ว = พื้นเทา */
  transition: background .12s;
}
.ib-row::-webkit-details-marker { display: none; }   /* ซ่อนสามเหลี่ยมเริ่มต้นของเบราว์เซอร์ */
.ib-row:hover { background: #e8edf3; }
.inbox-item[open] > .ib-row { background: #eff6ff; }
.inbox-item.picked > .ib-row { background: #dbeafe; }   /* กำลังเลือกไว้เพื่อลบ */

/* ★ ยังไม่อ่าน — ต่างจากอ่านแล้ว 4 ทาง: พื้นขาว + แถบน้ำเงินซ้าย + จุดแดง + ตัวหนา */
.inbox-item.unread > .ib-row { background: var(--bg); border-left-color: var(--primary); }
.inbox-item.unread > .ib-row:hover { background: #f5f9ff; }

.ib-check { flex: none; display: flex; align-items: center; padding: 4px 2px 0; }
.ib-check input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.ib-dot {
  flex: none; width: 10px; height: 10px; margin-top: 8px;
  border-radius: 50%; background: #cbd5e1;              /* อ่านแล้ว = จุดเทาจาง */
}
.inbox-item.unread .ib-dot { background: #dc2626; box-shadow: 0 0 0 3px #fee2e2; }
.ib-main { flex: 1; min-width: 0; }
.ib-title {
  display: block; font-size: 16px; font-weight: 500; color: var(--muted);  /* อ่านแล้ว = จาง+บาง */
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inbox-item.unread .ib-title { font-weight: 800; color: var(--text); }
.ib-snippet {
  display: block; margin-top: 2px; font-size: 14px; color: #94a3b8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inbox-item.unread .ib-snippet { color: var(--muted); }
.ib-when {
  flex: none; font-size: 12.5px; color: #94a3b8; white-space: nowrap; margin-top: 2px;
}
.inbox-item.unread .ib-when { color: #b91c1c; font-weight: 800; }
.ib-new {
  display: inline-block; margin-left: 8px; vertical-align: middle;
  font-size: 11px; font-weight: 800; padding: 1px 8px;
  border-radius: 999px; background: #dc2626; color: #fff; white-space: nowrap;
}

/* เนื้อหาเต็ม (กางออก) */
.ib-open { padding: 4px 16px 18px; background: var(--bg); }
.ib-date { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.ib-body { font-size: 16px; line-height: 1.6; color: var(--text); overflow-wrap: anywhere; }
.ib-body a { color: var(--primary); }
.ib-body img { max-width: 100%; height: auto; }
.ib-body table { width: 100%; border-collapse: collapse; }
.ib-tools { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
@media (max-width: 480px) {
  .ib-row { padding: 11px 12px; }
  .ib-title { font-size: 15px; }
  .ib-snippet { font-size: 13px; }
  .ib-open { padding: 4px 12px 16px; }
}

.section-title { font-size: 22px; margin: 24px 0 4px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }
.notice { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin: 14px 0; }
.lock-note { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; border-radius: 10px; padding: 14px; }
.pay-info-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; margin: 10px 0;
}
.pay-info-label {
  font-size: 13px; color: var(--muted); font-weight: 700;
  margin-bottom: 6px; letter-spacing: .5px;
}
.pay-info-body {
  white-space: pre-wrap; font-size: 16px; font-weight: 600;
  color: var(--text); overflow-wrap: anywhere;
}

/* ============ สรุปยอดที่ต้องโอน (แสดงเหนือข้อมูลบัญชี) ============ */
.pay-summary {
  background: linear-gradient(135deg, #fffbeb, #fff7ed);
  border: 1px solid #fcd34d; border-left: 5px solid #d97706;
  border-radius: var(--radius); padding: 14px 16px; margin: 12px 0;
}
.ps-label { font-size: 13px; font-weight: 700; color: #92400e; letter-spacing: .5px; }
.ps-amount {
  font-size: 32px; font-weight: 800; color: #b45309;
  line-height: 1.25; margin: 2px 0 4px; overflow-wrap: anywhere;
}
.ps-amount-none { font-size: 16px; font-weight: 700; color: #b91c1c; margin: 4px 0; line-height: 1.5; }
.ps-old { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.ps-item { font-size: 16px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.ps-meta { font-size: 13px; color: var(--muted); margin-top: 5px; overflow-wrap: anywhere; }
.ps-hint { font-size: 13.5px; color: #92400e; margin-top: 9px; line-height: 1.5; }

/* ============ ยกเลิกคำขอลงทะเบียน (2 ขั้น) ============ */
.cancel-req { margin: 14px 0 4px; text-align: center; }
/* ขั้นแรกทำให้ดูไม่เด่น — เป็นทางออก ไม่ใช่ปุ่มหลักที่อยากให้กด */
.cancel-req-link {
  background: none; border: 0; padding: 6px 10px;
  font-family: inherit; font-size: 14px; color: var(--muted);
  text-decoration: underline; cursor: pointer;
}
.cancel-req-link:hover { color: #b91c1c; }
.cancel-req-confirm {
  background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--radius);
  padding: 14px 16px; text-align: left;
}
.cancel-req-confirm .cr-note {
  margin-top: 6px; font-size: 14px; color: var(--muted); line-height: 1.6;
}
.cancel-req-confirm .cr-note b { color: #b91c1c; }
.cancel-req-actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px;
}
.cancel-req-actions .btn { flex: 1; min-width: 140px; }
/* ช่องกรอกเหตุผล (เฉพาะกรณีอัปสลิปแล้ว) */
.cr-reason { margin-top: 10px; }
.cr-reason label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.cr-reason textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 15px; resize: vertical; background: #fff;
}
/* ส่งคำขอยกเลิกไปแล้ว รอแอดมิน */
.cancel-pending {
  background: #fffbeb; border: 1px solid #fcd34d; border-radius: var(--radius);
  padding: 14px 16px; text-align: left; color: #92400e;
}
.cancel-pending .cr-note { margin-top: 6px; font-size: 14px; color: var(--text); line-height: 1.6; }

/* ============ กล่องอัปโหลดสลิป ============ */
.slip-box {
  background: #f0fdf4; border: 1px solid #86efac; border-radius: 10px;
  padding: 14px; margin: 10px 0;
}
.slip-label {
  font-weight: 700; font-size: 15px; margin-bottom: 8px; color: #166534;
}
.slip-thumb {
  display: inline-block; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; max-width: 200px; background: #fff;
}
.slip-thumb img { display: block; width: 100%; height: auto; }
.slip-thumb:hover { border-color: var(--primary); }
.adm-slip { max-width: 160px; }

/* ============ หน้าเรียน (single-column flow: บทก่อน → วีดีโอ → บทถัดไป) ============ */
.learn-flow { max-width: 700px; margin: 0 auto; }
.back-link { display: inline-block; padding: 6px 0; }
.learn-title { font-size: 21px; margin: 8px 0 14px; line-height: 1.4; overflow-wrap: anywhere; }
.learn-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 16px 0 4px; }
.learn-nav-center {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 0; flex-shrink: 1;
}
.learn-nav-center .progress-label { font-size: 13px; }
@media (max-width: 480px) {
  .learn-nav { gap: 6px; }
  .learn-nav-center .btn { padding: 6px 8px; font-size: 13px; }
}
.current-lesson {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  margin: 12px 0;
  scroll-margin-top: 70px; /* offset ให้ pinned header */
  box-shadow: var(--shadow);
}
.lesson-text { font-size: 17px; }
.lesson-text h2 { font-size: 20px; margin: 18px 0 8px; }
.lesson-text h3 { font-size: 18px; margin: 16px 0 6px; }
.lesson-text p { margin: 0 0 12px; overflow-wrap: anywhere; }

/* ============ ไฟล์แถม (ebook) ============ */
.ebook-list { margin: 12px 0 24px; display: flex; flex-direction: column; gap: 8px; }
.ebook-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg);
}
.ebook-row.error { background: #fef2f2; border-color: #fecaca; }
.ebook-icon { flex: none; font-size: 20px; }
.ebook-title {
  flex: 1; min-width: 0; font-weight: 600;
  overflow-wrap: anywhere; word-break: break-word;
}
.ebook-actions { display: flex; gap: 6px; flex: none; flex-wrap: wrap; }

/* Modal สำหรับอ่าน */
.ebook-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(15, 23, 42, .75);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.ebook-modal {
  background: #fff; border-radius: var(--radius);
  width: 100%; max-width: 1000px; height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.ebook-mhead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.ebook-mhead h3 { margin: 0; font-size: 17px; overflow-wrap: anywhere; }
.ebook-x {
  background: transparent; border: 0; font-size: 22px; cursor: pointer;
  color: var(--muted); padding: 4px 10px;
}
.ebook-x:hover { color: var(--text); }
.ebook-frame { flex: 1; border: 0; width: 100%; background: #f3f4f6; }

/* ============ จอใหญ่ขึ้น ============ */
@media (min-width: 640px) {
  .course-grid { grid-template-columns: 1fr 1fr; }
  .bundle-grid { grid-template-columns: 1fr 1fr; }
  .hero-text h1 { font-size: 32px; }
}
@media (min-width: 900px) {
  .course-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* ============ แถบชวนติดตั้งไอคอน (PWA install promotion) ============ */
/* วางล่างจอ ไม่บังเนื้อหา · ปุ่มติดต่อลอยถูกดันขึ้นตามความสูงจริงของแถบ (--pwa-promo-h) */
body.pwa-promo-open #contact-fab { bottom: calc(24px + var(--pwa-promo-h, 120px)); }
#contact-fab { transition: bottom .28s ease; }
.pwa-promo {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 70;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  padding: 14px 40px 14px 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  transform: translateY(130%); opacity: 0;
  transition: transform .28s ease, opacity .28s ease;
}
.pwa-promo.on { transform: translateY(0); opacity: 1; }
.pwa-promo-ico { font-size: 30px; line-height: 1; flex: 0 0 auto; }
.pwa-promo-body { flex: 1 1 190px; min-width: 0; }
.pwa-promo-body b { display: block; font-size: 15px; margin-bottom: 3px; }
.pwa-promo-body span { color: var(--muted); font-size: 13px; line-height: 1.5; }
.pwa-promo-steps { margin: 6px 0 0; padding-left: 20px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.pwa-promo-actions { display: flex; gap: 8px; flex: 0 0 auto; margin-left: auto; }
.pwa-promo-x {
  position: absolute; top: 6px; right: 8px; border: 0; background: none;
  color: var(--muted); font-size: 17px; line-height: 1; cursor: pointer; padding: 6px;
}
/* จอแคบ: ปุ่มลงบรรทัดใหม่เต็มความกว้าง กดง่ายด้วยนิ้วโป้ง */
@media (max-width: 420px) {
  .pwa-promo-actions { margin-left: 0; width: 100%; }
  .pwa-promo-actions .btn { flex: 1; }
}

/* กล่องแจ้งผลหลังเพิ่มไอคอน — กลางจอ เด่นชัด ปิดได้ด้วยการแตะปุ่มเท่านั้น */
.pwa-done {
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(15, 23, 42, .62);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; transition: opacity .25s ease;
}
.pwa-done.on { opacity: 1; }
.pwa-done-card {
  background: #fff; border-radius: 18px; padding: 26px 22px 20px;
  max-width: 360px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  transform: translateY(16px) scale(.97);
  transition: transform .25s ease;
  max-height: 90vh; overflow-y: auto;
}
.pwa-done.on .pwa-done-card { transform: none; }
.pwa-done-check {
  width: 58px; height: 58px; margin: 0 auto 12px; border-radius: 50%;
  background: #dcfce7; color: #16a34a;
  font-size: 32px; font-weight: 800; line-height: 58px;
}
.pwa-done-card h2 { margin: 0 0 6px; font-size: 21px; color: var(--text); }
.pwa-done-lead { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.6; }
/* ตัวอย่างไอคอนจริง — ให้ผู้ใช้เห็นหน้าตาสิ่งที่ต้องไปหา ไม่ใช่บรรยายด้วยคำ */
.pwa-done-preview {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; margin-bottom: 14px;
}
.pwa-done-hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.pwa-done-icon { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.pwa-done-icon img {
  width: 72px; height: 72px; border-radius: 17px; display: block;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
}
.pwa-done-label {
  font-size: 13px; font-weight: 600; color: var(--text);
  max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pwa-done-where {
  margin: 0 0 16px; font-size: 13px; line-height: 1.65;
  color: #065f46; background: #ecfdf5; border: 1px solid #a7f3d0;
  border-radius: 10px; padding: 11px 13px; text-align: left;
}

/* เคารพผู้ใช้ที่ตั้งค่าลดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
  .pwa-promo, .pwa-done, .pwa-done-card { transition: none; }
}
@media (min-width: 560px) {
  .pwa-promo { left: auto; right: 16px; bottom: 16px; max-width: 420px; }
}

/* ปุ่มจ่ายเงินออนไลน์ (Stripe Payment Link) — เด่นกว่าเลขบัญชี เพราะกดจบในคลิกเดียว */
.pay-online-btn { margin: 14px 0 6px; text-decoration: none; }
.pay-online-hint { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-bottom: 12px; text-align: center; }
/* ลิงก์ในกล่องข้อมูลโอนเงินที่แอดมินพิมพ์เอง — ต้องกดได้ ไม่ให้ลูกค้าต้องคัดลอกเอง */
.pay-info-body a { color: var(--primary); word-break: break-all; }

/* ช่องกรอกบัญชีรับเงินของผู้แนะนำ (affiliate.html)
   ⚠️ หน้านี้โหลดเฉพาะ styles.css ไม่ได้โหลด admin.css ⇒ textarea ไม่มีสไตล์ใด ๆ
   เบราว์เซอร์จึงให้ความกว้างปริยายราว 20 ตัวอักษร ซึ่งแคบเกินกว่าจะกรอกเลขบัญชีได้ */
.aff-payout {
  display: block; width: 100%;
  min-height: 130px;                 /* ~5 บรรทัด: ธนาคาร / เลขบัญชี / ชื่อบัญชี / พร้อมเพย์ */
  padding: 10px 12px;
  border: 1px solid var(--border, #ccc); border-radius: 8px;
  font-family: inherit; font-size: 15px; line-height: 1.7;
  background: #fff; color: var(--text);
  resize: vertical;                  /* ผู้ใช้ขยายเองได้ถ้ายังไม่พอ */
}
.aff-payout:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.aff-payout::placeholder { color: var(--muted); }

/* กล่อง "บัญชีที่บันทึกไว้" เหนือช่องกรอก — ข้อความที่อยู่ในช่องกรอกดูเหมือนยังไม่ได้บันทึก */
.aff-payout-saved {
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px;
  padding: 10px 12px; margin-bottom: 10px;
}
.aff-payout-saved-lbl { font-size: 12.5px; font-weight: 700; color: #166534; margin-bottom: 4px; }
.aff-payout-saved-val {
  white-space: pre-wrap;      /* เก็บการขึ้นบรรทัดที่ผู้ใช้พิมพ์ไว้ */
  word-break: break-word;     /* เลขบัญชียาว ๆ ไม่ดันกล่องล้นจอ */
  font-size: 15px; line-height: 1.7; color: var(--text);
}
.aff-payout-none {
  background: #fffbeb; border: 1px solid #fcd34d; border-radius: 8px;
  padding: 10px 12px; margin-bottom: 10px;
  font-size: 14px; line-height: 1.6; color: #92400e;
}

/* ปุ่ม "ดูเว็บต่อไปก่อน" ในประตูกันเบราว์เซอร์ในแอป — เป็นทางออกเสมอ ห้ามบล็อกตายตัว */
.btn-link-plain {
  display: block; width: 100%; margin-top: 14px;
  background: none; border: 0; padding: 6px;
  color: var(--primary); font: inherit; font-size: 15px; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}
