:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #dde1e6;
  --primary: #1f4e8c;
  --primary-ink: #ffffff;
  --director: #1f6f5c;
  --director-soft: #e3f2ee;
  --executive: #8a3b12;
  --executive-soft: #fbeee6;
  --ok: #1d7a3e;
  --ok-soft: #e4f4e9;
  --warn: #9a6400;
  --warn-soft: #fff4dc;
  --info: #1f4e8c;
  --info-soft: #e5eefb;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --text: #e8eaed;
    --muted: #9aa4b1;
    --border: #2e353f;
    --primary: #6aa1ec;
    --primary-ink: #0b1520;
    --director: #5cc4a6;
    --director-soft: #15302a;
    --executive: #f0a077;
    --executive-soft: #3a2216;
    --ok: #5cc98a;
    --ok-soft: #15301f;
    --warn: #f0c060;
    --warn-soft: #33290f;
    --info: #6aa1ec;
    --info-soft: #172a45;
    --danger: #f2877d;
    --danger-soft: #3a1714;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Sarabun', 'Noto Sans Thai', system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.55;
}
.wrap { max-width: 640px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.wide { max-width: 1180px; }
h1 { font-size: 1.5rem; margin: 0 0 4px; line-height: 1.3; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
h3 { font-size: 1.05rem; margin: 0 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=number], input[type=tel], select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
button, .btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  background: var(--primary);
  color: var(--primary-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}
button.block { width: 100%; padding: 13px; margin-top: 16px; }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.danger { background: var(--danger); color: #fff; }
button.small { padding: 6px 12px; font-size: .9rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
.err { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.err:empty { display: none; }
.hidden { display: none !important; }

.badge {
  display: inline-block;
  font-size: .82rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.lv-director { background: var(--director-soft); color: var(--director); }
.lv-executive { background: var(--executive-soft); color: var(--executive); }
.st-pending { background: var(--surface-2); color: var(--muted); }
.st-logged_in { background: var(--info-soft); color: var(--info); }
.st-selecting { background: var(--warn-soft); color: var(--warn); }
.st-submitted { background: var(--ok-soft); color: var(--ok); }

.header-band { border-top: 6px solid var(--primary); }
.header-band.director { border-top-color: var(--director); }
.header-band.executive { border-top-color: var(--executive); }

/* candidate list */
.cand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}
.cand input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.cand.on { border-color: var(--primary); background: var(--info-soft); }
.cand.off { opacity: .45; }
.cand .no { color: var(--muted); font-variant-numeric: tabular-nums; width: 2em; text-align: right; flex: none; }
.sticky-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  margin: 0 -16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sticky-bar .count { flex: 1; font-weight: 600; }

/* modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal { background: var(--surface); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.modal ol { padding-left: 1.4em; margin: 8px 0 12px; }
.phrase { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-weight: 700; margin: 6px 0; }

/* admin */
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.topbar .grow { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  background: none; color: var(--muted); border: 0; border-bottom: 3px solid transparent;
  border-radius: 0; padding: 10px 14px; white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--primary); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .8rem; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); }
.rank-top td { font-weight: 600; }
.rank-pill {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); font-weight: 700;
}
.rank-top .rank-pill { background: var(--primary); color: var(--primary-ink); }
.qr-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.qr-box .qr { background: #fff; padding: 8px; border-radius: 8px; line-height: 0; }
.link-text { word-break: break-all; font-size: .9rem; background: var(--surface-2); padding: 6px 10px; border-radius: 8px; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.ok-notice { background: var(--ok-soft); color: var(--ok); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.switch input { width: 20px; height: 20px; }
