@font-face {
  font-family: "Sig";
  src: url("/fonts/dancing-script-latin-400-normal.woff2") format("woff2");
  font-display: block;
}
:root {
  --ink: #1d2320;
  --muted: #5f6b64;
  --line: #d9ded9;
  --paper: #ffffff;
  --bg: #f2f1ec;
  --accent: #2f5d46;
  --accent-ink: #ffffff;
  --accent-soft: #e7efe9;
  --warn: #9a3b22;
  --done: #2f6f4a;
  --radius: 12px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}
main { max-width: 680px; margin: 0 auto; padding: 16px 14px 24px; }
.loading { text-align: center; color: var(--muted); margin-top: 30vh; }

.doc {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 18px;
}
.doc-head { text-align: center; border-bottom: 2px solid var(--ink); padding-bottom: 12px; margin-bottom: 14px; }
.doc-head .org { font: 700 15px/1.25 Georgia, "Times New Roman", serif; letter-spacing: .06em; margin: 0; }
.doc-head h1 { font: 700 20px/1.25 Georgia, "Times New Roman", serif; margin: 4px 0 4px; }
.doc-head .sub { font-style: italic; color: var(--muted); font-size: 13px; margin: 0; }

h2.sec {
  font: 700 13px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  text-transform: uppercase; letter-spacing: .08em; color: var(--accent);
  margin: 24px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
p { margin: 0 0 10px; }
.small { font-size: 14px; color: var(--muted); }
.fine { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.center { text-align: center; }

.note {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 10px 12px; border-radius: 6px; font-size: 14.5px; margin: 14px 0 4px;
}

/* Detail rows (read-only and inputs share fixed geometry) */
.rows { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.row { display: grid; grid-template-columns: 1fr; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .k { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 8px 12px 0; }
.row .v { padding: 2px 12px 9px; min-height: 34px; overflow-wrap: anywhere; }
@media (min-width: 560px) {
  .row { grid-template-columns: 200px 1fr; }
  .row .k { padding: 10px 12px; background: #fafaf7; border-right: 1px solid var(--line); }
  .row .v { padding: 10px 12px; }
}

.fld { display: block; margin: 0 0 12px; }
.fld > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=date], input[type=number], input[type=tel] {
  width: 100%; height: 46px; padding: 0 12px;
  font: inherit; font-size: 16px; color: var(--ink);
  border: 1px solid #c3cac4; border-radius: 8px; background: #fff;
  appearance: none; -webkit-appearance: none;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.money { position: relative; }
.money::before { content: "$"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 24px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; }
.choice span {
  display: flex; align-items: center; justify-content: center; height: 44px;
  border: 1px solid #c3cac4; border-radius: 8px; font-size: 15px; background: #fff;
}
.choice input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 48px; padding: 0 18px; border-radius: 10px; border: 1px solid #c3cac4;
  background: #fff; color: var(--ink); font-family: inherit; font-weight: 600; font-size: 16px; line-height: 1; cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { height: 38px; font-size: 14px; padding: 0 12px; }
.link { background: none; border: 0; color: var(--accent); font-family: inherit; font-weight: 600; font-size: 14px; line-height: 1; padding: 8px 0; cursor: pointer; }
.link.danger { color: var(--warn); }

/* Signature blocks */
.sig {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
}
.sig .who { font-weight: 700; }
.sig .role { font-size: 13px; color: var(--muted); }
.sig .box {
  grid-column: 1 / -1; height: 84px; border: 1px dashed #c3cac4; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; background: #fcfcfa; overflow: hidden;
}
.sig.signed .box { border-style: solid; border-color: #cfe0d5; background: #fff; }
.sig .box img { max-height: 76px; max-width: 100%; }
.sig .meta { grid-column: 1 / -1; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: #eef0ee; color: var(--muted); white-space: nowrap; }
.signed .badge { background: #e3f1e8; color: var(--done); }

.status { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }

/* Bottom bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  backdrop-filter: blur(6px);
}
.bar-in { max-width: 680px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 17px; margin: 0 0 6px; }
.linkbox { display: flex; gap: 8px; margin: 8px 0 12px; }
.linkbox input { flex: 1; font-size: 14px; height: 42px; }

.err { color: var(--warn); font-size: 14px; min-height: 0; margin: 6px 0; }
.err:empty { display: none; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20,25,22,.45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 94vh; overflow: auto;
  background: #fff; border-radius: 16px 16px 0 0; padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 680px; margin: 0 auto;
}
@media (min-width: 700px) { .sheet-panel { bottom: auto; top: 6vh; border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: #fff; padding: 14px 0 8px; z-index: 1; }
.sheet-head h2 { font-size: 18px; margin: 0; }
.x { background: none; border: 0; font-size: 30px; line-height: 1; padding: 0 4px; color: var(--muted); cursor: pointer; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: #eef0ee; border-radius: 10px; padding: 3px; margin: 4px 0 12px; }
.tabs button { height: 38px; border: 0; border-radius: 8px; background: none; font-family: inherit; font-weight: 600; font-size: 15px; line-height: 1; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected=true] { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.pad-wrap { position: relative; border: 1px solid #c3cac4; border-radius: 10px; background: #fff; touch-action: none; }
#pad { display: block; width: 100%; height: 180px; touch-action: none; cursor: crosshair; }
.pad-line { position: absolute; left: 16px; right: 16px; bottom: 40px; border-bottom: 1px solid #c9cfca; pointer-events: none; }
.pad-hint { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; font-size: 13px; color: #9aa39d; pointer-events: none; }
.typed-preview {
  height: 90px; display: flex; align-items: center; justify-content: center;
  font-family: "Sig", cursive; font-size: 44px; border: 1px solid var(--line); border-radius: 10px;
  white-space: nowrap; overflow: hidden; padding: 0 10px;
}

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60;
  max-width: 90vw;
}
footer.docfoot { margin-top: 18px; font-size: 12.5px; font-style: italic; color: var(--muted); text-align: center; }
