:root {
  --accent: #7A2E2E;
  --accent-ink: #5d2121;
  --bg: #f7f3eb;
  --panel: #fffdf8;
  --paper: #ffffff;
  --ink: #23211f;
  --muted: #6f6760;
  --soft: #e7ded2;
  --soft-2: #d8cfc3;
  --warning: #a45118;
  --danger: #9a1f1f;
  --success: #28704a;
  --focus: #135d73;
  --preview-scale: 0.9;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: system-ui, Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  line-height: 1.6;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

textarea {
  resize: vertical;
}

::selection {
  color: #fff;
  background: var(--accent);
}

:focus-visible {
  outline: 3px solid rgba(19, 93, 115, 0.42);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 30;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: 6px;
  color: #fff;
  background: var(--focus);
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--soft);
  background: rgba(247, 243, 235, 0.96);
  backdrop-filter: blur(16px);
}

.app-header h1,
.preview-toolbar h2 {
  margin: 0;
  font-size: clamp(1.18rem, 1.4vw, 1.55rem);
  line-height: 1.25;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
}

.document-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.document-tabs a {
  padding: 8px 12px;
  border: 1px solid var(--soft);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.8);
  font-size: 0.88rem;
  font-weight: 900;
  text-decoration: none;
}

.document-tabs a[aria-current="page"] {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.header-actions,
.editor-toolbar,
.zoom-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.save-status {
  min-width: 112px;
  color: var(--muted);
  font-size: 0.87rem;
  text-align: right;
}

.button {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--soft-2);
  border-radius: 6px;
  color: var(--ink);
  background: #fffaf2;
  font-weight: 700;
  line-height: 1.2;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.button:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: #fff7ec;
}

.button:active {
  transform: translateY(1px);
}

.button.primary {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.button.primary:hover {
  color: #fff;
  background: var(--accent-ink);
}

.button.secondary {
  color: var(--accent-ink);
  background: #fbf0e8;
}

.button.danger {
  color: var(--danger);
}

.button.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.88rem;
}

.icon-button {
  width: 38px;
  min-width: 38px;
  padding: 8px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 77px);
}

body.editor-collapsed .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body.editor-collapsed .editor-panel {
  display: none;
}

.editor-panel {
  max-height: calc(100vh - 77px);
  overflow-y: auto;
  padding: 0 22px 22px;
  border-right: 1px solid var(--soft);
  background: var(--panel);
}

.editor-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -22px 18px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--soft);
  background: rgba(255, 253, 248, 0.97);
  backdrop-filter: blur(14px);
}

