/* SHINHA Receipt Tool — scoped styles (does not touch recruitment tool CSS) */
:root {
  --rt-blue: #0B4DBA;
  --rt-ink: #061A40;
  --rt-muted: #5D6B82;
  --rt-line: #D6DEE8;
  --rt-bg: #F3F6FA;
  --rt-panel: #ffffff;
  --rt-radius: 10px;
  --rt-font: "Inter", system-ui, sans-serif;
  --rt-display: "Be Vietnam Pro", "Inter", system-ui, sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

/* Desktop shell: lock page height so form scrolls independently (scoped; not page-tool) */
body.page-receipt-tool {
  font-family: var(--rt-font);
  color: var(--rt-ink);
  background: var(--rt-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  min-height: 0;
}

.rt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: #fff;
  border-bottom: 1px solid var(--rt-line);
  flex: 0 0 auto;
  position: relative;
}

.rt-header__brand {
  font-family: var(--rt-display);
  font-weight: 800;
  color: var(--rt-blue);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.rt-header__subtitle {
  font-size: 12px;
  font-weight: 600;
  color: var(--rt-muted);
}

.rt-header__menu-btn {
  display: none;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid var(--rt-line);
  border-radius: 8px;
  background: #fff;
  color: var(--rt-ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.rt-header__nav {
  display: flex;
  gap: 14px;
}

.rt-header__nav a {
  color: var(--rt-ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.rt-header__nav a:hover { color: var(--rt-blue); }

.rt-notice {
  margin: 0;
  padding: 8px 18px;
  background: #FFF8E8;
  border-bottom: 1px solid #F0E0B8;
  font-size: 12px;
  color: #6B5A2A;
  line-height: 1.45;
  flex: 0 0 auto;
}

.rt-notice p { margin: 0 0 4px; }
.rt-notice p:last-child { margin-bottom: 0; }

.rt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 8px 18px;
  background: #fff;
  border-bottom: 1px solid var(--rt-line);
  flex: 0 0 auto;
  min-width: 0;
}

.rt-toolbar__group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.rt-toolbar__palette {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
}

.rt-toolbar__palette-label {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--rt-muted);
}

.rt-toolbar label {
  font-size: 13px;
  font-weight: 600;
  color: var(--rt-muted);
}

.rt-select {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--rt-line);
  border-radius: 8px;
  background: #fff;
  min-width: 160px;
}

.rt-btn {
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 12px;
  cursor: pointer;
  background: #fff;
  color: var(--rt-ink);
}

.rt-btn:hover { filter: brightness(0.98); }
.rt-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.rt-btn--primary {
  background: var(--rt-blue);
  color: #fff;
}

.rt-btn--secondary {
  border-color: var(--rt-line);
  background: #fff;
}

.rt-btn--ghost {
  border-color: var(--rt-line);
  background: #F8FAFC;
}

.rt-mobile-actions {
  display: none;
  flex-direction: column;
  background: #fff;
  border-bottom: 1px solid var(--rt-line);
  flex: 0 0 auto;
}

.rt-mobile-actions__row {
  display: flex;
  width: 100%;
}

.rt-mobile-actions__row--export {
  border-top: 1px solid #eef0f4;
}

.rt-mobile-actions__btn {
  flex: 1 1 0;
  min-height: 44px;
  padding: 10px 12px;
  border: none;
  border-right: 1px solid #eef0f4;
  background: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--rt-blue);
  cursor: pointer;
}

.rt-mobile-actions__btn:last-child {
  border-right: none;
}

.rt-mobile-actions__btn:active {
  background: #f0f6ff;
}

.rt-mobile-actions__btn--accent {
  background: #f0f6ff;
  color: var(--rt-blue);
}

.rt-mobile-actions__btn--export {
  font-size: 13px;
  background: #f8f9fb;
}

.rt-mobile-actions__btn--export:first-child {
  color: #fff;
  background: var(--rt-blue);
}

/* Receipt data sheet — scoped; not #data-sheet */
.rt-tool-sheet {
  position: fixed;
  inset: 0;
  z-index: 10060;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.rt-tool-sheet[hidden] {
  display: none !important;
}

.rt-tool-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 26, 64, 0.5);
  cursor: pointer;
}

.rt-tool-sheet__panel {
  position: relative;
  width: 100%;
  max-height: 92vh;
  max-height: 92dvh;
  background: #fff;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.rt-tool-sheet__header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid #eef0f4;
  flex: 0 0 auto;
  background: #fff;
}

.rt-tool-sheet__heading {
  flex: 1;
  min-width: 0;
}

.rt-tool-sheet__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--rt-blue);
  font-family: var(--rt-display);
}

