* {
  box-sizing: border-box;
}
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  background: #f6f7fb;
  color: #0f172a;
}
.container {
  max-width: 960px;
  margin: 24px auto;
  padding: 24px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

h1 {
  margin-top: 0;
  font-size: 28px;
  color: #1e3a8a;
  text-align: center;
  margin-bottom: 24px;
}

form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
}

.field {
  display: flex;
  flex-direction: column;
}

.field label {
  font-size: 14px;
  color: #334155;
  margin-bottom: 6px;
  font-weight: 600;
}

.field input,
.field textarea {
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 15px;
  width: 100%;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.full-width {
  grid-column: 1 / -1;
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.actions button, .secondary-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: background-color 0.2s ease;
}

#previewBtn {
  background: #2563eb;
  color: #fff;
}
#previewBtn:hover {
  background: #1d4ed8;
}

#downloadBtn {
  background: #10b981;
  color: #fff;
}
#downloadBtn:hover {
  background: #047857;
}

#sendBtn {
  background: #f59e0b;
  color: #fff;
}
#sendBtn:hover {
  background: #b45309;
}

.secondary-btn {
  background: #e2e8f0;
  color: #334155;
  margin-top: 8px;
}
.secondary-btn:hover {
  background: #cbd5e1;
}

.status {
  grid-column: 1 / -1;
  margin-top: 16px;
  min-height: 22px;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  background-color: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.status[style*="b91c1c"] { /* Error state */
  background-color: #fef2f2;
  color: #b91c1c;
  border-color: #fca5a5;
}

.preview {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid #e5e7eb;
}

.preview h2 {
  font-size: 20px;
  margin: 0 0 16px 0;
  color: #1e3a8a;
}

#pdfFrame {
  width: 100%;
  height: 700px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

#openPdfLink {
  display: inline-block;
  margin: 0 0 12px 0;
  color: #2563eb;
  font-weight: 600;
  text-decoration: none;
}

#openPdfLink:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  form {
    grid-template-columns: 1fr;
  }
  .actions {
    flex-direction: column;
  }
  .actions button, .secondary-btn {
    width: 100%;
  }
  .container {
    margin: 16px;
    padding: 16px;
  }
  #pdfFrame {
    height: 500px;
  }
}

/* Letterhead Template (A4 proportions 1:1.414, e.g., 794px x 1123px) */
.letterhead-template {
  width: 794px;
  min-height: 1123px;
  background: white;
  padding: 60px;
  box-sizing: border-box;
  font-family: 'Times New Roman', Times, serif;
  color: #000;
  position: relative;
}

.lh-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.lh-logo {
  width: 120px;
  height: auto;
  margin-right: 20px;
}

.lh-header-text {
  flex: 1;
  text-align: center;
}

.lh-title {
  color: #002b7f;
  font-size: 28px;
  font-weight: bold;
  margin: 0 0 10px 0;
  font-family: Arial, sans-serif;
}

.lh-address, .lh-contact, .lh-email {
  margin: 4px 0;
  font-size: 14px;
  font-family: Arial, sans-serif;
  color: #333;
}

.lh-divider {
  border: none;
  border-top: 3px solid #002b7f;
  margin-bottom: 40px;
}

.lh-body {
  font-size: 16px;
  line-height: 1.6;
}

.lh-date-row {
  margin-bottom: 30px;
  font-weight: normal;
}

.lh-recipient p {
  margin: 0;
}

.lh-salutation {
  margin-top: 30px;
  margin-bottom: 20px;
}

.lh-subject {
  font-size: 16px;
  font-weight: bold;
  text-decoration: underline;
  margin-bottom: 30px;
}

.lh-details {
  margin-left: 20px;
  margin-bottom: 40px;
}

.lh-row {
  display: flex;
  margin-bottom: 10px;
}

.lh-label {
  width: 150px;
}

.lh-colon {
  width: 20px;
}

.lh-value {
  font-weight: bold;
}

.lh-closing {
  margin-bottom: 10px;
}

.lh-best-regards {
  margin-bottom: 20px;
}

.lh-signature-container {
  margin-top: 10px;
}

.lh-signature {
  max-width: 200px;
  max-height: 100px;
  object-fit: contain;
  display: block;
}

.lh-signature-text {
  margin-top: 5px;
  font-weight: bold;
}

.lh-footer {
  position: absolute;
  bottom: 40px;
  left: 60px;
  right: 60px;
  text-align: left;
  font-size: 12px;
  color: #666;
  border-top: 1px solid #ccc;
  padding-top: 10px;
}
