/* TSC Site Induction — กระดานตารางอบรมหน้าไซต์งาน */
:root {
  --ink: #1d1b2e;
  --muted: #5e6066;
  --brand: #5b2a9e;
  --brand-ink: #3a1c6b;
  --brand-wash: #f1ebf9;
  --concrete: #e9eae6;
  --paper: #ffffff;
  --line: #d3d4cf;
  --vest: #f2c200;
  --go: #2f7d3b;
  --go-wash: #e6f2e7;
  --stop: #b83227;
  --stop-wash: #f8e7e5;
  --wait: #8a5a00;
  --wait-wash: #fdf3d6;

  --f-display: "Chakra Petch", "IBM Plex Sans Thai", sans-serif;
  --f-body: "IBM Plex Sans Thai", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, monospace;

  --r: 6px;
  --shadow: 0 1px 0 rgba(29, 27, 46, .06), 0 2px 8px rgba(29, 27, 46, .05);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--concrete);
  color: var(--ink);
  font: 400 16px/1.6 var(--f-body);
}
img { max-width: 100%; display: block; }
a { color: var(--brand); }
h1, h2, h3 { font-family: var(--f-display); line-height: 1.25; margin: 0; letter-spacing: .005em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.2rem); font-weight: 600; }
h2 { font-size: 1.35rem; font-weight: 600; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0; }
.mono { font-family: var(--f-mono); letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--vest); outline-offset: 2px; border-radius: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- โครงหน้า ---------- */
.wrap { width: min(1100px, 100% - 32px); margin-inline: auto; }

.topbar { background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .wrap { display: flex; align-items: center; gap: 16px; min-height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); margin-right: auto; }
.brand img { width: 40px; height: 40px; object-fit: contain; }
.brand b { font-family: var(--f-display); font-size: 1.05rem; font-weight: 600; display: block; line-height: 1.1; }
.brand span { font-size: .78rem; color: var(--muted); letter-spacing: .04em; }
.nav { display: flex; gap: 4px; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: var(--r);
  font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; gap: 6px;
}
.nav a:hover { color: var(--ink); background: var(--concrete); }
.nav a[aria-current="page"] { color: var(--brand-ink); box-shadow: inset 0 -3px 0 var(--brand); border-radius: 0; }

main { padding: 28px 0 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.page-head p { color: var(--muted); max-width: 60ch; margin-top: 4px; }

.rules { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: .875rem; color: var(--muted); margin-bottom: 24px; padding-left: 0; list-style: none; }
.rules li { display: flex; align-items: center; gap: 6px; }
.rules svg { color: var(--brand); flex: none; }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.panel-pad { padding: 20px; }

footer { color: var(--muted); font-size: .8rem; padding: 24px 0 40px; border-top: 1px solid var(--line); }

/* ---------- ปุ่ม / ฟอร์ม ---------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: var(--r); cursor: pointer;
  font: 500 .95rem/1 var(--f-body); padding: 0 16px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--brand); color: #fff; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--brand-ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--brand-ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--brand); background: var(--brand-wash); }
.btn.go { background: var(--go); } .btn.go:hover { background: #24622e; }
.btn.stop { background: transparent; color: var(--stop); border-color: #e3b8b3; } .btn.stop:hover { background: var(--stop-wash); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn[aria-busy="true"] { pointer-events: none; opacity: .7; }

.field { display: grid; gap: 6px; }
.field > span { font-size: .875rem; font-weight: 500; }
.field small { color: var(--muted); font-size: .8rem; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #bfc0bb; border-radius: var(--r);
  background: #fff; color: var(--ink); font: inherit;
}
textarea.input { min-height: 72px; resize: vertical; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(91, 42, 158, .18); }
.input[readonly] { background: #f6f6f4; color: #3b3a46; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; }
.inline-form .input { flex: 1; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); padding: 3px; }
.seg button {
  border: 0; background: transparent; font: 500 .875rem var(--f-body); color: var(--muted);
  padding: 0 14px; min-height: 36px; border-radius: 4px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--brand-wash); color: var(--brand-ink); }

/* ---------- สถานะ ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.Pending, .chip.CancelRequested, .chip.MoveRequested { color: var(--wait); background: var(--wait-wash); }
.chip.Approved, .chip.Open { color: var(--go); background: var(--go-wash); }
.chip.Rejected, .chip.Cancelled, .chip.Closed, .chip.Full { color: var(--stop); background: var(--stop-wash); }

/* ---------- การ์ดพื้นที่ / โครงการ ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: .875rem; color: var(--muted); margin-bottom: 12px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--brand); text-decoration: underline; }
.crumbs [aria-current] { color: var(--ink); font-weight: 500; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: 8px; min-height: 180px; padding: 18px 18px 14px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none; position: relative; transition: border-color .15s, transform .15s;
}
/* ขอบบนสีม่วงบางๆ เหมือนแถบป้ายไซต์ */
.card::before { content: ""; position: absolute; left: -1px; right: -1px; top: -1px; height: 4px; background: var(--brand); border-radius: var(--r) var(--r) 0 0; }
.card:hover { border-color: var(--brand); transform: translateY(-2px); }
.card h2 { font-size: 1.3rem; }
.card-kicker { font-size: .8rem; color: var(--brand); font-weight: 600; letter-spacing: .03em; }
.card .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 3px; background: var(--concrete); color: var(--ink); }
.card-foot { margin-top: auto; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; justify-content: space-between; align-items: center; font-size: .875rem; color: var(--muted); }
.card:hover .card-foot { color: var(--brand-ink); }

