/* ===== GLOBAL STYLES ===== */
* {
  font-family: "Times New Roman", Times, serif;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-size: 10pt;
  line-height: 1.2;
}

/* ===== FORM STYLES ===== */
.form-section {
  background: #f8f9fa;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  border-left: 4px solid #007bff;
  font-size: 10pt;
}

.section-title {
  color: #007bff;
  font-weight: 600;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12pt;
}

.dynamic-list {
  border: 1px solid #dee2e6;
  border-radius: 5px;
  padding: 15px;
  background: white;
}

.list-item {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}

.form-control,
.form-select {
  font-family: "Times New Roman", Times, serif;
  font-size: 10pt;
}

/* ===== BUTTON STYLES ===== */
.btn-custom {
  background: linear-gradient(45deg, #007bff, #0056b3);
  border: none;
  color: white;
  padding: 12px 30px;
  border-radius: 25px;
  font-weight: 600;
  transition: all 0.3s ease;
  font-size: 10pt;
}

.btn-custom:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 123, 255, 0.3);
  color: white;
}

/* ===== HEADER STYLES ===== */
.header-section {
  background: linear-gradient(135deg, #007bff, #0056b3);
  color: white;
  padding: 30px 0;
  margin-bottom: 30px;
  border-radius: 0 0 20px 20px;
}

.header-section h1 {
  font-size: 20pt;
  font-weight: bold;
}

.header-section p {
  font-size: 12pt;
}

/* ===== LOADING STYLES ===== */
.loading-spinner {
  display: none;
}

/* ===== PDF PREVIEW STYLES ===== */
#pdfPreview {
  background: white;
  margin: 20px 0;
  border: 2px solid #007bff;
  border-radius: 10px;
  font-family: "Times New Roman", Times, serif;
  font-size: 10pt;
  line-height: 1.2;
  position: relative;
  width: 210mm;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* ===== PRECISE A4 PAGE STRUCTURE ===== */
.pdf-page {
  width: 210mm;
  min-height: 297mm;
  position: relative;
  page-break-after: always;
  break-after: page;
  background: white;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  border-bottom: 2px solid #dee2e6;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow: hidden; /* Prevent content overflow during conversion */
}

.pdf-page:last-child {
  page-break-after: auto;
  break-after: auto;
  border-bottom: none;
}

/* Enhanced Letterhead with better margins */
.page-letterhead {
  display: none;
}

.letterhead-image {
  display: none;
}

/* Improved Content Area with better margins */
.page-content {
  margin-left: 25mm;
  margin-right: 20mm;
  margin-top: 15mm; /* Increased top margin since no letterhead */
  margin-bottom: 20mm;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(297mm - 15mm - 20mm - 15mm); /* Adjusted for no letterhead */
}

/* Enhanced Footer with better positioning */
.page-footer {
  position: absolute;
  bottom: 8mm;
  left: 25mm;
  right: 20mm;
  height: 12mm;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1pt solid #dee2e6;
  background: white;
  font-size: 9pt;
  font-weight: 500;
  color: #666;
  flex-shrink: 0;
}

/* ===== CONTENT STYLES ===== */
.content-section {
  margin-bottom: 6mm;
  page-break-inside: avoid;
  break-inside: avoid;
}

.doc-header {
  text-align: center;
  margin-bottom: 5mm;
  padding: 0;
}

.doc-title {
  font-size: 14pt;
  font-weight: bold;
  margin-bottom: 3mm;
  color: #333;
  line-height: 1.2;
}

.doc-meta {
  background: #f8f9fa;
  border: 1pt solid #dee2e6;
  border-radius: 3mm;
  padding: 5mm;
  margin-bottom: 8mm;
  font-size: 10pt;
}

.doc-meta-item {
  display: flex;
  margin-bottom: 3mm;
  line-height: 1.4;
}

.doc-meta-label {
  font-weight: bold;
  width: 40mm;
  color: #555;
  font-size: 10pt;
}

.doc-meta-value {
  flex: 1;
  font-size: 10pt;
}

.doc-section {
  margin-bottom: 8mm;
  padding: 3mm 0;
}

.doc-section-title {
  font-size: 12pt;
  font-weight: bold;
  color: #007bff;
  border-bottom: 1.5pt solid #007bff;
  padding-bottom: 2mm;
  margin-bottom: 4mm;
  line-height: 1.3;
}

.doc-list {
  list-style-type: decimal;
  padding-left: 5mm;
  font-size: 9pt;
  margin: 0;
}

.doc-list li {
  margin-bottom: 2mm;
  line-height: 1.3;
}

/* ===== TABLE STYLES ===== */
.table {
  font-size: 8pt;
  font-family: "Times New Roman", Times, serif;
  margin-bottom: 3mm;
  width: 100%;
  border-collapse: collapse;
}

.table th {
  font-size: 8pt;
  font-weight: bold;
  background-color: #f8f9fa;
  padding: 2mm;
  line-height: 1.1;
  border: 0.5pt solid #dee2e6;
  text-align: center;
}

.table td {
  font-size: 8pt;
  padding: 2mm;
  line-height: 1.2;
  border: 0.5pt solid #dee2e6;
  text-align: left;
}

/* ===== ENHANCED SORTABLE IMAGE GALLERY ===== */
.sortable-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-top: 20px;
}

