/* 마크다운 에디터 스타일 - json-csv-converter 디자인 언어 차용 (indigo/violet 테마) */
.md-tool {
    --tool-primary: #4338ca;
    --tool-bg: #eef2ff;
    --tool-gradient: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
}

/* 히어로 */
.md-hero {
    background: var(--tool-gradient);
    border-radius: 16px;
    padding: 36px 32px;
    color: #fff;
    text-align: center;
    position: relative;
    overflow: hidden;
    margin-bottom: 28px;
}
.md-hero::before {
    content: '';
    position: absolute;
    top: -80px;
    right: -80px;
    width: 300px;
    height: 300px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 50%;
}
.md-hero::after {
    content: '';
    position: absolute;
    bottom: -120px;
    left: -60px;
    width: 260px;
    height: 260px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 50%;
}
.md-hero h1 {
    font-size: 28px;
    font-weight: 800;
    position: relative;
    z-index: 1;
    margin: 10px 0 6px;
}
.md-hero p {
    opacity: 0.85;
    position: relative;
    z-index: 1;
    margin-bottom: 0;
}

/* 툴바 */
.md-toolbar {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 14px;
    padding: 12px 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.btn-action {
    display: inline-flex;
    align-items: center;
    padding: 7px 14px;
    border-radius: 9px;
    border: 1px solid #dee2e6;
    background: #fff;
    color: #495057;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-action:hover {
    border-color: var(--tool-primary);
    color: var(--tool-primary);
    background: var(--tool-bg);
}
.btn-action-sm {
    padding: 5px 11px;
    font-size: 12.5px;
    border-radius: 8px;
}
/* 아이콘 전용 툴바 버튼 (서식/제목 등) */
.btn-action-icon {
    padding: 6px 9px;
    font-size: 15px;
    line-height: 1;
}
.btn-action-icon i {
    line-height: 1;
}
.btn-action-primary {
    background: var(--tool-gradient);
    border: none;
    color: #fff;
}
.btn-action-primary:hover {
    background: var(--tool-gradient);
    border: none;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(67, 56, 202, 0.3);
}
.toolbar-divider {
    width: 1px;
    align-self: stretch;
    background: #e9ecef;
    margin: 0 2px;
}

/* 에디터 카드 */
.editor-card {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.editor-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #f1f3f5;
}
.editor-title {
    font-weight: 700;
    font-size: 14px;
    color: #343a40;
}
.editor-title i {
    color: var(--tool-primary);
}
.size-badge {
    font-size: 12px;
    font-weight: 600;
    color: #868e96;
    background: #f1f3f5;
    padding: 3px 10px;
    border-radius: 20px;
}
.editor-body {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.editor-textarea {
    width: 100%;
    height: 498px;
    resize: none;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    background: #f8f9fb;
    padding: 14px 16px;
    font-size: 13px;
    line-height: 1.7;
    color: #212529;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    tab-size: 4;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
}
.editor-textarea:focus {
    border-color: var(--tool-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(67, 56, 202, 0.12);
}

/* ==========================================
   파일 열기 / 드래그 앤 드롭
   ========================================== */
/* label 을 버튼처럼 쓰므로 커서만 보정 */
.md-file-label {
    cursor: pointer;
}
/* textarea 를 감싸는 드롭 영역 — inline-block 여백 제거 + 전체화면 높이 전달용 */
#mdDropZone {
    display: flex;
    flex-direction: column;
}
.md-drop-overlay {
    background-color: rgba(67, 56, 202, 0.08);
    border: 2px dashed var(--tool-primary);
    z-index: 10;
    pointer-events: none;
}
.md-drop-overlay i,
.md-drop-overlay p {
    color: var(--tool-primary) !important;
}

/* 통계 바 */
.md-stats-bar {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 14px;
    padding: 10px 16px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 28px;
    color: #868e96;
    font-size: 13.5px;
}
.md-stats-bar strong {
    color: var(--tool-primary);
}

/* 서포트 카드 */
.support-card {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 14px;
    overflow: hidden;
}
.support-card .card-hd {
    padding: 14px 18px;
    font-weight: 700;
    font-size: 15px;
    border-bottom: 1px solid #f1f3f5;
}
.support-card .card-bd {
    padding: 18px;
}
.support-subtitle {
    font-size: 15px;
    font-weight: 700;
    color: #343a40;
    margin: 18px 0 10px;
}

/* 아코디언 */
.md-tool .accordion-button:not(.collapsed) {
    background-color: var(--tool-bg);
    color: var(--tool-primary);
    box-shadow: none;
}
.md-tool .accordion-button:focus {
    box-shadow: none;
}

/* ==========================================
   미리보기 영역 타이포그래피 (인디고 테마로 재조정)
   ========================================== */
.md-preview-output {
    background-color: #fff;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    line-height: 1.8;
    font-size: 0.95rem;
    color: #333;
    word-wrap: break-word;
}

/* 미리보기 제목 */
.md-preview-output h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0.8em 0 0.4em;
    padding-bottom: 0.3em;
    border-bottom: 2px solid #e9ecef;
}
.md-preview-output h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0.8em 0 0.4em;
    padding-bottom: 0.25em;
    border-bottom: 1px solid #e9ecef;
}
.md-preview-output h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0.7em 0 0.3em;
}
.md-preview-output h4 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0.6em 0 0.3em;
}
.md-preview-output h5 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0.5em 0 0.2em;
}
.md-preview-output h6 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0.5em 0 0.2em;
    color: #6c757d;
}