/* ---------- ตารางรอบอบรม ---------- */
.today {
  position: relative; padding: 18px 20px 18px 26px; margin-bottom: 28px;
}
/* แถบสีเสื้อสะท้อนแสง ใช้ที่เดียวคือ "วันนี้" */
.today::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; border-radius: var(--r) 0 0 var(--r);
  background: repeating-linear-gradient(-45deg, var(--vest) 0 8px, var(--ink) 8px 16px);
}
.today-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.today-head h2 { font-size: 1.1rem; }
.today-list { display: grid; gap: 8px; }
.today-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 12px; align-items: center; padding: 8px 0; border-top: 1px dashed var(--line); }
.today-row:first-child { border-top: 0; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

.day { display: grid; grid-template-columns: 96px 1fr; gap: 20px; padding: 18px 0; border-top: 1px solid var(--line); }
.day:first-of-type { border-top: 0; }
.datestamp { text-align: left; font-family: var(--f-display); line-height: 1; padding-top: 4px; }
.datestamp .d { font-size: 2.6rem; font-weight: 600; color: var(--brand-ink); }
.datestamp .w { display: block; margin-top: 6px; font-size: .9rem; font-weight: 500; }
.datestamp .m { display: block; font-size: .8rem; color: var(--muted); margin-top: 2px; font-family: var(--f-body); }
.sessions { display: grid; gap: 10px; }

.session {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 20px; align-items: center;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px;
}
.session.is-closed { background: #f6f6f4; }
.session .time { font-family: var(--f-mono); font-size: .875rem; color: var(--brand-ink); font-weight: 500; }
.session h3 { margin: 2px 0 4px; }
.session .meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .875rem; color: var(--muted); }
.session .meta span { display: inline-flex; align-items: center; gap: 5px; }
.session .side { display: grid; gap: 8px; justify-items: end; }
.session .note { grid-column: 1 / -1; font-size: .8rem; color: var(--stop); }

/* แผงที่นั่ง: 1 ช่อง = 1 ที่นั่ง (ช่องทึบ = อนุมัติแล้ว) */
.seats { display: grid; gap: 4px; justify-items: end; }
.seat-grid { display: flex; flex-wrap: wrap; gap: 3px; max-width: 210px; justify-content: flex-end; }
.seat-grid i { width: 9px; height: 9px; border-radius: 2px; border: 1.5px solid #a7a0b8; }
.seat-grid i.on { background: var(--brand); border-color: var(--brand); }
.seat-grid.dense i { width: 6px; height: 6px; border-width: 1px; border-radius: 1px; }
.seats-label { font-size: .8rem; color: var(--muted); }
.seats-label b { color: var(--ink); font-family: var(--f-mono); font-weight: 600; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

/* ปฏิทิน */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head h3 { min-width: 160px; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.cal > div { background: var(--paper); min-height: 96px; padding: 6px; font-size: .8rem; }
.cal .dow { min-height: 0; text-align: center; font-weight: 600; background: #f6f6f4; padding: 6px; }
.cal .off { background: #f3f3f1; color: #9a9ba0; }
.cal .sun { background: repeating-linear-gradient(-45deg, #f3f3f1 0 6px, #ececea 6px 12px); }
.cal .num { font-family: var(--f-mono); font-weight: 500; }
.cal .is-today .num { background: var(--vest); color: var(--ink); padding: 0 5px; border-radius: 3px; }
.cal button.ev {
  display: block; width: 100%; text-align: left; margin-top: 4px; border: 0; border-left: 3px solid var(--brand);
  background: var(--brand-wash); color: var(--brand-ink); font: 500 .75rem/1.3 var(--f-body); padding: 3px 5px; border-radius: 2px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal button.ev.closed { border-color: #a7a8ad; background: #efefed; color: var(--muted); }

/* ---------- ขั้นตอนจอง ---------- */
.book-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.step { padding: 20px; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; }
.step-head { display: flex; gap: 12px; align-items: baseline; margin-bottom: 14px; }
.step-no { font-family: var(--f-display); font-weight: 600; color: var(--brand); font-size: 1.05rem; min-width: 1.5em; }
.step.locked { opacity: .5; pointer-events: none; }
.step.done .step-no { color: var(--go); }

.people { display: grid; gap: 8px; margin-top: 12px; }
.person {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; text-align: left;
  border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; background: #fff; cursor: pointer; font: inherit; color: inherit;
}
.person:hover { border-color: var(--brand); }
.person[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-wash); box-shadow: inset 3px 0 0 var(--brand); }
.person .sub { font-size: .8rem; color: var(--muted); }

.picked { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px; background: var(--brand-wash); border-radius: var(--r); }

.course-pick { display: grid; gap: 8px; }
.course-opt { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; cursor: pointer; }
.course-opt:has(input:checked) { border-color: var(--brand); background: var(--brand-wash); }
.course-opt input { width: 18px; height: 18px; accent-color: var(--brand); }
.course-opt.disabled { opacity: .55; cursor: not-allowed; }

.summary { position: sticky; top: 84px; }
.summary dl { margin: 0; display: grid; gap: 10px; }
.summary dt { font-size: .78rem; color: var(--muted); }
.summary dd { margin: 0; font-weight: 500; }

/* ใบนัด */
.ticket { max-width: 560px; margin: 0 auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.ticket-top { padding: 20px 24px; border-bottom: 2px dashed var(--line); display: flex; justify-content: space-between; gap: 16px; align-items: start; }
.ticket-ref { font-family: var(--f-mono); font-size: 1.35rem; font-weight: 600; color: var(--brand-ink); letter-spacing: .03em; }
.ticket-body { padding: 20px 24px; display: grid; gap: 12px; }
.ticket-body dl { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; }
.ticket-body dt { color: var(--muted); font-size: .875rem; }
.ticket-body dd { margin: 0; }
.ticket-foot { padding: 14px 24px; background: #f6f6f4; font-size: .875rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; align-items: center; }

/* ผลค้นหาสถานะ */
.results { display: grid; gap: 10px; }
.result { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 14px 16px; }
.result .actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- แจ้งเตือน / dialog ---------- */
.notice { padding: 10px 12px; border-radius: var(--r); font-size: .9rem; border: 1px solid; }
.notice.err { background: var(--stop-wash); border-color: #e3b8b3; color: #7d1f17; }
.notice.ok { background: var(--go-wash); border-color: #b5d6b8; color: #1d5426; }
.notice.info { background: #f6f6f4; border-color: var(--line); color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--r); font-size: .95rem; max-width: calc(100% - 32px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.toast.err { background: var(--stop); }

dialog { border: 0; border-radius: var(--r); padding: 0; width: min(480px, calc(100% - 32px)); color: var(--ink); box-shadow: 0 16px 48px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(29, 27, 46, .45); }
.dlg-body { padding: 20px; display: grid; gap: 14px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; background: #f6f6f4; }
dialog.wide { width: min(760px, calc(100% - 32px)); }

.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 32px; color: var(--muted); }

/* ---------- ส่วนผู้ดูแล ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tabs button {
  border: 0; background: none; font: 500 .95rem var(--f-body); color: var(--muted); padding: 10px 14px; min-height: 44px; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--brand-ink); box-shadow: inset 0 -3px 0 var(--brand); }
.tabs .count { font-family: var(--f-mono); font-size: .75rem; background: var(--wait-wash); color: var(--wait); padding: 1px 6px; border-radius: 999px; margin-left: 4px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat b { display: block; font-family: var(--f-display); font-size: 1.9rem; font-weight: 600; line-height: 1.1; }
.stat span { font-size: .85rem; color: var(--muted); }

.table-wrap { overflow-x: auto; }
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-size: .78rem; font-weight: 600; color: var(--muted); background: #f6f6f4; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .sub { display: block; font-size: .8rem; color: var(--muted); }
td.num { font-family: var(--f-mono); white-space: nowrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.bulkbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--brand-wash); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }

.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(0, 220px) 1fr 48px; gap: 10px; align-items: center; font-size: .875rem; }
.bar .track { height: 10px; background: var(--concrete); border-radius: 2px; overflow: hidden; }
.bar .track i { display: block; height: 100%; background: var(--brand); }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.quota-rows { display: grid; gap: 8px; }
.quota-row { display: grid; grid-template-columns: 1fr 100px auto; gap: 8px; }

.login-box { max-width: 380px; margin: 40px auto; }

.check .mono { white-space: nowrap; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 20px; margin: 0; }
.kv dt { font-size: .78rem; color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.seg.att button { padding: 0 10px; min-height: 32px; }
.seg.att button[aria-pressed="true"][data-att="Passed"] { background: var(--go-wash); color: var(--go); }
.seg.att button[aria-pressed="true"][data-att="Failed"], .seg.att button[aria-pressed="true"][data-att="Absent"] { background: var(--stop-wash); color: var(--stop); }
.check-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-top: 8px; max-height: 45vh; overflow: auto; }
.check-group { border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px 10px; margin: 0; }
.check-group legend { font-weight: 600; font-size: .9rem; padding: 0 4px; }
.check-group legend label, .check { display: flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; }

/* ---------- จอเล็ก ---------- */
@media (max-width: 860px) {
  .book-layout { grid-template-columns: 1fr; }
  .summary { position: static; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .topbar .wrap { flex-wrap: wrap; gap: 4px; padding: 8px 0; }
  .nav { width: 100%; overflow-x: auto; }
  .nav a { padding: 6px 10px; font-size: .9rem; }
  .day { grid-template-columns: 1fr; gap: 10px; }
  .datestamp { display: flex; align-items: baseline; gap: 10px; }
  .datestamp .d { font-size: 1.8rem; }
  .datestamp .w, .datestamp .m { display: inline; margin: 0; }
  .session { grid-template-columns: 1fr; }
  .session .side { justify-items: start; grid-template-columns: 1fr auto; align-items: end; }
  .seats { justify-items: start; }
  .seat-grid { justify-content: flex-start; }
  .grid-2 { grid-template-columns: 1fr; }
  .today-row { grid-template-columns: 1fr; gap: 2px; }
  .cal > div { min-height: 64px; padding: 3px; }
  .cal button.ev { font-size: .68rem; padding: 2px 3px; }
  .ticket-body dl { grid-template-columns: 1fr; gap: 2px; }
  .ticket-body dd { margin-bottom: 8px; }
  .bar { grid-template-columns: 1fr 40px; }
  .bar .track { grid-column: 1 / -1; grid-row: 2; }
  .inline-form { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .topbar, footer, .no-print { display: none !important; }
  body { background: #fff; }
  .ticket { box-shadow: none; }
}