.rt-tool-sheet__template {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--rt-muted);
}

.rt-tool-sheet__close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #f0f2f5;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #333;
  flex-shrink: 0;
}

.rt-tool-sheet__quick {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid #eef0f4;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.rt-tool-sheet__quick .rt-btn {
  flex: 1 1 calc(50% - 4px);
  min-height: 44px;
}

.rt-tool-sheet__section-label {
  padding: 10px 16px 4px;
  font-size: 12px;
  font-weight: 700;
  color: #5a6270;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex: 0 0 auto;
}

.rt-tool-sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 8px 16px 16px;
  -webkit-overflow-scrolling: touch;
}

.rt-tool-sheet__footer {
  display: flex;
  gap: 10px;
  align-items: stretch;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #eef0f4;
  background: #fff;
  flex: 0 0 auto;
}

.rt-sheet-save-slot {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
}

.rt-sheet-save-slot:empty {
  display: none;
}

.rt-sheet-save-slot .rt-btn {
  flex: 1 1 auto;
  min-height: 44px;
  width: 100%;
}

.rt-tool-sheet__footer > .rt-btn {
  flex: 1 1 auto;
  min-height: 44px;
}

body.page-receipt-tool.is-rt-sheet-open {
  overflow: hidden !important;
}

.rt-layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  min-height: 0;
  overflow: hidden;
}

.rt-form-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--rt-panel);
  border-right: 1px solid var(--rt-line);
}

.rt-form-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px 16px 18px;
  -webkit-overflow-scrolling: touch;
}

.rt-form-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--rt-line);
  background: #fff;
}

.rt-form-actions .rt-btn { flex: 1 1 auto; }

.rt-form-actions #rt-btn-save {
  flex: 1 1 100%;
}

.rt-form-actions .rt-btn[hidden] {
  display: none !important;
}

.rt-section {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rt-line);
}

.rt-section:last-child { border-bottom: 0; }

.rt-section__title {
  margin: 0 0 10px;
  font-family: var(--rt-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--rt-blue);
}

.rt-field {
  margin-bottom: 10px;
}

.rt-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--rt-ink);
}

.rt-field input[type="text"],
.rt-field input[type="number"],
.rt-field input[type="date"],
.rt-field input[type="email"],
.rt-field input[type="url"],
.rt-field input[type="file"],
.rt-field select,
.rt-field textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1px solid var(--rt-line);
  border-radius: 8px;
  background: #fff;
}

.rt-field textarea { min-height: 72px; resize: vertical; }

/* A5: action "Tạo ngày hôm nay" — nút thật (không chip/quickTag) */
.rt-date-today-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  max-width: 100%;
  min-height: 40px;
  box-sizing: border-box;
}

.rt-date-today-btn:hover,
.rt-date-today-btn:focus {
  border-color: var(--rt-blue);
  background: #eaf2ff;
  color: var(--rt-blue);
  outline: none;
}

.rt-date-today-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(11, 77, 186, 0.22);
}

/* A5: chuyển số tiền thành chữ — dưới Loại tiền */
.rt-field--action {
  margin-bottom: 10px;
}

.rt-convert-words-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  min-height: 40px;
  box-sizing: border-box;
}

.rt-convert-words-btn:hover,
.rt-convert-words-btn:focus {
  border-color: var(--rt-blue);
  background: #eaf2ff;
  color: var(--rt-blue);
  outline: none;
}

.rt-convert-words-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(11, 77, 186, 0.22);
}

.rt-helper {
  margin: 4px 0 0;
  font-size: 12px;
  color: #667085;
  line-height: 1.4;
}

.rt-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
}

.rt-check input { margin-top: 3px; }

