/* หน้าสแกนในแอป (scan-hub.js · เจ้าของระบบ 28 ต.ค. 2569)
   เต็มจอ: หัว (โหมด/กิจกรรมของทีมงาน) · กล้องครึ่งบน · ปุ่ม QR ของฉัน · รายการที่สแกนได้ + ปุ่มยืนยันครึ่งล่าง
   ปุ่ม "สแกน" ขวาสุดของเมนูล่าง: เมนูล่างเป็น 3 ช่อง */
.bottom-nav:has(#scanNavBtn) {
  grid-template-columns: 1fr 1fr 1fr;
}
.bottom-nav #scanNavBtn,
.healthy-formal .bottom-nav #scanNavBtn,
.healthy-formal .bottom-nav #scanNavBtn:hover {
  background: #256e45 !important;
  color: #fff !important;
}
.healthy-formal .bottom-nav #scanNavBtn .material-symbols-rounded {
  background: transparent !important;
  color: #fff !important;
}

html.scan-hub-open,
html.scan-hub-open body {
  overflow: hidden;
}
.scan-hub {
  position: fixed;
  inset: 0;
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: #f4f6f4;
  color: #17211c;
  overscroll-behavior: contain;
}
/* รายการที่สแกนได้สูงอย่างน้อย 9rem เสมอ (เจ้าของระบบ 29 ต.ค. 2569: จอมือถือที่มีแถบเบราว์เซอร์ หัว "รายการที่สแกนได้" ตกกรอบ)
   พื้นที่ไม่พอ = กล้องเตี้ยลงแทน (แถวกล้องโตได้ถึง 46dvh เฉพาะเมื่อเหลือที่) */
.scan-hub[open] {
  /* ขนาดกรอบเล็ง: ไม่เกิน 62% ของความกว้าง 280px และความสูงกล้อง (เหลือที่ให้ข้อความเหนือกรอบ) */
  --sh-frame: min(62vw, 280px, calc(46dvh - 90px));
  display: grid;
  grid-template-rows: auto minmax(0, 46dvh) auto auto minmax(9rem, 1fr);
}
/* ทีมงาน: หัวมีแถบโหมด+กิจกรรม และต้องเห็นรายชื่อหลายคน → กล้องเตี้ยลง */
.scan-hub[open]:is([data-mode='checkin'], [data-mode='finish']) {
  --sh-frame: min(62vw, 280px, calc(36dvh - 90px));
  grid-template-rows: auto minmax(0, 36dvh) auto auto minmax(9rem, 1fr);
}
/* QR ของฉัน: ไม่ต้องใช้รายการ ให้ QR ใหญ่เต็มที่ */
.scan-hub[open][data-view='qr'] {
  grid-template-rows: auto minmax(0, 1fr) auto auto 0;
}
.scan-hub[data-view='qr'] .sh-list,
.scan-hub[data-view='qr'] .sh-status {
  display: none;
}
.scan-hub[data-view='qr'] .sh-switch {
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.scan-hub::backdrop {
  background: rgba(10, 20, 15, 0.6);
}

.sh-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 10px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: #fff;
  border-bottom: 1px solid #e3e8e5;
}
.sh-close {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #eef1ef;
  color: #17211c;
  cursor: pointer;
}
.sh-modes,
.sh-events {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
}
/* ไม่มีหัว "สแกน QR" (เจ้าของระบบ 28 ต.ค. 2569): แถบโหมดอยู่แถวเดียวกับปุ่มปิด */
.sh-modes {
  grid-column: 1;
  grid-row: 1;
}
.sh-modes button[hidden] {
  display: none;
}
.sh-modes[hidden],
.sh-events[hidden] {
  display: none;
}
.sh-modes {
  padding: 4px;
  border-radius: 14px;
  background: #eef1ef;
}
.sh-modes button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #4b564f;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.sh-modes button .material-symbols-rounded {
  font-size: 19px;
}
.sh-modes button[aria-checked='true'] {
  background: #fff;
  color: #194e31;
  box-shadow: 0 1px 4px rgba(23, 33, 28, 0.14);
}
.scan-hub[data-mode='finish'] .sh-modes button[aria-checked='true'] {
  color: #9a3412;
}
.sh-events {
  overflow-x: auto;
  scrollbar-width: none;
}
.sh-events button {
  flex: none;
  display: grid;
  gap: 1px;
  max-width: 220px;
  padding: 6px 12px;
  border: 1px solid #d9dfdb;
  border-radius: 12px;
  background: #fff;
  color: #17211c;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.sh-events button strong {
  overflow: hidden;
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sh-events button small {
  color: #69716b;
  font-size: 0.76rem;
}
.sh-events button[aria-checked='true'] {
  border-color: #256e45;
  background: #eaf5ee;
  box-shadow: inset 0 0 0 1px #256e45;
}

.sh-stage {
  position: relative;
  overflow: hidden;
  background: #0d1410;
}
.sh-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.sh-frame {
  position: absolute;
  inset: 50% auto auto 50%;
  width: var(--sh-frame, min(62%, 280px));
  aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 22px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.32);
  transform: translate(-50%, -50%);
  transition: border-color 0.2s ease;
}
.scan-hub.is-hit .sh-frame {
  animation: sh-hit 0.5s ease;
}
@keyframes sh-hit {
  30% {
    border-color: #4ade80;
    transform: translate(-50%, -50%) scale(1.04);
  }
}
.scan-hub[data-view='qr'] .sh-stage {
  background: #fff;
}
.scan-hub[data-view='qr'] .sh-stage video,
.scan-hub[data-view='qr'] .sh-frame {
  display: none;
}
.sh-myqr {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  padding: 12px;
  text-align: center;
}
.sh-myqr[hidden] {
  display: none;
}
/* พื้นกล้องสีดำขึ้นไปถึงขอบบนของจอ (เจ้าของระบบ 28 ต.ค. 2569): หัวลอยทับกล้อง · --sh-top-h = ความสูงหัว (scan-hub.js วัดให้)
   กรอบเล็งและ QR ของฉันอยู่กลางพื้นที่ใต้หัว */
