:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --primary: #3b5bdb;
  --primary-dark: #2f49b0;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e3e8f0;
  --green: #2f9e44;
  --red: #e03131;
  --amber: #f08c00;
  --shadow: 0 2px 12px rgba(30, 40, 80, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Sarabun", "Noto Sans Thai", -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; font-size: 18px; color: var(--primary); }
.topbar .who { color: var(--muted); font-size: 14px; }

.container { max-width: 900px; margin: 24px auto; padding: 0 16px; }
.container.wide { max-width: 1100px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }

label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 240px; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 13px; }

input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary); color: #fff; border: none;
  padding: 10px 16px; border-radius: 8px; font-size: 15px; font-family: inherit;
  cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { background: #b8c0d8; cursor: not-allowed; }
.btn.secondary { background: #eef1f8; color: var(--primary); }
.btn.secondary:hover { background: #e2e7f5; }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); }
.btn.amber { background: var(--amber); }
.btn.sm { padding: 6px 10px; font-size: 13px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.tile {
  border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  background: #fff; cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); }
.tile .t-title { font-weight: 700; font-size: 16px; }
.tile .t-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.open { background: #e6f4ea; color: var(--green); }
.badge.closed { background: #f1f3f5; color: var(--muted); }
.badge.left { background: #eef1f8; color: var(--primary); }
.badge.none { background: #fdecec; color: var(--red); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr:hover td { background: #fafbff; }

.muted { color: var(--muted); }
.error { color: var(--red); font-size: 14px; margin-top: 8px; }
.hidden { display: none !important; }
.center { text-align: center; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { padding: 9px 16px; border-radius: 8px; cursor: pointer; background: var(--card); border: 1px solid var(--border); font-weight: 600; font-size: 14px; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.q-block { border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 14px; }
.q-block .q-num { color: var(--primary); font-weight: 700; }
.choice { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.choice:hover { background: #f5f7fd; }
.choice input { width: auto; }

.timer {
  position: sticky; top: 64px; float: right;
  background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 8px;
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.timer.warn { background: var(--red); }

.login-wrap { max-width: 400px; margin: 8vh auto; }
.login-wrap .card { padding: 28px; }
.result-score { font-size: 42px; font-weight: 800; color: var(--primary); }

.code-box {
  font-size: 30px; font-weight: 800; letter-spacing: 4px; color: var(--primary);
  background: #eef1f8; padding: 12px 18px; border-radius: 10px; display: inline-block;
}
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.list-row:last-child { border-bottom: none; }