/* Compact color pills — toolbar-mounted (scoped; not recruitment selectors) */
.rt-toolbar__palette .rt-palette {
  margin: 0;
  min-width: 0;
  max-width: 100%;
  flex: 1 1 auto;
}

.rt-palette {
  margin: 0;
  min-width: 0;
  max-width: 100%;
}

.rt-palette__scroller {
  position: relative;
  min-width: 0;
  max-width: 100%;
}

.rt-palette__list {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  scrollbar-width: thin;
}

.rt-palette__opt {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 100%;
  padding: 5px 10px 5px 8px;
  border: 1.5px solid var(--rt-line);
  border-radius: 999px;
  background: #fff;
  color: var(--rt-ink);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.rt-palette__opt:hover {
  border-color: #94A3B8;
  background: #F8FAFC;
}

.rt-palette__opt:focus-visible {
  outline: 2px solid var(--rt-blue);
  outline-offset: 2px;
}

.rt-palette__opt.is-active {
  border-color: var(--rt-blue);
  box-shadow: 0 0 0 1px var(--rt-blue);
  background: #F0F6FF;
}

.rt-palette__swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(6, 26, 64, 0.18);
  flex: 0 0 auto;
}

.rt-palette__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 11em;
}

.rt-palette__check {
  display: none;
  margin-left: 2px;
  font-size: 11px;
  color: var(--rt-blue);
  font-weight: 700;
}

.rt-palette__opt.is-active .rt-palette__check {
  display: inline;
}

.rt-palette__fade,
.rt-palette__hint {
  display: none;
  pointer-events: none;
}

/* Desktop toolbar: compact color dots (names via title attribute) */
@media (min-width: 901px) {
  .rt-toolbar__palette .rt-palette__opt {
    padding: 4px;
    border-radius: 50%;
    gap: 0;
  }

  .rt-toolbar__palette .rt-palette__name,
  .rt-toolbar__palette .rt-palette__check {
    display: none;
  }

  .rt-toolbar__palette .rt-palette__swatch {
    width: 18px;
    height: 18px;
  }

  .rt-toolbar__palette .rt-palette__opt.is-active {
    background: #fff;
  }

  .rt-toolbar__group--desktop {
    flex: 0 0 auto;
  }
}

.rt-preview-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: #E8EEF5;
  padding: 16px;
}

.rt-zoom-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px;
  min-width: 0;
}

.rt-zoom-bar__btn {
  padding: 6px 10px;
  min-height: 36px;
}

.rt-zoom-bar__label {
  min-width: 52px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--rt-ink);
}

.rt-preview-stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
}

.rt-preview-scale {
  transform-origin: 0 0;
  flex: 0 0 auto;
}

.rt-preview-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.rt-preview-root .receipt-page {
  box-shadow: 0 8px 28px rgba(6, 26, 64, 0.12);
  background: #fff;
}

/* A5 × 2 liên: một tờ A4 portrait (210×297) — 2 A5 landscape xếp trên/dưới, không scale */
.rt-preview-root .receipt-a4-sheet--two-a5 {
  box-sizing: border-box;
  width: 210mm;
  height: 297mm;
  min-width: 210mm;
  min-height: 297mm;
  max-width: 210mm;
  max-height: 297mm;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  row-gap: 0;
  background: #fff;
  box-shadow: 0 8px 28px rgba(6, 26, 64, 0.12);
  overflow: hidden;
}

.rt-preview-root .receipt-a4-sheet--two-a5 .receipt-a5-copy {
  box-sizing: border-box;
  width: 210mm;
  height: 148mm;
  min-height: 148mm;
  max-height: 148mm;
  flex: 0 0 148mm;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.rt-preview-root .receipt-a4-sheet--two-a5 .receipt-a5-copy .receipt-page {
  box-shadow: none;
  margin: 0;
}

/*
 * Đường cắt không chiếm flow / không cần position:relative trên sheet
 * (relative trên sheet từng làm regression co kích thước khi in).
 * Dùng border-bottom dashed của Liên 1 (nằm trong box-sizing của page).
 * Ẩn spacer DOM cũ.
 */
.rt-preview-root .receipt-a4-sheet--two-a5 .receipt-a5-cut-line {
  display: none !important;
}

.rt-preview-root .receipt-a4-sheet--two-a5 .receipt-a5-copy--1 .receipt-page--a5 {
  border-bottom: 1px dashed #666;
}

.rt-preview-root .receipt-a4-sheet--two-a5 .receipt-a5-copy--2 .receipt-page--a5 {
  border-top-color: transparent;
}

.rt-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--rt-ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 10070;
  max-width: min(90vw, 420px);
  text-align: center;
}

