/* Rich Text Editor Styles */
.rich-text-editor {
    border: 1px solid #E5E5E5;
    border-radius: 8px;
    overflow: hidden;
    background: white;
}

.editor-toolbar {
    background: white;
    border-bottom: 1px solid #D7D7D7;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 0;
    height: 52px;
    flex-wrap: wrap;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-text-style {
    font-family: 'Pretendard', sans-serif;
    font-weight: 400;
    font-size: 18px;
    line-height: 1.5;
    letter-spacing: -0.01em;
    color: #121212;
    width: 84px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: #D7D7D7;
    margin: 0 10px;
}

.toolbar-button {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: #565656; /* 기본 아이콘 컬러: gray 70 */
    transition: all 0.2s ease;
}

.toolbar-button:hover {
    background: #F7F7F8;
    color: #121212;
}

.toolbar-button.active {
    background: #F4FFF5; /* 클릭 시 배경 컬러: primary 2 */
    color: #03C124; /* 클릭 시 아이콘 컬러: primary 50 */
}

.toolbar-button.image-selected {
    background: #E6F9E9;
    color: #03C124;
    border: 2px solid #03C124;
}

/* 드롭다운 스타일 */
.toolbar-dropdown {
    position: relative;
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    min-width: 32px;
    width: 32px;
    height: 32px;
    justify-content: center;
}

/* 본문 드롭다운은 텍스트가 있으므로 더 넓게 */
.dropdown-trigger[data-action="text-size"] {
    width: auto;
    min-width: 80px;
    padding: 0 8px;
    justify-content: space-between;
}

/* 인용구, 정렬, 목록 드롭다운은 화살표가 있으므로 더 넓게 */
.dropdown-trigger[data-action="quote"],
.dropdown-trigger[data-action="text-align"],
.dropdown-trigger[data-action="list"] {
    width: auto;
    min-width: 50px;
    padding: 0 8px;
    justify-content: space-between;
}

.dropdown-text {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

/* 본문 드롭다운만 텍스트 표시, 나머지는 아이콘만 */
.dropdown-trigger:not([data-action="text-size"]) .dropdown-text {
    display: none;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #E5E5E5;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    min-width: 120px;
    display: none;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #121212;
    border-bottom: 1px solid #F7F7F8;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: #F7F7F8;
}

.dropdown-item.active {
    background: #F4FFF5;
    color: #03C124;
}

/* 컬러 팔레트 스타일 */
.color-palette {
    min-width: 180px;
    padding: 8px;
}

.color-section {
    margin-bottom: 8px;
}

.color-section:last-child {
    margin-bottom: 0;
}

.color-label {
    font-size: 12px;
    font-weight: 500;
    color: #565656;
    margin-bottom: 6px;
}

.color-row {
    display: flex;
    gap: 4px;
}

.color-btn {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.color-btn:hover {
    border-color: #03C124;
    transform: scale(1.1);
}

.color-btn.active {
    border-color: #03C124;
    box-shadow: 0 0 0 2px rgba(3, 193, 36, 0.2);
}

/* 색상 버튼 아이콘 스타일 */
.color-button-icon {
    position: relative;
    display: inline-block;
}

.color-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    border: 1px solid #E5E5E5;
    background: white;
    z-index: 10;
    display: block; /* 항상 표시 */
}

/* 색상 인디케이터 강제 표시 */
.color-indicator.force-show {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.editor-wrapper {
    position: relative;
}

.editor-placeholder {
    position: absolute;
    top: 16px;
    left: 16px;
    color: #8F8F8F;
    font-family: 'Pretendard', sans-serif;
    font-weight: 500;
    font-size: 20px;
    line-height: 1.4;
    letter-spacing: -0.025em;
    pointer-events: none;
    z-index: 1;
}

.editor-content {
    min-height: calc(100vh - 200px); /* 화면 높이에서 헤더/푸터 등 제외 */
    max-height: calc(100vh - 200px); /* 최대 높이 제한 */
    padding: 16px;
    border: none;
    outline: none;
    font-family: 'Pretendard', sans-serif;
    font-size: 18px;
    line-height: 1.5;
    color: #121212;
    background: white;
    resize: none;
    overflow-y: auto; /* 세로 스크롤 활성화 */
    overflow-x: hidden; /* 가로 스크롤 숨김 */
}

/* Tiptap 에디터 스타일 (study_edit.html 방식) */
.tiptap-editor {
    outline: none;
    min-height: calc(100vh - 250px); /* 화면 높이에서 헤더/푸터/툴바 등 제외 */
    max-height: calc(100vh - 250px); /* 최대 높이 제한 */
    padding: 12px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: white;
    overflow-y: auto; /* 세로 스크롤 활성화 */
    overflow-x: hidden; /* 가로 스크롤 숨김 */
}

.tiptap-editor:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* TipTap 콘텐츠 스타일 */
.tiptap-editor .ProseMirror {
    outline: none;
    min-height: calc(100vh - 300px); /* 화면 높이에서 헤더/푸터/툴바/패딩 등 제외 */
    max-height: calc(100vh - 300px); /* 최대 높이 제한 */
    overflow-y: auto; /* 세로 스크롤 활성화 */
    overflow-x: hidden; /* 가로 스크롤 숨김 */
}

/* ============================================
   Tiptap 공통 스타일 (에디터와 뷰어 모두에 적용)
   reset.css 오버라이드를 위해 !important 사용
   ============================================ */

/* Tiptap 공통 스타일 - 에디터와 뷰어 모두에 적용 */
.tiptap-editor,
.viewer-content {
    font-family: 'Pretendard', sans-serif !important;
}

/* Tiptap 공통 스타일 - reset.css 오버라이드 */
.tiptap-editor h1,
.tiptap-editor h2,
.tiptap-editor h3,
.tiptap-editor h4,
.tiptap-editor h5,
.tiptap-editor h6,
.viewer-content h1,
.viewer-content h2,
.viewer-content h3,
.viewer-content h4,
.viewer-content h5,
.viewer-content h6 {
    margin: 1em 0 0.5em 0 !important;
    padding: 0 !important;
    line-height: 1.4 !important;
    font-weight: 600 !important;
    color: #121212 !important;
    text-decoration: none !important;
    font-family: 'Pretendard', sans-serif !important;
    vertical-align: baseline !important;
}

.tiptap-editor h1,
.viewer-content h1 {
    font-size: 2em !important;
}

.tiptap-editor h2,
.viewer-content h2 {
    font-size: 1.5em !important;
}

.tiptap-editor h3,
.viewer-content h3 {
    font-size: 1.25em !important;
}

.tiptap-editor h4,
.viewer-content h4 {
    font-size: 1.1em !important;
}

.tiptap-editor h5,
.viewer-content h5 {
    font-size: 1em !important;
}

.tiptap-editor h6,
.viewer-content h6 {
    font-size: 0.9em !important;
}

.tiptap-editor p,
.viewer-content p {
    margin: 0.75em 0 !important;
    padding: 0 !important;
    line-height: 1.6 !important;
    color: #333 !important;
    font-family: 'Pretendard', sans-serif !important;
}

.tiptap-editor ul,
.tiptap-editor ol,
.viewer-content ul,
.viewer-content ol {
    margin: 0 0 16px 0 !important;
    padding: 0 0 0 24px !important;
    list-style: disc !important;
}

.tiptap-editor ol,
.viewer-content ol {
    list-style: decimal !important;
}

.tiptap-editor li,
.viewer-content li {
    margin: 4px 0 !important;
    padding: 0 !important;
    line-height: 1.6 !important;
    list-style: inherit !important;
}

.tiptap-editor a,
.viewer-content a {
    color: #03C124 !important;
    text-decoration: none !important;
}

.tiptap-editor a:hover,
.viewer-content a:hover {
    text-decoration: underline;
}

.tiptap-editor strong,
.tiptap-editor b,
.viewer-content strong,
.viewer-content b {
    font-weight: 600;
}

.tiptap-editor em,
.tiptap-editor i,
.viewer-content em,
.viewer-content i {
    font-style: italic;
}

.tiptap-editor u,
.viewer-content u {
    text-decoration: underline;
}

.tiptap-editor s,
.viewer-content s {
    text-decoration: line-through;
}

/* Tiptap 에디터 전용 스타일 */
.tiptap-editor h1 { 
    font-size: 36px; 
    font-weight: bold; 
    margin: 1em 0 0.5em 0;
    line-height: 1.2;
}

.tiptap-editor h2 { 
    font-size: 28px; 
    font-weight: bold; 
    margin: 1em 0 0.5em 0;
    line-height: 1.3;
}

.tiptap-editor h3 { 
    font-size: 24px; 
    font-weight: bold; 
    margin: 1em 0 0.5em 0;
    line-height: 1.4;
}

.tiptap-editor h4 { 
    font-size: 20px; 
    font-weight: bold; 
    margin: 1em 0 0.5em 0;
    line-height: 1.4;
}

.tiptap-editor p { 
    font-size: 18px; 
    line-height: 1.6; 
    margin-bottom: 1em; 
}

.tiptap-editor ul, 
.tiptap-editor ol {
    padding-left: 1.5em;
    margin: 1em 0;
}

.tiptap-editor li {
    margin: 0.5em 0;
}

.tiptap-editor blockquote {
    border-left: 4px solid #e5e7eb;
    padding-left: 1em;
    margin: 1em 0;
    font-style: italic;
    color: #6b7280;
}

.tiptap-editor hr {
    border: none;
    border-top: 2px solid var(--gray-300);
    margin: 2em 0;
}

.tiptap-editor img {
    max-width: 100%;
    height: auto;
    margin: 1em 0;
    border-radius: 4px;
}

/* Tiptap TextAlign extension을 사용한 이미지 정렬 */
.tiptap-editor img[style*="text-align: left"] {
    display: block;
    margin: 1em 0;
}

.tiptap-editor img[style*="text-align: center"] {
    display: block;
    margin: 1em auto;
}

.tiptap-editor img[style*="text-align: right"] {
    display: block;
    margin: 1em 0 1em auto;
}

/* 이미지 선택 상태 표시 */
.tiptap-editor img.ProseMirror-selectednode {
    outline: 2px solid #03C124;
    outline-offset: 2px;
    border-radius: 4px;
    position: relative;
}

/* 이미지 선택 시 호버 효과 */
.tiptap-editor img:hover {
    outline: 4px solid #03C124;
    outline-offset: 1px;
    cursor: pointer;
}

/* 이미지 선택 시 전체 테두리 표시 */
.tiptap-editor img.image-selected {
    outline: 4px solid #03C124 !important;
    outline-offset: 1px;
    border-radius: 4px;
    position: relative;
    z-index: 1000;
}

.tiptap-editor a {
    color: #3b82f6;
    text-decoration: underline;
}

.tiptap-editor a:hover {
    color: #1d4ed8;
}

/* 인용구 스타일 */
.quote-with-quotes {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    margin: 16px 0;
    background: white;
    border: 1px dashed #9747FF;
    border-radius: 5px;
    gap: 8px;
}

.quote-mark-top,
.quote-mark-bottom {
    font-size: 48px;
    color: #BABABA;
    font-weight: 300;
    line-height: 1;
    text-align: center;
    width: 100%;
}

.quote-content {
    font-family: 'Pretendard', sans-serif;
    font-weight: 600;
    font-size: 24px;
    line-height: 1.34;
    letter-spacing: -0.02em;
    text-align: center;
    color: #000000;
    width: 100%;
    padding: 8px 0;
}

/* 툴바 버튼 활성 상태 */
.toolbar-button.is-active {
    background: #E6F9E9;
    color: #03C124;
}

.editor-placeholder.hidden {
    display: none;
}

/* Loading Spinner Styles */
.editor-loading-spinner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner-container {
    text-align: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #03C124;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-container p {
    color: #565656;
    font-family: 'Pretendard', sans-serif;
    font-weight: 600;
    font-size: 18px;
    line-height: 1.5;
    letter-spacing: -0.025em;
    margin: 0;
}

/* Mobile Styles */
@media (max-width: 768px) {
    .editor-toolbar {
        gap: 8px;
        padding: 0 12px;
        height: auto;
        min-height: 52px;
    }
    
    .toolbar-section {
        gap: 4px;
    }
    
    .toolbar-button {
        width: 28px;
        height: 28px;
    }
    
    .toolbar-divider {
        margin: 0 6px;
    }
    
    .editor-content {
        min-height: calc(100vh - 150px); /* 모바일에서 화면 높이 조정 */
        max-height: calc(100vh - 150px);
        font-size: 16px;
    }
    
    .tiptap-editor {
        min-height: calc(100vh - 200px); /* 모바일에서 화면 높이 조정 */
        max-height: calc(100vh - 200px);
    }
    
    .tiptap-editor .ProseMirror {
        min-height: calc(100vh - 250px); /* 모바일에서 화면 높이 조정 */
        max-height: calc(100vh - 250px);
    }
    
    .editor-placeholder {
        font-size: 18px;
    }
}

/* 링크 모달 스타일 */
.link-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.link-modal {
    background: white;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    width: 600px;
    padding: 28px 32px;
    position: relative;
}

.link-modal-title {
    font-family: 'Pretendard', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: #565656;
    margin-bottom: 12px;
}

.link-modal-input-wrapper {
    position: relative;
    margin-bottom: 4px;
}

.link-modal-input {
    width: 100%;
    padding: 12px;
    border: 1px solid #D7D7D7;
    border-radius: 8px;
    font-family: 'Pretendard', sans-serif;
    font-size: 16px;
    color: #121212;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.link-modal-input:focus {
    border-color: #03C124;
    caret-color: #03C124;
}

.link-modal-error {
    font-family: 'Pretendard', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: #E82929;
    margin-top: -8px;
    margin-bottom: 16px;
}

.link-modal-buttons {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 32px;
}

.link-modal-btn {
    padding: 12px 36.5px;
    border-radius: 8px;
    font-family: 'Pretendard', sans-serif;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.link-modal-btn-cancel {
    background: white;
    color: #565656;
    border: 1px solid #D7D7D7;
}

.link-modal-btn-cancel:hover {
    background: #F7F7F8;
}

.link-modal-btn-submit {
    background: #D7D7D7;
    color: #8F8F8F;
}

.link-modal-btn-submit:not(:disabled) {
    background: #03C124;
    color: white;
}

.link-modal-btn-submit:not(:disabled):hover {
    background: #027416;
}

.link-modal-btn-submit:disabled {
    cursor: not-allowed;
}

/* 모바일 스타일 */
@media (max-width: 768px) {
    .link-modal {
        width: 90%;
        max-width: 600px;
        padding: 24px 20px;
    }
    
    .link-modal-buttons {
        flex-direction: column;
    }
    
    .link-modal-btn {
        width: 100%;
    }
}

