/* ============================================================================
   ui.css — Upskill88 Design System
   ----------------------------------------------------------------------------
   แหล่งความจริงเดียวของ "หน้าตา" ทั้งเว็บ

   ก่อนหน้านี้ระบบมี :root แยกกัน 7 ชุด (--auth-*, --d2-*, --identity-*,
   --course2-*, home-base, --admin-*, theme.css.php) ที่นิยามสีเดียวกัน
   ด้วยค่าต่างกัน — ดำ 6 เฉด เทา 6 เฉด แบรนด์ 3 สี ไฟล์นี้ยุบทั้งหมดเหลือชุดเดียว

   ทุกคู่สีในไฟล์นี้ผ่าน WCAG AA (>= 4.5:1) ตรวจด้วยการคำนวณจริงแล้ว
   ถ้าจะเพิ่มสีใหม่ ต้องคำนวณ contrast ก่อนเสมอ

   โครงไฟล์
     1. Tokens          — ตัวแปรทั้งหมด
     2. Reset & base    — พื้นฐานเอกสาร
     3. Typography      — สเกลตัวอักษร
     4. Layout          — container / stack / grid
     5. Components      — button, card, badge, form, alert, table, progress
     6. Site chrome     — header, mobile bottom nav, footer
     7. Utilities       — ตัวช่วยที่ใช้บ่อยจริง
     8. Motion & print  — reduced-motion, print
   ========================================================================= */

/* ── 1. TOKENS ───────────────────────────────────────────────────────────── */

