/* =========================================
   Post Editor Editor CSS (Tiptap/ProseMirror)
   ========================================= */

/* Hidden sync field: keep in DOM for submit payload only */
#postContent {
    display: none !important;
}

/* Title row (desktop): title + save button */
.title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.1rem;
}

/* Editor Toolbar - Desktop Defaults */
#editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 14px;
    flex-wrap: wrap;
    overflow-x: auto;
    white-space: nowrap;
    margin-top: 0;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    width: min(1180px, calc(100vw - 28px));
    z-index: 4000;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#editor-toolbar::-webkit-scrollbar {
    display: none;
}

/* Post Header (Title, Category, Tags) Styles */
.post-title {
    flex: 1 1 auto;
    max-width: none;
    padding: 12px 15px;
    font-size: 1.4rem;
    font-weight: 700;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    /* Slightly rounded for premium feel */
    margin-bottom: 0;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.title-row #savePost {
    flex: 0 0 auto;
    min-width: 86px;
    height: 44px;
    padding: 0.5rem 0.9rem;
    margin-left: 0;
}

/* 파란 포커스 링은 쓰지 않는다(원장 지시 260918) — 테두리 한 단계만 밝힌다.
   데스크톱에서는 제목 테두리 자체가 없어 아무 변화도 보이지 않는다. */
.post-title:focus {
    outline: none;
    border-color: #a9b3bf;
    box-shadow: none;
}

.post-meta {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.post-category {
    flex: 1;
    padding: 0 15px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.95rem;
    height: 44px;
    /* Consistent height */
    background-color: #fcfcfc;
}

.post-tags {
    flex: 2;
    padding: 10px 15px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.95rem;
    height: 44px;
    box-sizing: border-box;
    background-color: #fcfcfc;
}

/* Mobile/Tablet Toolbar Override */
@media (max-width: 1024px) {
    #editor-toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Firefox */
        -ms-overflow-style: none;
        /* IE/Edge */
        padding: 0.5rem;
    }
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background-color: #e0e0e0;
    margin: 0 0.25rem;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    color: #555;
    font-size: 0.9rem;
    transition: all 0.2s;
    min-width: 32px;
}

.toolbar-btn:hover {
    background-color: #e9ecef;
    color: #2c3e50;
}

/* Toolbar Button Details */
.toolbar-btn span {
    font-size: 0.85rem;
    font-weight: 500;
}

.toolbar-btn i {
    font-size: 0.9rem;
}

.toolbar-btn.is-active {
    background-color: #e8edf5;
    color: var(--color-primary);
    border-color: #dbe4f1;
}

/* Table Floating Menu */
.table-floating-menu {
    position: fixed;
    display: none;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    max-width: min(92vw, 760px);
    padding: 8px;
    border-radius: 10px;
    border: 1px solid #d8dee9;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(4px);
    z-index: 9000;
}

.table-floating-menu.is-visible {
    display: flex;
}

.table-floating-menu button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #d7dde8;
    background: #ffffff;
    color: #344054;
    border-radius: 7px;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1;
    padding: 7px 9px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.table-floating-menu button i {
    font-size: 0.78rem;
}

.table-floating-menu button:hover:not(:disabled) {
    border-color: #b8c6e0;
    background: #f5f8ff;
}

.table-floating-menu button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.table-floating-menu button.is-danger {
    border-color: #f2c4c4;
    color: #b42318;
    background: #fff7f7;
}

.table-floating-menu .table-floating-sep {
    width: 1px;
    height: 18px;
    background: #dde3ee;
    margin: 0 2px;
}

.table-mobile-sheet {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    width: min(940px, calc(100vw - 20px));
    z-index: 9100;
    display: none;
}

.table-mobile-sheet.is-visible {
    display: block;
}

.table-mobile-sheet__panel {
    border: 1px solid #d8dee9;
    border-radius: 16px;
    padding: 10px 10px 12px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.24);
    backdrop-filter: blur(6px);
}

.table-mobile-sheet__handle {
    width: 54px;
    height: 5px;
    border-radius: 999px;
    background: #d5dbe8;
    margin: 2px auto 10px;
}

.table-mobile-sheet__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    color: #334155;
    font-size: 0.9rem;
    margin-bottom: 10px;
    padding: 0 4px;
}

.table-mobile-sheet__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.table-mobile-sheet__grid button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid #d7dde8;
    background: #ffffff;
    color: #344054;
    border-radius: 9px;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1;
    padding: 9px 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.table-mobile-sheet__grid button i {
    font-size: 0.8rem;
}

.table-mobile-sheet__grid button:hover:not(:disabled) {
    border-color: #b8c6e0;
    background: #f5f8ff;
}

