/* ===== Signature/initials fonts (vendored at public/fonts/, Part A/A7) =====
   Family names are our own choice — they don't need to match each font's
   internal name metadata, only the url() target needs to match the
   vendored filename exactly. The two names with spaces are quoted; no
   renaming or percent-encoding needed. */
@font-face {
  font-family: "SigTheSignature";
  src: url("../fonts/Thesignature.otf") format("opentype");
  font-display: swap;
}
@font-face {
  font-family: "SigMalvides";
  src: url("../fonts/Malvides.otf") format("opentype");
  font-display: swap;
}
@font-face {
  font-family: "SigGratefulMemories";
  src: url("../fonts/Grateful Memories.otf") format("opentype");
  font-display: swap;
}
@font-face {
  font-family: "SigFallinForYou";
  src: url("../fonts/Fallin For You Script.otf") format("opentype");
  font-display: swap;
}

/* ===== Design tokens ===== */
:root {
  --color-ink: #1b1b18;
  --color-ink-soft: #55534a;
  --color-paper: #eae6da;
  --color-paper-card: #faf8f2;
  --color-rule: #d6d0bd;
  --color-accent: #2b4636;
  --color-accent-strong: #1e3327;
  --color-accent-ink: #f6f4ec;
  --color-brass: #8a6a2f;
  --color-brass-bg: #eadfc2;
  --color-alert: #7c2f22;
  --color-alert-bg: #f1ded7;
  --color-success-bg: #e1e8db;

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;

  --radius: 3px;
  --shadow-sheet: 0 1px 2px rgba(27, 27, 24, 0.06), 0 12px 32px rgba(27, 27, 24, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-ink: #eeece3;
    --color-ink-soft: #b9b6a9;
    --color-paper: #1b1b18;
    --color-paper-card: #232320;
    --color-rule: #3a3933;
    --color-accent: #7fae94;
    --color-accent-strong: #9cc6ad;
    --color-accent-ink: #10201a;
    --color-brass: #d8b866;
    --color-brass-bg: #362c17;
    --color-alert: #e2a394;
    --color-alert-bg: #3a1f19;
    --color-success-bg: #1c2a20;
    --shadow-sheet: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --color-ink: #eeece3;
  --color-ink-soft: #b9b6a9;
  --color-paper: #1b1b18;
  --color-paper-card: #232320;
  --color-rule: #3a3933;
  --color-accent: #7fae94;
  --color-accent-strong: #9cc6ad;
  --color-accent-ink: #10201a;
  --color-brass: #d8b866;
  --color-brass-bg: #362c17;
  --color-alert: #e2a394;
  --color-alert-bg: #3a1f19;
  --color-success-bg: #1c2a20;
  --shadow-sheet: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.5);
}
:root[data-theme="light"] {
  --color-ink: #1b1b18;
  --color-ink-soft: #55534a;
  --color-paper: #eae6da;
  --color-paper-card: #faf8f2;
  --color-rule: #d6d0bd;
  --color-accent: #2b4636;
  --color-accent-strong: #1e3327;
  --color-accent-ink: #f6f4ec;
  --color-brass: #8a6a2f;
  --color-brass-bg: #eadfc2;
  --color-alert: #7c2f22;
  --color-alert-bg: #f1ded7;
  --color-success-bg: #e1e8db;
  --shadow-sheet: 0 1px 2px rgba(27, 27, 24, 0.06), 0 12px 32px rgba(27, 27, 24, 0.12);
}

/* ===== Reset & base ===== */
* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  padding: 0;
}
body {
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
a {
  color: var(--color-accent);
}

/* ===== Page shell ===== */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
}

.letterhead {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 4px 16px;
  border-bottom: 2px solid var(--color-ink);
  margin-bottom: 20px;
}
.letterhead__name {
  font-family: var(--font-display);
  font-size: 1.5rem;
  letter-spacing: 0.02em;
}
.letterhead__tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
}

.sheet {
  width: 100%;
  max-width: 640px;
  background: var(--color-paper-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sheet);
  padding: 28px 24px 32px;
}
@media (min-width: 480px) {
  .sheet {
    padding: 40px 44px 44px;
  }
}

.page-footer {
  width: 100%;
  max-width: 640px;
  margin-top: 20px;
  font-size: 0.8rem;
  color: var(--color-ink-soft);
  text-align: center;
}
.page-footer p {
  margin: 0;
}

.loading {
  color: var(--color-ink-soft);
}

/* ===== Eyebrow / section divider ===== */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-brass);
  margin: 0 0 10px;
}
.section-divider {
  border: none;
  border-top: 1px solid var(--color-rule);
  margin: 28px 0 20px;
}

/* ===== Identity block ===== */
.identity h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  margin: 0 0 4px;
}
.identity p {
  margin: 0 0 2px;
  color: var(--color-ink-soft);
}
.identity .role-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent);
  background: var(--color-success-bg);
  padding: 3px 8px;
  border-radius: var(--radius);
  margin-top: 6px;
}

