/* ===== TipTap 3.x 에디터 기본 스타일 ===== */
.ProseMirror { 
  outline: none; 
  min-height: 40vh; 
  cursor: text;
  user-select: text;
  /* Tiptap 3.x 공백 처리 최적화 */
  white-space: normal;
  word-wrap: break-word;
  /* 공백 입력 문제 해결 */
  word-spacing: normal;
  letter-spacing: normal;
}

/* 모바일에서 에디터 최소 높이를 키보드 높이만큼 추가 */
@media (max-width: 767px) {
  .ProseMirror {
    min-height: calc(40vh + 360px) !important; /* 기본 높이 + 키보드 높이 */
  }
}

/* Tiptap 3.x 공백 입력 문제 해결을 위한 설정 */
.ProseMirror p,
.ProseMirror h1,
.ProseMirror h2,
.ProseMirror h3,
.ProseMirror h4,
.ProseMirror h5,
.ProseMirror h6 {
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ===== TipTap 에디터 스크롤바 커스터마이징 ===== */
/* Webkit 기반 브라우저 (Chrome, Safari, Edge) */
.ProseMirror::-webkit-scrollbar {
  width: 8px;
}

.ProseMirror::-webkit-scrollbar-track {
  background: transparent;
}

.ProseMirror::-webkit-scrollbar-thumb {
  background: #dcfce7; /* 아주 옅은 초록색 */
  border-radius: 4px;
  border: 1px solid #bbf7d0;
  transition: transform 0.2s ease;
}

.ProseMirror::-webkit-scrollbar-thumb:hover {
  transform: scale(1.1); /* 호버 시 살짝 확대 */
}

/* 위아래 화살표 버튼 제거 */
.ProseMirror::-webkit-scrollbar-button {
  display: none;
}

/* Firefox */
.ProseMirror {
  scrollbar-width: thin;
  scrollbar-color: #dcfce7 transparent;
}

/* 모바일에서 스크롤바 숨김 */
@media (max-width: 768px) {
  .ProseMirror::-webkit-scrollbar {
    display: none;
  }
  
  .ProseMirror {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
}

.ProseMirror p { 
  color: #374151; 
  line-height: 1.9; 
}

/* ===== Placeholder 스타일 ===== */
.ProseMirror p.is-editor-empty:first-child::before {
  color: #9ca3af;
  content: attr(data-placeholder);
  float: left;
  height: 0;
  pointer-events: none;
  font-style: normal;
  font-size: 0.95em;
}

/* ===== 텍스트 정렬 스타일 ===== */
.ProseMirror p[style*="text-align: left"],
.ProseMirror h1[style*="text-align: left"],
.ProseMirror h2[style*="text-align: left"],
.ProseMirror h3[style*="text-align: left"],
.ProseMirror h4[style*="text-align: left"],
.ProseMirror h5[style*="text-align: left"],
.ProseMirror h6[style*="text-align: left"] {
  text-align: left !important;
}

.ProseMirror p[style*="text-align: center"],
.ProseMirror h1[style*="text-align: center"],
.ProseMirror h2[style*="text-align: center"],
.ProseMirror h3[style*="text-align: center"],
.ProseMirror h4[style*="text-align: center"],
.ProseMirror h5[style*="text-align: center"],
.ProseMirror h6[style*="text-align: center"] {
  text-align: center !important;
}

.ProseMirror p[style*="text-align: right"],
.ProseMirror h1[style*="text-align: right"],
.ProseMirror h2[style*="text-align: right"],
.ProseMirror h3[style*="text-align: right"],
.ProseMirror h4[style*="text-align: right"],
.ProseMirror h5[style*="text-align: right"],
.ProseMirror h6[style*="text-align: right"] {
  text-align: right !important;
}

.ProseMirror p[style*="text-align: justify"],
.ProseMirror h1[style*="text-align: justify"],
.ProseMirror h2[style*="text-align: justify"],
.ProseMirror h3[style*="text-align: justify"],
.ProseMirror h4[style*="text-align: justify"],
.ProseMirror h5[style*="text-align: justify"],
.ProseMirror h6[style*="text-align: justify"] {
  text-align: justify !important;
}

.ProseMirror a { 
  color: #2563eb; 
  text-decoration: underline dotted; 
}

/* ===== 에디터 텍스트 줄바꿈 설정 ===== */
#editor {
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  max-width: 100%;
  overflow-x: hidden;
  cursor: text;
  user-select: text;
  pointer-events: auto;
  /* 공백 입력 문제 해결 */
  word-spacing: normal;
  letter-spacing: normal;
}

/* 에디터 내부 요소들 줄바꿈 */
#editor * {
  word-wrap: break-word !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  max-width: 100% !important;
}

/* 코드 블록이나 pre 태그 줄바꿈 */
#editor pre, #editor code {
  white-space: pre-wrap !important;
  word-break: break-all !important;
  overflow-x: hidden !important;
}

/* ===== 기본 밑줄/취소선 색상 제거 - 커스텀 마크에서 관리 ===== */
.ProseMirror u{ 
  text-decoration-thickness:3px; 
  text-underline-offset: 2px; 
}

.ProseMirror s{ 
  text-decoration-thickness:3px; 
}

/* ===== 볼드 스타일이 모든 커스텀 마크와 함께 작동하도록 보장 ===== */
.ProseMirror strong, 
.ProseMirror b,
.ProseMirror span[data-underline-styled] strong,
.ProseMirror span[data-underline-styled] b {
  /* 기본 볼드 스타일 */
}

