/* ===== A4 PAPER ===== */
#a4-paper {
  /* NOTE: we don't define explicit width and height, so the paper will scale automatically to SVG element */
  flex: 0.95;
  background: #fff;
  border-radius: 3mm;
  box-shadow: 0 0.3mm 0.5mm 0 rgba(60, 64, 67, .3), 0 0.3mm 0.8mm 0.3mm rgba(60, 64, 67, .15);
  display: flex;
  flex-direction: column;
  transform-origin: top center;
  position: relative;
  overflow: hidden;
  aspect-ratio: 210 / 280;
}

/* ===== VOUCHER SVG ===== */
#svg-voucher {
  width: 100%;
  height: auto;
  flex-shrink: 0;
}

/* ===== A4 IMAGE GALLERY (bottom of page) ===== */
#a4-images {
  flex: 1;
  min-height: 0;
  padding: 3mm;
  display: flex;
  flex-direction: column;
}

.a4-images-label {
  display: none; /* shown by JS when images are present */
  font-size: 5mm;
  font-weight: bold;
  text-align: center;
  margin-bottom: 1.6mm;
  flex-shrink: 0;
}

#a4ImageGallery {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  gap: 1.6mm;
  align-content: center;
  overflow: hidden;
}

.a4-thumb {
  flex: 1 1 calc(50% - 0.8mm);
  width: calc((100% - 3.2mm) / 3);
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.a4-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transform-origin: center center;
}

/* ===== VOUCHER CARD ===== */

#voucher {
  margin: 2mm 2mm;
  border: 1px solid #333;
  border-radius: 1mm;
  padding: 2mm 3mm;
  overflow: hidden;
  direction: rtl;
}

/* ===== HEADER ===== */
.header-row {
  display: flex;
  align-items: flex-start;
  gap: 2.1mm;
  padding-bottom: 2.6mm;
}

.title-block {
  flex: 1;
  text-align: center;
  position: relative;
}
.title-block h1 {
  font-size: clamp(4.2mm, 5.6mm, 5.8mm);
  font-weight: bold;
  letter-spacing: 0.3mm;
  margin: 0.5mm 0;
}
.subtitle {
  font-size: 2.9mm;
  text-decoration: underline;
  margin-bottom: 0.5mm;
}
.copy-note {
  font-size: 2.6mm;
  color: #333;
  position: absolute;
  bottom: 0;
  right: 0;
}

.box-small {
  border: 0.3mm solid #333;
  padding: 1.1mm 2.1mm;
  min-width: 24mm;
  text-align: center;
}

/* ===== FROM / TO ===== */
.from-to-row {
  display: flex;
  gap: 2.1mm;
  flex-wrap: wrap;
  margin-bottom: 2.6mm;
  align-items: flex-end;
}

.from-to-row .field-group {
  border: 1px solid #000;
}

.from-to-row .field-label {
  padding-right: 2mm;
}

.field-group {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 32mm;
}

.from-to-row .field-group input,
.header-row input {
  border: none;
}

.field-group.narrow { max-width: 42mm; }

.field-label {
  font-size: 2.9mm;
  font-weight: bold;
  color: #333;
  margin-bottom: 0.5mm;
  white-space: nowrap;
}

.field-input {
  border: none;
  border-bottom: 0.3mm solid #555;
  padding: 0.8mm 1.1mm;
  font-size: 3.4mm;
  direction: rtl;
  width: 100%;
  background: transparent;
  outline: none;
  text-align: center;
}
.field-input:focus { border-bottom-color: #1565C0; }
.field-input.wide { min-width: 37mm; }

/* ===== TABLE ===== */
.table-wrapper {
  overflow-x: auto;
  margin-bottom: 2.6mm;
}

#itemsTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 3mm;
}

#itemsTable th,
#itemsTable td {
  border: 0.3mm solid #333;
  padding: 1.1mm 1.6mm;
  text-align: center;
  vertical-align: middle;
}

#itemsTable th {
  background: #f0f0f0;
  font-size: 2.9mm;
  white-space: nowrap;
}

.col-cat  { width: 36.5mm; }
.col-name { width: 64.8mm; }
.col-unit { width: 28.4mm; }
.col-qty  { width: 24.3mm; }
.col-notes{ width: 48.6mm; }

#itemsTable td[contenteditable] {
  outline: none;
  min-height: 4mm;
}
#itemsTable td[contenteditable]:focus {
  background: #fffde7;
}

/* ===== BOTTOM SECTION ===== */
.bottom-section {
  display: flex;
  gap: 2.1mm;
  align-items: baseline;
}

.bottom-block {
  flex: 1;
  min-width: 48mm;
  border: 0.3mm solid #333;
  padding: 1.6mm;
}

.middle-block {
  max-width: 48mm;
  display: flex;
  flex-direction: column;
  gap: 2.1mm;
}

.bottom-label {
  font-weight: bold;
  font-size: 3.2mm;
  text-align: center;
  border-bottom: 1px solid #000;
  padding-bottom: 1mm;
  margin-bottom: 1.5mm;
}

.sig-row {
  display: flex;
  gap: 1.6mm;
  margin-bottom: 1.6mm;
}

.sig-row .field-group {
  flex-direction: row;
  align-items: center;
}

.sig-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.phone-row .field-label {
  text-align: center;
}

#voucher .sig-field {
  flex-direction: row;
  justify-content: space-evenly;
  align-items: stretch;
}

.sig-area {
  aspect-ratio: 2 / 1;
  border: 0.2mm dashed var(--theme);
  border-radius: 2mm;
  position: relative;
  cursor: pointer;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.sig-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}

.sig-placeholder {
  font-size: 2rem;
  color: #aaa;
  z-index: 1;
  pointer-events: none;
  text-align: center;
}

#voucher .sig-placeholder {
  font-size: 3mm;
}

.sig-area.has-sig .sig-placeholder,
.stamp-box.has-sig .sig-placeholder { 
  display: none;
}

.date-personal-row {
  display: flex;
  gap: 1mm;
  flex-wrap: wrap;
  text-align: center;
}
.date-personal-row .field-group {
  min-width: 16mm;
}

.phone-row {
  margin-top: 1mm;
}

.phone-row .field-group {
  width: 100%;
}

.reg-field .field-label {
  font-size: 2.6mm;
}

/* ===== PRINT (a4-paper overrides) ===== */

@page {
  size: A4 portrait;
  margin: 13mm;
}

@media print {
  #a4-paper {
    width: 100% !important;
    max-width: 184mm !important;
    height: auto !important;
    min-height: 270mm !important;
    zoom: 1 !important;
    margin: 0 auto !important;
    border-radius: initial !important;
    box-shadow: initial !important;
  }
  #voucher { border: 0.3mm solid #000; }
  .sig-area { border: none; }
  .no-print { display: none !important; }
}


