@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;700&display=swap');

:root {
  --brand: #f0a640;
  --brand-d: #c97c12;
  --ink: #2b2118;
  --muted: #7a6d60;
  --line: #e8dfd3;
  --bg: #faf6f0;
  --ok: #2f9e44;
  --warn: #e8590c;
  --danger: #c92a2a;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Noto Sans KR', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  color: var(--ink); background: var(--bg); font-size: 16px; line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
a { color: var(--brand-d); }

/* ---------- 상단바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.topbar img { width: 34px; height: 34px; border-radius: 8px; }
.topbar b { font-size: 17px; }
.topbar .sp { flex: 1; }
.topbar .badge { font-size: 12px; }

.wrap { max-width: 860px; margin: 0 auto; padding: 16px; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.card h2 { margin: 0 0 6px; font-size: 20px; }
.card h3 { margin: 18px 0 8px; font-size: 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 14px; }
.center { text-align: center; }

/* ---------- 폼 ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.field label .req { color: var(--danger); margin-left: 2px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 12px; border: 1px solid #d7ccbe;
  border-radius: 10px; background: #fff; color: var(--ink); min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
input[readonly] { background: #f5f1ea; color: #5c5046; }
textarea { min-height: 96px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; font-size: 15px; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; accent-color: var(--brand-d); }
.seg { display: flex; border: 1px solid #d7ccbe; border-radius: 10px; overflow: hidden; }
.seg label { flex: 1; text-align: center; padding: 11px 4px; cursor: pointer; font-size: 15px; margin: 0; border-right: 1px solid #d7ccbe; }
.seg label:last-child { border-right: 0; }
.seg input { display: none; }
.seg input:checked + span { font-weight: 700; color: var(--brand-d); }
.seg label:has(input:checked) { background: #fff4e3; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 16px; font-weight: 500; min-height: 48px; padding: 0 18px;
  border-radius: 10px; border: 1px solid #d7ccbe; background: #fff; color: var(--ink); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f1c0c0; }
.btn.small { min-height: 36px; font-size: 14px; padding: 0 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 13px; font-weight: 500; background: #eee; }
.badge.pending { background: #fff4e3; color: var(--brand-d); }
.badge.signed { background: #e6f6ea; color: var(--ok); }
.badge.demo { background: #ffe3e3; color: var(--danger); }

/* ---------- 단계 표시 ---------- */
.stepper { display: flex; gap: 4px; margin: 0 0 14px; }
.stepper button {
  flex: 1; border: 0; background: #efe7dc; color: var(--muted); font: inherit; font-size: 13px;
  padding: 8px 2px; border-radius: 8px; cursor: pointer; line-height: 1.25;
}
.stepper button b { display: block; font-size: 15px; }
.stepper button.on { background: var(--brand); color: #fff; }
.stepper button.done { background: #f7dfba; color: var(--ink); }

/* ---------- 하단 고정 바 ---------- */
.bottombar {
  position: sticky; bottom: 0; z-index: 20; background: rgba(255,255,255,.97); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center;
  margin: 0 -16px;
}
.bottombar .prog { flex: 1; font-size: 14px; }
.bar { height: 6px; background: #efe7dc; border-radius: 9px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .3s; }

/* ---------- 서명 패드 ---------- */
.sigpad-wrap { border: 2px dashed #d7ccbe; border-radius: 12px; background: #fff; position: relative; touch-action: none; }
.sigpad-wrap canvas { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.sigpad-wrap .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #c9bdaf; pointer-events: none; font-size: 18px; }
.sig-preview { max-height: 70px; max-width: 200px; }

/* ---------- 모달 ---------- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(30,20,10,.5); display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: #fff; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal { align-items: center; } .modal .sheet { border-radius: 18px; } }
.modal .sheet.wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h3 { margin: 0; }
.postcode-layer { height: 470px; border: 1px solid var(--line); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 200; background: #2b2118; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px; max-width: 90vw; }
.overlay-busy { position: fixed; inset: 0; z-index: 300; background: rgba(255,255,255,.85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; font-size: 16px; }
.spinner { width: 40px; height: 40px; border: 4px solid #f3e3cc; border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.kv-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 15px; }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; word-break: break-all; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 26px; letter-spacing: 3px; font-weight: 700; background: #fff4e3; padding: 8px 14px; border-radius: 10px; display: inline-block; }

/* ---------- 목록 ---------- */
.list-item { display: flex; flex-direction: column; gap: 6px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .t { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-item .t b { font-size: 17px; }
.list-item .m { color: var(--muted); font-size: 14px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: none; border: 1px solid var(--line); background: #fff; font: inherit; padding: 9px 16px; border-radius: 99px; cursor: pointer; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.map-preview { width: 100%; height: 260px; border-radius: 10px; border: 1px solid var(--line); overflow: hidden; background: #f3efe8; }
.map-preview img { width: 100%; height: 100%; object-fit: cover; }

/* =================================================================
 *  계약서 지면 (A4)
 *  .paper-print : PDF/페이지 분할용 고정 A4 (794 x 1123 px)
 *  .paper-screen: 화면 열람용 (모바일 가변 폭)
 * ================================================================= */
.a4 { background: #fff; color: #111; font-family: 'Noto Sans KR', 'Malgun Gothic', sans-serif; position: relative; }
.a4 .a4-head { display: flex; align-items: center; gap: 8px; border-bottom: 1.5px solid #e2b15f; padding-bottom: 6px; margin-bottom: 14px; font-size: 11px; color: #8a6a3a; }
.a4 .a4-head img { width: 26px; height: 26px; }
.a4 .a4-head .pg { margin-left: auto; }
.a4 .a4-body { font-size: 12.2px; line-height: 1.68; text-align: justify; word-break: keep-all; overflow-wrap: anywhere; }
.a4 .a4-foot { border-top: 1px solid #ccc; padding-top: 6px; margin-top: 8px; }
.a4 .b-h { font-weight: 700; font-size: 13px; margin: 14px 0 6px; }
.a4 .b-h:first-child { margin-top: 0; }
.a4 .b-p, .a4 .b-c, .a4 .b-i, .a4 .b-i2, .a4 .b-s { margin: 0 0 6px; }
.a4 .b-i { padding-left: 1.2em; }
.a4 .b-i2 { padding-left: 2.2em; }
.a4 .b-s { padding-left: 2em; }
.a4 .b-title { text-align: center; font-weight: 700; font-size: 15px; margin: 0 0 6px; }
.a4 .b-center { text-align: center; font-weight: 700; margin: 8px 0; }
.a4 .b-right { text-align: right; font-size: 11px; margin: 0 0 4px; }
.a4 .b-special { white-space: pre-wrap; border: 1px solid #bbb; min-height: 120px; padding: 8px 10px; margin-bottom: 8px; }
.a4 table.ct { width: 100%; border-collapse: collapse; margin: 4px 0 10px; font-size: 11px; line-height: 1.4; }
.a4 table.ct th, .a4 table.ct td { border: 1px solid #555; padding: 4px 5px; vertical-align: middle; text-align: center; word-break: keep-all; }
.a4 table.ct th { background: #f4ede2; font-weight: 700; }
.a4 table.ct.sm { font-size: 9.2px; }
.a4 table.ct.sm th, .a4 table.ct.sm td { padding: 3px 2px; }
.a4 table.ct td.l { text-align: left; }
.a4 .tbl-wrap { width: 100%; }

/* 페이지 하단 확인 서명란 */
.a4 .confirm { display: flex; align-items: center; justify-content: flex-end; gap: 8px; font-size: 11.5px; }
.a4 .confirm .lbl { margin-right: auto; color: #333; }
.a4 .sigbox { width: 92px; height: 40px; border: 1px solid #999; display: inline-flex; align-items: center; justify-content: center; position: relative; background: #fff; }
.a4 .sigbox img { max-width: 88px; max-height: 38px; }
.a4 .sigbox .need { font: inherit; font-size: 11px; border: 0; background: #fff4e3; color: var(--brand-d); width: 100%; height: 100%; cursor: pointer; font-weight: 700; }
.a4 .pno { text-align: center; font-size: 11px; color: #555; margin-top: 4px; }

/* 표지 */
.a4 .cover { text-align: center; padding-top: 10px; }
.a4 .cover-type { text-align: left; font-size: 13px; }
.a4 .cover-logo { width: 150px; margin: 60px auto 10px; display: block; }
.a4 .cover h1 { font-size: 40px; letter-spacing: 14px; margin: 10px 0 70px; font-weight: 700; }
.a4 .cover table.ct { font-size: 13px; width: 86%; margin: 0 auto 40px; }
.a4 .cover table.ct th { width: 34%; }
.a4 .cover table.ct td { text-align: left; padding: 8px 10px; }
.a4 .cover .fill { font-weight: 700; color: #0b3d91; }
.a4 .cover-note { font-size: 12px; text-align: left; border-top: 1px solid #ccc; padding-top: 10px; }

/* 기입란 */
.a4 .fill { font-weight: 700; color: #0b3d91; }
.a4 .blank { color: #aaa; font-weight: 400; }
.a4 .inl-sig { display: inline-block; vertical-align: middle; height: 34px; min-width: 60px; position: relative; }
.a4 .inl-sig img { height: 34px; max-width: 120px; }
.a4 .seal { height: 46px; vertical-align: middle; }
.a4 .party th { width: 15%; background: #f4ede2; font-size: 11px; }
.a4 .party td { text-align: left; font-size: 11.5px; }
.a4 .map-box { height: 560px; position: relative; background: #f3efe8; overflow: hidden; }
.a4 .map-box img { width: 100%; height: 100%; object-fit: cover; display: block; }
.a4 .map-box .kmap { width: 100%; height: 100%; }
.a4 .map-cap { font-size: 11px; color: #333; text-align: left; padding-top: 6px; }
.a4 .audit dt { font-weight: 700; }

/* 인쇄용 고정 A4 */
.paper-print { position: absolute; left: -10000px; top: 0; width: 794px; }
.paper-print .a4 { width: 794px; height: 1123px; padding: 40px 62px 26px; display: flex; flex-direction: column; overflow: hidden; }
.paper-print .a4 .a4-body { flex: 1; overflow: hidden; }
/* 원본 docx 와 동일한 쪽 배치(영업거점지역=21p, 계약당사자=22p, 총 23p)가 되도록 맞춘 값 */
.paper-print .a4 .a4-body { font-size: 13.6px; line-height: 1.9; }
.paper-print .a4 .b-p, .paper-print .a4 .b-c, .paper-print .a4 .b-i, .paper-print .a4 .b-s, .paper-print .a4 .b-i2 { margin-bottom: 10px; }
.paper-print .a4 .b-h { font-size: 15px; margin: 20px 0 8px; }
.paper-print .a4 table.ct.sm { font-size: 11px; }
.paper-print .a4 table.ct.sm th, .paper-print .a4 table.ct.sm td { padding: 6px 3px; }
.paper-print .a4[data-kind=parties] .a4-body, .paper-print .a4[data-kind=request] .a4-body, .paper-print .a4[data-kind=map] .a4-body, .paper-print .a4[data-kind=audit] .a4-body { font-size: 12.5px; line-height: 1.6; }
.paper-print .need { display: none; }
.paper-print .screen-only { display: none !important; }

/* 화면 열람용 */
.paper-screen .a4 { width: 100%; border-radius: 10px; border: 1px solid var(--line); padding: 18px 16px 12px; margin-bottom: 14px; box-shadow: 0 2px 6px rgba(60,40,10,.06); }
.paper-screen .a4 .a4-body { font-size: 14.5px; line-height: 1.75; }
.paper-screen .a4 .b-h { font-size: 15.5px; }
.paper-screen .a4 .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.paper-screen .a4 table.ct.sm { min-width: 720px; font-size: 11px; }
.paper-screen .a4 .cover-logo { margin-top: 24px; width: 120px; }
.paper-screen .a4 .cover h1 { margin-bottom: 30px; font-size: 32px; }
.paper-screen .a4 .cover table.ct { width: 100%; font-size: 14px; }
.paper-screen .a4 .map-box { height: 380px; }
.paper-screen .a4.confirmed { border-color: #b8e2c1; }
.paper-screen .a4 .confirm { font-size: 13px; }
.paper-screen .a4 .sigbox { width: 110px; height: 46px; }
.paper-screen .a4.flash { animation: flash 1.2s; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--brand); } 100% { box-shadow: none; } }
@media (max-width: 480px) {
  .paper-screen .a4 .confirm .lbl { font-size: 12px; }
  .paper-screen .a4 table.party th { width: 22%; }
}
