:root {
  --navy: #1a3560;
  --navy-deep: #12284a;
  --gold: #c9922a;
  --gold-bright: #e0a83a;
  --ink: #1e1e1e;
  --muted: #3a3a3a;
  --paper: #ffffff;
  --page-bg: #e8ecf1;
  --edit-bg: rgba(201, 146, 42, 0.08);
  --edit-outline: rgba(26, 53, 96, 0.25);
  --a4-w: 794px;
  --a4-h: 1123px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
}

body {
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  background: var(--page-bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.45;
}

/* ── Toolbar ── */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--navy-deep);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.toolbar-brand {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}

.toolbar-logo {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.toolbar-logo span {
  color: var(--gold-bright);
}

.toolbar-hint {
  font-size: 0.8rem;
  opacity: 0.7;
}

.toolbar-actions {
  display: flex;
  gap: 0.6rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1.1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--gold);
  color: #fff;
  box-shadow: 0 2px 8px rgba(201, 146, 42, 0.4);
}

.btn-primary:hover {
  background: var(--gold-bright);
}

.btn-primary.loading {
  opacity: 0.7;
  pointer-events: none;
}

.btn-ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ── Page wrap ── */
.page-wrap {
  padding: 1.5rem 1rem 3rem;
  display: flex;
  justify-content: center;
}

/* ── Letter (A4) ── */
.letter {
  width: var(--a4-w);
  min-height: var(--a4-h);
  background: var(--paper);
  box-shadow: 0 8px 40px rgba(18, 40, 74, 0.18);
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top bar */
.top-bar {
  height: 10px;
  background: var(--navy);
  position: relative;
  flex-shrink: 0;
}

.top-flourish {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, -30%);
  width: 48px;
  height: 14px;
  background: var(--gold);
  clip-path: polygon(0 40%, 15% 0, 50% 60%, 85% 0, 100% 40%, 50% 100%);
}

/* Header */
.letter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.4rem 0.5rem;
  gap: 1rem;
}

.brand-block {
  flex: 0 1 auto;
  max-width: 52%;
}

.brand-logo {
  display: block;
  width: auto;
  height: 92px;
  max-width: 100%;
  object-fit: contain;
  object-position: left center;
}

.contact-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: left;
}

.contact-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.icon-circle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  display: block;
  object-fit: cover;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Title */
.title-block {
  text-align: center;
  padding: 0.4rem 1.4rem 0.5rem;
}

.title-block h1 {
  font-family: "Source Sans 3", sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: 0.12em;
  line-height: 1.1;
}

.subtitle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 0.2rem;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.sub-line {
  width: 28px;
  height: 1.5px;
  background: var(--gold);
}

/* Intro */
.intro {
  padding: 0.3rem 1.5rem 0.5rem;
  font-size: 0.82rem;
}

.date-line {
  margin-bottom: 0.55rem;
  font-weight: 500;
}

.salutation {
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.intro-text {
  color: var(--muted);
  text-align: justify;
}

/* Sections */
.section {
  padding: 0.35rem 1.5rem 0.25rem;
  position: relative;
}

.section-head {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: #1a3560;
  color: #ffffff;
  padding: 0.28rem 0.9rem 0.28rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.sec-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.18);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.sec-icon img {
  display: block;
  width: 12px;
  height: 12px;
}

.sec-title {
  color: #ffffff !important;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.section-head-img {
  display: block;
  height: 28px;
  width: auto;
  max-width: 100%;
  margin-bottom: 0.4rem;
}

.details-grid {
  padding-left: 0.35rem;
  font-size: 0.8rem;
}

.detail-row {
  display: grid;
  grid-template-columns: 130px 12px 1fr;
  gap: 0.15rem;
  margin-bottom: 0.18rem;
  align-items: start;
}

.detail-row .label {
  font-weight: 600;
  color: var(--ink);
}

.detail-row .colon {
  font-weight: 600;
}

.detail-row .value {
  color: var(--muted);
}

.bullet-list {
  list-style: none;
  padding-left: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.bullet-list li {
  position: relative;
  padding-left: 0.95rem;
  margin-bottom: 0.22rem;
  text-align: justify;
}

.bullet-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--navy);
  font-weight: 700;
}

.section-terms {
  min-height: 0;
}

.taj-mark {
  position: absolute;
  right: 0.5rem;
  bottom: -0.5rem;
  width: 160px;
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
}

