/* =============================================
   문서 보기 (마크다운 뷰어) — js/modules/mdViewer/mdViewer.js
   어두운 반투명 배경 위 흰 종이. 다크 모드와 상관없이 항상 밝은 문서로 보인다.
   z-index: 채팅·메모 패널(9500~9700), 칠판 쪽 넘김 버튼(9990) 위, 앱 대화상자(20000) 아래
   ============================================= */

.md-viewer-overlay {
    --md-text: #1f2328;
    --md-muted: #59636e;
    --md-border: #d1d9e0;
    --md-soft: #f6f8fa;
    --md-link: #0969da;
    --md-accent: #2b7de9;
    position: fixed;
    inset: 0;
    z-index: 15000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 16, 24, 0.62);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: md-fade-in 0.16s ease-out;
}

.md-viewer-overlay[hidden] {
    display: none;
}

@keyframes md-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.md-viewer {
    display: flex;
    flex-direction: column;
    width: min(1640px, calc(100vw - 40px));
    height: calc(100vh - 40px);
    background: #fff;
    color: var(--md-text);
    border-radius: 12px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", "Noto Sans", sans-serif;
}

/* 상단 막대 */
.md-viewer-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: none;
    padding: 8px 10px 8px 18px;
    border-bottom: 1px solid var(--md-border);
    background: #fbfcfd;
}

.md-viewer-icon {
    color: var(--md-accent);
    font-size: 18px;
    margin-right: 6px;
}

.md-viewer-title {
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.md-viewer-spacer {
    flex: 1;
}

.md-viewer-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--md-muted);
    font-size: 15px;
    cursor: pointer;
}

.md-viewer-btn:hover {
    background: rgba(31, 35, 40, 0.08);
    color: var(--md-text);
}

.md-viewer-btn.active {
    color: var(--md-accent);
    background: rgba(43, 125, 233, 0.1);
}

.md-viewer-btn.md-font-label {
    min-width: 54px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.md-viewer-btn.md-close-btn {
    margin-left: 6px;
    font-size: 18px;
    border-radius: 50%;
    min-width: 36px;
    padding: 0;
    transition: background-color 0.18s ease, color 0.18s ease;
}

/* 다른 모달의 닫기 버튼(.close-btn)과 같은 효과: 마우스를 올리면 빨간색 */
.md-viewer-btn.md-close-btn:hover {
    background: var(--close-btn-hover-bg);
    color: #fff;
}

.md-viewer-overlay.no-toc .md-toc-btn {
    display: none;
}

.md-viewer-overlay.no-doc .md-clear-btn {
    display: none;
}

/* 본문 = 목차 + 문서 */
.md-viewer-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

.md-toc {
    flex: none;
    width: 310px;
    overflow-y: auto;
    padding: 18px 12px 24px 16px;
    border-right: 1px solid var(--md-border);
    background: var(--md-soft);
    font-size: 14px;
}

.md-viewer-overlay.no-toc .md-toc,
.md-viewer-overlay.toc-hidden .md-toc {
    display: none;
}

.md-toc-title {
    padding: 0 8px 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--md-muted);
}

.md-toc-item {
    display: block;
    padding: 5px 8px;
    border-radius: 6px;
    color: var(--md-text);
    text-decoration: none;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.md-toc-item:hover {
    background: rgba(31, 35, 40, 0.06);
}

.md-toc-item.active {
    color: var(--md-accent);
    background: rgba(43, 125, 233, 0.1);
    font-weight: 600;
}

.md-toc-item.depth-1 { padding-left: 22px; font-size: 13.5px; }
.md-toc-item.depth-2 { padding-left: 36px; font-size: 13px; color: var(--md-muted); }

.md-viewer-scroll {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    outline: none;
    scroll-padding-top: 12px;
}

.md-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    min-height: 100%;
    padding: 40px;
    color: var(--md-muted);
    font-size: 17px;
    text-align: center;
}

.md-empty[hidden] {
    display: none;
}

