/* 레이아웃: 왼쪽은 입력 카드, 오른쪽은 책상 위에 놓인 A4 계약서. 좁은 화면에서는 위아래로 쌓는다. */
:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --desk: #e3e6ec;
  --fg: #1b2130;
  --muted: #5d6576;
  --line: #d6dbe4;
  --line-strong: #b9c0cd;
  --accent: #2446a6;        /* 볼펜 잉크색 */
  --accent-fg: #ffffff;
  --accent-weak: #e7ecfa;
  --ok: #1d7a4c;
  --ok-weak: #e3f3ea;
  --warn: #9a5b00;
  --warn-weak: #fbf0dc;
  --focus: #2f62ff;

  --font-ui: 'IBM Plex Sans KR', 'Malgun Gothic', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  --font-doc: 'Nanum Gothic', 'Malgun Gothic', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Noto Sans CJK KR', sans-serif;

  --header-h: 56px;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171e; --surface: #1c2029; --desk: #0f1217; --fg: #e6e9f0; --muted: #a3abbb;
    --line: #2e3442; --line-strong: #444c5e; --accent: #8ea8ff; --accent-fg: #0f1430; --accent-weak: #232c4a;
    --ok: #6fd3a0; --ok-weak: #1b3328; --warn: #f0b862; --warn-weak: #3a2c14; --focus: #8ea8ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171e; --surface: #1c2029; --desk: #0f1217; --fg: #e6e9f0; --muted: #a3abbb;
  --line: #2e3442; --line-strong: #444c5e; --accent: #8ea8ff; --accent-fg: #0f1430; --accent-weak: #232c4a;
  --ok: #6fd3a0; --ok-weak: #1b3328; --warn: #f0b862; --warn-weak: #3a2c14; --focus: #8ea8ff;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { text-wrap: balance; line-height: 1.3; }

/* ---------- 헤더 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.site-header .inner {
  max-width: 1360px; margin: 0 auto; padding-inline: 16px;
  height: var(--header-h); display: flex; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 8px; flex: none; white-space: nowrap; font-weight: 700; font-size: 17px; color: var(--fg); text-decoration: none; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.site-nav { display: flex; gap: 2px; margin-left: auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
@media (max-width: 480px) { .site-header .inner { gap: 10px; } .site-nav a { padding: 6px 7px; font-size: 13.5px; } .brand span { font-size: 16px; } }
.site-nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; }
.site-nav a:hover { color: var(--fg); background: var(--bg); }
.site-nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* ---------- 본문 ---------- */
.wrap { max-width: 1360px; margin: 0 auto; padding-inline: 16px; padding-block: 0 48px; }
.intro { padding-block: 28px 12px; display: grid; gap: 10px; }
.intro h1 { font-size: clamp(22px, 3.2vw, 30px); margin: 0; letter-spacing: -0.02em; }
.intro p { margin: 0; color: var(--muted); max-width: 66ch; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 4px 0 0; }
.badges li { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.badges li strong { color: var(--fg); font-weight: 600; }

/* ---------- 작업 영역 ---------- */
.workspace { display: grid; gap: 20px; margin-top: 12px; }
.form-pane { min-width: 0; }
.preview-pane { min-width: 0; background: var(--desk); border-radius: 14px; padding: 0 12px 16px; }

@media (min-width: 1080px) {
  .workspace { grid-template-columns: minmax(380px, 460px) minmax(0, 1fr); align-items: start; gap: 24px; }
  .preview-pane {
    position: sticky; top: calc(var(--header-h) + 12px);
    height: calc(100vh - var(--header-h) - 24px);
    overflow: auto; padding: 0 20px 20px;
  }
}

/* 미리보기 도구 막대 */
.toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 12px 0; background: var(--desk);
}
.toolbar .spacer { flex: 1; }
.toolbar .opt-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--fg); cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--fg); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); border-color: var(--line-strong); }
.btn svg { width: 16px; height: 16px; flex: none; }

/* 계약서 언어 선택 */
.langsel { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-top: 12px; }
.langsel-label { font-size: 13px; color: var(--muted); margin-right: 4px; }
.langsel label { position: relative; display: inline-flex; cursor: pointer; }
.langsel input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.langsel span:not(.langsel-label) {
  display: inline-flex; align-items: center; height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 13.5px; color: var(--fg);
}
.langsel input:checked + span { background: var(--fg); border-color: var(--fg); color: var(--bg); font-weight: 600; }
.langsel input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.lang-note { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); max-width: 72ch; }
.preview-pane .langsel + .lang-note + .toolbar, .preview-pane .langsel + .toolbar { padding-top: 8px; }

.viewport { position: relative; overflow: hidden; }
.save-status { font-size: 12.5px; color: var(--muted); padding: 2px 0 10px; min-height: 1.6em; }

/* ---------- 입력 폼 ---------- */
.form-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.form-head .hint { font-size: 13px; color: var(--muted); flex: 1 1 200px; }
form.doc-form { display: grid; gap: 10px; }

details.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
details.sec > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; font-weight: 600; font-size: 15.5px; user-select: none;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after {
  content: ''; width: 8px; height: 8px; border: solid var(--muted); border-width: 0 2px 2px 0;
  transform: rotate(45deg); margin-left: 4px; margin-top: -4px; transition: transform .15s;
}
details.sec[open] > summary::after { transform: rotate(-135deg); margin-top: 4px; }
.sec-no {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--accent-weak); color: var(--accent); font-variant-numeric: tabular-nums;
}
.sec-title { flex: 1; min-width: 0; }
.sec-count { font-size: 12px; font-weight: 500; color: var(--muted); padding: 1px 8px; border-radius: 999px; background: var(--bg); font-variant-numeric: tabular-nums; }
.sec-count.some { color: var(--accent); background: var(--accent-weak); }
.sec-count.done { color: var(--ok); background: var(--ok-weak); }
.sec-body { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px 10px; padding: 2px 14px 16px; }
.sec-desc { grid-column: 1 / -1; margin: 0; font-size: 13px; color: var(--muted); }

