/* assets/css/style.css - ธีมสไตล์ ThaiMOOC (โทนสีม่วง) — เวอร์ชันพรีเมียม */

:root {
    --brand-400: #818cf8;
    --brand-500: #6366f1;
    --brand-600: #4f46e5;
    --brand-700: #4338ca;
    --brand-800: #3730a3;
    --brand-50: #eef2ff;
    --brand-100: #e0e7ff;
    --brand-200: #c7d2fe;
    --violet-400: #a78bfa;

    /* ช่องสี R,G,B ดิบของสีแบรนด์ — จำเป็นเพราะ rgba() รับ var() เป็นก้อนสีไม่ได้
       ต้องแยกช่องไว้แบบนี้ ไม่งั้นทุกจุดที่ใช้สีแบรนด์แบบโปร่งแสง (เงา, focus ring,
       ripple, hover ในตาราง) จะค้างเป็นสีม่วงถาวรแม้เปลี่ยนธีมไปแล้ว */
    --brand-500-rgb: 99, 102, 241;
    --brand-600-rgb: 79, 70, 229;
    --violet-400-rgb: 167, 139, 250;

    /* ฟอนต์ — เดิมเขียน 'Kanit' ตรง ๆ สองที่ ทำให้เปลี่ยนฟอนต์ทั้งเว็บไม่ได้จากจุดเดียว */
    --font-sans: 'Kanit', system-ui, -apple-system, "Segoe UI", sans-serif;

    /* accent ของการ์ดสถิติสีม่วง — แยก token เพราะเป็นสีเสริม ไม่ใช่สีแบรนด์หลัก */
    /* สีแบรนด์แบบสว่าง สำหรับใช้เป็นสีตัวอักษรบนพื้นเข้มในโหมดมืด
       (ใช้ --brand-200 แทนไม่ได้ เพราะโหมดมืดมันกลับด้านเป็นสีเข้ม) */
    --brand-bright: #c7d2fe;

    --accent-violet: #7c3aed;
    --accent-violet-surface: #f5f3ff;

    --ink: #1b1f2a;
    --ink-soft: #5b6270;
    --ink-faint: #6b7280;   /* เข้มขึ้นเพื่อ contrast (AA) */
    --surface: #f5f6fb;
    --card: #ffffff;            /* พื้นผิวการ์ด/แถบเมนู — สลับค่าในโหมดมืด */
    --line: #e9eaf3;

    /* สีเชิงความหมาย — ก่อนหน้านี้ใช้โค้ดสีดิบกระจายอยู่ 6 ไฟล์และไม่มีเวอร์ชันโหมดมืด
       แต่ละชุดมี 3 ระดับ: สีหลัก / พื้นหลังอ่อน / เส้นขอบ */
    --success: #16a34a;  --success-surface: #ecfdf3;  --success-border: #bbf7d0;
    --warning: #d97706;  --warning-surface: #fffbeb;  --warning-border: #fde68a;
    --danger:  #dc2626;  --danger-surface:  #fef2f2;  --danger-border:  #fecaca;
    --info:    #0891b2;  --info-surface:    #ecfeff;  --info-border:    #a5f3fc;

    /* ความยาวบรรทัดที่อ่านสบาย — ภาษาไทยไม่มีช่องว่างระหว่างคำ บรรทัดยาวเกินจะหาที่ต่อยาก */
    --measure: 68ch;

    /* จังหวะการเคลื่อนไหว — เดิมมี 13 ความเร็วกระจัดกระจาย */
    --t-fast: .15s;
    --t-base: .22s;
    --t-slow: .4s;
    --ease-out: cubic-bezier(.22, .61, .36, 1);

    /* วงแหวนโฟกัส — เดิมมี 10 สูตรไม่ซ้ำกันเลย */
    --focus-ring: 0 0 0 3px rgba(var(--brand-500-rgb), .42);
    --radius-xl: 20px;
    --radius-lg: 15px;
    --radius-md: 11px;
    --radius-sm: 8px;
    --shadow-xs: 0 1px 2px rgba(17, 24, 39, 0.05);
    --shadow-sm: 0 2px 8px rgba(17, 24, 39, 0.06);
    --shadow-md: 0 8px 24px rgba(17, 24, 39, 0.07);
    --shadow-brand: 0 12px 28px rgba(var(--brand-600-rgb), 0.15);
    --grad-brand: linear-gradient(135deg, var(--brand-500), var(--brand-800));
    --grad-brand-soft: linear-gradient(135deg, var(--brand-400), var(--brand-700));
}

/* สเกลฐานของทั้งเว็บ: 15px ทำให้ทุกองค์ประกอบกระชับพอดีตา (Bootstrap ใช้ rem ทั้งหมด) */
html { font-size: 15px; }
html, body { height: 100%; }

/* คุมความกว้างสูงสุดไม่ให้คอนเทนต์ยืดเกินบนจอใหญ่ */
@media (min-width: 1200px) {
    .container, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl { max-width: 1120px; }
    /* ฝั่ง admin: กระชับกว่า (ตาราง/แดชบอร์ดไม่ยืดเต็มจอจนเซลล์โล่ง) */
    .is-admin main > .container { max-width: 1000px; }
    /* ยกเว้นหน้าที่มีเมนูด้านข้าง — ต้องกว้างขึ้นเพราะ sidebar กินไป 236px */
    .is-admin main > .container.admin-shell { max-width: 1264px; }
}

/* Type scale กลาง — หัวข้อทุกหน้าขนาดสม่ำเสมอ พอดีตา (คอมโพเนนต์ที่กำหนดขนาดเองจะชนะ selector นี้) */
h1, .h1 { font-size: 1.8rem; }
h2, .h2 { font-size: 1.45rem; }
h3, .h3 { font-size: 1.28rem; }
h4, .h4 { font-size: 1.12rem; }
h5, .h5 { font-size: 1.02rem; }
h6, .h6 { font-size: .92rem; }

/* หัวข้อ: ไม่บีบระยะห่างตัวอักษร (letter-spacing ติดลบเป็นเทคนิคของภาษาละติน
   พอใช้กับภาษาไทยแล้ววรรณยุกต์กับสระบนจะเบียดชนตัวข้างเคียง) */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0;
    text-wrap: pretty;          /* เบราว์เซอร์ที่รองรับจะไม่ปล่อยคำเดียวค้างบรรทัดสุดท้าย */
}

/* ความยาวบรรทัดของเนื้อความ — ใช้กับย่อหน้าที่เป็นคำอธิบายยาว ๆ */
.measure { max-width: var(--measure); }

/* ภาษาไทยไม่มีช่องว่างระหว่างคำ การตัดบรรทัดจึงพึ่งพจนานุกรมของเบราว์เซอร์ล้วน
   (Chrome ทำได้ดี แต่ Firefox/Safari อ่อนกว่า) จุดที่ช่องแคบต้องกันข้อความล้นไว้ */
.course-card__title,
.admin-nav__link span { overflow-wrap: anywhere; }
/* ตาราง: เดิมใช้ anywhere ด้วย ทำให้เบราว์เซอร์ตัดคำไทยได้ทุกตัวอักษร คอลัมน์จึงหดจนหัวตารางขาดกลางคำ
   ("ห้องเรีย/น") และบนมือถือเหลือบรรทัดละ 1–2 ตัวอักษร — หัวตารางห้ามตัด ส่วนเนื้อตัดเฉพาะเมื่อคำยาวเกินช่องจริง ๆ */
.table th { white-space: nowrap; }
.table td { overflow-wrap: break-word; }

body {
    background:
        radial-gradient(1200px 500px at 100% -10%, rgba(var(--brand-500-rgb), 0.07), transparent 60%),
        radial-gradient(900px 500px at -10% 0%, rgba(var(--violet-400-rgb), 0.06), transparent 55%),
        var(--surface);
    /* แสงไล่สีมุมบนวาดครั้งเดียว — เดิมพื้นหลังสูงเท่า 1 จอ (html/body height:100%) แล้ววาดซ้ำทุก 1 จอ
       บนมือถือรอยต่อจึงเป็นเส้นตัดกลางเนื้อหา (เช่น ผ่ากลางวงกลมขั้นตอนที่ 3 ในหน้าแรก) */
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;

    /* จังหวะบรรทัดสำหรับภาษาไทย
       เดิมไม่ได้ตั้งค่าไว้เลย จึงตกไปใช้ 1.5 ของ Bootstrap ซึ่งทำมาเพื่อภาษาอังกฤษ
       ภาษาไทยซ้อนสระบน + วรรณยุกต์ได้ 2 ชั้นเหนือเส้นฐาน ที่ 1.5 วรรณยุกต์เกือบชนบรรทัดบน */
    line-height: 1.7;
}

body > main { flex: 1 0 auto; }
body > footer { flex-shrink: 0; }

::selection { background: var(--brand-100); color: var(--brand-800); }

/* ===== Navbar ===== */
.site-navbar {
    background: var(--card);   /* พื้นทึบแทน frosted glass — เลี่ยง backdrop blur ที่ทำให้เลื่อนแลค */
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset, 0 2px 12px rgba(17, 24, 39, 0.05);
    padding-top: .5rem;
    padding-bottom: .5rem;
    z-index: 1030;
}

.site-navbar .navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    font-weight: 600;
    color: var(--brand-800);
}
/* โหมดมืด: --brand-800 เป็นสีเข้มสุดของแบรนด์ วางบนแถบสีเข้มแล้วแทบมองไม่เห็น
   (ธีมม่วงเดิมได้ contrast แค่ 1.75:1 ซึ่งตกเกณฑ์ AA) — ใช้สีตัวอักษรปกติแทน */
[data-bs-theme="dark"] .site-navbar .navbar-brand { color: var(--ink); }

/* โลโก้ (หมวก+จอ+หนังสือ) — พื้นเข้ม (โหมดมืด/ท้ายเว็บ) ใช้ไฟล์ที่เปลี่ยนน้ำเงินเข้มเป็นสีอ่อน ไม่งั้นกลืนหายไปกับพื้น */
.brand-mark {
    display: inline-block;
    flex-shrink: 0;
    width: 44px;
    height: 36px;
    background: url("../img/logo-mark.png") center / contain no-repeat;
}
[data-bs-theme="dark"] .brand-mark,
.footer-brand .brand-mark { background-image: url("../img/logo-mark-dark.png"); }

.brand-text { line-height: 1; font-size: 1.05rem; letter-spacing: .2px; }
.brand-text small {
    display: block;
    font-size: .66rem;
    font-weight: 500;
    color: var(--ink-faint);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-top: 3px;
}

.site-navbar .nav-link {
    position: relative;
    color: var(--ink-soft);
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: .45rem .9rem;
    transition: color .15s ease, background-color .15s ease;
}
.site-navbar .nav-link:hover,
.site-navbar .nav-link:focus {
    color: var(--brand-700);
    background-color: var(--brand-50);
}
.site-navbar .navbar-toggler { border-color: var(--line); }
.site-navbar .navbar-toggler:focus { box-shadow: 0 0 0 .2rem rgba(var(--brand-500-rgb),.18); }

/* ปุ่มเข้าสู่ระบบ/สมัครสมาชิก (ผู้ที่ยังไม่ได้เข้าสู่ระบบ) */
.site-navbar .nav-auth { display: flex; align-items: center; gap: .4rem; }

/* เมนูตอนพับบนจอเล็ก: เดิมปุ่มธีมอยู่โดด ๆ ลิงก์กับปุ่มไม่ตรงแนว ปุ่มเล็กเบียดกัน
   → ปุ่มธีมย้ายไปข้างปุ่มเมนู ลิงก์เป็นแถวกดง่าย ปุ่มบัญชีกว้างเท่ากันสองช่อง */
@media (max-width: 991.98px) {
    .site-navbar .navbar-collapse {
        margin-top: .55rem;
        padding-top: .45rem;
        border-top: 1px solid var(--line);
    }
    .site-navbar .navbar-nav { gap: .1rem; padding-bottom: .4rem; }
    .site-navbar .navbar-nav .nav-link { padding: .7rem .8rem; font-size: 1.02rem; }
    .site-navbar .nav-auth {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: .6rem;
        margin-top: .45rem;
    }
    .site-navbar .nav-auth .btn { padding: .6rem 1rem; font-size: .98rem; }
}

.nav-user { display: inline-flex !important; align-items: center; gap: .55rem; }
.nav-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--grad-brand-soft);
    color: #fff;
    font-weight: 600;
    font-size: .9rem;
    box-shadow: var(--shadow-xs);
}
.dropdown-menu {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: .4rem;
}
.dropdown-item { border-radius: var(--radius-sm); padding: .5rem .75rem; font-weight: 500; }
.dropdown-item:active { background: var(--brand-600); }

/* ===== Hero ===== */
.hero {
    position: relative;
    overflow: hidden;
    background: var(--grad-brand);
    color: #fff;
}
.hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(600px 300px at 85% 10%, rgba(255,255,255,.18), transparent 60%),
        radial-gradient(500px 350px at 10% 90%, rgba(var(--violet-400-rgb),.35), transparent 60%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M0 39h40M39 0v40' fill='none' stroke='%23ffffff' stroke-opacity='0.06' stroke-width='1'/%3E%3C/svg%3E");
    pointer-events: none;
}
.hero__inner {
    position: relative;
    padding: 3.25rem 0 4.5rem;
}
.hero .eyebrow {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.22);
    color: #fff;
    font-size: .82rem;
    font-weight: 500;
    padding: .35rem .85rem;
    border-radius: 999px;
    margin-bottom: 1.25rem;
}
.hero h1 {
    font-weight: 700;
    font-size: clamp(1.6rem, 3.2vw, 2.35rem);
    /* ไทยต้องการบรรทัดสูงกว่าอังกฤษ เพราะซ้อนสระบน + วรรณยุกต์สองชั้น
       และไม่ใส่ letter-spacing ติดลบ เพราะทำให้วรรณยุกต์เบียดตัวอักษรข้าง ๆ */
    line-height: 1.32;
}
.hero p.lead {
    color: rgba(255, 255, 255, .9);
    font-size: 1rem;
    font-weight: 300;
    max-width: 520px;
}
.btn-hero {
    background: #fff;
    color: var(--brand-700);
    font-weight: 600;
    border: none;
    padding: .6rem 1.4rem;
    box-shadow: 0 8px 18px rgba(0,0,0,.15);
    transition: transform .15s ease, box-shadow .15s ease;
}
.btn-hero:hover { transform: translateY(-2px); box-shadow: 0 12px 24px rgba(0,0,0,.2); color: var(--brand-800); }
.btn-ghost {
    background: rgba(255,255,255,.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,.35);
    font-weight: 500;
    padding: .6rem 1.25rem;
    transition: background .15s ease;
}
.btn-ghost:hover { background: rgba(255,255,255,.2); color: #fff; }

.hero-stats { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.9rem; }
.hero-stats .stat {
    background: rgba(255,255,255,.14);
    border: 1px solid rgba(255,255,255,.16);
    border-radius: var(--radius-md);
    padding: .65rem 1rem;
    min-width: 104px;
}
.hero-stats .num { font-size: 1.45rem; font-weight: 700; line-height: 1; }
.hero-stats .lbl { font-size: .78rem; color: rgba(255, 255, 255, .82); margin-top: .3rem; }

/* ภาพประกอบฝั่งขวาของฮีโร่ */
.hero-illustration { position: relative; max-width: 440px; margin-left: auto; }
.hero-illustration svg { width: 100%; height: auto; filter: drop-shadow(0 16px 32px rgba(0,0,0,.22)); }

/* เส้นโค้งด้านล่างฮีโร่ */
.hero__wave { position: absolute; left: 0; right: 0; bottom: -1px; line-height: 0; }
.hero__wave svg { width: 100%; height: 60px; display: block; }

/* ===== Section headings ===== */
.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.35rem;
}
.section-head h2 {
    font-weight: 700;
    font-size: clamp(1.25rem, 2vw, 1.5rem);
    margin: 0;
    letter-spacing: -.3px;
}
.section-head .eyebrow-line {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    color: var(--brand-600);
    font-weight: 600;
    font-size: .85rem;
    letter-spacing: .5px;
    text-transform: uppercase;
    margin-bottom: .4rem;
}
.section-head .eyebrow-line::before {
    content: "";
    width: 26px; height: 3px; border-radius: 3px;
    background: var(--grad-brand);
}
.section-head .sub { color: var(--ink-soft); margin: .35rem 0 0; }

