/* Tiep nhan Luu dong — mobile first (Pages / online) + live scan + JSON handoff */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: #f1f5f9; color: #0f172a;
  font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; }
.wrap { max-width: 520px; margin: 0 auto; padding: 0.75rem 0.75rem 2.5rem; }

/* ── Modal user ── */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,0.55); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal.hidden { display: none !important; }
.modal-card { background: #fff; border-radius: 16px; padding: 1.1rem 1.15rem 1.2rem;
  width: 100%; max-width: 420px; box-shadow: 0 16px 40px rgba(0,0,0,0.35); }
.modal-title { font-size: 1.2rem; font-weight: 800; color: #0f172a; }
.modal-sub { font-size: 0.8rem; color: #64748b; margin: 0.35rem 0 0.85rem; }
.lbl { display: block; font-size: 0.78rem; font-weight: 700; color: #334155; margin-bottom: 0.3rem; }
.btn-user-save { width: 100%; margin-top: 1rem; border: none; border-radius: 12px;
  padding: 0.95rem; background: linear-gradient(180deg, #16a34a, #15803d); color: #fff;
  font-size: 1.05rem; font-weight: 800; cursor: pointer; }
.btn-user-save:active { transform: scale(0.98); }
.modal-hint { font-size: 0.72rem; color: #94a3b8; margin: 0.7rem 0 0; line-height: 1.45; }

/* ── Live scan overlay ── */
.live-wrap { position: fixed; inset: 0; background: #0b1220; z-index: 60;
  display: flex; flex-direction: column; }
.live-wrap.hidden { display: none !important; }
.live-hd { display: flex; justify-content: space-between; align-items: flex-start;
  padding: 0.75rem 0.85rem 0.4rem; color: #fff; }
.live-title { font-size: 1rem; font-weight: 800; }
.live-sub { font-size: 0.72rem; opacity: 0.85; margin-top: 2px; }
.live-close { border: 1px solid rgba(255,255,255,0.35); background: rgba(255,255,255,0.1);
  color: #fff; border-radius: 10px; width: 40px; height: 40px; font-size: 1.1rem; cursor: pointer; }
.live-stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  min-height: 0; overflow: hidden; background: #000; }
.live-reader { position: absolute; inset: 0; width: 100% !important; height: 100% !important;
  overflow: hidden; background: #000; }
.live-reader video,
#qr-live video,
#qr-live > video {
  position: absolute !important;
  filter: none !important;
  transform: none !important;
  image-rendering: auto;
  left: 0 !important; top: 0 !important;
  width: 100% !important; height: 100% !important;
  max-width: none !important;
  object-fit: cover !important;
  background: #000;
}
/* wrapper html5-qrcode hay set kích thước cố định → phá fullscreen */
.live-reader > div,
#qr-live > div:not(video) {
  width: 100% !important; height: 100% !important;
  position: absolute !important; left: 0 !important; top: 0 !important;
  margin: 0 !important; padding: 0 !important;
}
.live-reader img { max-width: 100%; }

/* Khung + laser rà quét */
.live-frame { position: absolute; width: min(78vw, 300px); height: min(78vw, 300px);
  border: 2px solid rgba(56, 189, 248, 0.9); border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.38); pointer-events: none;
  overflow: hidden; transition: border-color 0.15s; }
.live-frame::after { content: 'Đưa mã QR vào giữa · 20–30cm · chạm màn hình để lấy nét'; position: absolute;
  left: -10%; right: -10%; bottom: -1.7rem; text-align: center; color: #e0f2fe;
  font-size: 0.72rem; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.live-frame .laser { position: absolute; left: 6%; right: 6%; height: 2.5px; top: 10%;
  background: linear-gradient(90deg, transparent 0%, #38bdf8 20%, #a5f3fc 50%, #38bdf8 80%, transparent 100%);
  box-shadow: 0 0 14px 2px rgba(56, 189, 248, 0.75);
  border-radius: 2px; opacity: 0; }
.live-frame.scanning .laser { animation: laserSweep 1.55s ease-in-out infinite; }
.live-frame .corners { position: absolute; inset: 6px; border-radius: 8px;
  background:
    linear-gradient(#38bdf8, #38bdf8) left top / 22px 2.5px no-repeat,
    linear-gradient(#38bdf8, #38bdf8) left top / 2.5px 22px no-repeat,
    linear-gradient(#38bdf8, #38bdf8) right top / 22px 2.5px no-repeat,
    linear-gradient(#38bdf8, #38bdf8) right top / 2.5px 22px no-repeat,
    linear-gradient(#38bdf8, #38bdf8) left bottom / 22px 2.5px no-repeat,
    linear-gradient(#38bdf8, #38bdf8) left bottom / 2.5px 22px no-repeat,
    linear-gradient(#38bdf8, #38bdf8) right bottom / 22px 2.5px no-repeat,
    linear-gradient(#38bdf8, #38bdf8) right bottom / 2.5px 22px no-repeat;
  opacity: 0.95; }
.live-frame.scanning { animation: framePulse 1.55s ease-in-out infinite; }
.live-frame.hit { border-color: #4ade80; box-shadow: 0 0 0 9999px rgba(0,0,0,0.45), 0 0 24px #4ade80; }
.live-frame.hit .laser { animation: none; opacity: 0; top: 50%; }
.live-frame.hit .corners {
  background:
    linear-gradient(#4ade80, #4ade80) left top / 22px 3px no-repeat,
    linear-gradient(#4ade80, #4ade80) left top / 3px 22px no-repeat,
    linear-gradient(#4ade80, #4ade80) right top / 22px 3px no-repeat,
    linear-gradient(#4ade80, #4ade80) right top / 3px 22px no-repeat,
    linear-gradient(#4ade80, #4ade80) left bottom / 22px 3px no-repeat,
    linear-gradient(#4ade80, #4ade80) left bottom / 3px 22px no-repeat,
    linear-gradient(#4ade80, #4ade80) right bottom / 22px 3px no-repeat,
    linear-gradient(#4ade80, #4ade80) right bottom / 3px 22px no-repeat;
}
@keyframes laserSweep {
  0%   { top: 8%;  opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { top: 90%; opacity: 0; }
}
@keyframes framePulse {
  0%, 100% { box-shadow: 0 0 0 9999px rgba(0,0,0,0.45); }
  50%      { box-shadow: 0 0 0 9999px rgba(0,0,0,0.45), 0 0 0 3px rgba(56,189,248,0.35); }
}

.scan-badge { position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.78); color: #7dd3fc; border: 1px solid rgba(56,189,248,0.5);
  border-radius: 999px; padding: 0.35rem 0.75rem; font-size: 0.75rem; font-weight: 800;
  letter-spacing: 0.3px; z-index: 5; pointer-events: none;
  animation: badgeBlink 1.1s ease-in-out infinite; }
.scan-badge.hit { color: #86efac; border-color: #4ade80; animation: none; }
.scan-badge.hidden { display: none !important; }
@keyframes badgeBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.live-bar { padding: 0.65rem 0.85rem 1rem; background: #0f172a; color: #fff; }
.live-status { font-size: 0.88rem; font-weight: 600; min-height: 1.2rem; }
.live-status.ok { color: #86efac; }
.live-status.err { color: #fca5a5; }
.scanning-text { color: #7dd3fc; }
.scanning-text::after { content: ''; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}
.live-actions { display: flex; gap: 0.5rem; margin-top: 0.55rem; flex-wrap: wrap; }
.live-actions .btn-mini { background: #1e293b; border-color: #334155; color: #e2e8f0; }
.live-timeout { margin-top: 0.55rem; font-size: 0.8rem; color: #fcd34d; }
.live-timeout.hidden { display: none !important; }
.linkish { border: none; background: none; color: #7dd3fc; font-weight: 700;
  text-decoration: underline; cursor: pointer; padding: 0; font-size: 0.85rem; }

/* tap giữa khung để lấy nét */
.live-stage { cursor: crosshair; }

/* ── Header ── */
.hd { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem;
  background: linear-gradient(135deg, #0284c7, #0369a1); color: #fff;
  border-radius: 12px; padding: 0.85rem 1rem; margin-bottom: 0.75rem; }
.hd-title { font-size: 1.15rem; font-weight: 800; }
.hd-sub { font-size: 0.72rem; opacity: 0.92; margin-top: 2px; }
.hd-right { display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; }
.badge-off { font-size: 0.62rem; background: rgba(255,255,255,0.2);
  border-radius: 999px; padding: 4px 8px; font-weight: 700; white-space: nowrap; }
.badge-on { background: #dc2626; }
.btn-change-user { border: 1px solid rgba(255,255,255,0.45); background: rgba(255,255,255,0.12);
  color: #fff; border-radius: 8px; width: 32px; height: 28px; font-size: 1rem; font-weight: 700;
  cursor: pointer; line-height: 1; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-bottom: 0.75rem; }
.stat-card { background: #fff; border-radius: 10px; padding: 0.6rem 0.4rem; text-align: center;
  border: 1px solid #e2e8f0; }
.stat-label { font-size: 0.6rem; font-weight: 700; color: #64748b; letter-spacing: 0.4px; }
.stat-num { font-size: 1.7rem; font-weight: 800; line-height: 1.15; }
.stat-sub { font-size: 0.66rem; color: #94a3b8; }
.c-blue { color: #0284c7; } .c-gray { color: #64748b; } .c-teal { color: #0d9488; }

.btn-scan { width: 100%; border: none; border-radius: 14px; padding: 1.1rem;
  background: linear-gradient(180deg, #16a34a, #15803d); color: #fff; font-size: 1.2rem;
  font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  box-shadow: 0 4px 14px rgba(22,163,74,0.35); cursor: pointer; margin-bottom: 0.45rem; }
.btn-scan:active { transform: scale(0.98); }
.btn-scan span { letter-spacing: 0.4px; }

.btn-photo { width: 100%; border: 2px dashed #94a3b8; border-radius: 14px; padding: 0.85rem;
  background: #f8fafc; color: #334155; font-size: 0.98rem; font-weight: 700;
  cursor: pointer; margin-bottom: 0.6rem; }
.btn-photo:active { transform: scale(0.99); background: #e2e8f0; }
.btn-photo-attention { border-color: #f59e0b; background: #fffbeb; color: #92400e;
  animation: pulsePhoto 1.2s ease-in-out 3; }
@keyframes pulsePhoto {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
}
.photo-row { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.btn-photo-half { flex: 1; width: auto; margin-bottom: 0; padding: 0.85rem 0.4rem;
  font-size: 0.92rem; }

.paste-row { margin-bottom: 0.6rem; }
.inp { width: 100%; border: 1px solid #cbd5e1; border-radius: 10px; padding: 0.65rem 0.75rem;
  font-size: 0.95rem; background: #fff; }
.inp:focus { outline: 2px solid #0284c7; border-color: transparent; }

.scan-status { border-radius: 10px; padding: 0.6rem 0.8rem; font-size: 0.88rem; font-weight: 600;
  margin-bottom: 0.6rem; }
.scan-ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.scan-err { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.scan-busy { background: #e0f2fe; color: #075985; border: 1px solid #7dd3fc; }
.hidden { display: none !important; }

.last-card { background: #fffbeb; border: 1px solid #f59e0b; border-radius: 10px;
  padding: 0.6rem 0.8rem; margin-bottom: 0.6rem; font-size: 0.85rem; }
.last-card .lc-name { font-weight: 800; font-size: 0.98rem; }
.last-card .lc-meta { color: #92400e; font-size: 0.78rem; margin-top: 2px; }
.last-card button { margin-top: 0.4rem; border: 1px solid #fca5a5; background: #fff; color: #b91c1c;
  border-radius: 8px; padding: 0.3rem 0.7rem; font-size: 0.78rem; font-weight: 700; }

.card { background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 0.75rem 0.85rem; margin-bottom: 0.75rem; }
.card-title { font-size: 0.86rem; font-weight: 800; margin-bottom: 0.5rem; color: #0f172a; }

.date-row { display: flex; gap: 0.4rem; align-items: center; }
.date-row .inp { flex: 1; }
.btn-mini { border: 1px solid #cbd5e1; background: #f8fafc; border-radius: 8px;
  padding: 0.55rem 0.7rem; font-size: 0.78rem; font-weight: 700; color: #334155; cursor: pointer; }
.btn-warn { border-color: #fca5a5; color: #b91c1c; background: #fef2f2; }
.btn-export { width: 100%; border: none; border-radius: 10px; padding: 0.75rem;
  background: #0284c7; color: #fff; font-size: 0.95rem; font-weight: 800; cursor: pointer; }
.btn-export:active { transform: scale(0.99); }
.day-count { font-size: 0.78rem; color: #64748b; margin-top: 0.4rem; }
.export-hint { font-size: 0.7rem; color: #94a3b8; margin: 0.45rem 0; line-height: 1.45; }
.row-btns { margin-top: 0.55rem; display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: stretch; }
.chk-row { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.8rem; color: #334155;
  margin: 0.35rem 0 0.15rem; line-height: 1.4; cursor: pointer; }
.chk-row input { margin-top: 0.15rem; width: 1.05rem; height: 1.05rem; accent-color: #0284c7; }

.list-wrap { overflow-x: auto; }
.list-tbl { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.list-tbl th { background: #f1f5f9; color: #64748b; font-size: 0.66rem; text-align: left;
  padding: 0.4rem 0.35rem; border-bottom: 1px solid #e2e8f0; }
.list-tbl td { padding: 0.45rem 0.35rem; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.list-tbl .t-name { font-weight: 700; }
.list-tbl .t-sub { color: #94a3b8; font-size: 0.7rem; }
.btn-del { border: none; background: #fee2e2; color: #b91c1c; border-radius: 6px;
  padding: 0.25rem 0.45rem; font-size: 0.72rem; font-weight: 700; cursor: pointer; }
.empty-row { color: #94a3b8; text-align: center; padding: 1rem 0; font-size: 0.82rem; }

.week-tbl { display: flex; flex-direction: column; gap: 0.3rem; }
.week-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; }
.week-row .w-date { width: 82px; color: #475569; font-weight: 600; }
.week-row .w-bar { flex: 1; height: 12px; background: #f1f5f9; border-radius: 6px; overflow: hidden; }
.week-row .w-fill { height: 100%; background: #0284c7; border-radius: 6px; }
.week-row .w-num { width: 56px; text-align: right; font-weight: 800; color: #0f172a; }

.ft { text-align: center; color: #94a3b8; font-size: 0.68rem; line-height: 1.5; margin-top: 1rem; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0f172a; color: #fff; border-radius: 10px; padding: 0.6rem 1.1rem;
  font-size: 0.85rem; font-weight: 700; z-index: 99; max-width: 92%; text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25); }
.toast-ok { background: #15803d; }
.toast-err { background: #b91c1c; }

.warn-banner { border-radius: 10px; padding: 0.6rem 0.8rem; font-size: 0.82rem; font-weight: 600;
  margin-bottom: 0.6rem; background: #e0f2fe; color: #075985; border: 1px solid #7dd3fc; }
.warn-banner.warn-err { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.warn-banner.warn-warn { background: #fffbeb; color: #92400e; border: 1px solid #fcd34d; }

/* Video pipeline thuần getUserMedia — tuyệt đối không scale blur */
.live-cam-video {
  position: absolute !important;
  left: 0 !important; top: 0 !important;
  width: 100% !important; height: 100% !important;
  object-fit: cover !important;
  filter: none !important;
  transform: none !important;
  background: #000;
  z-index: 1;
}
