:root {
  --bg: #f3efe6;
  --bg-2: #e7e0d2;
  --paper: #fffcf7;
  --ink: #1c1915;
  --muted: #5e584e;
  --line: #e3d9c8;
  --brand: #1f4d3a;
  --accent: #a56b3c;
  --ok: #1f7a4d;
  --warn: #8a5a00;
  --bad: #9f2d2d;
  --shadow: 0 12px 32px rgba(48, 36, 18, 0.08);
  --radius: 18px;
  --tap: 48px;
  --nav: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: clip;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.app-header, .signer-header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; object-fit: cover;
  background: var(--brand); color: white; display: grid; place-items: center;
  font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.brand-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.header-spacer { flex: 1; }
.content {
  padding: 16px 16px calc(var(--nav) + 48px + env(safe-area-inset-bottom));
  max-width: 1100px; margin: 0 auto;
}
.signer .content, .focus .content { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--paper); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; text-decoration: none; color: var(--muted);
  padding: 8px 4px 10px; font-size: 11px; font-weight: 600;
  min-height: var(--tap); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar a.active { color: var(--brand); }
.tabbar svg { width: 22px; height: 22px; }
.sidenav { display: none; }

.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
h1 { font-size: 28px; line-height: 1.15; margin: 0 0 6px; letter-spacing: -0.03em; }
h2 { font-size: 18px; margin: 0 0 8px; }
.muted { color: var(--muted); overflow-wrap: anywhere; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 650; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=file], select, textarea {
  width: 100%; background: white; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; min-height: var(--tap); font-size: 16px;
}
input[type=file] { padding: 10px 14px; }
textarea { min-height: 96px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: white; font-weight: 700; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn.accent { background: var(--accent); color: white; border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #e7c7c7; background: #fff6f6; }
.btn.full { width: 100%; }
.btn:disabled { opacity: 0.55; }

.pill {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 10px;
  font-size: 12px; font-weight: 700; background: var(--bg-2); color: var(--muted);
}
.pill.completed, .pill.signed { background: #e5f6ec; color: var(--ok); }
.pill.sent, .pill.in_progress, .pill.awaiting_signature, .pill.pending { background: #f8efe2; color: var(--accent); }
.pill.declined, .pill.voided, .pill.expired { background: #fdecec; color: var(--bad); }

.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc-card {
  display: block; text-decoration: none; color: inherit; background: var(--paper);
  border: 1px solid var(--line); border-radius: 16px; padding: 14px 14px 12px;
}
.doc-card strong { display: block; font-size: 17px; }
.doc-card .meta { margin-top: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }

.empty {
  text-align: center; padding: 28px 12px 12px;
}
.empty h1 { font-size: 26px; }
.alert {
  background: #fff6f4; color: var(--bad); border: 1px solid #f0d0cb; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px;
}
.oknote {
  background: #eef8f2; color: var(--ok); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px;
}

.tools { display: flex; gap: 8px; flex-wrap: wrap; padding-bottom: 4px; }
.tools button, .chips button {
  flex: 0 0 auto; min-height: var(--tap); border-radius: 999px; border: 1px solid var(--line);
  background: white; padding: 0 14px; font-weight: 700;
}
.tools button[aria-pressed="true"] { background: var(--brand); color: white; border-color: var(--brand); }

.stage-wrap { overflow: auto; background: #d9d1c3; border-radius: 16px; padding: 10px; max-width: 100%; }
.stage { position: relative; margin: 0 auto; touch-action: none; width: 100%; }
.stage img { display: block; width: 100%; height: auto; background: white; }
.field-box {
  position: absolute; border: 2px solid var(--brand); background: rgba(31, 77, 58, 0.12);
  border-radius: 6px; color: var(--ink); font-size: 11px; font-weight: 700;
  display: flex; align-items: flex-end; padding: 2px 4px; touch-action: none;
  box-sizing: border-box;
}
.field-box .handle {
  position: absolute; width: 18px; height: 18px; right: -8px; bottom: -8px;
  background: var(--accent); border-radius: 50%; border: 2px solid white;
}
.sheet {
  position: sticky; bottom: 0; background: var(--paper); border: 1px solid var(--line);
  border-radius: 16px 16px 0 0; padding: 12px; margin-top: 12px;
  box-shadow: 0 -8px 24px rgba(48, 36, 18, 0.06);
}

.signer-doc { background: #d9d1c3; border-radius: 16px; padding: 8px; }
.sign-field {
  position: absolute; border: 2px dashed var(--brand); background: rgba(255, 252, 247, 0.86);
  border-radius: 8px; font-size: 12px; font-weight: 700; display: flex; align-items: center;
  justify-content: center; text-align: center; padding: 2px; overflow: hidden;
}
.sign-field.done { border-style: solid; background: rgba(31, 122, 77, 0.08); }
.sign-field img, .sign-field canvas { max-width: 100%; max-height: 100%; }

.modal {
  position: fixed; inset: 0; background: rgba(28, 25, 21, 0.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal .panel {
  background: var(--paper); width: min(640px, 100%); border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto;
}
canvas.pad {
  width: 100%; height: 180px; background: white; border: 1px solid var(--line); border-radius: 12px;
  touch-action: none;
}
.checkline { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.checkline input { width: 22px; height: 22px; margin-top: 2px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline .when { font-size: 12px; color: var(--muted); }
.hash { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; word-break: break-word; }
.editor-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.editor-head h1 { font-size: 22px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice-list label { min-height: var(--tap); display: flex; align-items: center; gap: 10px; font-weight: 650; }
.warn-banner { background: #fff6e8; color: #6a4200; border: 1px solid #f0dfc4; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.legal-copy { white-space: pre-wrap; }

.banner-ok { background: #e7f6ee; color: #145c38; padding: 12px 14px; border-radius: 12px; font-weight: 700; }
.banner-bad { background: #fdecec; color: var(--bad); padding: 12px 14px; border-radius: 12px; font-weight: 700; }

.drop {
  border: 2px dashed var(--line); border-radius: 16px; padding: 28px 16px; text-align: center; background: white;
}

@media (min-width: 900px) {
  .tabbar { display: none; }
  body.app { display: grid; grid-template-columns: 220px 1fr; }
  .sidenav {
    display: flex; flex-direction: column; gap: 4px; padding: 22px 14px;
    background: var(--paper); border-right: 1px solid var(--line); min-height: 100vh;
    position: sticky; top: 0;
  }
  .sidenav a { text-decoration: none; color: var(--ink); padding: 12px 12px; border-radius: 12px; font-weight: 700; min-height: 44px; }
  .sidenav a.active, .sidenav a:hover { background: var(--bg); color: var(--brand); }
  .app-header { display: none; }
  .content { padding: 28px 32px 48px; }
  .brand-name, .brand-sub { max-width: none; }
  .editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
  .home-actions { flex-direction: row; }
  .home-actions .btn { width: auto; }
  .home-features { grid-template-columns: 1fr 1fr; }
}

.home .content { padding-bottom: calc(28px + env(safe-area-inset-bottom)); max-width: 760px; }
.home-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0 0 18px;
}
.home-brand { font-weight: 800; font-size: 20px; color: var(--ink); text-decoration: none; letter-spacing: -0.03em; }
.home-hero h1 { font-size: 34px; line-height: 1.12; letter-spacing: -0.04em; }
.home-kicker { margin: 0 0 8px; color: var(--brand); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 12px; }
.home-lede { font-size: 18px; color: var(--muted); }
.home-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.home-actions .btn { width: 100%; }
.home-section { margin-top: 28px; }
.home-features { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.home-features li, .home-steps li {
  background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px;
}
.home-features h3, .home-steps h3 { margin: 0 0 4px; font-size: 17px; }
.home-features p, .home-steps p { margin: 0; color: var(--muted); }
.home-steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.home-steps li { display: flex; gap: 12px; align-items: flex-start; }
.home-steps span {
  flex: 0 0 36px; height: 36px; border-radius: 50%; background: var(--brand); color: white;
  display: grid; place-items: center; font-weight: 800;
}
.home-footer {
  display: flex; flex-wrap: wrap; gap: 16px; margin-top: 28px; padding-top: 16px;
  border-top: 1px solid var(--line);
}
.home-footer a { font-weight: 700; min-height: 44px; display: inline-flex; align-items: center; }
