:root {
  --paper: #ffffff;
  --paper-alt: #f3f3f0;
  --ink: #0d0d0d;
  --muted: #55554e;
  --line: #1a1a1a;
  --line-soft: #c9c8c0;
  --accent: #7a1414;
  --accent-soft: #f4e7e5;
  --focus-ring: #0d0d0d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141412;
    --paper-alt: #1c1c19;
    --ink: #efeee7;
    --muted: #b3b1a4;
    --line: #e6e4d9;
    --line-soft: #47463d;
    --accent: #e2685c;
    --accent-soft: #2c1917;
    --focus-ring: #efeee7;
  }
}
:root[data-theme="dark"] {
  --paper: #141412;
  --paper-alt: #1c1c19;
  --ink: #efeee7;
  --muted: #b3b1a4;
  --line: #e6e4d9;
  --line-soft: #47463d;
  --accent: #e2685c;
  --accent-soft: #2c1917;
  --focus-ring: #efeee7;
}
:root[data-theme="light"] {
  --paper: #ffffff;
  --paper-alt: #f3f3f0;
  --ink: #0d0d0d;
  --muted: #55554e;
  --line: #1a1a1a;
  --line-soft: #c9c8c0;
  --accent: #7a1414;
  --accent-soft: #f4e7e5;
  --focus-ring: #0d0d0d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper-alt);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.45;
  padding: 40px 16px 64px;
  -webkit-font-smoothing: antialiased;
}

.sheet {
  max-width: 760px;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px var(--paper-alt), 0 8px 24px rgba(0, 0, 0, 0.08);
}

/* ---------- Header band ---------- */
.letterhead {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 28px 32px 22px;
  border-bottom: 3px solid var(--line);
}

.seal {
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  padding: 5px;
  background: repeating-conic-gradient(var(--ink) 0deg 6deg, transparent 6deg 18deg);
}
.seal-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--ink);
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.05;
}
.seal-inner .rule {
  width: 20px;
  height: 1px;
  background: var(--ink);
  margin: 3px auto;
}
.seal-inner .mono {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
}
.seal-inner .est {
  font-size: 7px;
  letter-spacing: 1.2px;
  color: var(--muted);
  text-transform: uppercase;
}

.letterhead-text { flex: 1; min-width: 0; }

.agency-line {
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 4px;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 4px;
  text-wrap: balance;
}

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

.doc-control {
  flex: none;
  text-align: right;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}
.doc-control strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
}

/* ---------- Notice strip ---------- */
.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 14px 32px;
  background: var(--paper-alt);
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
  color: var(--muted);
}
.notice b { color: var(--ink); }

/* ---------- Form body ---------- */
form { padding: 8px 32px 32px; }

.section {
  padding: 22px 0;
  border-bottom: 1px solid var(--line-soft);
}
.section:last-of-type { border-bottom: none; }

.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 16px;
}
.section-title .num {
  font-size: 13px;
  border: 1px solid var(--ink);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  flex: none;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 20px;
}
.field.full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; }

label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--ink);
}
label .req { color: var(--accent); margin-left: 2px; }

.hint {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: -2px;
}

input:not([type="radio"]):not([type="checkbox"]), select {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 12px;
  width: 100%;
  min-height: 46px;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:not([type="radio"]):not([type="checkbox"])::placeholder { color: var(--line-soft); }
input:not([type="radio"]):not([type="checkbox"]):hover { border-color: var(--ink); }
input:not([type="radio"]):not([type="checkbox"]):focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="radio"], input[type="checkbox"] {
  appearance: auto;
  -webkit-appearance: auto;
  accent-color: var(--ink);
  margin: 0;
}

.amount-wrap {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
}
.amount-wrap .currency {
  display: grid;
  place-items: center;
  padding: 0 12px;
  background: var(--paper-alt);
  border-right: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
}
.amount-wrap input {
  border: none;
}
.amount-wrap:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

input:invalid.touched, .field.error input {
  border-color: var(--accent);
}
.error-msg {
  font-size: 12.5px;
  color: var(--accent);
  min-height: 15px;
  margin-top: -2px;
}

.certify {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 14px;
  color: var(--muted);
  padding-top: 6px;
}
.certify input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--ink); flex: none; }
.certify label { text-transform: none; font-weight: 400; letter-spacing: 0; color: var(--ink); cursor: pointer; }

/* ---------- Actions ---------- */
.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-top: 26px;
  flex-wrap: wrap;
}

.ref-preview {
  font-size: 12px;
  color: var(--muted);
}

.form-error {
  display: none;
  font-size: 13.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  padding: 12px 14px;
  margin-top: 20px;
}
.form-error.show { display: block; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--ink);
  padding: 14px 28px;
  min-height: 48px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  transition: opacity 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:hover { opacity: 0.85; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button[disabled] { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  background: var(--paper);
  color: var(--ink);
}

.footnote {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 16px 32px 0;
}

/* ---------- Confirmation ---------- */
.confirm {
  display: none;
  padding: 40px 32px 34px;
}
.confirm.show { display: block; }
form.hidden { display: none; }

.stamp {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--accent);
  color: var(--accent);
  padding: 6px 14px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-size: 13px;
  transform: rotate(-2deg);
}

.confirm h2 {
  font-size: 22px;
  margin: 18px 0 6px;
}
.confirm p.lead { color: var(--muted); font-size: 20px; margin: 0 0 22px; }

dl.summary {
  display: grid;
  grid-template-columns: 160px 1fr;
  row-gap: 12px;
  column-gap: 16px;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  padding: 18px 0;
  margin: 0 0 24px;
  font-size: 14px;
}
dl.summary dt { color: var(--muted); font-weight: 700; }
dl.summary dd { margin: 0; }

.confirm .actions { justify-content: flex-start; }

@media print {
  body { background: #fff; padding: 0; }
  .sheet { border: none; box-shadow: none; max-width: 100%; }
  .actions, .notice { display: none !important; }
}

@media (max-width: 640px) {
  body { padding: 0 0 40px; }
  .sheet { border-left: none; border-right: none; box-shadow: none; }
  .letterhead { padding: 22px 20px 18px; flex-wrap: wrap; }
  .doc-control { text-align: left; }
  .notice { padding: 12px 20px; }
  form { padding: 4px 20px 28px; }
  .footnote { padding: 16px 20px 0; }
  .confirm { padding: 32px 20px 28px; }
  h1 { font-size: 22px; }
  .grid { grid-template-columns: 1fr; }
  .actions { flex-direction: column-reverse; align-items: stretch; }
  .actions button { width: 100%; }
  .ref-preview { text-align: center; }
  dl.summary { grid-template-columns: 130px 1fr; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
