body, h1, h2, h3, h4, h5, h6 {
  font-family: "Montserrat", sans-serif;
}

.w3-sidebar {
  width: 120px;
  background: #000;
}

#main {
  margin-left: 120px;
}

:root {
  --letter-width: 210mm;
  --letter-height: 297mm;
  --left-margin: 25mm;
  --right-margin: 20mm;
}

.letter-container {
  width: var(--letter-width);
  min-height: var(--letter-height);
  background-color: white;
  background-image: 
    linear-gradient(to bottom, transparent 296mm, #ccc 296mm, #ccc 297mm),
    linear-gradient(to bottom, transparent 296mm, #ccc 296mm, #ccc 297mm);
  background-size: 15mm 297mm, 15mm 297mm;
  background-position: left top, right top;
  background-repeat: repeat-y, repeat-y;
  color: black;
  position: relative;
  font-family: "Arial", sans-serif; /* Letter standard font */
  font-size: 11pt;
  line-height: 1.4;
  box-shadow: 0 4px 15px rgba(255,255,255,0.2);
  box-sizing: border-box;
  
  /* Start flow at the subject line (Form B: approx 98.4mm) */
  padding-top: 100mm; 
  padding-left: var(--left-margin);
  padding-right: var(--right-margin);
  padding-bottom: 25mm;
  text-align: left;
  margin: 0 auto;
}

[contenteditable="true"] {
  outline: none;
  border: 1px dashed rgba(0,0,0,0.2);
  transition: border 0.3s, background 0.3s;
  min-height: 1.4em;
  padding: 2px;
  border-radius: 3px;
  white-space: pre-wrap;
}

[contenteditable="true"]:hover,
[contenteditable="true"]:focus {
  border-color: #000;
  background: rgba(0,0,0,0.03);
}

[contenteditable="true"]:empty:before {
  content: attr(data-placeholder);
  color: #999;
  pointer-events: none;
  display: block;
}

/* Fixed elements for DIN 5008 */
.header-sender {
  position: absolute;
  top: 15mm;
  right: var(--right-margin);
  text-align: right;
  font-size: 9pt;
  color: #555;
  max-width: 120mm;
}

.address-window {
  position: absolute;
  top: 45mm;
  left: 20mm;
  width: 85mm;
  height: 45mm;
  padding-left: 5mm; /* Text aligns at 25mm */
  padding-top: 5mm;
  box-sizing: border-box;
}

.return-address {
  font-size: 7pt;
  text-decoration: underline;
  margin-bottom: 3mm;
  color: #333;
}

.recipient-address {
  font-size: 11pt;
}

.info-block {
  position: absolute;
  top: 90mm;
  right: var(--right-margin);
  text-align: right;
}

/* Fold and punch marks */
.fold-mark {
  position: absolute;
  left: 0;
  width: 4mm;
  border-top: 1px solid #000;
}
.fold-mark-1 { top: 105mm; }
.fold-mark-2 { top: 210mm; }

.punch-mark {
  position: absolute;
  left: 0;
  top: 148.5mm;
  width: 6mm;
  border-top: 1px solid #000;
}

/* Flow elements */
.subject-line {
  font-weight: bold;
  margin-bottom: 10mm;
}

.salutation {
  margin-bottom: 5mm;
}

.letter-body {
  margin-bottom: 5mm;
  text-align: justify;
}

.closing {
  margin-bottom: 0; 
  page-break-inside: avoid;
  break-inside: avoid;
}

.signature-name {
  margin-bottom: 10mm;
  page-break-inside: avoid;
  break-inside: avoid;
}

.enclosures {
  font-size: 10pt;
  page-break-inside: avoid;
  break-inside: avoid;
}

/* Responsive for smaller screens */
@media only screen and (max-width: 992px) {
  #main {
    margin-left: 0;
  }
}

@media only screen and (max-width: 600px) {
  .letter-container {
    width: 100%;
    min-height: auto;
  }
}

/* Print Styles */
@media print {
  body {
    background: white;
    margin: 0;
    padding: 0;
  }
  .w3-sidebar, .w3-top, header, footer, button {
    display: none !important;
  }
  #main {
    margin: 0 !important;
    padding: 0 !important;
  }
  .w3-padding-64 {
    padding: 0 !important;
  }
  .w3-content {
    max-width: none !important;
  }
  .letter-container {
    box-shadow: none;
    width: 210mm;
    min-height: auto;
    margin: 0;
    padding-bottom: 0 !important;
    background-image: none !important;
  }
  @page {
    size: A4;
    margin: 25mm 0mm;
  }
  @page :first {
    margin-top: 0mm;
  }
  [contenteditable="true"] {
    border: none !important;
    padding: 0 !important;
  }
  [contenteditable="true"]:empty:before {
    content: "";
  }
}