/* ===== Course card ===== */
.course-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.course-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-brand);
    border-color: var(--brand-100);
}

.course-card__cover {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--brand-50);
    overflow: hidden;
}
.course-card__cover img {
    width: 100%; height: 100%;
    object-fit: cover; display: block;
    transition: transform .4s ease;
}
.course-card:hover .course-card__cover img { transform: scale(1.06); }
.course-card__overlay {
    position: absolute; inset: 0;
    background: linear-gradient(180deg, transparent 55%, rgba(20, 20, 43, .35));
    pointer-events: none;
}
.course-card__cover--placeholder {
    display: flex; align-items: center; justify-content: center;
    background: var(--grad-brand);
}
.course-card__cover--placeholder::before {
    content: "";
    position: absolute; inset: 0;
    background:
        radial-gradient(120px 120px at 78% 22%, rgba(255,255,255,.22), transparent 60%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30'%3E%3Cpath d='M0 29h30M29 0v30' fill='none' stroke='%23ffffff' stroke-opacity='0.08'/%3E%3C/svg%3E");
}
.course-card__initial {
    position: relative;
    color: rgba(255, 255, 255, .95);
    font-size: 3.4rem;
    font-weight: 700;
    text-shadow: 0 4px 16px rgba(0,0,0,.2);
}

.course-card__badge {
    position: absolute;
    top: .75rem; left: .75rem;
    background: #fff;
    color: var(--brand-700);
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .3px;
    padding: .3em .8em;
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    z-index: 2;
}
.course-card__tag {
    position: absolute;
    top: .75rem; right: .75rem;
    background: rgba(255, 255, 255, .96);
    color: var(--brand-700);
    font-size: .74rem;
    font-weight: 600;
    padding: .3em .8em;
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    z-index: 2;
}
.course-card__tag--muted { background: rgba(20, 20, 43, .78); color: #fff; }

.course-card__body {
    display: flex; flex-direction: column; flex: 1 1 auto;
    padding: 1rem 1.05rem 1.1rem;
}
.course-card__title {
    font-weight: 600;
    font-size: 1rem;
    line-height: 1.4;
    margin: 0 0 .5rem;
    color: var(--ink);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.course-card__desc {
    color: var(--ink-soft);
    font-size: .88rem;
    line-height: 1.55;
    margin: 0 0 .85rem;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.course-card__meta {
    display: flex; flex-direction: column; gap: .4rem;
    padding: .75rem 0 .9rem;
    margin-top: auto;
    border-top: 1px dashed var(--line);
    color: var(--ink-soft);
    font-size: .85rem;
}
.course-card__meta .meta-item { display: inline-flex; align-items: center; gap: .5rem; }
.course-card__meta .meta-item svg { color: var(--brand-500); flex-shrink: 0; }

.course-card .btn { padding: .6rem 1rem; }

/* หมวดหมู่ + ผู้สอน/หน่วยงาน */
.course-cat {
    display: inline-block; align-self: flex-start;
    background: var(--brand-50); color: var(--brand-700);
    font-size: .72rem; font-weight: 600; letter-spacing: .2px;
    padding: .22em .7em; border-radius: 999px; margin-bottom: .5rem;
}
.course-by {
    display: flex; align-items: center; gap: .35rem;
    color: var(--ink-faint); font-size: .82rem; margin: -.1rem 0 .6rem;
}
.course-by i { color: var(--brand-400); flex-shrink: 0; }

/* ===== Buttons ===== */
.btn { border-radius: var(--radius-sm); font-weight: 500; }
.btn-primary {
    background: var(--grad-brand);
    border: none;
    box-shadow: 0 8px 18px rgba(var(--brand-600-rgb), 0.22);
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.btn-primary:hover, .btn-primary:focus {
    filter: brightness(1.05);
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(var(--brand-600-rgb), 0.3);
}
.btn-outline-primary { color: var(--brand-600); border-color: var(--brand-400); }
.btn-outline-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-warning { font-weight: 600; }

/* ===== Cards ทั่วไป ===== */
.card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

/* ===== Forms ===== */
.form-control, .form-select { border-radius: var(--radius-sm); border-color: #e2e4ec; padding: .55rem .8rem; }
/* select ต้องเผื่อที่ด้านขวาให้ลูกศร — padding บรรทัดบนทับค่าของ Bootstrap (2.25rem) ไปด้วย
   ลูกศรจึงชนตัวหนังสือทุกช่อง เห็นชัดตอนช่องกว้างพอดีข้อความ (เช่น หน้าพื้นที่จัดเก็บ) */
.form-select {
    padding-right: 2.6rem;
    background-position: right .85rem center;
    background-size: 14px 10px;
    cursor: pointer;
}
/* ตัวเล็กใช้กับตัวกรองเหนือตาราง — ต้องประกาศหลัง .form-select ไม่งั้นโดน padding ตัวใหญ่ทับ */
.form-select-sm {
    padding: .35rem 2.2rem .35rem .7rem;
    background-position: right .65rem center;
    background-size: 12px 9px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 .2rem rgba(var(--brand-500-rgb), .16);
}
.form-label { font-weight: 500; }

/* ===== Alerts =====
   ใช้ 21 จุดทั่วเว็บ (รวม render_flash() ที่แสดงเกือบทุกหน้า) แต่เดิมเป็นสีพาสเทล
   มาตรฐานของ Bootstrap ล้วน ซึ่งขัดกับภาษาการออกแบบการ์ดของเรา
   ทำใหม่เป็นการ์ดพื้นอ่อน + แถบสีด้านซ้าย ใช้ token สีเชิงความหมาย */
.alert {
    border: 1px solid transparent;
    border-left-width: 4px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    padding: .85rem 1rem;
}
.alert-success { background: var(--success-surface); border-color: var(--success-border); border-left-color: var(--success); color: var(--ink); }
.alert-danger  { background: var(--danger-surface);  border-color: var(--danger-border);  border-left-color: var(--danger);  color: var(--ink); }
.alert-warning { background: var(--warning-surface); border-color: var(--warning-border); border-left-color: var(--warning); color: var(--ink); }
.alert-info    { background: var(--info-surface);    border-color: var(--info-border);    border-left-color: var(--info);    color: var(--ink); }
.alert-secondary { background: var(--surface); border-color: var(--line); border-left-color: var(--brand-400); color: var(--ink-soft); }
.alert-success .bi { color: var(--success); }
.alert-danger  .bi { color: var(--danger); }
.alert-warning .bi { color: var(--warning); }
.alert-info    .bi { color: var(--info); }

/* ===== Badges / ป้ายสถานะ ===== */
.badge { border-radius: 999px; font-weight: 500; padding: .45em .8em; }

/* ป้ายสถานะแบบมีจุดสีนำหน้า — อ่านง่ายกว่าป้ายทึบเวลามีหลายอันในตารางเดียวกัน */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .28rem .7rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-soft);
    font-size: .8rem;
    font-weight: 500;
    white-space: nowrap;
}
.status-pill::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}
.status-pill--success { background: var(--success-surface); border-color: var(--success-border); color: var(--success); }
.status-pill--danger  { background: var(--danger-surface);  border-color: var(--danger-border);  color: var(--danger); }
.status-pill--warning { background: var(--warning-surface); border-color: var(--warning-border); color: var(--warning); }
.status-pill--info    { background: var(--info-surface);    border-color: var(--info-border);    color: var(--info); }
.status-pill--brand   { background: var(--brand-50);        border-color: var(--brand-200);      color: var(--brand-700); }

/* ===== Tables ===== */
.table { --bs-table-hover-bg: var(--brand-50); }
.table thead th {
    text-transform: uppercase;
    font-size: .74rem;
    letter-spacing: .4px;
    color: var(--ink-faint);
    border-bottom-width: 1px;
}

/* ===== Stat tiles (การ์ดสถิติ) =====
   เดิมมี CSS แค่ 3 บรรทัด — ไม่มีไอคอน ไม่มีสีแยกความหมาย
   ทั้งที่เป็นสิ่งแรกที่แอดมินเห็นตอนเปิดระบบ
   ตัวแปร --accent ตั้งจากคลาส .stat-tile--* ด้านล่าง */
.stat-tile {
    --accent: var(--brand-600);
    --accent-surface: var(--brand-50);
    position: relative;
    overflow: hidden;
    transition: transform var(--t-base) var(--ease-out), box-shadow var(--t-base) var(--ease-out);
}
.stat-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-brand); }

/* แถบสีบาง ๆ ด้านบนการ์ด บอกประเภทของตัวเลขโดยไม่ต้องอ่าน */
.stat-tile::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--accent);
}

.stat-tile .card-body { display: flex; align-items: flex-start; gap: .85rem; }

.stat-tile__icon {
    flex-shrink: 0;
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border-radius: var(--radius-md);
    background: var(--accent-surface);
    color: var(--accent);
    font-size: 1.25rem;
}
.stat-tile__body { min-width: 0; }
.stat-tile__label { color: var(--ink-soft); font-size: .85rem; line-height: 1.4; }
.stat-tile__value {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--accent);
    /* ตัวเลขความกว้างคงที่ ไม่งั้นเลขจะกระตุกซ้าย-ขวาตอนวิ่ง count-up */
    font-variant-numeric: tabular-nums;
}
.stat-tile__hint { color: var(--ink-faint); font-size: .75rem; line-height: 1.5; }

.stat-tile--brand   { --accent: var(--brand-600); --accent-surface: var(--brand-50); }
.stat-tile--violet  { --accent: var(--accent-violet); --accent-surface: var(--accent-violet-surface); }
.stat-tile--success { --accent: var(--success); --accent-surface: var(--success-surface); }
.stat-tile--danger  { --accent: var(--danger);  --accent-surface: var(--danger-surface); }
.stat-tile--warning { --accent: var(--warning); --accent-surface: var(--warning-surface); }

/* ===== หัวข้อหน้า (ใช้ร่วมทุกหน้า) =====
   เดิมมี 4 แพตเทิร์นหัวข้อแข่งกันเอง — .section-head, .training-head,
   <h3> เปล่า ๆ และ flex row เฉพาะกิจ */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem 1rem;
    margin-bottom: 1.5rem;
}
.page-head__main { display: flex; align-items: flex-start; gap: .8rem; min-width: 0; }
.page-head__icon {
    flex-shrink: 0;
    width: 42px; height: 42px;
    display: grid; place-items: center;
    border-radius: var(--radius-md);
    background: var(--brand-50);
    color: var(--brand-600);
    font-size: 1.2rem;
}
.page-head__title { font-size: 1.32rem; font-weight: 600; margin: 0; }
.page-head__sub { color: var(--ink-soft); font-size: .88rem; margin: .15rem 0 0; max-width: var(--measure); }
.page-head__actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* ===== เปลือกครอบตาราง =====
   ทั้ง 7 ตารางในเว็บเดิมเป็น table-striped ลอย ๆ ไม่มีอะไรครอบ */
.data-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: .35rem 1.15rem 1rem;
}
.data-card .table { margin-bottom: 0; }
.data-card .table > :not(caption) > * > * { padding: .7rem .5rem; }
.data-card .table td.num, .data-card .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ===== Video player ===== */
#trainingVideo { width: 100%; background: #000; border-radius: var(--radius-md); }

/* ===== Footer (3 คอลัมน์กระชับ) ===== */
.site-footer {
    background: #12122a;
    color: rgba(255, 255, 255, .68);
    padding: 1.9rem 0 1.15rem;
    margin-top: 2.75rem;
    position: relative;
}
.site-footer::before {
    content: "";
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--grad-brand-soft);
}
.footer-brand {
    display: inline-flex; align-items: center; gap: .55rem;
    text-decoration: none; color: #fff; margin-bottom: .55rem;
}
.footer-brand .brand-text small { color: rgba(255, 255, 255, .5); }
.footer-desc { font-size: .85rem; line-height: 1.6; max-width: 300px; margin: 0; color: rgba(255, 255, 255, .6); }
.footer-heading { color: #fff; font-weight: 600; font-size: .9rem; margin-bottom: .65rem; }
.footer-links { list-style: none; padding: 0; margin: 0; }
.footer-links li { margin-bottom: .4rem; font-size: .88rem; }
.footer-links a { color: rgba(255, 255, 255, .68); text-decoration: none; transition: color .15s ease; }
.footer-links a:hover { color: #fff; }
.footer-social { display: flex; gap: .45rem; }
.footer-social a {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 9px;
    background: rgba(255, 255, 255, .08);
    color: #fff; font-size: .98rem; text-decoration: none;
    transition: background .15s ease, transform .15s ease;
}
.footer-social a:hover { background: var(--brand-600); transform: translateY(-2px); }
.footer-divider { border-color: rgba(255, 255, 255, .1); margin: 1.35rem 0 1rem; }
.footer-bottom { text-align: center; font-size: .8rem; color: rgba(255, 255, 255, .45); }

/* ===== Auth cards (login/register/profile) ===== */
.card-body h4.card-title { font-weight: 600; color: var(--brand-800); }

/* ===== Fade-in ===== */
@media (prefers-reduced-motion: no-preference) {
    [data-aos] { will-change: transform, opacity; }
}

/* ===== ลูกเล่น / Interactions ===== */
html { scroll-behavior: smooth; }

/* ฮีโร่ไล่สีเคลื่อนไหวช้า ๆ + ภาพประกอบลอยขึ้นลง */
/* hero ใช้ gradient นิ่ง — ตัด animation heroPan (background-position วนไม่หยุด) ที่ทำให้ repaint ทุกเฟรม = กระตุก */
.hero-illustration { animation: floaty 6s ease-in-out infinite; }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }

/* navbar ทึบขึ้นเมื่อเลื่อนหน้า */
.site-navbar.scrolled {
    background: var(--card);
    box-shadow: 0 6px 24px rgba(17, 24, 39, 0.09);
}

/* ปุ่มกลับขึ้นบนสุด */
.to-top {
    position: fixed; right: 20px; bottom: 20px; z-index: 1040;
    width: 46px; height: 46px; border-radius: 50%;
    border: none; color: #fff; background: var(--grad-brand);
    box-shadow: var(--shadow-brand);
    display: grid; place-items: center; font-size: 1.2rem; cursor: pointer;
    opacity: 0; visibility: hidden; transform: translateY(12px);
    transition: opacity .25s ease, transform .25s ease, visibility .25s;
}
.to-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
.to-top:hover { filter: brightness(1.08); transform: translateY(-2px); }

/* ปุ่ม: ripple ตอนกด + กดหดเล็กน้อย */
.btn { position: relative; overflow: hidden; }
.btn:active { transform: translateY(0) scale(.98); }
.ripple {
    position: absolute; border-radius: 50%; transform: scale(0);
    background: rgba(255, 255, 255, .55);
    pointer-events: none; animation: rippleGo .6s ease-out;
}
@keyframes rippleGo { to { transform: scale(2.5); opacity: 0; } }
.btn-outline-primary .ripple, .btn-outline-secondary .ripple,
.btn-outline-success .ripple, .btn-outline-danger .ripple,
.btn-outline-info .ripple, .btn-light .ripple { background: rgba(var(--brand-500-rgb), .26); }

/* เมนู navbar: เส้นใต้ไล่สีวิ่งตอน hover */
.site-navbar .nav-link { position: relative; }
.site-navbar .nav-link::after {
    content: ""; position: absolute; left: .9rem; right: .9rem; bottom: .22rem;
    height: 2px; border-radius: 2px; background: var(--grad-brand);
    transform: scaleX(0); transform-origin: left; transition: transform .22s ease;
}
@media (hover: hover) and (min-width: 992px) {
    .site-navbar .nav-link:hover::after { transform: scaleX(1); }
}

/* แถบโหลดด้านบนตอนเปลี่ยนหน้า */
#topbar {
    position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 2000;
    background: var(--grad-brand-soft);
    box-shadow: 0 0 8px rgba(var(--brand-500-rgb), .7);
    opacity: 0; transition: width .25s ease, opacity .3s ease;
}
#topbar.active { opacity: 1; }