@media (max-width: 900px) {
  /* Mobile: preview-first + form in sheet — desktop dual-pane unchanged above */
  body.page-receipt-tool {
    height: auto;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100dvh;
  }

  body.page-receipt-tool.is-rt-sheet-open {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden !important;
  }

  .rt-header {
    padding: 8px 12px;
    gap: 8px;
  }

  .rt-header__menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
  }

  .rt-header__nav {
    display: none;
    position: absolute;
    top: 100%;
    right: 12px;
    left: auto;
    flex-direction: column;
    gap: 0;
    min-width: 180px;
    padding: 6px 0;
    background: #fff;
    border: 1px solid var(--rt-line);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(6, 26, 64, 0.14);
    z-index: 80;
  }

  .rt-header.is-nav-open .rt-header__nav {
    display: flex;
  }

  .rt-header__nav a {
    display: block;
    padding: 12px 14px;
    font-size: 14px;
    white-space: nowrap;
  }

  .rt-notice {
    padding: 6px 12px;
    font-size: 11px;
  }

  .rt-toolbar__group--desktop { display: none; }
  .rt-mobile-actions { display: flex; }

  /* Toolbar: template row, then full-width color scroller (no collide) */
  .rt-toolbar {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    overflow-x: hidden;
    gap: 8px;
    padding: 8px 12px;
  }

  .rt-toolbar > .rt-toolbar__group:first-child {
    flex: 0 0 auto;
    width: 100%;
  }

  .rt-toolbar .rt-select {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
  }

  .rt-toolbar__palette {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .rt-toolbar__palette-label {
    display: inline;
    flex: 0 0 auto;
  }

  .rt-palette {
    flex: 1 1 auto;
    min-width: 0;
  }

  .rt-palette__scroller {
    overflow: hidden;
  }

  .rt-palette__list {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
    padding: 2px 4px 6px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .rt-palette__list::-webkit-scrollbar {
    display: none;
  }

  .rt-palette__opt {
    flex: 0 0 auto;
    scroll-snap-align: start;
    min-height: 36px;
    padding: 7px 12px 7px 10px;
  }

  .rt-palette__fade {
    display: block;
    position: absolute;
    top: 0;
    bottom: 6px;
    width: 28px;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 1;
  }

  .rt-palette__fade--left {
    left: 0;
    background: linear-gradient(90deg, #fff 20%, rgba(255, 255, 255, 0));
  }

  .rt-palette__fade--right {
    right: 0;
    background: linear-gradient(270deg, #fff 20%, rgba(255, 255, 255, 0));
  }

  .rt-palette__hint {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 50%;
    transform: translateY(-60%);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(11, 77, 186, 0.12);
    color: var(--rt-blue);
    font-size: 14px;
    font-weight: 700;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 2;
  }

  .rt-palette__hint--left { left: 2px; }
  .rt-palette__hint--right { right: 2px; }

  .rt-palette__scroller.is-overflow-left .rt-palette__fade--left,
  .rt-palette__scroller.is-overflow-left .rt-palette__hint--left,
  .rt-palette__scroller.is-overflow-right .rt-palette__fade--right,
  .rt-palette__scroller.is-overflow-right .rt-palette__hint--right {
    opacity: 1;
  }

  .rt-mobile-actions {
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }

  .rt-layout {
    display: block;
    flex: 0 0 auto;
    overflow: visible;
    min-height: 0;
    width: 100%;
    max-width: 100%;
  }

  /* Form lives in sheet on mobile — hide desktop side panel */
  .rt-form-panel {
    display: none !important;
  }

  .rt-form-scroll {
    max-height: none;
    overflow: visible;
    height: auto;
    min-height: 0;
    min-width: 0;
    max-width: 100%;
    padding: 0 0 12px;
  }

  .rt-form {
    min-width: 0;
    max-width: 100%;
  }

  /* In sheet: sample/clear/save live in sheet chrome */
  #rt-data-sheet .rt-form-actions #rt-btn-sample,
  #rt-data-sheet .rt-form-actions #rt-btn-clear,
  #rt-data-sheet .rt-form-actions #rt-btn-save {
    display: none !important;
  }

  #rt-data-sheet .rt-form-actions {
    border-top: 0;
    padding: 0 0 8px;
    background: transparent;
  }

  #rt-data-sheet .rt-form-actions[hidden] {
    display: none !important;
  }

  .rt-preview-panel {
    padding: 10px 8px 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
  }

  .rt-zoom-bar {
    margin-bottom: 8px;
  }

  .rt-zoom-bar__btn {
    font-size: 12px;
    padding: 6px 8px;
  }

  .rt-preview-stage {
    overflow: auto;
    width: 100%;
    min-height: 0;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  /* Sheet: sole scroll in body; footer flush to panel bottom (svh) */
  #rt-data-sheet.rt-tool-sheet {
    height: 100vh;
    max-height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    height: 100svh;
    max-height: 100svh;
  }

  #rt-data-sheet .rt-tool-sheet__panel {
    height: 92%;
    max-height: 92%;
    overflow: hidden;
  }

  #rt-data-sheet .rt-tool-sheet__header,
  #rt-data-sheet .rt-tool-sheet__quick,
  #rt-data-sheet .rt-tool-sheet__section-label {
    flex: 0 0 auto;
  }

  #rt-data-sheet .rt-tool-sheet__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;
  }

  #rt-data-sheet .rt-tool-sheet__body > .rt-form-scroll,
  #rt-data-sheet .rt-tool-sheet__body > .rt-form-actions {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
  }

  #rt-data-sheet .rt-tool-sheet__footer {
    flex: 0 0 auto;
    margin-top: auto;
    background: #fff;
    border-top: 1px solid #eef0f4;
    padding-top: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 3;
  }
}

