/**
 * TeachSYS Plus - 第一階段功能模組樣式
 * ---------------------------------------------------------------------------
 * 掃描主控台、項目選擇、名冊編輯器、進度條。
 */

/* ── 掃描主控台：大螢幕左右分欄，手機上下堆疊 ───────────────────────── */

.scan-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
}

@media (max-width: 1024px) {
  .scan-layout { grid-template-columns: 1fr; }
}

/* ── 相機預覽 ───────────────────────────────────────────────────────── */

.scan-stage {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #0f172a;
  box-shadow: var(--sh-3);
}

.scan-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 未啟動時的提示，啟動後隱藏 */
.scan-stage__idle {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  color: rgba(255, 255, 255, 0.75);
  font-size: var(--fs-md);
  text-align: center;
  padding: var(--sp-4);
}

.scan-stage.is-live .scan-stage__idle { display: none; }

/* 取景框：引導教師把條碼對準中央 */
.scan-stage__reticle {
  position: absolute;
  inset: 18% 12%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--r-md);
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.28);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-mid) var(--ease-out);
}

.scan-stage.is-live .scan-stage__reticle { opacity: 1; }

/* 掃描線動效 */
.scan-stage.is-live .scan-stage__reticle::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  height: 3px;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, transparent, var(--c-brand), transparent);
  animation: scanline 2.4s var(--ease-out) infinite;
}

@keyframes scanline {
  0%, 100% { top: 6px; opacity: 0.2; }
  50%      { top: calc(100% - 9px); opacity: 1; }
}

/* ── 掃描結果大字報 ─────────────────────────────────────────────────── */

.scan-result {
  margin-top: var(--sp-4);
  padding: var(--sp-5);
  border-radius: var(--r-lg);
  border: 2px solid var(--c-border);
  background: var(--c-surface);
  text-align: center;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
}

.scan-result__main {
  font-size: var(--fs-2xl);
  font-weight: 800;
  line-height: 1.2;
}

.scan-result__sub {
  font-size: var(--fs-lg);
  color: var(--c-text-muted);
}

.scan-result--success { background: var(--c-success-soft); border-color: var(--c-success); }
.scan-result--success .scan-result__main { color: var(--c-success); }
.scan-result--warn    { background: var(--c-warn-soft);    border-color: var(--c-warn); }
.scan-result--warn .scan-result__main    { color: var(--c-warn); }
.scan-result--error   { background: var(--c-danger-soft);  border-color: var(--c-danger); }
.scan-result--error .scan-result__main   { color: var(--c-danger); }

.scan-result.is-pop { animation: result-pop var(--dur-slow) var(--ease-spring); }

@keyframes result-pop {
  0%   { transform: scale(0.94); }
  60%  { transform: scale(1.02); }
  100% { transform: scale(1); }
}

/* ── 項目選擇大按鈕 ─────────────────────────────────────────────────── */

.item-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tap-gap);
}

.item-btn {
  min-height: var(--tap-lg);
  padding: 0 var(--sp-5);
  border: 2px solid var(--c-border-strong);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  color: var(--c-text);
  font-family: inherit;
  font-size: var(--fs-lg);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--sh-1);
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

.item-btn:active { transform: scale(0.95); }
.item-btn.is-on {
  background: var(--c-brand);
  border-color: var(--c-brand);
  color: var(--c-text-invert);
  box-shadow: var(--sh-3);
}

/* ── 小尺寸切換晶片（每日指定收件） ─────────────────────────────────── */

.chip-row { display: flex; flex-wrap: wrap; gap: var(--tap-gap); }

.chip {
  min-height: var(--tap-min);
  padding: 0 var(--sp-4);
  border: 2px solid var(--c-border-strong);
  border-radius: var(--r-pill);
  background: var(--c-surface);
  color: var(--c-text-muted);
  font-family: inherit;
  font-size: var(--fs-md);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}

.chip:active { transform: scale(0.95); }
.chip.is-on {
  background: var(--c-brand-soft);
  border-color: var(--c-brand);
  color: var(--c-brand-strong);
}

/* ── 掃描歷史列 ─────────────────────────────────────────────────────── */

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 340px;
  overflow-y: auto;
}

.feed__item {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-inline-start: 4px solid var(--c-border);
  border-radius: var(--r-sm);
  margin-bottom: var(--sp-2);
  background: var(--c-surface-2);
  font-size: var(--fs-sm);
  animation: feed-in var(--dur-mid) var(--ease-out);
}

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