/* progress bar วิ่งนุ่ม + แถวตารางไล่สีตอน hover */
.progress-bar { transition: width 1s cubic-bezier(.22, .61, .36, 1); }
.table tbody tr { transition: background-color .15s ease; }

/* ===== เครื่องเล่นวิดีโอ custom (ตัวจับเวลา admin) ===== */
.player {
    position: relative;
    max-width: 640px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
    box-shadow: var(--shadow-md);
    outline: none;
}
.player:focus-visible { box-shadow: 0 0 0 .2rem rgba(var(--brand-500-rgb),.4), var(--shadow-md); }
.player__stage { position: relative; line-height: 0; }
.player__stage video {
    display: block;
    width: 100%;
    max-height: 360px;
    background: #000;
    cursor: pointer;
}

/* ฟอร์มแอดมินให้กว้างพอดีตา ไม่ยืดเต็มจอ */
.form-narrow { max-width: 820px; }

/* ===== หน้าอบรม (ผู้เรียนดูวิดีโอ) ===== */
.training-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem; margin-bottom: 1.1rem; }
.training-head h3 { margin: 0; }
.training-meta { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; color: var(--ink-soft); font-size: .88rem; margin-top: .3rem; }
.training-meta i { color: var(--brand-500); }

.player-shell {
    background: radial-gradient(130% 130% at 50% 0%, #26264a, #0f0f22);
    border-radius: var(--radius-lg);
    padding: 12px;
    box-shadow: var(--shadow-md);
}
.player-shell .ratio { border-radius: var(--radius-md); overflow: hidden; background: #000; }

.training-note, .quiz-progress {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius-md); padding: 1rem 1.15rem; height: 100%;
    box-shadow: var(--shadow-sm);
}
.training-note ul { margin: 0; padding-left: 1.15rem; color: var(--ink-soft); font-size: .9rem; line-height: 1.75; }

.checkpoints { display: flex; flex-wrap: wrap; gap: .4rem; }
.checkpoint {
    width: 30px; height: 30px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .82rem; font-weight: 600;
    border: 1px solid var(--line); background: var(--card); color: var(--ink-faint);
    transition: transform .15s ease;
}
.checkpoint:hover { transform: translateY(-2px); }
.checkpoint.done {
    background: linear-gradient(135deg, #22c55e, #15803d);
    border: 0; color: #fff; box-shadow: 0 3px 8px rgba(21, 128, 61, .28);
}

/* ===== เครื่องเล่นวิดีโอฝั่งผู้เรียน (custom — คงกฎห้ามข้าม) ===== */
.tr-player { position: relative; border-radius: var(--radius-md); overflow: hidden; }
.tr-player video { display: block; width: 100%; height: 100%; background: #000; cursor: pointer; }
.tr-bigplay {
    position: absolute; inset: 0; margin: auto; width: 68px; height: 68px;
    border: 0; border-radius: 50%; background: rgba(var(--brand-600-rgb), .92); color: #fff;
    font-size: 1.8rem; display: grid; place-items: center; cursor: pointer; z-index: 4;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .45); transition: opacity .2s ease, transform .2s ease;
}
.tr-bigplay:hover { transform: scale(1.06); background: var(--brand-600); }
.tr-controls {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
    padding: 26px 12px 10px;
    background: linear-gradient(transparent, rgba(0, 0, 0, .72));
}
.tr-seek { position: relative; height: 16px; display: flex; align-items: center; cursor: pointer; }
.tr-seek::before { content: ""; position: absolute; left: 0; right: 0; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .25); }
.tr-allowed { position: absolute; left: 0; height: 5px; width: 0; border-radius: 3px; background: rgba(255, 255, 255, .42); }
.tr-played  { position: absolute; left: 0; height: 5px; width: 0; border-radius: 3px; background: var(--grad-brand-soft); }
.tr-handle {
    position: absolute; left: 0; top: 50%; width: 14px; height: 14px; margin-left: -7px;
    border-radius: 50%; background: #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .5);
    transform: translateY(-50%); transition: transform .1s ease;
}
.tr-seek:hover .tr-handle { transform: translateY(-50%) scale(1.18); }
.tr-row { display: flex; align-items: center; gap: .3rem; margin-top: .45rem; color: #fff; }
.tr-btn {
    background: transparent; border: 0; color: #fff; width: 34px; height: 34px; border-radius: 8px;
    display: inline-grid; place-items: center; cursor: pointer; font-size: 1.05rem; transition: background .15s ease;
}
.tr-btn:hover { background: rgba(255, 255, 255, .18); }
.tr-time { font-size: .85rem; margin-left: .4rem; font-variant-numeric: tabular-nums; }
.tr-row .tr-spacer { flex: 1; }

/* ปรับระดับเสียง */
.tr-vol { display: flex; align-items: center; gap: .15rem; }
.tr-vol-slider {
    -webkit-appearance: none; appearance: none;
    width: 72px; height: 4px; border-radius: 3px;
    background: rgba(255, 255, 255, .35); cursor: pointer; outline: none;
}
.tr-vol-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 12px; height: 12px; border-radius: 50%; background: #fff; cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
.tr-vol-slider::-moz-range-thumb {
    width: 12px; height: 12px; border: 0; border-radius: 50%; background: #fff; cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
.tr-vol-slider:focus-visible { box-shadow: 0 0 0 .18rem rgba(var(--brand-500-rgb), .5); }
@media (max-width: 575.98px) { .tr-vol-slider { width: 54px; } }

/* ===== หน้ารายละเอียดหลักสูตร ===== */
.breadcrumb-item + .breadcrumb-item::before { color: var(--ink-faint); }
.breadcrumb-item a { color: var(--brand-600); text-decoration: none; }
.breadcrumb-item a:hover { text-decoration: underline; }

.course-detail-cover .course-card__cover {
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}
.course-detail-desc { color: var(--ink-soft); line-height: 1.85; font-size: .98rem; }

.enroll-card { border: 1px solid var(--line); box-shadow: var(--shadow-md); }
@media (min-width: 992px) { .enroll-card { position: sticky; top: 82px; } }
.meta-list { list-style: none; margin: 0 0 1.1rem; padding: 0; }
.meta-list li {
    display: flex; align-items: center; gap: .65rem;
    padding: .6rem 0; border-bottom: 1px dashed var(--line);
    font-size: .92rem; color: var(--ink-soft);
}
.meta-list li:last-child { border-bottom: 0; }
.meta-list li i { color: var(--brand-500); width: 20px; text-align: center; }
.meta-list li b { margin-left: auto; color: var(--ink); }

/* ===== แถบค้นหา/กรอง (หน้าหลักสูตร) ===== */
.course-toolbar { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: center; margin-bottom: 1.5rem; }
.course-search { position: relative; flex: 1 1 260px; max-width: 380px; }
.course-search i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--ink-faint); }
.course-search input { padding-left: 2.3rem; border-radius: 999px; }
.filter-chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.filter-label { font-size: .82rem; color: var(--ink-faint); font-weight: 500; margin-right: .15rem; }
.filter-chip {
    border: 1px solid var(--line); background: var(--card); color: var(--ink-soft);
    border-radius: 999px; padding: .35rem .9rem; font-size: .85rem; font-weight: 500;
    cursor: pointer; transition: all .15s ease;
}
.filter-chip:hover { border-color: var(--brand-400); color: var(--brand-600); }
.filter-chip.active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.no-results { text-align: center; color: var(--ink-soft); padding: 2.5rem 1rem; }
.no-results i { font-size: 2.5rem; color: var(--brand-200); display: block; margin-bottom: .5rem; }
.player__bigplay {
    position: absolute; inset: 0; margin: auto;
    width: 74px; height: 74px;
    border: none; border-radius: 50%;
    background: rgba(var(--brand-600-rgb), .92); color: #fff;
    font-size: 2rem; display: grid; place-items: center;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .45);
    cursor: pointer; transition: opacity .2s ease, transform .2s ease;
}
.player__bigplay:hover { transform: scale(1.07); background: var(--brand-600); }

.player__controls {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 30px 12px 10px;
    background: linear-gradient(transparent, rgba(0, 0, 0, .7));
    opacity: 0; transition: opacity .2s ease;
}
.player:hover .player__controls,
.player.paused .player__controls,
.player:focus-within .player__controls { opacity: 1; }

.player__seek { position: relative; height: 16px; display: flex; align-items: center; cursor: pointer; }
.player__seek::before {
    content: ""; position: absolute; left: 0; right: 0; height: 5px;
    border-radius: 3px; background: rgba(255, 255, 255, .25);
}
.player__buffered { position: absolute; left: 0; height: 5px; width: 0; border-radius: 3px; background: rgba(255, 255, 255, .35); }
.player__played   { position: absolute; left: 0; height: 5px; width: 0; border-radius: 3px; background: var(--grad-brand-soft); }
.player__handle {
    position: absolute; left: 0; top: 50%;
    width: 14px; height: 14px; margin-left: -7px;
    border-radius: 50%; background: #fff;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .5);
    transform: translateY(-50%); transition: transform .1s ease;
}
.player__seek:hover .player__handle { transform: translateY(-50%) scale(1.18); }

.player__markers { position: absolute; left: 0; right: 0; top: 0; height: 100%; pointer-events: none; }
.player__marker { position: absolute; top: 50%; width: 3px; height: 15px; transform: translate(-50%, -50%); border-radius: 2px; display: none; }
.player__marker--show   { background: #f59e0b; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }
.player__marker--rewind { background: #22d3ee; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }

.player__row { display: flex; align-items: center; gap: .3rem; margin-top: .45rem; color: #fff; }
.player__btn {
    background: transparent; border: none; color: #fff;
    width: 34px; height: 34px; border-radius: 8px;
    display: inline-grid; place-items: center; cursor: pointer;
    font-size: 1.05rem; position: relative; transition: background .15s ease;
}
.player__btn:hover { background: rgba(255, 255, 255, .18); }
.player__btn small { position: absolute; bottom: 2px; right: 2px; font-size: .55rem; font-weight: 700; line-height: 1; }
.player__time { font-size: .85rem; margin-left: .45rem; font-variant-numeric: tabular-nums; }
.player__row .spacer { flex: 1; }

/* legend marker ใต้เครื่องเล่น */
.vt-legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .8rem; color: var(--ink-soft); margin-top: .5rem; }
.vt-legend .k { display: inline-flex; align-items: center; gap: .4rem; }
.vt-legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* รายการคำถามที่เพิ่มแล้ว (ใต้ฟอร์มเพิ่มคำถาม) */
.added-list { display: flex; flex-direction: column; gap: .5rem; max-height: 340px; overflow-y: auto; }
.added-item {
    display: flex; align-items: flex-start;
    padding: .6rem .75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--card);
    font-size: .9rem;
    line-height: 1.4;
}
.added-item .badge { font-variant-numeric: tabular-nums; flex-shrink: 0; }
.added-item--new { animation: addedPop .9s ease; }
@keyframes addedPop {
    0%   { background: var(--brand-50); box-shadow: 0 0 0 .18rem rgba(var(--brand-500-rgb),.28); }
    100% { background: var(--card); box-shadow: 0 0 0 0 rgba(var(--brand-500-rgb),0); }
}

/* ไฮไลต์ช่องวินาทีตอนกดจับเวลาจากวิดีโอ */
.vt-flash { animation: vtFlash .7s ease; }
@keyframes vtFlash {
    0%   { box-shadow: 0 0 0 0 rgba(var(--brand-500-rgb), .55); }
    100% { box-shadow: 0 0 0 .4rem rgba(var(--brand-500-rgb), 0); }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .hero, .hero-illustration { animation: none; }
    .vt-flash { animation: none; }
    .btn:active { transform: none; }
    .ripple { display: none; }
    .site-navbar .nav-link::after { transition: none; }
    .progress-bar, #topbar { transition: none; }
}

/* ===== Accessibility ===== */
.skip-link {
    position: fixed; top: -60px; left: 12px; z-index: 3000;
    background: var(--brand-600); color: #fff;
    padding: .6rem 1.1rem; border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    text-decoration: none; font-weight: 500;
    transition: top .2s ease;
}
.skip-link:focus { top: 0; color: #fff; }

:focus-visible { outline: 3px solid rgba(var(--brand-500-rgb), .5); outline-offset: 2px; border-radius: 4px; }
.btn:focus-visible, .nav-link:focus-visible, .filter-chip:focus-visible,
.page-link:focus-visible, .dropdown-item:focus-visible, .checkpoint:focus-visible {
    outline: none;
    box-shadow: 0 0 0 .22rem rgba(var(--brand-500-rgb), .4);
}
/* คีย์บอร์ดโฟกัสในการ์ดคอร์ส */
.course-card a:focus-visible { outline-offset: 3px; }

/* ===== Mobile tuning ===== */
@media (max-width: 575.98px) {
    .hero__inner { padding: 2.4rem 0 3.4rem; }
    .hero h1 { font-size: 1.5rem; }
    .hero p.lead { font-size: .95rem; }
    /* ตัวเลข 3 กล่องเรียงแถวเดียว (เดิม 2 คอลัมน์ กล่องที่ 3 ยืดเต็มแถวดูไม่สมดุล) */
    .hero-stats { gap: .5rem; flex-wrap: nowrap; }
    .hero-stats .stat { flex: 1 1 0; min-width: 0; text-align: center; padding: .6rem .35rem; }
    .hero-stats .num { font-size: 1.3rem; }
    .hero-stats .lbl { font-size: .72rem; line-height: 1.35; }
    .section-head { flex-direction: column; align-items: flex-start; }
    .course-toolbar { flex-direction: column; align-items: stretch; }
    .course-search { max-width: none; }
    .filter-chips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
    .filter-chip { flex: 0 0 auto; }
    .player-shell { padding: 8px; }
    /* ปุ่มกลับขึ้นบน: เล็กลงและโปร่งนิดหน่อย ไม่บังข้อความด้านล่างมากเกินไป */
    .to-top { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); width: 40px; height: 40px; font-size: 1.05rem; }
    .to-top.show { opacity: .88; }
}

/* ─────────────────────────────────────────────────────────────
   ช่องรหัสผ่าน: ปุ่มดู/ซ่อน + แถบวัดความแข็งแรง
   ───────────────────────────────────────────────────────────── */
.pw-wrap { position: relative; }
.pw-wrap .form-control { padding-right: 44px; }

.pw-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--ink-faint);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color .15s, background .15s;
}
.pw-toggle:hover { color: var(--brand-600); background: var(--brand-50); }
.pw-toggle:focus-visible { outline: 3px solid var(--brand-400); outline-offset: 1px; }

