/**
 * 에디터/뷰어 공통 CSS
 * 동일한 렌더 규칙을 공유하여 에디터 화면과 뷰어 화면의 일관성 유지
 */

/* 공통 컨테이너 */
.post-content,
.editor-content,
.post-detail-content {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.8;
    color: #333;
}

/* 타이포그래피 */
.post-content p,
.editor-content p,
.post-detail-content p {
    margin-bottom: 1em;
    line-height: 1.8;
}

.post-content h1,
.editor-content h1,
.post-detail-content h1,
.post-content h2,
.editor-content h2,
.post-detail-content h2,
.post-content h3,
.editor-content h3,
.post-detail-content h3,
.post-content h4,
.editor-content h4,
.post-detail-content h4,
.post-content h5,
.editor-content h5,
.post-detail-content h5,
.post-content h6,
.editor-content h6,
.post-detail-content h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
    color: #222;
}

.post-content h1,
.editor-content h1,
.post-detail-content h1 {
    font-size: 2em;
}

.post-content h2,
.editor-content h2,
.post-detail-content h2 {
    font-size: 1.5em;
}

.post-content h3,
.editor-content h3,
.post-detail-content h3 {
    font-size: 1.25em;
}

.post-content h4,
.editor-content h4,
.post-detail-content h4 {
    font-size: 1.1em;
}

/* 리스트 */
.post-content ul,
.editor-content ul,
.post-detail-content ul,
.post-content ol,
.editor-content ol,
.post-detail-content ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.post-content li,
.editor-content li,
.post-detail-content li {
    margin-bottom: 0.3em;
}

.post-content ul li,
.editor-content ul li,
.post-detail-content ul li {
    list-style-type: disc;
}

.post-content ol li,
.editor-content ol li,
.post-detail-content ol li {
    list-style-type: decimal;
}

/* Blockquote */
.post-content blockquote,
.editor-content blockquote,
.post-detail-content blockquote {
    margin: 1em 0;
    padding: 0.5em 1em;
    border-left: 4px solid #ccc;
    background-color: #f9f9f9;
    font-style: italic;
    color: #666;
}

/* Code */
.post-content code,
.editor-content code,
.post-detail-content code {
    background-color: #f0f0f0;
    border-radius: 3px;
    padding: 0 0.3em;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

.post-content pre,
.editor-content pre,
.post-detail-content pre {
    background-color: #f0f0f0;
    border-radius: 3px;
    padding: 1em;
    margin-bottom: 1em;
    white-space: pre-wrap;
    overflow-x: auto;
}

.post-content pre code,
.editor-content pre code,
.post-detail-content pre code {
    background-color: transparent;
    padding: 0;
}

/* 코드 블록 복사 단추 — 올려놓으면 나타난다 */
pre.has-code-copy {
    position: relative;
}

.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    background: none;
    color: var(--color-text-muted);
    font-size: 13px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease, color 0.12s ease;
}

pre.has-code-copy:hover .code-copy-btn,
.code-copy-btn:focus-visible,
.code-copy-btn.is-done {
    opacity: 1;
}

.code-copy-btn:hover {
    color: var(--color-text-primary);
}

.code-copy-btn.is-done {
    color: var(--color-success);
}

@media (hover: none) {
    .code-copy-btn {
        opacity: 1;
    }
}

/* 링크 */
.post-content a,
.editor-content a,
.post-detail-content a {
    color: var(--primary-color, #4a6da7);
    text-decoration: none;
    transition: color 0.2s ease;
}

.post-content a:hover,
.editor-content a:hover,
.post-detail-content a:hover {
    color: var(--primary-color-dark, #4d7a69);
    text-decoration: underline;
}

/* 이미지 */
.post-content img,
.editor-content img,
.post-detail-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.post-content .post-image-wrap,
.editor-content .post-image-wrap,
.post-detail-content .post-image-wrap {
    margin: 1rem 0;
}

.post-content .post-image-wrap[data-image-skeleton="true"],
.editor-content .post-image-wrap[data-image-skeleton="true"],
.post-detail-content .post-image-wrap[data-image-skeleton="true"] {
    position: relative;
    overflow: hidden;
    min-height: 180px;
    border-radius: 10px;
    background: var(--color-surface-alt);
}

.post-content .post-image-wrap[data-image-skeleton="true"]::before,
.editor-content .post-image-wrap[data-image-skeleton="true"]::before,
.post-detail-content .post-image-wrap[data-image-skeleton="true"]::before {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent 0%, var(--color-surface-raised) 50%, transparent 100%);
    animation: post-image-skeleton-shimmer 1.2s infinite;
    pointer-events: none;
}

.post-content .post-image-wrap[data-image-skeleton="true"] img,
.editor-content .post-image-wrap[data-image-skeleton="true"] img,
.post-detail-content .post-image-wrap[data-image-skeleton="true"] img {
    display: block; /* 글자 줄 위에 놓이면 아래에 글자 아래 공간만큼 틈이 생긴다 */
    opacity: 0;
    transition: opacity 0.2s ease;
}

.post-content .post-image-wrap[data-image-skeleton="true"].is-loaded::before,
.editor-content .post-image-wrap[data-image-skeleton="true"].is-loaded::before,
.post-detail-content .post-image-wrap[data-image-skeleton="true"].is-loaded::before,
.post-content .post-image-wrap[data-image-skeleton="true"].is-error::before,
.editor-content .post-image-wrap[data-image-skeleton="true"].is-error::before,
.post-detail-content .post-image-wrap[data-image-skeleton="true"].is-error::before {
    display: none;
}

.post-content .post-image-wrap[data-image-skeleton="true"].is-loaded img,
.editor-content .post-image-wrap[data-image-skeleton="true"].is-loaded img,
.post-detail-content .post-image-wrap[data-image-skeleton="true"].is-loaded img {
    opacity: 1;
}

/* 다 불러온 뒤에는 자리 표시 바탕을 지운다 — 사진과 모서리 반경이 달라 모서리에 비친다 */
.post-content .post-image-wrap[data-image-skeleton="true"].is-loaded,
.editor-content .post-image-wrap[data-image-skeleton="true"].is-loaded,
.post-detail-content .post-image-wrap[data-image-skeleton="true"].is-loaded {
    background: transparent;
}

@keyframes post-image-skeleton-shimmer {
    100% {
        transform: translateX(100%);
    }
}

/* 표 */
.post-content .post-table-wrap,
.editor-content .post-table-wrap,
.post-detail-content .post-table-wrap {
    width: 100%;
    overflow-x: auto;
    margin: 1rem 0;
}

.post-content .post-table,
.editor-content .post-table,
.post-detail-content .post-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 420px;
}