.table-mobile-sheet__grid button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.table-mobile-sheet__grid button.is-danger {
    border-color: #f2c4c4;
    color: #b42318;
    background: #fff7f7;
}

/* Color Picker Styles (Restored) */
.color-picker {
    position: fixed;
    top: -9999px;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: auto;
    visibility: visible;
    z-index: 9999;
}

.toolbar-color-wrapper {
    position: relative;
    display: inline-block;
}

.color-palette {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    padding: 12px;
    min-width: 200px;
}

.color-palette.show {
    display: block;
}

.color-palette-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.color-palette-item {
    width: 36px;
    height: 36px;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    box-sizing: border-box;
}

.color-palette-item:hover {
    border-color: var(--color-primary);
    transform: scale(1.1);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--color-primary) 30%, transparent);
}

.color-palette-item:active {
    transform: scale(0.95);
}

/* Rainbow Gradient Button */
.color-palette-gradient {
    background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285AEB 90%) !important;
    position: relative;
    overflow: hidden;
}

.color-palette-gradient::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--last-selected-color, transparent);
    opacity: 0.8;
    transition: opacity 0.2s ease;
    border-radius: 2px;
}

.color-palette-gradient:hover::after {
    opacity: 0.5;
}

.color-palette-footer {
    border-top: 1px solid #e0e0e0;
    padding-top: 8px;
    margin-top: 8px;
}

.color-palette-more {
    width: 100%;
    padding: 8px 12px;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #555;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.color-palette-more:hover {
    background-color: #e9ecef;
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.color-palette-more i {
    font-size: 0.9rem;
}

.color-indicator {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    border: 1px solid #ccc;
    display: inline-block;
    margin-left: 4px;
    vertical-align: middle;
}

/* Dropdown Styles */
.toolbar-select {
    padding: 0.4rem 0.75rem;
    border: none;
    background-color: transparent;
    color: #555;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    height: 32px;
    line-height: 1.5;
    min-width: 80px;
    transition: all 0.2s ease;
    box-sizing: border-box;
    vertical-align: middle;
}

.toolbar-select:hover {
    background-color: #e9ecef;
}

/* Editor Container */
#editor-container {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background-color: #fff;
    min-height: 700px;
    cursor: text;
}

@media (min-width: 1025px) {
    #editor-container {
        max-height: calc(100vh - 350px);
        overflow-y: auto;
    }
}

/* ProseMirror Core Styles */
.ProseMirror {
    outline: none;
    padding: 0.75rem 1rem 6.5rem 1rem;
    /* Reduced from 1.5rem to fix large margins */
    min-height: 700px;
    font-size: 1.05rem;
    line-height: 1.8;
    color: #333;
}

/* 다크 면은 중성 회색으로 맞춘다 — 이 바만 파랑이 섞여 있었다(배경 R28 G31 B36, 테두리 #303640).
   앱의 다른 다크 면은 전부 회색이다(theme.dark.css: #10100f · #171717 · #1d1d1d · #2a2a2a).
   여기 값은 --dark-surface-2 와 같은 계열로 잡았다. 아이콘 색도 전역 --dark-text-muted(#c2c8d0)가
   푸른 회색이라 이 바 안에서만 중성으로 돌린다. */
html[data-theme="dark"] #editor-toolbar,
body[data-theme="dark"] #editor-toolbar {
    background: rgba(29, 29, 29, 0.96);
    border-color: #3a3a3a;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
}

html[data-theme="dark"] #editor-toolbar .toolbar-btn,
body[data-theme="dark"] #editor-toolbar .toolbar-btn {
    color: #c8c8c8;
}

html[data-theme="dark"] .table-floating-menu,
body[data-theme="dark"] .table-floating-menu,
html[data-theme="dark"] .table-mobile-sheet__panel,
body[data-theme="dark"] .table-mobile-sheet__panel {
    background: rgba(28, 31, 36, 0.96);
    border-color: #303640;
}

html[data-theme="dark"] .table-floating-menu button,
body[data-theme="dark"] .table-floating-menu button,
html[data-theme="dark"] .table-mobile-sheet__grid button,
body[data-theme="dark"] .table-mobile-sheet__grid button {
    background: #1f242d;
    border-color: #394152;
    color: #e7ecf4;
}

html[data-theme="dark"] .table-mobile-sheet__title,
body[data-theme="dark"] .table-mobile-sheet__title {
    color: #e7ecf4;
}

html[data-theme="dark"] .table-mobile-sheet__handle,
body[data-theme="dark"] .table-mobile-sheet__handle {
    background: #495366;
}

html[data-theme="dark"] .ProseMirror td.selectedCell::after,
body[data-theme="dark"] .ProseMirror td.selectedCell::after,
html[data-theme="dark"] .ProseMirror th.selectedCell::after,
body[data-theme="dark"] .ProseMirror th.selectedCell::after {
    background: rgba(117, 162, 227, 0.2);
    box-shadow: inset 0 0 0 2px rgba(153, 193, 255, 0.95);
}