.scan-hub[open] > .sh-top {
  grid-row: 1;
  grid-column: 1;
  z-index: 2;
  align-self: start;
  background: transparent;
  border-bottom: 0;
}
.scan-hub[open] > .sh-stage {
  grid-row: 1 / 3;
  grid-column: 1;
}
.scan-hub[open] > .sh-switch {
  grid-row: 3;
}
/* ข้อความสถานะ ("ส่องกล้องไปที่ QR …" / ผลที่อ่านได้) ลอยบนกล้อง เหนือกรอบเล็งสีขาว (เจ้าของระบบ 29 ต.ค. 2569)
   กลางพื้นที่กล้อง แล้วเลื่อนขึ้นครึ่งกรอบ (--sh-frame) + ช่องว่าง 10px */
.scan-hub[open] > .sh-status {
  grid-row: 1 / 3;
  grid-column: 1;
  z-index: 1;
  align-self: center;
  justify-self: center;
  max-width: min(92vw, 420px);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(10, 20, 15, 0.62);
  color: #fff;
  backdrop-filter: blur(6px);
  transform: translateY(calc(var(--sh-top-h, 0px) / 2 - var(--sh-frame, 280px) / 2 - 50% - 10px));
}
.scan-hub[open] > .sh-status:empty {
  display: none;
}
.scan-hub[open] > .sh-status[data-tone='ok'] {
  background: rgba(21, 128, 61, 0.92);
  color: #fff;
}
.scan-hub[open] > .sh-status[data-tone='error'] {
  background: rgba(180, 35, 24, 0.92);
  color: #fff;
}
.scan-hub[open] > .sh-list {
  grid-row: 5;
}
.sh-frame {
  top: calc(50% + var(--sh-top-h, 0px) / 2);
}
.sh-myqr {
  top: var(--sh-top-h, 0px);
}
.scan-hub:not([data-view='qr']) .sh-modes {
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
}
.scan-hub:not([data-view='qr']) .sh-modes button:not([aria-checked='true']) {
  color: #e7ece9;
}
.scan-hub:not([data-view='qr']) .sh-close {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  backdrop-filter: blur(10px);
}
.scan-hub:not([data-view='qr']) .sh-events button:not([aria-checked='true']) {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(13, 20, 16, 0.55);
  color: #fff;
}
.scan-hub:not([data-view='qr']) .sh-events button:not([aria-checked='true']) small {
  color: #c9d1cc;
}
.sh-qr {
  width: min(78vw, 50dvh, 340px);
  aspect-ratio: 1;
}
.sh-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}
.sh-qr.is-loading {
  border-radius: 16px;
  background: #eef1ef;
}
.sh-qr-note {
  margin: 4px 0 0;
  font-weight: 700;
}
.sh-qr-timer {
  margin: 0;
  color: #5f6761;
  font-size: 0.88rem;
}
.sh-link {
  border: 0;
  background: none;
  color: #194e31;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.sh-switch {
  display: flex;
  justify-content: center;
  padding: 10px 14px 0;
}
.sh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 20px;
  border: 1.5px solid #256e45;
  border-radius: 999px;
  background: #fff;
  color: #194e31;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.sh-toggle[hidden] {
  display: none;
}
.sh-status {
  min-height: 1.5em;
  margin: 8px 16px 0;
  color: #4b564f;
  font-size: 0.92rem;
  text-align: center;
}
.sh-status[data-tone='ok'] {
  color: #15803d;
  font-weight: 700;
}
.sh-status[data-tone='error'] {
  color: #b42318;
  font-weight: 700;
}