.image-preview-item {
  border: 2px solid #dee2e6;
  border-radius: 8px;
  overflow: hidden;
  background: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  cursor: move;
  position: relative;
}

.image-preview-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-color: #007bff;
}

.image-preview-item.sortable-ghost {
  opacity: 0.4;
  transform: rotate(5deg);
}

.image-preview-item.sortable-chosen {
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.image-preview-item.sortable-drag {
  opacity: 0.8;
  transform: rotate(3deg);
  z-index: 1000;
}

.image-preview-container {
  position: relative;
  padding-top: 75%;
  overflow: hidden;
}

.image-preview-container img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background-color: #f8f9fa;
}

.image-preview-content {
  padding: 12px;
}

.image-caption-input {
  margin-bottom: 10px;
  font-size: 9pt;
}

.remove-image-btn {
  width: 100%;
  font-size: 9pt;
}

/* ===== DRAG HANDLE ===== */
.drag-handle {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(0, 123, 255, 0.9);
  color: white;
  padding: 5px;
  border-radius: 3px;
  font-size: 12px;
  cursor: move;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-preview-item:hover .drag-handle {
  opacity: 1;
}

/* ===== IMAGE NUMBER STYLES ===== */
.image-number {
  position: absolute;
  top: 5px;
  left: 5px;
  background: rgba(0, 123, 255, 0.9);
  color: white;
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: bold;
  z-index: 10;
}

/* ===== PDF IMAGE GALLERY ===== */
.doc-image-gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4mm;
  margin: 3mm 0;
  page-break-inside: avoid;
}

.doc-image-item {
  border: 0.5pt solid #dee2e6;
  border-radius: 1mm;
  overflow: hidden;
  box-shadow: 0 0.5mm 1mm rgba(0, 0, 0, 0.1);
  background: white;
  display: flex;
  flex-direction: column;
  min-height: 65mm;
  page-break-inside: avoid;
}

.doc-image-container {
  position: relative;
  overflow: hidden;
  min-height: 55mm;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
}