/* HTML 문서: 격리된 iframe 이 본문 자리를 채운다 (스크롤은 iframe 안에서) */
.md-viewer-overlay.is-html .md-toc,
.md-viewer-overlay.is-html .md-toc-btn {
    display: none;
}

.md-viewer-overlay.is-html .md-viewer-scroll {
    overflow: hidden;
}

.md-html-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

.md-html-frame[hidden] {
    display: none;
}

/* =============================================
   문서 본문 (GitHub 문서와 비슷한 모양)
   ============================================= */
.md-doc {
    --md-font: 18px;
    max-width: 1120px;
    margin: 0 auto;
    padding: 36px 60px 80px;
    font-size: var(--md-font);
    line-height: 1.7;
    color: var(--md-text);
    overflow-wrap: break-word;
    word-break: keep-all;
}

.md-doc[hidden] {
    display: none;
}

.md-doc > :first-child { margin-top: 0 !important; }

.md-doc h1, .md-doc h2, .md-doc h3, .md-doc h4, .md-doc h5, .md-doc h6 {
    margin: 1.6em 0 0.6em;
    font-weight: 700;
    line-height: 1.3;
    color: var(--md-text);
}

.md-doc h1 { font-size: 2em; padding-bottom: 0.3em; border-bottom: 1px solid var(--md-border); }
.md-doc h2 { font-size: 1.5em; padding-bottom: 0.3em; border-bottom: 1px solid var(--md-border); }
.md-doc h3 { font-size: 1.25em; }
.md-doc h4 { font-size: 1.05em; }
.md-doc h5 { font-size: 0.95em; }
.md-doc h6 { font-size: 0.9em; color: var(--md-muted); }

.md-doc p, .md-doc ul, .md-doc ol, .md-doc blockquote, .md-doc .md-table-wrap, .md-doc .md-code, .md-doc dl {
    margin: 0 0 1em;
}

.md-doc ul, .md-doc ol { padding-left: 2em; }
.md-doc li + li { margin-top: 0.25em; }
.md-doc li > ul, .md-doc li > ol { margin: 0.25em 0 0; }
.md-doc li > p { margin: 0.4em 0; }

.md-doc a { color: var(--md-link); text-decoration: none; }
.md-doc a:hover { text-decoration: underline; }

.md-doc strong { font-weight: 700; }

.md-doc hr {
    height: 3px;
    margin: 1.8em 0;
    border: 0;
    background: var(--md-border);
    border-radius: 2px;
}

.md-doc img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

.md-doc blockquote {
    padding: 0 1em;
    color: var(--md-muted);
    border-left: 4px solid var(--md-border);
}

.md-doc blockquote > :last-child { margin-bottom: 0; }

/* 인라인 코드 */
.md-doc :not(pre) > code {
    padding: 0.15em 0.4em;
    border-radius: 6px;
    background: rgba(129, 139, 152, 0.16);
    font-family: Consolas, "D2Coding", "Courier New", monospace;
    font-size: 0.88em;
    word-break: break-word;
}

/* 코드 블록 */
.md-code {
    border: 1px solid var(--md-border);
    border-radius: 8px;
    background: var(--md-soft);
    overflow: hidden;
}

.md-code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px 4px 14px;
    border-bottom: 1px solid var(--md-border);
    background: #eef1f4;
    font-size: 13px;
    color: var(--md-muted);
}

.md-code-lang {
    font-family: Consolas, "D2Coding", monospace;
}

.md-code-copy {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--md-muted);
    font-size: 13px;
    cursor: pointer;
}

.md-code-copy:hover {
    border-color: var(--md-border);
    background: #fff;
    color: var(--md-text);
}

.md-code pre {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto;
    font-family: Consolas, "D2Coding", "Courier New", monospace;
    font-size: 0.86em;
    line-height: 1.55;
    tab-size: 4;
    -moz-tab-size: 4;
    color: #1f2328;
}

.md-code pre code,
.md-code pre code.hljs {
    padding: 0;
    background: transparent;
    font: inherit;
    color: inherit;
    white-space: pre;
    word-break: normal;
}

