body {
  font-family: 'SF Pro Display', Arial, sans-serif;
  background-color: #ffffff;
}

/* Nút Đăng xuất (trước là nút Đăng nhập / Đăng xuất Google) — nổi bật, đổi màu theo trạng thái */
.gauth-btn {
  font-size: 13px;
  font-weight: bold;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
  transition: all 0.2s ease;
  white-space: nowrap;
}
.gauth-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 12px rgba(0,0,0,0.3);
}
.gauth-btn.gauth-out {
  background: linear-gradient(135deg, #4285F4, #3367d6); /* xanh dương Google - chưa đăng nhập */
}
.gauth-btn.gauth-out:hover {
  background: linear-gradient(135deg, #3367d6, #2a56c6);
}
.gauth-btn.gauth-in {
  background: linear-gradient(135deg, #e74c3c, #c0392b); /* đỏ - đã đăng nhập, bấm để đăng xuất */
}
.gauth-btn.gauth-in:hover {
  background: linear-gradient(135deg, #c0392b, #a93226);
}

/* Container để gom input và preview song song */
.container {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  margin: 20px;
  gap: 20px;
}

/* Khung nhập liệu bên trái */
.input-section {
  flex: 0 0 35%;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 12px;
  background: linear-gradient(135deg, #fdfdfd, #f3f7fb);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.input-section h3, .input-section h4 {
  margin-top: 15px;
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: bold;
  color: #2c3e50;
  border-left: 4px solid #2196F3;
  padding-left: 8px;
}

.input-section label {
  display: block;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 500;
  color: #333;
}

.input-section input[type="text"],
.input-section input[type="file"],
.input-section textarea,
.input-section select {
  width: 95%;
  padding: 8px 10px;
  margin-top: 5px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 13px;
  transition: border-color 0.3s, box-shadow 0.3s;
  background-color: #fff;
  font-family: inherit;
}

.input-section input:focus,
.input-section textarea:focus,
.input-section select:focus {
  border-color: #2196F3;
  box-shadow: 0 0 5px rgba(33,150,243,0.4);
  outline: none;
}

/* ===== Gợi ý mã sản phẩm (autocomplete tự viết, không dùng datalist để
   lọc đúng kiểu "bắt đầu bằng" thay vì "chứa" ký tự bất kỳ) ===== */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  left: 0;
  top: 100%;
  width: 95%;
  background: #fff;
  border: 1px solid #bbb;
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  display: none;
  box-shadow: 0 6px 14px rgba(0,0,0,0.12);
}
.autocomplete-list div {
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.autocomplete-list div:last-child { border-bottom: none; }
.autocomplete-list div:hover,
.autocomplete-list div.active { background: #eaf3fc; }
.autocomplete-list .ac-code { font-weight: 600; color: #2c3e50; }
.autocomplete-list .ac-name { font-size: 11px; color: #778; margin-left: 8px; }
.button-row button:nth-child(2) {
  background-color: #e74c3c;
  color: #fff;
}

.button-row button:nth-child(2):hover {
  background-color: #c0392b;
  transform: translateY(-2px);
}


/* Hàng nút */
.fixed-buttons {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: grid;
  grid-template-columns: repeat(4, auto); /* tối đa 4 nút mỗi hàng */
  gap: 10px;
  background: rgba(255,255,255,0.95);
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 9999;
}

.fixed-buttons button {
  min-width: 100px;   /* chiều rộng tối thiểu cho đều */
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
  border: none;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: all 0.2s ease;
}

/* Khoá mọi nút cần đăng nhập Google trước khi dùng (trừ nút Đăng nhập Google) */
.needs-google-auth:disabled {
  background: #ccc !important;
  color: #888 !important;
  cursor: not-allowed !important;
  box-shadow: none !important;
  transform: none !important;
}
.needs-google-auth:disabled:hover {
  background: #ccc !important;
  transform: none !important;
}

/* Mỗi nút một màu — gán theo CHỨC NĂNG (class), không theo vị trí (nth-child),
   để màu luôn giống nhau trên mọi layout dù thứ tự/số lượng nút trong DOM có khác nhau. */
.btn-clear {
  background: #e74c3c; /* đỏ cho nút Xóa toàn bộ */
}
.btn-clear:hover {
  background: #c0392b;
  transform: translateY(-2px);
}

.btn-export {
  background: #3498db; /* xanh dương cho nút Lưu / Xuất PDF */
}
.btn-export:hover {
  background: #2980b9;
  transform: translateY(-2px);
}

.btn-save-drive {
  background: #27ae60; /* xanh lá cho nút Lưu Lên Drive */
}
.btn-save-drive:hover {
  background: #1e8449;
  transform: translateY(-2px);
}

.btn-layout {
  background: #1abc9c; /* xanh ngọc cho các nút đổi Layout */
}
.btn-layout:hover {
  background: #16a085;
  transform: translateY(-2px);
}

.btn-help {
  background: #9b59b6; /* tím cho nút Hướng dẫn / Báo lỗi */
}
.btn-help:hover {
  background: #8e44ad;
  transform: translateY(-2px);
}

.btn-origin-ref {
  background: #2c3e50; /* xanh xám đậm cho nút Tham khảo xuất xứ */
}
.btn-origin-ref:hover {
  background: #1a252f;
  transform: translateY(-2px);
}
/* Nút Hiển thị trên giấy */
.button-row button:first-child {
  background-color: #4CAF50; /* xanh lá */
  color: #fff;
}

.button-row button:first-child:hover {
  background-color: #45a049;
  transform: translateY(-2px);
}

/* Nút Xuất PDF */
.button-row button:last-child {
  background-color: #2196F3; /* xanh dương */
  color: #fff;
}

.button-row button:last-child:hover {
  background-color: #1976D2;
  transform: translateY(-2px);
}

/* Preview A5 bên phải */
.a5-portrait {
  flex: 0 0 auto;
  width: 148mm;   /* chiều ngang A5 */
  height: 210mm;  /* chiều dọc A5 */
  position: relative;
  box-sizing: border-box;
  /* Không đặt border trực tiếp trên chính khung này: khi vị trí của
     khung rơi vào số lẻ pixel, html2canvas hay cắt mất cạnh trên/trái
     của border (đúng hiện tượng bị thiếu đường kẻ trên+trái, chỉ còn
     dưới+phải khi xuất PDF). border được vẽ bằng .a5-frame lùi vào
     trong 1mm ở dưới thay vì nằm sát mép ngoài. (Thử dùng box-shadow
     thay border cũng không ổn — html2canvas 1.4.1 render sai thành
     một khối đen lớn, nên không dùng cách đó.) */
}

/* Bọc toàn bộ nội dung (viền + logo + tên SP + giá + thông tin +
   footer) và thu nhỏ còn 95%, canh giữa trang A5 — chừa lại 5% viền
   trắng an toàn quanh mép trang. Máy in thường không in được sát mép
   giấy (vùng an toàn ~3-5mm mỗi cạnh), nên nếu vẽ viền sát mép 148x210mm
   thật thì máy in sẽ cắt mất; thu nhỏ lại để viền luôn nằm trong vùng
   in được của mọi máy in. */
.a5-scale-wrap {
  position: absolute;
  inset: 0;
  transform: scale(0.95);
  transform-origin: center center;
}

.a5-frame {
  position: absolute;
  top: 1mm;
  left: 1mm;
  right: 1mm;
  bottom: 1mm;
  border: 1px solid #000;
  pointer-events: none;
}

/* Cột nội dung chính: tên SP, giá, thông tin, kích thước đều nằm
   trong 1 cột duy nhất, cùng lề trái/phải, xếp chồng tự nhiên theo
   thứ tự — trước đây mỗi khối bị neo cứng bằng "top: Xmm" riêng nên
   chỗ thì đè nhau, chỗ thì hở khoảng trắng quá to tuỳ theo dữ liệu. */
.half.left {
  position: absolute;
  top: 7mm;
  left: 12mm;
  width: 124mm;         /* lề trái/phải đều 12mm trên khổ 148mm */
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Logo công ty trên cùng trang */
.company-logo-top {
  width: 62mm;
  height: auto;
  margin-bottom: 4mm;
}

/* Khung nhóm 1: Tên sản phẩm + Mô tả */
.group1 {
  width: 100%;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 4mm;
}

.group1 h2 {
  margin: 0;
  font-size: 34px;
  font-weight: bold;
  text-align: center;
  text-transform: uppercase;
}

.group1 p {
  margin: 4px 0 0 0;
  font-size: 20px;
  text-align: center;
  text-transform: capitalize;
}

/* Khung nhóm 2: Giá */
.group2 {
  width: 100%;          /* trước lệch lề (20mm) so với các khối bên dưới (12mm) */
  margin-bottom: 5mm;
}

.price-box.combined {
  width: 100%;
  box-sizing: border-box;
  border: 1.5px solid #000;
  border-radius: 6px;
  background-color: #fff;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.price {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2mm 1mm;
  box-sizing: border-box;
}

.price .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.price .value {
  font-size: 18px;
  margin-top: 4px;
  line-height: 1;
}

/* Giá niêm yết: nhạt/nhỏ hơn để làm nền cho giá ưu đãi */
.price.listed .label {
  color: #777;
  font-weight: 500;
}

.price.listed .value {
  color: #777;
  font-weight: 500;
}

.price.listed .value .amount {
  text-decoration: line-through;
}

/* Giá ưu đãi: nổi bật nhờ cỡ chữ to + đậm hơn hẳn giá niêm yết,
   không tô nền đen để đỡ tốn mực khi in nhiều tờ */
.price.discount .label {
  color: #000;
}

.price.discount .value strong {
  font-size: 30px;
  font-weight: 800;
  color: #000;
}

.divider {
  width: 1.5px;
  background-color: #000;
  align-self: stretch;   /* co giãn theo chiều cao 2 cột giá, không cần height:100% */
}

.group3, .group4 {
  width: 100%;
  background-color: #fff;
  font-size: 14px;
  margin-bottom: 4mm;
}

.group3 h3, .group4 h3 {
  margin: 0 0 2mm 0;
  padding-bottom: 1mm;
  font-size: 16px;
  font-weight: bold;
  text-transform: uppercase;
  border-bottom: 1.5px solid #000;   /* gạch chân tiêu đề để phân tách khối rõ ràng */
}

.group3 ul, .group4 ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.group3 li, .group4 li {
  padding: 0.6mm 0;
  border-bottom: 1px dotted #bbb;    /* các dòng thông số ngăn cách nhẹ như phiếu in */
}

.group3 li:last-child, .group4 li:last-child {
  border-bottom: none;
}

#paperRightContent {
  font-size: 18px;
  line-height: 1.5;
  white-space: pre-wrap;        /* giữ xuống dòng, đồng thời cho phép wrap chữ */
  word-wrap: break-word;        /* ngắt từ dài */
  overflow-wrap: break-word;    /* ngắt từ dài (chuẩn mới) */
  top: 30mm;
  left: 9mm;
  width: 85mm;                  /* giới hạn chiều rộng khung */
  box-sizing: border-box;       /* đảm bảo padding/border không làm tràn */

  /* Giới hạn số dòng hiển thị */
  display: -webkit-box;
  -webkit-line-clamp: 17;       /* tối đa 17 dòng */
  -webkit-box-orient: vertical;
  overflow: hidden;
}


@import url('https://cdn.jsdelivr.net/npm/sf-font@latest/sf-font.css');
/* Input bắt buộc: viền đỏ nhạt */
.input-section input[required],
.input-section textarea[required],
.input-section select[required] {
  border: 1px solid #d88;   /* đỏ nhạt */
  background-color: #fff;   /* giữ nền trắng */
}

/* Input không bắt buộc: viền xanh nhạt */
.input-section input:not([required]),
.input-section textarea:not([required]),
.input-section select:not([required]) {
  border: 1px solid #88b;   /* xanh nhạt */
  background-color: #fff;   /* giữ nền trắng */
}

/* Hiệu ứng khi focus để nổi bật hơn một chút */
.input-section input:focus,
.input-section textarea:focus {
  outline: none;
  border-color: #555;       /* viền xám đậm khi focus */
  box-shadow: 0 0 4px rgba(0,0,0,0.1);
}


.btn-drive {
  display: flex;
  align-items: center;
  justify-content: center;   /* căn giữa theo chiều ngang */
  gap: 6px;              /* khoảng cách giữa icon và chữ */
  background: #ff69b4;   /* màu nền nút */
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: all 0.2s ease;
}

.btn-drive:hover {
  background: #d63384;
  transform: translateY(-2px);
}

.btn-drive:disabled {
  background: #ccc;
  color: #888;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-drive:disabled:hover {
  background: #ccc;
  transform: none;
}

.icon-drive {
  width: 18px;
  height: 18px;
}

#progress-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;
  height: 24px;
  background: linear-gradient(135deg, #ddd, #bbb);
  border-radius: 12px;
  overflow: hidden;
  display: none;
  z-index: 99999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4caf50, #81c784);
  transition: width 0.3s ease;
}

#progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: bold;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
#toast {
  min-width: 300px;
  max-width: 80%;
  background: linear-gradient(135deg, #4caf50, #81c784);
  color: #fff;
  text-align: center;
  border-radius: 8px;
  padding: 14px 20px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  z-index: 10000;
  font-size: 15px;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none; /* tránh click */
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#toast.hide {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.9);
}

#toast.error {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
}
.search-box {
  display: flex;
  align-items: center;   /* căn giữa theo chiều dọc */
  gap: 6px;              /* khoảng cách giữa input và nút */
  margin-top: 8px;
}

.search-box input {
  flex: 1;               /* input chiếm hết chiều ngang */
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.search-box button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px; /* đẩy xuống dưới */
}

.search-box button:hover {
  background-color: #0056b3;
}
/* Danh sách kết quả — giới hạn chiều cao giống ô gợi ý Mã sản phẩm (.autocomplete-list),
   không cho xổ dài vô hạn, cuộn bên trong khi có nhiều kết quả */
#searchResults {
  list-style: none;
  padding: 0;
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 6px;
}
#searchResults:empty {
  border: none;
}
#searchResults li {
  padding: 8px;
  border-bottom: 1px solid #ddd;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
#searchResults li:hover {
  background-color: #f0f0f0;
}
#searchResults li:active {
  background-color: #d0e0ff; /* hiệu ứng click */
}
#searchResults li {
  user-select: none;   /* không cho chọn text */
}
#tipsModal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

#tipsModal .modal-content {
  background: #fff;
  padding: 20px;
  border-radius: 10px;
  width: 1000px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

#tipsModal h3 {
  margin-top: 0;
  font-size: 16px;
  font-weight: bold;
  color: #2c3e50;
}

#tipsModal button {
  margin-top: 10px;
  padding: 6px 12px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
#tipsModal button:hover {
  background: #2980b9;
}
#tipsModal pre {
  font-family: 'SF Pro Display', Arial, sans-serif; /* không dùng monospace */
  white-space: pre-line; /* giữ xuống dòng nhưng font vẫn đẹp */
}
#confirmModal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

