/* Forager — the house style of a tool for paperwork.
 *
 * A document, not a dashboard. Off-white ground, one ink, one accent for the
 * thing to press, hairline rules, tabular figures. System fonts only: this
 * page ships with `style-src 'self'` and no external origin is admitted for a
 * typeface. Nothing is set below 12px.
 *
 * THE TYPOGRAPHIC LAW, borrowed from A.P.E.S.: if a machine cares about it, it
 * is mono — case numbers, dates, amounts, filenames. If a human wrote it, it is
 * sans. The letter itself is the one exception: it is serif, because it is a
 * letter, and it prints that way.
 *
 * Three theme states are wired: the full palette on bare :root, the dark
 * overrides under prefers-color-scheme guarded so an explicit light choice
 * still wins, and the same overrides again under [data-theme="dark"]. No
 * colour is ever defined only inside a media query. The printed letter ignores
 * all of it and is black on white.
 */

:root {
  color-scheme: light dark;

  --fg-paper: #f6f4ee;
  --fg-paper-2: #ebe7dc;
  --fg-ink: #1c1b18; /* 15.6:1 on paper */
  --fg-ink-2: #5b564c; /* 6.7:1 */
  --fg-accent: #2e6b46; /* the one thing to press; 5.6:1 */
  --fg-link: #1f5f5c; /* 6.4:1 */
  --fg-error: #a8320f; /* 5.8:1 */
  --fg-rule: #7a7364; /* 4.5:1 — bounds a control */
  --fg-hairline: #cfc9b8;
  --fg-on-accent: #f6f4ee;

  --fg-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fg-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --fg-serif: Georgia, "Times New Roman", Times, serif;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  --fg-measure: 38rem;
  --fg-measure-wide: 60rem;
  --fg-radius: 3px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fg-paper: #191815;
    --fg-paper-2: #24221d;
    --fg-ink: #efeadb;
    --fg-ink-2: #b1a996;
    --fg-accent: #6cc294;
    --fg-link: #6fc4bd;
    --fg-error: #ff8a5c;
    --fg-rule: #8b8474;
    --fg-hairline: #3a372f;
    --fg-on-accent: #191815;
  }
}

:root[data-theme="dark"] {
  --fg-paper: #191815;
  --fg-paper-2: #24221d;
  --fg-ink: #efeadb;
  --fg-ink-2: #b1a996;
  --fg-accent: #6cc294;
  --fg-link: #6fc4bd;
  --fg-error: #ff8a5c;
  --fg-rule: #8b8474;
  --fg-hairline: #3a372f;
  --fg-on-accent: #191815;
}

/* --- Reset ---------------------------------------------------------------- */

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  font-variant-numeric: tabular-nums;
}

body {
  margin: 0;
  background-color: var(--fg-paper);
  color: var(--fg-ink);
  font-family: var(--fg-sans);
  font-size: 16px;
  line-height: 1.55;
}

img {
  max-width: 100%;
  height: auto;
}

/* --- Layout --------------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--fg-hairline);
}

.wordmark {
  margin: 0;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.wordmark a {
  color: inherit;
  text-decoration: none;
}

.nav {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
  font-size: 14px;
}

.nav-form {
  margin: 0;
}

.sheet {
  max-width: var(--fg-measure);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-4) var(--sp-8);
}

.sheet--wide {
  max-width: var(--fg-measure-wide);
}

.colophon {
  max-width: var(--fg-measure-wide);
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--fg-hairline);
  font-size: 12px;
  line-height: 1.6;
  color: var(--fg-ink-2);
}

.colophon p {
  margin: 0;
  max-width: none;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}

.titlebar h1 {
  margin: 0;
}

.subnav {
  font-size: 14px;
  color: var(--fg-ink-2);
  margin: var(--sp-4) 0 var(--sp-5);
}

/* --- Type ----------------------------------------------------------------- */

h1 {
  font-size: clamp(24px, 5vw, 32px);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 var(--sp-4);
  overflow-wrap: anywhere;
}

h2 {
  font-size: clamp(18px, 4vw, 21px);
  font-weight: 700;
  margin: var(--sp-6) 0 var(--sp-3);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--fg-hairline);
}

p {
  margin: 0 0 var(--sp-4);
  max-width: 66ch;
}

a {
  color: var(--fg-link);
  text-underline-offset: 0.2em;
}