:root {
  /* ---- Brand: teal-green ----
     เลือกจากสีที่ระบบใช้อยู่แล้วในหน้าที่ทำได้ดีที่สุด (auth #0b6d87,
     home forest #173b38, meta theme-color #123f3b) แล้วหลอมเป็นสเกลเดียว */
  --u-brand-900: #0e2f2c;   /* hero, footer, surface เข้ม  — white บนนี้ 14.4:1 */
  --u-brand-800: #103f3a;
  --u-brand-700: #14514a;   /* หัวข้อสีแบรนด์ — 9.1:1 บนขาว */
  --u-brand-600: #0f6b62;   /* สีหลักของสิ่งที่กดได้ — 6.4:1 ทั้งสองทาง */
  --u-brand-500: #13857a;
  --u-brand-200: #bfe0da;
  --u-brand-100: #e3f2ef;   /* พื้นอ่อน */

  /* ---- Accent: coral — ใช้กับ CTA ที่เกี่ยวกับเงินเท่านั้น ----
     จำกัดการใช้ไว้กับ "ซื้อ / สมัคร / จ่ายเงิน" เพื่อให้ปุ่มสีนี้
     มีความหมายเดียว ผู้ใช้จะเรียนรู้ได้ว่าสีส้ม = ก้าวต่อไปที่ต้องจ่าย */
  --u-accent-700: #a8371c;
  --u-accent-600: #bf4526;  /* 5.1:1 ทั้งสองทาง */
  --u-accent-100: #fdeee9;

  /* ---- Gold: ใบรับรอง / ความสำเร็จ ---- */
  --u-gold-700: #7f5a08;
  --u-gold-600: #8f610b;    /* 5.4:1 ทั้งสองทาง */
  --u-gold-100: #fdf3dc;

  /* ---- Neutrals: แทน "ink" 6 เฉดและ "muted" 6 เฉดเดิม ---- */
  --u-ink:        #16211f;  /* ข้อความหลัก      — 16.5:1 */
  --u-ink-2:      #3d4b48;  /* ข้อความรอง       —  9.1:1 */
  --u-muted:      #5f6f6b;  /* ข้อความประกอบ    —  5.3:1 (ผ่านบน canvas ด้วย) */
  --u-line:       #dde4e1;  /* เส้นคั่นทั่วไป */
  --u-line-strong:#c3cfcb;  /* ขอบ input, เส้นที่ต้องเห็นชัด */
  --u-surface:    #ffffff;  /* พื้นการ์ด */
  --u-surface-2:  #f6f8f7;  /* พื้นรอง เช่น thead, well */
  --u-canvas:     #f2f5f3;  /* พื้นหลังหน้า */

  /* ---- Semantic ---- */
  --u-ok-600:     #14724e;  --u-ok-100:     #e6f5ee;
  --u-warn-600:   #8a5a00;  --u-warn-100:   #fff3d9;
  --u-danger-600: #b3261e;  --u-danger-100: #fdeceb;
  --u-info-600:   #1d5fb8;  --u-info-100:   #e8f1fd;

  /* ---- Typography ----
     ตระกูลเดียวทั้งเว็บ เดิมมี 10 Google Fonts URL / 3 ตระกูลไทย
     IBM Plex Sans Thai รองรับน้ำหนัก 400-700 และคู่กับ Latin ได้ในตัว */
  --u-font: "IBM Plex Sans Thai", "IBM Plex Sans", -apple-system,
            BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
            Arial, "Noto Sans Thai", sans-serif;
  --u-font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  /* สเกลตัวอักษร — ปรับตามจอด้วย clamp() ไม่ต้องเขียน media query ซ้ำ
     ภาษาไทยไม่มีตัวพิมพ์ใหญ่ช่วยแยกคำ จึงตั้ง base 16px และ line-height สูง
     กว่าเว็บอังกฤษเล็กน้อย เพื่อให้สระบน/ล่างไม่ชนกัน */
  --u-fs-xs:  0.75rem;    /* 12 — meta, badge */
  --u-fs-sm:  0.8125rem;  /* 13 — ข้อความประกอบ */
  --u-fs-md:  0.9375rem;  /* 15 — UI ทั่วไป */
  --u-fs-base:1rem;       /* 16 — เนื้อความ */
  --u-fs-lg:  1.125rem;   /* 18 */
  --u-fs-xl:  clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
  --u-fs-2xl: clamp(1.5rem, 1.25rem + 1.1vw, 2rem);
  --u-fs-3xl: clamp(1.875rem, 1.4rem + 2vw, 2.75rem);
  --u-fs-4xl: clamp(2.25rem, 1.5rem + 3.2vw, 3.5rem);

  --u-lh-tight: 1.25;
  --u-lh-snug:  1.45;
  --u-lh-body:  1.7;   /* ไทยต้องการมากกว่าอังกฤษ เพราะสระซ้อนสองชั้น */

  /* ---- Spacing: สเกล 4px ---- */
  --u-1: 4px;   --u-2: 8px;   --u-3: 12px;  --u-4: 16px;
  --u-5: 20px;  --u-6: 24px;  --u-8: 32px;  --u-10: 40px;
  --u-12: 48px; --u-16: 64px; --u-20: 80px;

  /* ---- Radius ---- */
  --u-r-sm: 6px;  --u-r-md: 10px;  --u-r-lg: 14px;
  --u-r-xl: 20px; --u-r-pill: 999px;

  /* ---- Elevation: เงาสีเดียวกับ ink ทำให้ดูเป็นเนื้อเดียวกัน ---- */
  --u-shadow-sm: 0 1px 2px rgba(22, 33, 31, .06),
                 0 1px 3px rgba(22, 33, 31, .04);
  --u-shadow-md: 0 4px 12px rgba(22, 33, 31, .07),
                 0 2px 4px rgba(22, 33, 31, .04);
  --u-shadow-lg: 0 12px 32px rgba(22, 33, 31, .10),
                 0 4px 8px rgba(22, 33, 31, .05);

  /* ---- Layout ---- */
  --u-container: 1180px;
  --u-container-narrow: 760px;
  --u-gutter: clamp(16px, 4vw, 24px);
  --u-header-h: 62px;
  --u-bottomnav-h: 58px;

  --u-ring: 0 0 0 3px rgba(15, 107, 98, .35);
  --u-t-fast: .14s ease;
  --u-t: .2s ease;

  color-scheme: light;
}

/* Dark mode ตั้งเป็น opt-in (data-theme) ไม่ใช่ media query โดยตั้งใจ
   เพราะยังมี CSS ฝังในไฟล์ PHP อีกราว 5,500 บรรทัดที่ hardcode พื้นขาวไว้
   ถ้าเปิด auto ทันทีจะได้หน้าที่อ่านไม่ออก เปิดใช้เมื่อย้าย inline CSS หมดแล้ว */