.ProseMirror p {
    margin: 0 0 1rem 0;
}

/* Headings */
.ProseMirror h1 {
    font-size: 1.8rem;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    color: #2c3e50;
}

.ProseMirror h2 {
    font-size: 1.5rem;
    margin-top: 1.2rem;
    margin-bottom: 0.8rem;
    color: #34495e;
}

.ProseMirror h3 {
    font-size: 1.2rem;
    margin-top: 1rem;
    margin-bottom: 0.6rem;
    color: var(--color-primary);
}

/* Lists */
.ProseMirror ul,
.ProseMirror ol {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.ProseMirror li {
    margin-bottom: 0.3rem;
}

/* Blockquotes */
.ProseMirror blockquote {
    border-left: 4px solid var(--color-primary);
    background: #f8f9fa;
    margin: 1rem 0;
    padding: 1rem;
    font-style: italic;
    color: #555;
}

/* Code Blocks */
.ProseMirror code {
    background-color: #f1f3f5;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
    color: #e83e8c;
}

.ProseMirror pre {
    background-color: #2c3e50;
    color: #f8f9fa;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-family: monospace;
    margin: 1rem 0;
}

.ProseMirror pre code {
    background-color: transparent;
    color: inherit;
    padding: 0;
}

/* Images */
.ProseMirror img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 1rem 0;
    display: block;
}

.ProseMirror img.is-loading {
    width: 100%;
    min-height: 180px;
    border-radius: 8px;
    background: linear-gradient(90deg, #eef1f5 0%, #f7f9fc 50%, #eef1f5 100%);
    background-size: 200% 100%;
    animation: post-editor-image-skeleton 1.2s ease-in-out infinite;
    opacity: 0.35;
}

.ProseMirror img.is-loaded {
    opacity: 1;
    animation: none;
    min-height: 0;
}

.ProseMirror img.is-error {
    min-height: 120px;
    background: #f3f4f6;
    opacity: 0.5;
}

@keyframes post-editor-image-skeleton {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

.ProseMirror img.ProseMirror-selectednode {
    outline: 3px solid var(--color-primary);
}

/* Table selected cells (supports multi-cell selection) */
.ProseMirror .tableWrapper {
    overflow-x: auto;
}

.ProseMirror table {
    table-layout: fixed;
    width: 100%;
    overflow: hidden;
}

.ProseMirror td,
.ProseMirror th {
    position: relative;
    min-width: 88px;
}

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

.ProseMirror td.selectedCell::after,
.ProseMirror th.selectedCell::after {
    content: '';
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--color-primary) 14%, transparent);
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--color-primary) 85%, transparent);
    pointer-events: none;
}

.ProseMirror .column-resize-handle {
    position: absolute;
    right: -2px;
    top: 0;
    bottom: -2px;
    width: 4px;
    background-color: color-mix(in srgb, var(--color-primary) 45%, transparent);
    pointer-events: none;
}

.ProseMirror.resize-cursor {
    cursor: col-resize;
}

html[data-theme="dark"] .ProseMirror td[data-visual-header-row="true"],
body[data-theme="dark"] .ProseMirror td[data-visual-header-row="true"],
html[data-theme="dark"] .ProseMirror td[data-visual-header-column="true"],
body[data-theme="dark"] .ProseMirror td[data-visual-header-column="true"] {
    background: rgba(75, 89, 112, 0.42);
}

/* Links */
.ProseMirror a {
    color: var(--color-primary);
    text-decoration: underline;
    cursor: pointer;
}

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

/* Focus State */
.ProseMirror-focused {
    /* Optional: add focus ring if needed, but usually strictly inside is cleaner */
}

/* =========================================
   Citation & Legacy Editor Styles (Restored)
   ========================================= */

.ProseMirror p {
    margin: 0.5rem 0;
}

.ProseMirror p:first-child {
    margin-top: 0;
}

.ProseMirror p:last-child {
    margin-bottom: 0;
}

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

.ProseMirror.is-empty::before {
    content: attr(data-placeholder);
    position: absolute;
    top: 15px;
    left: 15px;
    color: #adb5bd;
    pointer-events: none;
}

/* Inline Citation Style */
.citation-inline {
    display: inline;
    padding: 0 1px;
    margin: 0 1px;
    color: var(--color-primary);
    background-color: color-mix(in srgb, var(--color-primary) 10%, transparent);
    border-radius: 3px;
    text-decoration: none;
    cursor: pointer;
    vertical-align: baseline;
    line-height: 1;
    font-size: 0.95em;
    font-weight: normal;
    transition: background-color 0.2s ease;
    border: 1px solid rgba(90, 143, 123, 0.3);
}