.pw-meter__bar {
    height: 5px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.pw-meter__bar span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    transition: width .25s ease, background-color .25s ease;
}
.pw-meter__bar span.lv0 { background: #dc3545; }
.pw-meter__bar span.lv1 { background: #f97316; }
.pw-meter__bar span.lv2 { background: #eab308; }
.pw-meter__bar span.lv3 { background: #22c55e; }
.pw-meter__bar span.lv4 { background: #16a34a; }
.pw-meter__label { font-size: .78rem; }

@media (prefers-reduced-motion: reduce) {
    .pw-meter__bar span, .pw-toggle { transition: none; }
}

/* ─────────────────────────────────────────────────────────────
   เลย์เอาต์ฝั่งผู้ดูแลระบบ: เมนูด้านข้าง + พื้นที่เนื้อหา
   ───────────────────────────────────────────────────────────── */
.admin-shell {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-top: 24px;
    margin-bottom: 40px;
    align-items: start;
}

@media (min-width: 992px) {
    .admin-shell { grid-template-columns: 236px minmax(0, 1fr); }
}

/* กันเนื้อหาในกริดล้นเวลาตารางกว้างเกิน (minmax(0,1fr) อย่างเดียวไม่พอบนบางเบราว์เซอร์) */
.admin-content { min-width: 0; }

.admin-sidebar {
    position: sticky;
    top: 84px;                     /* เว้นระยะจาก navbar ที่ sticky อยู่ */
    align-self: start;
    max-height: calc(100vh - 104px);
    overflow-y: auto;
    padding: 14px 10px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.admin-nav__group + .admin-nav__group { margin-top: 16px; }

.admin-nav__title {
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .6px;
    text-transform: uppercase;
    color: var(--ink-faint);
    padding: 0 12px 6px;
}

.admin-nav__list { list-style: none; margin: 0; padding: 0; }

.admin-nav__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    margin-bottom: 2px;
    border-radius: var(--radius-md);
    color: var(--ink-soft);
    font-size: .9rem;
    text-decoration: none;
    transition: background .15s, color .15s;
}

.admin-nav__link i { font-size: 1.02rem; flex-shrink: 0; }
.admin-nav__link span { flex-grow: 1; }

.admin-nav__link:hover { background: var(--brand-50); color: var(--brand-700); }
.admin-nav__link:focus-visible { outline: 3px solid var(--brand-400); outline-offset: 1px; }

.admin-nav__link.active {
    background: var(--grad-brand);
    color: #fff;
    box-shadow: var(--shadow-brand);
    font-weight: 500;
}
.admin-nav__link.active:hover { color: #fff; }

.admin-nav__badge {
    flex-shrink: 0;
    min-width: 22px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--brand-50);
    color: var(--brand-700);
    font-size: .72rem;
    font-weight: 500;
    text-align: center;
}
.admin-nav__link.active .admin-nav__badge {
    background: rgba(255, 255, 255, .22);
    color: #fff;
}

/* ปุ่มเปิด drawer บนจอเล็ก */
.admin-drawer-btn {
    border: 1px solid var(--line);
    color: var(--brand-700);
    background: var(--card);
    border-radius: var(--radius-md);
    line-height: 1;
    padding: 6px 10px;
}
.admin-drawer-btn i { font-size: 1.2rem; }

.admin-drawer { max-width: 280px; }
.admin-drawer .offcanvas-title { font-size: 1rem; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
    .admin-nav__link { transition: none; }
}

/* ─────────────────────────────────────────────────────────────
   โหมดมืด (Dark mode)

   Bootstrap 5.3 รองรับ data-bs-theme="dark" อยู่แล้ว จึงจัดการ
   การ์ด/ตาราง/ฟอร์ม/ดรอปดาวน์/โมดัลให้เองโดยอัตโนมัติ
   ที่นี่จึงเหลือแค่สลับค่า token ของธีมเราเอง + คอมโพเนนต์ที่เขียนเอง
   ───────────────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
    --brand-50:  #1e1b4b;       /* พื้นอ่อนของแบรนด์ กลับด้านเป็นโทนเข้ม */
    --brand-100: #262261;
    --brand-200: #312c7a;

    /* accent สีม่วงกลับด้าน: ตัวอักษรสว่างขึ้น พื้นหลังเข้มลง */
    --accent-violet: #a78bfa;
    --accent-violet-surface: #241a45;

    --ink:       #e8eaf2;
    --ink-soft:  #adb3c4;
    --ink-faint: #98a0b3;

    --surface:   #0f1117;
    --card:      #171a23;
    --line:      #2a2f3d;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, .4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .45);
    --shadow-brand: 0 12px 28px rgba(var(--brand-600-rgb), .3);

    color-scheme: dark;
}

[data-bs-theme="dark"] body {
    background:
        radial-gradient(1200px 500px at 100% -10%, rgba(var(--brand-500-rgb), .12), transparent 60%),
        radial-gradient(900px 500px at -10% 0%, rgba(var(--violet-400-rgb), .09), transparent 55%),
        var(--surface);
    background-repeat: no-repeat;
}

/* ให้คอมโพเนนต์ของ Bootstrap ใช้พื้นผิวเดียวกับธีมเรา แทนสีเทากลางของ Bootstrap */
[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .dropdown-menu,
[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .offcanvas {
    --bs-card-bg: var(--card);
    --bs-dropdown-bg: var(--card);
    --bs-modal-bg: var(--card);
    --bs-offcanvas-bg: var(--card);
    background-color: var(--card);
    border-color: var(--line);
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background-color: #11141c;
    border-color: var(--line);
    color: var(--ink);
}
[data-bs-theme="dark"] .form-control::placeholder { color: #6b7280; }
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    background-color: #11141c;
    border-color: var(--brand-500);
    color: var(--ink);
}
[data-bs-theme="dark"] .form-control:disabled {
    background-color: #0d1016;
    color: var(--ink-faint);
}

[data-bs-theme="dark"] .table {
    --bs-table-color: var(--ink);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--line);
    --bs-table-striped-color: var(--ink);
    --bs-table-striped-bg: rgba(255, 255, 255, .028);
    --bs-table-hover-bg: rgba(var(--brand-500-rgb), .08);
}

/* พื้นหลังอ่อนของแบรนด์กลายเป็นโทนเข้ม ตัวอักษรจึงต้องสว่างขึ้นด้วย */
[data-bs-theme="dark"] .admin-nav__link:hover { color: var(--brand-bright); }
[data-bs-theme="dark"] .admin-nav__badge { color: var(--brand-bright); }
[data-bs-theme="dark"] .pw-toggle:hover { color: var(--brand-bright); }
[data-bs-theme="dark"] .filter-chip:hover { color: var(--brand-bright); }
[data-bs-theme="dark"] ::selection { background: var(--brand-600); color: #fff; }

/* หน้าเข้าสู่ระบบ/รายงานที่พิมพ์ — เส้นคั่นและตัวอักษรรอง */
[data-bs-theme="dark"] .form-text,
[data-bs-theme="dark"] .text-muted { color: var(--ink-faint) !important; }

/* ป้ายบนรูปปกหลักสูตรยังเป็นพื้นขาว (อยู่บนรูปภาพ) ตัวอักษรจึงต้องคงสีเข้ม */
[data-bs-theme="dark"] .course-card__badge { color: var(--brand-700); }
/* ป้ายหมวดหมู่อยู่บนพื้นการ์ด (พื้น brand-50 ซึ่งโหมดมืดเป็นโทนเข้ม) — ตัวอักษรเข้มเดิมแทบอ่านไม่ออก */
[data-bs-theme="dark"] .course-cat { color: var(--brand-bright); }
/* ปุ่มขอบ (เช่น "เข้าสู่ระบบ" บนแถบเมนู): ตัวอักษรน้ำเงินเข้มบนพื้นมืดอ่านยาก */
[data-bs-theme="dark"] .btn-outline-primary { color: var(--brand-bright); }
[data-bs-theme="dark"] .btn-outline-primary:hover,
[data-bs-theme="dark"] .btn-outline-primary:active { color: #fff; }

/* DataTables: ปุ่มแบ่งหน้าและกล่องค้นหา */
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_length,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate { color: var(--ink-soft); }
[data-bs-theme="dark"] .page-link {
    background-color: var(--card);
    border-color: var(--line);
    color: var(--ink-soft);
}
[data-bs-theme="dark"] .page-item.active .page-link {
    background-color: var(--brand-600);
    border-color: var(--brand-600);
    color: #fff;
}
[data-bs-theme="dark"] .page-item.disabled .page-link {
    background-color: var(--card);
    color: #565e70;
}

/* SweetAlert2 */
[data-bs-theme="dark"] .swal2-popup {
    background: var(--card);
    color: var(--ink);
}
[data-bs-theme="dark"] .swal2-title,
[data-bs-theme="dark"] .swal2-html-container { color: var(--ink); }

/* ปุ่มสลับธีมบนแถบเมนู */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-soft);
    border-radius: 50%;
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease, transform .15s ease;
}
.theme-toggle:hover { color: var(--brand-600); border-color: var(--brand-200); transform: rotate(-12deg); }
.theme-toggle:focus-visible { outline: 3px solid var(--brand-400); outline-offset: 2px; }
[data-bs-theme="dark"] .theme-toggle:hover { color: var(--brand-bright); }

@media (prefers-reduced-motion: reduce) {
    .theme-toggle { transition: none; }
    .theme-toggle:hover { transform: none; }
}

/* ─────────────────────────────────────────────────────────────
   แถบความคืบหน้าตอนอัปโหลดไฟล์วิดีโอ
   (ไฟล์ 500MB ใช้เวลาเป็นนาที เดิมเห็นแค่ปุ่มหมุน ไม่รู้ว่าค้างหรือยังไป)
   ───────────────────────────────────────────────────────────── */
.upload-progress {
    margin-top: 1rem;
    padding: 1rem 1.15rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--card);
}
.upload-progress__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .75rem;
    margin-bottom: .5rem;
    font-size: .88rem;
}
.upload-progress__pct { font-weight: 600; color: var(--brand-600); }
.upload-progress__bar {
    height: 8px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.upload-progress__bar span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--grad-brand);
    transition: width .2s ease;
}
.upload-progress__hint { margin-top: .5rem; font-size: .8rem; color: var(--ink-faint); }

@media (prefers-reduced-motion: reduce) {
    .upload-progress__bar span { transition: none; }
}

/* ซ่อนปุ่ม "แสดงรหัสผ่าน" ของ Edge/IE ไม่ให้ซ้อนกับปุ่มรูปตาของเราเอง */
.pw-wrap .form-control::-ms-reveal,
.pw-wrap .form-control::-ms-clear { display: none; }

/* ─────────────────────────────────────────────────────────────
   SweetAlert2 — ให้เข้าธีม
   สำคัญเพราะตัวนี้เรนเดอร์ "คำถามที่เด้งกลางวิดีโอ" ซึ่งเป็นจุดขายของทั้งโครงงาน
   รวมถึงกล่องยืนยันทุกอันและ toast ทุกอัน
   เดิมมี CSS ของเราแค่ 3 บรรทัด (เฉพาะโหมดมืด) โหมดสว่างจึงเป็นของ SweetAlert ล้วน
   ───────────────────────────────────────────────────────────── */
.swal2-popup {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    font-family: var(--font-sans);
    background: var(--card);
    color: var(--ink);
}
.swal2-title { font-size: 1.2rem; font-weight: 600; color: var(--ink); line-height: 1.45; }
.swal2-html-container { font-size: .95rem; color: var(--ink-soft); line-height: 1.7; }

.swal2-styled.swal2-confirm {
    background: var(--grad-brand) !important;
    border-radius: 999px;
    box-shadow: 0 8px 18px rgba(var(--brand-600-rgb), .22);
    font-weight: 500;
    padding: .6rem 1.7rem;
}
.swal2-styled.swal2-confirm:focus-visible { box-shadow: var(--focus-ring); }
.swal2-styled.swal2-cancel {
    background: transparent !important;
    color: var(--ink-soft) !important;
    border: 1px solid var(--line) !important;
    border-radius: 999px;
    font-weight: 500;
    padding: .6rem 1.5rem;
}
.swal2-styled.swal2-cancel:hover { background: var(--surface) !important; }

.swal2-toast { border-radius: var(--radius-md); box-shadow: var(--shadow-md); }
.swal2-timer-progress-bar { background: var(--brand-400); }

/* ── การ์ดตัวเลือกคำตอบในป็อปอัปคำถาม ──
   เดิมเป็น radio ของเบราว์เซอร์ล้วน ๆ ทั้งที่เป็นปฏิสัมพันธ์หลักของผลิตภัณฑ์
   ซ่อน radio จริงไว้ (ยังโฟกัสด้วยคีย์บอร์ดได้) แล้ววาดการ์ดแทน */
.quiz-options { display: grid; gap: .55rem; text-align: left; margin-top: .35rem; }

.quiz-option {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: .7rem;
    padding: .7rem .9rem;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--card);
    cursor: pointer;
    transition: border-color var(--t-fast) ease, background var(--t-fast) ease, transform var(--t-fast) ease;
}
.quiz-option:hover { border-color: var(--brand-400); background: var(--brand-50); }
.quiz-option:active { transform: scale(.995); }

.quiz-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1px; height: 1px;
    margin: 0;
}

/* ตัวอักษรประจำข้อ (ก/ข/ค/ง) */
.quiz-option__key {
    flex-shrink: 0;
    width: 26px; height: 26px;
    display: grid; place-items: center;
    border-radius: 50%;
    border: 1.5px solid var(--line);
    background: var(--surface);
    color: var(--ink-soft);
    font-size: .82rem;
    font-weight: 600;
    transition: background var(--t-fast) ease, color var(--t-fast) ease, border-color var(--t-fast) ease;
}
.quiz-option__text { font-size: .93rem; line-height: 1.65; color: var(--ink); }

/* สถานะถูกเลือก — :has() รองรับในเบราว์เซอร์ยุคปัจจุบันทั้งหมด
   ถ้าเบราว์เซอร์เก่าไม่รองรับ ก็ยังใช้งานได้ปกติเพียงแต่ไม่ไฮไลต์ */
.quiz-option:has(input:checked) {
    border-color: var(--brand-500);
    background: var(--brand-50);
}
.quiz-option:has(input:checked) .quiz-option__key {
    background: var(--grad-brand);
    background-origin: border-box;   /* สีไล่คลุมถึงขอบโปร่งใส ไม่มีวงแหวนสีเพี้ยนรอบตัวอักษร */
    border-color: transparent;
    color: #fff;
}
/* วงแหวนโฟกัสต้องไปอยู่ที่การ์ด เพราะ radio จริงถูกซ่อน */
.quiz-option:has(input:focus-visible) { box-shadow: var(--focus-ring); }

