:root {
  --bg: #f4f6fb;
  --surface: #fff;
  --text: #1b2333;
  --muted: #6b7587;
  --line: #e1e6f0;
  --primary: #1f5eff;
  --primary-dark: #1648cc;
  --ok-bg: #e7f7ee; --ok: #12703d;
  --warn-bg: #fff4dc; --warn: #8a5a00;
  --err-bg: #fdeaea; --err: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 8px 24px rgba(20, 30, 60, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --surface: #181f2e; --text: #e8ecf5; --muted: #98a2b8; --line: #2a3347;
    --primary: #5b8bff; --primary-dark: #7a9fff;
    --ok-bg: #11301f; --ok: #6fd69b; --warn-bg: #33270a; --warn: #f0c36a; --err-bg: #3a1614; --err: #ff9b94;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[v-cloak] { display: none; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 "Segoe UI", "Noto Sans Thai", "Sarabun", Tahoma, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
small { color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- ปุ่ม / ฟอร์ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--err); }
.btn.danger.solid { background: var(--err); border-color: var(--err); color: #fff; }
.btn.link { border-color: transparent; background: none; color: var(--muted); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: .85rem; border-radius: 8px; }
.btn.block { display: flex; width: 100%; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .95rem; }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; font-size: .9rem; }
label.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
input:not([type=checkbox]), select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 400;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }

.alert { padding: 10px 14px; border-radius: 10px; font-size: .92rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.err { background: var(--err-bg); color: var(--err); }
.hint { color: var(--muted); font-size: .88rem; margin-bottom: 12px; }
.devnote { text-align: center; font-size: .8rem; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 6px; }

/* ---------- หน้า auth ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-card { width: 100%; max-width: 400px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.auth-card.wide { max-width: 460px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 1.35rem; line-height: 1.2; }
.brand p { color: var(--muted); font-size: .88rem; }
.brand.sm { gap: 10px; }
.logo {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 12px;
  background: var(--primary); color: #fff; font-weight: 800; letter-spacing: .5px;
}
.brand.sm .logo { width: 34px; height: 34px; border-radius: 9px; font-size: .85rem; }
.userbox { display: flex; flex-direction: column; gap: 4px; text-align: center; padding: 16px; border-radius: 10px; background: var(--bg); }
.userbox strong { font-size: 1.8rem; letter-spacing: 1px; color: var(--primary); }

/* ---------- ฝั่งลูกค้า ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.who { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.who-name { display: flex; flex-direction: column; line-height: 1.25; font-weight: 600; text-align: right; }
.who-name small { font-size: .78rem; }
.container { max-width: 880px; margin: 0 auto; padding: 24px 16px 48px; }
.page-title { font-size: 1.3rem; margin-bottom: 16px; }
.page-title small { font-size: .9rem; margin-left: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.tile {
  display: flex; flex-direction: column; gap: 6px; padding: 24px 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text);
}
.tile .ico { font-size: 2rem; }
.tile.disabled { opacity: .6; }

/* ---------- ฝั่ง admin ---------- */
.shell.admin { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 20px;
  padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--line);
}
.side nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side nav a, .side nav .soon {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-radius: 10px; color: var(--text); font-weight: 600; text-decoration: none;
}
.side nav a:hover { background: var(--bg); }
.side nav a.on { background: var(--primary); color: #fff; }
.side nav .soon { color: var(--muted); font-weight: 400; opacity: .75; }
.side nav .soon small { font-size: .72rem; }
.side-foot { display: flex; flex-direction: column; gap: 8px; font-weight: 600; }
.side-foot span small { display: block; }
.badge { background: #e5484d; color: #fff; border-radius: 999px; padding: 0 8px; font-size: .78rem; line-height: 20px; }
.content { padding: 24px 28px 56px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head .page-title { margin: 0; }
.head > div { display: flex; gap: 8px; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.search { max-width: 360px; flex: 1 1 240px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button {
  min-height: 36px; padding: 0 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .88rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.chips button b { color: var(--muted); margin-left: 4px; }
.chips button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chips button.on b { color: #dbe5ff; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--bg); font-size: .8rem; color: var(--muted); text-transform: none; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--primary) 5%, transparent); }
td.num, th.num { text-align: right; }
td.empty { text-align: center; color: var(--muted); padding: 32px; }
.w-check { width: 40px; }
.w-actions { width: 1%; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 6px; }
.tag { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); }
.tag.active { background: var(--ok-bg); color: var(--ok); }
.tag.pending { background: var(--warn-bg); color: var(--warn); }
.tag.disabled { background: var(--err-bg); color: var(--err); }
.tag.admin { margin-left: 6px; background: var(--primary); color: #fff; }

/* ---------- Modal / toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(10, 16, 30, .5); overflow-y: auto; }
.modal { width: 100%; max-width: 560px; padding: 24px; background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); display: flex; flex-direction: column; gap: 14px; }
.modal.sm { max-width: 440px; }
.modal h3 { font-size: 1.15rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.zone { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg); }
.zone-title { font-size: .88rem; color: var(--muted); font-weight: 600; }
.zone-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px);
  padding: 12px 20px; border-radius: 10px; background: #1b2333; color: #fff; box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
}
.toast.err { background: var(--err); }

/* ---------- มือถือ / แท็บเล็ต ---------- */
@media (max-width: 860px) {
  .shell.admin { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: column; gap: 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side nav { flex-direction: row; flex-wrap: wrap; flex: none; }
  .side nav .soon { display: none; }
  .side-foot { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .side-foot .btn.block { width: auto; }
  .content { padding: 16px 12px 48px; }
}
@media (max-width: 520px) {
  .grid2 { grid-template-columns: 1fr; }
  .auth-card { padding: 22px 18px; }
  .who-name { display: none; }
}

/* ================= เฟส 2 ================= */

/* ---------- banner ประกาศ (แถบแดงวิ่ง) ---------- */
.banner { position: sticky; top: 0; z-index: 30; overflow: hidden; background: #d92d20; color: #fff; font-weight: 600; }
.banner.preview { position: static; border-radius: 8px; }
/* animation-delay ติดลบ = เริ่มวิ่งมาแล้วช่วงหนึ่ง ข้อความจะเห็นทันทีที่เปิดหน้า ไม่ต้องรอแถบว่างๆ */
.marquee { display: inline-block; white-space: nowrap; padding: 9px 0 9px 100%; animation: marquee 30s linear -4s infinite; }
.marquee:hover { animation-play-state: paused; }
.marquee.static { animation: none; padding-left: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.marquee .ann { margin-right: 80px; }
.marquee .ann b { margin-right: 6px; padding: 1px 8px; border-radius: 6px; background: rgba(255, 255, 255, .22); }
@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(-100%); } }
@media (prefers-reduced-motion: reduce) {
  .marquee { animation: none; padding-left: 14px; white-space: normal; display: block; }
}

/* ---------- สถานะของรอบ ---------- */
.tag.st-open { background: var(--ok-bg); color: var(--ok); }
.tag.st-upcoming { background: var(--warn-bg); color: var(--warn); }
.tag.st-ended, .tag.st-closed { background: var(--err-bg); color: var(--err); }

/* ---------- ฝั่งลูกค้า: สมัครรอบ ---------- */
a.tile { text-decoration: none; }
a.tile:hover { border-color: var(--primary); text-decoration: none; }
.back { display: inline-block; margin-bottom: 12px; font-weight: 600; }
.card.pad { padding: 20px 22px; }
.round-list { display: grid; gap: 14px; }
.round-card { display: flex; flex-direction: column; gap: 4px; padding: 16px 20px; color: var(--text); text-decoration: none; }
a.round-card:hover { border-color: var(--primary); text-decoration: none; }
.round-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.round-head .page-title { margin: 0; }
.mine { margin-top: 6px; font-weight: 600; }
.mine.cta { color: var(--primary); }
.empty-card { text-align: center; color: var(--muted); }
.apply { display: flex; flex-direction: column; gap: 14px; }
.desc { white-space: pre-line; color: var(--muted); }
.facts { margin: 0; display: grid; gap: 4px; font-size: .92rem; }
.facts div { display: flex; gap: 10px; flex-wrap: wrap; }
.facts dt { color: var(--muted); min-width: 92px; }
.facts dd { margin: 0; font-weight: 600; }
.sub { font-size: 1.02rem; }
.checklist { display: grid; gap: 8px; }
.checklist.boxed { max-height: 210px; overflow-y: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin-top: 6px; }
label.check.item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; align-items: center; font-size: 1rem; cursor: pointer; }
.checklist.boxed label.check.item { padding: 4px 2px; border: 0; }
label.check.item.locked { opacity: .75; cursor: default; }
label.check.item input { margin-top: 0; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- ฝั่ง admin ---------- */
.lbl { display: block; font-weight: 600; font-size: .95rem; }
.cards2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-bottom: 8px; }
.ctl { display: flex; flex-direction: column; gap: 8px; }
.ctl-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; align-self: flex-start; }
.seg button { min-height: 36px; padding: 0 14px; border: 0; border-right: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--primary); color: #fff; font-weight: 600; }
.seg button:disabled { opacity: .6; cursor: wait; }
.chip { display: inline-block; margin: 2px 4px 2px 0; padding: 1px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: .82rem; white-space: nowrap; }
.badge.inline { margin-left: 8px; background: var(--warn-bg); color: var(--warn); }
td.wrap { white-space: normal; min-width: 220px; max-width: 420px; }
.modal-actions.spread { align-items: center; }
.grow { flex: 1; }
.content > section > .back { margin-bottom: 6px; }

/* ---------- แถบแจ้งเตือนรายบุคคล (ผลกระทบจากการที่ admin ลบรอบ/เอารายการออก) ---------- */
.notices { display: grid; gap: 10px; margin-bottom: 16px; }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--warn); background: var(--warn-bg); color: var(--warn); }
.notice .ico { font-size: 1.3rem; line-height: 1.4; }
.notice .msg { flex: 1; min-width: 0; }
.notice .msg p { margin: 2px 0; color: var(--text); white-space: pre-line; overflow-wrap: anywhere; }
.notice .msg small { color: var(--muted); }
.notice .btn { flex: none; }
@media (max-width: 520px) { .notice { flex-wrap: wrap; } .notice .btn { margin-left: 34px; } }

/* ช่องทางติดต่อ admin */
.contact { text-align: center; font-size: .82rem; color: var(--muted); line-height: 1.6; }
.contact a { font-weight: 700; }
.contact.footer { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); }

/* ================= เฟส 3 ================= */
.modal.wide { max-width: 760px; }
.fields-editor { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg); }
.field-row { display: grid; grid-template-columns: minmax(140px, 2fr) 110px minmax(70px, .8fr) auto auto; gap: 8px; align-items: center; }
.field-row .opts { grid-column: 1 / -2; }
.field-row .mv { display: inline-flex; gap: 4px; }
.field-row .mv button { min-width: 32px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; font: inherit; }
.field-row .mv button:disabled { opacity: .35; cursor: default; }
.field-row .mv button.x { color: var(--err); }
.field-row input, .field-row select { min-height: 38px; }
.field-row label.req { white-space: nowrap; }
@media (max-width: 700px) { .field-row { grid-template-columns: 1fr 1fr; } .field-row .opts { grid-column: 1 / -1; } }

.release { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.release p { margin-top: 4px; }
.inline-select { flex-direction: row; align-items: center; gap: 8px; }
.inline-select select { min-width: 240px; }
.bulk { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .9rem; }
select.verdict { min-height: 34px; width: 120px; padding: 2px 8px; font-weight: 600; }
select.verdict.pass { background: var(--ok-bg); color: var(--ok); }
select.verdict.fail { background: var(--err-bg); color: var(--err); }

.round-card.row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
a.round-card.row { cursor: pointer; }
.tag.big { font-size: .95rem; padding: 3px 16px; }
.req-mark { color: var(--err); }
.apply label span small { font-weight: 400; }

.field-row label.check { align-items: center; }
.field-row label.check input { margin-top: 0; }

/* ================= เฟส 4: Certificate ================= */
/* ฟอนต์ไทย Sarabun เก็บในโปรเจกต์ (ไม่พึ่ง CDN) ใช้วาดใบรับรองบน canvas */
@font-face { font-family: 'Sarabun'; font-weight: 400; font-display: swap; src: url(../vendor/fonts/sarabun-thai-400-normal.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun'; font-weight: 400; font-display: swap; src: url(../vendor/fonts/sarabun-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Sarabun'; font-weight: 600; font-display: swap; src: url(../vendor/fonts/sarabun-thai-600-normal.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun'; font-weight: 600; font-display: swap; src: url(../vendor/fonts/sarabun-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Sarabun'; font-weight: 700; font-display: swap; src: url(../vendor/fonts/sarabun-thai-700-normal.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Sarabun'; font-weight: 700; font-display: swap; src: url(../vendor/fonts/sarabun-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

.cert-view { display: flex; flex-direction: column; gap: 12px; }
.cert-img { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.modal.xwide { max-width: 980px; }
.cert-filters { display: flex; gap: 14px; flex-wrap: wrap; }

/* ผลการทดสอบ: รายชื่อ user / หัวข้อ user ที่เลือก */
tr.row-click { cursor: pointer; }
.user-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.user-head .back { margin-bottom: 2px; }
.user-head .sub { margin: 0; }
.pager { display: inline-flex; align-items: center; gap: 10px; }
td.nowrap .tag + .tag { margin-left: 4px; }
