/* Shared document content styles — editor screen & print preview (1:1) */

.doc-title-input {
  display: block;
  border: none;
  outline: none;
  background: transparent;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #141b2b;
  margin: 0 auto;
}

.doc-page {
  position: relative;
  background-color: #ffffff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.1);
  border-radius: 2px;
  box-sizing: border-box;
  overflow: visible;
  color: #1f2330;
  font-family: var(--doc-font, inherit);
  font-size: var(--doc-base, 16px);
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
  word-break: break-word;
}

/* Word/HWPX 원본 페이지 단위 — 페이지 경계 유지, 잘림 없음 */
.doc-page[data-imported-fixed="true"],
.doc-page[data-page-mm-w] {
  overflow: visible;
}

.doc-page:has(.doc-page-body) {
  display: flex;
  flex-direction: column;
}

.doc-page-header,
.doc-page-footer {
  flex-shrink: 0;
  pointer-events: none;
}

.doc-page[data-imported-fixed="true"] .doc-page-footer,
.doc-page[data-page-mm-w] .doc-page-footer {
  margin-top: auto;
}

.doc-page-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Word/HWPX 임포트 — 인라인 스타일이 에디터 기본 타이포에 덮이지 않도록 */
.doc-page[data-imported-fixed="true"] .doc-page-body p,
.doc-page[data-page-mm-w] .doc-page-body p {
  margin: revert-layer;
  line-height: unset;
  letter-spacing: unset;
  text-align: unset;
}

.doc-page[data-imported-fixed="true"] .doc-page-body :is(h1, h2, h3, h4, h5, h6),
.doc-page[data-page-mm-w] .doc-page-body :is(h1, h2, h3, h4, h5, h6) {
  font-size: revert-layer;
  font-weight: revert-layer;
  margin: revert-layer;
  line-height: unset;
  letter-spacing: unset;
  text-align: unset;
}

.doc-page[data-imported-fixed="true"] .doc-page-body li,
.doc-page[data-page-mm-w] .doc-page-body li {
  line-height: unset;
  letter-spacing: unset;
  text-align: unset;
}

.doc-page[data-imported-fixed="true"] .doc-page-body :is(blockquote, pre),
.doc-page[data-page-mm-w] .doc-page-body :is(blockquote, pre) {
  line-height: unset;
  letter-spacing: unset;
  text-align: unset;
}

.doc-page[data-imported-fixed="true"] .doc-page-body p[style],
.doc-page[data-page-mm-w] .doc-page-body p[style] {
  margin: revert;
  font-size: revert;
}

.doc-page[data-imported-fixed="true"] .doc-page-body :is(h1, h2, h3, h4, h5, h6)[style],
.doc-page[data-page-mm-w] .doc-page-body :is(h1, h2, h3, h4, h5, h6)[style] {
  font-size: revert;
  font-weight: revert;
  margin: revert;
}

.doc-page[data-imported-fixed="true"] .doc-page-body li[style],
.doc-page[data-page-mm-w] .doc-page-body li[style] {
  font-size: revert;
  margin: revert;
}

.doc-page[data-imported-fixed="true"] .doc-page-body :is(blockquote, pre)[style],
.doc-page[data-page-mm-w] .doc-page-body :is(blockquote, pre)[style] {
  font-size: revert;
  margin: revert;
}

.doc-page[data-imported-fixed="true"] .doc-page-body span[style]:not(.doc-sel-fmt),
.doc-page[data-page-mm-w] .doc-page-body span[style]:not(.doc-sel-fmt) {
  font-size: revert;
  font-family: revert;
  font-weight: revert;
  font-style: revert;
  text-decoration: revert;
  color: revert;
  vertical-align: revert;
}

.doc-page[data-imported-fixed="true"] .doc-table td p[style],
.doc-page[data-imported-fixed="true"] .doc-table th p[style],
.doc-page[data-page-mm-w] .doc-table td p[style],
.doc-page[data-page-mm-w] .doc-table th p[style] {
  margin: revert;
  font-size: revert;
}