.sh-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  margin: 8px 12px max(12px, env(safe-area-inset-bottom));
  padding: 12px;
  border: 1px solid #e3e8e5;
  border-radius: 18px;
  background: #fff;
}
.sh-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.sh-list-head h3 {
  margin: 0;
  font-size: 1rem;
}
.sh-count {
  color: #194e31;
  font-weight: 800;
}
.sh-items {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.sh-empty {
  padding: 18px 8px;
  color: #7a817c;
  text-align: center;
}
.sh-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: 'lead main action remove';
  align-items: center;
  gap: 6px 10px;
  padding: 10px 2px;
  border-bottom: 1px solid #edf0ee;
}
.sh-item:last-child {
  border-bottom: 0;
}
.sh-item.is-done {
  opacity: 0.72;
}
.sh-item.is-skip .sh-main {
  opacity: 0.6;
}
.sh-main {
  display: grid;
  min-width: 0;
}
.sh-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sh-main small {
  color: #69716b;
  font-size: 0.8rem;
}
.sh-bib {
  min-width: 52px;
  padding: 4px 8px;
  border-radius: 10px;
  background: #eaf5ee;
  color: #194e31;
  font-weight: 800;
  text-align: center;
}
.sh-badge {
  padding: 4px 9px;
  border-radius: 999px;
  background: #eaf5ee;
  color: #194e31;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}
.sh-badge-checkout {
  background: #fff1e6;
  color: #9a3412;
}
.sh-item > .sh-badge,
.sh-item > .sh-bib {
  grid-area: lead;
}
.sh-item > .sh-main {
  grid-area: main;
}
.sh-item > .sh-result {
  grid-area: action;
}
.sh-item > .sh-remove {
  grid-area: remove;
}
/* แถวของกิจกรรม (ผู้ร่วมยืนยันเอง): ปุ่มยืนยันเต็มความกว้างบรรทัดล่าง กดง่ายบนมือถือ */
.sh-item.has-btn {
  grid-template-areas: 'lead main remove' 'btn btn btn';
  grid-template-columns: auto minmax(0, 1fr) auto;
}
.sh-item.has-btn > .sh-row-btn {
  grid-area: btn;
  width: 100%;
}
.sh-item.has-btn > .sh-result {
  grid-area: btn;
  white-space: normal;
  max-width: none;
  text-align: left;
}
.sh-row-btn {
  min-height: 40px;
  padding: 6px 14px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.sh-row-btn .material-symbols-rounded {
  font-size: 18px;
}
.sh-result {
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}
.sh-result.is-ok {
  color: #15803d;
}
.sh-result.is-error {
  color: #b42318;
}
.sh-result.is-warn {
  color: #a16207;
}
.sh-remove {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #f1f3f2;
  color: #5f6761;
  cursor: pointer;
}
.sh-remove .material-symbols-rounded {
  font-size: 18px;
}
.sh-confirm {
  width: 100%;
  margin-top: 10px;
}
.scan-hub[data-mode='finish'] .sh-confirm {
  background: #c2410c;
  border-color: #c2410c;
}
.sh-confirm[hidden] {
  display: none;
}

@media (max-width: 420px) {
  .sh-item {
    gap: 8px;
  }
  .sh-result {
    white-space: normal;
    max-width: 7.5em;
    text-align: right;
  }
}
@media (prefers-reduced-motion: reduce) {
  .scan-hub.is-hit .sh-frame {
    animation: none;
  }
}

/* ผล BIA ในรายการที่สแกนได้ (29 ต.ค. 2569): ค่าที่อ่านได้ + ปุ่มยืนยันบันทึกผล */
.sh-badge-bia { background: #e8f1ff; color: #1d4ed8; }
.sh-item-bia .sh-main strong { white-space: normal; }
.sh-warn { color: #9a5b00; }
.sh-bia-save { display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 12px; border: 0; border-radius: 12px; background: #087f3f; color: #fff; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.sh-bia-save:disabled { opacity: .6; cursor: progress; }
.sh-bia-save .material-symbols-rounded { font-size: 18px; }

/* โหมดอนุมัติ (29 ต.ค. 2569): ผู้ขอที่สแกนได้ + ปุ่มเปิดหน้าอนุมัติใน Organize */
.sh-badge-approve { background: #fff4e5; color: #9a5b00; }
.sh-item-approve .sh-main strong { white-space: normal; }