#confirmModal .modal-content {
  background: #fff;
  padding: 20px;
  border-radius: 10px;
  width: 360px;
  font-family: 'SF Pro Display', Arial, sans-serif;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  text-align: center;
}

#confirmModal .modal-buttons {
  margin-top: 15px;
  display: flex;
  justify-content: space-around;
}

#confirmModal button {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

#confirmYes {
  background: #27ae60;
  color: #fff;
}
#confirmYes:hover {
  background: #219150;
}

#confirmNo {
  background: #e74c3c;
  color: #fff;
}
#confirmNo:hover {
  background: #c0392b;
}

/* 3 lựa chọn khi phát hiện trùng file trên Drive */
#confirmOverwrite {
  background: #e67e22;
  color: #fff;
}
#confirmOverwrite:hover {
  background: #ca6f1e;
}
#confirmExportOnly {
  background: #3498db;
  color: #fff;
}
#confirmExportOnly:hover {
  background: #2980b9;
}
#confirmCancel {
  background: #95a5a6;
  color: #fff;
}
#confirmCancel:hover {
  background: #7f8c8d;
}
.company-footer {
  position: absolute;
  bottom: 7mm;
  left: 12mm;                  /* căn cùng lề 12mm với cột nội dung phía trên */
  right: 12mm;
  padding-top: 2mm;
  border-top: 1px solid #000;  /* tách phần footer khỏi nội dung phía trên */
  display: flex;              /* logo và text nằm ngang */
  align-items: center;        /* căn giữa logo theo chiều dọc với text */
  gap: 10px;                  /* khoảng cách logo và text */
}

