:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e3e5ea;
  --accent: #1f2937;
  --primary: #111827;
  --ok: #0f7b3f;
  --warn: #b42318;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "맑은 고딕",
               "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px;
  margin-bottom: 16px;
}
.card.narrow { max-width: 400px; margin: 60px auto; }
.wrap.wide { max-width: 1180px; }
.card.center { text-align: center; }

h1 { font-size: 21px; line-height: 1.4; margin: 0 0 12px; letter-spacing: -0.4px; }
h2 { font-size: 15px; margin: 22px 0 10px; letter-spacing: -0.2px; }
h2:first-of-type { margin-top: 0; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 28px 0; }
.step { font-size: 12px; color: var(--muted); letter-spacing: 1px; margin: 0 0 6px; }

.hash { font-family: Consolas, "Courier New", monospace; font-size: 11px; word-break: break-all; }

.alert {
  background: #fdf2f2; border: 1px solid #f5c2c0; color: var(--warn);
  padding: 11px 13px; border-radius: 8px; margin-bottom: 14px; font-size: 14px;
}
.ok-banner {
  background: #eefaf2; border: 1px solid #b7e3c9; color: var(--ok);
  padding: 11px 13px; border-radius: 8px; margin-bottom: 14px; font-size: 14px;
}

.big-icon {
  width: 56px; height: 56px; border-radius: 50%; margin: 4px auto 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700; background: #fdecea; color: var(--warn);
}
.big-icon.ok { background: #e8f6ee; color: var(--ok); }

/* --- 폼 --- */
.field { display: block; margin-bottom: 16px; }
.field .label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .hint { display: block; font-size: 12px; color: var(--muted); margin-top: 5px; }
.req { color: var(--warn); font-size: 11px; font-weight: 600; margin-left: 3px; }
.opt { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 3px; }

input[type=text], input[type=tel], input[type=password] {
  width: 100%; padding: 12px 13px; font-size: 16px;
  border: 1px solid #cfd3da; border-radius: 9px; background: #fff; color: var(--ink);
  font-family: inherit;
}
input[type=text]:focus, input[type=tel]:focus, input[type=password]:focus {
  outline: 2px solid #b9c0cc; outline-offset: 0; border-color: #97a0ae;
}

.privacy-note {
  background: #f7f8fa; border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 13px; font-size: 12.5px; color: #4b5563; line-height: 1.6; margin-bottom: 18px;
}

.btn {
  display: inline-block; padding: 12px 18px; font-size: 15px; font-weight: 600;
  border-radius: 9px; border: 1px solid #cfd3da; background: #fff; color: var(--ink);
  cursor: pointer; font-family: inherit; text-decoration: none; text-align: center;
}
.btn.primary { width: 100%; background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:disabled { background: #c3c7cf; border-color: #c3c7cf; color: #f0f1f3; cursor: not-allowed; }
.btn.ghost { background: #fff; }
.btn.danger { background: #fff; border-color: #e5a9a6; color: var(--warn); }
.btn.tiny { padding: 6px 10px; font-size: 12px; font-weight: 500; border-radius: 7px; }
.btn.copied { background: #e8f6ee; border-color: #b7e3c9; color: var(--ok); }
.inline { display: inline-block; margin-left: 8px; }

/* --- 계약 당사자 표 --- */
.parties, .kv { width: 100%; border-collapse: collapse; margin: 12px 0 18px; }
.parties th, .kv th {
  text-align: left; font-size: 13px; color: var(--muted); font-weight: 500;
  padding: 8px 10px 8px 0; width: 108px; vertical-align: top; white-space: nowrap;
}
.parties td, .kv td { padding: 8px 0; font-size: 14px; border-bottom: 1px solid var(--line); }
.parties th { border-bottom: 1px solid var(--line); }
.kv th { border-bottom: 1px solid var(--line); }
.done-table { text-align: left; margin: 18px 0; }

/* --- 계약서 본문 --- */
.doc {
  height: 46vh; min-height: 300px; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--line); border-radius: 9px; background: #fcfcfd;
  padding: 16px 14px; -webkit-overflow-scrolling: touch;
}
.doc.small-doc { height: 320px; }
.doc-body {
  margin: 0; white-space: pre-wrap;
  word-break: keep-all; overflow-wrap: break-word;  /* 한글은 어절 단위로 줄바꿈 */
  font-family: inherit; font-size: 13.5px; line-height: 1.8; color: #23262d;
}
.read-state {
  margin-top: 10px; padding: 9px 12px; border-radius: 8px; font-size: 13px;
  background: #fff7e8; border: 1px solid #f0dcb4; color: #8a5b12; text-align: center;
}
.read-state.done { background: #eefaf2; border-color: #b7e3c9; color: var(--ok); }

/* --- 동의 항목 --- */
.card.locked { opacity: 0.5; pointer-events: none; }
.consents { list-style: none; margin: 0 0 12px; padding: 0; }
.consents li { border-bottom: 1px solid var(--line); }
.consents li:last-child { border-bottom: 0; }
.consents label {
  display: flex; align-items: flex-start; gap: 10px; padding: 13px 2px; cursor: pointer;
}
.consents input[type=checkbox] { width: 21px; height: 21px; margin: 1px 0 0; flex: 0 0 auto; accent-color: var(--primary); }
.consents .num {
  flex: 0 0 auto; width: 21px; height: 21px; border-radius: 50%; background: #eef0f4;
  color: #4b5563; font-size: 11.5px; font-weight: 700; display: flex;
  align-items: center; justify-content: center; margin-top: 1px;
}
.consents .text { flex: 1; font-size: 14px; line-height: 1.6; }
.counter { text-align: right; font-size: 13px; color: var(--muted); font-weight: 600; }

/* --- 서명 --- */
.sigwrap { position: relative; }
.sigpad {
  width: 100%; height: 190px; display: block; touch-action: none;
  background: #fff; border: 1px dashed #b9bfc9; border-radius: 9px; cursor: crosshair;
}
.sig-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #b0b6c0; font-size: 15px; pointer-events: none;
}
.sig-actions { display: flex; gap: 8px; margin: 10px 0 4px; }
.sig-actions .btn { flex: 1; padding: 9px; font-size: 13px; }
.sig-view { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.final { margin: 20px 0 16px; padding: 14px; background: #f7f8fa; border-radius: 9px; border: 1px solid var(--line); }
.final-text { font-size: 13.5px; margin: 0 0 10px; line-height: 1.6; }
.final-check { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px; cursor: pointer; }
.final-check input { width: 21px; height: 21px; accent-color: var(--primary); }
#blockReason { margin-top: 10px; }
#blockReason.ready { color: var(--ok); }

.checkline { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 14px; font-size: 14px; cursor: pointer; }
.checkline input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--primary); }

/* --- 관리자 --- */
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 16px; }
.admin-head h1 { margin: 0; font-size: 19px; }
.back { text-decoration: none; color: var(--muted); margin-right: 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row input[type=text] { flex: 1 1 240px; }
.row .btn { flex: 0 0 auto; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  padding: 7px 12px; border-radius: 999px; font-size: 13px; text-decoration: none;
  color: var(--muted); background: #f1f2f5; border: 1px solid transparent;
}
.tab.on { background: var(--primary); color: #fff; }

.table-scroll { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.list th, table.list td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
table.list a { color: var(--ink); text-decoration: none; }
table.list a:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.sent { background: #fff4e0; color: #96620f; }
.badge.signed { background: #e8f6ee; color: var(--ok); }
.badge.cancelled { background: #f1f2f5; color: var(--muted); }
.badge.expired { background: #fdecea; color: var(--warn); }
b.yes { color: var(--ok); }
b.no { color: var(--warn); }

.linkbox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.linkbox .label { font-size: 12px; color: var(--muted); }
.linkbox input { flex: 1 1 260px; font-size: 12.5px; }

@media (max-width: 520px) {
  .wrap { padding: 14px 12px 56px; }
  .card { padding: 18px 15px; }
  h1 { font-size: 19px; }
  .parties th, .kv th { width: 92px; font-size: 12px; }
}
