:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2330; --muted: #6a7281; --line: #e2e5ea; --line2: #cfd4dc;
  --accent: #1f4fd1; --accent-weak: #e8eefc; --danger: #c62828; --danger-weak: #fdecec; --ok: #18794e; --ok-weak: #e6f4ec;
  --warn: #a15c00; --warn-weak: #fff4e0; --us: #1f4fd1; --them: #d9700b; --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.7 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; justify-content: space-between; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: .02em; white-space: nowrap; }
.brand span { font-weight: 500; color: var(--muted); margin-left: 4px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
nav a, nav .link { color: var(--text); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 14px; }
nav a:hover, nav .link:hover { background: var(--bg); }
main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 80px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.narrow { max-width: 520px; margin: 0 auto; }
.pad { padding: 40px 0; } .center { text-align: center; } .muted { color: var(--muted); } .small { font-size: 13px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }
label.f { display: block; margin: 0 0 14px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=date], select, textarea {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--line2); border-radius: 8px; background: #fff; color: var(--text); }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line2); background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: #f0c4c4; }
.btn.big { padding: 13px 22px; font-size: 16px; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: 0; font: inherit; color: var(--accent); cursor: pointer; padding: 0; }
.err { background: var(--danger-weak); color: var(--danger); border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; font-size: 14px; }
.note { background: var(--accent-weak); border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; font-size: 14px; }
.warnbox { background: var(--warn-weak); color: var(--warn); border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; font-size: 14px; }
table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; } table.list tr.click:hover td { background: #fafbfc; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.signed { background: var(--ok-weak); color: var(--ok); }
.badge.sent, .badge.opened { background: var(--accent-weak); color: var(--accent); }
.badge.declined, .badge.canceled, .badge.expired { background: var(--danger-weak); color: var(--danger); }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 8px; margin-bottom: 12px; }
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; word-break: break-all; }
ol.events { list-style: none; padding: 0; margin: 0; font-size: 13px; }
ol.events li { padding: 7px 0; border-bottom: 1px dashed var(--line); display: grid; grid-template-columns: 150px 1fr; gap: 12px; }
ol.events li .ip { color: var(--muted); }

/* 配置の手直し */
.editor { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
.pages { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.page { position: relative; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); width: 100%; max-width: 760px; }
.page canvas { display: block; width: 100%; height: auto; }
.page .pno { position: absolute; top: -2px; left: -38px; font-size: 12px; color: var(--muted); }
.fld { position: absolute; border: 1.5px solid var(--them); background: rgba(217,112,11,.10); border-radius: 3px; cursor: move; touch-action: none; }
.fld.us { border-color: var(--us); background: rgba(31,79,209,.10); }
.fld.sel { box-shadow: 0 0 0 3px rgba(31,79,209,.35); }
.fld .tag { position: absolute; left: 0; top: -15px; font-size: 10px; line-height: 14px; padding: 0 4px; border-radius: 3px 3px 0 0; color: #fff; background: var(--them); white-space: nowrap; pointer-events: none; }
.fld.us .tag { background: var(--us); }
.fld .val { position: absolute; left: 2px; right: 2px; bottom: 1px; font-size: 10px; line-height: 1.1; white-space: nowrap; overflow: hidden; color: var(--text); pointer-events: none; }
.fld .rz { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; background: #fff; border: 1.5px solid currentColor; border-radius: 2px; cursor: nwse-resize; }
.side { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 12px; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.adding .page { cursor: crosshair; }

/* 相手の画面 */
.sign-wrap { max-width: 860px; margin: 0 auto; }
.sign-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.sign-form { position: sticky; top: 70px; }
.sfld { position: absolute; border: 1.5px dashed var(--them); background: rgba(217,112,11,.08); border-radius: 3px; display: flex; align-items: flex-end; overflow: hidden; }
.sfld.filled { border-style: solid; background: rgba(24,121,78,.06); border-color: var(--ok); }
.sfld span { font-size: 10px; line-height: 1.05; padding: 0 2px 1px; white-space: nowrap; }
.sfld.seal { align-items: center; justify-content: center; border-radius: 50%; }
.sfld.seal img { width: 100%; height: 100%; object-fit: contain; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button { flex: 1; font: inherit; font-size: 13px; padding: 7px; border: 1px solid var(--line2); background: #fff; border-radius: 8px; cursor: pointer; }
.tabs button.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.sealprev { display: flex; justify-content: center; padding: 8px; }
.sealprev canvas, .sealprev img { width: 96px; height: 96px; }
.codebox { font-size: 26px; letter-spacing: .4em; text-align: center; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin: 12px 0; }
.check input { margin-top: 5px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d2330; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
.steps { display: flex; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.steps b { color: var(--accent); }

@media (max-width: 860px) {
  .editor, .sign-grid { grid-template-columns: 1fr; }
  .side, .sign-form { position: static; }
  .filters { grid-template-columns: 1fr 1fr; }
  .page .pno { display: none; }
  dl.kv { grid-template-columns: 110px 1fr; }
  ol.events li { grid-template-columns: 1fr; gap: 0; }
  table.list .hide-sm { display: none; }
  .top { padding: 10px 16px; flex-wrap: wrap; }
}
[hidden] { display: none !important; }
/* ラベルは選んだ枠・指を置いた枠だけに出す（重なり防止） */
.fld .tag { display: none; }
.fld:hover .tag, .fld.sel .tag { display: block; z-index: 2; }
.fld .val.ph { color: var(--them); opacity: .85; }
.fld.us .val.ph { color: var(--us); }
.jump { display: none; margin: 0 0 12px; width: 100%; }
@media (max-width: 860px) { .jump { display: flex; } }

input.bad { border-color: var(--danger); box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 20%, transparent); }
