html{color-scheme:light dark}
/* Layout: working form on the left, live paper preview on the right; one pane at a time on phones. */
:root {
  --bg: #f1eef5;
  --surface: #ffffff;
  --fg: #251b2f;
  --muted: #6a5f76;
  --line: #dbd3e3;
  --accent: #5b2a86;
  --accent-fg: #ffffff;
  --brass: #9a7410;
  --danger: #a3362c;
  --ok: #2f7a3e;
  --field: #f8f6fa;
  --paper: #ffffff;
  --paper-fg: #251b2f;
  --paper-muted: #6a5f76;
  --paper-line: #ddd5e4;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151019; --surface: #1e1726; --fg: #eee8f3; --muted: #a698b3; --line: #35293f;
    --accent: #b88cf0; --accent-fg: #1a0f26; --brass: #e2bb4c; --danger: #ef8a7e; --ok: #7fd18f; --field: #261d30;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151019; --surface: #1e1726; --fg: #eee8f3; --muted: #a698b3; --line: #35293f;
  --accent: #b88cf0; --accent-fg: #1a0f26; --brass: #e2bb4c; --danger: #ef8a7e; --ok: #7fd18f; --field: #261d30;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  padding-block: 20px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap { max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img { width: 64px; height: auto; flex: none; }
.brand .site { font-family: var(--font-mono); font-size: 12px; color: var(--brass); letter-spacing: .04em; margin: 0 0 2px; }
.top { border-bottom: 3px solid var(--brass); padding-bottom: 14px; }
.paper .letterhead { display: flex; align-items: center; gap: 14px; padding-bottom: 12px; margin-bottom: 14px; border-bottom: 2.5px solid #c9a227; }
.paper .letterhead img { width: 62px; height: auto; flex: none; }
.paper .letterhead .org { margin: 0; }
.paper .foot { margin-top: 22px; padding-top: 8px; border-top: 1px solid var(--paper-line); font-size: 10.5px; color: var(--paper-muted); text-align: center; }
.top h1 { font-family: var(--font-display); font-weight: 700; font-size: 1.9rem; line-height: 1.1; margin: 0; text-wrap: balance; }
.top p { margin: 4px 0 0; color: var(--muted); max-width: 52ch; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
button, .btn {
  font: inherit; font-weight: 600; font-size: 14px; border-radius: 8px; padding: 9px 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.banner {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
  border: 1px solid var(--brass); border-radius: 8px; padding: 10px 14px; background: var(--surface);
}
.banner p { margin: 0; flex: 1 1 260px; min-width: 0; }
.tabs { display: flex; gap: 6px; }
.tabs button { flex: 1; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.grid[data-view="form"] #previewPane { display: none; }
.grid[data-view="preview"] #formPane { display: none; }
@media (min-width: 1000px) {
  .tabs { display: none; }
  .grid, .grid[data-view] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .grid[data-view] #previewPane, .grid[data-view] #formPane { display: block; }
  #previewPane { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
}
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
#formPane { display: flex; flex-direction: column; gap: 16px; }
.grid[data-view="preview"] #formPane { display: none; }
@media (min-width: 1000px) { #formPane { display: flex !important; } }
.card h2 { font-family: var(--font-display); font-size: 1.15rem; margin: 0; font-weight: 700; }
.card h2 span { font-family: var(--font-mono); font-size: .8rem; color: var(--accent); margin-right: 8px; font-weight: 500; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); min-width: 0; }
label small { font-weight: 400; }
input, select, textarea {
  font: inherit; font-size: 15px; font-weight: 400; color: var(--fg); background: var(--field);
  border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.items { display: flex; flex-direction: column; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.item .r1 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.item .r2 { display: grid; grid-template-columns: 72px minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.item .r3 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.line-total { font-family: var(--font-mono); font-size: 14px; font-variant-numeric: tabular-nums; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-variant-numeric: tabular-nums; }
.totals .num { font-family: var(--font-mono); text-align: right; }
.totals .big { font-weight: 700; font-size: 1.05rem; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.foot-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* Paper preview */
.paper {
  background: var(--paper); color: var(--paper-fg); border: 1px solid var(--line); border-radius: 4px;
  padding: clamp(18px, 4vw, 40px); max-width: 680px; margin: 0 auto; font-size: 13px; line-height: 1.5;
  box-shadow: 0 1px 0 rgba(0,0,0,.04), 0 10px 30px rgba(0,0,0,.08);
}
.paper .org { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: #5b2a86; font-weight: 600; }
.paper h3.title { font-family: var(--font-display); font-size: 1.9rem; line-height: 1.1; margin: 4px 0 2px; font-weight: 700; }
.paper .sub { color: var(--paper-muted); margin: 0 0 14px; }
.paper .sec { font-family: var(--font-display); font-size: 1rem; font-weight: 700; color: #5b2a86; border-bottom: 1.5px solid #5b2a86; padding-bottom: 3px; margin: 20px 0 10px; }
.paper .kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 14px; margin-bottom: 8px; }
.paper .k { font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--paper-muted); font-weight: 600; }
.paper .v { overflow-wrap: anywhere; white-space: pre-wrap; }
.paper .empty { color: #8b979c; }
.paper .block { margin-bottom: 10px; }
.paper .tw { overflow-x: auto; }
.paper table { width: 100%; border-collapse: collapse; font-size: 12px; }
.paper th { text-align: left; background: #5b2a86; color: #fff; padding: 5px 7px; font-weight: 600; font-size: 11px; }
.paper td { border-bottom: 1px solid var(--paper-line); padding: 6px 7px; vertical-align: top; overflow-wrap: anywhere; }
.paper td.n, .paper th.n { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.paper tfoot td { font-weight: 700; background: #f3eef8; border-bottom: none; }
.paper .sig td { height: 40px; }
.paper .dec { margin-top: 10px; font-size: 12px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600; font-size: 14px; max-width: min(92vw, 520px); z-index: 10;
}
@media (max-width: 520px) { .item .r2 { grid-template-columns: 64px minmax(0, 1fr); } .item .r2 label:last-child { grid-column: 1 / -1; } }
/* Logo in the live preview letterhead */
.paper .letterhead .min-name { margin: 0; }
/* Validation */
.err { color: var(--danger); font-size: 12.5px; font-weight: 600; margin: 0; }
[aria-invalid="true"] { border-color: var(--danger); outline: 1px solid var(--danger); outline-offset: 0; }
.err-summary { border: 1.5px solid var(--danger); border-radius: 8px; padding: 10px 14px; background: var(--field); }
.err-summary p { margin: 0 0 4px; font-weight: 700; color: var(--danger); }
.err-summary ul { margin: 0; padding-left: 18px; }
.err-summary a { color: var(--fg); }
/* Submit card */
.submit-card { border-color: var(--accent); }
.submit-total { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.status { border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.status p { margin: 0; }
.status.sending { border: 1px solid var(--line); background: var(--field); }
.status.ok { border: 1.5px solid var(--ok); background: var(--field); }
.status.ok strong { color: var(--ok); }
.status.fail { border: 1.5px solid var(--danger); background: var(--field); }
.status.fail strong { color: var(--danger); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; vertical-align: -2px; margin-right: 8px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
button:disabled { opacity: .6; cursor: progress; }
/* Honeypot: off-screen, not display:none, so simple bots still fill it */
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
