/* ---------- 내용증명 작성 페이지 ---------- */
.demo-badge {
  margin-right: auto; margin-left: 8px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em;
  color: var(--primary); border: 1px solid var(--primary);
  border-radius: 6px; padding: 1px 6px;
}

.mode-switch {
  position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 9;
  display: flex; gap: 6px; padding-top: 10px; padding-bottom: 10px;
  background: var(--bg);
}
.mode-switch button {
  flex: 1; height: 42px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font: inherit; font-weight: 600; cursor: pointer;
}
.mode-switch button[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

.editor-layout { padding-bottom: 24px; }
.editor-layout[data-mode="edit"] .preview-wrap { display: none; }
.editor-layout[data-mode="preview"] .editor { display: none; }

.sample-banner {
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--border));
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
}
.sample-banner[hidden] { display: none; }
.sample-banner p { margin: 0 0 10px; font-size: 0.9rem; }
.sample-banner .btn { width: 100%; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.panel h2 { margin: 0 0 12px; font-size: 1rem; }
.field { display: block; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; font-size: 0.88rem; font-weight: 600; margin-bottom: 4px; }
.req { color: #d64545; font-weight: 700; }
.field input, .field select, .field textarea {
  width: 100%; font: inherit; font-size: 16px; /* iOS 확대 방지 */
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.field textarea { resize: vertical; line-height: 1.7; min-height: 260px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent;
}
.hint { margin: 8px 0 0; font-size: 0.82rem; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.btn {
  height: 46px; padding: 0 18px; border-radius: 10px; font: inherit; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; flex: 1 1 100%; }
.btn.ghost { flex: 1; }
.preview-actions { margin-top: 12px; }
.notice { line-height: 1.7; }

/* ---------- 문서 미리보기 (A4 느낌) ---------- */
.preview-scale { overflow-x: auto; }
.doc {
  background: #fff; color: #111;
  width: 100%; max-width: 210mm; margin: 0 auto;
  padding: clamp(20px, 6vw, 25mm) clamp(16px, 5vw, 20mm);
  border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  font-family: "Batang", "바탕", "AppleMyungjo", "Noto Serif KR", serif;
  font-size: clamp(13px, 3.4vw, 15px); line-height: 1.85;
  word-break: keep-all;
}
.doc-heading { text-align: center; font-size: 1.9em; letter-spacing: 0.3em; margin: 0 0 1.4em; }
.doc-party { width: 100%; border-collapse: collapse; margin-bottom: 0.9em; font-size: 0.95em; }
.doc-party th, .doc-party td { border: 1px solid #333; padding: 0.35em 0.6em; text-align: left; vertical-align: middle; }
.doc-party th { white-space: nowrap; font-weight: 600; background: #f3f3f3; width: 4.5em; }
.doc-party th.doc-role { width: 4em; text-align: center; background: #e8e8e8; }
.doc-title { margin: 1.6em 0 1.2em; font-size: 1.1em; padding-bottom: 0.4em; border-bottom: 2px solid #333; }
.doc-body { white-space: pre-wrap; min-height: 8em; }
.doc-date { text-align: center; margin: 2.4em 0 1em; }
.doc-sign { text-align: right; margin: 0; }
.doc-sign b { margin: 0 0.6em; }
.doc-sign .seal { color: #555; }
.doc .empty { color: #aaa; font-weight: normal; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 0.9rem; transition: 0.2s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Desktop: 좌우 분할 ---------- */
@media (min-width: 900px) {
  .mode-switch { display: none; }
  .editor-layout {
    display: grid; grid-template-columns: minmax(340px, 420px) 1fr; gap: 24px;
    align-items: start; padding-top: 24px; max-width: 1280px;
  }
  .editor-layout[data-mode] .preview-wrap,
  .editor-layout[data-mode] .editor { display: block; }
  .preview-wrap { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; padding-bottom: 8px; }
  .preview-actions { display: none; }
  .toast { bottom: 24px; }
  .doc { font-size: 14px; padding: 22mm 18mm; }
}

/* ---------- 인쇄: 문서만 A4로 ---------- */
@media print {
  @page { size: A4; margin: 20mm 18mm; }
  body { background: #fff !important; padding: 0 !important; }
  .topbar, .tabbar, .mode-switch, .editor, .preview-actions, .notice, .toast { display: none !important; }
  .editor-layout, .editor-layout[data-mode] .preview-wrap { display: block !important; padding: 0; max-width: none; }
  .preview-wrap { position: static; max-height: none; overflow: visible; }
  .doc {
    border: 0; box-shadow: none; border-radius: 0; padding: 0; max-width: none;
    font-size: 11.5pt; color: #000;
  }
  .doc .empty { color: #000; }
  .doc-party th, .doc-party th.doc-role { background: none !important; }
}