/* 미리보기 단락 */
.md-preview-output p {
    margin: 0.6em 0;
}

/* 미리보기 인라인 코드 */
.md-preview-output .md-inline-code {
    background-color: #eef2ff;
    color: #4338ca;
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.88em;
}

/* 미리보기 코드 블록 (catppuccin 다크) */
.md-preview-output .md-code-block {
    background-color: #1e1e2e;
    color: #cdd6f4;
    padding: 1em 1.2em;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.8em 0;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.88em;
    line-height: 1.6;
}
.md-preview-output .md-code-block code {
    background: none;
    color: inherit;
    padding: 0;
    font-size: inherit;
}

/* Mermaid 다이어그램 — 가운데 정렬, 넓은 도표는 가로 스크롤 */
.md-preview-output .md-mermaid {
    margin: 0.8em 0;
    padding: 0.6em;
    background: #ffffff;
    border: 1px solid var(--tool-border, #e5e7eb);
    border-radius: 8px;
    overflow-x: auto;
    text-align: center;
}
.md-preview-output .md-mermaid svg {
    max-width: 100%;
    height: auto;
}

/* 미리보기 인용문 */
.md-preview-output blockquote {
    border-left: 4px solid var(--tool-primary);
    padding: 0.5em 1em;
    margin: 0.8em 0;
    background-color: var(--tool-bg);
    color: #555;
    border-radius: 0 6px 6px 0;
}

/* 미리보기 목록 */
.md-preview-output ul,
.md-preview-output ol {
    padding-left: 1.8em;
    margin: 0.5em 0;
}
.md-preview-output li {
    margin: 0.25em 0;
}

/* 미리보기 구분선 */
.md-preview-output hr {
    border: none;
    border-top: 2px solid #e9ecef;
    margin: 1.5em 0;
}

/* 미리보기 표 */
.md-preview-output .md-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.8em 0;
    font-size: 0.92em;
}
.md-preview-output .md-table th,
.md-preview-output .md-table td {
    border: 1px solid #dee2e6;
    padding: 0.5em 0.75em;
}
.md-preview-output .md-table th {
    background-color: #f1f3f5;
    font-weight: 600;
}
.md-preview-output .md-table tr:nth-child(even) {
    background-color: #f8f9fa;
}

/* 미리보기 이미지 */
.md-preview-output .md-image {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 0.5em 0;
}

/* 미리보기 링크 */
.md-preview-output a {
    color: var(--tool-primary);
    text-decoration: none;
}
.md-preview-output a:hover {
    text-decoration: underline;
}

/* 미리보기 강조 */
.md-preview-output strong {
    font-weight: 700;
}
.md-preview-output del {
    color: #999;
}

