/* ==========================================================================
   TRANG TẠO BÁO GIÁ — khung nhập (cột trái) + bản báo giá (cột phải).
   Bản báo giá (.qp-page) xếp DỌC, chữ to vừa đủ để khách xem trên điện
   thoại; màu theo mẫu Excel "BẢNG BÁO GIÁ - MẪU".
   ========================================================================== */

/* ---------- Khung nhập ---------- */
body.vtm-quote .input-section input[type="date"] {
  width: 100%;
  box-sizing: border-box;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #d9cfca;
  border-radius: 8px;
  background: #fff;
  font-family: var(--ui-font);
  font-size: 13.5px;
  color: var(--text);
}
body.vtm-quote .input-section input[type="date"]:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139, 30, 35, 0.12); }
body.vtm-quote .q-hint { margin: -2px 0 10px; font-size: 12px; line-height: 1.5; color: var(--muted); }
body.vtm-quote .q-remember { font-size: 11px; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--muted); margin-left: 6px; }

body.vtm-quote .q-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 12px;
  margin-bottom: 10px;
  background: #fcfaf9;
}
body.vtm-quote .q-item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
body.vtm-quote .q-item-head b { font-size: 13px; color: var(--brand); }
body.vtm-quote .q-link {
  border: none;
  background: none;
  padding: 2px 4px;
  font-family: var(--ui-font);
  font-size: 12.5px;
  color: var(--brand);
  cursor: pointer;
  text-decoration: underline;
}
body.vtm-quote .q-link:hover { color: var(--brand-dark); }
body.vtm-quote .q-img-row { display: flex; align-items: center; gap: 10px; }
body.vtm-quote .q-img-row img { width: 56px; height: 56px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
body.vtm-quote .q-noimg { font-size: 12px; color: var(--muted); }
body.vtm-quote .form-card > button.q-add {
  width: 100%;
  height: 38px;
  border: 1px dashed var(--brand);
  border-radius: 10px;
  background: #fff;
  color: var(--brand);
  font-family: var(--ui-font);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
body.vtm-quote .form-card > button.q-add:hover { background: var(--brand-soft); }
body.vtm-quote .fixed-buttons.q-buttons { grid-template-columns: auto 1fr 1fr 1fr; }
body.vtm-app .fixed-buttons .btn-preview { background: #fff; color: var(--text); border: 1px solid #d9cfca; }
body.vtm-app .fixed-buttons .btn-preview:hover { border-color: var(--brand); color: var(--brand); background: #fff; transform: none; }
body.vtm-app .fixed-buttons .btn-preview:disabled { opacity: 0.6; cursor: wait; }
body.vtm-quote .q-send-hint { grid-column: 1 / -1; margin: 0; font-family: var(--ui-font); font-size: 11.5px; line-height: 1.45; color: var(--muted); text-align: center; }

/* Khung Xem trước: các trang ảnh như khách nhận, rộng bằng màn hình điện thoại */
body.qv-open { overflow: hidden; }
#qPreview {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 24px 16px;
  background: rgba(30, 20, 20, 0.6);
  font-family: var(--ui-font);
}
#qPreview .qv-panel {
  display: flex;
  flex-direction: column;
  width: 430px;
  max-width: 100%;
  background: #f3f0ed;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
#qPreview .qv-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line); }
#qPreview .qv-head b { display: block; font-size: 15px; color: var(--brand); }
#qPreview .qv-head span { font-size: 12px; color: var(--muted); }
#qPreview .qv-pages { flex: 1; overflow-y: auto; padding: 14px; }
#qPreview .qv-page + .qv-page { margin-top: 16px; }
#qPreview .qv-no { margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; }
#qPreview .qv-page img { display: block; width: 100%; border-radius: 4px; box-shadow: 0 2px 10px rgba(60, 30, 30, 0.15); }
#qPreview .qv-foot { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; padding: 12px 16px; background: #fff; border-top: 1px solid var(--line); }
#qPreview button { height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid #d9cfca; background: #fff; color: var(--text); font-family: var(--ui-font); font-size: 14px; font-weight: 600; cursor: pointer; }
#qPreview .qv-head .qv-close { height: 32px; font-size: 13px; }
#qPreview button.qv-png { border-color: var(--brand); color: var(--brand); }
#qPreview button.qv-pdf { border-color: var(--brand); background: var(--brand); color: #fff; }
#qPreview button.qv-pdf:hover { background: var(--brand-dark); }

/* Nút chuyển khổ Dọc / Ngang */
body.vtm-quote .q-seg { display: grid; grid-template-columns: 1fr 1fr; height: 36px; border: 1px solid #d9cfca; border-radius: 8px; overflow: hidden; background: #fff; }
body.vtm-quote .q-seg button { border: none; background: none; font-family: var(--ui-font); font-size: 13.5px; color: var(--muted); cursor: pointer; }
body.vtm-quote .q-seg button + button { border-left: 1px solid #d9cfca; }
body.vtm-quote .q-seg button.active { background: var(--brand); color: #fff; font-weight: 600; }
body.vtm-quote .q-seg button:not(.active):hover { background: var(--brand-soft); color: var(--brand); }

/* Thu gọn: thẻ nhập (bấm tiêu đề) + từng sản phẩm đã nhập xong */
body.vtm-quote .form-card > .q-card-head { display: flex; align-items: baseline; gap: 8px; cursor: pointer; user-select: none; }
body.vtm-quote .form-card.collapsed > .q-card-head { margin-bottom: 0; }
body.vtm-quote .q-card-title { flex: 0 0 auto; }
body.vtm-quote .q-card-sum { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--muted); }
body.vtm-quote .form-card:not(.collapsed) .q-card-sum { visibility: hidden; }
body.vtm-quote .form-card > .q-card-head > button.q-fold {
  flex: 0 0 auto;
  margin: 0;
  padding: 2px 4px;
  border: none;
  background: none;
  font-family: var(--ui-font);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--brand);
  text-decoration: underline;
  cursor: pointer;
}
body.vtm-quote .form-card.collapsed > :not(.q-card-head) { display: none !important; }
body.vtm-quote .form-card.collapsed:hover { border-color: #e3c9c9; }

body.vtm-quote .q-item-min { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 6px; }
body.vtm-quote .q-item-sum {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px;
  border: none;
  background: none;
  font-family: var(--ui-font);
  text-align: left;
  color: var(--text);
  cursor: pointer;
}
body.vtm-quote .q-item-sum img { width: 40px; height: 40px; flex: 0 0 40px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
body.vtm-quote .q-sum-no { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: 12px; font-weight: 700; line-height: 22px; text-align: center; }
body.vtm-quote .q-sum-name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; line-height: 1.3; }
body.vtm-quote .q-sum-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.vtm-quote .q-sum-name small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
body.vtm-quote .q-item-sum b { flex: 0 0 auto; font-size: 13px; color: var(--brand); }
body.vtm-quote .q-item-min:hover { border-color: #e3c9c9; background: #fff; }
body.vtm-quote .q-item-empty .q-sum-name { font-weight: 400; font-style: italic; color: var(--muted); }
body.vtm-quote .q-item-head .q-item-acts { display: flex; gap: 6px; }

/* Gợi ý mã sản phẩm (nổi trên trang, bám theo ô Mã đang gõ) */
#qSuggest {
  position: fixed;
  z-index: 300;
  max-height: 340px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #d9cfca;
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(60, 30, 30, 0.18);
  font-family: var(--ui-font);
}
#qSuggest .qs-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid #f2ecea;
}
#qSuggest .qs-row:last-child { border-bottom: none; }
#qSuggest .qs-row.active,
#qSuggest .qs-row:hover { background: var(--brand-soft); }
#qSuggest .qs-row b { color: var(--brand); white-space: nowrap; }
#qSuggest .qs-row span { color: #5a4f4c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#qSuggest .qs-row em { font-style: normal; color: var(--muted); white-space: nowrap; font-size: 12px; }

/* ---------- Bản báo giá ----------
   Khổ 560px: gửi ảnh / PDF qua Zalo, mở trên điện thoại vẫn đọc rõ không cần phóng to. */
.qp-page {
  --q-red: #7d2128;
  --q-ink: #1f1a19;
  --q-mute: #77695f;
  --q-line: #e8e0db;
  width: 560px;
  flex: 0 0 auto;
  box-sizing: border-box;
  background: #fff;
  color: var(--q-ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: 0 6px 24px rgba(60, 30, 30, 0.14);
  margin-bottom: 60px;
  border-top: 6px solid var(--q-red);
}
.qp-page .qp-label { font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--q-red); }

/* Đầu trang */
.qp-page .qp-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--q-line);
}
.qp-page .qp-brand { display: flex; gap: 12px; min-width: 0; }
.qp-page .qp-brand img { width: 58px; height: 52px; flex: 0 0 58px; object-fit: contain; object-position: left top; }
.qp-page .qp-company { font-size: 11.5px; line-height: 1.5; color: var(--q-mute); min-width: 0; }
.qp-page .qp-company b { display: block; font-size: 12.5px; color: var(--q-ink); margin-bottom: 2px; }
.qp-page .qp-doc { text-align: right; flex: 0 0 auto; }
.qp-page .qp-title { font-size: 26px; font-weight: 800; letter-spacing: 3px; color: var(--q-red); line-height: 1.1; }
.qp-page .qp-meta { margin-top: 8px; font-size: 12px; }
.qp-page .qp-meta div { display: flex; justify-content: flex-end; gap: 8px; }
.qp-page .qp-meta span { color: var(--q-mute); }

/* Khách hàng */
.qp-page .qp-to { padding: 16px 26px 6px; }
.qp-page .qp-customer { font-size: 18px; font-weight: 700; margin-top: 2px; }
.qp-page .qp-to p { margin: 8px 0 0; color: var(--q-mute); font-size: 13px; }

/* Bảng sản phẩm */
.qp-page .qp-table { width: calc(100% - 52px); margin: 10px 26px 0; border-collapse: collapse; }
.qp-page .qp-table th {
  padding: 8px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  text-align: left;
  color: #fff;
  background: var(--q-red);
}
.qp-page .qp-table td { padding: 12px 6px; vertical-align: top; border-bottom: 1px solid var(--q-line); }
.qp-page .qp-c-no { width: 18px; text-align: center !important; color: var(--q-mute); }
.qp-page .qp-c-price { width: 92px; text-align: right !important; white-space: nowrap; }
.qp-page .qp-c-qty { width: 26px; text-align: center !important; }
.qp-page .qp-c-sum { width: 100px; text-align: right !important; white-space: nowrap; font-weight: 700; }
.qp-page td.qp-c-price, .qp-page td.qp-c-qty, .qp-page td.qp-c-sum { font-size: 13px; }
.qp-page .qp-old { font-size: 11.5px; color: #9b8f88; text-decoration: line-through; }
.qp-page .qp-prod { display: flex; gap: 10px; }
.qp-page .qp-prod img { width: 58px; height: 58px; flex: 0 0 58px; object-fit: contain; border: 1px solid var(--q-line); border-radius: 6px; background: #fff; }
.qp-page .qp-name { font-weight: 700; font-size: 13.5px; line-height: 1.35; }
.qp-page .qp-detail { font-size: 11.5px; color: var(--q-mute); }
.qp-page .qp-stock { display: inline-block; margin-top: 4px; font-size: 11px; font-weight: 700; }
.qp-page .qp-stock.ok { color: #2a7a3b; }
.qp-page .qp-stock.wait { color: #a06a00; }
.qp-page .qp-empty { padding: 26px 0 !important; text-align: center; color: #9a8f8b; }

/* Tổng tiền */
.qp-page .qp-total { margin: 14px 26px 0 auto; width: 300px; margin-right: 26px; }
.qp-page .qp-total div { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 13px; }
.qp-page .qp-total div span { color: var(--q-mute); }
.qp-page .qp-total .qp-grand { margin-top: 6px; padding: 10px 12px; background: var(--q-red); color: #fff; border-radius: 6px; }
.qp-page .qp-total .qp-grand span { color: #fff; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; font-size: 12px; align-self: center; }
.qp-page .qp-total .qp-grand b { font-size: 18px; }
.qp-page .qp-total .qp-words { display: block; padding: 6px 0 0; font-size: 11.5px; font-style: italic; color: var(--q-mute); text-align: right; }

/* Điều khoản */
.qp-page .qp-terms { margin: 20px 26px 0; padding-top: 14px; border-top: 1px solid var(--q-line); }
.qp-page .qp-terms[hidden] { display: none; }
.qp-page .qp-terms ol { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; }
.qp-page .qp-terms li { margin-bottom: 3px; padding-left: 2px; }

/* QR chuyển khoản của chi nhánh (ảnh QR gốc BIDV, đã có địa chỉ + số tài khoản) */
.qp-page .qp-pay { display: flex; align-items: center; gap: 18px; margin: 20px 26px 0; padding-top: 14px; border-top: 1px solid var(--q-line); }
.qp-page .qp-pay[hidden] { display: none; }
.qp-page .qp-pay img { width: 170px; flex: 0 0 170px; border-radius: 8px; }
.qp-page .qp-acct { margin-top: 6px; font-size: 12.5px; line-height: 1.6; color: #4a403c; }
.qp-page .qp-acct b { color: var(--q-ink); }
.qp-page .qp-acct .qp-acct-no { font-size: 17px; letter-spacing: 0.5px; color: var(--q-red); }
.qp-page .qp-pay p { margin: 8px 0 0; font-size: 12.5px; color: #4a403c; }

/* Chân trang: người báo giá + ký */
.qp-page .qp-foot { display: flex; justify-content: space-between; gap: 16px; margin: 20px 26px 0; padding: 14px 0 22px; border-top: 1px solid var(--q-line); font-size: 12.5px; }
.qp-page .qp-staff-name { font-size: 15px; font-weight: 700; margin: 2px 0 2px; }
.qp-page .qp-staff div:not(.qp-label):not(.qp-staff-name) { color: #4a403c; }
.qp-page .qp-sign { text-align: right; }
.qp-page .qp-sign #qpPlaceDate { font-style: italic; color: var(--q-mute); }
.qp-page .qp-sign-co { font-weight: 700; margin-top: 4px; }
.qp-page .qp-thanks { margin-top: 10px; color: var(--q-red); font-weight: 600; }
.qp-page .qp-band { background: var(--q-red); color: #f6e7d6; text-align: center; font-size: 11.5px; letter-spacing: 0.4px; padding: 8px; }

/* Các trang dựng ra khi xuất (nằm ngoài màn hình, không bóng đổ) */
.qp-stage { position: fixed; left: -10000px; top: 0; }
.qp-page.qp-clone { box-shadow: none; margin: 0; }
.qp-page .qp-cont { display: flex; align-items: baseline; gap: 12px; padding: 16px 26px 6px; }
.qp-page .qp-cont b { font-size: 16px; letter-spacing: 2px; color: var(--q-red); }
.qp-page .qp-cont span { font-size: 13px; color: var(--q-mute); }
.qp-page .qp-pageno { padding: 8px 26px 10px; text-align: right; font-size: 11.5px; color: var(--q-mute); }

/* ---------- Khổ NGANG: đúng khổ A4 ngang (1123 x 794 px) để PDF in vừa trang ----------
   Phần cuối xếp 2 cột cho đỡ tốn chiều cao: điều khoản | tổng tiền, QR | người báo giá.
   Bản xem trước thu nhỏ cho vừa màn hình (#qpFit), file xuất vẫn dựng ở kích thước thật. */
#qpFit.land { position: relative; margin-bottom: 60px; }
#qpFit.land > #quotePaper { position: absolute; top: 0; left: 0; margin: 0; transform-origin: 0 0; }
.qp-page.qp-land { width: 1123px; display: grid; grid-template-columns: 1fr 380px; grid-auto-flow: row dense; align-items: start; }
.qp-land > * { grid-column: 1 / -1; }
.qp-land > .qp-terms, .qp-land > .qp-pay { grid-column: 1; }
.qp-land > .qp-total, .qp-land > .qp-foot { grid-column: 2; }
.qp-land > .qp-pay[hidden] + .qp-foot { grid-column: 1 / -1; }
.qp-land .qp-top { padding: 20px 32px 14px; }
.qp-land .qp-to { padding: 12px 32px 4px; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.qp-land .qp-to p { margin: 0; flex-basis: 100%; }
.qp-land .qp-customer { margin-top: 0; }
.qp-land .qp-table { width: calc(100% - 64px); margin: 10px 32px 0; }
.qp-land .qp-table td { padding: 9px 6px; }
.qp-land .qp-c-orig { width: 96px; }
.qp-land .qp-c-war { width: 86px; }
.qp-land .qp-c-st { width: 104px; }
.qp-land .qp-c-price { width: 118px; }
.qp-land .qp-c-qty { width: 34px; }
.qp-land .qp-c-sum { width: 128px; }
.qp-land td.qp-c-orig, .qp-land td.qp-c-war, .qp-land td.qp-c-st { font-size: 12.5px; }
.qp-land td.qp-c-st .qp-stock { margin-top: 0; font-size: 12px; }
.qp-land .qp-prod img { width: 48px; height: 48px; flex-basis: 48px; }
.qp-land .qp-total { width: auto; margin: 16px 32px 0 0; }
.qp-land .qp-terms { margin: 16px 28px 0 32px; padding-top: 10px; }
.qp-land .qp-terms ol { font-size: 12px; }
.qp-land .qp-terms li { margin-bottom: 2px; }
.qp-land .qp-pay { margin: 14px 28px 0 32px; padding-top: 10px; gap: 14px; }
.qp-land .qp-pay img { width: 112px; flex-basis: 112px; }
.qp-land .qp-pay p { font-size: 12px; }
.qp-land .qp-acct { font-size: 12px; line-height: 1.5; }
.qp-land .qp-acct .qp-acct-no { font-size: 15px; }
.qp-land .qp-foot { margin: 14px 32px 0 0; padding: 10px 0 16px; flex-direction: column; gap: 10px; }
.qp-land > .qp-pay[hidden] + .qp-foot { margin-left: 32px; flex-direction: row; }
.qp-land .qp-sign { text-align: left; }
.qp-land > .qp-pay[hidden] + .qp-foot .qp-sign { text-align: right; }
.qp-land .qp-thanks { margin-top: 6px; }
.qp-land .qp-cont, .qp-land .qp-pageno { padding-left: 32px; padding-right: 32px; }
#qPreview.land .qv-panel { width: 1180px; }
