@font-face {
  font-family: "B Nazanin";
  src: local("B Nazanin"), url("../assets/fonts/BNazanin.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "B Nazanin";
  src: local("B Nazanin Bold"), url("../assets/fonts/BNazanin-Bold.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

:root {
  --navy: #0b3e67;
  --navy-deep: #082d4a;
  --blue: #2879ae;
  --blue-soft: #eaf5fc;
  --gold: #c89c49;
  --ink: #17212b;
  --muted: #637180;
  --line: #d9e2ea;
  --surface: #fff;
  --canvas: #edf2f6;
  --danger: #a72b3b;
  --shadow: 0 22px 65px rgba(22, 48, 68, 0.15);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 6% 6%, rgba(40, 121, 174, 0.12), transparent 30rem),
    var(--canvas);
  font-family: "B Nazanin", Tahoma, serif;
  font-size: 18px;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
label,
select,
input[type="range"] {
  -webkit-tap-highlight-color: transparent;
}

button,
.file-button {
  cursor: pointer;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  right: 8px;
  padding: 8px 13px;
  border-radius: 8px;
  color: #fff;
  background: var(--navy);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(1530px, calc(100% - 30px));
  margin: 0 auto;
  padding: 20px 0 38px;
  display: grid;
  grid-template-columns: minmax(330px, 390px) minmax(720px, 1fr);
  gap: 22px;
  align-items: start;
}

.editor-panel {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(94, 121, 142, 0.24);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 15px 45px rgba(32, 61, 82, 0.1);
  scrollbar-width: thin;
}

.editor-heading {
  padding: 0 3px 15px;
}

.back-link {
  display: inline-flex;
  margin-bottom: 12px;
  color: var(--navy);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}

.back-link::before {
  content: "←";
  margin-left: 6px;
}

.back-link:hover,
.back-link:focus-visible {
  text-decoration: underline;
}

.eyebrow {
  display: block;
  color: var(--blue);
  font-size: 15px;
  font-weight: 700;
}

.editor-heading h1 {
  margin: 2px 0 0;
  color: var(--navy-deep);
  font-size: 29px;
  line-height: 1.2;
}

.editor-heading p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.form-section {
  margin-top: 13px;
  padding: 16px;
  border: 1px solid #dde6ed;
  border-radius: 16px;
  background: #fff;
}

.emphasis-section {
  border-color: #bfd8e9;
  background: linear-gradient(145deg, #f7fbff, #fff 58%);
}

.form-section h2 {
  margin: 0 0 13px;
  color: var(--navy-deep);
  font-size: 19px;
}

.section-help {
  margin: -6px 0 13px;
  color: var(--muted);
  font-size: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-grid.single-column {
  grid-template-columns: 1fr;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
  color: #344757;
  font-size: 15px;
  font-weight: 700;
}

.field > span b {
  color: var(--danger);
}

.field-wide {
  grid-column: 1 / -1;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid #cbd7e1;
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  background: #fff;
  font-size: 16px;
  font-weight: 400;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input,
.field select {
  height: 43px;
  padding: 7px 10px;
}

.field textarea {
  min-height: 82px;
  padding: 9px 10px;
  line-height: 1.55;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 121, 174, 0.13);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(167, 43, 59, 0.08);
}

.field-error {
  min-height: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 400;
}

.field-error:empty {
  display: none;
}

.is-conditional[hidden] {
  display: none;
}

.media-controls {
  display: grid;
  gap: 10px;
}

.media-control {
  padding: 11px;
  border: 1px solid #e0e8ee;
  border-radius: 12px;
  background: #fafcfd;
}

.media-control-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 15px;
}

.media-control-heading > div {
  display: flex;
  align-items: center;
  gap: 5px;
}

.file-button,
.text-button {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
}

.file-button {
  border: 1px solid #bed6e6;
  color: var(--navy);
  background: #eef7fc;
}

.text-button {
  border: 0;
  color: #7a4550;
  background: transparent;
}

.range-field {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.range-field input {
  width: 100%;
  accent-color: var(--navy);
}

.privacy-note {
  margin: 14px 2px 0;
  padding: 11px 13px;
  border-radius: 11px;
  color: #446172;
  background: #edf7f3;
  font-size: 14px;
}

.privacy-note > strong,
.privacy-note > span,
.privacy-note > small {
  display: block;
}

.privacy-note > strong {
  color: #254d40;
  font-size: 15px;
}

.privacy-note > small {
  margin-top: 4px;
  color: #6a786f;
  line-height: 1.45;
}

.storage-consent {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  color: #294f43;
  font-weight: 700;
}

.storage-consent input {
  width: 17px;
  height: 17px;
  accent-color: #27765c;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px;
  margin-top: 13px;
}

.primary-button,
.secondary-button,
.compact-print-button {
  border-radius: 11px;
  font-weight: 700;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  padding: 8px 13px;
}

.primary-button {
  border: 1px solid var(--navy);
  color: #fff;
  background: linear-gradient(135deg, var(--navy), #176594);
  box-shadow: 0 8px 18px rgba(11, 62, 103, 0.18);
}

.secondary-button {
  border: 1px solid #cbd7e0;
  color: #495e6c;
  background: #fff;
}

.preview-column {
  min-width: 0;
  overflow: auto;
  padding: 0 1px 30px;
}

.preview-toolbar {
  width: 210mm;
  max-width: 100%;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  color: #3d5362;
}

.preview-toolbar div {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.preview-toolbar span {
  color: var(--muted);
  font-size: 14px;
}

.compact-print-button {
  min-height: 34px;
  padding: 4px 15px;
  border: 1px solid #c3d5e2;
  color: var(--navy);
  background: rgba(255, 255, 255, 0.9);
}

.letter-paper {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  overflow: hidden;
  padding: 17mm 18mm 15mm;
  color: #161d23;
  background: #fff;
  box-shadow: var(--shadow);
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.letterhead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 49mm;
  gap: 11mm;
  align-items: center;
  min-height: 30mm;
}

.brand-block {
  display: grid;
  grid-template-columns: 28mm minmax(0, 1fr);
  gap: 5mm;
  align-items: center;
}

.brand-block h2 {
  margin: 0;
  color: var(--navy-deep);
  font-size: 22px;
  line-height: 1.35;
}

.brand-block > div:last-child > span {
  color: #657682;
  font-size: 14px;
}

.company-kicker {
  margin: 0 0 2px;
  color: var(--gold);
  font-size: 15px;
  font-weight: 700;
}

.letter-meta {
  margin: 0;
  padding: 4mm 5mm;
  border: 1px solid #d6e0e8;
  border-radius: 3mm;
  background: #f8fbfd;
  font-size: 14px;
}

.letter-meta div {
  display: grid;
  grid-template-columns: 13mm 1fr;
  gap: 2mm;
}

.letter-meta div + div {
  margin-top: 2mm;
}

.letter-meta dt {
  color: #5a6a76;
  font-weight: 700;
}

.letter-meta dd {
  margin: 0;
  text-align: right;
}

.header-rule {
  height: 3px;
  margin: 8mm 0 12mm;
  background: var(--navy);
}

.header-rule span {
  display: block;
  width: 24%;
  height: 100%;
  background: var(--gold);
}

.letter-content {
  padding: 0 3mm;
}

.recipient-line {
  margin: 0 0 5mm;
  font-size: 19px;
  font-weight: 700;
}

.letter-content h1 {
  margin: 0 0 8mm;
  padding: 3mm 5mm;
  border-right: 3px solid var(--gold);
  color: var(--navy-deep);
  background: #f6f9fb;
  font-size: 18px;
}

.letter-content h1 span {
  font-weight: 400;
}

.greeting {
  margin: 0 0 6mm;
  font-weight: 700;
}

.body-paragraph {
  margin: 0 0 7mm;
  font-size: 19px;
  line-height: 2.05;
  text-align: justify;
}

.closing-copy {
  white-space: pre-line;
}

.letter-footer {
  position: absolute;
  right: 21mm;
  bottom: 19mm;
  left: 21mm;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 63mm;
  gap: 14mm;
  align-items: end;
}

.validity-note {
  padding-top: 4mm;
  border-top: 1px solid #d6dfe5;
  color: #6d7982;
  font-size: 13px;
}

.signer-block {
  min-height: 46mm;
  text-align: center;
}

.signer-block > strong,
.signer-block > span {
  position: relative;
  z-index: 3;
  display: block;
}

.signer-block > strong {
  color: var(--navy-deep);
  font-size: 17px;
}

.signer-block > span {
  margin-top: 1px;
  color: #52626e;
  font-size: 14px;
}

.mark-stage {
  position: relative;
  height: 33mm;
  margin-top: 2mm;
}

.media-slot {
  --image-scale: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-slot img {
  display: block;
  width: calc(100% * var(--image-scale));
  max-width: none;
  max-height: calc(100% * var(--image-scale));
  object-fit: contain;
}

.media-slot.is-empty img {
  display: none;
}

.media-slot.is-empty::after {
  content: attr(aria-label);
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  border: 1px dashed #c8d5dd;
  border-radius: 3mm;
  color: #91a0aa;
  background: #fbfcfd;
  font-size: 12px;
}

.logo-slot {
  width: 28mm;
  height: 25mm;
}

.seal-slot,
.signature-slot {
  position: absolute;
}

.seal-slot {
  z-index: 1;
  right: 2mm;
  bottom: 0;
  width: 31mm;
  height: 31mm;
  opacity: 0.92;
}

.signature-slot {
  z-index: 2;
  left: 0;
  bottom: 3mm;
  width: 40mm;
  height: 24mm;
}

.paper-accent {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 5mm;
  background: linear-gradient(90deg, var(--gold) 0 22%, var(--navy) 22% 100%);
}

.toast {
  position: fixed;
  z-index: 90;
  right: 50%;
  bottom: 24px;
  max-width: min(420px, calc(100% - 28px));
  padding: 9px 16px;
  border-radius: 999px;
  color: #fff;
  background: #172a39;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transform: translate(50%, 16px);
  transition: opacity 0.16s, transform 0.16s;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(50%, 0);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 350px minmax(650px, 1fr);
    width: calc(100% - 20px);
    gap: 14px;
  }
}

@media (max-width: 970px) {
  .app-shell {
    display: block;
    width: min(820px, calc(100% - 24px));
  }

  .editor-panel {
    position: static;
    max-height: none;
    margin-bottom: 22px;
  }

  .preview-column {
    width: 100%;
  }
}

@media (max-width: 620px) {
  body {
    font-size: 16px;
  }

  .app-shell {
    width: calc(100% - 14px);
    padding-top: 8px;
  }

  .editor-panel {
    padding: 16px;
    border-radius: 16px;
  }

  .field-grid,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .field-wide {
    grid-column: auto;
  }

  .preview-column {
    display: none;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    height: 297mm;
    background: #fff;
  }

  body {
    margin: 0;
  }

  .screen-only,
  .skip-link,
  .toast {
    display: none !important;
  }

  .app-shell,
  .preview-column {
    display: block;
    width: 210mm;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  .letter-paper {
    width: 210mm;
    height: 297mm;
    min-height: 0;
    margin: 0;
    box-shadow: none;
    break-after: avoid-page;
    page-break-after: avoid;
  }

  .media-slot.is-empty::after {
    display: none;
  }
}
