/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
  line-height: 1.6;
  color: #1e3a8a;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* Background Graphics */
.background-graphics {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

.bg-shape {
  position: absolute;
  border-radius: 50%;
  opacity: 0.03;
  animation: float 20s ease-in-out infinite;
}

.shape-1 {
  width: 300px;
  height: 300px;
  background: linear-gradient(45deg, #87ceeb, #4682b4);
  top: 10%;
  left: -10%;
  animation-delay: 0s;
}

.shape-2 {
  width: 200px;
  height: 200px;
  background: linear-gradient(135deg, #4682b4, #1e3a8a);
  top: 60%;
  right: -5%;
  animation-delay: 5s;
}

.shape-3 {
  width: 150px;
  height: 150px;
  background: linear-gradient(225deg, #87ceeb, #4682b4);
  bottom: 20%;
  left: 20%;
  animation-delay: 10s;
}

.shape-4 {
  width: 250px;
  height: 250px;
  background: linear-gradient(315deg, #4682b4, #87ceeb);
  top: 30%;
  right: 30%;
  animation-delay: 15s;
}

.shape-5 {
  width: 180px;
  height: 180px;
  background: linear-gradient(45deg, #87ceeb, #1e3a8a);
  top: 5%;
  right: 10%;
  animation-delay: 8s;
}

.shape-6 {
  width: 120px;
  height: 120px;
  background: linear-gradient(180deg, #4682b4, #87ceeb);
  bottom: 10%;
  right: 5%;
  animation-delay: 12s;
}

/* Background Patterns */
.bg-pattern {
  position: absolute;
  opacity: 0.02;
  animation: rotate 30s linear infinite;
}

.pattern-1 {
  width: 100px;
  height: 100px;
  background: repeating-linear-gradient(
    45deg,
    #4682b4,
    #4682b4 10px,
    transparent 10px,
    transparent 20px
  );
  top: 25%;
  left: 5%;
  animation-delay: 0s;
}

.pattern-2 {
  width: 80px;
  height: 80px;
  background: repeating-linear-gradient(
    -45deg,
    #87ceeb,
    #87ceeb 8px,
    transparent 8px,
    transparent 16px
  );
  top: 70%;
  right: 15%;
  animation-delay: 10s;
}

.pattern-3 {
  width: 60px;
  height: 60px;
  background: repeating-linear-gradient(
    90deg,
    #1e3a8a,
    #1e3a8a 5px,
    transparent 5px,
    transparent 10px
  );
  bottom: 40%;
  left: 10%;
  animation-delay: 20s;
}

/* Background Hexagons */
.bg-hexagon {
  position: absolute;
  opacity: 0.025;
  animation: pulse 25s ease-in-out infinite;
}

.hex-1 {
  width: 90px;
  height: 90px;
  background: #4682b4;
  clip-path: polygon(30% 0%, 70% 0%, 100% 50%, 70% 100%, 30% 100%, 0% 50%);
  top: 15%;
  right: 25%;
  animation-delay: 5s;
}

.hex-2 {
  width: 70px;
  height: 70px;
  background: #87ceeb;
  clip-path: polygon(30% 0%, 70% 0%, 100% 50%, 70% 100%, 30% 100%, 0% 50%);
  bottom: 25%;
  left: 25%;
  animation-delay: 15s;
}

.hex-3 {
  width: 50px;
  height: 50px;
  background: #1e3a8a;
  clip-path: polygon(30% 0%, 70% 0%, 100% 50%, 70% 100%, 30% 100%, 0% 50%);
  top: 50%;
  left: 15%;
  animation-delay: 25s;
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.025;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.04;
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0px) rotate(0deg);
  }
  25% {
    transform: translateY(-20px) rotate(90deg);
  }
  50% {
    transform: translateY(0px) rotate(180deg);
  }
  75% {
    transform: translateY(20px) rotate(270deg);
  }
}

/* Main Container */
.letterhead-container {
  max-width: 8.5in;
  min-height: 11in;
  margin: 0 auto;
  background: white;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  z-index: 1;
  padding: 0;
}

/* Header Styles */
.letterhead-header {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 50%, #cbd5e1 100%);
  /* padding: 1.5rem 2rem; */
  border-bottom: 2px solid #4682b4;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 1rem;
  overflow: hidden;
  height: 100px;
}

.logo {
  width: 300px;
  height: 125px;
}

.logo img {
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
  width: inherit;
  height: inherit;
}

.company-info {
  display: flex;
  flex-direction: column;
}

.company-name {
  font-size: 2rem;
  font-weight: 700;
  color: #1e3a8a;
  margin: 0;
  letter-spacing: -0.02em;
}

.tm {
  font-size: 0.8rem;
  vertical-align: super;
  color: #4682b4;
}

.company-subtitle {
  font-size: 1.1rem;
  font-weight: 400;
  color: #4682b4;
  margin-top: -0.2rem;
}

/* Content Styles */
.letterhead-content {
  padding: 2.5rem;
  background: white;
}

/* Title Section Styles */
.title-section {
  text-align: center;
  margin: 2rem 0;
}

.title-field {
  display: flex;
  justify-content: center;
}

.letter-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: #1e3a8a;
  text-align: center;
  min-width: 300px;
  padding: 0.75rem 1rem;
  border: 2px solid transparent;
  border-radius: 6px;
  background: rgba(135, 206, 235, 0.05);
}

.letter-title:hover {
  background: rgba(135, 206, 235, 0.1);
  border-color: rgba(135, 206, 235, 0.3);
}

.letter-title:focus {
  background: rgba(135, 206, 235, 0.15);
  border-color: #4682b4;
  box-shadow: 0 0 0 3px rgba(70, 130, 180, 0.1);
}

/* Subject Section Styles */
.subject-section {
  margin-bottom: 1.5rem;
}

.subject-field {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.subject-field label {
  font-weight: 600;
  color: #374151;
  min-width: 80px;
}

.subject-content {
  flex: 1;
}

/* Recipient Section Styles */
.recipient-section {
  margin-bottom: 1.5rem;
}

.section-header {
  margin-bottom: 0.5rem;
}

.section-header label {
  font-weight: 600;
  color: #374151;
}

.recipient-address {
  margin-left: 2rem;
  flex: 1;
  min-height: 80px;
  white-space: pre-line;
}

/* Updated Recipient Address Styles */
.recipient-address {
  min-height: auto;
  line-height: 1.6;
  white-space: pre-line;
}

/* Toggle Controls in Action Buttons */
.toggle-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.btn-toggle {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-toggle:hover {
  background: #e2e8f0;
  color: #334155;
}

.btn-toggle.active {
  background: #87ceeb;
  color: white;
  border-color: #4682b4;
}

.date-section,
.title-section,
.recipient-section,
.subject-section,
.salutation-section,
.body-section,
.closing-section {
  margin-bottom: 1.5rem;
}

.body-section {
  margin: 2rem 0;
}

.date-field,
.recipient-field,
.subject-field {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.date-field label,
.recipient-field label,
.subject-field label {
  font-weight: 600;
  color: #374151;
  min-width: 80px;
  margin-top: 0.1rem;
}

.editable-field {
  outline: none;
  border: 2px solid transparent;
  border-radius: 4px;
  padding: 0.5rem;
  transition: all 0.2s ease;
  background: transparent;
  color: #1e3a8a;
  font-family: inherit;
  line-height: 1.6;
}

.editable-field:hover {
  background: rgba(135, 206, 235, 0.05);
  border-color: rgba(135, 206, 235, 0.2);
}

.editable-field:focus {
  background: rgba(135, 206, 235, 0.1);
  border-color: #4682b4;
  box-shadow: 0 0 0 3px rgba(70, 130, 180, 0.1);
}

.editable-field[placeholder]:empty::before {
  content: attr(placeholder);
  color: #9ca3af;
  font-style: italic;
}

.recipient-address {
  flex: 1;
  min-height: 80px;
}

.letter-body {
  min-height: 300px;
  font-size: 15px;
  line-height: 1.8;
  text-align: justify;
}

.letter-body p {
  margin-bottom: 1rem;
}

.closing-field {
  margin-bottom: 3rem;
  min-width: 200px;
  display: inline-block;
}

.signature-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-left: 0;
}

.signature-name {
  font-weight: 600;
  font-size: 1.1rem;
}

.signature-title {
  color: #64748b;
  font-size: 0.95rem;
}

.signature-company {
  color: #4682b4;
  font-weight: 500;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Footer Styles */
.letterhead-footer {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-top: 1px solid #cbd5e1;
  padding: 1rem 2rem;
  margin-top: auto;
  box-shadow: inset 1px 1px 16px #eeee;
  position: absolute;
  bottom: 0;
  width: 100%;
}

.footer-content {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.75rem;
  color: #64748b;
}

.footer-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.footer-label {
  font-weight: 600;
  color: #475569;
}

.footer-value {
  color: #64748b;
}

.footer-separator {
  color: #cbd5e1;
  font-weight: 300;
}

/* Floating Action Button Styles */
.fab-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
}

.fab-main {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4682b4, #1e3a8a);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(70, 130, 180, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 1001;
}

.fab-main:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(70, 130, 180, 0.5);
}

.fab-main.active {
  transform: rotate(45deg);
}

.fab-menu {
  position: absolute;
  bottom: 70px;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fab-menu.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.fab-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: white;
  border: none;
  border-radius: 28px;
  color: #374151;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.2s ease;
  transform: scale(0.8);
  animation: fabItemIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.fab-item:nth-child(1) {
  animation-delay: 0.05s;
}
.fab-item:nth-child(2) {
  animation-delay: 0.1s;
}
.fab-item:nth-child(3) {
  animation-delay: 0.15s;
}
.fab-item:nth-child(4) {
  animation-delay: 0.2s;
}
.fab-item:nth-child(5) {
  animation-delay: 0.25s;
}
.fab-item:nth-child(6) {
  animation-delay: 0.3s;
}

.fab-item:hover {
  background: #f8fafc;
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.fab-item svg {
  color: #4682b4;
  flex-shrink: 0;
}

@keyframes fabItemIn {
  to {
    transform: scale(1);
  }
}

/* Print Styles */
@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  @page {
    margin: 0.5in 0.75in 0.5in 0.75in;
    size: A4;
  }

  html,
  body {
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    font-size: 12pt !important;
    line-height: 1.4 !important;
  }

  .background-graphics,
  .fab-container {
    display: none !important;
  }

  .letterhead-container {
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
    width: 100% !important;
    height: auto !important;
    display: block !important;
    page-break-inside: auto !important;
  }

  .letterhead-header {
    background: linear-gradient(
      135deg,
      #f8fafc 0%,
      #e2e8f0 50%,
      #cbd5e1 100%
    ) !important;
    border-bottom: 2px solid #4682b4 !important;
    padding: 0 !important;
    height: 100px !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1000 !important;
    page-break-inside: avoid !important;
    page-break-after: avoid !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
  }

  .letterhead-content {
    padding: 1.5rem 2rem !important;
    margin-top: 120px !important;
    margin-bottom: 60px !important;
    page-break-inside: auto !important;
  }

  .letterhead-footer {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%) !important;
    border-top: 1px solid #cbd5e1 !important;
    padding: 1rem 1rem !important;
    height: 50px !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;

    z-index: 1000 !important;
    page-break-inside: avoid !important;
    page-break-before: avoid !important;
    display: flex !important;
    flex-direction: column;
    align-items: center !important;
    justify-content: center !important;
  }

  .editable-field {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    color: #1e3a8a !important;
    opacity: 1 !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .footer-content {
    font-size: 9pt !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 0.5rem !important;
  }

  .footer-separator {
    display: inline !important;
  }

  /* Ensure content flows properly across pages */
  .date-section,
  .title-section,
  .recipient-section,
  .subject-section,
  .salutation-section {
    page-break-inside: avoid !important;
    margin-bottom: 1rem !important;
  }

  .body-section {
    margin-bottom: 1.5rem !important;
    page-break-inside: auto !important;
  }

  .closing-section {
    page-break-inside: avoid !important;
    margin-bottom: 1rem !important;
  }

  .closing-field {
    margin-bottom: 2rem !important;
    min-height: 1.5rem !important;
    display: block !important;
    width: 100% !important;
  }

  .signature-field {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    margin-left: 0 !important;
  }

  .letter-body p {
    margin-bottom: 0.75rem !important;
    page-break-inside: auto !important;
    orphans: 2 !important;
    widows: 2 !important;
  }

  /* Logo sizing for print */
  .logo {
    width: 300px !important;
    height: 125px !important;
    overflow: hidden !important;
  }

  .logo img {
    width: inherit !important;
    height: inherit !important;
    object-fit: contain !important;
  }

  /* Ensure proper spacing */
  .recipient-address {
    margin-left: 1rem !important;
  }

  .subject-field {
    display: flex !important;
    align-items: baseline !important;
    gap: 0.5rem !important;
  }

  .subject-field label {
    font-weight: bold !important;
    min-width: 60px !important;
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .letterhead-container {
    margin: 1rem;
    border-radius: 0;
  }

  .letterhead-header {
    padding: 1rem;
  }

  .letterhead-content {
    padding: 1.5rem;
  }

  .letterhead-footer {
    padding: 0.75rem;
  }

  .footer-content {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .footer-separator {
    display: none;
  }

  .date-field,
  .subject-field {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .fab-container {
    bottom: 1rem;
    right: 1rem;
  }

  .company-name {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .fab-main {
    width: 48px;
    height: 48px;
  }

  .fab-item {
    font-size: 12px;
    padding: 10px 14px;
  }
}

/* Accessibility */
.editable-field:focus-visible {
  outline: 2px solid #4682b4;
  outline-offset: 2px;
}

/* Animation for smooth interactions */
.letterhead-container {
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