.lede {
  font-size: 18px;
}

.fine {
  font-size: 13px;
  line-height: 1.6;
  color: var(--fg-ink-2);
}

.block-header {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-ink-2);
  margin: 0 0 var(--sp-2);
}

.data {
  font-family: var(--fg-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--fg-ink-2);
}

/* --- Focus ---------------------------------------------------------------- */

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.file-btn:focus-within {
  outline: 3px solid var(--fg-accent);
  outline-offset: 2px;
}

/* --- Forms ---------------------------------------------------------------- */

.field {
  display: block;
  margin-bottom: var(--sp-4);
  min-width: 0;
}

.field > .label,
.label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-ink-2);
  margin-bottom: var(--sp-2);
}

.hint {
  font-size: 13px;
  color: var(--fg-ink-2);
  margin: var(--sp-2) 0 0;
}

.error {
  font-size: 13px;
  color: var(--fg-error);
  font-weight: 600;
  margin: var(--sp-2) 0 0;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--fg-sans);
  font-size: 16px; /* never smaller: iOS zooms the page on focus below 16px */
  color: var(--fg-ink);
  background-color: var(--fg-paper-2);
  border: 2px solid var(--fg-rule);
  border-radius: var(--fg-radius);
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.field--error input,
.field--error select,
.field--error textarea {
  border-color: var(--fg-error);
}

input::placeholder {
  color: var(--fg-ink-2);
  opacity: 1;
}

.code-input {
  font-family: var(--fg-mono);
  font-weight: 700;
  font-size: clamp(24px, 9vw, 34px);
  letter-spacing: 0.14em;
  text-align: center;
  min-height: 56px;
  max-width: 14rem;
}

fieldset.group {
  border: 1px solid var(--fg-hairline);
  border-radius: var(--fg-radius);
  padding: var(--sp-4) var(--sp-4) var(--sp-1);
  margin: 0 0 var(--sp-5);
  min-width: 0;
}

fieldset.group > legend {
  font-weight: 700;
  padding: 0 var(--sp-2);
}

fieldset.group > .hint {
  margin: 0 0 var(--sp-4);
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 var(--sp-5);
}

@media (min-width: 640px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }
  .field--wide {
    grid-column: 1 / -1;
  }
}

.inline-form {
  display: flex;
  align-items: end;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin: 0 0 var(--sp-3);
}

.inline-form .label {
  flex-basis: 100%;
  margin-bottom: 0;
}

.inline-form input[type="text"] {
  flex: 1 1 12rem;
  min-height: 40px;
}

input:read-only:not([type="hidden"]),
textarea:read-only {
  background-color: transparent;
  border-color: var(--fg-hairline);
  color: var(--fg-ink-2);
}

form[aria-busy="true"] {
  cursor: progress;
}

/* --- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-5);
  font-family: var(--fg-sans);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  cursor: pointer;
  border: 2px solid var(--fg-accent);
  border-radius: var(--fg-radius);
  background-color: var(--fg-accent);
  color: var(--fg-on-accent);
  transition: background-color 120ms ease, border-color 120ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
}

.btn:hover {
  background-color: color-mix(in srgb, var(--fg-accent) 85%, var(--fg-ink));
  border-color: color-mix(in srgb, var(--fg-accent) 85%, var(--fg-ink));
}

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

.btn--quiet {
  background-color: transparent;
  color: var(--fg-ink);
  border-color: var(--fg-rule);
}

.btn--quiet:hover {
  background-color: var(--fg-paper-2);
  border-color: var(--fg-rule);
}

.btn--small {
  min-height: 36px;
  padding: var(--sp-1) var(--sp-3);
  font-size: 13px;
}

.btn--danger {
  color: var(--fg-error);
}

.btn.is-busy {
  opacity: 0.7;
  cursor: progress;
}

.linklike {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--fg-link);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

/* A file input dressed as a button. The real input stays in the tree and
 * focusable; the label is what a person sees and presses. */
.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* --- Notices -------------------------------------------------------------- */

.notice {
  border-left: 4px solid var(--fg-rule);
  background-color: var(--fg-paper-2);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-5);
  border-radius: var(--fg-radius);
}

.notice--error {
  border-left-color: var(--fg-error);
}

.notice > .notice-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-ink-2);
  margin-bottom: var(--sp-1);
}