.feed__item--success { border-inline-start-color: var(--c-success); }
.feed__item--warn    { border-inline-start-color: var(--c-warn); }
.feed__item--error   { border-inline-start-color: var(--c-danger); }

.feed__time { flex: none; color: var(--c-text-muted); font-size: var(--fs-xs); }
.feed__msg  { font-weight: 700; }
.feed__detail { margin-inline-start: auto; text-align: end; }

/* ── 進度條 ─────────────────────────────────────────────────────────── */

.progress {
  height: 12px;
  border-radius: var(--r-pill);
  background: var(--c-surface-2);
  overflow: hidden;
  margin-bottom: var(--sp-3);
}

.progress__bar {
  height: 100%;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--c-brand), var(--c-success));
  transition: width var(--dur-slow) var(--ease-out);
}

.progress-num { font-size: var(--fs-lg); }
.progress-num strong { font-size: var(--fs-xl); color: var(--c-brand-strong); }

/* ── 未交名單摺疊區 ─────────────────────────────────────────────────── */

.missing {
  margin-top: var(--sp-4);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
}

.missing summary {
  cursor: pointer;
  font-weight: 700;
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
}

/* ── 表格列操作按鈕 ─────────────────────────────────────────────────── */

.row-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.row-actions .btn { min-height: var(--tap-min); padding: 0 var(--sp-3); font-size: var(--fs-sm); }

tr.is-inactive td { opacity: 0.5; }

/* ── 提示橫幅 ───────────────────────────────────────────────────────── */

.notice {
  padding: var(--sp-4);
  border-radius: var(--r-md);
  border-inline-start: 4px solid var(--c-info);
  background: var(--c-info-soft);
  margin-bottom: var(--sp-4);
}

.notice p { margin: var(--sp-2) 0 0; font-size: var(--fs-sm); }
.notice--danger { border-inline-start-color: var(--c-danger); background: var(--c-danger-soft); }
.notice--warn   { border-inline-start-color: var(--c-warn);   background: var(--c-warn-soft); }

/* ── 大電視：結果大字報再放大 ───────────────────────────────────────── */

@media (min-width: 1600px) {
  .scan-result__main { font-size: var(--fs-hero); }
  .scan-result { min-height: 180px; }
}

/* ── 掃描診斷面板 ───────────────────────────────────────────────────── */

.diag {
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
}

.diag summary {
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--c-text-muted);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
}

.diag__grid { margin-top: var(--sp-2); }

.diag__row {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-1) 0;
  font-size: var(--fs-sm);
  border-bottom: 1px dashed var(--c-border);
}

.diag__row:last-child { border-bottom: none; }
.diag__label { flex: none; width: 7.5em; color: var(--c-text-muted); }
.diag__value { word-break: break-all; }
.diag__value.is-ok   { color: var(--c-success); font-weight: 700; }
.diag__value.is-warn { color: var(--c-warn);    font-weight: 700; }
.diag__value.is-bad  { color: var(--c-danger);  font-weight: 700; }

/* ── 統計數字列（測驗成績、點名進度） ───────────────────────────────── */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: var(--tap-gap);
  margin-bottom: var(--sp-4);
}

.stat {
  padding: var(--sp-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  text-align: center;
}

.stat__value {
  font-size: var(--fs-xl);
  font-weight: 800;
  line-height: 1.1;
}

.stat__value.is-good { color: var(--c-success); }
.stat__value.is-warn { color: var(--c-warn); }
.stat__value.is-bad  { color: var(--c-danger); }

.stat__label {
  margin-top: var(--sp-1);
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

/* ── 成績數字 ───────────────────────────────────────────────────────── */

.score {
  display: inline-block;
  min-width: 3ch;
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--c-success);
}

.score.is-fail { color: var(--c-danger); }

/* ── 測驗模式：等待分數的狀態列 ─────────────────────────────────────── */

.pending {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 2px dashed var(--c-brand);
  border-radius: var(--r-lg);
  background: var(--c-brand-soft);
  animation: pending-pulse 1.6s var(--ease-out) infinite;
}

@keyframes pending-pulse {
  0%, 100% { border-color: var(--c-brand); }
  50%      { border-color: var(--c-border-strong); }
}

.pending__who { flex: 1; font-size: var(--fs-lg); }

/* ── 螢幕數字鍵盤 ───────────────────────────────────────────────────── */

.keypad__display {
  margin-bottom: var(--sp-3);
  padding: var(--sp-3);
  border: 2px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
  text-align: center;
  font-family: var(--ff-mono);
  font-size: var(--fs-2xl);
  font-weight: 800;
  color: var(--c-text-muted);
}

.keypad__display.is-filled {
  color: var(--c-brand-strong);
  border-color: var(--c-brand);
  background: var(--c-brand-soft);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--tap-gap);
}

