/**
 * Tiptap Editor Styles - 출판용 에디터
 * 표, 각주, 하이라이트, 원어 지원
 */

.tiptap-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 8px 12px;
    background: var(--note-bg, #fff);
    border-bottom: 1px solid var(--note-border, #e2e8f0);
    position: sticky;
    top: 0;
    z-index: 10;
}

.tiptap-toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 4px;
    border-right: 1px solid var(--note-border, #e2e8f0);
}

.tiptap-toolbar-group:last-child {
    border-right: none;
}

.tiptap-toolbar button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--note-text, #2d3748);
    font-size: 14px;
    transition: all 0.15s ease;
}

.tiptap-toolbar button:hover {
    background: var(--note-hover, #f7fafc);
}

.tiptap-toolbar button.active {
    background: var(--primary-color, #4FD1C5);
    color: white;
}

.tiptap-toolbar button .material-icons {
    font-size: 18px;
}

.tiptap-toolbar select {
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--note-border, #e2e8f0);
    border-radius: 4px;
    background: var(--note-bg, #fff);
    color: var(--note-text, #2d3748);
    font-size: 13px;
    cursor: pointer;
}

.tiptap-toolbar select:focus {
    outline: none;
    border-color: var(--primary-color, #4FD1C5);
}

.tiptap-toolbar input[type="color"] {
    width: 32px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--note-border, #e2e8f0);
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

.toolbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
    padding: 4px 0;
}

.toolbar-row-primary {
    padding-bottom: 4px;
}

.toolbar-row-secondary {
    padding-top: 4px;
    border-top: 1px solid var(--note-border, #e2e8f0);
}

.toolbar-row-secondary.hidden {
    display: none;
}

.toolbar-more-toggle {
    margin-left: auto;
}

.tiptap-editor-content {
    min-height: 300px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    padding: 16px;
    outline: none;
    font-size: 15px;
    line-height: 1.7;
    color: var(--note-text, #2d3748);
}

.tiptap-editor-content:focus {
    outline: none;
}

.tiptap-editor-content p {
    margin: 0 0 0.75em;
}

.tiptap-editor-content h1 {
    font-size: 1.75em;
    font-weight: 700;
    margin: 1em 0 0.5em;
    color: var(--note-text, #2d3748);
}

.tiptap-editor-content h2 {
    font-size: 1.4em;
    font-weight: 600;
    margin: 0.9em 0 0.4em;
    color: var(--note-text, #2d3748);
}

.tiptap-editor-content h3 {
    font-size: 1.2em;
    font-weight: 600;
    margin: 0.8em 0 0.4em;
    color: var(--note-text, #2d3748);
}

.tiptap-editor-content h4 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0.7em 0 0.35em;
    color: var(--note-text, #2d3748);
}

.tiptap-editor-content blockquote {
    border-left: 4px solid var(--primary-color, #4FD1C5);
    margin: 1em 0;
    padding: 0.5em 1em;
    background: var(--note-hover, #f7fafc);
    border-radius: 0 8px 8px 0;
    font-style: italic;
    color: var(--note-text-sub, #718096);
}

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

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

/* 목록 내 헤더 스타일 유지 */
.tiptap-editor-content li > h1,
.tiptap-editor-content li > h2,
.tiptap-editor-content li > h3,
.tiptap-editor-content li > h4,
.tiptap-editor-content li h1,
.tiptap-editor-content li h2,
.tiptap-editor-content li h3,
.tiptap-editor-content li h4 {
    display: inline;
    margin: 0;
}

.tiptap-editor-content li > h1:first-child,
.tiptap-editor-content li > h2:first-child,
.tiptap-editor-content li > h3:first-child,
.tiptap-editor-content li > h4:first-child {
    display: block;
    margin: 0;
}

/* TaskList - 체크리스트 스타일 */
.tiptap-editor-content ul[data-type="taskList"] {
    list-style: none;
    padding-left: 0;
    margin: 0.5em 0;
}

.tiptap-editor-content ul[data-type="taskList"] li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0.35em 0;
    list-style: none !important;
}

.tiptap-editor-content ul[data-type="taskList"] li::before,
.tiptap-editor-content ul[data-type="taskList"] li::marker {
    content: none !important;
    display: none !important;
}

.tiptap-editor-content ul[data-type="taskList"] li > label {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.tiptap-editor-content ul[data-type="taskList"] li > label > input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color, #4FD1C5);
    border-radius: 4px;
}

.tiptap-editor-content ul[data-type="taskList"] li > div {
    flex: 1;
    min-width: 0;
}

.tiptap-editor-content ul[data-type="taskList"] li[data-checked="true"] > div {
    text-decoration: line-through;
    opacity: 0.6;
}

/* 중첩된 TaskList */
.tiptap-editor-content ul[data-type="taskList"] ul[data-type="taskList"] {
    padding-left: 1.5em;
}

/* 텍스트 정렬 */
.tiptap-editor-content p[style*="text-align: center"],
.tiptap-editor-content h1[style*="text-align: center"],
.tiptap-editor-content h2[style*="text-align: center"],
.tiptap-editor-content h3[style*="text-align: center"],
.tiptap-editor-content h4[style*="text-align: center"] {
    text-align: center;
}

.tiptap-editor-content p[style*="text-align: right"],
.tiptap-editor-content h1[style*="text-align: right"],
.tiptap-editor-content h2[style*="text-align: right"],
.tiptap-editor-content h3[style*="text-align: right"],
.tiptap-editor-content h4[style*="text-align: right"] {
    text-align: right;
}

.tiptap-editor-content p[style*="text-align: justify"],
.tiptap-editor-content h1[style*="text-align: justify"],
.tiptap-editor-content h2[style*="text-align: justify"],
.tiptap-editor-content h3[style*="text-align: justify"],
.tiptap-editor-content h4[style*="text-align: justify"] {
    text-align: justify;
}

.tiptap-editor-content a {
    color: var(--primary-color, #4FD1C5);
    text-decoration: underline;
    cursor: pointer;
}

.tiptap-editor-content a:hover {
    color: var(--note-secondary, #4299E1);
}

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

.tiptap-editor-content hr {
    border: none;
    border-top: 2px solid var(--note-border, #e2e8f0);
    margin: 1.5em 0;
}

.tiptap-editor-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
    margin: 1em 0;
}

.tiptap-editor-content code {
    background: var(--note-hover, #f7fafc);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
}

.tiptap-editor-content pre code {
    background: none;
    padding: 0;
}

.tiptap-editor-content mark {
    background-color: #ffeb3b;
    padding: 0.1em 0.2em;
    border-radius: 2px;
}

.tiptap-editor-content sub {
    font-size: 0.75em;
    vertical-align: sub;
}

.tiptap-editor-content sup {
    font-size: 0.75em;
    vertical-align: super;
}

.tiptap-table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
    overflow: hidden;
    border-radius: 8px;
    border: 1px solid var(--note-border, #e2e8f0);
}

.tiptap-table th,
.tiptap-table td {
    border: 1px solid var(--note-border, #e2e8f0);
    padding: 8px 12px;
    text-align: left;
    min-width: 80px;
    vertical-align: top;
}

.tiptap-table th {
    background: var(--note-hover, #f7fafc);
    font-weight: 600;
}

.tiptap-table tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.02);
}

.tiptap-editor-content .tiptap-table td:focus,
.tiptap-editor-content .tiptap-table th:focus {
    outline: 2px solid var(--primary-color, #4FD1C5);
    outline-offset: -2px;
}

.ProseMirror-selectednode {
    outline: 2px solid var(--primary-color, #4FD1C5);
}

.footnote-marker {
    color: var(--primary-color, #4FD1C5);
    font-weight: 600;
    cursor: help;
    font-size: 0.8em;
    vertical-align: super;
}

.footnote-marker:hover {
    color: var(--note-secondary, #4299E1);
}

.tiptap-editor-content .ProseMirror-gapcursor {
    position: relative;
}

.tiptap-editor-content .ProseMirror-gapcursor:after {
    content: "";
    position: absolute;
    width: 20px;
    height: 1px;
    top: -2px;
    left: 0;
    border-top: 1px solid var(--note-text, #2d3748);
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Placeholder rule moved to unified-note-editor.css to prevent duplication */

.table-controls {
    display: flex;
    gap: 4px;
    padding: 8px;
    background: var(--note-bg, #fff);
    border: 1px solid var(--note-border, #e2e8f0);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    position: absolute;
    z-index: 100;
}

.table-controls button {
    padding: 6px 10px;
    font-size: 12px;
    border: 1px solid var(--note-border, #e2e8f0);
    background: var(--note-bg, #fff);
    border-radius: 4px;
    cursor: pointer;
    color: var(--note-text, #2d3748);
}

.table-controls button:hover {
    background: var(--note-hover, #f7fafc);
}

.table-controls button.danger {
    color: #e53e3e;
    border-color: #e53e3e;
}

.table-controls button.danger:hover {
    background: #fff5f5;
}

.color-picker-popup {
    position: absolute;
    z-index: 100;
    background: var(--note-bg, #fff);
    border: 1px solid var(--note-border, #e2e8f0);
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: grid;
    grid-template-columns: repeat(8, 24px);
    gap: 4px;
}

.color-picker-popup .color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--note-border, #e2e8f0);
}

.color-picker-popup .color-swatch:hover {
    transform: scale(1.1);
}

.char-palette-btn {
    font-family: 'Ezra SIL SR', 'Gentium Plus', serif;
    font-size: 16px !important;
}

/* Details (접기/펼치기) 스타일 */
.tiptap-editor-content details.tiptap-details {
    background: var(--note-hover, #f7fafc);
    border: 1px solid var(--note-border, #e2e8f0);
    border-radius: 8px;
    margin: 1em 0;
    overflow: hidden;
}

.tiptap-editor-content details.tiptap-details summary {
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 600;
    background: linear-gradient(135deg, rgba(79, 209, 197, 0.1) 0%, rgba(66, 153, 225, 0.1) 100%);
    border-bottom: 1px solid var(--note-border, #e2e8f0);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tiptap-editor-content details.tiptap-details summary::before {
    content: '▶';
    font-size: 10px;
    transition: transform 0.2s ease;
}

.tiptap-editor-content details.tiptap-details[open] summary::before {
    transform: rotate(90deg);
}

.tiptap-editor-content details.tiptap-details[open] summary {
    border-bottom: 1px solid var(--note-border, #e2e8f0);
}

.tiptap-editor-content details.tiptap-details > *:not(summary) {
    padding: 12px 16px;
}

/* TOC (목차) 스타일 */
.tiptap-editor-content .tiptap-toc {
    background: linear-gradient(135deg, rgba(79, 209, 197, 0.1) 0%, rgba(66, 153, 225, 0.05) 100%);
    border: 1px solid var(--note-border, #e2e8f0);
    border-left: 4px solid var(--primary-color, #4FD1C5);
    border-radius: 0 8px 8px 0;
    padding: 12px 16px;
    margin: 1em 0;
}

.tiptap-editor-content .tiptap-toc > p {
    margin: 0 0 8px 0;
    color: var(--primary-color, #4FD1C5);
}

.tiptap-editor-content .tiptap-toc ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.tiptap-editor-content .tiptap-toc ul li {
    padding: 4px 0;
    color: var(--note-text, #2d3748);
    border-bottom: 1px dashed var(--note-border, #e2e8f0);
}

.tiptap-editor-content .tiptap-toc ul li:last-child {
    border-bottom: none;
}

/* 슬래시 명령 메뉴 스타일 */
.tiptap-slash-menu {
    font-size: 14px;
}

.tiptap-slash-menu .slash-cmd-item {
    transition: background 0.15s ease;
}

.tiptap-slash-menu .slash-cmd-item:hover,
.tiptap-slash-menu .slash-cmd-item.selected {
    background: var(--note-hover, #f7fafc);
}

.tiptap-slash-menu .slash-cmd-item .material-icons {
    font-size: 18px;
    color: var(--primary-color, #4FD1C5);
}

.tiptap-slash-menu .slash-cmd-hint {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-secondary, #718096);
    opacity: 0.7;
}

/* 노트 링크 스타일 */
.tiptap-editor-content .tiptap-note-link,
.tiptap-editor-content .tiptap-note-ref {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: linear-gradient(135deg, rgba(79, 209, 197, 0.15) 0%, rgba(66, 153, 225, 0.15) 100%);
    border: 1px solid var(--primary-color, #4FD1C5);
    border-radius: 4px;
    color: var(--primary-color, #4FD1C5);
    text-decoration: none;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tiptap-editor-content .tiptap-note-link:hover,
.tiptap-editor-content .tiptap-note-ref:hover {
    background: linear-gradient(135deg, rgba(79, 209, 197, 0.25) 0%, rgba(66, 153, 225, 0.25) 100%);
    transform: translateY(-1px);
}

/* 멘션(@) 메뉴 스타일 */
.tiptap-mention-menu {
    font-size: 14px;
}

.tiptap-mention-menu .mention-item {
    transition: background 0.15s ease;
}

.tiptap-mention-menu .mention-item:hover,
.tiptap-mention-menu .mention-item.selected {
    background: var(--note-hover, #f7fafc);
}

.tiptap-toolbar .divider {
    width: 1px;
    height: 24px;
    background: var(--note-border, #e2e8f0);
    margin: 0 4px;
}

[data-theme="dark"] .tiptap-editor-content pre {
    background: #0d1117;
}

[data-theme="dark"] .tiptap-table th {
    background: #2d3748;
}

[data-theme="dark"] .tiptap-table tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

@media (max-width: 768px) {
    .tiptap-toolbar {
        padding: 6px 8px;
    }
    
    .tiptap-toolbar button {
        width: 36px;
        height: 36px;
    }
    
    .tiptap-toolbar select {
        height: 36px;
        font-size: 12px;
    }
    
    .tiptap-editor-content {
        padding: 12px;
        font-size: 14px;
    }
    
    .toolbar-row-secondary {
        flex-wrap: wrap;
    }
}

/* ==================== 제목/부제목 스타일 ==================== */
/* 첫 번째 h1 제목은 중앙 정렬 */
.tiptap-editor-content > h1:first-of-type,
.tiptap-editor-content > p:first-child + h1 {
    text-align: center;
}

/* 제목 바로 다음 h2는 부제목 - 중앙 정렬 + 기울임 */
.tiptap-editor-content > h1:first-of-type + h2,
.tiptap-editor-content > h1:first-of-type + p + h2 {
    text-align: center;
    font-style: italic;
    font-weight: 400;
    color: var(--text-secondary, #666);
}

/* 명시적 title/subtitle 클래스 */
.tiptap-editor-content .note-title {
    text-align: center;
}

.tiptap-editor-content .note-subtitle {
    text-align: center;
    font-style: italic;
    font-weight: 400;
    color: var(--text-secondary, #666);
}

/* ==================== 헤더 + 목록 스타일 유지 ==================== */
/* 목록 내 헤더 스타일 유지 */
.tiptap-editor-content ul h1,
.tiptap-editor-content ul h2,
.tiptap-editor-content ul h3,
.tiptap-editor-content ul h4,
.tiptap-editor-content ol h1,
.tiptap-editor-content ol h2,
.tiptap-editor-content ol h3,
.tiptap-editor-content ol h4,
.tiptap-editor-content ul[data-type="taskList"] h1,
.tiptap-editor-content ul[data-type="taskList"] h2,
.tiptap-editor-content ul[data-type="taskList"] h3,
.tiptap-editor-content ul[data-type="taskList"] h4 {
    margin: 0;
    display: inline;
}

/* ==================== 각주 하단 영역 ==================== */
.footnotes-section {
    margin-top: 2em;
    padding-top: 1em;
    border-top: 1px solid var(--note-border, #e2e8f0);
}

.footnotes-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.footnote-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footnote-list-item {
    display: flex;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    line-height: 1.5;
    border-bottom: 1px dashed var(--note-border, #e2e8f0);
}

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

.footnote-list-number {
    flex-shrink: 0;
    color: var(--primary-color, #4FD1C5);
    font-weight: 600;
    min-width: 24px;
}

.footnote-list-content {
    color: var(--note-text-sub, #718096);
}

/* 각주 호버 팝업 */
.footnote-tooltip {
    position: absolute;
    z-index: 1000;
    background: var(--surface-color, #fff);
    border: 1px solid var(--note-border, #e2e8f0);
    border-radius: 8px;
    padding: 10px 14px;
    max-width: 300px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    font-size: 13px;
    line-height: 1.5;
    color: var(--note-text, #2d3748);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s, transform 0.2s;
}

.footnote-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.footnote-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 20px;
    width: 10px;
    height: 10px;
    background: var(--surface-color, #fff);
    border-left: 1px solid var(--note-border, #e2e8f0);
    border-top: 1px solid var(--note-border, #e2e8f0);
    transform: rotate(45deg);
}

/* Night mode 각주 */
body.night-mode .footnotes-section {
    border-top-color: rgba(255, 255, 255, 0.1);
}

body.night-mode .footnote-list-item {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

body.night-mode .footnote-tooltip {
    background: var(--surface-color, #2a2a2a);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

body.night-mode .footnote-tooltip::before {
    background: var(--surface-color, #2a2a2a);
    border-color: rgba(255, 255, 255, 0.2);
}
