/* ============================================================
   SCAN-POC — 工業掃描終端風格
   深色石墨底 + 琥珀雷射色 + 綠色成功狀態
   ============================================================ */

:root {
  --bg: #0b0e13;
  --bg-scanline: rgba(255, 255, 255, 0.022);
  --panel: #131a23;
  --panel-2: #0f151d;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e8edf4;
  --text-dim: #8b96a5;
  --amber: #ffb627;
  --amber-dim: rgba(255, 182, 39, 0.14);
  --green: #45e08a;
  --green-dim: rgba(69, 224, 138, 0.12);
  --blue: #5ab8ff;
  --blue-dim: rgba(90, 184, 255, 0.12);
  --red: #ff5d5d;
  --radius: 14px;
  --mono: "Chakra Petch", "Consolas", monospace;
  --sans: "Chakra Petch", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  background:
    repeating-linear-gradient(0deg, var(--bg-scanline) 0 1px, transparent 1px 4px),
    radial-gradient(120% 70% at 50% -10%, #16202c 0%, var(--bg) 55%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(92px + var(--safe-bottom));
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button { font-family: inherit; color: inherit; cursor: pointer; }

/* ===== 頂部 HUD ===== */
.hud {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: rgba(11, 14, 19, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.hud-brand { display: flex; align-items: center; gap: 10px; }

.hud-logo {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid rgba(255, 182, 39, 0.35);
  border-radius: 10px;
}

.hud-title strong {
  font-family: var(--mono);
  font-size: 17px;
  letter-spacing: 0.06em;
  display: block;
  line-height: 1.1;
}

.hud-title small {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}

.hud-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--green);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  background: var(--panel-2);
}

.hud-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse 2.2s ease-in-out infinite;
}

.hud-status[data-state="offline"] { color: var(--red); }
.hud-status[data-state="offline"] .dot { background: var(--red); box-shadow: 0 0 8px var(--red); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ===== 主區 ===== */
.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px 0;
}

/* ===== 動作磚 ===== */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  animation: rise 0.45s ease both;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 20px 16px 16px;
  min-height: 148px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: linear-gradient(160deg, #1a2330 0%, var(--panel-2) 70%);
  overflow: hidden;
  transition: transform 0.12s ease, border-color 0.2s ease;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(90% 60% at 20% 0%, rgba(255, 255, 255, 0.07), transparent 60%);
  pointer-events: none;
}

.tile:active { transform: scale(0.965); }

.tile-icon {
  display: grid;
  place-items: center;
  width: 54px; height: 54px;
  border-radius: 12px;
}

.tile-scan .tile-icon {
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid rgba(255, 182, 39, 0.4);
}

.tile-photo .tile-icon {
  color: var(--blue);
  background: var(--blue-dim);
  border: 1px solid rgba(90, 184, 255, 0.4);
}

.tile-scan { border-top: 2px solid rgba(255, 182, 39, 0.55); }
.tile-photo { border-top: 2px solid rgba(90, 184, 255, 0.55); }

.tile-label { font-size: 18px; font-weight: 700; letter-spacing: 0.04em; }

.tile-sub {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}

/* ===== 清單 ===== */
.list-panel {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(19, 26, 35, 0.66);
  overflow: hidden;
  animation: rise 0.45s 0.08s ease both;
}

.list-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.list-head h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-right: auto;
}

.list-counts { display: flex; gap: 6px; }

.chip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--text-dim);
  white-space: nowrap;
}

.chip b { font-weight: 700; }
.chip-pending b { color: var(--amber); }
.chip-done b { color: var(--green); }

.btn-ghost {
  font-size: 12px;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 5px 10px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.btn-ghost:active { color: var(--red); border-color: var(--red); }

.record-list { list-style: none; }

.record-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  animation: slide-in 0.28s ease both;
}

.record-item:last-child { border-bottom: none; }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: none; }
}

.record-thumb {
  flex: none;
  width: 52px; height: 52px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  overflow: hidden;
}

.record-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.record-thumb.is-barcode { color: var(--amber); background: var(--amber-dim); }
.record-thumb.is-photo { color: var(--blue); }

.record-body { flex: 1; min-width: 0; }