.doc-page[data-imported-fixed="true"] .doc-table td span[style]:not(.doc-sel-fmt),
.doc-page[data-imported-fixed="true"] .doc-table th span[style]:not(.doc-sel-fmt),
.doc-page[data-page-mm-w] .doc-table td span[style]:not(.doc-sel-fmt),
.doc-page[data-page-mm-w] .doc-table th span[style]:not(.doc-sel-fmt) {
  font-size: revert;
  font-family: revert;
  font-weight: revert;
  font-style: revert;
  text-decoration: revert;
  color: revert;
}

.doc-page li[data-list-marker] {
  list-style: none;
}

.doc-page li[data-list-marker]::before {
  content: attr(data-list-marker) " ";
}

/* 페이지 편집 모드 — 워드(흐름) / 자유(캔버스) */
.doc-page--word,
.doc-page[data-editor-mode="word"] {
  position: relative;
  overflow: hidden;
}

.doc-page--free,
.doc-page[data-editor-mode="free"],
.doc-page[data-editor-mode="block"] {
  position: relative;
  overflow: visible;
  background-image: linear-gradient(
      to right,
      rgba(70, 72, 212, 0.04) 1px,
      transparent 1px
    ),
    linear-gradient(to bottom, rgba(70, 72, 212, 0.04) 1px, transparent 1px);
  background-size: 24px 24px;
}

.doc-page-canvas {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  width: auto;
  min-height: 100%;
  cursor: default;
  overflow: visible;
}

.doc-page--free .doc-page-body,
.doc-page[data-editor-mode="free"] .doc-page-body,
.doc-page[data-editor-mode="block"] .doc-page-body {
  position: relative;
  min-height: 100%;
}

.doc-freeblock {
  position: absolute;
  min-width: 120px;
  cursor: grab;
  border: 1px dashed transparent;
  border-radius: 4px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  touch-action: none;
}

.doc-freeblock:hover,
.doc-freeblock:focus-within {
  border-color: rgba(70, 72, 212, 0.35);
  box-shadow: 0 0 0 2px rgba(70, 72, 212, 0.08);
}

.doc-freeblock > *:first-child {
  margin-top: 0;
}

.doc-freeblock > *:last-child {
  margin-bottom: 0;
}

.doc-freeblock-grip {
  position: absolute;
  top: -10px;
  left: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 18px;
  border-radius: 4px;
  opacity: 0;
  cursor: grab;
  z-index: 2;
}

.doc-freeblock-grip::before {
  content: "⠿";
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: #4648d4;
  font-size: 10px;
  color: #fff;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

/* 블록 삭제 버튼 */
.doc-freeblock-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: #e53e3e;
  border: none;
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.1s ease, background 0.1s ease;
  pointer-events: none;
}

.doc-freeblock:hover .doc-freeblock-delete,
.doc-freeblock:focus-within .doc-freeblock-delete,
.doc-block-frame--sel .doc-freeblock-delete {
  opacity: 1;
  pointer-events: auto;
}

.doc-freeblock-delete:hover {
  background: #c53030;
}

.doc-freeblock:hover .doc-freeblock-grip,
.doc-freeblock:focus-within .doc-freeblock-grip,
.doc-freeblock--dragging .doc-freeblock-grip {
  opacity: 1;
}

.doc-freeblock--dragging {
  cursor: grabbing;
  border-color: rgba(70, 72, 212, 0.55);
  box-shadow: 0 4px 16px rgba(70, 72, 212, 0.18);
  z-index: 5;
}

.doc-freeblock--resizing {
  border-color: rgba(70, 72, 212, 0.55);
  box-shadow: 0 0 0 2px rgba(70, 72, 212, 0.12);
  z-index: 5;
}

.doc-freeblock-resize {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #4648d4;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  cursor: nwse-resize;
  opacity: 0;
  z-index: 4;
}

