:root {
  --bg: #f1f4f2;
  --card: #ffffff;
  --ink: #0b1a15;
  --muted: #56645e;
  --line: #d5ddd8;
  --brand: #0b251e;
  --brand-ink: #ffffff;
  --bar: #0b251e;
  --bar-ink: #ffffff;
  --accent: #a5f927;
  --accent-ink: #0b251e;
  --info-bg: #ecfbd6;
  --info: #24420b;
  --ok: #1e7b3a;
  --warn: #9a6200;
  --warn-bg: #fff4d6;
  --bad: #b3261e;
  --bad-bg: #fde8e6;
  --radius: 12px;
  --tap: 48px;
  /* The email preview is a printed-page look in both themes. */
  --paper: #ffffff;
  --paper-ink: #222222;
  --scrim: rgba(10, 16, 24, .55);
  --bad-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07130f;
    --card: #10201a;
    --ink: #e8ecf0;
    --muted: #97a9a0;
    --line: #23362e;
    --brand: #a5f927;
    --brand-ink: #0b251e;
    --info-bg: #1a2e0c;
    --info: #c6f784;
    --warn-bg: #3a2f12;
    --warn: #f0c35a;
    --bad-bg: #3d1a18;
    --bad: #ff8a80;
    --bad-ink: #2a0b09;
    --ok: #6fcf8a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #07130f;
  --card: #10201a;
  --ink: #e8ecf0;
  --muted: #97a9a0;
  --line: #23362e;
  --brand: #a5f927;
  --brand-ink: #0b251e;
  --info-bg: #1a2e0c;
  --info: #c6f784;
  --warn-bg: #3a2f12;
  --warn: #f0c35a;
  --bad-bg: #3d1a18;
  --bad: #ff8a80;
  --bad-ink: #2a0b09;
  --ok: #6fcf8a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bar); color: var(--bar-ink);
}
.topbar { min-height: 56px; border-bottom: 3px solid var(--accent); }
.topbar .brand-logo { height: 34px; width: auto; display: none; }
.topbar .brand-symbol { height: 28px; width: auto; flex: 0 0 auto; }
.topbar.home .brand-logo { display: block; }
.topbar.home .brand-symbol, .topbar.home h1 { display: none; }
.topbar.home .save-state { margin-left: auto; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 24px; min-width: 40px; min-height: 40px; cursor: pointer; }
.save-state { font-size: 12px; opacity: .8; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 120px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.card h2 { font-size: 17px; margin: 0 0 10px; }
.card h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }

label.field { display: block; margin: 0 0 10px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=email], input[type=number], input:not([type]), select, textarea {
  width: 100%; min-height: var(--tap);
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 10px 16px;
  font: inherit; font-weight: 600; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  text-decoration: none;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 18px; }
.btn.sm { min-height: 36px; padding: 6px 10px; font-size: 14px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row.tight > * { flex: 0 0 auto; }
.stack > * + * { margin-top: 8px; }

.sticky-actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.sticky-actions .inner { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; }
.sticky-actions .inner > * { flex: 1; }

.sign-item { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.sign-item img, .thumb-ph { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--line); flex: 0 0 auto; }
.sign-item .meta { flex: 1; min-width: 0; }
.sign-item .meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--ink); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.req { background: none; color: var(--bad); padding: 0; }

.notice { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 8px 0; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.info { background: var(--info-bg); color: var(--info); }

.hero-photo { width: 100%; max-height: 360px; object-fit: contain; background: #000; border-radius: 10px; display: block; }

.item { border-top: 1px solid var(--line); padding: 12px 0; }
.item:first-of-type { border-top: 0; padding-top: 4px; }
.item .label { font-weight: 600; }
.item .why { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.item.done .label::after { content: " ✓"; color: var(--ok); }

.measure { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.measure.ftin { grid-template-columns: 1fr 1fr 96px; }
.note-toggle { background: none; border: 0; color: var(--brand); font: inherit; font-size: 13px; padding: 6px 0; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 40px; padding: 8px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: 15px; cursor: pointer; }
.chip[aria-pressed=true] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.thumb { position: relative; }
.thumb img { width: 88px; height: 88px; object-fit: cover; border-radius: 8px; display: block; }
.thumb button { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--bad); color: #fff; font-size: 14px; cursor: pointer; }
.thumb input { width: 88px; min-height: 32px; font-size: 12px; padding: 4px; margin-top: 4px; }

.spinner { width: 40px; height: 40px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; margin: 16px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: 90vw; }

ul.missing { margin: 6px 0 0; padding-left: 18px; font-size: 14px; color: var(--warn); }
.center { text-align: center; }

.btn.danger-fill { background: var(--bad); border-color: var(--bad); color: var(--bad-ink); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; /* above the sketch pad, which prompts for labels */
  background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
}
.modal {
  width: 100%; max-width: 480px;
  background: var(--card); color: var(--ink);
  border-radius: 16px; padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal h2 { margin: 0; font-size: 18px; text-wrap: balance; }
.modal-msg { margin: 0; color: var(--muted); white-space: pre-line; }
@media (min-width: 600px) { .modal-backdrop { align-items: center; } }

.email-paper {
  background: var(--paper); color: var(--paper-ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; overflow-x: auto;
}
.email-paper img { max-width: 100%; height: auto; }

/* Sign type picker */
.type-choice { justify-content: space-between; text-align: left; }
.type-choice .pct { font-weight: 500; font-variant-numeric: tabular-nums; opacity: .8; }
.type-line { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-top: 12px; }
.type-line .badge { margin-top: 4px; }

/* Form */
.tips { margin: 4px 0 8px; padding-left: 18px; color: var(--muted); }
.tips li + li { margin-top: 2px; }
.steps { margin: 0; padding-left: 22px; }
.steps li + li { margin-top: 6px; }
.item.computed .label { font-weight: 500; color: var(--muted); }
.item.computed strong { font-variant-numeric: tabular-nums; }
.repeat-row { display: flex; gap: 6px; align-items: center; margin: 0 0 8px; }
.repeat-row > input { flex: 1; min-width: 0; }
.repeat-row > .muted:first-child { flex: 0 0 18px; text-align: right; }
.icon-btn.small-x { flex: 0 0 auto; min-width: 36px; min-height: 36px; font-size: 16px; color: var(--muted); }

/* Sketch pad (full screen) */
.sketch {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column;
  background: #10201a; color: #fff;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sketch-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; background: var(--bar); }
.sketch-bar .btn { background: #10201a; color: #fff; border-color: #2f4a3f; }
.sketch-bar .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sketch-bar .btn[aria-pressed=true] { outline: 2px solid var(--accent); }
.sketch-bar .chips { flex: 1; justify-content: center; flex-wrap: nowrap; gap: 4px; }
.sketch-bar .btn.sm { padding: 6px 8px; }
.swatch { width: 32px; min-height: 32px; flex: 0 0 auto; padding: 0; background: var(--sw); border: 2px solid #666; }
.swatch[aria-pressed=true] { border-color: #fff; outline: 2px solid var(--accent); background: var(--sw); }
.sketch-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; }
.sketch-stage canvas { max-width: 100%; max-height: 100%; touch-action: none; background: #fff; border-radius: 4px; }
.sketch-hint { text-align: center; padding: 6px 8px 10px; color: #c8ccd1; }

/* Label + badge rows: long labels wrap instead of pushing the badge off-screen. */
.row.tight > .label { flex: 1 1 auto; min-width: 0; }
.row.tight > .badge, .row.tight > .muted { flex: 0 0 auto; margin-left: 8px; }