/* 미리보기 YAML Front Matter 카드 */
.md-preview-output .md-fm-card {
    border: 1px solid #dbe0ff;
    border-radius: 10px;
    background: linear-gradient(135deg, #f5f7ff 0%, #eef2ff 100%);
    margin: 0 0 1.2em;
    overflow: hidden;
}
.md-preview-output .md-fm-head {
    display: flex;
    align-items: center;
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--tool-primary);
    background: rgba(67, 56, 202, 0.06);
    border-bottom: 1px solid #dbe0ff;
    text-transform: uppercase;
}
.md-preview-output .md-fm-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 0.88em;
}
.md-preview-output .md-fm-table th,
.md-preview-output .md-fm-table td {
    padding: 0.5em 0.9em;
    border: none;
    border-bottom: 1px solid #e4e8ff;
    text-align: left;
    vertical-align: top;
}
.md-preview-output .md-fm-table tr:last-child th,
.md-preview-output .md-fm-table tr:last-child td {
    border-bottom: none;
}
.md-preview-output .md-fm-table th {
    width: 30%;
    font-weight: 600;
    color: #4b4f8a;
    white-space: nowrap;
    background: transparent;
}
.md-preview-output .md-fm-table td {
    color: #333;
    word-break: break-word;
}
.md-preview-output .md-fm-badge {
    display: inline-block;
    padding: 0.1em 0.6em;
    margin: 0.1em 0.15em 0.1em 0;
    font-size: 0.85em;
    font-weight: 600;
    color: var(--tool-primary);
    background: #fff;
    border: 1px solid #c9d0ff;
    border-radius: 20px;
}
.md-preview-output .md-fm-empty {
    color: #adb5bd;
}

/* ==========================================
   전체 화면 모드 (JS: .markdown-editor-tool + .md-fullscreen)
   ========================================== */
.md-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: #fff;
    margin: 0 !important;
    padding: 15px;
    overflow: auto;
    display: flex;
    flex-direction: column;
}
.md-fullscreen .container-xl {
    max-width: 100% !important;
    padding: 0 !important;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.md-fullscreen .row.g-4 {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.md-fullscreen .col-12 {
    flex: 1;
    max-width: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
}
.md-fullscreen .md-hero {
    display: none;
}
.md-fullscreen #editorRow {
    flex: 1;
    min-height: 0;
}
.md-fullscreen #editorRow > .col-lg-6 {
    display: flex;
}
.md-fullscreen #editorRow > .col-lg-6 > .editor-card {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.md-fullscreen #editorRow > .col-lg-6 > .editor-card > .editor-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.md-fullscreen #mdDropZone {
    flex: 1;
    min-height: 0;
}
.md-fullscreen #mdInput {
    flex: 1;
    height: auto !important;
    resize: none;
}
.md-fullscreen #mdPreview {
    flex: 1;
    height: auto !important;
}
.md-fullscreen .md-stats-bar,
.md-fullscreen .support-card,
.md-fullscreen .text-center.mt-4,
.md-fullscreen .en-comments-section {
    display: none !important;
}

/* 반응형 */
@media (max-width: 768px) {
    .md-hero { padding: 28px 20px; border-radius: 12px; }
    .md-hero h1 { font-size: 22px; }
    .editor-textarea { height: 320px; }
    .md-preview-output { height: 320px !important; }
    .md-stats-bar { gap: 16px; }
}

/* ==========================================
   PDF 저장(인쇄) — JS 가 미리보기 내용을 #mdPrintArea 로 복제해
   body 직속에 붙이고 body 에 .md-printing 을 건다.
   ========================================== */
/* 화면에서는 복제 컨테이너를 감춘다. body 밖(직속)이라 .md-tool 의 테마 변수를 다시 선언 */
#mdPrintArea {
    --tool-primary: #4338ca;
    --tool-bg: #eef2ff;
    display: none;
}

