/* =====================================================================
   สแกนบาร์โค้ดด้วยกล้อง: Components/CameraScanner.razor + ScanButton.razor (JS: scanner.js)
   หน้าจอสแกนเป็นพื้นมืดเสมอ (เหมือนแอปกล้อง) ทั้งโหมดสว่าง/มืด
   ===================================================================== */

/* ---- ปุ่มไอคอนข้างช่องค้นหา ---- */
.scan-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none;
  min-width: 42px; height: 42px; padding: 0 10px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.scan-btn:hover { border-color: var(--brand); color: var(--brand); }
.scan-btn:active { transform: scale(.96); }
.scan-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.scan-btn svg { flex: none; }
.scan-btn.sm { min-width: 36px; height: 36px; padding: 0 8px; border-radius: 10px; }
/* แถบสีของร้านในหน้าขาย */
.scan-btn.on-brand { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.35); color: var(--brand-ink); }
.scan-btn.on-brand:hover { background: rgba(255,255,255,.28); color: var(--brand-ink); border-color: rgba(255,255,255,.6); }
html.no-cam .scan-btn { display: none; }

/* ช่องค้นหา + ปุ่มสแกน ในแถวเดียว */
.scan-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.scan-row > :first-child { flex: 1 1 auto; min-width: 0; }

/* ---- หน้าจอสแกนเต็มจอ ---- */
body:has(.scn) { overflow: hidden; }
.scn {
  position: fixed; inset: 0; z-index: 90; background: #000; color: #fff; outline: none;
  display: flex; flex-direction: column; overflow: hidden;
  animation: scn-in .16s ease-out;
}
@keyframes scn-in { from { opacity: 0; } }
.scn-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }

/* เงามืดรอบกรอบเล็ง (ใช้ box-shadow ใหญ่ ๆ เจาะช่องกลาง) */
.scn-shade { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; padding-bottom: 12vh; }
.scn-frame {
  position: relative; width: min(82vw, 440px); aspect-ratio: 1.55; border-radius: 18px;
  box-shadow: 0 0 0 200vmax rgba(0,0,0,.52);
}
.scn-frame i { position: absolute; width: 34px; height: 34px; border: 4px solid #fff; }
.scn-frame .tl { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 18px; }
.scn-frame .tr { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 18px; }
.scn-frame .bl { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 18px; }
.scn-frame .br { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 18px; }
.scn-shade.live .scn-frame i { border-color: var(--brand); filter: brightness(1.25) saturate(1.1); }
.scn-laser {
  position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; border-radius: 2px; opacity: 0;
  background: #ff3b30; box-shadow: 0 0 10px 2px rgba(255,59,48,.7);
}
.scn-shade.live .scn-laser { opacity: .9; animation: scn-laser 2.2s ease-in-out infinite; }
@keyframes scn-laser { 0%, 100% { transform: translateY(-34px); } 50% { transform: translateY(34px); } }

/* แถบบน: ปิด / ชื่อ / ไฟฉาย */
.scn-top {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 24px;
  background: linear-gradient(rgba(0,0,0,.55), rgba(0,0,0,0));
}
.scn-title { flex: 1; min-width: 0; margin: 0; text-align: center; font-size: 1.05rem; font-weight: 700; color: #fff; }
.scn-btn, .scn-btn-space { flex: none; width: 46px; height: 46px; }
.scn-btn {
  display: grid; place-items: center; border-radius: 999px; border: 0; cursor: pointer;
  background: rgba(255,255,255,.16); color: #fff; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.scn-btn:hover { background: rgba(255,255,255,.26); }
.scn-btn.on { background: #fff; color: #1F1A17; }

/* แผงล่าง: สถานะ / รหัสล่าสุด / สลับโหมด */
.scn-panel {
  position: relative; z-index: 1; margin-top: auto; display: grid; gap: 10px; justify-items: center;
  padding: 28px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.7) 34%);
  text-align: center;
}
.scn-status { margin: 0; font-size: .95rem; color: rgba(255,255,255,.9); text-shadow: 0 1px 2px rgba(0,0,0,.6); min-height: 1.4em; }
.scn-last {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.95); color: #1F1A17;
  box-shadow: 0 6px 18px rgba(0,0,0,.35); animation: scn-pop .2s ease-out;
}
.scn-last span { font-size: .8rem; color: #6B5F57; flex: none; }
.scn-last b { font-family: var(--font-mono); font-size: 1rem; letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.scn-last em { font-style: normal; font-weight: 700; color: #fff; background: var(--brand); border-radius: 999px; padding: 1px 8px; font-size: .8rem; flex: none; }
@keyframes scn-pop { from { transform: scale(.92); opacity: .4; } }
.scn-msg { margin: 0; max-width: 520px; padding: 8px 14px; border-radius: 12px; background: rgba(179,38,30,.92); color: #fff; font-size: .9rem; }

.scn-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px 16px; width: 100%; max-width: 520px; }
.scn-toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; color: #fff; font-weight: 600; user-select: none; padding: 6px 4px; }
.scn-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.scn-switch { position: relative; width: 46px; height: 28px; border-radius: 999px; background: rgba(255,255,255,.3); transition: background .15s; flex: none; }
.scn-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.scn-toggle input:checked + .scn-switch { background: var(--brand); }
.scn-toggle input:checked + .scn-switch::after { transform: translateX(18px); }
.scn-toggle input:focus-visible + .scn-switch { outline: 2px solid #fff; outline-offset: 2px; }
.scn-done { min-width: 120px; }

/* ข้อผิดพลาด (ไม่อนุญาตกล้อง / ไม่มีกล้อง / ต้องใช้ https) */
.scn-error {
  display: grid; gap: 6px; width: 100%; max-width: 440px; padding: 16px 18px; border-radius: 18px; text-align: left;
  background: rgba(255,255,255,.96); color: #1F1A17; box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.scn-error strong { font-size: 1.02rem; color: #B3261E; }
.scn-error span { font-size: .9rem; color: #4A403A; line-height: 1.45; }
.scn-error-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }

@media (min-width: 761px) {
  .scn-frame { width: min(60vw, 520px); }
}
@media (prefers-reduced-motion: reduce) {
  .scn, .scn-last { animation: none; }
  .scn-shade.live .scn-laser { animation: none; }
}
@media print { .scn, .scan-btn { display: none !important; } }
/* การ์ดข้อผิดพลาดเป็นสีสว่างเสมอ → ปุ่มรองต้องสว่างด้วยแม้อยู่ในโหมดมืด */
.scn-error .btn:not(.primary) { background: #F7EEE6; color: #1F1A17; border-color: #EADCD0; }

/* ปุ่มอยู่ในกล่องค้นหา (เช่น หน้าขาย .posb-search) ไม่มีกรอบ */
.scan-btn.inline { border: 0; background: transparent; color: var(--muted); min-width: 40px; height: 40px; padding: 0 6px; margin-right: -6px; border-radius: 10px; }
.scan-btn.inline:hover { background: var(--brand-soft); color: var(--brand); }
/* สูงเท่าช่องกรอกข้าง ๆ */
.scan-row > .scan-btn { align-self: stretch; height: auto; min-height: 40px; }
.sc-scanbar > .scan-btn { height: auto; min-width: 52px; border-width: 2px; border-radius: 14px; }