.record-value {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.record-meta {
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.record-format { color: var(--amber); }

.record-side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.status {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 999px;
}

.status-pending { color: var(--amber); background: var(--amber-dim); border: 1px solid rgba(255, 182, 39, 0.4); }
.status-uploaded { color: var(--green); background: var(--green-dim); border: 1px solid rgba(69, 224, 138, 0.4); }

.btn-del {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  padding: 4px 6px;
}

.btn-del:active { color: var(--red); }

.empty-hint {
  padding: 38px 16px;
  text-align: center;
  color: var(--text-dim);
}

.empty-hint p:first-child {
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.2em;
  margin-bottom: 6px;
}

.empty-sub { font-size: 12.5px; }

.list-panel.has-records .empty-hint { display: none; }

/* ===== payload 檢視 ===== */
.payload-box {
  margin-top: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-2);
  font-size: 13px;
}

.payload-box summary {
  padding: 12px 14px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12.5px;
  letter-spacing: 0.03em;
}

.payload-box pre {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  color: var(--green);
  padding: 4px 14px 14px;
  overflow-x: auto;
  white-space: pre;
}

/* ===== 底部上傳列 ===== */
.upload-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(11, 14, 19, 0.92) 34%);
}

.btn-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 528px;
  margin: 0 auto;
  padding: 16px;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #171101;
  background: linear-gradient(160deg, #ffc954, var(--amber));
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 6px 26px rgba(255, 182, 39, 0.32);
  transition: transform 0.12s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.btn-upload:active { transform: scale(0.975); }

.btn-upload:disabled {
  opacity: 0.35;
  box-shadow: none;
  cursor: default;
}

.btn-upload.is-busy { pointer-events: none; opacity: 0.75; }

.btn-upload-count {
  font-family: var(--mono);
  font-size: 13px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ===== overlay 共用 ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #05070a;
  animation: fade 0.2s ease;
}

.overlay[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }

.overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  border-bottom: 1px solid var(--line);
}

.overlay-head h3 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.btn-close {
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  font-size: 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.viewport-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#scan-viewport { width: 100%; }
#scan-viewport video { display: block; width: 100% !important; }

/* 掃描裝飾（四角 + 雷射線） */
.scan-deco {
  position: absolute;
  top: 50%; left: 50%;
  width: min(72vw, 340px);
  height: min(46vw, 220px);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.corner {
  position: absolute;
  width: 26px; height: 26px;
  border: 3px solid var(--amber);
}

.c-tl { top: 0; left: 0; border-right: none; border-bottom: none; border-radius: 6px 0 0 0; }
.c-tr { top: 0; right: 0; border-left: none; border-bottom: none; border-radius: 0 6px 0 0; }
.c-bl { bottom: 0; left: 0; border-right: none; border-top: none; border-radius: 0 0 0 6px; }
.c-br { bottom: 0; right: 0; border-left: none; border-top: none; border-radius: 0 0 6px 0; }

.laser {
  position: absolute;
  left: 8%; right: 8%;
  top: 10%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--amber) 18%, #ffe9b8 50%, var(--amber) 82%, transparent);
  box-shadow: 0 0 12px rgba(255, 182, 39, 0.8);
  animation: laser 2s ease-in-out infinite;
}

@keyframes laser {
  0%, 100% { top: 10%; }
  50% { top: 88%; }
}

.overlay-hint {
  padding: 14px 20px calc(20px + var(--safe-bottom));
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}

/* 掃描控制（變焦 / 手電筒），裝置支援才顯示 */
.scan-controls {
  position: absolute;
  bottom: 20px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 14px;
  z-index: 5;
}

.btn-scan-ctrl {
  min-width: 52px;
  height: 44px;
  padding: 0 16px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: rgba(19, 26, 35, 0.82);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.btn-scan-ctrl.on {
  color: #171101;
  background: var(--amber);
  border-color: var(--amber);
}

/* ===== 拍照 overlay ===== */
#photo-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.photo-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.photo-flash.flashing { animation: flash 0.28s ease; }

@keyframes flash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

.photo-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 40px calc(24px + var(--safe-bottom));
}

.btn-flip, .btn-flip-placeholder {
  width: 48px; height: 48px;
}

.btn-flip {
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.btn-shutter {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  display: grid;
  place-items: center;
  transition: transform 0.1s ease;
}

.btn-shutter span {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: #fff;
  display: block;
  transition: transform 0.1s ease;
}

.btn-shutter:active span { transform: scale(0.86); }

/* ===== toast ===== */
.toast {
  position: fixed;
  top: calc(70px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translate(-50%, -12px);
  z-index: 90;
  max-width: 86vw;
  padding: 11px 18px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 10px;
  background: #1d2632;
  border: 1px solid var(--line-strong);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: rgba(69, 224, 138, 0.5); color: var(--green); }
.toast.warn { border-color: rgba(255, 93, 93, 0.5); color: var(--red); }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* 窄機型：動作磚改直排 */
@media (max-width: 340px) {
  .actions { grid-template-columns: 1fr; }
}