/* ─────────────────────────────────────────────────────────────
   สถานะ "ไม่มีข้อมูล" ที่ใช้ร่วมกันทุกหน้า
   ───────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1.25rem;
    color: var(--ink-soft);
}
.empty-state__icon {
    width: 68px; height: 68px;
    margin: 0 auto .9rem;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--brand-50);
    color: var(--brand-400);
    font-size: 1.9rem;
}
.empty-state__title { font-size: 1.05rem; font-weight: 600; color: var(--ink); margin: 0 0 .35rem; }
.empty-state__desc { font-size: .9rem; margin: 0 auto 1.25rem; max-width: 46ch; }

/* ไอคอนวางต่ำกว่าเส้นฐานของ Kanit เล็กน้อยทุกจุด — ดันขึ้นให้ตรงกัน */
.bi { vertical-align: -.125em; }

/* ─────────────────────────────────────────────────────────────
   โหมดมืด — token สีเชิงความหมาย + คอมโพเนนต์ที่เพิ่มใหม่
   ───────────────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
    --success: #4ade80;  --success-surface: #0e2a1a;  --success-border: #1a5233;
    --warning: #fbbf24;  --warning-surface: #2b2008;  --warning-border: #5c4410;
    --danger:  #f87171;  --danger-surface:  #2c1315;  --danger-border:  #5c2226;
    --info:    #38bdf8;  --info-surface:    #0b2430;  --info-border:    #14495e;

    --focus-ring: 0 0 0 3px rgba(129, 140, 248, .5);
}

[data-bs-theme="dark"] .status-pill { background: #11141c; border-color: var(--line); }
[data-bs-theme="dark"] .status-pill--success { background: var(--success-surface); border-color: var(--success-border); }
[data-bs-theme="dark"] .status-pill--danger  { background: var(--danger-surface);  border-color: var(--danger-border); }
[data-bs-theme="dark"] .status-pill--warning { background: var(--warning-surface); border-color: var(--warning-border); }
[data-bs-theme="dark"] .status-pill--info    { background: var(--info-surface);    border-color: var(--info-border); }
[data-bs-theme="dark"] .status-pill--brand   { background: var(--brand-50); border-color: var(--brand-200); color: var(--brand-bright); }

[data-bs-theme="dark"] .data-card { background: var(--card); }
[data-bs-theme="dark"] .quiz-option { background: #11141c; }
[data-bs-theme="dark"] .quiz-option__key { background: #0d1016; }
[data-bs-theme="dark"] .empty-state__icon { color: var(--brand-400); }
[data-bs-theme="dark"] .swal2-styled.swal2-cancel:hover { background: #11141c !important; }

/* บั๊ก: แถวรายการคำถามที่เพิ่งเพิ่มตรึงพื้นขาวไว้ ไม่มี override โหมดมืด
   ทำให้เป็นแถบขาวโพลนกลางหน้าจอเข้ม */
[data-bs-theme="dark"] .added-item { background: #11141c; border-color: var(--line); }
[data-bs-theme="dark"] .vt-legend { color: var(--ink-soft); }

/* บั๊ก: ป้ายตัวเลือกในหน้าพรีวิว AI ใช้ utility bg-light ของ Bootstrap ตรง ๆ
   ในโหมดมืดจึงกลายเป็นชิปขาวจ้าบนการ์ดเข้ม */
[data-bs-theme="dark"] .bg-light {
    background-color: #11141c !important;
    color: var(--ink-soft) !important;
}
[data-bs-theme="dark"] .bg-light.text-dark { color: var(--ink-soft) !important; }
[data-bs-theme="dark"] .border { border-color: var(--line) !important; }

/* ─────────────────────────────────────────────────────────────
   การ์ดผลคะแนนรายหลักสูตร (หน้าผลคะแนนของนักศึกษา)
   เดิมหน้านี้เป็นตาราง Bootstrap เปล่า ๆ ที่โชว์คะแนนที่ได้กับคะแนนผ่าน
   แยกคนละคอลัมน์ ให้ผู้เรียนเทียบเลขเอง
   ───────────────────────────────────────────────────────────── */
.result-card { transition: transform var(--t-base) var(--ease-out), box-shadow var(--t-base) var(--ease-out); }
.result-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.result-card--highlight { border-color: var(--brand-400); box-shadow: var(--shadow-brand); }

.result-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1rem;
}
.result-card__title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.5;
    margin: 0;
    overflow-wrap: anywhere;
}

/* แถบคะแนน พร้อมขีดบอกเกณฑ์ผ่าน */
.result-bar {
    position: relative;
    height: 10px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.result-bar__fill {
    height: 100%;
    border-radius: 999px;
    background: var(--grad-brand);
    transition: width .9s var(--ease-out);
}
.result-bar__fill.is-pass { background: linear-gradient(135deg, #22c55e, #15803d); }
.result-bar__fill.is-fail { background: linear-gradient(135deg, #f87171, #dc2626); }

/* ขีดบอกเกณฑ์ผ่าน — วางทับแถบ ไม่ถูก overflow ตัดเพราะ .result-bar เป็น overflow:hidden
   จึงต้องยกออกมาเป็น element ลูกที่ position ต่างหาก */
.result-bar { overflow: visible; }
.result-bar__fill { position: relative; z-index: 1; }
.result-bar::after {
    content: "";
    position: absolute; inset: 0;
    border-radius: 999px;
    background: var(--line);
    z-index: 0;
}
.result-bar__mark {
    position: absolute;
    top: -3px; bottom: -3px;
    width: 2px;
    background: var(--ink-soft);
    border-radius: 2px;
    z-index: 2;
    opacity: .55;
}

.result-bar__legend {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    margin-top: .5rem;
    font-size: .85rem;
    color: var(--ink-soft);
}
.result-bar__legend b { color: var(--ink); font-size: 1.02rem; font-variant-numeric: tabular-nums; }

.result-card__progress {
    display: flex; align-items: center; gap: .45rem;
    margin: .85rem 0 0;
    font-size: .85rem;
    color: var(--ink-soft);
}
.result-card__progress i { color: var(--brand-500); }

/* ประวัติการสอบแบบไทม์ไลน์ */
.result-history { margin-top: .9rem; }
.result-history summary {
    display: flex; align-items: center; gap: .4rem;
    cursor: pointer;
    font-size: .85rem;
    color: var(--ink-soft);
    list-style: none;
}
.result-history summary::-webkit-details-marker { display: none; }
.result-history summary:hover { color: var(--brand-600); }
.result-history summary i { color: var(--brand-400); }

.result-timeline { list-style: none; margin: .7rem 0 0; padding: 0 0 0 1.1rem; position: relative; }
.result-timeline::before {
    content: "";
    position: absolute;
    left: 3px; top: .5rem; bottom: .5rem;
    width: 2px;
    background: var(--line);
}
.result-timeline li {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .25rem .75rem;
    padding: .3rem 0;
    font-size: .85rem;
}
.result-timeline li::before {
    content: "";
    position: absolute;
    left: -1.1rem; top: .85rem;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--ink-faint);
    box-shadow: 0 0 0 3px var(--card);
}
.result-timeline li.is-pass::before { background: var(--success); }
.result-timeline li.is-fail::before { background: var(--danger); }
.result-timeline__date { color: var(--ink-faint); font-size: .8rem; }

.result-card__foot { margin-top: 1.1rem; }

@media (prefers-reduced-motion: reduce) {
    .result-card, .result-bar__fill { transition: none; }
    .result-card:hover { transform: none; }
}

/* ─────────────────────────────────────────────────────────────
   หน้าดูวิดีโอ — ย้ายมาจาก <style> ที่เคยแทรกอยู่กลาง user/training.php
   (คลาส .video-fs-btn ที่อยู่ในนั้นถูกลบทิ้งแล้ว เพราะไม่มีมาร์กอัปไหนใช้เลย)
   ───────────────────────────────────────────────────────────── */
.video-wrap { position: relative; }

/* จัดวิดีโอให้พอดีจอตอนเต็มจอเนทีฟ (desktop/Android); iPhone ใช้ player เนทีฟของ iOS เอง */
.video-wrap:fullscreen { background: #000; }
.video-wrap:fullscreen .ratio { width: 100%; height: 100%; }
.video-wrap:fullscreen .ratio::before { display: none; }
.video-wrap:fullscreen video { object-fit: contain; }
.video-wrap:-webkit-full-screen { background: #000; }
.video-wrap:-webkit-full-screen .ratio { width: 100%; height: 100%; }
.video-wrap:-webkit-full-screen .ratio::before { display: none; }
.video-wrap:-webkit-full-screen video { object-fit: contain; }

/* สถานะกำลังบัฟเฟอร์ */
.tr-buffering {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(10, 10, 20, .35);
    z-index: 4;
    pointer-events: none;
}
.tr-buffering .spinner-border {
    width: 2.75rem; height: 2.75rem;
    color: #fff;
    border-width: .22em;
}

/* หมุดคำถามบนแถบเวลาของผู้เรียน — ให้เห็นว่าคำถามจะเด้งตอนไหน */
.tr-markers { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.tr-marker {
    position: absolute;
    top: 50%;
    width: 9px; height: 9px;
    margin-left: -4.5px;
    transform: translateY(-50%);
    border-radius: 50%;
    background: #f59e0b;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, .45);
}
.tr-marker.is-done { background: #22c55e; }

/* ─────────────────────────────────────────────────────────────
   ป็อปอัปคำถามระหว่างวิดีโอ
   ───────────────────────────────────────────────────────────── */
.quiz-question {
    text-align: left;
    font-size: 1rem;
    line-height: 1.75;
    color: var(--ink);
    margin: 0 0 1rem;
}

.quiz-timer {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    margin-top: 1.1rem;
    padding-top: .9rem;
    border-top: 1px dashed var(--line);
    font-size: .88rem;
    color: var(--ink-soft);
}
.quiz-timer b { color: var(--ink); font-variant-numeric: tabular-nums; }
.quiz-timer__bar {
    flex: 1 1 100px;
    height: 5px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.quiz-timer__bar > span {
    display: block;
    height: 100%;
    width: 100%;
    border-radius: 999px;
    background: var(--brand-500);
    transition: width 1s linear, background-color .3s ease;
}
/* 10 วินาทีสุดท้ายค่อยเร่งเร้า ไม่ต้องกดดันตั้งแต่วินาทีแรก */
.quiz-timer.is-urgent { color: var(--danger); }
.quiz-timer.is-urgent b { color: var(--danger); }
.quiz-timer.is-urgent .quiz-timer__bar > span { background: var(--danger); }

@media (prefers-reduced-motion: reduce) {
    .quiz-timer__bar > span { transition: none; }
}

/* ─────────────────────────────────────────────────────────────
   หัวการ์ดของหน้ากลุ่ม auth (เข้าสู่ระบบ / สมัคร / ลืมรหัส / ตั้งรหัสใหม่ / ยืนยันอีเมล)
   ───────────────────────────────────────────────────────────── */
.auth-head {
    --auth-accent: var(--brand-600);
    --auth-surface: var(--brand-50);
    text-align: center;
    margin-bottom: 1.5rem;
}
.auth-head--success { --auth-accent: var(--success); --auth-surface: var(--success-surface); }
.auth-head--danger  { --auth-accent: var(--danger);  --auth-surface: var(--danger-surface); }
.auth-head--warning { --auth-accent: var(--warning); --auth-surface: var(--warning-surface); }
/* โหมดมืด: ไอคอนสีน้ำเงินเข้มบนวงกลมพื้นเข้มแทบมองไม่เห็น — ใช้สีสว่างของแบรนด์ (แบบสำเร็จ/ผิดพลาด/เตือนคงสีเดิม) */
[data-bs-theme="dark"] .auth-head { --auth-accent: var(--brand-bright); }
[data-bs-theme="dark"] .auth-head--success { --auth-accent: var(--success); }
[data-bs-theme="dark"] .auth-head--danger  { --auth-accent: var(--danger); }
[data-bs-theme="dark"] .auth-head--warning { --auth-accent: var(--warning); }

.auth-head__icon {
    width: 56px; height: 56px;
    margin: 0 auto .85rem;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--auth-surface);
    color: var(--auth-accent);
    font-size: 1.6rem;
}
.auth-head__title {
    font-size: 1.22rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
}
.auth-head__sub {
    font-size: .88rem;
    color: var(--ink-soft);
    margin: .4rem auto 0;
    max-width: 34ch;
    line-height: 1.65;
    /* เกลี่ยความยาวบรรทัดให้ใกล้กัน — เดิมบนมือถือคำสุดท้ายหลุดลงไปบรรทัดใหม่คำเดียว ("…ที่ค้าง / ไว้") */
    text-wrap: balance;
}

/* ── หัวการ์ดหน้าโปรไฟล์ ── */
.profile-head {
    display: flex;
    align-items: center;
    gap: .9rem;
    padding-bottom: 1.1rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px dashed var(--line);
}
.profile-head__avatar {
    flex-shrink: 0;
    width: 52px; height: 52px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--grad-brand);
    color: #fff;
    font-size: 1.35rem;
    font-weight: 600;
}
.profile-head__name { font-size: 1.1rem; font-weight: 600; margin: 0; }
.profile-head__meta { font-size: .85rem; color: var(--ink-soft); margin: .1rem 0 0; }

/* ─────────────────────────────────────────────────────────────
   ชุดควบคุมของ DataTables (ช่องค้นหา / เลือกจำนวนแถว / ข้อความสรุป / ปุ่มแบ่งหน้า)
   เดิมแต่งไว้เฉพาะโหมดมืด โหมดสว่างจึงเป็นเทา-ฟ้ามาตรฐานที่ตัดกับธีมม่วงทั้งเว็บ
   ───────────────────────────────────────────────────────────── */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    color: var(--ink-soft);
    font-size: .87rem;
}

/* แถวบน: เลือกจำนวนแถว + ช่องค้นหา */
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--ink);
    padding: .3rem .6rem;
    transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}
.dataTables_wrapper .dataTables_filter input {
    border-radius: 999px;
    padding: .35rem .9rem;
    min-width: 220px;
}
.dataTables_wrapper .dataTables_length select:focus,
.dataTables_wrapper .dataTables_filter input:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: var(--focus-ring);
}
.dataTables_wrapper .dataTables_filter { margin-bottom: .35rem; }
.dataTables_wrapper .dataTables_length { margin-bottom: .35rem; }

/* แถวล่าง: ข้อความสรุป + ปุ่มแบ่งหน้า */
.dataTables_wrapper .dataTables_info { padding-top: 1rem; }
.dataTables_wrapper .dataTables_paginate { padding-top: .75rem; }

.page-link {
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink-soft);
    font-size: .87rem;
    padding: .35rem .75rem;
    transition: background var(--t-fast) ease, color var(--t-fast) ease, border-color var(--t-fast) ease;
}
.page-link:hover {
    background: var(--brand-50);
    border-color: var(--brand-200);
    color: var(--brand-700);
}
.page-item.active .page-link {
    background: var(--grad-brand);
    background-origin: border-box;
    border-color: transparent;
    color: #fff;
    box-shadow: var(--shadow-brand);
}
.page-item.disabled .page-link {
    background: var(--card);
    border-color: var(--line);
    color: var(--ink-faint);
    opacity: .6;
}
/* ปุ่มแรก/สุดท้ายมนตามการ์ด */
.page-item:first-child .page-link { border-top-left-radius: var(--radius-sm); border-bottom-left-radius: var(--radius-sm); }
.page-item:last-child  .page-link { border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }

@media (prefers-reduced-motion: reduce) {
    .dataTables_wrapper .dataTables_length select,
    .dataTables_wrapper .dataTables_filter input,
    .page-link { transition: none; }
}

/* โหมดมืด: ช่องกรอกใช้พื้นเข้มกว่าการ์ดเล็กน้อยให้เห็นขอบเขตชัด */
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_length select,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter input {
    background: #11141c;
    color: var(--ink);
}
[data-bs-theme="dark"] .page-link:hover { color: var(--brand-bright); }

/* ─────────────────────────────────────────────────────────────
   หน้าพรีวิวคำถามที่ AI สร้าง
   ขอได้ถึง 20 ข้อ = การ์ด 20 ใบเรียงกัน ถ้าไม่มีตัวช่วยต้องเลื่อนยาวมาก
   ───────────────────────────────────────────────────────────── */
.preview-toolbar {
    position: sticky;
    top: 74px;                 /* ใต้ navbar ที่ sticky อยู่ */
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .6rem 1rem;
    margin-bottom: 1rem;
    padding: .7rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--card);
    box-shadow: var(--shadow-sm);
}
.preview-toolbar__count { font-size: .9rem; color: var(--ink-soft); }
.preview-toolbar__count b { color: var(--brand-600); font-variant-numeric: tabular-nums; }

/* แถบปุ่มลอยติดขอบล่าง — กดบันทึกได้โดยไม่ต้องเลื่อนลงสุด */
.preview-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin: 1.25rem -1rem -1rem;
    padding: .9rem 1rem;
    background: var(--card);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 18px rgba(17, 24, 39, .07);
}

