/* =====================================================================
   style.css — โครงหน้าเว็บและส่วนประกอบ (ปุ่ม การ์ด ตาราง หน้าสอบ ฯลฯ)
   สี ฟอนต์ ความโค้ง และขนาด อยู่ในไฟล์ theme.css — แนะนำให้แก้ที่ไฟล์นั้นก่อน
   ===================================================================== */

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: var(--font-size); line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--container); margin: 0 auto; padding: 0 20px; height: 56px;
  display: flex; align-items: center; gap: 24px;
}
.brand { font-weight: 600; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 400; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: var(--radius-sm);
  white-space: nowrap; font-size: .92rem;
}
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a.active { color: var(--text); background: var(--surface); }
.user { display: flex; align-items: center; gap: 12px; font-size: .9rem; white-space: nowrap; }
.container { max-width: var(--container); margin: 0 auto; padding: 32px 20px 64px; }
.narrow { max-width: 440px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar-inner { gap: 12px; padding: 0 16px; }
  .container { padding: 24px 16px 48px; }
  .user .who { display: none; }
}

/* ---------- surfaces ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; background: var(--bg); }
.card + .card { margin-top: 16px; }
.section { margin-top: 32px; }
.stat .label { color: var(--muted); font-size: .82rem; }
.stat .value { font-size: 1.7rem; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ---------- forms ---------- */
label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 9px 11px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 1px;
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
input[type=file] { padding: 7px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; font-size: .92rem; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 4px; margin: 0 0 20px; }
legend { padding: 0 6px; font-weight: 600; font-size: .9rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: .9rem; font-weight: 500; cursor: pointer; text-decoration: none;
  padding: 8px 14px; border-radius: var(--radius-btn); border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; }
.btn.sm { padding: 4px 9px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 500; color: var(--muted); font-size: .8rem; background: var(--surface); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 520px; }

/* ---------- badges & notes ---------- */
.badge {
  display: inline-block; font-size: .74rem; font-weight: 500; padding: 2px 8px;
  border-radius: 99px; border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.bad { color: var(--bad); border-color: currentColor; }
.badge.dark { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.note { padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); font-size: .9rem; }
.note.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.note.bad { background: var(--bad-bg); border-color: transparent; color: var(--bad); }
.note.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok); }

/* ---------- toast & modal ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(440px, calc(100% - 32px)); }
.toast { background: var(--accent); color: var(--accent-text); padding: 11px 14px; border-radius: var(--radius); font-size: .9rem; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.toast.bad { background: var(--bad); color: #fff; }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 90; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: var(--bg); border-radius: calc(var(--radius) + 2px); width: min(560px, 100%); padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(860px, 100%); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-box { width: min(380px, 100%); }
.auth-box h1 { margin-bottom: 4px; }
.auth-box .sub { color: var(--muted); margin-bottom: 28px; }

/* ---------- exam list ---------- */
.exam-item { display: flex; gap: 16px; justify-content: space-between; align-items: center; flex-wrap: wrap; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.exam-item:last-child { border-bottom: 0; }
.exam-item .meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.list { border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- exam taking ---------- */
.exam-bar { position: sticky; top: 0; z-index: 30; background: var(--bg); border-bottom: 1px solid var(--line); }
.exam-bar-inner { max-width: var(--container); margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 16px; }
.exam-bar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { font-family: var(--mono); font-size: 1.25rem; font-weight: 600; padding: 4px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); }
.timer.low { color: var(--warn); border-color: currentColor; }
.timer.critical { color: #fff; background: var(--bad); border-color: var(--bad); }
.save-state { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.save-state.off { color: var(--bad); }
.exam-layout { max-width: var(--container); margin: 0 auto; padding: 28px 20px 80px; display: grid; grid-template-columns: minmax(0,1fr) 260px; gap: 32px; }
@media (max-width: 860px) { .exam-layout { grid-template-columns: 1fr; } }
.q-num { color: var(--muted); font-size: .9rem; margin-bottom: 10px; }
.q-text { font-size: 1.15rem; line-height: 1.6; margin-bottom: 18px; white-space: pre-wrap; }
.q-img { display: block; max-width: 100%; max-height: 420px; height: auto; object-fit: contain; border-radius: var(--radius-sm); border: 1px solid var(--line); margin-bottom: 18px; }
.choices { display: grid; gap: 10px; }
.choice { display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; border: 1px solid var(--line-strong); border-radius: var(--radius); cursor: pointer; text-align: left; font: inherit; color: inherit; background: var(--bg); width: 100%; }
.choice:hover { background: var(--surface); }
.choice.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice .letter { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-strong); display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.choice.selected .letter { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.choice img { display: block; max-width: 100%; max-height: 220px; object-fit: contain; margin-top: 8px; border-radius: 4px; }
.choice.correct { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); }
.choice.wrong { border-color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); }
.q-nav-buttons { display: flex; gap: 8px; margin-top: 28px; align-items: center; }
.palette { position: sticky; top: 84px; align-self: start; }
.palette-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 12px 0 16px; }
.pal { position: relative; aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: .82rem; cursor: pointer; background: var(--bg); color: var(--text); font-family: inherit; }
.pal.answered { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.pal.current { outline: 2px solid var(--focus); outline-offset: 1px; }
.pal.flagged::after { content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.legend { display: grid; gap: 6px; font-size: .8rem; color: var(--muted); }
.legend span.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line-strong); vertical-align: -2px; margin-right: 6px; }
.legend span.sw.a { background: var(--accent); border-color: var(--accent); }
.legend span.sw.f { background: var(--warn); border-color: var(--warn); border-radius: 50%; width: 8px; height: 8px; }
.overlay { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: grid; place-items: center; padding: 24px; text-align: center; }
.banner { max-width: var(--container); margin: 12px auto 0; padding: 0 20px; }

/* ---------- question preview / review ---------- */
.review-q { padding: 20px 0; border-bottom: 1px solid var(--line); }
.review-q:last-child { border-bottom: 0; }
.tag { display: inline-block; font-size: .75rem; padding: 1px 7px; border-radius: 4px; background: var(--surface); border: 1px solid var(--line); margin: 0 4px 4px 0; }
.thumb { max-width: 160px; max-height: 100px; object-fit: contain; border: 1px solid var(--line); border-radius: 4px; display: block; margin-top: 6px; }
.checklist { max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 10px; }
.checklist .check { padding: 5px 0; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: .85rem; color: var(--muted); }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }
.btn.primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.grid > .card + .card { margin-top: 0; }
.brand { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1280px) { .user .who { display: none; } .nav a { padding: 6px 8px; } }
@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 6px; row-gap: 6px; }
  .brand { flex: 1; max-width: none; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -8px; }
}