.citation-inline:hover {
    background-color: color-mix(in srgb, var(--color-primary) 20%, transparent);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Citation Item (Manage List) */
.citation-item {
    transition: all 0.3s ease;
    border-left: 2px solid transparent;
    margin-bottom: 10px;
    padding: 12px;
    border-radius: 6px;
    background-color: white;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.citation-item .remove-citation {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: #888;
    font-size: 16px;
    cursor: pointer;
    padding: 0 5px;
    border-radius: 50%;
    transition: all 0.2s ease;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.citation-item .remove-citation:hover {
    color: #e74c3c;
    background-color: rgba(0, 0, 0, 0.05);
}

.citation-item.highlight {
    background-color: #fffde7;
    border-left: 2px solid #ffca28;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.citation-item.active {
    background-color: #e8edf5;
    border-left: 2px solid var(--color-primary);
}

/* Citation Content Typography */
.citation-content {
    font-size: 0.9rem;
    line-height: 1.5;
    padding-right: 20px;
    /* Space for delete button */
}

.citation-content .original-text {
    font-weight: 500;
    color: #333;
    margin-bottom: 6px;
    padding: 6px 8px;
    background-color: #f9f9f9;
    border-radius: 4px;
}

.citation-content .translation-text {
    color: #555;
    font-style: italic;
    padding: 2px 8px;
}

/* =========================================
   제목과 본문 — 테두리 없이, 사이에 가는 선 하나 (원장 지시 260918)

   참조는 Ghost 의 Koenig 편집기. 거기는 제목이 <textarea> 48px / 본문 17px 에
   테두리도 outline 도 없고 배경이 투명하다. 한글이라 제목만 34px 로 낮췄다.
   선은 Koenig 에 없지만 원장이 「그 사이에만 선을 하나」라고 해서 넣었다.
   ========================================= */

@media (min-width: 1025px) {

    body[data-chrome="editor"] .title-row {
        margin-bottom: 0;
        padding-bottom: 22px;
        border-bottom: 1px solid #ebeef1;
    }

    body[data-chrome="editor"] #postTitle {
        height: auto;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        font-size: 34px;
        line-height: 1.32;
        font-weight: 700;
        letter-spacing: -0.01em;
        color: #15171a;
    }

    body[data-chrome="editor"] #postTitle::placeholder {
        font-weight: 700;
        color: #c3c9d1;
    }

    body[data-chrome="editor"] #postTitle:focus {
        border: 0;
        outline: none;
        box-shadow: none;
    }

    /* 본문 입력칸의 상자(배경·테두리·모서리)도 걷는다 */
    body[data-chrome="editor"] #editor-container {
        margin-top: 26px;
        background: transparent;
        border: 0;
        border-radius: 0;
    }

    body[data-chrome="editor"] .ProseMirror {
        padding: 0;
        min-height: 60vh;
        font-size: 17px;
        line-height: 1.85;
    }

    /* 툴바는 글 쓰는 열에 맞춘다 */
    body[data-chrome="editor"] #editor-toolbar { width: min(860px, calc(100vw - 28px)); }

    body[data-theme="dark"][data-chrome="editor"] .title-row { border-bottom-color: #262626; }
    body[data-theme="dark"][data-chrome="editor"] #postTitle { color: #edf0f3; }
    body[data-theme="dark"][data-chrome="editor"] #postTitle::placeholder { color: #5c5c5c; }
}

/* =========================================
   본문 플레이스홀더 — 선택자가 두 요소를 한 요소로 찾고 있었다

   syncEditorPlaceholderState(post-editor-tiptap.js:169)가 붙이는 `is-empty` 는
   Tiptap 에 넘긴 컨테이너(#editor-container)에 붙고, `data-placeholder`
   (post-editor-tiptap.js:550)는 그 안쪽 편집 div(.ProseMirror)에 붙는다.
   위쪽의 `.ProseMirror.is-empty::before` 는 둘을 한 요소로 찾아 영영 안 맞았다.
   위치는 absolute(left:0·top:0) 가 아니라 float 으로 둔다. absolute 는 .ProseMirror
   의 여백(폭마다 0 · 8·16px)을 무시해 첫 글자 자리보다 왼쪽 위에 붙었다.
   높이 0 인 float 은 여백 안쪽 첫 줄에 앉고 커서를 밀지 않는다.
   ========================================= */

body[data-chrome="editor"] #editor-container.is-empty .ProseMirror::before {
    content: attr(data-placeholder);
    float: left;
    height: 0;
    pointer-events: none;
    color: #b4bcc6;
}

body[data-theme="dark"][data-chrome="editor"] #editor-container.is-empty .ProseMirror::before { color: #5c5c5c; }