/* การ์ดที่ไม่ได้ติ๊ก — จางลงให้เห็นชัดว่าจะไม่ถูกบันทึก */
.card.is-unpicked {
    opacity: .5;
    filter: saturate(.5);
    transition: opacity var(--t-base) ease, filter var(--t-base) ease;
}

[data-bs-theme="dark"] .preview-actions { box-shadow: 0 -6px 18px rgba(0, 0, 0, .45); }

@media (prefers-reduced-motion: reduce) {
    .card.is-unpicked { transition: none; }
}

/* ─────────────────────────────────────────────────────────────
   วงแหวนความคืบหน้าบนการ์ดหลักสูตร
   วาดด้วย conic-gradient ตัวเดียว ไม่ต้องใช้ SVG หรือไลบรารีเพิ่ม
   ค่าเปอร์เซ็นต์ส่งผ่านตัวแปร --pct
   ───────────────────────────────────────────────────────────── */
.course-progress {
    display: flex;
    align-items: center;
    gap: .7rem;
    margin: .15rem 0 .9rem;
    padding-top: .85rem;
    border-top: 1px dashed var(--line);
}

.progress-ring {
    --pct: 0;
    --ring: var(--brand-500);
    flex-shrink: 0;
    position: relative;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: conic-gradient(var(--ring) calc(var(--pct) * 1%), var(--line) 0);
    transition: background var(--t-slow) var(--ease-out);
}
/* เจาะรูตรงกลางให้เป็นวงแหวน */
.progress-ring::before {
    content: "";
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: var(--card);
}
.progress-ring__label {
    position: relative;
    font-size: .78rem;
    font-weight: 600;
    color: var(--ring);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.progress-ring__label small { font-size: .62rem; font-weight: 500; }

.progress-ring.is-done { --ring: var(--success); }

.course-progress__text {
    font-size: .82rem;
    line-height: 1.55;
    color: var(--ink-soft);
}
.course-progress__text b { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
    .progress-ring { transition: none; }
}

/* ─────────────────────────────────────────────────────────────
   Skeleton loading — โครงร่างสีเทาเลื่อนแสงระหว่างรอเนื้อหา
   ใช้ตอนกรองหลักสูตร และตอนโหลดหน้าที่มีรูปเยอะ
   ───────────────────────────────────────────────────────────── */
.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--line);
    border-radius: var(--radius-sm);
    color: transparent !important;
    user-select: none;
    pointer-events: none;
}
.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg,
        transparent,
        rgba(255, 255, 255, .55),
        transparent);
    animation: skeletonSweep 1.3s ease-in-out infinite;
}
[data-bs-theme="dark"] .skeleton::after {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .07), transparent);
}
@keyframes skeletonSweep {
    100% { transform: translateX(100%); }
}

/* การ์ดหลักสูตรจำลอง */
.skeleton-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--card);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    height: 100%;
}
.skeleton-card__cover { aspect-ratio: 16 / 9; }
.skeleton-card__body { padding: 1rem 1.05rem 1.15rem; display: grid; gap: .55rem; }
.skeleton-line { height: 12px; }
.skeleton-line--sm { height: 10px; width: 55%; }
.skeleton-line--lg { height: 16px; width: 85%; }
.skeleton-line--btn { height: 38px; border-radius: var(--radius-sm); margin-top: .35rem; }

@media (prefers-reduced-motion: reduce) {
    .skeleton::after { animation: none; }
}

/* พื้นหลัง skeleton ระหว่างรอรูปปกหลักสูตรโหลด — ถอดออกด้วย JS เมื่อรูปมาแล้ว */
.course-card__cover--loading { background: var(--line); position: relative; }
.course-card__cover--loading::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .5), transparent);
    animation: skeletonSweep 1.3s ease-in-out infinite;
    z-index: 1;
}
[data-bs-theme="dark"] .course-card__cover--loading::after {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .06), transparent);
}
/* รูปค่อย ๆ ปรากฏแทนการกระโดดเข้ามา */
.course-card__cover img { opacity: 0; transition: opacity var(--t-base) ease; }
.course-card__cover:not(.course-card__cover--loading) img { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
    .course-card__cover--loading::after { animation: none; }
    .course-card__cover img { transition: none; }
}

/* ============================================================
   โควตา AI — แถบบอกว่าเหลือเท่าไหร่ และงานนี้ต้องใช้เท่าไหร่
   ใช้ในหน้า admin/ai_settings.php และ admin/generate_questions.php
   ============================================================ */

.quota-panel { display: flex; flex-direction: column; gap: 1rem; }

.quota-row__head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: .4rem;
    font-size: .85rem;
}
.quota-row__label { color: var(--ink-soft); font-weight: 500; }
.quota-row__value { font-weight: 600; white-space: nowrap; }

/* แถบเดียวกันกับ .result-bar แต่เตี้ยกว่าและมีสถานะสี
   overflow ต้องเป็น visible เพราะขีดบอก "ต้องใช้เท่าไหร่" ยื่นเกินขอบบนล่าง */
.quota-bar {
    position: relative;
    height: 9px;
    border-radius: 999px;
    background: var(--line);
    overflow: visible;
}
.quota-bar__fill {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--success);
    transition: width var(--t-slow) var(--ease-out);
}
.quota-bar.is-warning .quota-bar__fill { background: var(--warning); }
.quota-bar.is-danger  .quota-bar__fill { background: var(--danger); }

/* ขีดบอกปริมาณที่งานนี้ต้องใช้ — ถ้าแถบสั้นกว่าขีด แปลว่าโควตาไม่พอ */
.quota-bar__mark {
    position: absolute;
    top: -4px; bottom: -4px;
    width: 2px;
    background: var(--ink);
    border-radius: 2px;
    opacity: .5;
}

.quota-row__note { margin: .4rem 0 0; font-size: .8rem; }
.quota-panel__stamp { margin: 0; font-size: .78rem; color: var(--ink-soft); }

/* กล่องรวมข้อมูลวิดีโอ + โควตา ในหน้าสร้างคำถาม */
.quota-card {
    padding: .9rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
}
.quota-card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: .85rem;
    font-size: .88rem;
}
.quota-card__key { color: var(--ink-soft); font-size: .82rem; white-space: nowrap; }

/* แถวสถานะคีย์ในหน้าตั้งค่า AI */
.key-status { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.key-status__masked {
    padding: .2rem .55rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--line);
    color: var(--ink-soft);
    font-size: .85rem;
    letter-spacing: .04em;
}

[data-bs-theme="dark"] .quota-bar { background: #2a2f3d; }
[data-bs-theme="dark"] .quota-card { background: #161a24; }
[data-bs-theme="dark"] .key-status__masked { background: #11141c; border-color: var(--line); }

@media (prefers-reduced-motion: reduce) {
    .quota-bar__fill { transition: none; }
}

/* ============================================================
   ธีม Deep Navy — เปิดใช้ด้วย <html data-theme="navy">
   (ตั้งค่าที่ config/theme.php ค่าเดียว)

   ทับเฉพาะ token เท่านั้น ไม่แตะกฎของคอมโพเนนต์เลย
   ธีมม่วงเดิมอยู่ใน :root ด้านบนครบถ้วน สลับกลับได้ตลอด
   ============================================================ */

:root[data-theme="navy"] {
    --brand-400: #60a5fa;
    --brand-500: #3b82f6;
    --brand-600: #1e40af;
    --brand-700: #1e3a8a;
    --brand-800: #172554;
    --brand-50:  #eff6ff;
    --brand-100: #dbeafe;
    --brand-200: #bfdbfe;

    --brand-500-rgb: 59, 130, 246;
    --brand-600-rgb: 30, 64, 175;

    /* สีเสริมของธีมนี้เป็นฟ้าอ่อน ไม่ใช่ม่วง */
    --violet-400: #7dd3fc;
    --violet-400-rgb: 125, 211, 252;

    --brand-bright: #bfdbfe;

    /* การ์ดสถิติใบที่เคยเป็นม่วง เปลี่ยนเป็นทองอำพัน ตัดกับน้ำเงินได้ดี */
    --accent-violet: #b45309;
    --accent-violet-surface: #fffbeb;

    --ink: #0f172a;
    --ink-soft: #475569;
    --ink-faint: #64748b;

    --surface: #f8fafc;
    --card: #ffffff;
    --line: #e2e8f0;

    --font-sans: 'IBM Plex Sans Thai', system-ui, -apple-system, "Segoe UI", sans-serif;

    /* มุมคมกว่าธีมเดิม ให้ความรู้สึกเป็นทางการขึ้น */
    --radius-xl: 14px;
    --radius-lg: 10px;
    --radius-md: 8px;
    --radius-sm: 6px;
}

/* โหมดมืดของธีมนี้ — ต้องมาหลัง :root[data-theme] เพราะ specificity เท่ากัน (0,2,0) */
[data-theme="navy"][data-bs-theme="dark"] {
    --brand-50:  #172554;
    --brand-100: #1e3a8a;
    --brand-200: #1e40af;

    --brand-bright: #bfdbfe;
    --accent-violet: #fbbf24;
    --accent-violet-surface: #3a2a08;

    --ink: #e2e8f0;
    --ink-soft: #94a3b8;
    --ink-faint: #8593a8;

    --surface: #0b1220;
    --card: #131c2e;
    --line: #24314a;
}

/* ============================================================
   หน้าแรก — ส่วนที่เพิ่มเข้ามาเพื่อเล่าจุดเด่นของระบบ
   เดิมหน้าแรกมีแค่ hero กับการ์ดหลักสูตรแล้วจบ ไม่ได้บอกเลยว่า
   ระบบนี้ต่างจากเว็บดูวิดีโอทั่วไปตรงไหน
   ============================================================ */

/* หัวข้อกลางของแต่ละส่วน */
.sec-head {
    max-width: 640px;
    margin: 0 auto 2.5rem;
    text-align: center;
}
.sec-head .eyebrow-line { justify-content: center; }
.sec-head h2 {
    font-size: clamp(1.35rem, 2.4vw, 1.85rem);
    font-weight: 700;
    margin-bottom: .6rem;
}
.sec-head p {
    color: var(--ink-soft);
    margin: 0 auto;
    max-width: 52ch;
    text-wrap: balance;      /* ไม่ปล่อยคำเดียวค้างบรรทัดท้าย (เช่น "…เวลาถอย / หลัง") */
}

/* ---------- จุดเด่น ---------- */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.15rem;
}
.feature-card {
    position: relative;
    padding: 1.6rem 1.35rem 1.45rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    transition: transform var(--t-base) var(--ease-out),
                box-shadow var(--t-base) var(--ease-out),
                border-color var(--t-base) var(--ease-out);
}
.feature-card:hover {
    transform: translateY(-4px);
    border-color: var(--brand-200);
    box-shadow: var(--shadow-md);
}
.feature-card__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px; height: 46px;
    margin-bottom: .95rem;
    border-radius: var(--radius-md);
    background: var(--brand-50);
    color: var(--brand-600);
    font-size: 1.3rem;
}
/* ใบแรกคือจุดขายหลัก จึงเน้นให้เด่นกว่าใบอื่น */
.feature-card--hero .feature-card__icon {
    background: var(--grad-brand);
    color: #fff;
    box-shadow: var(--shadow-brand);
}
.feature-card h3 {
    font-size: 1.02rem;
    font-weight: 600;
    margin-bottom: .45rem;
}
.feature-card p {
    margin: 0;
    font-size: .89rem;
    color: var(--ink-soft);
}

/* ---------- ขั้นตอนการใช้งาน ---------- */
.step-flow {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    position: relative;
}
.step {
    position: relative;
    text-align: center;
    padding: 0 .5rem;
}
/* เส้นประเชื่อมระหว่างขั้น — ซ่อนบนจอเล็กเพราะการ์ดเรียงลงมาแนวตั้ง */
.step:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 27px; left: calc(50% + 34px); right: calc(-50% + 34px);
    border-top: 2px dashed var(--line);
}
.step__num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 54px; height: 54px;
    margin-bottom: 1rem;
    border-radius: 50%;
    background: var(--card);
    border: 2px solid var(--brand-200);
    color: var(--brand-600);
    font-size: 1.2rem;
    font-weight: 700;
    position: relative;
    z-index: 1;
}
.step h3 { font-size: 1rem; font-weight: 600; margin-bottom: .4rem; }
.step p { margin: 0 auto; font-size: .88rem; color: var(--ink-soft); max-width: 30ch; text-wrap: balance; }

/* ---------- ตัวอย่างคำถามเด้งกลางวิดีโอ ---------- */
.demo-stage {
    position: relative;
    max-width: 760px;
    margin: 0 auto;
}
.demo-player {
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: linear-gradient(135deg, #1c2431, #0d1219);
    box-shadow: var(--shadow-md);
    aspect-ratio: 16 / 8;
    display: flex;
    align-items: center;
    /* ชิดซ้าย ไม่ใช่กลาง เพราะการ์ดคำถามลอยทับอยู่ครึ่งขวา */
    justify-content: flex-start;
    padding-left: clamp(1.5rem, 8%, 4rem);
    position: relative;
}
.demo-player::before {
    content: "";
    position: absolute; inset: 0;
    background: radial-gradient(600px 300px at 50% 40%, rgba(var(--brand-500-rgb), .28), transparent 70%);
}
.demo-player__play {
    position: relative;
    width: 66px; height: 66px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .16);
    border: 1px solid rgba(255, 255, 255, .3);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.7rem;
}
.demo-player__tag {
    position: absolute;
    top: 1.1rem; left: 1.1rem;
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .28rem .7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, .14);
    border: 1px solid rgba(255, 255, 255, .24);
    color: #fff;
    font-size: .74rem;
}
.demo-player__tag i { color: var(--brand-400); font-size: .6rem; }