.fld { grid-column: span 6; min-width: 0; margin: 0; padding: 0; border: 0; border-radius: 8px; transition: background-color .4s; }
.fld-half { grid-column: span 3; }
.fld-third { grid-column: span 2; }
@media (max-width: 380px) { .fld-third { grid-column: span 3; } }
.fld.flash { background: var(--accent-weak); box-shadow: 0 0 0 6px var(--accent-weak); }
.fld > label, .fld > legend { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 500; color: var(--fg); margin-bottom: 5px; padding: 0; }
.tag { white-space: nowrap; font-size: 11px; font-weight: 600; color: var(--warn); background: var(--warn-weak); padding: 0 6px; border-radius: 4px; }
.ctl { position: relative; display: flex; align-items: center; }
.ctl input, .ctl textarea {
  width: 100%; min-width: 0; font: inherit; font-size: 15px; color: var(--fg);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 8px 10px; height: 42px;
}
.ctl textarea { height: auto; min-height: 84px; resize: vertical; line-height: 1.55; }
.ctl input:focus, .ctl textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.ctl input[inputmode="numeric"], .ctl input[inputmode="decimal"] { text-align: right; font-variant-numeric: tabular-nums; }
.ctl .unit { position: absolute; right: 10px; color: var(--muted); font-size: 14px; pointer-events: none; }
.ctl:has(.unit) input { padding-right: 34px; }
.ctl input::placeholder, .ctl textarea::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.help { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); min-height: 0; }
.help:empty { display: none; }
.fld[data-key] .help { font-variant-numeric: tabular-nums; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { position: relative; display: inline-flex; cursor: pointer; }
.opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.opt span {
  display: inline-flex; align-items: center; min-height: 36px; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 14px; line-height: 1.35;
}
.opt input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.opt input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.opt-check span { padding-left: 34px; position: relative; }
.opt-check span::before {
  content: ''; position: absolute; left: 11px; top: 50%; width: 15px; height: 15px; margin-top: -8px;
  border: 1.5px solid var(--line-strong); border-radius: 4px; background: var(--surface);
}
.opt-check input:checked + span::before { border-color: var(--accent-fg); background: transparent; }
.opt-check input:checked + span::after {
  content: ''; position: absolute; left: 16px; top: 50%; width: 5px; height: 9px; margin-top: -6px;
  border: solid var(--accent-fg); border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.chip {
  font: inherit; font-size: 12.5px; padding: 4px 10px; border-radius: 999px; cursor: pointer;
  border: 1px dashed var(--line-strong); background: transparent; color: var(--accent);
}
.chip:hover { border-style: solid; border-color: var(--accent); background: var(--accent-weak); }

/* ---------- 광고 슬롯 ---------- */
.ad-slot { margin-block: 16px; min-height: 0; text-align: center; }
.ad-slot .ad-label { display: block; font-size: 11px; color: var(--muted); letter-spacing: 0.08em; margin-bottom: 4px; }
.ad-slot.is-placeholder {
  min-height: 100px; display: grid; place-items: center; border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 60%, transparent);
}
form.doc-form .ad-slot { margin-block: 6px; }

/* ---------- 안내문 ---------- */
.guide { margin-top: 40px; display: grid; gap: 28px; }
.guide section { max-width: 820px; }
.guide h2 { font-size: 21px; margin: 0 0 10px; letter-spacing: -0.01em; }
.guide p, .guide li { color: var(--fg); }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.steps li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.steps b { display: block; margin-bottom: 4px; }
.steps span { color: var(--muted); font-size: 14px; }
.faq details { border-bottom: 1px solid var(--line); padding: 12px 2px; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { margin: 8px 0 0; color: var(--muted); }

.prose { max-width: 760px; padding-block: 28px 8px; }
.prose h1 { font-size: 26px; margin: 0 0 16px; }
.prose h2 { font-size: 18px; margin: 28px 0 8px; }
.prose p, .prose li { color: var(--fg); }
.prose table { border-collapse: collapse; width: 100%; font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface); }
.table-scroll { overflow-x: auto; }

/* ---------- 푸터 ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); }
.site-footer .inner { max-width: 1360px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 32px; display: grid; gap: 10px; font-size: 13px; color: var(--muted); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.site-footer a { color: var(--fg); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer p { margin: 0; max-width: 90ch; }

/* ---------- 모바일 하단 막대 ---------- */
.mobile-bar { display: none; }
@media (max-width: 1079.98px) {
  .mobile-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .mobile-bar .btn { flex: 1; height: 44px; }
  body.has-mobile-bar { padding-bottom: 72px; }
  .preview-pane .toolbar { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- 인쇄: 계약서 시트만 출력 ---------- */
@media print {
  body { background: #fff !important; padding: 0 !important; }
  .site-header, .intro, .form-pane, .toolbar, .langsel, .lang-note, .save-status, .guide, .site-footer, .mobile-bar,
  .ad-slot, ins.adsbygoogle, .google-auto-placed, .adsbygoogle, .no-print { display: none !important; }
  .wrap { max-width: none; padding: 0 !important; margin: 0; }
  .workspace { display: block; margin: 0; }
  .preview-pane { position: static; height: auto; overflow: visible; padding: 0; background: none; border-radius: 0; }
  .viewport { height: auto !important; overflow: visible; }
}