@media print {
    @page {
        margin: 16mm 14mm;
    }

    /* 인쇄 시에는 복제한 미리보기만 남기고 헤더·푸터·히어로·툴바·입력창·FAQ 등
       페이지 전체(레이아웃 요소 포함)를 감춘다 */
    body.md-printing > *:not(#mdPrintArea) {
        display: none !important;
    }
    body.md-printing {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        overflow: visible !important;
    }

    /* 미리보기는 화면에서 height:498px + overflow:auto 라 그대로 두면 잘린다 */
    #mdPrintArea {
        display: block !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        background: #fff !important;
        color: #000;
        font-size: 11pt;
        line-height: 1.7;
    }

    /* 제목이 페이지 끝에 홀로 남지 않게 */
    #mdPrintArea h1,
    #mdPrintArea h2,
    #mdPrintArea h3,
    #mdPrintArea h4,
    #mdPrintArea h5,
    #mdPrintArea h6 {
        break-inside: avoid;
        page-break-inside: avoid;
        break-after: avoid-page;
        page-break-after: avoid;
    }
    #mdPrintArea h1 { font-size: 19pt; }
    #mdPrintArea h2 { font-size: 15pt; }
    #mdPrintArea h3 { font-size: 13pt; }

    /* 문단·목록의 한 줄 끊김 최소화 */
    #mdPrintArea p,
    #mdPrintArea li {
        orphans: 3;
        widows: 3;
    }

    /* 덩어리 요소는 페이지 경계에서 쪼개지지 않게 */
    #mdPrintArea pre,
    #mdPrintArea table,
    #mdPrintArea blockquote,
    #mdPrintArea img,
    #mdPrintArea .md-mermaid,
    #mdPrintArea .md-fm-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* 코드 블록: 화면용 다크 테마는 "배경 그래픽" 옵션을 끄면 글자가 사라지므로 밝게 반전.
       가로 스크롤 대신 줄바꿈으로 풀어 잘리지 않게 한다 */
    #mdPrintArea pre.md-code-block {
        background: #f6f8fa !important;
        color: #1f2328 !important;
        border: 1px solid #d0d7de;
        overflow: visible !important;
        white-space: pre-wrap;
        word-break: break-word;
        font-size: 9.5pt;
    }
    #mdPrintArea .md-code-block code {
        color: #1f2328 !important;
    }
    #mdPrintArea .md-inline-code {
        background: transparent !important;
        color: #1f2328 !important;
        border: 1px solid #d0d7de;
    }

    /* 표: 배경 없이도 머리행이 구분되게 */
    #mdPrintArea .md-table th {
        background: transparent !important;
        border-bottom: 2px solid #868e96;
    }
    #mdPrintArea .md-table tr:nth-child(even) {
        background: transparent !important;
    }

    /* mermaid 다이어그램(SVG): 지면 폭에 맞춰 축소, 테두리·스크롤 제거 */
    #mdPrintArea .md-mermaid {
        border: none !important;
        padding: 0 !important;
        overflow: visible !important;
        background: transparent !important;
    }
    /* mermaid 는 svg 에 width="100%" + 인라인 max-width(자연 크기) 를 준다.
       max-width 에 !important 를 걸면 인라인 값을 눌러 지면 폭까지 늘어나므로 걸지 않는다. */
    #mdPrintArea .md-mermaid svg {
        max-width: 100%;
        height: auto !important;
    }

    #mdPrintArea img,
    #mdPrintArea .md-image {
        max-width: 100% !important;
        height: auto !important;
    }

    /* 링크는 흑백 인쇄에서도 구분되도록 밑줄로 */
    #mdPrintArea a {
        color: #000 !important;
        text-decoration: underline;
    }

    /* 인용문·Front Matter 카드는 배경 대신 선으로 구분 */
    #mdPrintArea blockquote {
        background: transparent !important;
        border-left: 3px solid #868e96;
        color: #333;
    }
    #mdPrintArea .md-fm-card {
        background: transparent !important;
        border: 1px solid #adb5bd;
    }
    #mdPrintArea .md-fm-head {
        background: transparent !important;
        color: #000 !important;
    }
    #mdPrintArea .md-fm-badge {
        color: #000 !important;
        border-color: #adb5bd;
    }
}
