/* ทะเบียนนักกีฬาสี - หน้าจอมือถือเป็นหลัก + หน้าพิมพ์ A4 */
:root {
  --bg: #F4F5F7; --surface: #FFFFFF; --surface2: #F0F2F5; --ink: #1F2328; --muted: #5F6670; --line: #E1E4E8; --field: #B9BFC7;
  --primary: #1F5FAD; --primary-deep: #174A88; --primary-soft: #E5EEF9;
  --bad: #B3261E; --bad-soft: #FBE7E4; --warn: #7A4A00; --warn-soft: #FFF1D6; --ok: #1E7A45; --ok-soft: #E2F4E8;
  --team: #1F5FAD; --team-soft: #E5EEF9;
  --radius: 18px; --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 6px 20px rgba(20, 30, 50, .06);
  --font: "Noto Sans Thai", system-ui, -apple-system, "Thonburi", sans-serif;
  --nav-h: 66px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
#app { padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); min-height: 100vh; }
#app.no-nav { padding-bottom: 24px; }
#print { display: none; }
a { color: var(--primary); }
h2 { font-size: 20px; margin: 0 0 4px; line-height: 1.35; }
h3 { font-size: 17px; margin: 0 0 8px; }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

/* แถบบน */
header.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
header.top .in { max-width: 760px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 12px; align-items: center; }
header.top img { width: 38px; height: 38px; border-radius: 50%; flex: none; }
header.top .title { flex: 1; min-width: 0; line-height: 1.3; }
header.top .title b { display: block; font-size: 16px; }
header.top .title small { color: var(--muted); font-size: 13px; }
.team-bar { height: 5px; background: var(--team); }

/* ปุ่มและช่องกรอก */
button, .btn { font: inherit; font-weight: 600; min-height: 44px; padding: 8px 18px; border-radius: var(--radius-sm); border: 0; background: var(--primary); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.3; text-decoration: none; }
button:hover:not(:disabled) { background: var(--primary-deep); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost, .btn.ghost { background: var(--surface); color: var(--primary-deep); border: 1.5px solid var(--field); font-weight: 500; }
button.ghost:hover:not(:disabled) { background: var(--primary-soft); }
button.danger { background: var(--surface); color: var(--bad); border: 1.5px solid #E7B4AE; font-weight: 500; }
button.danger:hover:not(:disabled) { background: var(--bad-soft); }
button.sm { min-height: 36px; padding: 4px 12px; font-size: 14px; }
button.team { background: var(--team); }
button.link { background: none; color: var(--primary); padding: 4px 6px; min-height: 0; font-weight: 500; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
input, select, textarea { font: inherit; width: 100%; min-height: 44px; padding: 8px 12px; border: 1.5px solid var(--field); border-radius: var(--radius-sm); background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid #9CC2F0; outline-offset: 1px; }
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; vertical-align: middle; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }

/* การ์ด */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 15px; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.badge { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.badge.m { background: #E3EDFB; color: #1D4F91; }
.badge.f { background: #FBE6EF; color: #9A2457; }
.badge.x { background: #EDE7F8; color: #4E3796; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; margin-right: 4px; }

/* หน้าเข้าสู่ระบบ */
.login { max-width: 460px; margin: 0 auto; padding: 28px 16px; }
.login .brand { text-align: center; margin-bottom: 20px; }
.login .brand img { width: 84px; height: 84px; border-radius: 50%; }
.login .brand h1 { font-size: 22px; margin: 10px 0 2px; }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.colors button { min-height: 76px; font-size: 19px; border-radius: var(--radius); color: #fff; }
.colors button.on { outline: 4px solid #1F2328; outline-offset: 2px; }

/* ตัวกรอง */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chips button { flex: none; min-height: 38px; padding: 4px 14px; font-weight: 500; background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); border-radius: 999px; }
.chips button.on { background: var(--team); border-color: var(--team); color: #fff; }

/* รายการแข่ง */
.cat { margin: 20px 0 8px; font-size: 15px; color: var(--muted); font-weight: 700; letter-spacing: .2px; }
.ev { display: flex; gap: 12px; align-items: center; background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 12px 14px; cursor: pointer; border: 0; width: 100%; text-align: left; color: var(--ink); font-weight: 400; }
.ev:hover:not(:disabled) { background: #FAFBFC; }
.ev + .ev { margin-top: 8px; }
.ev .nm { font-weight: 600; }
.ev .meta { font-size: 13.5px; color: var(--muted); }
.count { flex: none; text-align: center; min-width: 58px; }
.count b { font-size: 20px; display: block; line-height: 1.1; }
.count small { font-size: 12px; color: var(--muted); }
.count.full b { color: var(--ok); }
.bar { height: 6px; background: var(--surface2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--team); border-radius: 99px; }
.closed { opacity: .65; }

/* รายชื่อคน */
.person { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.person:first-child { border-top: 0; }
.person .who { flex: 1; min-width: 0; }
.person .who b { font-weight: 600; }
.person .who .meta { font-size: 13.5px; color: var(--muted); }
.sessions { margin: 8px 0 0; padding: 0; list-style: none; }
.sessions li { padding: 6px 10px; background: var(--surface2); border-radius: 10px; font-size: 14.5px; }
.sessions li + li { margin-top: 6px; }

/* แถบล่าง */
nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.bottom .in { max-width: 760px; margin: 0 auto; display: flex; }
nav.bottom a { flex: 1; text-align: center; padding: 8px 4px; min-height: var(--nav-h); text-decoration: none; color: var(--muted); font-size: 13px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
nav.bottom a svg { width: 24px; height: 24px; }
nav.bottom a.on { color: var(--team); font-weight: 700; }

/* ตาราง (ภาพรวมแอดมิน) */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); }
.tbl th, .tbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: var(--surface2); font-weight: 600; position: sticky; top: 0; }
.tbl td.c { text-align: center; white-space: nowrap; }
.tbl .full { color: var(--ok); font-weight: 700; }
.tbl .empty { color: var(--bad); }
.scroll-x { overflow-x: auto; border-radius: var(--radius-sm); box-shadow: var(--shadow); }

/* ป้ายแจ้ง */
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1F2328; color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 15px; z-index: 50; max-width: calc(100vw - 32px); opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); }

.session-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; background: var(--surface2); border-radius: var(--radius-sm); margin-bottom: 8px; }
.session-row .full { grid-column: 1 / -1; }

/* ---------- หน้าพิมพ์ ---------- */
.sheet { font-family: "Sarabun", "TH Sarabun New", "TH SarabunPSK", var(--font); color: #000; background: #fff; }
.sheet .page { padding: 0; page-break-after: always; break-after: page; }
.sheet .page:last-child { page-break-after: auto; break-after: auto; }
.sheet .head { display: flex; gap: 12px; align-items: center; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 10px; }
.sheet .head img { width: 54px; height: 54px; }
.sheet .head .t { flex: 1; line-height: 1.3; }
.sheet .head .t b { font-size: 17pt; display: block; }
.sheet .head .t span { font-size: 13pt; }
.sheet .room { font-size: 19pt; font-weight: 700; margin: 4px 0 8px; display: flex; gap: 10px; align-items: center; }
.sheet .chip { display: inline-block; padding: 1px 12px; border-radius: 999px; color: #fff; font-size: 14pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 13.5pt; }
.sheet th, .sheet td { border: 1px solid #555; padding: 3px 6px; vertical-align: top; line-height: 1.3; }
.sheet th { background: #EEE; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sheet td.c { text-align: center; }
.sheet tr { page-break-inside: avoid; break-inside: avoid; }
.sheet .foot { margin-top: 12px; font-size: 12.5pt; display: flex; justify-content: space-between; gap: 12px; }
.sheet .slips { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.sheet .slip { border: 1px dashed #777; padding: 8px 10px; page-break-inside: avoid; break-inside: avoid; font-size: 13pt; line-height: 1.35; }
.sheet .slip .nm { font-size: 15pt; font-weight: 700; }
.sheet .slip ul { margin: 4px 0 0; padding-left: 18px; }
.sheet .evblock { page-break-inside: avoid; break-inside: avoid; margin-bottom: 12px; }
.sheet .evblock h4 { font-size: 15pt; margin: 0 0 2px; }
.sheet .evblock .when { font-size: 12.5pt; margin-bottom: 4px; }
.preview { background: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 16px; overflow-x: auto; }
.preview .page { border-bottom: 2px dashed #CCC; padding-bottom: 16px; margin-bottom: 16px; }

@page { size: A4 portrait; margin: 12mm 12mm 14mm; }
@media print {
  body { background: #fff; }
  #app, #toast { display: none !important; }
  #print { display: block !important; }
}