/* ===== State banners (error / cancelled / already-signed / done) ===== */
.banner {
  padding: 18px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--color-rule);
}
.banner h1 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin: 0 0 8px;
}
.banner p {
  margin: 0;
  color: var(--color-ink-soft);
}
.banner--alert {
  background: var(--color-alert-bg);
  border-color: var(--color-alert);
}
.banner--alert h1 {
  color: var(--color-alert);
}
.banner--success {
  background: var(--color-success-bg);
  border-color: var(--color-accent);
}
.banner--success h1 {
  color: var(--color-accent-strong);
}

/* ===== Documents list ===== */
.documents {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.documents a {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.9rem;
  color: var(--color-ink);
  background: var(--color-paper);
}
.documents a:hover,
.documents a:focus-visible {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.documents a::after {
  content: " ↗";
}

/* ===== Checklist ledger ===== */
.checklist {
  border-top: 1px solid var(--color-rule);
}
.checklist-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-rule);
}
.checklist-row__text {
  flex: 1;
  min-width: 0;
}
.checklist-row__label {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
  margin: 0 0 2px;
}
.checklist-row__value {
  margin: 0;
  font-size: 0.98rem;
  overflow-wrap: break-word;
}

.initial-target {
  flex-shrink: 0;
  width: 60px;
  height: 44px;
  border: 1.5px dashed var(--color-brass);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
}
.initial-target:hover,
.initial-target:focus-visible {
  background: var(--color-brass-bg);
}
.initial-target:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}
.initial-target__hint {
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-brass);
}
.initial-target img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.initial-target--stamped {
  border-style: solid;
  cursor: default;
  animation: stamp-in 260ms ease-out;
}

@keyframes stamp-in {
  0% { transform: scale(1.5); opacity: 0; }
  60% { transform: scale(0.92); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .initial-target--stamped {
    animation: none;
  }
}

.apply-all {
  margin: 14px 0 4px;
  display: flex;
  justify-content: flex-end;
}
.apply-all[hidden] {
  /* .apply-all's own `display: flex` above has the same specificity as
     the UA stylesheet's `[hidden] { display: none }` and, being an
     author rule, would otherwise win the tie — silently showing the
     "apply to all" link before any row has been initialled. */
  display: none;
}

/* ===== TDS date fields (agency only) ===== */
.tds-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 6px;
}
@media (min-width: 480px) {
  .tds-fields {
    grid-template-columns: 1fr 1fr;
  }
}
.field label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
  margin-bottom: 4px;
}
.field input[type="date"] {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
  background: var(--color-paper);
  color: var(--color-ink);
}
.field input[type="date"]:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* ===== Mark capture (signature / initials) ===== */
.mark-capture {
  margin-top: 6px;
}
.mark-capture--attention {
  outline: 2px solid var(--color-alert);
  outline-offset: 6px;
  border-radius: var(--radius);
}
.style-card[aria-checked="true"] {
  border-color: var(--color-brass);
  box-shadow: inset 0 0 0 1px var(--color-brass);
  background: var(--color-brass-bg);
}
.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.mode-toggle button {
  border: none;
  background: var(--color-paper);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 0.85rem;
}
.mode-toggle button[aria-pressed="true"] {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}
.mode-toggle button:not(:last-child) {
  border-right: 1px solid var(--color-rule);
}

.style-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.style-card {
  border: 1.5px solid var(--color-rule);
  border-radius: var(--radius);
  background: var(--color-paper);
  padding: 10px 6px;
  cursor: pointer;
  text-align: center;
  overflow: hidden;
}
.style-card__signature {
  display: block;
  font-size: 1.7rem;
  line-height: 1.2;
  color: var(--color-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.style-card__initials {
  display: block;
  font-size: 1.3rem;
  color: var(--color-ink);
}
.style-card__label {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
}
.style-card:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.draw-pad-wrap {
  /* Always white, regardless of theme — signature_pad draws dark ink
     strokes onto it, same as a real paper signature strip. */
  border: 1.5px dashed var(--color-rule);
  border-radius: var(--radius);
  background: #ffffff;
  touch-action: none;
}
.draw-pad-wrap canvas {
  display: block;
  width: 100%;
  height: 160px;
}
.draw-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.85rem;
}
.link-button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-accent-strong);
}
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-secondary {
  background: transparent;
  border-color: var(--color-rule);
  color: var(--color-ink);
}
.btn-secondary:hover {
  border-color: var(--color-brass);
}
.btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.submit-row {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.submit-hint {
  font-size: 0.82rem;
  color: var(--color-ink-soft);
  margin: 0;
}
.error-inline {
  color: var(--color-alert);
  font-size: 0.88rem;
  margin: 4px 0 0;
}

.note {
  font-size: 0.88rem;
  color: var(--color-ink-soft);
  background: var(--color-paper);
  border-left: 3px solid var(--color-brass);
  padding: 10px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 18px 0;
}
