:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --line: #e2e7ec;
  --text: #17212b;
  --muted: #5b6875;
  --brand: #0d6e6e;
  --brand-ink: #ffffff;
  --brand-soft: #e3f2f1;
  --accent: #b4532a;
  --ok: #157f3b; --ok-soft: #e4f4ea;
  --warn: #9a6200; --warn-soft: #fdf1d8;
  --bad: #b42318; --bad-soft: #fde8e6;
  --info: #1d5fa8; --info-soft: #e5eef9;
  --series-1: #257de0; --series-2: #f47230;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.6 "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: clamp(1.4rem, 4vw, 2rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
small, .muted { color: var(--muted); }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.wrap.wide { max-width: 1280px; }

/* header */
.topbar { background: var(--brand); color: var(--brand-ink); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; min-height: 56px; flex-wrap: wrap; }
.topbar a { color: inherit; text-decoration: none; }
.topbar .brand { font-weight: 700; letter-spacing: .2px; }
.topbar .spacer { flex: 1; }
.topbar select { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 8px; padding: 4px 8px; max-width: 260px; }
.topbar select option { color: #000; }

.hero { background: linear-gradient(160deg, #0d6e6e 0%, #0a4f5c 100%); color: #fff; padding: 36px 0 44px; }
.hero .kicker { opacity: .85; font-size: .9rem; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 12px; opacity: .95; font-size: .95rem; }
.hero .actions { margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; }

/* layout */
main { padding: 20px 0 60px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 9px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.light { background: #fff; color: var(--brand); border-color: #fff; }
.btn.ghost-light { background: transparent; color: #fff; border-color: rgba(255,255,255,.55); }
.btn.danger { color: var(--bad); border-color: #f1c4bf; }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: .9rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* forms */
label { display: block; font-weight: 600; font-size: .95rem; margin-bottom: 4px; }
label .req { color: var(--bad); }
.field { margin-bottom: 14px; }
.hint { font-size: .85rem; color: var(--muted); font-weight: 400; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=password],
input[type=date], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: 9px 12px; border: 1px solid #cbd3db; border-radius: 10px; background: #fff; color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 5px; width: 18px; height: 18px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { font-weight: 400; border: 1px solid #cbd3db; border-radius: 999px; padding: 6px 14px; cursor: pointer; margin: 0; background: #fff; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips input:checked + span { color: var(--brand); font-weight: 700; }
.chips label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.likert { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.likert label { text-align: center; border: 1px solid #cbd3db; border-radius: 10px; padding: 8px 2px; cursor: pointer; font-weight: 400; margin: 0; background: #fff; }
.likert label b { display: block; font-size: 1.1rem; }
.likert label small { font-size: .72rem; }
.likert input { position: absolute; opacity: 0; pointer-events: none; }
.likert label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.opts label { font-weight: 400; display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 6px; cursor: pointer; }
.opts label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.opts input { margin-top: 6px; }

/* badges & notices */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-muted { background: #eef1f4; color: var(--muted); }
.notice { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; border: 1px solid transparent; }
.notice.ok { background: var(--ok-soft); border-color: #bfe3cb; }
.notice.warn { background: var(--warn-soft); border-color: #f2d9a6; }
.notice.bad { background: var(--bad-soft); border-color: #f4c5bf; }
.notice.info { background: var(--info-soft); border-color: #c6d9f1; }

/* schedule */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 700; }
.sched { list-style: none; padding: 0; margin: 0; }
.sched li { display: grid; grid-template-columns: 112px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.sched li:last-child { border-bottom: 0; }
.sched .time { font-variant-numeric: tabular-nums; color: var(--brand); font-weight: 700; font-size: .95rem; }
.sched .t-break .title { color: var(--muted); font-weight: 400; }
.sched .title { font-weight: 700; }
.sched .speakers { font-size: .9rem; color: var(--muted); margin-top: 4px; }
@media (max-width: 560px) { .sched li { grid-template-columns: 1fr; gap: 2px; } }

.ann { border-left: 4px solid var(--brand); padding: 4px 0 4px 14px; margin-bottom: 14px; }
.ann.pin { border-left-color: var(--accent); }
.ann .when { font-size: .8rem; color: var(--muted); }

/* tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f3f8f8; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* KPI */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .lbl { color: var(--muted); font-size: .88rem; }
.kpi .val { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .sub { font-size: .82rem; color: var(--muted); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #9aa5b1; }
.live.on::before { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.18); }

/* bars (pure HTML) */
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr 44px; gap: 8px; align-items: center; font-size: .9rem; }
.bar .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track, .bar .fill { display: block; }
.bar .track { height: 14px; background: #eef1f4; border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* code / QR card */
.ticket { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.ticket .qr { background: #fff; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.ticket .code { font-size: 2rem; font-weight: 800; letter-spacing: 2px; color: var(--brand); font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .ticket { grid-template-columns: 1fr; justify-items: center; text-align: center; } }

/* admin shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 56px); }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px; }
.side a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.side a.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.side a:hover { background: var(--surface-2); }
.content { padding: 20px; min-width: 0; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: flex; overflow-x: auto; gap: 4px; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side a { white-space: nowrap; margin: 0; }
  .content { padding: 16px; }
}

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; max-width: 720px; width: 100%; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); }
#toast div { background: #17212b; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
#toast div.err { background: var(--bad); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.slip-img { max-width: 100%; max-height: 70vh; border-radius: 8px; border: 1px solid var(--line); display: block; margin: 0 auto; }
footer.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 0 40px; }
.hide { display: none !important; }
#reader { width: 100%; max-width: 420px; margin: 0 auto; }
@media print { .topbar, .side, .no-print { display: none !important; } .shell { display: block; } }