/* ===== 커스텀 스타일드 마크 ===== */
.ProseMirror span[data-underline-styled] { 
  text-decoration: none; /* 기본 밑줄 제거 */
  text-underline-offset: 2px; 
  word-break: break-word; /* 줄바꿈 시 밑줄 겹침 방지 */
  overflow-wrap: break-word; /* 긴 단어 줄바꿈 */
}

/* Fix underline breaking issue */
.ProseMirror span[data-underline-styled] {
  text-decoration: none; /* 기본 밑줄 제거 */
  text-decoration-skip-ink: none;
  text-decoration-skip: none;
  text-underline-offset: 2px;
  word-break: break-word; /* 줄바꿈 시 밑줄 겹침 방지 */
  overflow-wrap: break-word; /* 긴 단어 줄바꿈 */
}

/* ===== 물결 밑줄과 취소선을 위한 기본 스타일 ===== */
.ProseMirror span[data-underline-styled][data-underline-style="wavy"] {
  /* CSS text-decoration-style: wavy가 자동으로 처리 */
}

.ProseMirror span[data-strike-styled][data-strike-style="wavy"] {
  /* CSS text-decoration-style: wavy가 자동으로 처리 */
}

/* ===== 커스텀 구분선 스타일링 ===== */
.ProseMirror hr {
  width: 80% !important;
  margin: 12px auto !important;
  border: none !important;
  height: 3px !important;
  background-image: repeating-linear-gradient(90deg, transparent, transparent 4px, #e5e7eb 4px, #e5e7eb 8px) !important;
  background-color: transparent !important;
}

/* ===== YouTube 임베드 스타일 ===== */
.youtube-embed-container {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 20px auto;
  text-align: center;
}

.youtube-embed {
  width: 100%;
  height: 315px;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  border: 1px solid #e5e7eb;
}

/* 반응형 YouTube 임베드 */
@media (max-width: 768px) {
  .youtube-embed {
    height: 200px;
  }
}



.ProseMirror .node-imageWrapper[data-align="right"] {
  margin-left: auto;
  margin-right: 0;
}

/* Image styles within the wrapper */
.ProseMirror .node-imageWrapper img {
  display: block;
  margin: 0; /* Margin is handled by the wrapper */
  cursor: default; /* Let the wrapper handle cursor */
}

/* Force auto width on the resize wrapper's inner div */
.ProseMirror .ProseMirror-selectednode > div {
    width: auto !important;
}

/* Pop-up alignment toolbar styles (Restored) */
.ProseMirror .node-imageWrapper .alignment-buttons {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: #333;
  border-radius: 6px;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
  z-index: 10;
  pointer-events: none;
}

.ProseMirror .node-imageWrapper:hover .alignment-buttons,
.ProseMirror .node-imageWrapper.ProseMirror-selectednode .alignment-buttons {
  opacity: 1;
  pointer-events: auto;
}

.ProseMirror .node-imageWrapper .alignment-buttons button {
  background: transparent;
  border: none;
  color: white;
  padding: 4px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.ProseMirror .node-imageWrapper .alignment-buttons button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ProseMirror .node-imageWrapper .alignment-buttons button.active {
  background: #3b82f6;
}

.ProseMirror .node-imageWrapper .alignment-buttons button svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ===== Tiptap 3.x 공백 입력 문제 해결 스타일 ===== */
/* 기본 텍스트 요소에서 공백 처리 */
.ProseMirror p,
.ProseMirror h1,
.ProseMirror h2,
.ProseMirror h3,
.ProseMirror h4,
.ProseMirror h5,
.ProseMirror h6 {
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Tiptap 3.x 공백 입력 시 발생할 수 있는 문제 방지 */
.ProseMirror {
  text-rendering: optimizeLegibility;
  -webkit-font-feature-settings: "liga" 1, "kern" 1;
  font-feature-settings: "liga" 1, "kern" 1;
}

/* Tiptap 3.x 공백 입력 최적화 */
.ProseMirror * {
  word-spacing: normal;
  letter-spacing: normal;
}

/* ===== 모바일 에디터 여백 설정 ===== */
@media (max-width: 767px) {
  .ProseMirror {
    padding: 1rem !important;
    margin: 0 !important;
  }
  
  /* 에디터 컨테이너 모바일 여백 조정 */
  #editorContainer {
    padding: 1rem !important;
    background: white !important; /* 하얀 배경 */
  }
  
  /* 에디터 내부 요소들 모바일 여백 */
  .ProseMirror p,
  .ProseMirror h1,
  .ProseMirror h2,
  .ProseMirror h3,
  .ProseMirror h4,
  .ProseMirror h5,
  .ProseMirror h6 {
    margin-bottom: 0.75rem !important;
    margin-top: 0.75rem !important;
  }
  
  .ProseMirror p:first-child,
  .ProseMirror h1:first-child,
  .ProseMirror h2:first-child,
  .ProseMirror h3:first-child,
  .ProseMirror h4:first-child,
  .ProseMirror h5:first-child,
  .ProseMirror h6:first-child {
    margin-top: 0 !important;
  }
  
  .ProseMirror p:last-child,
  .ProseMirror h1:last-child,
  .ProseMirror h2:last-child,
  .ProseMirror h3:last-child,
  .ProseMirror h4:last-child,
  .ProseMirror h5:last-child,
  .ProseMirror h6:last-child {
    margin-bottom: 0 !important;
  }
  
  /* 모바일에서 에디터 하단에 키보드 여백 추가 (360px) - 하얀 배경 */
  .ProseMirror {
    padding-bottom: 360px !important; /* 키보드 여백 추가 */
    background: white !important;
  }
}