[data-theme="dark"] {
  --u-ink:        #e8edeb;
  --u-ink-2:      #c3cecb;
  --u-muted:      #97a5a1;
  --u-line:       #2b3a37;
  --u-line-strong:#3d504c;
  --u-surface:    #16211f;
  --u-surface-2:  #1c2b28;
  --u-canvas:     #101917;
  --u-brand-600:  #4fb3a6;
  --u-brand-100:  #17302d;
  color-scheme: dark;
}

/* ── 2. RESET & BASE ─────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--u-header-h) + var(--u-4));
}

body {
  margin: 0;
  background: var(--u-canvas);
  color: var(--u-ink);
  font-family: var(--u-font);
  font-size: var(--u-fs-base);
  line-height: var(--u-lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* กันเนื้อหาโดน bottom nav บนมือถือทับ */
  padding-bottom: env(safe-area-inset-bottom);
}

img, svg, video, canvas { max-width: 100%; height: auto; display: block; }
svg { flex-shrink: 0; }

/* ต้องมาหลังกฎ img ด้านบน และต้องใช้ !important
   เหตุผล: [hidden] เป็นกฎของ user-agent stylesheet ซึ่งแพ้กฎของเราเสมอ
   ถ้าไม่บังคับ การสั่ง el.hidden = true กับ <img> จะไม่มีผลเลย
   (เจอจริงตอนทดสอบ: โลโก้สำรองกับโลโก้จริงโผล่พร้อมกันสองอัน) */
[hidden] { display: none !important; }

/* โฟกัสต้องเห็นชัดเสมอ — เดิมมีแค่ 19 จาก 87 ไฟล์ที่จัดการเรื่องนี้ */
:focus-visible {
  outline: 2px solid var(--u-brand-600);
  outline-offset: 2px;
  border-radius: var(--u-r-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--u-brand-200); color: var(--u-brand-900); }

hr { border: 0; border-top: 1px solid var(--u-line); margin: var(--u-6) 0; }

/* ── 3. TYPOGRAPHY ───────────────────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--u-3);
  line-height: var(--u-lh-tight);
  font-weight: 700;
  color: var(--u-ink);
  letter-spacing: 0;   /* ห้าม letter-spacing ติดลบกับไทย สระจะชนกัน */
}
h1 { font-size: var(--u-fs-3xl); }
h2 { font-size: var(--u-fs-2xl); }
h3 { font-size: var(--u-fs-xl); }
h4 { font-size: var(--u-fs-lg); }
h5, h6 { font-size: var(--u-fs-base); }

p { margin: 0 0 var(--u-4); }
p:last-child { margin-bottom: 0; }

a { color: var(--u-brand-600); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--u-brand-700); }

small, .u-small { font-size: var(--u-fs-sm); }
strong, b { font-weight: 700; }
code, kbd, samp, pre { font-family: var(--u-font-mono); font-size: .9em; }

.u-eyebrow {
  display: block;
  font-size: var(--u-fs-xs);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--u-brand-600);
  margin-bottom: var(--u-2);
}
.u-lead  { font-size: var(--u-fs-lg); color: var(--u-ink-2); }
.u-muted { color: var(--u-muted); }

/* ── 4. LAYOUT ───────────────────────────────────────────────────────────── */

.u-container {
  width: 100%;
  max-width: var(--u-container);
  margin-inline: auto;
  padding-inline: var(--u-gutter);
}
.u-container--narrow { max-width: var(--u-container-narrow); }

.u-section { padding-block: clamp(32px, 6vw, 64px); }
.u-section--tight { padding-block: clamp(20px, 3vw, 32px); }

/* stack = ระยะห่างแนวตั้งสม่ำเสมอ ไม่ต้องไล่ margin ทีละอัน */
.u-stack > * + * { margin-top: var(--u-4); }
.u-stack-lg > * + * { margin-top: var(--u-8); }

.u-row { display: flex; flex-wrap: wrap; gap: var(--u-3); align-items: center; }
.u-row--between { justify-content: space-between; }
.u-row--end { justify-content: flex-end; }