.doc-freeblock:hover .doc-freeblock-resize,
.doc-freeblock--sel .doc-freeblock-resize,
.doc-freeblock--resizing .doc-freeblock-resize {
  opacity: 1;
}

/* 컨테이너 블록 — 표 등 여러 개체 수용 */
.doc-block-frame {
  min-height: 72px;
}

.doc-block-frame--sel {
  border-color: rgba(70, 72, 212, 0.65);
  box-shadow: 0 0 0 2px rgba(70, 72, 212, 0.15);
}

.doc-block-frame-body {
  position: relative;
  min-height: 40px;
  padding: 8px 10px 6px;
  outline: none;
  cursor: grab;
}

.doc-block-frame-body > *:first-child {
  margin-top: 0;
}

.doc-block-frame-body > *:last-child {
  margin-bottom: 0;
}

.doc-block-frame-body .doc-tableblock,
.doc-block-frame-body .doc-imgblock {
  margin: 0.35em 0;
}

.doc-page--free .doc-block-frame-body .doc-imgblock,
.doc-page[data-editor-mode="free"] .doc-block-frame-body .doc-imgblock {
  margin: 0;
}

/* 추가 바 — 블록 박스 바깥(아래쪽)에 표시 */
.doc-block-frame-addbar {
  position: absolute;
  top: 100%;
  right: 0;
  bottom: auto;
  margin-top: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 3;
}

.doc-block-frame:hover .doc-block-frame-addbar,
.doc-block-frame--sel .doc-block-frame-addbar,
.doc-block-frame:focus-within .doc-block-frame-addbar {
  opacity: 1;
}

.doc-block-frame-addbar button {
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #464554;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 999px;
  cursor: pointer;
}

.doc-block-frame-addbar button:hover {
  border-color: #4648d4;
  color: #4648d4;
  background: #f1f3ff;
}

/* 페이지 여백 안내선 — 본문 영역 경계 (편집기 전용, 저장 제외) */
.doc-page-margin-guides {
  position: absolute;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 4;
  border: 1px dashed rgba(70, 72, 212, 0.42);
  border-radius: 1px;
}

.doc-page > *:first-child {
  margin-top: 0;
}

