/* Palette and layout carried over from the prototype. */
:root {
  --navy: #1B2A4A;
  --navy-light: #2E4272;
  --paper: #FAFAF8;
  --ink: #3D4451;
  --ink-strong: #22262E;
  --brass: #A67C3D;
  --line: #D8D9DB;
  --line-soft: #E8E9EB;
  --muted: #767E8C;
  --error: #B3402A;
  --ok: #2C6E49;
  --radius: 6px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 24px; }

/* ---------------------------------------------------------------- header -- */
.site-header { background: var(--navy); color: #fff; }
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding-top: 26px; padding-bottom: 26px;
}
.site-header h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: 0.2px; }
.site-header p { margin: 5px 0 0; font-size: 14px; color: #C7CEDD; max-width: 62ch; }
.header-jump {
  flex: none; color: #fff; text-decoration: none; font-size: 14px; font-weight: 600;
  border: 1px solid rgba(255,255,255,.45); border-radius: var(--radius); padding: 9px 20px;
}
.header-jump:hover { background: rgba(255,255,255,.12); }

/* ------------------------------------------------------------- explainer -- */
.explainer { background: #fff; border-bottom: 1px solid var(--line); }
.explainer-grid {
  display: grid; grid-template-columns: 1.15fr 1fr; gap: 40px;
  padding-top: 32px; padding-bottom: 32px;
}
.explainer h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.7px;
  color: var(--navy); margin: 0 0 10px;
}
.explainer p { margin: 0 0 10px; font-size: 14.5px; max-width: 66ch; }
.explainer p:last-child { margin-bottom: 0; }

.disclaimer {
  border-left: 3px solid var(--brass);
  background: #FCFAF6;
  padding: 14px 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.disclaimer p { font-size: 13.5px; }

/* ---------------------------------------------------------------- layout -- */
.layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 32px;
  padding-top: 32px; padding-bottom: 48px; align-items: start;
}

.form-panel {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px;
}

.form-panel h2 {
  font-size: 15px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--navy); margin: 30px 0 14px; padding-bottom: 8px;
  border-bottom: 2px solid var(--brass);
}
.form-panel h2:first-child { margin-top: 0; }

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

/* ----------------------------------------------------------------- form -- */
.field { margin-bottom: 15px; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  margin-bottom: 4px; color: var(--navy);
}
.field .opt { font-weight: 400; color: var(--muted); font-size: 12px; }
.field .hint {
  display: block; font-weight: 400; font-size: 12px;
  color: var(--muted); margin-top: 3px;
}

input[type="text"], input[type="email"], input[type="date"], select, textarea {
  width: 100%; padding: 9px 10px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 4px;
  font-family: inherit; color: var(--ink); background: var(--paper);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--navy-light); outline-offset: 1px;
}
textarea { resize: vertical; min-height: 54px; }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.span-2 { grid-column: 1 / -1; }

/* Grid and flex children default to min-width:auto, so a <select> with long
   option text (the origin criteria) would otherwise widen the whole column
   past the viewport. Let them shrink and clip instead. */
.layout > *, .row-2 > *, .row-3 > *, .party-fields > *, .field, .code-row > * {
  min-width: 0;
}
select, input, textarea { max-width: 100%; }

.party-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.party-fields .field { grid-column: 1 / -1; }
.party-fields .field.half { grid-column: auto; }

.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.checkbox-row input { width: auto; }
.checkbox-row label {
  margin: 0; font-weight: 600; font-size: 13px; color: var(--navy); cursor: pointer;
}

/* Collapsed by default; .open reveals. */
.collapsible { display: none; }
.collapsible.open { display: grid; }

.mode-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 6px 13px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--paper); color: var(--muted); cursor: pointer;
}
.chip input:checked + span {
  background: var(--navy); border-color: var(--navy); color: #fff;
}
.chip input:focus-visible + span { outline: 2px solid var(--navy-light); outline-offset: 2px; }

.error-text { color: var(--error); font-size: 12px; margin-top: 4px; display: none; }
.error-text.visible { display: block; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--error); }
.field.invalid .error-text { display: block; }

.note {
  font-size: 12.5px; color: var(--error); margin: 4px 0 12px;
  background: #FDF3F1; border-radius: 4px; padding: 8px 10px;
}

/* ---------------------------------------------------------------- goods -- */
.good {
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 14px 14px 2px; margin-bottom: 12px; background: #FDFDFC;
}
.good-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px;
}
.good-no {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--brass);
}
.link-danger {
  background: none; border: 0; color: var(--muted); font-size: 12px;
  cursor: pointer; padding: 0; text-decoration: underline;
}
.link-danger:hover { color: var(--error); }

