:root {
  --blue: #2563eb; --blue-dark: #1d4ed8; --bg: #f1f5f9; --card: #ffffff;
  --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --ok: #16a34a; --warn: #d97706; --err: #dc2626;
  --radius: 16px; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.05);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { overflow-x: clip; }   /* chặn bóng đổ/full-bleed (100vw) tràn mép trên Chromium & Safari16+; clip KHÔNG tạo scroll-container nên không phá sticky. (Desktop có thanh cuộn cổ điển vẫn còn ~8px cuộn ngang — lỗi cũ, vô hại trên mobile vốn cuộn overlay nên 100vw = đúng bề rộng nhìn thấy.) */
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 17px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }

.btn { font: inherit; font-weight: 600; border: none; border-radius: 12px; padding: 13px 18px; min-height: 48px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform .05s ease, background .15s ease; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; box-shadow: none; }
.btn-primary { background: var(--blue); color: #fff; } .btn-primary:active { background: var(--blue-dark); }
.btn-ghost { background: transparent; color: var(--blue); } .btn-danger { background: #fee2e2; color: var(--err); }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: 15px; } .btn-big { font-size: 19px; min-height: 58px; border-radius: 14px; } .btn-block { width: 100%; } .ic { font-size: 22px; line-height: 1; }

/* PIN */
.pin-screen { position: fixed; inset: 0; background: linear-gradient(160deg,#2563eb,#1e3a8a); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 50; }
.pin-box { background: #fff; border-radius: 22px; padding: 34px 24px; width: 100%; max-width: 360px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.brand-mark { margin: 6px 0 2px; } .eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .34em; color: #94a3b8; text-transform: uppercase; padding-left: .34em; }
.logotype { font-family: "Playfair Display","Times New Roman",Georgia,serif; font-size: 42px; font-weight: 700; color: #1e293b; line-height: 1.04; margin-top: 3px; }
.pin-sub { color: var(--muted); margin: 14px 0 20px; font-size: 14px; }
.pin-input { width: 100%; font-size: 22px; text-align: center; padding: 14px; border: 2px solid var(--line); border-radius: 14px; margin-bottom: 14px; } .pin-input:focus { outline: none; border-color: var(--blue); }
.pin-err { color: var(--err); min-height: 22px; margin-top: 10px; font-size: 15px; }
.pin-locked { padding: 14px 0; } .lock-ic { font-size: 46px; } .lock-msg { font-size: 22px; font-weight: 800; color: var(--err); margin-top: 8px; }

/* Shell */
.app { max-width: 820px; margin: 0 auto; min-height: 100vh; }
.topbar { position: static; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
.brand-eyebrow { font-size: 10px; font-weight: 600; letter-spacing: .3em; text-transform: uppercase; opacity: .82; padding-left: .3em; }
.brand-name { font-family: "Playfair Display",Georgia,serif; font-weight: 700; font-size: 21px; line-height: 1.08; }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; background: rgba(255,255,255,.18); padding: 5px 10px; border-radius: 999px; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; }
.status-online .dot { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.3); } .status-offline .dot { background: #f87171; }
.main { padding: 8px; padding-bottom: 40px; }
.pick { margin-bottom: 16px; } .hint { color: var(--muted); font-size: 14px; margin: 8px 4px 0; text-align: center; }

/* Printer panel real-time */
.printer-panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 16px; }
.pp-printer + .pp-printer { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.pp-row { display: flex; align-items: center; gap: 9px; font-size: 15px; }
.pp-dot { width: 11px; height: 11px; border-radius: 50%; background: #cbd5e1; flex: 0 0 auto; }
.pp-dot.on { background: #16a34a; } .pp-dot.off { background: #ef4444; }
.pp-dot.busy-mine { background: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.25); animation: ppulse 1.2s infinite; }
.pp-dot.busy-other { background: #d97706; box-shadow: 0 0 0 3px rgba(217,119,6,.22); animation: ppulse 1.2s infinite; }
@keyframes ppulse { 50% { opacity: .4; } }
.pp-sub { color: var(--muted); font-size: 13px; margin: 4px 0 0 20px; }
.pp-sub b { color: var(--ink); }
.job-prog { height: 6px; background: #eef2ff; border-radius: 999px; overflow: hidden; margin: 9px 0; }
.job-prog-bar { height: 100%; background: var(--blue); border-radius: 999px; transition: width .3s ease; }
.job-prog-bar.processing { width: 35%; } .job-prog-bar.uploading { width: 70%; } .job-prog-bar.sent { width: 92%; }
.job-actions { margin-top: 10px; }

/* FILE CARD */
.file-list { display: flex; flex-direction: column; gap: 26px; }
/* Thẻ chứa từng file: FULL-BLEED ngang. RANH GIỚI RÕ: vạch màu DÀY ở TRÊN và DƯỚI + bóng nổi + khoảng cách lớn -> tách rõ với file khác và với nút IN */
.file-card { background: #cbd5e1; box-shadow: 0 6px 18px rgba(0,0,0,.20); padding: 0 14px 18px; border: none; border-top: 5px solid var(--blue); border-bottom: 5px solid var(--blue); border-radius: 0; width: 100vw; margin-left: calc(-50vw + 50%); }
.file-card.pdf-card { border-top-color: #f59e0b; border-bottom-color: #f59e0b; }
.a4-warn { margin-top: 12px; background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; font-weight: 600; font-size: 14px; border-radius: 10px; padding: 10px 12px; }
.fc-head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; padding-top: 12px; }
/* STT số ĐƠN (1, 2, 3…) trong huy hiệu tròn rõ */
.fc-num { font-size: 15px; font-weight: 800; background: #0f172a; color: #fff; border-radius: 999px; min-width: 28px; height: 28px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.fc-badge { font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: #eef2ff; color: var(--blue); flex: 0 0 auto; }
.fc-badge.pdf { background: #fef3c7; color: #92400e; }
.fc-name { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; word-break: break-word; }
.fc-del { background: none; border: none; font-size: 26px; color: #cbd5e1; cursor: pointer; padding: 0 4px; flex: 0 0 auto; } .fc-del:active { color: var(--err); }

/* Ảnh & PDF: trang preview đều render trong .preview-block (full-bleed) bên dưới. */

/* ====== ẢNH: KHỐI PREVIEW — trang to HẾT CỠ (viền chạm mép màn hình), công cụ dính sát đáy ====== */
/* Khối tràn hết bề ngang màn hình; nền xám để trang trắng "nổi".
   --pageW = bề rộng trang: to nhất tới mép màn hình, NHƯNG chừa đủ chiều cao để công cụ vẫn nằm trong màn hình. */
.preview-block { width: 100vw; margin-left: calc(-50vw + 50%); background: #cbd5e1;
  padding: 2px 0 10px; margin-top: 8px; display: flex; flex-direction: column; align-items: center;
  --pageW: min(100vw, calc((100vh - 220px) * var(--arn))); }
@supports (height: 100dvh) { .preview-block { --pageW: min(100vw, calc((100dvh - 196px) * var(--arn))); } }

/* page-frame: khung định vị cho TRANG + chip số trang (để chip không bị img-stage cắt) */
.page-frame { position: relative; width: var(--pageW); }
/* TRANG IN: viền đen đậm CHẠM mép màn hình khi đủ rộng, KHÔNG bo góc, shadow 3D đều+đậm */
.img-stage { position: relative; background: #fff; border: 2px solid #0f172a; border-radius: 0; overflow: hidden;
  box-shadow: 0 0 32px 9px rgba(0,0,0,.55), 0 0 13px 4px rgba(0,0,0,.5);
  aspect-ratio: var(--arn); width: 100%; }
.img-stage .page-img { position: absolute; user-select: none; -webkit-user-drag: none; filter: grayscale(1); }

/* HÀNG CÔNG CỤ: rộng ĐÚNG bằng trang (--pageW), dính sát đáy trang, KHÔNG thành ô riêng (nền trong suốt) */
.ctrl-scroll { position: relative; width: var(--pageW); max-width: 100vw; margin-top: 0; }
.ctrl-row { display: flex; gap: 16px; align-items: flex-start; justify-content: flex-start;
  overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 150px 6px 4px;   /* 150px DƯ ở cuối để cuộn thoải mái */
  scrollbar-width: none; }                       /* ẩn thanh cuộn gốc — dùng thanh tự vẽ .hbar luôn hiện */
.ctrl-row::-webkit-scrollbar { display: none; }
.ctrl-grp { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 0 0 auto; }
/* chữ chú thích GIỮ NGUYÊN cỡ (11px) — thêm VIỀN SÁNG để đọc rõ ngay trên bóng đổ, không cần nền */
/* dời xuống 4px bằng position:relative (KHÔNG đẩy nút bên dưới) -> nằm giữa viền dưới page và viền trên nút; viền sáng MẠNH hơn */
.ctrl-lbl { position: relative; top: 4px; color: #0f172a; font-size: 11px; font-weight: 800; text-align: center; line-height: 1.15; max-width: 120px;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 5px #fff, 0 0 7px #fff, 0 0 9px #fff, 0 0 11px #fff, 0 1px 2px #fff; }
.scale-ctrl { display: inline-flex; align-items: center; gap: 2px; }
.pad-row { display: inline-flex; gap: 4px; }
.padbtn { width: 38px; height: 38px; border: 1px solid var(--line); background: #f8fafc; border-radius: 9px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.padbtn:active { background: #eef2ff; }
.padbtn svg { width: 21px; height: 21px; display: block; pointer-events: none; }   /* icon nút RÕ RÀNG (vẽ SVG) */
.padbtn svg path { fill: none; stroke: var(--blue); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.scaleval { min-width: 46px; text-align: center; font-weight: 700; font-size: 14px; }
.seg.sm button { padding: 0 12px; height: 38px; font-size: 14px; }

/* GỢI Ý CUỘN NGANG: mũi tên TRÒN rõ ràng (mất khi cuộn hết phía đó) + mờ nhẹ mép; THANH CUỘN tự vẽ LUÔN hiện */
.cue { position: absolute; top: 0; bottom: 16px; width: 30px; display: flex; align-items: center; pointer-events: none; transition: opacity .15s ease; z-index: 2; }
.cue-l { left: 0; justify-content: flex-start; background: linear-gradient(to right, rgba(203,213,225,.95), rgba(203,213,225,0)); }
.cue-r { right: 0; justify-content: flex-end; background: linear-gradient(to left, rgba(203,213,225,.95), rgba(203,213,225,0)); }
.cue-ico { display: flex; align-items: center; justify-content: center; width: 23px; height: 23px; border-radius: 50%; background: #0f172a; box-shadow: 0 1px 5px rgba(0,0,0,.4); }
.cue-ico svg { width: 12px; height: 12px; display: block; }   /* mũi tên SVG: căn giữa tuyệt đối trong nút (không lệch) */
.cue-ico svg path { fill: none; stroke: #fff; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.ctrl-scroll.at-start .cue-l, .ctrl-scroll.at-end .cue-r, .ctrl-scroll.no-scroll .cue { opacity: 0; }
/* Thanh cuộn ngang TỰ VẼ — LUÔN hiển thị để người dùng biết có thể cuộn (không ẩn) */
.hbar { height: 6px; margin: 4px 8px 2px; background: rgba(15,23,42,.16); border-radius: 999px; position: relative; }
.hbar-thumb { position: absolute; top: 0; left: 0; height: 100%; width: 100%; min-width: 22px; background: rgba(15,23,42,.55); border-radius: 999px; }

.fc-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; margin-top: 10px; }
.mini { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background:#fff; }
.stepper button { width: 40px; height: 40px; border: none; background: #f8fafc; font-size: 22px; color: var(--blue); cursor: pointer; } .stepper button:active { background: #eef2ff; } .stepper b { min-width: 46px; text-align: center; font-size: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background:#fff; }
.seg button { border: none; background: #f8fafc; padding: 0 16px; height: 40px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; } .seg button.on { background: var(--blue); color: #fff; }

/* PDF: mỗi trang render Y NHƯ ẢNH (page-frame + img-stage + Bộ điều khiển đầy đủ). */
.pdf-group { margin-top: 10px; }
.pdf-group-head { font-weight: 700; font-size: 13px; color: #475569; margin-bottom: 6px; padding: 0 2px; }
.pdf-pages { display: flex; flex-direction: column; gap: 28px; }
.pdf-page { display: flex; flex-direction: column; }
.preview-block.pdf { padding-top: 30px; }   /* chừa chỗ cho CHIP số trang đè LÊN viền trên của trang */
.pdf-page.excluded .img-stage { outline: 3px solid var(--err); }
.pdf-page.excluded .page-img { opacity: .45; }
/* Dấu X TO gạch chéo (xám đen) đè lên trang khi tick "Không in trang này" */
.excl-x { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; z-index: 2; transition: opacity .12s ease; }
.excl-x line { stroke: #334155; stroke-width: 3; vector-effect: non-scaling-stroke; stroke-linecap: round; }
.pdf-page.excluded .excl-x { opacity: 1; }
/* CHIP số trang: chữ ĐEN nền TRẮNG, đè LÊN viền TRÊN của trang — đáy chip CHẠM viền, KHÔNG lấn vào trong trang, chồng lên shadow */
.pnum-chip { position: absolute; left: 50%; top: 0; transform: translate(-50%, -100%); z-index: 3;
  font-size: 17px; font-weight: 800; line-height: 1; color: #0f172a; background: #fff; border: 1px solid rgba(15,23,42,.18); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
/* Ô "Không in trang này": NẰM TRONG bộ điều khiển (trước Hướng giấy) — khung nền trắng, chữ đen 2 dòng canh trái, giữ fontsize 16px */
.page-check { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; cursor: pointer;
  background: #fff; border: 1px solid rgba(15,23,42,.18); border-radius: 12px; padding: 6px 10px;
  font-weight: 800; font-size: 16px; line-height: 1.12; color: #0f172a; }
.page-check .pc-text { text-align: left; white-space: nowrap; }
.page-check input { width: 22px; height: 22px; accent-color: var(--err); flex: 0 0 auto; margin: 0; }
.page-check.on { color: #991b1b; background: #fee2e2; border-color: #fecaca; }

/* PRINT DOCK */
.print-dock { position: static; margin: 20px 0 8px; }
.print-dock .btn { width: 100%; box-shadow: 0 6px 20px rgba(37,99,235,.35); }

/* JOBS LIST (thẻ, sẵn cho progress + huỷ ở Đợt 2) */
.jobs { margin-top: 28px; } .jobs-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; } .jobs-head h2 { font-size: 17px; margin: 0; } .jobs-sub { color: var(--muted); font-size: 13px; }
.jobs-list { display: flex; flex-direction: column; gap: 10px; }
.jobs-pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; }
.jobs-pager .pager-info { font-size: 13px; font-weight: 700; color: var(--muted); }
.jobs-empty { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; text-align: center; color: var(--muted); }
.job-card { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; }
.job-top { display: flex; align-items: center; gap: 10px; }
.job-name { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; word-break: break-word; }
.job-time { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.job-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.jst { font-weight: 700; font-size: 11px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.jst-queued { background: #fef9c3; color: #854d0e; } .jst-printing { background: #dbeafe; color: #1e40af; } .jst-done { background: #dcfce7; color: #166534; }
.jst-failed, .jst-jam { background: #fee2e2; color: #991b1b; } .jst-cancelled { background: #e2e8f0; color: #475569; }
.faint { opacity: .55; }

/* Toast + busy */
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px; z-index: 60; max-width: 90%; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.toast.err { background: var(--err); } .toast.ok { background: var(--ok); }
.busy { position: fixed; inset: 0; background: rgba(255,255,255,.85); z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; font-weight: 600; }
.spinner { width: 44px; height: 44px; border: 4px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