.section-terms .bullet-list {
  position: relative;
  z-index: 1;
}

/* Closing */
.closing {
  padding: 0.5rem 1.5rem 0.8rem;
  font-size: 0.82rem;
  position: relative;
  z-index: 1;
}

.closing > p:first-child {
  color: var(--muted);
  text-align: justify;
  margin-bottom: 0.7rem;
}

.regards {
  margin-bottom: 0.15rem;
}

.signature {
  font-family: "Great Vibes", cursive;
  font-size: 1.85rem;
  color: #2a5a9e;
  line-height: 1.2;
  margin: 0.1rem 0 0.15rem;
}

.signatory-name,
.signatory-title,
.signatory-company {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.35;
}

/* Footer */
.letter-footer {
  margin-top: auto;
  background-color: #1a3560;
  color: #ffffff;
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 0.75rem;
  padding: 0.7rem 1.1rem;
  font-size: 0.62rem;
  line-height: 1.35;
  flex-shrink: 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.footer-col {
  display: flex;
  gap: 0.4rem;
}

.footer-col.address {
  align-items: flex-start;
}

.footer-col.mid,
.footer-col.right {
  flex-direction: column;
  gap: 0.3rem;
}

.footer-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.footer-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  display: block;
  object-fit: cover;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.footer-col strong {
  display: block;
  font-size: 0.7rem;
  margin-bottom: 0.1rem;
}

.socials {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.15rem;
}

.social {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.social svg {
  display: block;
}

.bottom-accent {
  height: 4px;
  background: var(--gold);
  flex-shrink: 0;
}

/* Editable highlight (screen only) */
[contenteditable="true"] {
  outline: none;
  border-radius: 2px;
  transition: background 0.15s, box-shadow 0.15s;
  cursor: text;
}

body:not(.printing) [contenteditable="true"]:hover {
  background: var(--edit-bg);
}

body:not(.printing) [contenteditable="true"]:focus {
  background: rgba(201, 146, 42, 0.14);
  box-shadow: 0 0 0 2px var(--edit-outline);
}

.editable {
  display: inline;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-deep);
  color: #fff;
  padding: 0.7rem 1.4rem;
  border-radius: 8px;
  font-size: 0.9rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  z-index: 200;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* Print / PDF mode */
body.printing .toolbar,
body.printing .toast {
  display: none !important;
}

body.printing {
  background: #fff;
}

body.printing .page-wrap {
  padding: 0;
}

body.printing .letter {
  box-shadow: none;
  width: 794px;
  min-height: 1123px;
}

/* Fixed desktop layout for PDF export clone */
.pdf-export {
  width: 794px !important;
  max-width: 794px !important;
  min-height: 1123px !important;
  box-shadow: none !important;
  transform: none !important;
  margin: 0 !important;
}

.pdf-export .letter-header {
  flex-direction: row !important;
  align-items: center !important;
}

.pdf-export .letter-footer {
  grid-template-columns: 1.5fr 1fr 1fr !important;
}

.pdf-export .detail-row {
  grid-template-columns: 130px 12px 1fr !important;
}

body.printing [contenteditable="true"] {
  background: transparent !important;
  box-shadow: none !important;
}

body.printing .section-head,
body.printing .sec-title,
body.printing .letter-footer,
body.printing .top-bar,
body.printing .bottom-accent,
body.printing .icon-circle,
body.printing .footer-icon,
body.printing .social {
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

body.printing .sec-title {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  text-shadow: 0 0 0.5px #ffffff;
}

/* Mobile — screen only (avoid breaking PDF capture width) */
@media screen and (max-width: 860px) {
  .page-wrap {
    padding: 1rem 0.5rem 2rem;
  }

  .letter {
    width: 100%;
    max-width: 794px;
    transform-origin: top center;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem;
  }

  .toolbar-actions {
    justify-content: stretch;
  }

  .toolbar-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .letter-header {
    flex-direction: column;
  }

  .detail-row {
    grid-template-columns: 110px 10px 1fr;
  }

  .letter-footer {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
}

@media print {
  .no-print {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .page-wrap {
    padding: 0;
  }

  .letter {
    box-shadow: none;
    width: 100%;
    min-height: 100vh;
  }

  [contenteditable="true"] {
    background: transparent !important;
    box-shadow: none !important;
  }
}