.doc-page p {
  margin: 0;
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page h1 {
  font-size: var(--doc-h1, 26px);
  font-weight: 700;
  margin: 0.8em 0 0.4em;
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page h2 {
  font-size: var(--doc-h2, 21px);
  font-weight: 700;
  margin: 0.7em 0 0.4em;
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page h3 {
  font-size: var(--doc-h3, 18px);
  font-weight: 700;
  margin: 0.6em 0 0.3em;
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page h4 {
  font-size: var(--doc-h4, 16px);
  font-weight: 700;
  margin: 0.6em 0 0.3em;
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page h5 {
  font-size: var(--doc-h5, 15px);
  font-weight: 700;
  margin: 0.5em 0 0.3em;
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page h6 {
  font-size: var(--doc-h6, 14px);
  font-weight: 700;
  margin: 0.5em 0 0.3em;
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page ul,
.doc-page ol {
  margin: 0 0 1em;
  padding-left: 1.5em;
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page li {
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-page ul {
  list-style: disc;
}

.doc-page ol {
  list-style: decimal;
}

.doc-page a {
  color: #4648d4;
  text-decoration: underline;
}

.doc-page img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.doc-pagebreak {
  height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

/* ---- Table block ---- */
.doc-tableblock {
  position: relative;
  margin: 0 0 1.75em;
  overflow: visible;
  max-width: 100%;
}

.doc-table {
  border-collapse: collapse;
  width: 100%;
  table-layout: auto;
}

.doc-table.doc-table--sized {
  table-layout: fixed;
}

.doc-table td:not([style]),
.doc-table th:not([style]) {
  border: 1px solid #d1d5db;
  padding: 6px 8px;
  vertical-align: top;
  min-width: 2.5em;
}

.doc-table th:not([style]) {
  font-weight: 700;
  background-color: #f1f3ff;
  color: #141b2b;
}

.doc-table td[style],
.doc-table th[style] {
  padding: 6px 8px;
}

.doc-table p {
  margin: 0;
  line-height: inherit;
  letter-spacing: inherit;
}

.doc-table td,
.doc-table th {
  line-height: var(--doc-line-height, 1.9);
  letter-spacing: var(--doc-letter-spacing, 0em);
}

.doc-tableblock[data-align="center"] {
  margin-left: auto;
  margin-right: auto;
}

.doc-tableblock[data-align="right"] {
  margin-left: auto;
  margin-right: 0;
}

/* ---- Image block ---- */
.doc-imgblock {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 1em;
  overflow: hidden;
  position: relative;
}

.doc-imgcells {
  display: grid;
  gap: 8px;
  width: 100%;
}

.doc-imgblock[data-layout="single"] .doc-imgcells {
  grid-template-columns: 1fr;
}

.doc-imgblock[data-layout="two"] .doc-imgcells {
  grid-template-columns: 1fr 1fr;
}

.doc-imgblock[data-layout="three"] .doc-imgcells {
  grid-template-columns: repeat(3, 1fr);
}

.doc-imgblock[data-layout="row"] .doc-imgcells {
  display: flex;
}

.doc-imgblock[data-layout="row"] .doc-imgcells > img {
  flex: 1 1 0;
  min-width: 0;
}

.doc-imgcells > img,
.doc-imgblock > img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  height: var(--cell-h, auto);
  object-fit: cover;
  border-radius: 4px;
  background: transparent;
  margin: 0;
}

.doc-imgblock[data-align="left"] {
  margin-right: auto;
}

.doc-imgblock[data-align="center"] {
  margin-left: auto;
  margin-right: auto;
}

.doc-imgblock[data-align="right"] {
  margin-left: auto;
}

.doc-imgblock[data-layout="single"] .doc-imgcells > img,
.doc-imgblock[data-layout="single"] > img {
  aspect-ratio: 16 / 9;
}

.doc-imgblock[data-fit="cover"] img {
  object-fit: cover;
}

.doc-imgblock[data-fit="contain"] img {
  object-fit: contain;
}

.doc-imgblock[data-fit="fill"] img {
  object-fit: fill;
}

.doc-imgcaption {
  width: 100%;
  margin: 0;
  padding: 2px 0 0;
  font-size: 0.85em;
  line-height: 1.5;
  color: #464554;
  text-align: center;
  white-space: pre-wrap;
  word-break: break-word;
}

.doc-imgcaption.doc-imgcaption--hidden,
.doc-imgcaption:empty {
  display: none;
}

.doc-imgblock--sel .doc-imgcaption.doc-imgcaption--hidden,
.doc-imgblock--sel .doc-imgcaption:empty {
  display: block;
}

.doc-imgblock[data-align="left"] .doc-imgcaption {
  text-align: left;
}

.doc-imgblock[data-align="right"] .doc-imgcaption {
  text-align: right;
}

/* ---- Print preview (screen + paper) ---- */
.doc-print {
  margin: 0;
  padding: 0;
  background: #fff;
}

.doc-print .doc-page.print-sheet {
  box-shadow: none;
  border-radius: 0;
  margin: 0;
  overflow: hidden;
  page-break-after: always;
  break-after: page;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.doc-print .doc-page.print-sheet:last-child {
  page-break-after: auto;
  break-after: auto;
}

.doc-print .doc-page.print-sheet::after {
  display: none !important;
}

.doc-print .doc-table-handle,
.doc-print .doc-pagebreak {
  display: none !important;
}

.doc-print .doc-imgcaption.doc-imgcaption--hidden,
.doc-print .doc-imgcaption:empty {
  display: none !important;
}

.doc-divider-block {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  margin: 4px 0;
}

.doc-divider-block svg {
  width: min(100%, 320px);
  height: auto;
  display: block;
}