.company-logo {
  width: 16mm;
  height: auto;
  flex-shrink: 0;
}

.company-text {
  flex: 1;
  font-size: 10px;
  line-height: 1.3;
}

.company-text p {
  margin: 0;                  /* trước dùng <br>...</br> khiến mỗi dòng bị xuống dòng 2 lần
                                  (</br> không hợp lệ, bị trình duyệt hiểu thành 1 <br> nữa) */
}
.note {
  position: absolute;
  top: 100%;                  /* nằm ngay dưới khung A5, không dùng margin ảo nữa */
  left: 0;
  width: 100%;
  margin-top: 6px;
  font-size: 12px;
  color: #666; /* màu xám nhạt */
  text-align: center;
  font-family: 'SF Pro Display', Arial, sans-serif;
}
#popupRef {
  position: fixed;
  right: 20px;
  bottom: 150px;   /* đẩy lên trên cụm nút */
  background: #2196F3;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 9999;
  font-size: 14px;
}

#popupRef a {
  color: #fff;
  text-decoration: none;
  font-weight: bold;
}

#popupRef:hover {
  background: #1976D2;
}

/* ===== Gợi ý đàn trong kho khi gõ Mã sản phẩm (xem piano-cu.js) — giống trang Chung ===== */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  left: 0;
  top: 100%;
  width: 95%;
  background: #fff;
  border: 1px solid #bbb;
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 50;
  display: none;
  box-shadow: 0 6px 14px rgba(0,0,0,0.12);
}
.autocomplete-list div {
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.autocomplete-list div:last-child { border-bottom: none; }
.autocomplete-list div:hover,
.autocomplete-list div.active { background: #eaf3fc; }
.autocomplete-list .ac-code { font-weight: 600; color: #2c3e50; }
.autocomplete-list .ac-name { font-size: 11px; color: #778; margin-left: 8px; }
/* Danh sách đàn rộng bằng cả 2 cột cho dễ đọc */
body.vtm-app #productCodeSuggestions { width: calc(200% + 12px); }