/* 표 */
.md-table-wrap {
    overflow-x: auto;
}

.md-doc table {
    border-collapse: collapse;
    font-size: 0.95em;
    word-break: normal;
}

.md-doc th, .md-doc td {
    padding: 7px 14px;
    border: 1px solid var(--md-border);
    vertical-align: top;
}

.md-doc th {
    font-weight: 700;
    background: var(--md-soft);
}

.md-doc tr:nth-child(2n) td {
    background: #fbfcfd;
}

/* 체크박스 목록 */
.md-doc li.md-task {
    list-style: none;
}

.md-doc li.md-task > .md-check,
.md-doc li.md-task > p > .md-check {
    margin-left: -1.5em;
}

.md-check {
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: 0.35em;
    vertical-align: -0.12em;
    border: 2px solid #8c959f;
    border-radius: 4px;
    box-sizing: border-box;
}

.md-check.is-checked {
    border-color: var(--md-accent);
    background: var(--md-accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 90% no-repeat;
}

/* GitHub 알림 상자 (> [!NOTE] …) */
.md-doc blockquote.md-alert {
    padding: 0.6em 1em;
    color: var(--md-text);
    border-left-width: 4px;
    border-radius: 0 6px 6px 0;
}

.md-alert-title {
    margin: 0 0 0.3em !important;
    font-weight: 700;
}

.md-alert-title i { margin-right: 0.25em; }
.md-alert-note { border-left-color: #0969da !important; background: rgba(9, 105, 218, 0.06); }
.md-alert-note .md-alert-title { color: #0969da; }
.md-alert-tip { border-left-color: #1a7f37 !important; background: rgba(26, 127, 55, 0.06); }
.md-alert-tip .md-alert-title { color: #1a7f37; }
.md-alert-important { border-left-color: #8250df !important; background: rgba(130, 80, 223, 0.06); }
.md-alert-important .md-alert-title { color: #8250df; }
.md-alert-warning { border-left-color: #9a6700 !important; background: rgba(191, 135, 0, 0.08); }
.md-alert-warning .md-alert-title { color: #9a6700; }
.md-alert-caution { border-left-color: #d1242f !important; background: rgba(209, 36, 47, 0.06); }
.md-alert-caution .md-alert-title { color: #d1242f; }

/* 변환기를 못 받았을 때 원문 표시 */
.md-load-note {
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(191, 135, 0, 0.12);
    color: #7d4e00;
    font-size: 0.85em;
}

.md-raw {
    white-space: pre-wrap;
    font-family: Consolas, "D2Coding", monospace;
    font-size: 0.88em;
}

/* 붙여넣기 제안·짧은 안내 (화면 아래 가운데) */
.md-paste-offer {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    z-index: 15100;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100vw - 32px);
    padding: 10px 10px 10px 18px;
    border-radius: 12px;
    background: rgba(24, 30, 38, 0.94);
    color: #fff;
    font-size: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    animation: md-fade-in 0.16s ease-out;
}

.md-paste-offer[hidden] {
    display: none;
}

.md-paste-offer .fa-file-lines {
    color: #7fb3ff;
}

.md-paste-offer .control-button {
    margin: 0;
    white-space: nowrap;
}

.md-offer-close {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-size: 16px;
    padding: 6px 8px;
    cursor: pointer;
}

.md-offer-close:hover {
    color: #fff;
}

/* 태블릿·스마트폰에서는 쓰지 않음 (mdViewer.js isMdViewerEnabled 와 같은 조건) */
@media (pointer: coarse) and (hover: none), (max-width: 768px) {
    #mdViewerButton,
    .md-viewer-overlay,
    .md-paste-offer {
        display: none !important;
    }
}

/* 좁은 화면 */
@media (max-width: 900px) {
    .md-viewer {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    .md-toc {
        display: none;
    }
    .md-toc-btn {
        display: none;
    }
    .md-doc {
        padding: 24px 20px 60px;
    }
}

@media print {
    .md-paste-offer { display: none !important; }
}
