:root {
  --ink: #171412;
  --muted: #675f58;
  --line: #d8d0c6;
  --paper: #fffdf7;
  --panel: #f5f1e8;
  --field: #ffffff;
  --teal: #006b5f;
  --teal-dark: #004c44;
  --red: #b73532;
  --gold: #c98f1a;
  --green: #477a43;
  --shadow: 0 24px 70px rgba(42, 34, 25, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(0, 107, 95, 0.12), transparent 30%),
    linear-gradient(315deg, rgba(183, 53, 50, 0.1), transparent 34%),
    #ede7db;
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", Verdana, sans-serif;
}

body {
  min-height: 100%;
  margin: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  align-items: center;
  background: rgba(255, 253, 247, 0.9);
  border: 1px solid rgba(23, 20, 18, 0.1);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(42, 34, 25, 0.08);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0 auto 18px;
  max-width: 1480px;
  padding: 12px;
  position: sticky;
  top: 12px;
  z-index: 10;
}

.brand {
  align-items: center;
  color: inherit;
  display: inline-flex;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--ink);
  border: 3px double var(--paper);
  color: var(--paper);
  display: inline-flex;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  height: 44px;
  justify-content: center;
  letter-spacing: 0;
  line-height: 1;
  width: 54px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  letter-spacing: 0;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.tool-nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tool-nav-item {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-size: 13px;
  padding: 9px 12px;
  text-decoration: none;
}

.tool-nav-item.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}

.tool-nav-item.muted {
  color: var(--muted);
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(360px, 0.9fr) minmax(440px, 1.1fr);
  margin: 0 auto;
  max-width: 1480px;
}

.control-panel,
.preview-panel {
  border: 1px solid rgba(23, 20, 18, 0.12);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  background: rgba(245, 241, 232, 0.96);
  padding: 18px;
}

.preview-panel {
  background: var(--paper);
  min-width: 0;
  padding: 18px;
}

.tool-heading {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  padding-bottom: 16px;
}

.eyebrow {
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: clamp(34px, 4vw, 58px);
  line-height: 0.96;
}

h2 {
  font-size: 28px;
}

.notice {
  background: #fff7dd;
  border: 1px solid rgba(201, 143, 26, 0.35);
  border-radius: 8px;
  color: #5f4311;
  line-height: 1.45;
  margin: 16px 0 0;
  padding: 12px;
}

.panel-block {
  background: rgba(255, 253, 247, 0.72);
  border: 1px solid rgba(23, 20, 18, 0.1);
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 14px;
}

.split-block {
  align-items: stretch;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 180px;
}

.block-title {
  align-items: baseline;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.block-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.block-title strong {
  color: var(--teal-dark);
  font-size: 13px;
  text-align: right;
}

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

.template-button {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 56px;
  padding: 10px;
  text-align: left;
}

.template-button:hover,
.template-button.active {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.template-button.active {
  background: #eaf6f1;
}

.template-button strong,
.template-button small {
  display: block;
}

.template-button strong {
  font-size: 14px;
}

.template-button small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.segmented {
  background: #ebe2d4;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
}

.seg-button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  padding: 10px;
}

.seg-button.active {
  background: var(--ink);
  color: var(--paper);
}

.completion-card {
  background: var(--ink);
  border-radius: 8px;
  color: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
  padding: 14px;
}

.completion-card span {
  font-size: 13px;
  font-weight: 700;
}

.meter {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.meter span {
  background: var(--gold);
  border-radius: inherit;
  display: block;
  height: 100%;
  width: 0;
}

.question-stage,
.full-form {
  margin-top: 14px;
}

.email-gate,
.ai-gate {
  background: #eef6f5;
  border: 1px solid rgba(0, 107, 95, 0.18);
  border-radius: 8px;
  margin-top: 14px;
  padding: 14px;
}

.ai-gate {
  background: #fffaf0;
  border-color: rgba(201, 143, 26, 0.26);
}

.lead-status {
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 800;
  min-height: 18px;
  margin: 8px 0 0;
}

.lead-status.error {
  color: var(--red);
}

.question-card {
  background: var(--paper);
  border: 1px solid rgba(23, 20, 18, 0.14);
  border-radius: 8px;
  padding: 16px;
}

.question-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  margin: 0 0 10px;
  text-transform: uppercase;
}

.field-label {
  display: block;
  font-weight: 800;
  margin-bottom: 8px;
}

.field-help {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: -2px 0 10px;
}

.input-field,
.select-field,
.text-field {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  outline: none;
  padding: 12px;
  width: 100%;
}

.text-field {
  min-height: 116px;
  resize: vertical;
}

.input-field:focus,
.select-field:focus,
.text-field:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 107, 95, 0.14);
}

