/* Lớp theme 3T Construction phủ lên Bootstrap 5: đỏ thương hiệu + xám than, chữ Times New Roman */

/* Tinos: cùng số đo với Times New Roman, dùng khi máy người xem không có sẵn Times New Roman */
@font-face { font-family: 'Tinos'; src: url('/fonts/Tinos-Regular.ttf') format('truetype'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Tinos'; src: url('/fonts/Tinos-Bold.ttf') format('truetype'); font-weight: 600 900; font-style: normal; font-display: swap; }
@font-face { font-family: 'Tinos'; src: url('/fonts/Tinos-Italic.ttf') format('truetype'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'Tinos'; src: url('/fonts/Tinos-BoldItalic.ttf') format('truetype'); font-weight: 600 900; font-style: italic; font-display: swap; }

:root {
  --brand: #d71f26;
  --brand-hover: #b3161c;
  --brand-active: #9c1218;
  --brand-soft: #fdecec;
  --ink: #36373b;
  --bs-primary: #d71f26;
  --bs-primary-rgb: 215, 31, 38;
  --bs-primary-text-emphasis: #8f1419;
  --bs-primary-bg-subtle: #fdecec;
  --bs-primary-border-subtle: #f4b9bc;
  --bs-link-color: #d71f26;
  --bs-link-color-rgb: 215, 31, 38;
  --bs-link-hover-color: #b3161c;
  --bs-link-hover-color-rgb: 179, 22, 28;
  --bs-body-font-family: 'Times New Roman', Tinos, Times, serif;
  --bs-body-font-size: 1.0625rem;
  --bs-body-color: #1f2937;
}
body { background-color: #f3f4f6; }
[hidden] { display: none !important; }

/* Trang Cấu hình */
.watermark-thumb { width: 180px; height: 120px; display: grid; place-items: center; padding: 8px;
  background: repeating-conic-gradient(#f1f3f5 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.watermark-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-sheet { background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12); aspect-ratio: 1 / 1.414; overflow: hidden; }
.preview-sheet img { width: 100%; height: 100%; object-fit: contain; display: block; }

.btn-primary {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-hover); --bs-btn-hover-border-color: var(--brand-hover);
  --bs-btn-active-bg: var(--brand-active); --bs-btn-active-border-color: var(--brand-active);
  --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
  --bs-btn-focus-shadow-rgb: 215, 31, 38;
}
.btn-outline-primary {
  --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand);
  --bs-btn-active-bg: var(--brand-active); --bs-btn-active-border-color: var(--brand-active);
  --bs-btn-focus-shadow-rgb: 215, 31, 38;
}
.form-control:focus, .form-select:focus { border-color: #ec8a8e; box-shadow: 0 0 0 0.25rem rgba(215, 31, 38, 0.15); }
.form-check-input:focus { border-color: #ec8a8e; box-shadow: 0 0 0 0.25rem rgba(215, 31, 38, 0.15); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.nav-underline .nav-link { color: #6b7280; font-weight: 600; }
.nav-underline .nav-link.active, .nav-underline .nav-link:hover { color: var(--brand); }
.text-ink { color: var(--ink) !important; }
.fw-semibold { font-weight: 600 !important; }

/* ---------- Thương hiệu ---------- */
.brand { display: inline-flex; align-items: center; gap: 0.6rem; color: var(--ink); text-decoration: none; line-height: 1.15; }
.brand img { height: 42px; width: auto; }
.brand strong { display: block; font-size: 1rem; }
.brand small { display: block; font-size: 0.7rem; color: #6b7280; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.company { font-size: 0.8rem; color: #6b7280; line-height: 1.6; }
.company strong { color: var(--ink); letter-spacing: 0.04em; }

/* ---------- Đăng nhập ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 1.25rem; padding: 1.5rem 1rem; background: radial-gradient(1200px 500px at 50% -10%, #f8dcdd, transparent), #f3f4f6; }
.auth-card { width: 100%; max-width: 420px; border: 0; border-top: 4px solid var(--brand); }
.auth-logo { display: block; width: 140px; height: auto; margin: 0 auto 1rem; }

/* ---------- Thư viện ---------- */
.dropzone {
  border: 2px dashed #f0b7b9; border-radius: 0.75rem; background: #fffafa;
  display: grid; place-items: center; text-align: center; padding: 1.5rem 1rem; cursor: pointer;
  min-height: 210px; height: 100%; transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover, .dropzone.drag { background: var(--brand-soft); border-color: var(--brand); }
.dropzone .bi { font-size: 2.4rem; color: var(--brand); }
.user-picker { max-height: 160px; overflow: auto; }
.doc-card { transition: box-shadow 0.15s, transform 0.15s; }
.doc-card:hover { box-shadow: 0 0.5rem 1.25rem rgba(15, 23, 42, 0.1) !important; transform: translateY(-1px); }
.doc-icon { font-size: 2.3rem; line-height: 1; }
.doc-icon.pdf { color: #dc2626; }
.doc-icon.docx { color: #2563eb; }
.doc-icon.image { color: #059669; }
.doc-title { font-size: 1rem; word-break: break-word; }
.table thead th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: #6b7280; white-space: nowrap; }
.stat-pill { font-variant-numeric: tabular-nums; }

/* ---------- Trình xem ---------- */
body.viewer {
  background: #3b4250; overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.vbar {
  position: fixed; inset: 0 0 auto 0; height: 56px; z-index: 30;
  display: flex; align-items: center; gap: 0.75rem; padding: 0 0.75rem;
  background: #1f2430; color: #e5e7eb; border-bottom: 1px solid #111827;
}
.vlogo { height: 38px; width: auto; background: #fff; border-radius: 0.4rem; padding: 2px 6px; }
.vtitle { flex: 1; min-width: 0; font-weight: 600; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vctrl .label { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; color: #cbd5e1; font-size: 0.85rem; }

#stage { position: fixed; inset: 56px 0 0 0; overflow: auto; overscroll-behavior: contain; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 1.25rem 0.75rem 4rem; }
.page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35); }
.page canvas { display: block; width: 100%; height: 100%; pointer-events: none; }
/* Canvas + lớp ghi chú nằm chung trong .page-inner; xoay trang là xoay khối này */
.page-inner { position: absolute; inset: 0; }
#pages.rotated .page .page-inner { inset: auto; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(var(--rot, 0deg)); }

/* Ghi chú / vẽ */
.annot { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.annot .pending { opacity: 0.85; }
body.annot-drawing .annot { pointer-events: auto; touch-action: none; cursor: crosshair; }
body[data-annot-tool="text"] .annot { cursor: text; }
body[data-annot-tool="eraser"] .annot { cursor: cell; }
.annot-bar { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 40; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  max-width: calc(100vw - 24px); padding: 6px 10px; border-radius: 12px; background: rgba(15, 23, 42, 0.94); color: #e2e8f0; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45); }
.annot-bar .btn-outline-light.active { background: #f8fafc; color: #0f172a; }
.annot-thread { max-width: 240px; }
.annot-color { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5); background: var(--c); padding: 0; }
.annot-color.active { border-color: #fff; box-shadow: 0 0 0 2px var(--c); }
.annot-status { min-width: 0; color: #cbd5e1; }
.annot-history { position: absolute; bottom: calc(100% + 8px); right: 0; width: min(420px, calc(100vw - 24px)); max-height: 50vh; overflow: auto;
  background: #fff; color: #0f172a; border-radius: 10px; padding: 10px 12px; font-size: 0.85rem; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35); }
.annot-history-row { border-top: 1px solid #e2e8f0; padding: 6px 0; }
.annot-input { position: fixed; z-index: 50; min-width: 220px; max-width: 60vw; border: 2px dashed currentColor; background: rgba(255, 255, 255, 0.95);
  font-family: 'Times New Roman', Tinos, serif; font-weight: 600; line-height: 1.2; padding: 2px 4px; resize: none; outline: none; }
body.shielded .annot-bar, body.shielded .annot-input { visibility: hidden; }
.page .loading { position: absolute; inset: 0; display: grid; place-items: center; color: #94a3b8; font-size: 0.85rem; }
.page .pno { position: absolute; left: 100%; bottom: 0; margin-left: 8px; font-size: 0.75rem; color: #9ca3af; }
/* Album ảnh: lưới ảnh nhỏ (vẫn có watermark), bấm để xem ảnh lớn */
#pages.grid { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 0.75rem; }
#pages.grid .page { cursor: zoom-in; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35); }
#pages.grid .page:hover { outline: 2px solid #f87171; }
#pages.grid .pno { left: auto; right: 6px; bottom: 6px; margin: 0; padding: 0 6px; border-radius: 8px; background: rgba(15, 23, 42, 0.7); color: #fff; }

/* Watermark nổi phía trên trang, đổi giờ liên tục: ảnh chụp nào cũng mang dấu người xem */
.wm-overlay { position: fixed; inset: 56px 0 0 0; z-index: 25; pointer-events: none; background-repeat: repeat; }

/* Tấm che: bật khi cửa sổ mất focus, chuột rời cửa sổ, giữ phím chụp màn hình… */
.shield {
  position: fixed; inset: 56px 0 0 0; z-index: 40;
  display: none; place-items: center; padding: 1rem;
  background: #1f2430;
  pointer-events: none; /* chuột vẫn đi xuyên qua để nhận biết lúc quay lại */
}
body.shielded .shield { display: grid; }
body.shielded #pages { visibility: hidden; }
.shield-box { max-width: 440px; text-align: center; color: #e5e7eb; }
.shield-box .bi { font-size: 2.8rem; color: #f87171; }
.shield-box h2 { font-size: 1.2rem; margin: 0.75rem 0 0.4rem; }
.shield-box p { color: #9ca3af; margin: 0; }
.blocked { position: fixed; inset: 56px 0 0 0; display: grid; place-items: center; padding: 1rem; }

/* Toàn màn hình: thanh công cụ trượt lên, tài liệu chiếm hết màn hình */
.vbar { transition: transform 0.2s ease; }
body.immersive .vbar { transform: translateY(-100%); }
body.immersive #stage, body.immersive .wm-overlay, body.immersive .shield { top: 0; }
.exit-immersive { position: fixed; top: 8px; right: 8px; z-index: 45; display: none; opacity: 0.75; }
body.immersive .exit-immersive { display: inline-flex; }

/* In: chỉ vùng in (trang đã vẽ watermark bản in) được đưa ra máy in */
#print-area { display: none; }
.print-status {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 46; max-width: calc(100vw - 24px);
  background: rgba(17, 24, 39, 0.92); color: #e5e7eb; font-size: 0.85rem; padding: 0.45rem 0.9rem; border-radius: 999px;
}
@media print {
  @page { margin: 6mm; }
  body * { display: none !important; }
  body::after { content: 'Tài liệu này chỉ được in bằng nút "In" của trình xem SecureDoc (bản in có watermark).'; display: block; padding: 40px; font: 16px serif; }
  body.printing { overflow: visible !important; background: #fff !important; }
  body.printing::after { content: none; display: none; }
  body.printing #print-area { display: block !important; }
  body.printing #print-area .print-page {
    display: flex !important; align-items: center; justify-content: center;
    height: calc(100vh - 1px); break-after: page; page-break-after: always;
  }
  body.printing #print-area .print-page:last-child { break-after: auto; page-break-after: auto; }
  body.printing #print-area img { display: block !important; max-width: 100%; max-height: 100%; object-fit: contain; }
}

@media (max-width: 767.98px) {
  .brand > span { display: none; }
  .vlogo, .vctrl .hide-sm, .protect-badge { display: none !important; }
}

/* Thư viện: cây thư mục */
.folder-panel { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; }
.folder-tree { padding: 0.35rem 0; font-size: 0.92rem; }
.folder-tree ul { list-style: none; padding: 0; margin: 0; }
.tree-row { display: flex; align-items: center; padding-left: calc(0.4rem + var(--depth, 0) * 0.9rem); border-left: 3px solid transparent; }
.tree-row:hover { background: #f6f7f9; }
.tree-row.active { background: #fdecec; border-left-color: var(--bs-danger); }
.tree-row.drop { background: #e7f1ff; outline: 2px dashed var(--bs-primary); outline-offset: -2px; }
.tree-caret { width: 1.4rem; flex: none; border: 0; background: none; padding: 0; color: #6c757d; font-size: 0.75rem; text-align: center; }
.tree-name { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 0.3rem 0.5rem 0.3rem 0.1rem; display: flex; gap: 0.35rem; align-items: center; color: inherit; }
.tree-name .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-count { margin-left: auto; font-size: 0.75rem; color: #6c757d; }
.folder-card { cursor: pointer; transition: box-shadow 0.15s ease; }
.folder-card:hover { box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.1) !important; }
.folder-card .bi-folder-fill { font-size: 1.8rem; color: #e0a526; }
.folder-card.drop { outline: 2px dashed var(--bs-primary); }
.stage-heading { font-size: 0.95rem; font-weight: 700; margin: 1.25rem 0 0.6rem; display: flex; align-items: center; gap: 0.5rem; }
.stage-heading:first-child { margin-top: 0; }
.doc-card.selected { outline: 2px solid var(--bs-primary); }
.doc-select { position: absolute; top: 0.6rem; right: 0.6rem; }
.doc-icon.gallery { color: #198754; }
.doc-path { font-size: 0.75rem; }
@media (max-width: 991.98px) { .folder-panel { position: static; max-height: 40vh; } }