/* แถบเวลาพร้อมหมุดคำถาม — สื่อว่าคำถามถูกวางไว้ตามจุดต่าง ๆ ของวิดีโอ */
.demo-player__bar {
    position: absolute;
    left: 1.1rem; right: 1.1rem; bottom: 1.1rem;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .22);
}
.demo-player__played {
    position: absolute; inset: 0 auto 0 0;
    width: 42%;
    border-radius: 999px;
    background: #fff;
}
.demo-player__pin {
    position: absolute;
    top: 50%;
    width: 11px; height: 11px;
    margin: -5.5px 0 0 -5.5px;
    border-radius: 50%;
    background: var(--brand-400);
    border: 2px solid #fff;
    box-shadow: 0 0 0 3px rgba(var(--brand-500-rgb), .35);
}

/* การ์ดคำถามลอยทับวิดีโอ เหมือนตอนใช้งานจริง */
.demo-quiz {
    position: absolute;
    right: -8px; bottom: -34px;
    width: min(340px, 78%);
    padding: 1.05rem 1.1rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}
.demo-quiz__label {
    display: inline-flex; align-items: center; gap: .35rem;
    font-size: .72rem; font-weight: 600;
    color: var(--brand-600);
    margin-bottom: .5rem;
}
.demo-quiz__q { font-size: .9rem; font-weight: 500; margin-bottom: .7rem; }
.demo-quiz__opt {
    display: flex; align-items: center; gap: .55rem;
    padding: .45rem .6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: .82rem;
    margin-bottom: .35rem;
}
.demo-quiz__opt.is-picked {
    border-color: var(--brand-500);
    background: var(--brand-50);
    font-weight: 500;
}
.demo-quiz__key {
    flex-shrink: 0;
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 6px;
    background: var(--line);
    font-size: .74rem; font-weight: 600;
}
.demo-quiz__opt.is-picked .demo-quiz__key { background: var(--grad-brand); color: #fff; }
.demo-quiz__timer {
    display: flex; align-items: center; gap: .4rem;
    margin-top: .6rem;
    font-size: .76rem; color: var(--ink-soft);
}
.demo-quiz__track {
    flex: 1; height: 4px; border-radius: 999px; background: var(--line); overflow: hidden;
}
.demo-quiz__timer b { color: var(--brand-600); font-variant-numeric: tabular-nums; }
.demo-quiz__fill { display: block; height: 100%; width: 68%; background: var(--brand-500); border-radius: 999px; }

@media (max-width: 767.98px) {
    /* จอเล็ก: เอาการ์ดคำถามลงมาไว้ใต้วิดีโอ ไม่ให้ทับจนอ่านไม่ออก */
    .demo-quiz { position: static; width: 100%; margin-top: 1rem; }
    .step:not(:last-child)::after { display: none; }
}

/* ---------- แถบชวนเริ่มเรียนก่อนจบหน้า ---------- */
.cta-band {
    position: relative;
    overflow: hidden;
    margin-top: 4rem;
    padding: 3.2rem 0;
    background: var(--grad-brand);
    color: #fff;
    text-align: center;
}
.cta-band::before {
    content: "";
    position: absolute; inset: 0;
    background:
        radial-gradient(600px 260px at 20% 0%, rgba(255,255,255,.16), transparent 60%),
        radial-gradient(500px 300px at 85% 100%, rgba(var(--violet-400-rgb), .3), transparent 60%);
    pointer-events: none;
}
.cta-band__inner { position: relative; }
.cta-band h2 {
    font-weight: 700;
    font-size: clamp(1.3rem, 2.6vw, 1.9rem);
    margin-bottom: .6rem;
}
.cta-band p {
    color: rgba(255, 255, 255, .88);
    max-width: 46ch;
    margin: 0 auto 1.6rem;
    text-wrap: balance;
}

/* แถบ CTA เป็นพื้นสีเข้มเต็มความกว้าง ต่อกับ footer ที่เข้มเหมือนกัน
   ถ้าปล่อยระยะห่างเดิมของ footer ไว้ จะเห็นเป็นแถบสีอ่อนคั่นกลางเหมือนวางผิด */
main:has(.cta-band) + .site-footer { margin-top: 0; }

/* ---------- แถบตัวเลขคั่นระหว่างส่วน ---------- */
.stat-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.stat-strip__item {
    background: var(--card);
    padding: 1.35rem 1rem;
    text-align: center;
}
.stat-strip__num {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--brand-600);
}
.stat-strip__lbl { font-size: .82rem; color: var(--ink-soft); margin-top: .25rem; }

/* โหมดมืด */
[data-bs-theme="dark"] .demo-quiz__key { background: #2a2f3d; }

@media (prefers-reduced-motion: reduce) {
    .feature-card { transition: none; }
    .feature-card:hover { transform: none; }
}

/* ============================================================
   ลูกเล่นเพิ่มเติม (รอบเก็บรายละเอียดหน้าแรก)
   ทุกอย่างเคารพ prefers-reduced-motion — ปิดหมดถ้าผู้ใช้ตั้งค่าขอลดการเคลื่อนไหว
   ============================================================ */

/* ---------- แถบบอกความคืบหน้าการเลื่อนหน้า (อยู่บนสุดของทุกหน้า) ---------- */
.scroll-progress {
    position: fixed;
    top: 0; left: 0;
    height: 3px;
    width: 0;
    z-index: 1040;               /* เหนือ navbar (1030) แต่ต่ำกว่า modal */
    background: var(--grad-brand-soft);
    box-shadow: 0 0 10px rgba(var(--brand-500-rgb), .5);
    pointer-events: none;
    transition: width .08s linear;
}

/* ---------- การ์ดจุดเด่น: เส้นไล่สีโผล่ที่ขอบบนตอนชี้ ---------- */
.feature-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: var(--grad-brand);
    opacity: 0;
    transform: scaleX(.4);
    transition: opacity var(--t-base) var(--ease-out), transform var(--t-base) var(--ease-out);
}
.feature-card:hover::before { opacity: 1; transform: scaleX(1); }
/* ไอคอนขยับตามตอนชี้ ให้รู้สึกว่าการ์ดตอบสนอง */
.feature-card__icon { transition: transform var(--t-base) var(--ease-out); }
.feature-card:hover .feature-card__icon { transform: translateY(-3px) scale(1.06); }

/* ---------- ภาพประกอบ hero ลอยขึ้นลงเบา ๆ ---------- */
@keyframes heroFloat {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-12px); }
}
.hero-illustration { animation: heroFloat 6s ease-in-out infinite; }

/* ---------- หมุดคำถามบนแถบเวลาเต้นเบา ๆ ---------- */
@keyframes pinPulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(var(--brand-500-rgb), .35); }
    50%      { box-shadow: 0 0 0 7px rgba(var(--brand-500-rgb), .12); }
}
.demo-player__pin { animation: pinPulse 2.4s ease-in-out infinite; }
.demo-player__pin:nth-of-type(3) { animation-delay: .3s; }
.demo-player__pin:nth-of-type(4) { animation-delay: .6s; }
.demo-player__pin:nth-of-type(5) { animation-delay: .9s; }

/* หมุดที่หัวเล่นกำลังจะถึง — เน้นให้เห็นว่าคำถามนี้กำลังทำงานอยู่ */
.demo-player__pin.is-active {
    background: #fff;
    box-shadow: 0 0 0 7px rgba(var(--brand-500-rgb), .45);
    animation: none;
}

/* หัวเล่นเลื่อนนุ่ม ๆ */
.demo-player__played { transition: width .25s linear; }

/* ---------- นาฬิกาในการ์ดตัวอย่างตอนใกล้หมดเวลา ---------- */
.demo-quiz__fill { transition: width .25s linear; }
.demo-quiz.is-urgent .demo-quiz__fill { background: var(--danger); }
.demo-quiz.is-urgent .demo-quiz__timer b { color: var(--danger); }

/* การ์ดคำถามเด้งเข้ามาตอนถึงจุดที่มีคำถาม */
@keyframes quizPop {
    0%   { transform: translateY(10px) scale(.96); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}
.demo-quiz.is-popping { animation: quizPop .45s var(--ease-out); }

/* ---------- วงกลมลำดับขั้นตอน: เติมสีตอนชี้ ---------- */
.step__num {
    transition: background var(--t-base) var(--ease-out),
                color var(--t-base) var(--ease-out),
                border-color var(--t-base) var(--ease-out),
                transform var(--t-base) var(--ease-out);
}
/* เฉพาะอุปกรณ์ที่มีเมาส์ — บนจอสัมผัส :hover ค้างหลังแตะ (วงกลมขั้นตอนที่แตะผ่านค้างสีทึบอยู่วงเดียว) */
@media (hover: hover) {
    .step:hover .step__num {
        background: var(--grad-brand);
        /* ให้สีไล่คลุมถึงขอบนอก — ค่าเริ่มต้นวาดเฉพาะกรอบด้านในแล้วซ้ำลงใต้ขอบโปร่งใส 2px
           จึงเห็นวงแหวนสีเพี้ยน/ขอบเหลี่ยมรอบวงกลม */
        background-origin: border-box;
        border-color: transparent;
        color: #fff;
        transform: translateY(-3px);
        box-shadow: var(--shadow-brand);
    }
}

/* ---------- แถบตัวเลข: ยกขึ้นตอนชี้ ---------- */
.stat-strip__item { transition: background var(--t-fast) var(--ease-out); }
@media (hover: hover) {
    .stat-strip__item:hover { background: var(--brand-50); }
}
.stat-strip__num { font-variant-numeric: tabular-nums; }

/* ---------- ปิดการเคลื่อนไหวทั้งหมดถ้าผู้ใช้ขอ ---------- */
@media (prefers-reduced-motion: reduce) {
    .scroll-progress { transition: none; }
    .hero-illustration,
    .demo-player__pin { animation: none; }
    .demo-quiz.is-popping { animation: none; }
    .feature-card::before,
    .feature-card__icon,
    .step__num,
    .demo-player__played,
    .demo-quiz__fill { transition: none; }
}

/* ─────────────────────────────────────────────────────────────
   ช่องเลือกวิดีโอแบบลากวาง + ตัวอย่างคลิป (video_drop_field() + video_picker.js)
   ใช้ token ที่สลับค่าตามธีมอยู่แล้ว จึงไม่ต้องเขียนโหมดมืดแยก
   ───────────────────────────────────────────────────────────── */
.vdrop__zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .3rem;
    margin: 0;
    padding: 1.6rem 1rem;
    text-align: center;
    border: 2px dashed color-mix(in srgb, var(--brand-500) 35%, var(--line));
    border-radius: var(--radius-md);
    background: rgba(var(--brand-500-rgb), .03);
    cursor: pointer;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.vdrop__zone:hover,
.vdrop.is-dragover .vdrop__zone {
    border-color: var(--brand-500);
    background: rgba(var(--brand-500-rgb), .08);
}
.vdrop:focus-within .vdrop__zone { box-shadow: var(--focus-ring); }
.vdrop__zone > .bi { font-size: 2rem; line-height: 1; color: var(--brand-500); }
.vdrop__title { font-weight: 500; color: var(--ink); }
.vdrop__link { color: var(--brand-600); text-decoration: underline; text-underline-offset: 3px; }
.vdrop__sub { font-size: .85rem; color: var(--ink-faint); }
.vdrop__zone.has-error { border-color: var(--danger); }
.vdrop__error { font-size: .88rem; color: var(--danger); }

.vdrop__picked {
    padding: .75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--card);
}
.vdrop__preview {
    display: block;
    width: 100%;
    max-height: 300px;
    border-radius: var(--radius-sm);
    background: #000;
}
.vdrop__noprev {
    padding: 1.2rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-soft);
    font-size: .9rem;
    text-align: center;
}
.vdrop__noprev .bi { display: block; font-size: 1.6rem; margin-bottom: .25rem; color: var(--ink-faint); }
.vdrop__meta {
    display: flex;
    flex-wrap: wrap;
    gap: .2rem 1rem;
    margin: .65rem 0 .35rem;
    font-size: .875rem;
    color: var(--ink-soft);
}
.vdrop__name {
    flex: 1 1 100%;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.vdrop__warn {
    margin-bottom: .45rem;
    padding: .45rem .7rem;
    border: 1px solid var(--warning-border);
    border-radius: var(--radius-sm);
    background: var(--warning-surface);
    color: var(--warning);
    font-size: .85rem;
}
.vdrop__actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.vdrop__cover {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-top: .65rem;
    font-size: .85rem;
    color: var(--ink-soft);
}
.vdrop__cover img {
    width: 128px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
}

/* ─────────────────────────────────────────────────────────────
   คู่มือการใช้งาน (manual.php, admin/manual.php)
   ───────────────────────────────────────────────────────────── */
.manual-toc { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1.25rem; }
.manual-toc a {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .35rem .85rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--ink-soft);
    font-size: .88rem;
    text-decoration: none;
    transition: border-color var(--t-fast), color var(--t-fast);
}
.manual-toc a:hover { border-color: var(--brand-500); color: var(--brand-600); }
.manual-section { scroll-margin-top: 90px; }
.manual-section .card-body { padding: 1.35rem 1.5rem; }
.manual-section h2 {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: .9rem;
    font-size: 1.15rem;
    font-weight: 600;
}
.manual-section h2 .num {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--brand-50);
    color: var(--brand-600);
    font-size: .95rem;
}
.manual-section h3 { margin: 1rem 0 .5rem; font-size: 1rem; font-weight: 600; }
.manual-section p, .manual-section li { line-height: 1.75; }
.manual-steps { counter-reset: step; list-style: none; margin: 0; padding-left: 0; }
.manual-steps > li { position: relative; margin-bottom: .55rem; padding-left: 2.2rem; }
.manual-steps > li::before {
    counter-increment: step;
    content: counter(step);
    position: absolute;
    left: 0;
    top: .2rem;
    display: grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: var(--grad-brand);
    color: #fff;
    font-size: .8rem;
    font-weight: 600;
}
.manual-note {
    margin-top: .8rem;
    padding: .75rem 1rem;
    border: 1px solid var(--info-border);
    border-radius: var(--radius-sm);
    background: var(--info-surface);
    font-size: .9rem;
}
.manual-note--warn { border-color: var(--warning-border); background: var(--warning-surface); }
.manual-note ul { margin: .35rem 0 0; padding-left: 1.2rem; }
/* ชื่อปุ่ม/เมนูบนหน้าจอ ให้เห็นว่าเป็นสิ่งที่ต้องกด */
.ui-label {
    display: inline-block;
    padding: 0 .45rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    font-size: .88em;
    font-weight: 500;
    white-space: nowrap;
}
.manual-link {
    display: flex;
    align-items: flex-start;
    gap: .9rem;
    margin-top: .6rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--card);
}
.manual-link > .bi { font-size: 1.6rem; line-height: 1; color: var(--brand-500); }
.manual-link__url { font-size: .85rem; color: var(--ink-faint); word-break: break-all; }
[data-bs-theme="dark"] .manual-section h2 .num,
[data-bs-theme="dark"] .manual-toc a:hover { color: var(--brand-bright); }

/* ─────────────────────────────────────────────────────────────
   ปรับรอบ 2026-09-30 — ความเรียบร้อยทั้งเว็บ
   ───────────────────────────────────────────────────────────── */

/* ฝั่งแอดมินจอใหญ่: แถบบนกับส่วนท้ายกว้างเท่ากรอบเนื้อหา (เดิมโลโก้กับเมนูด้านข้างไม่อยู่แนวเดียวกัน) */
@media (min-width: 1200px) {
    .is-admin .site-navbar > .container,
    .is-admin .admin-footer > .container { max-width: 1264px; }
}

