/* css/style.css */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Noto Sans TC", sans-serif;
}

body {
  background: #0f172a;
  color: #f8fafc;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh; /* 適配 iOS Safari 動態工具列 */
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
}

.hidden {
  display: none !important;
}

/* 頂部功能列 */
.top-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 60;
}

.nav-left-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 精準過渡屬性，杜絕 transition: all 造成的舊機卡頓 */
.nav-badge-btn {
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav-badge-btn:hover, .nav-badge-btn:active {
  background: #334155;
  color: #38bdf8;
  border-color: #38bdf8;
}

.nav-admin-btn {
  border-color: #38bdf8;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
}

/* 語言切換按鈕 */
.lang-toggle-btn {
  background: #334155;
  color: #38bdf8;
  border: 1px solid #475569;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* 提示條與人因色彩分級 */
.banner-notice {
  background: #b45309; /* 預設橙色：一般警告 */
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  font-weight: 600;
}

.banner-warning {
  background: #dc2626; /* 高危險紅色：資料遺失風險 */
}

.banner-info {
  background: #0284c7; /* 資訊藍色：更新提示 */
}

/* PIN 遮罩與卡片 */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.98);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  padding: 20px;
}

.pin-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pin-card h2 { font-size: 20px; }
.pin-card p { font-size: 14px; color: #94a3b8; }
.form-group { text-align: left; }
.form-group label { font-size: 13px; color: #94a3b8; }
.form-group select {
  width: 100%;
  margin-top: 4px;
  height: 44px;
  background: #0f172a;
  border: 1px solid #475569;
  color: #fff;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 15px;
}

.file-input-control {
  width: 100%;
  padding: 8px 0;
  color: #94a3b8;
  font-size: 13px;
}

.file-status-tag {
  font-size: 12px;
  color: #38bdf8;
  text-align: left;
  margin-top: 2px;
}

/* 自適應字級與間距，杜絕 8 位數以上長 PIN 爆框 */
#pinInput {
  height: 48px;
  background: #0f172a;
  border: 1px solid #475569;
  color: #fff;
  border-radius: 8px;
  font-size: clamp(18px, 5.5vw, 24px);
  letter-spacing: clamp(2px, 1.2vw, 4px);
  text-align: center;
  outline: none;
}

.btn-primary {
  height: 48px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-primary:active {
  background: #1d4ed8;
}

.error-msg {
  color: #ef4444;
  font-size: 13px;
  min-height: 18px;
}

.pwa-install-btn {
  margin-top: 8px;
  width: 100%;
}

.ios-guide-box {
  background: #1e293b;
  border: 1px solid #475569;
  margin-top: 8px;
  padding: 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
}

/* 彈窗樣式 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 150;
  padding: 20px;
}

.modal-card {
  background: #1e293b;
  border: 1px solid #38bdf8;
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-modal-card {
  max-width: 540px;
}

.modal-card h3 {
  font-size: 18px;
  color: #38bdf8;
  border-bottom: 1px solid #334155;
  padding-bottom: 10px;
}

.modal-content {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.guide-item strong {
  display: block;
  font-size: 14px;
  color: #f1f5f9;
  margin-bottom: 4px;
}

.guide-item p {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.5;
}

.modal-close-btn {
  margin-top: 8px;
  height: 42px;
}

/* 主辦方 Admin 產票專屬控制項 */
.roster-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.roster-label {
  margin: 0;
}

.roster-btn-group {
  display: flex;
  gap: 6px;
}

.btn-mini {
  font-size: 11px;
  padding: 3px 8px;
}

.btn-import-label {
  cursor: pointer;
  border-color: #38bdf8;
  color: #38bdf8;
}

.hidden-file-input {
  display: none;
}

.admin-input-text {
  width: 100%;
  height: 44px;
  background: #0f172a;
  border: 1px solid #475569;
  color: #fff;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 15px;
  margin-top: 4px;
  outline: none;
}

.admin-textarea {
  width: 100%;
  background: #0f172a;
  border: 1px solid #475569;
  color: #fff;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 4px;
  outline: none;
  font-family: monospace;
  resize: vertical;
}

.admin-action-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-result-box {
  background: #0f172a;
  border: 1px solid #22c55e;
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-success-tip {
  color: #22c55e;
  font-size: 13px;
  font-weight: 600;
}

.admin-download-row {
  display: flex;
  gap: 8px;
  flex-direction: column;
}

/* 狀態列 */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e293b;
  padding: 10px 16px;
  border-radius: 12px;
}

.station-control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lock-btn {
  padding: 4px 8px;
  font-size: 11px;
}

.counter-tag {
  font-size: 16px;
  font-weight: 700;
  color: #38bdf8;
}

.live-tally {
  font-size: 16px;
  font-weight: 700;
}

/* 掃描預覽容器與動態邊框動畫 */
#reader-container {
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  min-height: 200px;
  border: 3px solid transparent;
  transition: border-color 0.2s ease;
}

#reader { width: 100%; }

/* 相機閃爍邊框動畫（配合 ui.js flashCameraBorder 調用） */
#reader-container.flash-border-success {
  border-color: #22c55e !important;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.5);
}