.privacy-note,
.guide-text {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.privacy-note {
  padding: 10px 12px;
  border: 1px solid var(--soft);
  border-radius: 6px;
  background: #f8f4ee;
}

.form-section,
.quality-panel {
  padding: 20px 0;
  border-bottom: 1px solid var(--soft);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 14px;
}

.section-heading.with-action {
  justify-content: space-between;
  gap: 18px;
}

.section-heading-title {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.section-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.section-toggle {
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--soft-2);
  border-radius: 6px;
  color: var(--muted);
  background: #fffaf2;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.1;
}

.section-toggle:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.section-content[hidden] {
  display: none;
}

.form-section.is-collapsed {
  padding-bottom: 14px;
}

.section-heading h2,
.quality-panel h2 {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.25;
}

.section-kicker {
  min-width: 28px;
  margin: 2px 0 0;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 900;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field.wide,
.field-grid .wide {
  grid-column: 1 / -1;
}

label,
.legend-label {
  color: #3b3630;
  font-size: 0.9rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--soft-2);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}

input,
select {
  min-height: 42px;
  padding: 9px 10px;
}

textarea {
  padding: 10px;
  line-height: 1.6;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #c8b9aa;
}

.field-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.field-meta .over-limit {
  color: var(--danger);
  font-weight: 800;
}

.field-meta .under-guide {
  color: var(--muted);
}

.field-over textarea,
.field-over input {
  border-color: var(--warning);
  background: #fff9f2;
}

.recommendation-box {
  margin: 12px 0 16px;
  padding: 12px;
  border: 1px solid var(--soft);
  border-radius: 6px;
  background: #fbf8f1;
}

.recommendation-box strong {
  display: block;
  margin-bottom: 6px;
}

.recommendation-box ul {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.recommendation-box li {
  padding: 5px 8px;
  border: 1px solid #dccfc0;
  border-radius: 999px;
  color: #4e453d;
  background: #fffdf8;
  font-size: 0.82rem;
}

.repeat-list {
  display: grid;
  gap: 14px;
}

.repeat-list.compact {
  gap: 10px;
}

.repeat-item {
  padding: 14px;
  border: 1px solid var(--soft);
  border-radius: 8px;
  background: #fffdf8;
}

.repeat-item.compact {
  padding: 12px;
}

.repeat-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.repeat-item-header h3 {
  margin: 0;
  font-size: 0.98rem;
}

.repeat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.repeat-grid .wide {
  grid-column: 1 / -1;
}

.repeat-subsection {
  padding: 12px;
  border: 1px solid var(--soft);
  border-radius: 8px;
  background: #fbf8f1;
}

.repeat-subsection-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.repeat-subsection-header .guide-text {
  margin: 4px 0 0;
}

.guide-split {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.quality-panel {
  border-bottom: 0;
}

.checklist,
.cliche-panel ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.checklist li {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 8px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid var(--soft);
  border-radius: 6px;
  background: #fffdf8;
  font-size: 0.88rem;
}

.checklist .status-mark {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #fff;
  font-size: 0.76rem;
  font-weight: 900;
}

.checklist .pass .status-mark {
  background: var(--success);
}

.checklist .fail .status-mark {
  background: var(--warning);
}

.cliche-panel {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #e0c3a5;
  border-radius: 6px;
  background: #fff8ef;
}

.cliche-panel h3 {
  margin: 0 0 6px;
  font-size: 0.98rem;
}

.cliche-panel p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.cliche-panel li {
  color: var(--warning);
  font-size: 0.88rem;
}

.preview-panel {
  min-width: 0;
  padding: 22px;
  background: #eee7dd;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 10px;
}

.preview-controls,
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.preview-controls {
  flex-wrap: wrap;
}

.zoom-controls input[type="range"] {
  width: 128px;
  min-height: auto;
  padding: 0;
  accent-color: var(--accent);
}

.zoom-controls output {
  min-width: 44px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  text-align: center;
}

.page-status {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.page-status.warning {
  color: var(--danger);
  font-weight: 800;
}

.paper-scroll {
  overflow: auto;
  max-height: calc(100vh - 185px);
  padding: 22px 0 44px;
}

.paper-stage {
  position: relative;
  width: calc(210mm * var(--preview-scale));
  min-height: calc(297mm * var(--preview-scale));
  margin: 0 auto;
}

@media (min-width: 1101px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .app-header {
    position: relative;
    top: auto;
  }

  .app-shell {
    min-height: 0;
    height: auto;
    overflow: hidden;
  }

  .editor-panel {
    height: 100%;
    max-height: none;
    min-height: 0;
  }

  .preview-panel {
    display: flex;
    min-height: 0;
    overflow: hidden;
    flex-direction: column;
  }

  .paper-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }
}

.paper {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  padding: 16mm;
  overflow: visible;
  transform: scale(var(--preview-scale));
  transform-origin: top left;
  border: 1px solid #d7cec2;
  background: var(--paper);
  box-shadow: 0 24px 48px rgba(32, 28, 24, 0.18);
}

.paper.paged-paper {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.paper.paged-paper #paperContent {
  display: grid;
  gap: 30px;
}

.preview-page {
  position: relative;
  width: 210mm;
  height: 297mm;
  padding: 16mm;
  overflow: visible;
  border: 1px solid #d7cec2;
  background: var(--paper);
  box-shadow: 0 24px 48px rgba(32, 28, 24, 0.18);
}

.preview-page-content {
  height: calc(297mm - 32mm);
}

.preview-page-content > .doc-section:first-child,
.preview-page-content > .doc-entry:first-child {
  margin-top: 0;
}

.preview-page::after {
  content: "";
  position: absolute;
  right: 16mm;
  bottom: 16mm;
  left: 16mm;
  height: 1px;
  background: rgba(122, 46, 46, 0.12);
  pointer-events: none;
}

.page-guides {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.page-guide {
  position: absolute;
  left: -10mm;
  right: -10mm;
  border-top: 1px dashed rgba(122, 46, 46, 0.55);
}

.page-guide span {
  position: absolute;
  top: -11px;
  right: -1mm;
  padding: 2px 6px;
  border: 1px solid rgba(122, 46, 46, 0.3);
  border-radius: 999px;
  color: var(--accent);
  background: #fffaf2;
  font-size: 10px;
  font-weight: 800;
}

.paper.paged-paper .page-guides {
  display: none;
}

.page-measure {
  position: absolute;
  width: 1px;
  height: 297mm;
  visibility: hidden;
  pointer-events: none;
}

#paperContent {
  position: relative;
  z-index: 2;
}

[data-preview-path] {
  border-radius: 3px;
  outline: 1px solid transparent;
  outline-offset: 2px;
  cursor: text;
  transition: background 0.15s ease, outline-color 0.15s ease;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

[data-preview-path]:hover {
  background: #fff7eb;
  outline-color: rgba(122, 46, 46, 0.18);
}

[data-preview-path]:focus {
  background: #fffaf0;
  outline-color: var(--accent);
}

.doc-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  padding-bottom: 13px;
  border-bottom: 1.5px solid var(--ink);
}

.doc-header h1 {
  margin: 3px 0 6px;
  font-size: 23pt;
  line-height: 1.1;
}

.doc-header .application-label {
  margin: 0;
  color: var(--accent);
  font-size: 8.8pt;
  font-weight: 900;
  letter-spacing: 0;
}

.doc-role {
  margin: 0;
  color: #403b35;
  font-size: 10.5pt;
  font-weight: 800;
}

.doc-contact {
  display: grid;
  gap: 3px;
  align-content: start;
  color: #4c4741;
  font-size: 8.4pt;
  line-height: 1.45;
  text-align: right;
}

.doc-contact span {
  overflow-wrap: anywhere;
}

.doc-section {
  margin-top: 19px;
  break-inside: auto;
}

.doc-section-title {
  margin: 0 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid #d8d0c7;
  color: #211f1d;
  font-size: 10.7pt;
  font-weight: 900;
  line-height: 1.25;
  break-after: avoid;
}

.doc-section p,
.doc-section li,
.doc-section dd {
  font-size: 9.8pt;
  line-height: 1.62;
}

.doc-paragraph {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.profile-line {
  padding: 7px 9px;
  border-left: 3px solid var(--accent);
  background: #fbf7f1;
  font-weight: 800;
}

.doc-meta-grid,
.doc-extra-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 18px;
  margin: 0;
}

.doc-meta-grid div,
.doc-extra-grid div {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  min-width: 0;
}

.doc-extra-grid div {
  grid-template-columns: 92px 1fr;
}

.doc-meta-grid dt,
.doc-extra-grid dt {
  color: #615950;
  font-size: 8.2pt;
  font-weight: 900;
}

.doc-meta-grid dd,
.doc-extra-grid dd {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.doc-entry {
  margin-top: 9px;
  break-inside: avoid;
}

.doc-entry + .doc-entry {
  padding-top: 9px;
  border-top: 1px solid #e3dcd4;
}

.doc-entry h3 {
  margin: 0 0 5px;
  color: var(--accent-ink);
  font-size: 10.1pt;
  line-height: 1.35;
}

.doc-definition-list {
  display: grid;
  gap: 4px;
  margin: 0;
}

.doc-definition-list div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 8px;
}

.doc-definition-list dt {
  color: #615950;
  font-size: 8.1pt;
  font-weight: 900;
}

.doc-definition-list dd {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.star-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.star-list li {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 8px;
}

.star-list strong {
  color: #615950;
  font-size: 8.1pt;
}

.star-list span {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.plan-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.plan-list li {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  break-inside: avoid;
}

.plan-list strong {
  color: var(--accent-ink);
}

.empty-preview {
  margin: 18px 0 0;
  padding: 10px 12px;
  border: 1px dashed #d5c8ba;
  color: var(--muted);
  background: #fffaf4;
  font-size: 9.4pt;
}

.avoid-break {
  break-inside: avoid;
  page-break-inside: avoid;
}

@media screen and (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .editor-panel {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--soft);
  }

  .paper-scroll {
    max-height: none;
  }
}

@media screen and (max-width: 760px) {
  .app-header,
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .document-tabs {
    justify-content: flex-start;
  }

  .header-actions,
  .editor-toolbar,
  .preview-controls,
  .zoom-controls {
    align-items: stretch;
  }

  .header-actions .button,
  .editor-toolbar .button {
    flex: 1 1 150px;
  }

  .field-grid,
  .repeat-grid {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    padding: 16px;
  }

  .editor-panel {
    padding: 0 16px 16px;
  }

  .editor-toolbar {
    margin: 0 -16px 16px;
    padding: 14px 16px;
  }

  .doc-header {
    grid-template-columns: 1fr;
  }

  .doc-contact {
    text-align: left;
  }
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  :root {
    --preview-scale: 1;
  }

  html,
  body {
    width: 210mm;
    min-height: 297mm;
    margin: 0;
    background: #fff;
  }

  body {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .skip-link,
  .app-header,
  .editor-panel,
  .preview-toolbar,
  .page-status,
  .page-guides,
  .page-measure {
    display: none !important;
  }

  .app-shell,
  .preview-panel,
  .paper-scroll,
  .paper-stage {
    display: block;
    width: 210mm !important;
    min-height: 0 !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .paper {
    width: 210mm !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 16mm 15.5mm;
    transform: none !important;
    border: 0;
    box-shadow: none;
    background: #fff;
  }

  .paper.paged-paper {
    width: 210mm !important;
    min-height: 0 !important;
    padding: 0 !important;
    background: transparent !important;
  }

  .paper.paged-paper #paperContent {
    display: block !important;
    gap: 0 !important;
    width: 210mm !important;
  }

  .paper.paged-paper .preview-page {
    display: block !important;
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    margin: 0 !important;
    padding: 16mm !important;
    overflow: visible !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    break-after: page;
    page-break-after: always;
  }

  .paper.paged-paper .preview-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .paper.paged-paper .preview-page-content {
    display: block !important;
    height: calc(297mm - 32mm) !important;
    min-height: calc(297mm - 32mm) !important;
  }

  .preview-page::after {
    display: none !important;
  }

  .doc-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) max-content !important;
    align-items: start !important;
    gap: 16px !important;
  }

  .doc-header > :first-child {
    min-width: 0 !important;
  }

  .doc-contact {
    justify-self: end !important;
    min-width: max-content !important;
    max-width: 72mm !important;
    text-align: right !important;
  }

  .doc-contact span {
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
  }

  a[href]::after {
    content: "";
  }

  [data-preview-path],
  [data-preview-path]:hover,
  [data-preview-path]:focus {
    background: transparent !important;
    outline: 0 !important;
  }

  .doc-section-title {
    break-after: avoid;
    page-break-after: avoid;
  }

  .doc-entry,
  .profile-line,
  .plan-list li,
  .doc-meta-grid,
  .doc-extra-grid {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .empty-preview {
    display: none;
  }
}
