/* THE STANDARD brand tokens (from intranet design handoff) */
:root {
  --ink: #111111;
  --red: #c8102e;
  --bg: #f2f1ee;
  --card: #ffffff;
  --line: #eceae4;
  --soft: #f4f3f0;
  --muted: #8a877f;
  --faint: #b3b0a8;
  --ok: #1f7a3d; --ok-bg: #eaf7ee;
  --warn: #9a6700; --warn-bg: #fef6e6;
  --bad: #c8102e; --bad-bg: #fdeceb;
  --intern: #6b3fa0; --intern-bg: #f3ecfb;
  --radius: 14px;
  --head: "Archivo", "Noto Sans Thai", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 "Noto Sans Thai", Tahoma, sans-serif;
}
h1, h2 { font-family: var(--head); margin: 0; letter-spacing: -.01em; }
h1 { font-size: 20px; font-weight: 800; }
h2 { font-size: 16px; font-weight: 800; margin-bottom: 12px; }
a { color: inherit; }
.sub { color: var(--muted); margin: 2px 0; font-size: 13.5px; }
.hidden { display: none !important; }
.logo { display: block; height: 30px; width: auto; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; font-size: 14px; font-weight: 600; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; white-space: nowrap; transition: border-color .15s, background .15s;
}
button:hover, .btn:hover { border-color: #d8d6d1; background: var(--soft); }
button.primary, .btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
button.primary:hover, .btn.primary:hover { background: #2a2a2a; }
button.accent, .btn.accent { background: var(--red); color: #fff; border-color: var(--red); }
button.accent:hover, .btn.accent:hover { background: #a50d26; }
button:disabled { opacity: .45; cursor: default; }
button.sm, select.sm { padding: 4px 10px; font-size: 13px; }
input, select, textarea {
  font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 0 24px; height: 72px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar .divider { width: 1px; height: 28px; background: var(--line); }
.topbar .app-name { font-family: var(--head); font-weight: 800; font-size: 14px; color: #555; letter-spacing: .04em; text-transform: uppercase; }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: 13px; color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }
.event-head { margin-bottom: 20px; }
.event-head h1 { font-size: 26px; font-weight: 900; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 20px; }
.stat .num { font-family: var(--head); font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.stat.dark .lbl { color: #c7c5bf; }
.bar { height: 4px; background: rgba(255,255,255,.18); border-radius: 2px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--red); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar input, .toolbar select { width: auto; }
.toolbar input[type=search] { flex: 1; min-width: 200px; background: var(--soft); border-color: var(--soft); }
.toolbar .grow { flex: 1; }
.notice { padding: 12px 16px; border-radius: 10px; background: var(--warn-bg); color: #5c3d00; margin-bottom: 16px; font-size: 14px; border-left: 3px solid var(--warn); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--soft); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; background: var(--card); }
td.actions { white-space: nowrap; text-align: right; }
td.actions > * { margin-left: 4px; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.intern { background: var(--intern-bg); color: var(--intern); }
.tag.muted { background: var(--soft); color: #555; }

/* ---------- dialogs ---------- */
dialog { border: none; border-radius: var(--radius); padding: 24px; max-width: 520px; width: calc(100% - 32px); color: var(--ink); }
dialog::backdrop { background: rgba(17,17,17,.55); }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
dialog p { font-size: 14px; }
pre.sample { background: var(--soft); padding: 12px; border-radius: 8px; font-size: 12px; overflow-x: auto; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-weight: 500; margin-top: 16px; }
.check input { width: auto; }

/* ---------- login ---------- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; padding: 32px; }
.login .logo { height: 40px; margin-bottom: 24px; }
.login .rule { height: 1px; background: var(--line); margin: 0 0 20px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* ---------- ticket ---------- */
body.ticket { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
body.ticket .card { max-width: 400px; width: 100%; padding: 0; overflow: hidden; }
.ticket-top { padding: 24px 24px 20px; border-bottom: 1px dashed #d8d6d1; }
.ticket-top .logo { height: 34px; margin-bottom: 18px; }
.ticket-top h1 { font-size: 22px; font-weight: 900; }
.ticket-body { padding: 20px 24px 24px; text-align: center; }
.ticket-body .who { font-size: 20px; font-weight: 700; margin: 0; }
.qr { width: 100%; max-width: 280px; display: block; margin: 16px auto; }
.msg { padding: 12px; border-radius: 8px; font-weight: 700; }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg.bad { background: var(--bad-bg); color: var(--bad); }
.ticket-foot { background: var(--ink); color: #c7c5bf; font-size: 12px; padding: 10px 24px; text-align: center; }

/* ---------- scanner ---------- */
body.scan { background: var(--ink); min-height: 100vh; }
body.scan .topbar { height: 60px; padding: 0 12px; gap: 10px; }
body.scan .logo { height: 24px; }
.counter { font-family: var(--head); font-variant-numeric: tabular-nums; font-weight: 800; font-size: 15px; }
.counter small { font-family: "Noto Sans Thai", sans-serif; font-weight: 500; color: var(--muted); font-size: 12px; margin-right: 4px; }
.seg { display: inline-flex; background: var(--soft); border-radius: 8px; padding: 3px; }
.seg button { border: none; background: transparent; padding: 6px 12px; font-size: 13px; }
.seg button.on { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
#reader { width: 100%; max-width: 560px; margin: 0 auto; border: none !important; }
#reader video { display: block; }
.scan-hint { text-align: center; color: #c7c5bf; padding: 16px; font-size: 14px; }
.result {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 24px; color: #fff;
}
.result.ok { background: #1f7a3d; }
.result.duplicate { background: #9a6700; }
.result.bad { background: #c8102e; }
.result .status { font-family: var(--head); font-size: 15px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; opacity: .85; }
.result .title { font-size: 40px; font-weight: 800; line-height: 1.2; margin: 6px 0 0; }
.result .name { font-size: 26px; font-weight: 700; margin-top: 28px; padding-top: 24px; border-top: 1px solid rgba(255,255,255,.35); }
.result .dept { font-size: 17px; opacity: .9; }
.result .badge { margin-top: 16px; font-size: 16px; font-weight: 800; padding: 6px 18px; border-radius: 999px; background: #fff; color: var(--intern); letter-spacing: .04em; }
.result .note { margin-top: 12px; font-size: 16px; opacity: .92; }
.result .tap { position: absolute; bottom: 28px; font-size: 13px; opacity: .75; }
.search-panel { max-width: 560px; margin: 0 auto; padding: 16px; color: #fff; }
.search-list { list-style: none; padding: 0; margin: 12px 0 0; }
.search-list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid #2a2a2a; }
.search-list li.sub { color: var(--faint); border: none; }
.search-list li .who { flex: 1; }
.search-list li .who small { color: var(--faint); display: block; }

@media (max-width: 720px) {
  .hide-sm { display: none; }
  .topbar { padding: 0 16px; height: 64px; }
  .topbar .divider, .topbar .app-name { display: none; }
  .wrap { padding: 16px; }
  .stat .num { font-size: 22px; }
  .event-head h1 { font-size: 21px; }
}

/* ---------- รายการงาน ---------- */
.event-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.event-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; transition: border-color .15s, box-shadow .15s;
}
.event-card:hover { border-color: #d8d6d1; box-shadow: 0 2px 10px rgba(17,17,17,.06); }
.event-card.archived { opacity: .6; }
.event-card-main { display: block; padding: 20px 20px 16px; text-decoration: none; color: inherit; }
.event-card-top { display: flex; align-items: flex-start; gap: 8px; }
.event-card-top h2 { flex: 1; font-size: 17px; margin: 0; line-height: 1.35; }
.event-nums { display: flex; gap: 22px; margin: 16px 0 10px; }
.event-nums b { font-family: var(--head); font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; display: block; }
.event-nums small { color: var(--muted); font-size: 12px; }
.bar.light { background: var(--soft); }
.event-card-foot { display: flex; gap: 6px; padding: 12px 20px; border-top: 1px solid var(--soft); background: var(--soft); flex-wrap: wrap; }

/* ---------- หน้าสแกน: ผลลัพธ์ค้างจอ ---------- */
.result .result-body { display: flex; flex-direction: column; align-items: center; }
.result .next-btn {
  position: absolute; left: 16px; right: 16px; bottom: max(20px, env(safe-area-inset-bottom));
  background: #fff; color: var(--ink); border: none; padding: 20px; border-radius: 12px;
  font-size: 19px; font-weight: 800; justify-content: center; box-shadow: 0 4px 18px rgba(0,0,0,.25);
}
.result .next-btn:hover { background: #fff; }

/* ---------- จับฉลาก ---------- */
body.draw .draw-stage { text-align: center; padding: 24px 20px 28px; }
.draw-prize { max-width: 420px; margin: 0 auto 20px; }
.draw-prize input { text-align: center; }
.draw-display {
  min-height: 190px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 12px; background: var(--soft); padding: 20px; margin-bottom: 20px;
}
.draw-display.rolling { background: var(--ink); }
.draw-display.won { background: var(--ink); color: #fff; }
.draw-idle { color: var(--faint); font-size: 15px; }
.draw-roll {
  font-family: var(--head); font-size: clamp(26px, 6vw, 44px); font-weight: 800;
  color: #fff; opacity: .5; letter-spacing: -.02em;
}
.draw-prize-name {
  font-size: 14px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: #c7c5bf; margin-bottom: 10px;
}
.draw-winner { font-family: var(--head); font-size: clamp(30px, 7vw, 56px); font-weight: 900; line-height: 1.1; letter-spacing: -.02em; }
.draw-dept { font-size: 17px; color: #c7c5bf; margin-top: 8px; }
.draw-display .badge {
  margin-top: 14px; font-size: 14px; font-weight: 800; padding: 5px 16px;
  border-radius: 999px; background: #fff; color: var(--intern);
}
.draw-btn { font-size: 17px; padding: 15px 44px; justify-content: center; }