.u-grid { display: grid; gap: var(--u-4); }
.u-grid--auto  { grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }
.u-grid--2     { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.u-grid--stats { grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); }

/* หัวข้อ section + action ด้านขวา */
.u-section-head {
  display: flex; flex-wrap: wrap; gap: var(--u-3);
  align-items: flex-end; justify-content: space-between;
  margin-bottom: var(--u-5);
}
.u-section-head h2, .u-section-head h3 { margin-bottom: var(--u-1); }
.u-section-head p { margin: 0; color: var(--u-muted); font-size: var(--u-fs-md); }

/* ── 5. COMPONENTS ───────────────────────────────────────────────────────── */

/* -- Button --------------------------------------------------------------
   min-height 44px = ขนาดเป้าแตะขั้นต่ำที่นิ้วกดพลาดยาก บนมือถือ         */
.u-btn {
  --_bg: var(--u-surface);
  --_fg: var(--u-ink);
  --_bd: var(--u-line-strong);
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--u-2);
  min-height: 44px;
  padding: 10px var(--u-5);
  border: 1px solid var(--_bd);
  border-radius: var(--u-r-md);
  background: var(--_bg);
  color: var(--_fg);
  font: inherit;
  font-size: var(--u-fs-md);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--u-t-fast), border-color var(--u-t-fast),
              color var(--u-t-fast), box-shadow var(--u-t-fast);
}
.u-btn:hover { box-shadow: var(--u-shadow-sm); }
.u-btn:active { transform: translateY(1px); }
.u-btn:disabled, .u-btn[aria-disabled="true"] {
  opacity: .55; cursor: not-allowed; box-shadow: none; transform: none;
}

