/* ==========================================================================
   สไตล์รวมของระบบเช็คอิน — ธีม Clean Light (ขาวคลีน โมเดิร์น อ่านง่ายสบายตา)
   พื้นนวล #f6f8fc · การ์ดขาว · สีเน้นน้ำเงิน #2563eb · เขียว #16a34a
   ฟอนต์: Sarabun (ไทย) + JetBrains Mono (ตัวเลข KPI)
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@600;700;800&display=swap');

:root {
  --brand:        #2563eb;   /* น้ำเงินโมเดิร์น — สีเน้นหลัก */
  --brand-dark:   #1d4ed8;
  --brand-light:  #eaf1fe;   /* น้ำเงินอ่อน (chip / focus / hover) */
  --brand-ink:    #ffffff;   /* ข้อความบนปุ่มน้ำเงิน */
  --bg:           #f6f8fc;
  --surface:      #ffffff;
  --surface-2:    #f7f9fc;   /* หัวตาราง / พื้นซับเทิล */
  --card:         #ffffff;
  --border:       #e9edf3;
  --border-strong:#dde3ec;
  --text:         #1f2733;   /* near-black นุ่มตา */
  --text-muted:   #6b7280;
  --green:        #16a34a;
  --green-light:  #e6f6ec;
  --green-ink:    #ffffff;
  --amber:        #d97706;
  --amber-light:  #fef3c7;
  --red:          #e5484d;
  --red-light:    #fdecec;
  --gray-chip:    #eef1f6;
  --shadow:       0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --shadow-md:    0 4px 14px rgba(16,24,40,.08);
  --shadow-lg:    0 16px 40px rgba(16,24,40,.14);
  --radius:       16px;
  --radius-sm:    10px;
  --font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 700; letter-spacing: -.01em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- ปุ่ม ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 42px;
  padding: .55rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--brand-ink);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .05s, border-color .15s;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(37,99,235,.18);
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.btn-secondary:hover { background: #f4f6fa; border-color: #cfd6e2; }
.btn-ghost { background: transparent; color: var(--brand); box-shadow: none; }
.btn-ghost:hover { background: var(--brand-light); }
.btn-danger { background: var(--red); color: #fff; box-shadow: 0 1px 2px rgba(229,72,77,.2); }
.btn-danger:hover { background: #d13b40; }
.btn-success { background: var(--green); color: #fff; box-shadow: 0 1px 2px rgba(22,163,74,.2); }
.btn-success:hover { background: #15803d; }
.btn-sm { min-height: 36px; padding: .35rem .7rem; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-lg { min-height: 58px; font-size: 1.2rem; padding: 1rem 1.5rem; }

/* ---- อินพุต ----------------------------------------------------------- */
input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: .6rem .8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input::placeholder, textarea::placeholder { color: #9aa2b1; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-light);
}
label { font-weight: 600; font-size: .9rem; display: block; margin-bottom: .3rem; color: var(--text); }
.field { margin-bottom: .95rem; }
.field .req { color: var(--red); }

/* ---- chip / badge สถานะ ---------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .22rem .62rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
}
.chip-gray   { background: var(--gray-chip);   color: var(--text-muted); }
.chip-green  { background: var(--green-light); color: #157f3c; }
.chip-amber  { background: var(--amber-light); color: #92660a; }
.chip-red    { background: var(--red-light);   color: #c0343a; }
.chip-blue   { background: var(--brand-light); color: var(--brand-dark); }

/* ---- โครง layout ------------------------------------------------------ */
.app-header {
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header .title { font-size: 1.15rem; font-weight: 800; margin: 0; color: var(--text); letter-spacing: -.01em; }
.app-header .spacer { flex: 1; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem; }

/* ---- ตาราง ------------------------------------------------------------ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
thead th {
  text-align: left;
  padding: .8rem .9rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  color: var(--text-muted);
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
tbody td { padding: .7rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fbff; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-right: .25rem; }
.checkbox-cell { width: 40px; text-align: center; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }

.empty-state { text-align: center; padding: 3.5rem 1rem; color: var(--text-muted); }

/* ---- stats bar (KPI แบบ dashboard) ----------------------------------- */
.stats { display: flex; gap: .9rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem 1rem 1.35rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: box-shadow .15s, transform .1s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--brand);
}
.stat-card .num {
  font-family: var(--font-mono);
  font-size: 2.1rem; font-weight: 800; line-height: 1.05; letter-spacing: -1.5px;
  color: var(--text);
}
.stat-card .lbl { font-size: .8rem; color: var(--text-muted); font-weight: 600; margin-top: .3rem; }
.stats .stat-card:nth-child(2)::before { background: var(--green); }
.stats .stat-card:nth-child(2) .num { color: #157f3c; }

/* ---- toolbar ---------------------------------------------------------- */
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.1rem; }
.toolbar .search { flex: 1; min-width: 180px; max-width: 320px; }
.toolbar .grow { flex: 1; }

/* ---- modal ------------------------------------------------------------ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, .45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  overflow-y: auto;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  margin: 2.5rem auto;
  animation: pop .16s ease-out;
}
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.35rem;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: 1.35rem; }
.modal-foot {
  padding: 1rem 1.35rem;
  border-top: 1px solid var(--border);
  display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap;
}
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); width: auto; padding: 0 .3rem; }
.form-row { display: flex; gap: .8rem; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 160px; }

/* ---- toast ------------------------------------------------------------ */
#toast-wrap {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .5rem; z-index: 200; width: max-content; max-width: 90vw;
}
.toast {
  background: #1f2733; color: #fff;
  padding: .7rem 1.1rem; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: .95rem;
  animation: slideup .2s ease-out;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.warn { background: var(--amber); }
@keyframes slideup { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---- progress bar ----------------------------------------------------- */
.progress { height: 10px; background: var(--gray-chip); border-radius: 999px; overflow: hidden; margin: .6rem 0; }
.progress > span { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }

/* ---- landing ---------------------------------------------------------- */
.landing {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem 1rem; text-align: center; gap: 1.5rem;
  background: radial-gradient(900px 500px at 50% -5%, #eaf1fe, transparent 60%);
}
.landing .logo { font-size: 3rem; }
.landing h1 { font-size: 2rem; }
.landing .subtitle { color: var(--text-muted); margin-top: -.5rem; }
.landing .choices { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; width: 100%; max-width: 560px; }
.landing .choice {
  flex: 1; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.75rem 1.5rem; box-shadow: var(--shadow); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: .6rem;
  transition: transform .12s, box-shadow .18s, border-color .18s;
}
.landing .choice:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: #cfd9ee; }
.landing .choice .icon { font-size: 2.5rem; }
.landing .choice .name { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.landing .choice .desc { font-size: .9rem; color: var(--text-muted); }

/* ==========================================================================
   หน้าสแกน (scan.html) — mobile-first, ปุ่มใหญ่, ธีมสว่าง
   ========================================================================== */
.scan-body { background: var(--bg); color: var(--text); }
.scan-header {
  padding: .95rem 1rem; text-align: center; font-weight: 800; font-size: 1.1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.tab-btn {
  flex: 1; padding: 1rem .5rem; background: none; border: none; color: var(--text-muted);
  font-family: inherit; font-size: 1.05rem; font-weight: 700; cursor: pointer;
  border-bottom: 3px solid transparent; min-height: 56px;
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { display: none; padding: 1rem; max-width: 560px; margin: 0 auto; }
.tab-panel.active { display: block; }

#qr-reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #0b0b0b; border: 1px solid var(--border); }
#qr-reader video { border-radius: var(--radius); }

.scan-hint { text-align: center; color: var(--text-muted); margin: 1rem 0; font-size: .95rem; }

/* การ์ดผลลัพธ์เต็มจอ */
.result-card {
  position: fixed; inset: 0; z-index: 300;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem; text-align: center; color: #fff;
}
.result-card.show { display: flex; }
.result-card.ok      { background: var(--green); }
.result-card.already { background: var(--amber); }
.result-card.error   { background: var(--red); }
.result-card .rc-icon { font-size: 5rem; line-height: 1; margin-bottom: .5rem; }
.result-card .rc-title { font-size: 2rem; font-weight: 800; margin-bottom: .5rem; }
.result-card .rc-name { font-size: 1.5rem; font-weight: 700; }
.result-card .rc-sub { font-size: 1.1rem; opacity: .92; margin-top: .3rem; }
.result-card .rc-details {
  margin-top: 1.1rem; width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: .5rem;
}
.result-card .rc-details:empty { display: none; }
.result-card .rc-row {
  display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
  background: rgba(255,255,255,.16); border-radius: 10px; padding: .6rem .9rem;
}
.result-card .rc-k { font-size: 1rem; opacity: .9; }
.result-card .rc-v { font-size: 1.2rem; font-weight: 700; text-align: right; word-break: break-word; }
.result-card .rc-btn {
  margin-top: 2rem; background: rgba(255,255,255,.2); color: #fff;
  border: 2px solid #fff; min-height: 56px; font-size: 1.15rem; padding: .8rem 2rem; font-weight: 700;
}
.result-card .rc-btn:hover { background: rgba(255,255,255,.32); }

/* รายการค้นหาในหน้าสแกน */
.search-list { display: flex; flex-direction: column; gap: .6rem; margin-top: 1rem; }
.search-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem;
  display: flex; align-items: center; gap: 1rem; box-shadow: var(--shadow);
}
.search-item .info { flex: 1; min-width: 0; }
.search-item .nm { font-size: 1.15rem; font-weight: 700; }
.search-item .co { color: var(--text-muted); font-size: .9rem; }
.search-item .btn { min-height: 52px; padding: .7rem 1.3rem; font-size: 1.05rem; }
.search-empty { text-align: center; color: var(--text-muted); padding: 2rem 1rem; }

/* ---- ยูทิลิตี้ -------------------------------------------------------- */
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.row-gap { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.warn-box {
  background: var(--amber-light); border: 1px solid #fcd88d; color: #8a5a08;
  padding: .7rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 1rem;
}
.preview-box { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 1rem; background: #fafbfe; }

/* ตารางแมป CSV */
.map-table td { padding: .4rem .5rem; }
.map-table select { min-width: 140px; }

@media (max-width: 640px) {
  .app-header { padding: .6rem .8rem; }
  .container { padding: .85rem; }
  thead th, tbody td { padding: .55rem .6rem; font-size: .85rem; }
  .stat-card .num { font-size: 1.7rem; }
}

/* ==========================================================================
   ฟอร์มลงทะเบียนที่ออกแบบเอง (GrapesJS reg-designer) — สไตล์พื้นฐาน .rf-*
   ใช้ทั้งในหน้า designer (canvas) และหน้า register.html สาธารณะ
   ========================================================================== */
.rf-wrap { max-width: 560px; margin: 0 auto; padding: 8px; }
.rf-title { text-align: center; font-size: 1.5rem; font-weight: 800; color: #1f2733; margin: .2rem 0 .3rem; }
.rf-desc { text-align: center; color: #6b7280; font-size: .95rem; margin: 0 0 1.2rem; line-height: 1.5; }
.rf-form { max-width: 520px; margin: 0 auto; }
.rf-group { margin-bottom: 1rem; }
.rf-label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: .35rem; color: #1f2733; }
.rf-hint { font-weight: 400; color: #6b7280; }
.rf-req { color: #e5484d; }
.rf-input, .rf-select, .rf-textarea {
  width: 100%; padding: .8rem .9rem; border: 1px solid #dde3ec; background: #fff; color: #1f2733;
  border-radius: 10px; font-family: inherit; font-size: 1rem;
}
.rf-input::placeholder, .rf-textarea::placeholder { color: #9aa2b1; }
.rf-input:focus, .rf-select:focus, .rf-textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 4px #eaf1fe; }
.rf-textarea { min-height: 92px; resize: vertical; }
.rf-hr { border: none; border-top: 1px solid #e9edf3; margin: 1.2rem 0; }
.rf-img { max-width: 100%; display: block; margin: 0 auto 1rem; }
.rf-submit {
  width: 100%; margin-top: .5rem; padding: .9rem; background: #2563eb; color: #fff; border: none;
  border-radius: 10px; font-family: inherit; font-size: 1.05rem; font-weight: 700; cursor: pointer;
}
.rf-submit:hover { background: #1d4ed8; }
.rf-submit:disabled { opacity: .55; cursor: default; }