/* แถบบนฝั่งแอดมิน — ไม่ใช้ปุ่มสามขีดชุดที่สอง (เดิมบนมือถือมีสองปุ่มซ้อนกัน งงว่าปุ่มไหนเปิดอะไร) */
.admin-topbar { display: flex; align-items: center; gap: .4rem; margin-left: auto; }
.admin-topbar .nav-link { padding: .4rem .6rem; }
.admin-topbar .dropdown-toggle::after { margin-left: .35rem; }
@media (max-width: 575.98px) {
    .admin-topbar .nav-user__name { display: none; }
}

/* ส่วนท้ายฝั่งแอดมิน — บรรทัดเดียวพอ (ลิงก์หน้าแรก/เข้าสู่ระบบของเว็บสาธารณะไม่มีประโยชน์ในหลังบ้าน) */
.admin-footer {
    padding: 1.1rem 0 1.4rem;
    border-top: 1px solid var(--line);
    color: var(--ink-faint);
    font-size: .82rem;
}
.admin-footer .container { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1rem; }
.admin-footer a { color: var(--ink-soft); text-decoration: none; }
.admin-footer a:hover { color: var(--brand-600); }

/* ปุ่มจัดการในแถวตาราง — โทนเดียวกันทุกปุ่ม สีบอกความหมายตอนชี้ (เดิมกรอบ 4 สีเรียงกัน รก และตัวอักษรเหลืองอ่านยาก) */
.row-actions { display: inline-flex; align-items: center; gap: .35rem; }
.row-actions form { display: inline-flex; margin: 0; }
.btn-act {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .32rem .62rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--ink-soft);
    font-size: .82rem;
    font-weight: 500;
    line-height: 1.25;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.btn-act:hover,
.btn-act:focus-visible { color: var(--brand-600); border-color: var(--brand-200); background: var(--brand-50); }
.btn-act:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn-act--icon { padding: .32rem .5rem; }
.btn-act--danger:hover,
.btn-act--danger:focus-visible { color: var(--danger); border-color: var(--danger-border); background: var(--danger-surface); }
.btn-act:disabled,
.btn-act[aria-disabled="true"] { opacity: .45; cursor: not-allowed; background: var(--card); color: var(--ink-faint); border-color: var(--line); }
[data-bs-theme="dark"] .btn-act:hover,
[data-bs-theme="dark"] .btn-act:focus-visible { color: var(--brand-bright); }
[data-bs-theme="dark"] .btn-act--danger:hover { color: var(--danger); }

/* เซลล์สองบรรทัด (ชื่อ + รายละเอียดรอง) */
.cell-main { font-weight: 500; color: var(--ink); }
.cell-sub { display: block; font-size: .8rem; color: var(--ink-faint); }

/* ตารางบนมือถือ: เลื่อนซ้าย-ขวาเฉพาะตัวตาราง แทนการบีบคอลัมน์ */
.dataTables_wrapper .dt-row > [class*="col"] { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 767.98px) {
    .dataTables_wrapper table.table,
    .data-card table.table { min-width: 640px; }
    /* ชื่อในตารางต้องกว้างพออ่านได้ (ตารางเลื่อนแนวนอนได้อยู่แล้ว) — ไม่งั้นปุ่มจัดการกินที่จนชื่อเหลือบรรทัดละคำ */
    .table .cell-main { display: inline-block; min-width: 11rem; }
}

/* การ์ดสถิติ: ไอคอนไปมุมขวาบน ป้ายชื่อได้ความกว้างเต็มการ์ด (เดิมแถวละ 5 ใบ ป้ายขึ้นบรรทัดใหม่กลางคำ) */
.stat-tile .card-body { display: block; position: relative; }
.stat-tile__icon {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
}
.stat-tile__label { padding-right: 2.9rem; min-height: 1.4em; }
.stat-tile__value { margin-top: .15rem; }
/* หน้าผลคะแนนบนมือถือ: การ์ดแถวละ 3 ใบ (col-4) แคบจนป้ายเหลือที่ ~35px ข้างไอคอน คำไทยเลยถูกตัดกลางคำ
   ("ลง / ทะเบีย / นแล้ว") → ซ่อนไอคอน ให้ป้ายได้ความกว้างเต็มการ์ด */
@media (max-width: 575.98px) {
    .col-4 > .stat-tile .stat-tile__icon { display: none; }
    .col-4 > .stat-tile .stat-tile__label { padding-right: 0; }
}

/* กราฟยืดเต็มการ์ด — การ์ดในแถวเดียวกันสูงเท่ากัน เดิมกราฟสูงคงที่แล้วเหลือที่ว่างใต้กราฟ */
.card-body--fill { display: flex; flex-direction: column; }
.chart-box { position: relative; flex: 1 1 auto; }

/* หน้าหลักสูตรบนมือถือ: กล่องค้นหาเดิมใช้ flex-basis 260px ในแถบแนวตั้ง จึงกลายเป็น "สูง" 260px
   ไอคอนแว่นขยายลอยไปอยู่กลางกล่องห่างจากช่องพิมพ์ */
.filter-label { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 767.98px) {
    .course-toolbar .course-search { flex: 0 0 auto; }
    .filter-chips { -webkit-mask-image: linear-gradient(to right, #000 88%, transparent); mask-image: linear-gradient(to right, #000 88%, transparent); }
}

/* รายละเอียดหลักสูตร: ป้ายชื่อห้ามขึ้นบรรทัดใหม่ ("หน่วย/งาน") ค่าที่ยาวจัดชิดขวาแล้วตัดบรรทัดเอง */
.meta-list li span { flex-shrink: 0; white-space: nowrap; }
.meta-list li b { text-align: right; }

/* ฟอร์มยาว (เพิ่ม/แก้ไขหลักสูตร) แบ่งเป็นช่วง ๆ ให้กวาดตาหาได้เร็ว */
.form-section-title {
    display: flex;
    align-items: center;
    gap: .55rem;
    margin: 1.6rem 0 1rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--line);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
}
.card-body > .form-section-title:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
.form-section-title__num {
    display: inline-grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    background: var(--brand-50);
    color: var(--brand-600);
    font-size: .8rem;
}
[data-bs-theme="dark"] .form-section-title__num { color: var(--brand-bright); }
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: 1.4rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--line);
}
.form-switch .form-check-input { cursor: pointer; }
/* รูปปก/วิดีโอปัจจุบันในหน้าแก้ไข */
.current-media {
    display: block;
    max-width: 100%;
    max-height: 240px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #000;
}
img.current-media { background: none; }
/* ลายเซ็นพื้นโปร่งใส — พื้นขาวเสมอ ไม่งั้นโหมดมืดจะมองไม่เห็นเส้นหมึก */
img.current-media--sig { background: #fff; padding: .5rem 1rem; max-height: 110px; }
/* ปุ่มรอง (ยกเลิก) — Bootstrap ใช้เทาอ่อนแม้ในโหมดมืด จึงกำหนดให้ตามธีม */
.btn-light { background: var(--surface); border-color: var(--line); color: var(--ink-soft); }
.btn-light:hover { background: var(--brand-50); border-color: var(--brand-200); color: var(--brand-700); }
[data-bs-theme="dark"] .btn-light:hover { color: var(--brand-bright); }
[data-bs-theme="dark"] .vdrop__link { color: var(--brand-bright); }
[data-bs-theme="dark"] .stat-tile--brand { --accent: var(--brand-400); }
/* เมนู dropdown ที่เปิดอยู่ต้องลอยเหนือปุ่ม "กลับขึ้นบน" (1040) — เดิมรายการสุดท้ายโดนปุ่มบัง */
.dropdown-menu.show { z-index: 1045; }

/* ─────────────────────────────────────────────────────────────
   หน้าเรียน: โหมดทบทวน + ป้ายหยุดเพราะออกจากหน้าเรียน (training.php / training.js)
   ───────────────────────────────────────────────────────────── */
.result-card__foot { display: flex; flex-wrap: wrap; gap: .5rem; }

.review-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem 1rem;
    margin-bottom: 1rem;
    padding: .85rem 1.1rem;
    border: 1px solid var(--success-border);
    border-radius: var(--radius-md);
    background: var(--success-surface);
}
.review-banner > .bi { font-size: 1.5rem; color: var(--success); }
.review-banner__text { flex: 1 1 260px; display: flex; flex-direction: column; font-size: .9rem; color: var(--ink-soft); }
.review-banner__text b { color: var(--ink); font-size: .98rem; }
.review-banner__actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ทับทั้งวิดีโอรวมแถบควบคุม — ผู้เรียนต้องกด "ดูต่อ" เอง (ไม่เล่นต่ออัตโนมัติเมื่อกลับมา) */
.tr-away {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(12, 14, 28, .72);
    backdrop-filter: blur(3px);
}
.tr-away__box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    max-width: 22rem;
    text-align: center;
    color: #fff;
}
.tr-away__box .bi-pause-circle { font-size: 2.4rem; line-height: 1; opacity: .9; }
.tr-away__box b { font-size: 1.05rem; font-weight: 600; }
.tr-away__box span { font-size: .88rem; color: rgba(255, 255, 255, .78); }
.tr-away__box .btn { margin-top: .5rem; border-radius: 999px; padding-inline: 1.2rem; }

/* แถบส้มบนหัวหน้าเรียน: บอกกฎห้ามข้ามตั้งแต่เปิดหน้า — อยู่จนกว่าผู้เรียนจะกดปิดเอง */
.skip-note {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .3rem .35rem .3rem .85rem;
    border: 1px solid #fdba74;
    border-radius: 999px;
    background: #fff7ed;
    color: #c2410c;
    font-size: .9rem;
    font-weight: 600;
    line-height: 1.4;
}
.skip-note[hidden] { display: none; }
.skip-note > .bi { color: #ea580c; }
.skip-note__close {
    display: inline-grid;
    place-items: center;
    width: 1.8rem;
    height: 1.8rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: .8rem;
    opacity: .7;
    transition: background var(--t-fast, .15s) ease, opacity var(--t-fast, .15s) ease;
}
.skip-note__close:hover,
.skip-note__close:focus-visible { opacity: 1; background: rgba(234, 88, 12, .14); }
.skip-note__close:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(234, 88, 12, .35); }
[data-bs-theme="dark"] .skip-note { background: rgba(234, 88, 12, .14); border-color: rgba(251, 146, 60, .45); color: #fdba74; }
[data-bs-theme="dark"] .skip-note > .bi { color: #fb923c; }
@media (max-width: 575.98px) {
    .skip-note { margin-left: 0; }
}

/* หน้าจัดการหลักสูตร: แท็บ "หลักสูตรทั้งหมด / คลังหลักสูตรที่ลบ" */
.course-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--line);
}
.course-tab {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    margin-bottom: -1px;
    padding: .6rem 1rem;
    border-bottom: 2px solid transparent;
    color: var(--ink-soft);
    font-weight: 500;
    text-decoration: none;
}
.course-tab:hover { color: var(--brand-600); }
.course-tab.is-active { color: var(--brand-600); border-bottom-color: var(--brand-600); }
.course-tab__count {
    min-width: 1.6rem;
    padding: 0 .45rem;
    border-radius: 999px;
    background: var(--line);
    color: var(--ink-soft);
    font-size: .78rem;
    line-height: 1.5;
    text-align: center;
}
.course-tab.is-active .course-tab__count { background: var(--brand-600); color: #fff; }
[data-bs-theme="dark"] .course-tab:hover,
[data-bs-theme="dark"] .course-tab.is-active { color: var(--brand-bright); }
[data-bs-theme="dark"] .course-tab.is-active { border-bottom-color: var(--brand-bright); }
.trash-note { display: flex; gap: .5rem; align-items: flex-start; margin-bottom: 1rem; color: var(--ink-soft); font-size: .88rem; }
.trash-note .bi { color: var(--brand-500); margin-top: .15rem; }

/* ปุ่มลบแยกออกจากกลุ่มปุ่มจัดการ + มีตัวหนังสือ (เดิมเป็นไอคอนถังขยะปนอยู่กับปุ่มอื่น) */
.row-actions__sep { align-self: stretch; width: 1px; margin: .2rem .25rem; background: var(--line); }
.btn-act--delete { color: var(--danger); border-color: var(--danger-border); }
.btn-act--delete:hover,
.btn-act--delete:focus-visible { color: var(--danger); border-color: var(--danger); background: var(--danger-surface); }
.btn-act--restore { color: var(--success); border-color: var(--success-border); }
.btn-act--restore:hover,
.btn-act--restore:focus-visible { color: var(--success); border-color: var(--success); background: var(--success-surface); }
[data-bs-theme="dark"] .btn-act--delete:hover,
[data-bs-theme="dark"] .btn-act--delete:focus-visible { color: var(--danger); }
[data-bs-theme="dark"] .btn-act--restore:hover,
[data-bs-theme="dark"] .btn-act--restore:focus-visible { color: var(--success); }

/* หน้าเพิ่มคำถาม: เต็มจอจริง — เดิมกรอบเต็มจอแล้ว แต่วิดีโอยังโดน max-height 360px (จอดำ วิดีโอเล็ก ๆ)
   เขียนแยก :fullscreen / :-webkit-full-screen เพราะถ้ารวมในกฎเดียว เบราว์เซอร์ที่ไม่รู้จักตัวใดตัวหนึ่งจะทิ้งทั้งกฎ */
.player:fullscreen { max-width: none; border-radius: 0; box-shadow: none; }
.player:fullscreen .player__stage { height: 100%; }
.player:fullscreen .player__stage video { height: 100%; max-height: none; object-fit: contain; }
.player:fullscreen .player__controls { padding: 40px 24px 18px; }
.player:fullscreen .player__btn.player__cap { display: inline-flex; }
.player:-webkit-full-screen { max-width: none; border-radius: 0; box-shadow: none; }
.player:-webkit-full-screen .player__stage { height: 100%; }
.player:-webkit-full-screen .player__stage video { height: 100%; max-height: none; object-fit: contain; }
.player:-webkit-full-screen .player__controls { padding: 40px 24px 18px; }
.player:-webkit-full-screen .player__btn.player__cap { display: inline-flex; }

/* ปุ่มตั้งจุดบนแถบวิดีโอ — แสดงเฉพาะตอนเต็มจอ (ปกติใช้ปุ่ม "ใช้ …" ข้างช่องเวลา) */
.player__btn.player__cap {
    display: none; align-items: center; gap: .35rem; width: auto; padding: 0 .75rem;
    border: 1px solid rgba(255, 255, 255, .35); font-size: .85rem; font-weight: 600; white-space: nowrap;
}
.player__cap[data-target="showAt"] i { color: #f59e0b; }
.player__cap[data-target="rewindTo"] i { color: #22d3ee; }

/* ข้อความยืนยันบนวิดีโอ เมื่อกดตั้งจุดตอนเต็มจอ (ช่องเวลามองไม่เห็น) */
.player__toast {
    position: absolute; top: 18px; left: 50%; z-index: 3;
    transform: translate(-50%, -8px); padding: .45rem 1rem; border-radius: 999px;
    background: rgba(15, 23, 42, .86); color: #fff; font-size: .95rem; line-height: 1.4; white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
}
.player__toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* จุดสีหน้าป้ายช่องเวลา ให้ตรงกับหมุดบนแถบวิดีโอ */
.vt-dot { display: inline-block; width: 10px; height: 10px; margin-right: .4rem; border-radius: 3px; vertical-align: middle; }
.vt-dot--show { background: #f59e0b; }
.vt-dot--rewind { background: #22d3ee; }
.vt-cap { white-space: nowrap; }
.vt-cap .vt-now { font-variant-numeric: tabular-nums; }