/* --------------------------------------------------------------- buttons -- */
.btn-primary, .btn-secondary {
  width: 100%; padding: 12px; border-radius: 4px; font-size: 15px;
  font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-primary { background: var(--navy); color: #fff; border: none; }
.btn-primary:hover { background: var(--navy-light); }
.btn-secondary {
  background: #fff; color: var(--navy); border: 1px solid var(--line); margin-top: 8px;
}
.btn-secondary:hover { border-color: var(--navy-light); }

/* -------------------------------------------------------------- generate -- */
.generate-block {
  margin-top: 26px; border-top: 1px solid var(--line); padding-top: 20px;
}
.price-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 14px;
}
.price { font-size: 24px; font-weight: 700; color: var(--navy); line-height: 1.2; }
.price-note { font-size: 12px; color: var(--muted); max-width: 42ch; }
.price-row.paid .price { color: var(--muted); text-decoration: line-through; }

.badge {
  flex: none; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; padding: 5px 12px; border-radius: 999px;
}
.badge.locked { background: #F2EFE8; color: var(--brass); }
.badge.unlocked { background: #E7F1EA; color: var(--ok); }

.pay-panel {
  margin-top: 14px; padding: 14px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--paper);
}
.pay-panel p { margin: 0 0 10px; font-size: 13px; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
.code-row .btn-secondary { width: auto; margin-top: 0; padding: 9px 18px; font-size: 14px; }

.status {
  margin-top: 12px; font-size: 13px; padding: 9px 11px; border-radius: 4px;
  background: #F1F3F6; color: var(--navy);
}
.status.error { background: #FDF3F1; color: var(--error); }
.status.ok { background: #E7F1EA; color: var(--ok); }

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

/* --------------------------------------------------------------- preview -- */
.preview-wrap { position: sticky; top: 24px; align-self: start; }
.preview-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--muted); margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: 0.6px;
}
.preview-meta { text-transform: none; letter-spacing: 0; }

.sheet {
  background: #fff; border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(27, 42, 74, 0.08);
  padding: 30px 28px; color: var(--ink-strong);
  font-size: 12px; min-height: 520px;
  max-height: calc(100vh - 90px); overflow-y: auto;
}

.pv-head { border-bottom: 1px solid var(--brass); padding-bottom: 8px; margin-bottom: 14px; }
.pv-letterhead {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 9px; font-weight: 700; letter-spacing: 0.7px;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 2px solid var(--navy); padding-bottom: 5px; margin-bottom: 12px;
}
.pv-letterhead span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-letterhead span:last-child { flex: none; }
.sheet h3 {
  margin: 0; font-size: 19px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--navy);
}
.pv-sub { margin: 3px 0 0; font-size: 10px; color: var(--muted); }

.pv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.pv-box {
  border: 1px solid var(--line); padding: 8px 9px; min-height: 62px; background: #fff;
}
.pv-box.wide { grid-column: 1 / -1; }
.pv-label {
  font-size: 8px; font-weight: 700; letter-spacing: 0.7px; text-transform: uppercase;
  color: var(--brass); margin-bottom: 5px;
}
.pv-box .strong { font-weight: 700; color: var(--ink-strong); }
.pv-box .big { font-size: 14px; }
.pv-box .muted { color: var(--muted); font-size: 10.5px; }
.pv-box .italic { font-style: italic; }
.pv-box .small { font-size: 10.5px; }

.pv-section {
  font-size: 8.5px; font-weight: 700; letter-spacing: 0.9px; text-transform: uppercase;
  color: var(--brass); border-bottom: 1px solid var(--line-soft);
  padding-bottom: 3px; margin: 14px 0 8px;
}

.pv-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.pv-table th {
  background: #F5F6F8; border: 1px solid var(--line);
  font-size: 7.5px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--brass); text-align: left; padding: 5px 6px; vertical-align: top;
}
.pv-table td {
  border: 1px solid var(--line); padding: 5px 6px;
  font-size: 10.5px; vertical-align: top; word-break: break-word;
}
.pv-table .center { text-align: center; }
.pv-table .strong { font-weight: 700; }
.pv-table .muted { color: var(--muted); }
.pv-table .italic { font-style: italic; }

.pv-statement {
  border: 1px solid var(--line); border-left: 3px solid var(--brass);
  background: #F5F6F8; padding: 9px 11px; margin: 10px 0;
}
.pv-statement p { margin: 0; font-size: 10.5px; line-height: 1.5; }

.pv-grid.sig { grid-template-columns: 2fr 1fr; }
.pv-sig {
  font-size: 17px; font-style: italic; color: var(--navy);
  min-height: 26px; padding-left: 4px;
}
.pv-sigline { border-top: 1px solid var(--ink-strong); margin: 4px 0 6px; }

.pv-foot {
  margin-top: 14px; padding-top: 7px; border-top: 1px solid var(--line-soft);
  font-size: 8.5px; color: var(--muted);
}

/* ---------------------------------------------------------------- footer -- */
.site-footer {
  border-top: 1px solid var(--line); background: #fff;
  padding: 22px 0; font-size: 12.5px; color: var(--muted);
}
.site-footer p { margin: 0 0 6px; max-width: 90ch; }
.site-footer a { color: var(--navy); }

/* ------------------------------------------------------------ responsive -- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .explainer-grid { grid-template-columns: 1fr; gap: 24px; }
  /* On a phone the preview belongs under the form, not pinned beside it. */
  .preview-wrap { position: static; max-height: none; }
  .sheet { max-height: none; }
}

@media (max-width: 620px) {
  .wrap { padding: 0 16px; }
  .header-inner { flex-direction: column; align-items: flex-start; gap: 14px; }
  .header-jump { width: 100%; text-align: center; }
  .form-panel { padding: 18px 16px; }
  .row-2, .row-3, .party-fields { grid-template-columns: 1fr; }
  .party-fields .field.half { grid-column: 1 / -1; }
  .pv-grid, .pv-grid.sig { grid-template-columns: 1fr; }
  .sheet { padding: 20px 16px; }
  .price-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  /* Tables cannot shrink indefinitely - let this one scroll on its own. */
  .pv-table { display: block; overflow-x: auto; white-space: nowrap; }
  .pv-table td, .pv-table th { white-space: normal; min-width: 90px; }
  .code-row { flex-direction: column; }
  .code-row .btn-secondary { width: 100%; }
  /* Comfortable tap targets. */
  input[type="text"], input[type="email"], input[type="date"], select, textarea {
    font-size: 16px;   /* stops iOS zooming on focus */
    padding: 11px 12px;
  }
  .btn-primary, .btn-secondary { padding: 14px; }
}