/* ---------- branding (logo) ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-logo { height: 28px; width: auto; max-width: 140px; object-fit: contain; display: block; }
.auth-logo { height: 56px; width: auto; max-width: 240px; object-fit: contain; display: block; margin-bottom: 18px; }

/* ---------- appearance editor ---------- */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-btn); background: var(--bg); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; }
.swatch i { width: 16px; height: 16px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); }
.swatch.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type=color] { width: 44px; height: 38px; padding: 2px; cursor: pointer; flex: none; }
.preview-wrap { position: sticky; top: 76px; align-self: start; }
.preview { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.preview-top { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.preview-body { padding: 16px; display: grid; gap: 12px; }
.appearance-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 28px; }
@media (max-width: 900px) { .appearance-grid { grid-template-columns: 1fr; } .preview-wrap { position: static; } }

/* ---------- language switch (TH | EN) ---------- */
.lang-switch { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-btn); overflow: hidden; flex: none; }
.lang-switch button {
  font: inherit; font-size: .78rem; font-weight: 600; letter-spacing: .02em; cursor: pointer;
  background: transparent; color: var(--muted); border: 0; padding: 5px 9px; line-height: 1.2;
}
.lang-switch button + button { border-left: 1px solid var(--line-strong); }
.lang-switch button:hover { color: var(--text); background: var(--surface); }
.lang-switch button.active { background: var(--accent); color: var(--accent-text); }
.lang-switch.sm button { padding: 4px 7px; font-size: .72rem; }
.auth-lang { position: fixed; top: 16px; right: 16px; z-index: 5; }
.topbar .lang-switch { margin-right: 4px; }
@media (max-width: 760px) { .exam-bar .lang-switch { display: none; } }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -8px 0 24px; overflow-x: auto; }
.tabs a {
  text-decoration: none; color: var(--muted); padding: 8px 12px; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap; font-size: .92rem;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }

/* ---------- segmented buttons ---------- */
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-btn); overflow: hidden; }
.seg button { font: inherit; font-size: .88rem; cursor: pointer; background: var(--bg); color: var(--muted); border: 0; padding: 7px 12px; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.active { background: var(--accent); color: var(--accent-text); }
.seg .count { opacity: .8; }

/* ---------- website text editor ---------- */
.tx-section h2 { margin-bottom: 10px; }
.tx-section .card { padding: 4px 20px; }
.tx-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.tx-row:last-child { border-bottom: 0; }
.tx-row .tx-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.tx-row .tx-meta .tag { margin: 0; }
.tx-row textarea { min-height: 64px; }
.tx-row.changed input, .tx-row.changed textarea { border-color: var(--warn); }

/* ---------- เลือกหลายรายการ (bulk select) ---------- */
th.sel, td.sel { width: 40px; padding-right: 0; vertical-align: middle; }
th.sel input, td.sel input { width: 17px; height: 17px; cursor: pointer; margin: 0; }
tr.selected td { background: color-mix(in srgb, var(--accent) 7%, var(--bg)); }
.bulkbar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  width: max-content; max-width: calc(100% - 32px);
  padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--bg); box-shadow: 0 10px 36px rgba(0,0,0,.18);
}
.bulkbar[hidden] { display: none; }
.bulkbar-count { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.bulkbar-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.bulkbar .linkish { background: none; border: 0; padding: 0; font: inherit; font-size: .85rem; color: var(--focus); text-decoration: underline; cursor: pointer; }
body.has-bulkbar #toasts { bottom: 96px; }
body.has-bulkbar .container { padding-bottom: 120px; }
.bulk-errors { max-height: 220px; overflow-y: auto; margin: 0; padding-left: 18px; }
@media (max-width: 760px) {
  .bulkbar { left: 12px; right: 12px; bottom: 12px; transform: none; width: auto; max-width: none; }
}

/* แถบคำสั่งแบบอยู่เหนือตาราง (ใต้ช่องค้นหา) — ติดอยู่ใต้เมนูด้านบนเวลาเลื่อนจอ */
[data-bulk-slot] { position: sticky; top: 64px; z-index: 15; }
.bulkbar.inline {
  position: static; left: auto; right: auto; bottom: auto; transform: none;
  width: auto; max-width: none; margin: 0 0 12px;
  min-height: 48px; padding: 8px 12px; box-shadow: none; background: var(--surface); border-color: var(--line);
}
.bulkbar.inline.active { background: var(--bg); border-color: var(--accent); box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.bulkbar.inline .bulkbar-actions { margin-left: auto; }
@media (max-width: 760px) {
  [data-bulk-slot] { top: 8px; }
  .bulkbar.inline .bulkbar-actions { margin-left: 0; }
}
