/*******************************
            Tokens
*******************************/

:root {
  --brand: #E16C3E;
  --brand-strong: #C4552A;
  --brand-tint: #FCEEE7;
  --ink: #1F2328;
  --muted: #5F6670;
  --line: #E3E5E8;
  --surface: #FFFFFF;
  --canvas: #F6F4F2;
  --error: #C2362B;
  --success: #2E7D32;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.06), 0 4px 16px rgba(31, 35, 40, 0.06);
}

/*******************************
            Global
*******************************/

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

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: "Source Sans 3", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/*******************************
            Header
*******************************/

.site-header {
  background: var(--surface);
  border-top: 4px solid var(--brand);
  border-bottom: 1px solid var(--line);
}

.site-header__inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-header__logo {
  display: block;
  height: auto;
}

.site-header__divider {
  width: 1px;
  height: 24px;
  background: var(--line);
}

.site-header__title {
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
}

/*******************************
            Page
*******************************/

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 40px 24px 64px;
}

.intro {
  margin-bottom: 28px;
}

.intro h1 {
  margin: 0 0 6px;
  font-size: 32px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.intro h1::after {
  content: "";
  display: block;
  width: 48px;
  height: 4px;
  margin-top: 14px;
  border-radius: 2px;
  background: var(--brand);
}

.intro p {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 17px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card__heading {
  margin: 0 0 18px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-strong);
}

.card__heading--spaced {
  margin-top: 30px;
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

/*******************************
            Form
*******************************/

.form-card {
  padding: 28px;
}

.field {
  margin-bottom: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.req {
  color: var(--brand-strong);
}

.optional {
  margin-left: 4px;
  font-weight: 400;
  color: var(--muted);
}

.field input,
.select select {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0 14px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #CDD1D6;
  border-radius: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder {
  color: #A2A8AF;
}

.field input:hover,
.select select:hover {
  border-color: #AEB4BB;
}

.field input:focus,
.select select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(225, 108, 62, 0.2);
}

.field__error {
  display: none;
  margin-top: 6px;
  font-size: 13px;
  color: var(--error);
}

.field.error input {
  border-color: var(--error);
  background: #FFF8F7;
}

.field.error input:focus {
  box-shadow: 0 0 0 3px rgba(194, 54, 43, 0.18);
}

.field.error .field__error {
  display: block;
}

.field__hint {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field.error .field__hint {
  display: none;
}

.select {
  position: relative;
}

.select select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  cursor: pointer;
}

.select::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}

/*******************************
            Toggles
*******************************/

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 0;
  cursor: pointer;
}

.toggle[hidden] {
  display: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle__switch {
  flex: none;
  position: relative;
  width: 40px;
  height: 24px;
  margin-top: 1px;
  border-radius: 12px;
  background: #CDD1D6;
  transition: background 0.15s ease;
}

.toggle__switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s ease;
}

.toggle input:checked + .toggle__switch {
  background: var(--brand);
}

.toggle input:checked + .toggle__switch::after {
  transform: translateX(16px);
}

.toggle input:focus-visible + .toggle__switch {
  box-shadow: 0 0 0 3px rgba(225, 108, 62, 0.3);
}

.toggle__text strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
}

.toggle__text small {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

/*******************************
            Preview
*******************************/

.preview {
  position: sticky;
  top: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.preview-card {
  overflow: hidden;
}

.mail__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: #FAFAF9;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.mail__live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--brand-strong);
}

.mail__live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px rgba(225, 108, 62, 0.2);
}

.mail__meta {
  padding: 4px 20px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--ink);
}

.mail__meta div {
  padding: 8px 0;
}

.mail__meta div + div {
  border-top: 1px solid #F0F1F3;
}

.mail__meta span {
  display: inline-block;
  width: 72px;
  color: var(--muted);
}

.mail__body {
  padding: 24px 20px 28px;
}

.mail__line {
  height: 10px;
  margin-bottom: 12px;
  border-radius: 5px;
  background: #EEF0F2;
}

.mail__signoff {
  margin: 22px 0 14px;
  font-size: 15px;
  color: var(--muted);
}

.signature-frame {
  position: relative;
  overflow-x: auto;
}

.signature-frame.is-scaled {
  overflow: hidden;
}

#signature-scale {
  width: max-content;
  transform-origin: 0 0;
}

/* Neutral styles: these are inherited by the copied signature, so keep them as they were */
#signature {
  color: #555555;
  line-height: normal;
  font-family: Arial, Helvetica, sans-serif;
}

/* Signature HTML kept rendered for html2canvas while the image version is shown */
#signature.offscreen {
  position: absolute;
  left: -10000px;
  top: 0;
}

#signature_img canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.preview-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: #FAFAF9;
  border-top: 1px solid var(--line);
}

.status {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

/*******************************
            Button
*******************************/

.button {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 22px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: #FFFFFF;
  background: var(--brand-strong);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.button:hover {
  background: #AE4A23;
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(225, 108, 62, 0.35);
}

.button.is-pending {
  color: var(--muted);
  background: #E6E8EB;
}

.button.is-pending:hover {
  background: #DADDE1;
}

.button.is-copied {
  background: var(--success);
}

/*******************************
            Help
*******************************/

.help summary {
  padding: 16px 20px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.help summary::-webkit-details-marker {
  display: none;
}

.help summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.help[open] summary::after {
  transform: rotate(-135deg);
}

.help summary:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px rgba(225, 108, 62, 0.3);
  border-radius: var(--radius);
}

.help__body {
  padding: 0 20px 18px;
  font-size: 15px;
}

.help__body h3 {
  margin: 8px 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--brand-strong);
}

.help__body ol {
  margin: 0 0 14px;
  padding-left: 20px;
  color: var(--muted);
}

.help__body li {
  margin-bottom: 4px;
}

.help__body b {
  color: var(--ink);
}

/*******************************
          Responsive
*******************************/

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .preview {
    position: static;
  }
}

@media (max-width: 520px) {
  .page {
    padding: 24px 16px 48px;
  }

  .site-header__inner {
    padding: 14px 16px;
  }

  .site-header__divider,
  .site-header__title {
    display: none;
  }

  .intro h1 {
    font-size: 26px;
  }

  .form-card {
    padding: 22px 18px;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .preview-card__footer {
    flex-direction: column;
    align-items: stretch;
  }
}