.doc-image {
  max-width: 100%;
  max-height: 55mm;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: auto;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.doc-image-caption {
  padding: 2mm;
  font-style: italic;
  color: #666;
  font-size: 8pt;
  background: #f8f9fa;
  border-top: 0.5pt solid #dee2e6;
  line-height: 1.2;
  min-height: 8mm;
  display: flex;
  align-items: center;
  text-align: center;
  justify-content: center;
}

/* ===== SIGNATURE STYLES ===== */
.doc-signature {
  margin-top: 8mm;
  display: flex;
  justify-content: space-between;
  page-break-inside: avoid;
}

.doc-signature-block {
  text-align: center;
  width: 45%;
  font-size: 9pt;
}

.doc-signature-line {
  border-top: 0.5pt solid #333;
  margin-top: 12mm;
  margin-bottom: 3mm;
}

.doc-footer {
  margin-top: 8mm;
  border-top: 0.5pt solid #dee2e6;
  padding-top: 3mm;
  text-align: center;
  font-size: 11pt;
  page-break-inside: avoid;
}

/* ===== IMAGE UPLOAD STYLES ===== */
.bulk-image-upload {
  border: 2px dashed #007bff;
  border-radius: 10px;
  padding: 30px;
  text-align: center;
  background: #f8f9fa;
  margin-bottom: 20px;
  transition: all 0.3s ease;
  font-size: 10pt;
}

.bulk-image-upload:hover {
  background: #e9ecef;
  border-color: #0056b3;
}

.bulk-image-upload.dragover {
  background: #e3f2fd;
  border-color: #1976d2;
  transform: scale(1.02);
}

/* ===== MESSAGE STYLES ===== */
.error-message {
  color: #dc3545;
  font-size: 10pt;
  margin-top: 10px;
  text-align: center;
  padding: 10px;
  background: #f8d7da;
  border: 1px solid #f5c6cb;
  border-radius: 5px;
}

.success-message {
  color: #155724;
  font-size: 10pt;
  margin-top: 10px;
  text-align: center;
  padding: 10px;
  background: #d4edda;
  border: 1px solid #c3e6cb;
  border-radius: 5px;
}

/* ===== ALERT STYLES ===== */
.alert {
  padding: 12px 16px;
  margin-bottom: 15px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 9pt;
}

.alert-info {
  color: #0c5460;
  background-color: #d1ecf1;
  border-color: #bee5eb;
}

.alert-warning {
  color: #856404;
  background-color: #fff3cd;
  border-color: #ffeaa7;
}

.alert i {
  margin-right: 8px;
}

/* ===== RESPONSIVE STYLES ===== */
@media (max-width: 768px) {
  .doc-image-gallery,
  .sortable-grid {
    grid-template-columns: repeat(1, 1fr);
  }

  .page-content {
    margin-left: 15mm;
    margin-right: 15mm;
  }

  .page-footer {
    left: 15mm;
    right: 15mm;
  }

  #pdfPreview {
    width: 100%;
    transform: scale(0.8);
    transform-origin: top center;
  }

  .instruction-group {
    padding: 15px;
  }

  .person-title {
    font-size: 12pt;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .letterhead-image {
    width: calc(100% - 30mm);
  }
}

/* ===== PRINT OPTIMIZATION ===== */
@media print {
  .pdf-page {
    page-break-after: always;
    min-height: 297mm;
    width: 210mm;
    margin: 0;
    padding: 0;
    box-shadow: none;
    border: none;
  }

  .pdf-page:last-child {
    page-break-after: auto;
  }

  .content-section,
  .doc-section,
  .instruction-section {
    page-break-inside: avoid;
  }

  .doc-image-gallery {
    grid-template-columns: repeat(2, 1fr);
  }

  .doc-image-item {
    page-break-inside: avoid;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .page-content {
    margin-left: 25mm;
    margin-right: 20mm;
  }

  .page-footer {
    left: 25mm;
    right: 20mm;
  }
}

/* ===== INSTRUCTION GROUPS ===== */
.instruction-group {
  background: white;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  position: relative;
}

.instruction-group:hover {
  border-color: #007bff;
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.1);
}

.person-header {
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #dee2e6;
}

.person-title {
  color: #007bff;
  font-size: 14pt;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.instructions-list {
  margin-top: 15px;
}

.instruction-items {
  border: 1px solid #dee2e6;
  border-radius: 5px;
  padding: 15px;
  background: #f8f9fa;
}

.instruction-item {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: flex-start;
}

.instruction-item:last-child {
  margin-bottom: 0;
}

.instruction-text {
  flex: 1;
  font-size: 10pt;
  min-height: 60px;
}

/* ===== INSTRUCTION DISPLAY IN PDF ===== */
.instruction-section {
  margin-bottom: 8mm;
  padding: 4mm;
  background: #f9f9f9;
  border-left: 3pt solid #007bff;
  border-radius: 2mm;
}

.instruction-person-info {
  background: #e3f2fd;
  padding: 3mm;
  border-radius: 2mm;
  margin-bottom: 4mm;
  font-size: 10pt;
}

.instruction-person-name {
  font-weight: bold;
  color: #1976d2;
  font-size: 11pt;
}

.instruction-person-designation {
  color: #666;
  font-style: italic;
  margin-top: 1mm;
}

.instruction-list-container {
  margin-top: 3mm;
}

.instruction-list-title {
  font-weight: bold;
  color: #333;
  margin-bottom: 2mm;
  font-size: 10pt;
}