.key {
  min-height: var(--tap-lg);
  border: 2px solid var(--c-border-strong);
  border-radius: var(--r-md);
  background: var(--c-surface);
  color: var(--c-text);
  font-family: inherit;
  font-size: var(--fs-xl);
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--sh-1);
  transition: transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}

.key:active { transform: scale(0.94); background: var(--c-brand-soft); }

.key--ok {
  background: var(--c-success);
  border-color: var(--c-success);
  color: var(--c-text-invert);
  font-size: var(--fs-lg);
}

/* ── 點名座號上的時間戳 ─────────────────────────────────────────────── */

.seat__time {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}

/* ── 出勤四態座號配色 ───────────────────────────────────────────────── */

/* 未到（含尚未點名）：淡紅底、紅框 —— 點名開始時全班為紅，掃到即轉綠 */
.seat.is-absent {
  background: var(--c-danger-soft);
  border-color: var(--c-danger);
}
.seat.is-absent .seat__no { color: var(--c-danger); }

/* 到校：沿用原本的綠色 */
.seat.is-present {
  background: var(--c-success-soft);
  border-color: var(--c-success);
}
.seat.is-present .seat__no { color: var(--c-success); }

/* 遲到：沿用原本的琥珀色 */
.seat.is-late {
  background: var(--c-warn-soft);
  border-color: var(--c-warn);
}
.seat.is-late .seat__no { color: var(--c-warn); }

/* 請假：灰底，與「有事無法到校」的中性語意一致 */
.seat.is-excused {
  background: var(--c-surface-2);
  border-color: var(--c-border-strong);
}
.seat.is-excused .seat__no,
.seat.is-excused .seat__name { color: var(--c-text-muted); }

/* ── 假別配色 ───────────────────────────────────────────────────────── */

/* 同一組顏色同時套用於：座號上的小標籤、請假名單徽章、註記對話框按鈕，
   三處一致，教師才能建立「顏色 = 假別」的直覺 */

.badge--sick        { background: var(--c-sick-soft);        color: var(--c-sick); }
.badge--personal    { background: var(--c-personal-soft);    color: var(--c-personal); }
.badge--official    { background: var(--c-official-soft);    color: var(--c-official); }
.badge--bereavement { background: var(--c-bereavement-soft); color: var(--c-bereavement); }
.badge--leave-other { background: var(--c-surface-2);        color: var(--c-text-muted); }

/* 座號上的假別小標籤：座號本身已是灰底，故加邊框以維持辨識度 */
.seat__leave {
  margin-top: 2px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-pill);
  border: 1px solid currentColor;
  font-size: var(--fs-xs);
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat__leave--sick        { background: var(--c-sick-soft);        color: var(--c-sick); }
.seat__leave--personal    { background: var(--c-personal-soft);    color: var(--c-personal); }
.seat__leave--official    { background: var(--c-official-soft);    color: var(--c-official); }
.seat__leave--bereavement { background: var(--c-bereavement-soft); color: var(--c-bereavement); }
.seat__leave--leave-other { background: var(--c-surface);          color: var(--c-text-muted); }

/* 註記對話框中的假別按鈕：未選取時以邊框與文字呈現該假別的顏色，
   選取後整塊填滿，讓目前選擇一目了然 */
.chip--sick        { border-color: var(--c-sick);        color: var(--c-sick); }
.chip--personal    { border-color: var(--c-personal);    color: var(--c-personal); }
.chip--official    { border-color: var(--c-official);    color: var(--c-official); }
.chip--bereavement { border-color: var(--c-bereavement); color: var(--c-bereavement); }

.chip--sick.is-on {
  background: var(--c-sick); border-color: var(--c-sick); color: var(--c-text-invert);
}
.chip--personal.is-on {
  background: var(--c-personal); border-color: var(--c-personal); color: var(--c-text-invert);
}
.chip--official.is-on {
  background: var(--c-official); border-color: var(--c-official); color: var(--c-text-invert);
}
.chip--bereavement.is-on {
  background: var(--c-bereavement); border-color: var(--c-bereavement); color: var(--c-text-invert);
}