.checkbox-row {
  align-items: flex-start;
  display: flex;
  gap: 10px;
  line-height: 1.4;
}

.checkbox-row input {
  margin-top: 3px;
}

.question-actions,
.actions,
.toolbar-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.question-actions {
  justify-content: space-between;
  margin-top: 16px;
}

.actions {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}

.primary-action,
.ghost-action {
  border-radius: 8px;
  font-weight: 800;
  min-height: 44px;
  padding: 11px 14px;
}

.primary-action {
  background: var(--teal);
  border: 1px solid var(--teal);
  color: #ffffff;
}

.primary-action:hover {
  background: var(--teal-dark);
}

.ghost-action {
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
}

.ghost-action:hover {
  border-color: var(--teal);
}

.ghost-action.small {
  min-height: 38px;
  padding: 8px 11px;
}

.full-form {
  display: grid;
  gap: 12px;
}

.full-section {
  background: var(--paper);
  border: 1px solid rgba(23, 20, 18, 0.14);
  border-radius: 8px;
  padding: 14px;
}

.full-section h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  margin: 0 0 12px;
}

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

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

.preview-toolbar {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 14px;
}

.missing-card {
  background: #fdf1ee;
  border: 1px solid rgba(183, 53, 50, 0.25);
  border-radius: 8px;
  color: #6e201e;
  margin-bottom: 14px;
  padding: 12px;
}

.missing-card.ready {
  background: #edf7ea;
  border-color: rgba(71, 122, 67, 0.28);
  color: #31572e;
}

.missing-card ul,
.next-steps ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.missing-card li,
.next-steps li {
  margin: 5px 0;
}

.letter-paper {
  background:
    linear-gradient(90deg, rgba(183, 53, 50, 0.12) 0 1px, transparent 1px 100%),
    linear-gradient(#ffffff 0 0);
  background-position: 42px 0, 0 0;
  border: 1px solid rgba(23, 20, 18, 0.16);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(42, 34, 25, 0.1);
  color: #1b1714;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.62;
  min-height: 680px;
  outline: none;
  padding: 28px 28px 28px 64px;
  overflow-wrap: anywhere;
  width: 100%;
}

.letter-paper:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 107, 95, 0.13), 0 18px 40px rgba(42, 34, 25, 0.1);
}

.rich-letter p,
.rich-letter ol,
.rich-letter ul {
  margin: 0 0 14px;
}

.rich-letter ol,
.rich-letter ul {
  padding-left: 24px;
}

.rich-letter li {
  margin: 0 0 9px;
}

.rich-letter .letter-date {
  text-align: right;
}

.rich-letter .letter-subject {
  font-weight: 700;
  text-decoration: underline;
}

.rich-letter .letter-section-title {
  font-weight: 700;
}

.rich-letter .signature-space {
  height: 42px;
}

.rich-letter .placeholder-note {
  color: var(--muted);
}

.next-steps {
  background: #f4f7f3;
  border: 1px solid rgba(71, 122, 67, 0.22);
  border-radius: 8px;
  color: #304f2d;
  margin-top: 14px;
  padding: 12px;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    order: 2;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    position: static;
  }

  .tool-nav {
    justify-content: flex-start;
  }

  .split-block,
  .template-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .preview-toolbar {
    flex-direction: column;
  }

  .letter-paper {
    font-size: 15px;
    min-height: 520px;
    padding: 20px;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .control-panel,
  .preview-toolbar,
  .missing-card,
  .next-steps {
    display: none !important;
  }

  .app-shell {
    padding: 0;
  }

  .workspace,
  .preview-panel {
    box-shadow: none;
    display: block;
    max-width: none;
    padding: 0;
  }

  .letter-paper {
    border: 0;
    box-shadow: none;
    min-height: auto;
    padding: 0;
  }
}