.post-content .post-table th,
.editor-content .post-table th,
.post-detail-content .post-table th,
.post-content .post-table td,
.editor-content .post-table td,
.post-detail-content .post-table td {
    border: 1px solid #d9d9d9;
    padding: 0.55rem 0.65rem;
    vertical-align: top;
}

.post-content .post-table th,
.editor-content .post-table th,
.post-detail-content .post-table th {
    background: #f5f7fb;
    font-weight: 700;
}

/* No-header-row tables: make first row look like header */
.post-content .post-table tr:first-child td,
.editor-content .post-table tr:first-child td,
.post-detail-content .post-table tr:first-child td {
    background: #f5f7fb;
    font-weight: 700;
}

.post-content .post-table td[data-visual-header-row="true"],
.editor-content .post-table td[data-visual-header-row="true"],
.post-detail-content .post-table td[data-visual-header-row="true"],
.post-content .post-table td[data-visual-header-column="true"],
.editor-content .post-table td[data-visual-header-column="true"],
.post-detail-content .post-table td[data-visual-header-column="true"] {
    background: #f5f7fb;
    font-weight: 700;
}

.ProseMirror table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.ProseMirror th,
.ProseMirror td {
    border: 1px solid #d9d9d9;
    padding: 0.45rem 0.6rem;
    vertical-align: top;
}

.ProseMirror th {
    background: #f5f7fb;
    font-weight: 700;
}

/* No-header-row tables in editor: first row as visual header */
.ProseMirror table tr:first-child td {
    background: #f5f7fb;
    font-weight: 700;
}

.ProseMirror td[data-visual-header-row="true"],
.ProseMirror td[data-visual-header-column="true"] {
    background: #f5f7fb;
    font-weight: 700;
}

/* 인라인 인용 스타일 */
.post-content .citation-inline,
.editor-content .citation-inline,
.post-detail-content .citation-inline {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 0.2em 0.4em;
    margin: 0 0.2em;
    border-radius: 4px;
    transition: all 0.2s ease;
    vertical-align: baseline;
}