.u-btn--primary   { --_bg: var(--u-brand-600); --_fg: #fff; --_bd: var(--u-brand-600); }
.u-btn--primary:hover { --_bg: var(--u-brand-700); --_bd: var(--u-brand-700); color: #fff; }

/* สีส้มสงวนไว้สำหรับ "จ่ายเงิน" เท่านั้น — อย่าใช้กับปุ่มทั่วไป */
.u-btn--buy       { --_bg: var(--u-accent-600); --_fg: #fff; --_bd: var(--u-accent-600); }
.u-btn--buy:hover { --_bg: var(--u-accent-700); --_bd: var(--u-accent-700); color: #fff; }

.u-btn--dark      { --_bg: var(--u-brand-900); --_fg: #fff; --_bd: var(--u-brand-900); }
.u-btn--dark:hover{ --_bg: var(--u-brand-800); color: #fff; }

.u-btn--ghost     { --_bg: transparent; --_fg: var(--u-brand-700); --_bd: var(--u-line-strong); }
.u-btn--ghost:hover { --_bg: var(--u-brand-100); --_bd: var(--u-brand-200); }

.u-btn--quiet     { --_bg: transparent; --_fg: var(--u-ink-2); --_bd: transparent; }
.u-btn--quiet:hover { --_bg: var(--u-surface-2); }

.u-btn--danger    { --_bg: transparent; --_fg: var(--u-danger-600); --_bd: var(--u-danger-600); }
.u-btn--danger:hover { --_bg: var(--u-danger-100); }

.u-btn--sm  { min-height: 36px; padding: 6px var(--u-3); font-size: var(--u-fs-sm); }
.u-btn--lg  { min-height: 52px; padding: 14px var(--u-8); font-size: var(--u-fs-lg); }
.u-btn--block { width: 100%; }

/* -- Card ---------------------------------------------------------------- */
.u-card {
  background: var(--u-surface);
  border: 1px solid var(--u-line);
  border-radius: var(--u-r-lg);
  box-shadow: var(--u-shadow-sm);
  overflow: hidden;
}
.u-card__head {
  display: flex; flex-wrap: wrap; gap: var(--u-3);
  align-items: center; justify-content: space-between;
  padding: var(--u-4) var(--u-5);
  border-bottom: 1px solid var(--u-line);
  background: var(--u-surface-2);
}
.u-card__head h2, .u-card__head h3, .u-card__head h4 { margin: 0; font-size: var(--u-fs-lg); }
.u-card__body { padding: var(--u-5); }
.u-card__foot {
  padding: var(--u-3) var(--u-5);
  border-top: 1px solid var(--u-line);
  background: var(--u-surface-2);
}

/* การ์ดที่กดได้ทั้งใบ */
.u-card--link { display: block; text-decoration: none; color: inherit; transition: box-shadow var(--u-t), border-color var(--u-t); }
.u-card--link:hover { box-shadow: var(--u-shadow-md); border-color: var(--u-brand-200); color: inherit; }

/* แถบสีบอกหมวด — ใช้แทนการเปลี่ยนพื้นทั้งใบ ซึ่งทำให้ contrast พัง */
.u-card--brand  { border-top: 3px solid var(--u-brand-600); }
.u-card--gold   { border-top: 3px solid var(--u-gold-600); }
.u-card--ok     { border-top: 3px solid var(--u-ok-600); }

/* -- Badge --------------------------------------------------------------- */
.u-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: var(--u-r-pill);
  background: var(--u-surface-2);
  color: var(--u-ink-2);
  font-size: var(--u-fs-xs);
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}
.u-badge--brand  { background: var(--u-brand-100);  color: var(--u-brand-700); }
.u-badge--ok     { background: var(--u-ok-100);     color: var(--u-ok-600); }
.u-badge--warn   { background: var(--u-warn-100);   color: var(--u-warn-600); }
.u-badge--danger { background: var(--u-danger-100); color: var(--u-danger-600); }
.u-badge--info   { background: var(--u-info-100);   color: var(--u-info-600); }
.u-badge--gold   { background: var(--u-gold-100);   color: var(--u-gold-600); }

/* -- Form ---------------------------------------------------------------- */
.u-field { margin-bottom: var(--u-4); }
.u-label {
  display: block;
  margin-bottom: var(--u-1);
  font-size: var(--u-fs-md);
  font-weight: 600;
  color: var(--u-ink);
}
.u-label .u-req { color: var(--u-danger-600); }

.u-input, .u-select, .u-textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px var(--u-3);
  border: 1px solid var(--u-line-strong);
  border-radius: var(--u-r-md);
  background: var(--u-surface);
  color: var(--u-ink);
  font: inherit;
  font-size: var(--u-fs-base);   /* >=16px กัน iOS ซูมอัตโนมัติตอนโฟกัส */
  transition: border-color var(--u-t-fast), box-shadow var(--u-t-fast);
}
.u-textarea { min-height: 120px; line-height: var(--u-lh-snug); resize: vertical; }
.u-input:focus, .u-select:focus, .u-textarea:focus {
  outline: none;
  border-color: var(--u-brand-600);
  box-shadow: var(--u-ring);
}
.u-input[aria-invalid="true"], .u-select[aria-invalid="true"], .u-textarea[aria-invalid="true"] {
  border-color: var(--u-danger-600);
}
.u-input::placeholder, .u-textarea::placeholder { color: var(--u-muted); opacity: 1; }
.u-help  { margin: var(--u-1) 0 0; font-size: var(--u-fs-sm); color: var(--u-muted); }
.u-error { margin: var(--u-1) 0 0; font-size: var(--u-fs-sm); color: var(--u-danger-600); font-weight: 600; }

.u-select {
  appearance: none;
  padding-right: var(--u-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%235f6f6b' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--u-3) center;
  background-size: 12px;
}

/* -- Alert --------------------------------------------------------------- */
.u-alert {
  padding: var(--u-3) var(--u-4);
  border: 1px solid transparent;
  border-left-width: 4px;
  border-radius: var(--u-r-md);
  font-size: var(--u-fs-md);
  margin-bottom: var(--u-4);
}
.u-alert--ok     { background: var(--u-ok-100);     border-color: var(--u-ok-600);     color: var(--u-ok-600); }
.u-alert--warn   { background: var(--u-warn-100);   border-color: var(--u-warn-600);   color: var(--u-warn-600); }
.u-alert--danger { background: var(--u-danger-100); border-color: var(--u-danger-600); color: var(--u-danger-600); }
.u-alert--info   { background: var(--u-info-100);   border-color: var(--u-info-600);   color: var(--u-info-600); }

/* -- Progress ------------------------------------------------------------ */
.u-progress {
  height: 8px;
  border-radius: var(--u-r-pill);
  background: var(--u-line);
  overflow: hidden;
}
.u-progress__bar {
  height: 100%;
  border-radius: inherit;
  background: var(--u-brand-600);
  transition: width .5s ease;
}
.u-progress__bar--done { background: var(--u-ok-600); }

/* -- Table --------------------------------------------------------------- */
/* ตารางต้องเลื่อนในกล่องของตัวเอง ไม่ใช่ดันทั้งหน้าให้เลื่อนแนวนอน */
.u-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.u-table { width: 100%; border-collapse: collapse; font-size: var(--u-fs-md); }
.u-table th, .u-table td {
  padding: var(--u-3);
  text-align: left;
  border-bottom: 1px solid var(--u-line);
  vertical-align: top;
}
.u-table th { background: var(--u-surface-2); font-weight: 700; color: var(--u-ink-2); white-space: nowrap; }
.u-table tbody tr:hover { background: var(--u-surface-2); }

/* -- Empty state --------------------------------------------------------- */
.u-empty {
  padding: var(--u-10) var(--u-5);
  border: 1px dashed var(--u-line-strong);
  border-radius: var(--u-r-lg);
  background: var(--u-surface);
  text-align: center;
  color: var(--u-muted);
}
.u-empty h3 { color: var(--u-ink-2); margin-bottom: var(--u-2); font-size: var(--u-fs-lg); }

/* -- Skip link ----------------------------------------------------------- */
.u-skip {
  position: absolute;
  left: var(--u-3); top: -100px;
  z-index: 200;
  padding: var(--u-3) var(--u-5);
  background: var(--u-brand-900);
  color: #fff;
  border-radius: 0 0 var(--u-r-md) var(--u-r-md);
  font-weight: 700;
  text-decoration: none;
  transition: top var(--u-t-fast);
}
.u-skip:focus { top: 0; color: #fff; }

/* ── 6. SITE CHROME ──────────────────────────────────────────────────────── */

/* -- Header -------------------------------------------------------------- */
.u-header {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--u-surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--u-line);
}
@supports not (backdrop-filter: blur(1px)) { .u-header { background: var(--u-surface); } }

.u-header__inner {
  display: flex; align-items: center; gap: var(--u-4);
  min-height: var(--u-header-h);
}
.u-brand {
  display: inline-flex; align-items: center; gap: var(--u-2);
  font-weight: 800; font-size: var(--u-fs-lg);
  color: var(--u-ink); text-decoration: none;
  white-space: nowrap;
}
.u-brand__mark {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--u-brand-900);
  color: #fff;
  font-size: 13px; font-weight: 800;
}
.u-brand img { height: 30px; width: auto; }
/* ตัวสำรองเมื่อไฟล์โลโก้โหลดไม่ได้ — ถูกเปิดโดย onerror ของ <img> */
.u-brand__fallback { display: inline-flex; align-items: center; gap: var(--u-2); }
.u-brand__fallback[hidden] { display: none; }

.u-nav { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.u-nav__link {
  padding: var(--u-2) var(--u-3);
  border-radius: var(--u-r-sm);
  color: var(--u-ink-2);
  font-size: var(--u-fs-md); font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--u-t-fast), color var(--u-t-fast);
}
.u-nav__link:hover { background: var(--u-surface-2); color: var(--u-ink); }
.u-nav__link[aria-current="page"] {
  color: var(--u-brand-700);
  background: var(--u-brand-100);
}
.u-nav__count {
  display: inline-block; margin-left: 4px;
  padding: 0 6px; border-radius: var(--u-r-pill);
  background: var(--u-brand-100); color: var(--u-brand-700);
  font-size: var(--u-fs-xs); font-weight: 800;
}
.u-nav__actions { display: flex; align-items: center; gap: var(--u-2); margin-left: var(--u-2); }

/* ปุ่มเมนูมือถือ — แสดงเฉพาะจอเล็ก */
.u-navtoggle { display: none; }

@media (max-width: 900px) {
  .u-nav { display: none; }
  .u-navtoggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; margin-left: auto;
    border: 1px solid var(--u-line-strong); border-radius: var(--u-r-md);
    background: var(--u-surface); color: var(--u-ink); cursor: pointer;
  }
  .u-nav.is-open {
    display: flex; flex-direction: column; align-items: stretch;
    position: absolute; left: 0; right: 0; top: 100%;
    margin: 0; padding: var(--u-3) var(--u-gutter) var(--u-4);
    background: var(--u-surface);
    border-bottom: 1px solid var(--u-line);
    box-shadow: var(--u-shadow-lg);
    gap: var(--u-1);
  }
  .u-nav.is-open .u-nav__link { padding: var(--u-3); font-size: var(--u-fs-base); }
  .u-nav.is-open .u-nav__actions { margin: var(--u-2) 0 0; flex-direction: column; align-items: stretch; }
  .u-nav.is-open .u-btn { width: 100%; }
  .u-header { position: relative; }
  .u-header--sticky-mobile { position: sticky; }
}

/* -- Mobile bottom nav ---------------------------------------------------
   เก็บ pattern เดิมของระบบไว้ (ถูกแล้วสำหรับผู้ใช้ไทยที่ถือมือถือมือเดียว)
   แต่ผูกกับ token กลางและทำให้ทุกหน้ามีเหมือนกัน ไม่ใช่เฉพาะบางหน้า      */
.u-bottomnav { display: none; }

@media (max-width: 900px) {
  .u-bottomnav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 110;
    height: calc(var(--u-bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--u-surface);
    border-top: 1px solid var(--u-line);
  }
  body.has-bottomnav {
    padding-bottom: calc(var(--u-bottomnav-h) + env(safe-area-inset-bottom));
  }
  .u-bottomnav__item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    border: 0; background: none; cursor: pointer;
    color: var(--u-muted);
    font: inherit; font-size: 10px; font-weight: 600;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  .u-bottomnav__item svg { width: 21px; height: 21px; }
  .u-bottomnav__item[aria-current="page"] { color: var(--u-brand-600); }
}

/* -- Footer -------------------------------------------------------------- */
.u-footer {
  margin-top: var(--u-16);
  padding-block: var(--u-10) var(--u-8);
  background: var(--u-brand-900);
  color: rgba(255, 255, 255, .78);
  font-size: var(--u-fs-md);
}
.u-footer a { color: #fff; text-decoration: none; }
.u-footer a:hover { text-decoration: underline; color: #fff; }
.u-footer__grid {
  display: grid; gap: var(--u-8);
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  margin-bottom: var(--u-8);
}
.u-footer h2, .u-footer h3 {
  color: #fff; font-size: var(--u-fs-md);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: var(--u-3);
}
.u-footer ul { list-style: none; margin: 0; padding: 0; }
.u-footer li + li { margin-top: var(--u-2); }
.u-footer__bottom {
  padding-top: var(--u-5);
  border-top: 1px solid rgba(255, 255, 255, .15);
  display: flex; flex-wrap: wrap; gap: var(--u-3);
  justify-content: space-between;
  font-size: var(--u-fs-sm);
}

/* -- Breadcrumb ---------------------------------------------------------- */
.u-crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--u-2);
  margin-bottom: var(--u-4);
  font-size: var(--u-fs-sm);
  color: var(--u-muted);
  list-style: none; padding: 0;
}
.u-crumbs a { color: var(--u-muted); text-decoration: none; }
.u-crumbs a:hover { color: var(--u-brand-600); text-decoration: underline; }
.u-crumbs li + li::before { content: "/"; margin-right: var(--u-2); opacity: .5; }

/* -- Dropdown menu (บัญชี) ----------------------------------------------
   เขียนเองแทนการใช้ dropdown ของ Bootstrap เพราะของเดิมต้องมี JS ที่
   "แย่ง event" จาก Bootstrap ด้วย stopImmediatePropagation + capture phase
   (inc/navbar.php) ซึ่งเป็นอาการของการโหลด Bootstrap JS หลัง markup
   ตัวนี้ไม่พึ่ง framework จึงไม่มีการแย่ง event กัน                       */
.u-menu { position: relative; }
.u-menu__list {
  position: absolute; right: 0; top: calc(100% + 6px);
  z-index: 120;
  min-width: 232px;
  padding: var(--u-1);
  background: var(--u-surface);
  border: 1px solid var(--u-line);
  border-radius: var(--u-r-md);
  box-shadow: var(--u-shadow-lg);
}
.u-menu__list[hidden] { display: none; }
.u-menu__list a {
  display: block;
  padding: var(--u-2) var(--u-3);
  border-radius: var(--u-r-sm);
  color: var(--u-ink);
  font-size: var(--u-fs-md);
  font-weight: 600;
  text-decoration: none;
}
.u-menu__list a:hover { background: var(--u-surface-2); }
.u-menu__list a[aria-current="page"] { background: var(--u-brand-100); color: var(--u-brand-700); }
.u-menu__list hr { margin: var(--u-1) 0; }
.u-menu__danger { color: var(--u-danger-600) !important; }

@media (max-width: 900px) {
  /* ในเมนูมือถือที่กางออกมา ไม่ต้องลอย ให้ไหลตามปกติ */
  .u-menu__list { position: static; box-shadow: none; border: 0; padding: 0; min-width: 0; }
}

/* -- Bottom sheet (เมนู "เพิ่มเติม" บนมือถือ) ---------------------------- */
.u-sheet { position: fixed; inset: 0; z-index: 200; }
.u-sheet[hidden] { display: none; }
.u-sheet__backdrop { position: absolute; inset: 0; background: rgba(14, 47, 44, .5); }
.u-sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 78vh;
  display: flex; flex-direction: column;
  background: var(--u-surface);
  border-radius: var(--u-r-xl) var(--u-r-xl) 0 0;
  box-shadow: var(--u-shadow-lg);
  padding-bottom: env(safe-area-inset-bottom);
  animation: u-sheet-in .2s ease;
}
@keyframes u-sheet-in { from { transform: translateY(100%); } to { transform: none; } }
.u-sheet__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--u-4) var(--u-5);
  border-bottom: 1px solid var(--u-line);
}
.u-sheet__body { overflow-y: auto; padding: var(--u-2) var(--u-3) var(--u-5); }
.u-sheet__body a {
  display: block;
  padding: var(--u-3) var(--u-3);
  border-radius: var(--u-r-md);
  color: var(--u-ink);
  font-weight: 600;
  text-decoration: none;
}
.u-sheet__body a:hover, .u-sheet__body a:focus-visible { background: var(--u-surface-2); }
.u-sheet__danger { color: var(--u-danger-600) !important; }