#reader-container.flash-border-duplicate {
  border-color: #facc15 !important;
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.5);
}

#reader-container.flash-border-error {
  border-color: #dc2626 !important;
  box-shadow: 0 0 12px rgba(220, 38, 38, 0.5);
}

/* 結果卡片：改用 flex: 1 與最小高度，完美適應 iPhone SE 等小螢幕 */
.result-card {
  border-radius: 16px;
  padding: 14px;
  text-align: center;
  flex: 1;
  min-height: clamp(140px, 24vh, 190px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.result-card.idle {
  background: #1e293b;
  border: 2px dashed #475569;
}

.result-card.success {
  background: #16a34a !important;
  color: #ffffff !important;
}

.result-card.duplicate {
  background: #facc15 !important;
  color: #0f172a !important;
}

.result-card.error {
  background: #dc2626 !important;
  color: #ffffff !important;
}

@keyframes cardGreenFlash {
  0% { box-shadow: 0 0 0 8px #22c55e; }
  100% { box-shadow: 0 0 0 0px transparent; }
}

.result-card.flash-active {
  animation: cardGreenFlash 0.15s ease-out;
}

.view-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.view-staff { display: flex; }
.view-guest { display: none; }

body.mode-guest-facing .view-staff { display: none; }
body.mode-guest-facing .view-guest {
  display: flex;
  transform: rotate(180deg);
}

.card-guest-name { font-size: 20px; font-weight: 600; }
.table-number-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 4px 0;
}
.table-digit {
  font-size: clamp(52px, 18vw, 84px);
  font-weight: 900;
  line-height: 1;
}
.table-unit {
  font-size: clamp(22px, 7vw, 34px);
  font-weight: 700;
}
.card-location-hint {
  font-size: 15px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.15);
}
.guest-welcome {
  font-size: 22px;
  font-weight: 700;
  margin: 4px 0;
}

/* 手動搜尋補登 */
.manual-box {
  background: #1e293b;
  border-radius: 14px;
  padding: 10px 12px;
}
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.manual-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #fff;
  font-size: 15px;
  outline: none;
}
.manual-action-btn {
  height: 40px;
  margin-left: 8px;
  padding: 0 14px;
  font-size: 13px;
  flex-shrink: 0;
}
.clear-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #334155;
  color: #cbd5e1;
  font-size: 16px;
  cursor: pointer;
  display: none;
  margin-left: 6px;
}
.input-wrapper.has-val .clear-btn { display: block; }
.search-results {
  margin-top: 8px;
  max-height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.search-item {
  height: 48px;
  padding: 0 14px;
  border-radius: 8px;
  background: #334155;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search-item-info {
  font-size: 14px;
  color: #f8fafc;
  font-weight: 500;
}
.search-empty-tip {
  color: #94a3b8;
  font-size: 13px;
  padding: 8px 12px;
  text-align: left;
}
.btn-manual-confirm {
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  border: none;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.btn-manual-confirm.checked {
  background: #64748b !important;
  cursor: not-allowed !important;
}

/* 工具欄位 */
.footer-tools {
  margin-top: auto;
  display: flex;
  gap: 10px;
  padding-top: 4px;
}
.btn-tool {
  flex: 1;
  height: 46px;
  border-radius: 10px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #94a3b8;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn-tool:active { background: #334155; }
.btn-tool.btn-confirming {
  background: #b91c1c !important;
  color: #ffffff !important;
  border-color: #ef4444 !important;
}

/* 防點擊劫持封鎖樣式 (支援 100dvh 動態高度與嚴格 CSP 外部樣式) */
html.frame-blocked { height: 100%; background: #000; }
.frame-blocked-modal {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  background: #000;
  color: #ef4444;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  padding: 24px; 
}

.frame-blocked-detail {
  font-size: 14px;
  color: #94a3b8;
  font-weight: normal;
  margin-top: 10px;
  display: block;
}

/* QR 碼圖像銳利化顯示，防止瀏覽器內插平滑演算法造成定位角模糊 */
.qr-box img,
.ticket-card img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
