/* scan.css — "Scan tài liệu" (M15). DÙNG CHUNG PC + điện thoại (chép y nguyên sang ban-dien-thoai/www/scan.css).
   Màu lấy từ hệ thống thiết kế của nơi chứa: PC (--kl-*, css/kl-ds.css) hoặc điện thoại (--paper, --ink, --cobalt… trong app.css)
   → tự theo chế độ Sáng / Tối. Không viết mã màu cứng ngoài các giá trị dự phòng. */
.sc{
  --sc-bg: var(--kl-bg, var(--frost, #F2F5F9));
  --sc-card: var(--kl-surface, var(--paper, #FFFFFF));
  --sc-card2: var(--kl-surface-2, var(--muted-bg, #EEF2F7));
  --sc-text: var(--kl-text, var(--ink, #0F1B2D));
  --sc-muted: var(--kl-text-2, var(--muted, #4B5B70));
  --sc-line: var(--kl-line, var(--line, #E1E7EF));
  --sc-pri: var(--kl-blue, var(--cobalt, #0B57D0));
  --sc-pri-soft: var(--kl-blue-soft, var(--cobalt-soft, #EAF1FD));
  --sc-on-pri: var(--on-cobalt, #FFFFFF);
  --sc-red: var(--kl-red, var(--red, #C62828));
  --sc-r: var(--kl-r2, 10px);
  position: relative; display: flex; flex-direction: column; gap: 12px; min-height: 100%;
  color: var(--sc-text); font-family: var(--kl-font, inherit); box-sizing: border-box;
}
.sc *, .sc *::before, .sc *::after{ box-sizing: border-box; }
.sc svg{ width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sc [hidden]{ display: none !important; }

/* thanh đầu */
.sc-head{ display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sc-title{ display: flex; flex-direction: column; min-width: 0; }
.sc-title b{ font-size: calc(18px * var(--fs, 1)); }
.sc-title small{ color: var(--sc-muted); font-size: calc(13px * var(--fs, 1)); }
.sc-add{ display: flex; gap: 8px; flex-wrap: wrap; }

.sc-btn{ display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--sc-line); border-radius: var(--sc-r); background: var(--sc-card); color: var(--sc-text);
  font: inherit; font-weight: 600; cursor: pointer; }
.sc-btn:hover{ border-color: var(--sc-pri); }
.sc-btn.sc-pri{ background: var(--sc-pri); border-color: var(--sc-pri); color: var(--sc-on-pri); }
.sc-btn.sc-pri:hover{ filter: brightness(1.08); }
.sc-btn.sc-wide{ width: 100%; }
.sc-btn:focus-visible, .sc-ic:focus-visible, .sc-seg button:focus-visible, .sc-th:focus-visible, .sc-link:focus-visible{ outline: 2px solid var(--sc-pri); outline-offset: 2px; }

/* trang trống */
.sc-empty{ display: grid; gap: 16px; align-content: start; }
.sc-drop{ display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 20px;
  border: 2px dashed var(--sc-line); border-radius: 16px; background: var(--sc-card); }
.sc-drop svg{ width: 44px; height: 44px; color: var(--sc-pri); }
.sc-drop b{ font-size: calc(16px * var(--fs, 1)); }
.sc-drop p{ margin: 0; color: var(--sc-muted); max-width: 520px; line-height: 1.5; }
.sc-drop .sc-note{ font-size: calc(12.5px * var(--fs, 1)); }
.sc kbd{ padding: 1px 6px; border: 1px solid var(--sc-line); border-bottom-width: 2px; border-radius: 4px; font-size: calc(12px * var(--fs, 1)); line-height: 1.4; background: var(--sc-card2); }
.sc.is-drag .sc-drop, .sc.is-drag .sc-stage{ border-color: var(--sc-pri); background: var(--sc-pri-soft); }

.sc-lb{ font-size: calc(12px * var(--fs, 1)); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--sc-muted); margin-bottom: 8px; }
.sc-hist ul{ list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 6px; }
.sc-hist li{ display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 10px 12px; border: 1px solid var(--sc-line); border-radius: var(--sc-r); background: var(--sc-card); }
.sc-hist li b{ overflow-wrap: anywhere; }
.sc-hist li span{ color: var(--sc-muted); font-size: calc(13px * var(--fs, 1)); }
.sc-hist li small{ flex-basis: 100%; color: var(--sc-muted); font-size: calc(12px * var(--fs, 1)); overflow-wrap: anywhere; }

/* vùng làm việc — PC: [ảnh lớn | bảng thiết lập], dải trang ở dưới */
.sc-work{ display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr) auto; gap: 12px; flex: 1; min-height: 0; }
.sc-stage{ grid-column: 1; grid-row: 1; display: flex; flex-direction: column; gap: 8px; min-height: 0;
  border: 1px solid var(--sc-line); border-radius: 14px; background: var(--sc-card2); padding: 10px; }
.sc-cvwrap{ position: relative; flex: 1; min-height: 260px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.sc-cv{ max-width: 100%; max-height: 100%; width: auto; height: auto; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18); border-radius: 2px; }
.sc-pageno{ position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 999px; font-size: calc(12px * var(--fs, 1)); font-weight: 600;
  background: var(--sc-card); color: var(--sc-muted); border: 1px solid var(--sc-line); }
.sc-tools{ display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.sc-ic{ position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  border: 1px solid var(--sc-line); border-radius: var(--sc-r); background: var(--sc-card); color: var(--sc-text); cursor: pointer; touch-action: none; }
.sc-sep{ width: 1px; align-self: stretch; margin: 6px 4px; background: var(--sc-line); }
.sc-ic:hover:not(:disabled){ border-color: var(--sc-pri); color: var(--sc-pri); }
.sc-ic:disabled{ opacity: .35; cursor: default; }
.sc-ic.sc-danger:hover:not(:disabled){ border-color: var(--sc-red); color: var(--sc-red); }

.sc-strip{ grid-column: 1; grid-row: 2; display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 2px 2px 6px; scroll-snap-type: x proximity; }
.sc-th{ position: relative; flex: none; width: 76px; height: 100px; padding: 0; border: 2px solid var(--sc-line); border-radius: 8px;
  background: var(--sc-card); cursor: pointer; overflow: hidden; scroll-snap-align: start; }
.sc-th img{ width: 100%; height: 100%; object-fit: contain; background: #fff; display: block; }
.sc-th em{ position: absolute; left: 4px; bottom: 4px; min-width: 18px; padding: 0 4px; border-radius: 9px; font-weight: 600; font-size: calc(11px * var(--fs, 1)); line-height: 18px; font-style: normal;
  background: var(--sc-card); color: var(--sc-text); border: 1px solid var(--sc-line); }
.sc-th.is-on{ border-color: var(--sc-pri); box-shadow: 0 0 0 2px var(--sc-pri-soft); }
.sc-th-add{ display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border-style: dashed; color: var(--sc-pri); }
.sc-th-add em{ position: static; border: 0; background: none; color: var(--sc-pri); }
.sc-th-ph{ display: block; width: 100%; height: 100%; background: var(--sc-card2); }

.sc-panel{ grid-column: 2; grid-row: 1 / span 2; display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow-y: auto; }
.sc-sec{ padding: 14px; border: 1px solid var(--sc-line); border-radius: 14px; background: var(--sc-card); }
.sc-sec.is-off .sc-rg, .sc-sec.is-off .sc-row{ opacity: .4; pointer-events: none; }
.sc-seg{ display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 3px; border-radius: var(--sc-r); background: var(--sc-card2); }
.sc-seg-sm{ grid-template-columns: repeat(2, 1fr); margin: 10px 0; }
.sc-seg button{ min-height: 34px; padding: 4px 4px; white-space: nowrap; border: 0; border-radius: 8px; background: transparent; color: var(--sc-muted); font: inherit; font-size: calc(13px * var(--fs, 1)); font-weight: 600; cursor: pointer; }
.sc-seg button.is-on{ background: var(--sc-card); color: var(--sc-pri); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.sc-tip{ margin: 8px 0 0; font-size: calc(12.5px * var(--fs, 1)); color: var(--sc-muted); line-height: 1.45; }
.sc-rg{ display: grid; gap: 4px; margin-bottom: 10px; font-size: calc(13.5px * var(--fs, 1)); }
.sc-rg span{ display: flex; justify-content: space-between; }
.sc-rg b{ font-variant-numeric: tabular-nums; color: var(--sc-pri); }
.sc-rg input[type=range]{ width: 100%; accent-color: var(--sc-pri); min-height: 28px; }
.sc-row{ display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.sc-link{ display: inline-flex; align-items: center; gap: 4px; padding: 6px 0; border: 0; background: none; color: var(--sc-pri); font: inherit; font-size: calc(13px * var(--fs, 1)); font-weight: 600; cursor: pointer; }
.sc-link svg{ width: 14px; height: 14px; }
.sc-link.sc-danger{ color: var(--sc-red); }
.sc-out .sc-btn{ margin-top: 8px; }
.sc-fld{ display: grid; gap: 4px; font-size: calc(13px * var(--fs, 1)); color: var(--sc-muted); }
.sc-fld input{ min-height: 38px; padding: 6px 10px; border: 1px solid var(--sc-line); border-radius: 8px; background: var(--sc-card); color: var(--sc-text); font: inherit; font-size: calc(14px * var(--fs, 1)); }
.sc-fld input:focus{ outline: 2px solid var(--sc-pri); outline-offset: 0; border-color: transparent; }

/* đang xử lý */
.sc-busy{ position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: color-mix(in srgb, var(--sc-bg) 78%, transparent); font-weight: 600; }
.sc-spin{ width: 34px; height: 34px; border: 3px solid var(--sc-line); border-top-color: var(--sc-pri); border-radius: 50%; animation: sc-spin .8s linear infinite; }
@keyframes sc-spin{ to{ transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce){ .sc-spin{ animation-duration: 2.4s; } }

/* màn hẹp (điện thoại, cửa sổ PC nhỏ): xếp dọc — ảnh · dải trang · thiết lập */
@media (max-width: 860px){
  .sc-work{ display: flex; flex-direction: column; }
  .sc-stage, .sc-strip, .sc-panel{ flex: none; }
  .sc-cvwrap{ flex: none; min-height: 0; height: min(62vh, 560px); } /* flex:none — nếu không, flex:1 (basis 0) ghi đè height → khung xem trước cao 0, mất ảnh */
  .sc-panel{ overflow: visible; }
  .sc-add .sc-btn{ flex: 1; }
  .sc-add{ width: 100%; }
}

/* ===== Scan thông minh (PC 0.22 / ĐT 0.7): chọn kiểu, ô tích, trình chỉnh 4 góc ===== */
.sc-seg-kieu{ margin-top: 10px; }
.sc-chk{ display: flex; align-items: flex-start; gap: 10px; margin: 2px 0 10px; font-size: calc(13.5px * var(--fs, 1)); line-height: 1.35; cursor: pointer; }
.sc-chk input{ flex: none; width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--sc-pri); }
.sc-chk small{ display: block; color: var(--sc-muted); font-size: calc(12px * var(--fs, 1)); }
.sc-crop{ position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--sc-bg); }
.sc-crop-top{ display: flex; flex-direction: column; gap: 2px; }
.sc-crop-top small{ color: var(--sc-muted); font-size: calc(12.5px * var(--fs, 1)); }
.sc-crop-stage{ flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 12px; background: var(--sc-card2); }
.sc-crop-stage canvas{ max-width: 100%; max-height: 100%; touch-action: none; cursor: crosshair; }
.sc-crop-btns{ display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding-bottom: env(safe-area-inset-bottom, 0px); }
.sc-crop-btns .sc-btn{ padding: 8px 6px; }

/* ===== Camera trực tiếp (PC 0.23 / ĐT 0.8): hình camera + 4 chấm canh góc, xem trước sau khi chụp. Luôn nền tối. ===== */
.sc-live{ position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: #0b0f14; color: #fff; padding-top: env(safe-area-inset-top, 0px); }
.sc-live-top{ display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; }
.sc-live-top > div{ display: flex; flex-direction: column; min-width: 0; }
.sc-live-top b{ font-size: calc(15px * var(--fs, 1)); }
.sc-live-top small{ color: rgba(255,255,255,.75); font-size: calc(12.5px * var(--fs, 1)); line-height: 1.35; }
.sc-live-stage{ position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.sc-live-box{ position: relative; width: 100%; height: 100%; }
.sc-live-box video{ display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
.sc-live-box canvas{ position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.sc-live-prev{ max-width: 100%; max-height: 100%; background: #fff; box-shadow: 0 0 0 1px rgba(255,255,255,.25); }
.sc-live-bar{ display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px)); }
.sc-live-bar#scLvBar2{ grid-template-columns: repeat(3, 1fr); }
.sc-lv-b{ min-height: 44px; padding: 8px 14px; border-radius: 22px; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12); color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.sc-lv-b.on, .sc-lv-b.pri{ background: var(--sc-pri); border-color: var(--sc-pri); }
.sc-lv-b:focus-visible, .sc-shutter:focus-visible{ outline: 2px solid #fff; outline-offset: 2px; }
.sc-shutter{ position: relative; width: 72px; height: 72px; padding: 0; border-radius: 50%; border: 4px solid #fff; background: transparent; cursor: pointer; }
.sc-shutter::after{ content: ''; position: absolute; inset: 5px; border-radius: 50%; background: #fff; transition: inset .08s; }
.sc-shutter:active::after{ inset: 9px; }

/* PC 0.26 / ĐT 0.11 — thêm chế độ "Màu mực": thanh chọn có 5 nút (chế độ + kiểu) → chia đều trên 1 hàng */
.sc-seg:not(.sc-seg-sm){ grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-flow: row; }
.sc-seg:not(.sc-seg-sm) button{ font-size: calc(13px * var(--fs, 1)); padding: 6px 4px; white-space: normal; line-height: 1.2; min-width: 0; overflow-wrap: anywhere; }

/* ===== PC 0.27 / ĐT 0.12: nút Lưu vào máy + danh sách tài liệu đã lưu ===== */
.sc-btn.sc-save{ background: var(--kl-green, var(--green, #1B7F4B)); border-color: var(--kl-green, var(--green, #1B7F4B)); color: #fff; }
.sc-btn.sc-save:hover{ filter: brightness(1.08); border-color: var(--kl-green, var(--green, #1B7F4B)); }
.sc-lb2{ margin: 14px 0 6px; }
.sc-out .sc-tip{ margin: 6px 0 0; }
.sc-lib{ display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.sc-doc{ position: relative; display: flex; }
.sc-doc-open{ flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 3px; padding: 10px; text-align: left;
  border: 1px solid var(--sc-line); border-radius: 14px; background: var(--sc-card); color: var(--sc-text); font: inherit; cursor: pointer; }
.sc-doc-open:hover{ border-color: var(--sc-pri); }
.sc-doc-open:focus-visible{ outline: 2px solid var(--sc-pri); outline-offset: 2px; }
.sc-doc-open img, .sc-doc-open .sc-th-ph{ display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; object-position: top; border-radius: 8px; background: var(--sc-card2); margin-bottom: 6px; }
.sc-doc-open b{ font-size: calc(14px * var(--fs, 1)); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sc-doc-open span{ color: var(--sc-muted); font-size: calc(12.5px * var(--fs, 1)); }
.sc-doc-open small{ color: var(--sc-muted); font-size: calc(12px * var(--fs, 1)); }
.sc-doc-del{ position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border-radius: 50%; background: color-mix(in srgb, var(--sc-card) 88%, transparent); border: 1px solid var(--sc-line); box-shadow: 0 1px 4px rgba(0,0,0,.18); }
@media (max-width: 860px){ .sc-lib{ grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ===== PC 0.28 / ĐT 0.13: thu phóng ảnh xem trước; nút chế độ xuống hàng (hết chèn lẫn nhau) ===== */
.sc-scroll{ position: absolute; inset: 0; display: flex; overflow: auto; overscroll-behavior: contain; touch-action: pan-y; }
.sc-scroll.is-zoom{ cursor: grab; }
.sc-scroll .sc-cv{ flex: none; margin: auto; max-width: none; max-height: none; user-select: none; -webkit-user-drag: none; }
.sc-ic.sc-zfit{ width: auto; min-width: 54px; padding: 0 8px; font: inherit; font-size: calc(12.5px * var(--fs, 1)); font-weight: 700; }

.sc-rg.is-off{ opacity: .4; pointer-events: none; }