/* Print: only receipt pages */
@media print {
  @page {
    margin: 0;
  }

  @page receipt-a5-sheet {
    size: A5 landscape;
    margin: 0;
  }

  @page receipt-a4-sheet {
    size: A4 portrait;
    margin: 0;
  }

  body.page-receipt-tool * {
    visibility: hidden !important;
  }

  body.page-receipt-tool .rt-preview-root,
  body.page-receipt-tool .rt-preview-root * {
    visibility: visible !important;
  }

  body.page-receipt-tool .rt-header,
  body.page-receipt-tool .rt-notice,
  body.page-receipt-tool .rt-toolbar,
  body.page-receipt-tool .rt-mobile-actions,
  body.page-receipt-tool .rt-form-panel,
  body.page-receipt-tool #rt-data-sheet,
  body.page-receipt-tool .rt-zoom-bar,
  body.page-receipt-tool .rt-toast {
    display: none !important;
  }

  body.page-receipt-tool .rt-layout,
  body.page-receipt-tool .rt-preview-panel,
  body.page-receipt-tool .rt-preview-stage,
  body.page-receipt-tool .rt-preview-scale {
    all: unset;
    display: block;
  }

  /* Neutralize screen-only preview scale/margins (inline) for all print modes */
  body.page-receipt-tool .rt-preview-scale {
    transform: none !important;
    margin: 0 !important;
    width: auto !important;
    height: auto !important;
  }

  body.page-receipt-tool .rt-preview-root {
    display: block;
    gap: 0;
  }

  body.page-receipt-tool .receipt-page {
    box-shadow: none !important;
    page-break-after: always;
    break-after: page;
    margin: 0 auto;
  }

  body.page-receipt-tool .receipt-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  body.page-receipt-tool.rt-print-a5 .receipt-page--a5 {
    page: receipt-a5-sheet;
    width: 210mm;
    height: 148mm;
    max-width: 210mm;
    max-height: 148mm;
    min-width: 210mm;
    min-height: 148mm;
  }

  /*
   * A5 2 liên → 1 tờ A4 (LOCKED print size):
   * Preview scale sống trên #rt-preview-scale (inline transform).
   * all:unset không thắng inline → phải transform:none !important.
   * Không gắn position:relative lên sheet (gây regression co trang).
   */
  body.page-receipt-tool.rt-print-a5-two .rt-layout,
  body.page-receipt-tool.rt-print-a5-two .rt-preview-panel,
  body.page-receipt-tool.rt-print-a5-two .rt-preview-stage {
    display: block !important;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    transform: none !important;
    zoom: 1 !important;
  }

  body.page-receipt-tool.rt-print-a5-two .rt-preview-scale {
    display: block !important;
    position: static !important;
    transform: none !important;
    transform-origin: top left !important;
    width: 210mm !important;
    height: 297mm !important;
    min-width: 210mm !important;
    min-height: 297mm !important;
    max-width: 210mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    zoom: 1 !important;
  }

  body.page-receipt-tool.rt-print-a5-two .rt-preview-root {
    display: block !important;
    position: static !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  body.page-receipt-tool.rt-print-a5-two .receipt-a4-sheet--two-a5 {
    page: receipt-a4-sheet;
    box-sizing: border-box !important;
    position: static !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0 !important;
    row-gap: 0 !important;
    width: 210mm !important;
    height: 297mm !important;
    min-width: 210mm !important;
    min-height: 297mm !important;
    max-width: 210mm !important;
    max-height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
    page-break-after: auto;
    break-after: auto;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body.page-receipt-tool.rt-print-a5-two .receipt-a4-sheet--two-a5 .receipt-a5-copy {
    box-sizing: border-box !important;
    position: static !important;
    width: 210mm !important;
    height: 148mm !important;
    min-height: 148mm !important;
    max-height: 148mm !important;
    flex: 0 0 148mm !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.page-receipt-tool.rt-print-a5-two .receipt-a4-sheet--two-a5 .receipt-page {
    page-break-after: auto !important;
    break-after: auto !important;
    page: auto;
    box-shadow: none !important;
    margin: 0 !important;
  }

  body.page-receipt-tool.rt-print-a5-two .receipt-a4-sheet--two-a5 .receipt-page--a5 {
    width: 210mm !important;
    height: 148mm !important;
    max-width: 210mm !important;
    max-height: 148mm !important;
    min-width: 210mm !important;
    min-height: 148mm !important;
  }

  body.page-receipt-tool.rt-print-a5-two .receipt-a4-sheet--two-a5 .receipt-a5-cut-line {
    display: none !important;
  }

  body.page-receipt-tool.rt-print-a5-two .receipt-a4-sheet--two-a5 .receipt-a5-copy--1 .receipt-page--a5 {
    border-bottom: 1px dashed #666 !important;
  }

  body.page-receipt-tool.rt-print-a5-two .receipt-a4-sheet--two-a5 .receipt-a5-copy--2 .receipt-page--a5 {
    border-top-color: transparent !important;
  }

  /*
   * Gạch chéo = background-image trên .receipt-lock.
   * Mặc định trình duyệt in với print-color-adjust:economy → mất hatch.
   * Scope: preview root phiếu thu only (A4 / A5×1 / A5×2).
   */
  body.page-receipt-tool .rt-preview-root .receipt-lock {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.page-receipt-tool .rt-preview-root .receipt-page[data-strike="off"] .receipt-lock {
    background-image: none !important;
  }

  /*
   * A5×2 print hatch: do NOT force CSS rgba() gradient (mobile WebKit prints
   * translucent black as solid black). JS bakes SVG hatch (#000 + stroke-opacity)
   * onto locks before window.print(); keep color-adjust only.
   */
  body.page-receipt-tool.rt-print-a5-two .receipt-page--a5 .receipt-lock {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body.page-receipt-tool.rt-print-a5-two .receipt-page--a5[data-strike="off"] .receipt-lock {
    background-image: none !important;
  }

  body.page-receipt-tool.rt-print-a4 .receipt-page--a4 {
    page: receipt-a4-sheet;
    width: 210mm;
    height: 297mm;
  }
}