/* ── 7. UTILITIES ────────────────────────────────────────────────────────── */

.u-sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.u-hide { display: none !important; }
@media (max-width: 900px)  { .u-hide-mobile  { display: none !important; } }
@media (min-width: 901px)  { .u-hide-desktop { display: none !important; } }

.u-text-center { text-align: center; }
.u-mt-0 { margin-top: 0 !important; }
.u-mb-0 { margin-bottom: 0 !important; }

/* ตัดข้อความหลายบรรทัด — ใช้กับชื่อคอร์ส/บทเรียนที่ยาวไม่เท่ากัน
   ทำให้การ์ดในกริดสูงเท่ากันโดยไม่ต้องกำหนดความสูงตายตัว */
.u-clamp-1, .u-clamp-2, .u-clamp-3 {
  display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden;
}
.u-clamp-1 { -webkit-line-clamp: 1; }
.u-clamp-2 { -webkit-line-clamp: 2; }
.u-clamp-3 { -webkit-line-clamp: 3; }

/* ── 8. MOTION & PRINT ───────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .u-header, .u-bottomnav, .u-footer, .u-skip, .u-navtoggle { display: none !important; }
  body { background: #fff; padding: 0; }
  .u-card { box-shadow: none; border-color: #999; break-inside: avoid; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .8em; color: #555; }
}
