:root {
  --font: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg: #f2f6fb;
  --surface: #ffffff;
  --ink: #16202b;
  --sub: #55636f;
  --line: #d7e0ea;
  --accent: #1f5fae;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  font-size: 16px;
  line-height: 1.6;
}

img, svg { max-width: 100%; }

.site-header {
  padding: 24px 16px 8px;
  max-width: 1100px;
  margin: 0 auto;
}
.site-header .brand {
  margin: 0 0 4px;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.9rem;
}
.site-header h1 {
  margin: 0 0 8px;
  font-size: clamp(1.4rem, 4vw, 1.9rem);
}
.site-header .lead {
  margin: 0;
  color: var(--sub);
  max-width: 70ch;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

.form-panel, .preview-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

.form-panel h2, .preview-panel h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 16px;
  padding: 12px;
}
legend {
  font-weight: 700;
  padding: 0 6px;
}

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
/* 2026-09-29 위임 내용 길이 안내(비어 있으면 자리 차지 안 함) */
.field-hint { margin: 6px 0 0; font-size: 0.85rem; color: #8a4b00; }
.field-hint:empty { display: none; }

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

input[type="text"],
input[type="date"],
input[type="tel"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

textarea { resize: vertical; min-height: 96px; }

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.help-text {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--sub);
}

.privacy-note {
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: var(--sub);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.btn-main {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-sub {
  background: var(--surface);
  color: var(--ink);
}
.btn:hover { filter: brightness(0.97); }

/* ---- A4 미리보기 ---- */
.a4-scale-wrap {
  width: 100%;
  overflow: hidden;
  display: flex;
  justify-content: center;
  background: #e7ecf2;
  border-radius: 8px;
  padding: 12px 0;
}

.a4 {
  background: #ffffff;
  color: #111;
  width: 210mm;
  min-height: 297mm;
  padding: 18mm 16mm;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
  font-family: var(--font);
  transform-origin: top center;
  flex: 0 0 auto;
}

.a4-title {
  text-align: center;
  font-size: 1.7rem;
  letter-spacing: 0.3em;
  margin: 0 0 28px;
}

.a4-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.a4-table caption {
  text-align: left;
  font-weight: 700;
  margin-bottom: 6px;
  caption-side: top;
}
.a4-table th, .a4-table td {
  border: 1px solid #333;
  padding: 8px 10px;
  text-align: left;
  min-height: 1.6em;
}
.a4-table th {
  background: #f2f2f2;
  width: 30%;
  font-weight: 600;
}
.a4-table td {
  min-width: 4em;
}

.a4-content-block { margin: 20px 0; }
.a4-section-label {
  font-weight: 700;
  margin: 0 0 8px;
}
.a4-content {
  border: 1px solid #333;
  border-radius: 4px;
  min-height: 4.5em;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.a4-statement {
  text-align: center;
  margin: 28px 0;
  font-size: 1.05rem;
}

.a4-date {
  text-align: center;
  margin: 20px 0;
}

.a4-sign {
  text-align: right;
  margin: 24px 0 40px;
}
.a4-sign-name {
  display: inline-block;
  min-width: 6em;
  border-bottom: 1px solid #333;
  padding: 0 6px 2px;
  text-align: center;
}
.a4-sign-mark { margin-left: 6px; }

.a4-submit-to {
  text-align: left;
  font-size: 1.05rem;
  margin-top: 30px;
}

/* ---- 도움말 ---- */
.help {
  max-width: 1100px;
  margin: 8px auto 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.help h2 { margin-top: 0; font-size: 1.1rem; }
.help h3 { font-size: 1rem; margin-top: 24px; }
.help-list { padding-left: 1.2em; color: var(--ink); }
.help-list li { margin-bottom: 8px; }
.help details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.help summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.help details p { margin: 8px 0 0; color: var(--sub); }

/* ---- 바닥글 ---- */
.site-footer {
  max-width: 1100px;
  margin: 24px auto 0;
  padding: 16px;
  color: var(--sub);
  font-size: 0.85rem;
}
.site-footer .footer-brand {
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}
.footer-links {
  list-style: none;
  padding: 0;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 10px 0;
}
.footer-links a { color: var(--accent); }

/* ---- 좁은 화면(오너 폰: 갤럭시 Z 폴드5 접힘 약 360px, 펼침 약 1,100px 포함) ----
   1279px 까지는 한 칸(입력 -> 미리보기) 레이아웃을 유지한다. */
@media (max-width: 1279px) {
  .layout { grid-template-columns: 1fr; }
  .a4-scale-wrap { padding: 8px 0; }
}

/* 1280px 이상에서만 입력·미리보기를 나란히 놓는다 */
@media (min-width: 1280px) {
  .layout { grid-template-columns: 1fr 1fr; align-items: start; }
}

/* ---- 인쇄 ---- */
@page {
  size: A4;
  margin: 0;
}

/* 2026-09-27 인쇄 수정: visibility 방식은 숨긴 요소 자리가 남아 빈 장이 붙었다.
   A4 밖 요소는 display:none 으로 빼고, 화면용 축소(app.js fitA4 인라인 height/transform)를 풀고,
   A4 높이를 296mm 로 고정해 한 장을 넘지 않게 한다. */
@media print {
  html, body { margin: 0; padding: 0; background: #fff; }
  .skip,
  .site-header,
  .form-panel,
  .help,
  .site-footer,
  .preview-panel > h2 { display: none !important; }
  .layout,
  .preview-panel,
  .a4-scale-wrap {
    display: block;
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    height: auto !important;
    overflow: visible;
  }
  .a4 {
    position: static;
    width: 210mm;
    min-height: 0;
    height: auto;
    overflow: visible;
    margin: 0;
    box-shadow: none;
    transform: none !important;
    padding: 18mm 16mm;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    break-after: avoid;
    page-break-after: avoid;
  }
  /* 긴 위임 내용: 잘리지 않고 다음 장으로 — 날짜·서명·귀하 줄은 서로 떨어지지 않게 */
  /* 2026-09-29 「위임합니다」 문장도 날짜·서명과 같은 장에 붙인다 */
  .a4-statement { break-inside: avoid; break-after: avoid; page-break-after: avoid; }
  .a4-date { break-after: avoid; page-break-after: avoid; }
  .a4-sign, .a4-submit-to { break-inside: avoid; page-break-inside: avoid; break-before: avoid; }
}

/* 2026-09-27 web-design-guidelines 점검 반영: 본문 바로가기, 터치 반응, 제목 줄바꿈 */
.skip { position: absolute; left: 8px; top: -60px; z-index: 10; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none; }
.skip:focus-visible { top: 8px; }
button, a, select, summary { touch-action: manipulation; -webkit-tap-highlight-color: rgba(31, 95, 174, 0.15); }
h1, h2, h3 { text-wrap: balance; }
@media print { .skip { display: none; } }
body { word-break: keep-all; overflow-wrap: anywhere; }