/* --- Status --------------------------------------------------------------- */

.status {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 2px var(--sp-2);
  border: 1px solid var(--fg-rule);
  border-radius: var(--fg-radius);
  color: var(--fg-ink-2);
  vertical-align: middle;
}

.status--sent {
  border-color: var(--fg-link);
  color: var(--fg-link);
}

.status--resolved {
  border-color: var(--fg-accent);
  color: var(--fg-accent);
}

/* --- Records -------------------------------------------------------------- */

.record {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.record th,
.record td {
  text-align: left;
  padding: var(--sp-3) var(--sp-2);
  border-bottom: 1px solid var(--fg-hairline);
  vertical-align: top;
}

.record th {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-ink-2);
}

.scroller {
  overflow-x: auto;
}

/* --- Cards ---------------------------------------------------------------- */

.cards {
  list-style: none;
  padding: 0;
  margin: 0;
}

.card {
  border: 1px solid var(--fg-hairline);
  border-radius: var(--fg-radius);
  padding: var(--sp-4) var(--sp-5);
  margin-bottom: var(--sp-4);
}

.card h2 {
  margin-top: 0;
  border: 0;
  padding: 0;
}

/* --- Evidence ------------------------------------------------------------- */

.evidence {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--sp-5);
}

.evidence-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: var(--sp-4);
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--fg-hairline);
}

.evidence-thumb {
  display: block;
  border: 1px solid var(--fg-hairline);
  border-radius: var(--fg-radius);
  background-color: var(--fg-paper-2);
  overflow: hidden;
  aspect-ratio: 9 / 16;
}

.evidence-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.evidence-body {
  min-width: 0;
}

.evidence-controls {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
  align-items: center;
}

.upload {
  border: 1px dashed var(--fg-rule);
  border-radius: var(--fg-radius);
  padding: var(--sp-4);
}

/* --- The letter ----------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}

.paper {
  background-color: #fff;
  color: #000;
  padding: 1in 1in;
  box-shadow: 0 1px 4px rgb(0 0 0 / 15%);
  border: 1px solid var(--fg-hairline);
}

@media (max-width: 720px) {
  .paper {
    padding: var(--sp-5);
  }
}

.letter,
.letter-exhibit {
  font-family: var(--fg-serif);
  font-size: 12pt;
  line-height: 1.45;
  color: #000;
}

.letter p,
.letter li {
  max-width: none;
  color: #000;
}

.letter h2,
.letter-exhibit h2 {
  font-family: var(--fg-serif);
  font-size: 13pt;
  color: #000;
  border: 0;
  padding: 0;
  margin: 1.2em 0 0.5em;
}

.letter-head p {
  margin-bottom: 1em;
}

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

.letter-ref {
  font-family: var(--fg-mono);
  font-size: 10pt;
  font-weight: 400;
}

.letter-signature {
  margin-top: 2.5em;
}

.letter-exhibit {
  margin-top: 2em;
  padding-top: 2em;
  border-top: 1px solid #ccc;
}

.letter-exhibit figure {
  margin: 0;
  border: 1px solid #999;
  padding: var(--sp-3);
  text-align: center;
}

.letter-exhibit img {
  max-height: 8in;
  width: auto;
}

.letter-exhibit figcaption {
  margin-top: var(--sp-2);
  font-size: 10pt;
  color: #333;
}

.letter-exhibit-missing {
  padding: var(--sp-8) 0;
  color: #666;
}

/* --- Print ---------------------------------------------------------------- */

@media print {
  body {
    background: #fff;
    color: #000;
    font-size: 12pt;
  }
  .masthead,
  .colophon,
  .toolbar,
  .nav {
    display: none !important;
  }
  .sheet,
  .sheet--wide {
    max-width: none;
    padding: 0;
    margin: 0;
  }
  .paper {
    padding: 0;
    border: 0;
    box-shadow: none;
  }
  .letter-exhibit {
    break-before: page;
    page-break-before: always;
    border: 0;
    margin: 0;
    padding: 0;
  }
  .letter-exhibit img {
    max-height: 8.5in;
  }
  a {
    color: #000;
    text-decoration: none;
  }
}

/* --- Utility -------------------------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (forced-colors: active) {
  .btn,
  input,
  select,
  textarea,
  .status {
    border: 2px solid;
  }
}