.post-content .citation-inline:hover,
.editor-content .citation-inline:hover,
.post-detail-content .citation-inline:hover {
    background-color: color-mix(in srgb, var(--color-primary) 10%, transparent);
    border: 1px solid var(--primary-color, #4a6da7);
}

/* 인용 블록 공통 스타일 */
.post-content .classic-citation-block,
.editor-content .classic-citation-block,
.post-detail-content .classic-citation-block,
.post-content .chart-citation-block,
.editor-content .chart-citation-block,
.post-detail-content .chart-citation-block {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem;
    margin: 1.5rem 0;
    transition: all 0.2s ease;
    cursor: pointer;
}

.post-content .classic-citation-block:hover,
.editor-content .classic-citation-block:hover,
.post-detail-content .classic-citation-block:hover,
.post-content .chart-citation-block:hover,
.editor-content .chart-citation-block:hover,
.post-detail-content .chart-citation-block:hover {
    border-color: var(--primary-color, #5a8f7b);
    box-shadow: 0 2px 8px rgba(90, 143, 123, 0.1);
}

.post-content .classic-citation-block.selected,
.editor-content .classic-citation-block.selected,
.post-detail-content .classic-citation-block.selected,
.post-content .chart-citation-block.selected,
.editor-content .chart-citation-block.selected,
.post-detail-content .chart-citation-block.selected {
    border-color: var(--primary-color, #5a8f7b);
    background-color: #f0f7f4;
    box-shadow: 0 0 0 3px rgba(90, 143, 123, 0.1);
}

/* 고전 인용 블록 */
.post-content .classic-citation-block,
.editor-content .classic-citation-block,
.post-detail-content .classic-citation-block {
    background-color: #f9f9f9;
}

.post-content .classic-citation-block .citation-header,
.editor-content .classic-citation-block .citation-header,
.post-detail-content .classic-citation-block .citation-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--primary-color, #4a6da7);
}

.post-content .classic-citation-block .citation-icon,
.editor-content .classic-citation-block .citation-icon,
.post-detail-content .classic-citation-block .citation-icon {
    font-size: 1.2em;
}

.post-content .classic-citation-block .citation-content,
.editor-content .classic-citation-block .citation-content,
.post-detail-content .classic-citation-block .citation-content {
    font-size: 0.9rem;
    line-height: 1.6;
}

.post-content .classic-citation-block .citation-original,
.editor-content .classic-citation-block .citation-original,
.post-detail-content .classic-citation-block .citation-original {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background-color: #fff;
    border-radius: 4px;
    font-weight: 500;
}

.post-content .classic-citation-block .citation-translation,
.editor-content .classic-citation-block .citation-translation,
.post-detail-content .classic-citation-block .citation-translation {
    padding: 0.5rem;
    color: #666;
    font-style: italic;
}

/* 차트 인용 블록 */
.post-content .chart-citation-block,
.editor-content .chart-citation-block,
.post-detail-content .chart-citation-block {
    background-color: #f0f7ff;
}

.post-content .chart-citation-block .citation-header,
.editor-content .chart-citation-block .citation-header,
.post-detail-content .chart-citation-block .citation-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--primary-color, #4a6da7);
}

.post-content .chart-citation-block .citation-icon,
.editor-content .chart-citation-block .citation-icon,
.post-detail-content .chart-citation-block .citation-icon {
    font-size: 1.2em;
}

.post-content .chart-citation-block .citation-content,
.editor-content .chart-citation-block .citation-content,
.post-detail-content .chart-citation-block .citation-content {
    font-size: 0.9rem;
    line-height: 1.6;
    max-height: 600px;
    overflow: auto;
}

.post-content .chart-citation-block .citation-patient,
.editor-content .chart-citation-block .citation-patient,
.post-detail-content .chart-citation-block .citation-patient {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background-color: #fff;
    border-radius: 4px;
    font-weight: 500;
}

/* 필드 옵션 모달 버튼 (+) - 차트 인용 내부에서 사용 */
.post-content .field-option-modal-btn,
.editor-content .field-option-modal-btn,
.post-detail-content .field-option-modal-btn,
.chart-citation-block .field-option-modal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    margin-left: 4px;
    border: none;
    background: transparent;
    color: var(--primary-color, #4a6da7);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 0.7rem;
    flex-shrink: 0;
}

.post-content .field-option-modal-btn:hover,
.editor-content .field-option-modal-btn:hover,
.post-detail-content .field-option-modal-btn:hover,
.chart-citation-block .field-option-modal-btn:hover {
    background: color-mix(in srgb, var(--color-primary) 10%, transparent);
    color: #3a5a8a;
    transform: scale(1.1);
}

.post-content .field-option-modal-btn:active,
.editor-content .field-option-modal-btn:active,
.post-detail-content .field-option-modal-btn:active,
.chart-citation-block .field-option-modal-btn:active {
    transform: scale(0.95);
}

.post-content .field-option-modal-btn i,
.editor-content .field-option-modal-btn i,
.post-detail-content .field-option-modal-btn i,
.chart-citation-block .field-option-modal-btn i {
    pointer-events: none;
}


/* Horizontal rule */
.post-content hr,
.editor-content hr,
.post-detail-content hr {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 2em 0;
}

/* 텍스트 서식 */
.post-content strong,
.editor-content strong,
.post-detail-content strong {
    font-weight: bold;
}

.post-content em,
.editor-content em,
.post-detail-content em {
    font-style: italic;
}

.post-content u,
.editor-content u,
.post-detail-content u {
    text-decoration: underline;
}

.post-content s,
.editor-content s,
.post-detail-content s {
    text-decoration: line-through;
}

/* Tiptap 에디터 스타일 */
.ProseMirror {
    outline: none;
    padding: 1rem;
    min-height: 300px;
}

.ProseMirror:focus {
    outline: none;
}

.ProseMirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    color: #adb5bd;
    pointer-events: none;
    height: 0;
}

/* 반응형 */
@media (max-width: 768px) {

    .post-content,
    .editor-content,
    .post-detail-content {
        font-size: 0.95rem;
        line-height: 1.7;
    }

    .post-content h1,
    .editor-content h1,
    .post-detail-content h1 {
        font-size: 1.75em;
    }

    .post-content h2,
    .editor-content h2,
    .post-detail-content h2 {
        font-size: 1.4em;
    }

    .post-content .classic-citation-block,
    .editor-content .classic-citation-block,
    .post-detail-content .classic-citation-block,
    .post-content .chart-citation-block,
    .editor-content .chart-citation-block,
    .post-detail-content .chart-citation-block {
        padding: 0.75rem;
        margin: 1rem 0;
    }
}
