/*
 * 파일명: main.css
 * 위치: /assets/css/
 * 기능: 마크다운 에디터 메인 스타일시트
 * 작성일: 2025-08-14
 * 수정일: 2025-08-14
 */

/* ===================================
 전역 스타일
=================================== */

:root {
    --editor-bg: #ffffff;
    --editor-border: #e9ecef;
    --editor-text: #212529;
    --preview-bg: #ffffff;
    --toolbar-bg: #f8f9fa;
    --header-height: 56px;
    --toolbar-height: 50px;
    --footer-height: 60px;
}

/* 다크모드 변수 */
[data-bs-theme="dark"] {
    --editor-bg: #2d3748;
    --editor-border: #4a5568;
    --editor-text: #e2e8f0;
    --preview-bg: #1a202c;
    --toolbar-bg: #2d3748;
}

html, body {
    height: 100vh;
}

body {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - var(--footer-height));
    overflow: hidden;
}

/* 푸터 스타일 */
footer {
    flex-shrink: 0;
    background-color: #f8f9fa !important;
    border-top: 1px solid #dee2e6 !important;
    height: var(--footer-height);
    display: flex;
    align-items: center;
}

footer a:hover {
    text-decoration: underline !important;
}

/* 다크모드 푸터 */
[data-bs-theme="dark"] footer {
    background-color: #212529 !important;
    border-top-color: #4a5568 !important;
}

[data-bs-theme="dark"] footer .text-muted {
    color: #adb5bd !important;
}

/* 전체화면 모드에서 푸터 숨김 */
:fullscreen footer,
:-webkit-full-screen footer,
:-moz-full-screen footer,
.pseudo-fullscreen footer {
    display: none !important;
}

/* 전체화면 모드에서 main 높이 조정 */
:fullscreen main,
:-webkit-full-screen main,
:-moz-full-screen main,
.pseudo-fullscreen main {
    height: calc(100vh - var(--header-height)) !important;
}

/* ===================================
 헤더 스타일
=================================== */

.navbar-brand {
    font-size: 1.5rem;
    letter-spacing: -0.5px;
}

.navbar-brand i {
    font-size: 1.8rem;
}

/* ===================================
 도구바 스타일
=================================== */

.toolbar {
    background-color: var(--toolbar-bg) !important;
    border-bottom: 1px solid var(--editor-border) !important;
    height: var(--toolbar-height);
    flex-shrink: 0;
}

.btn-toolbar {
    height: 100%;
    align-items: center;
}

.btn-group-sm .btn {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
}

.vr {
    width: 1px;
    height: 24px;
    background-color: var(--bs-border-color);
}

/* ===================================
 에디터 및 미리보기 레이아웃
=================================== */

.row.g-0.h-100 {
    height: calc(100vh - var(--header-height) - var(--toolbar-height) - var(--footer-height)) !important;
    margin: 0;
}

.editor-container,
.preview-container {
    border-right: 1px solid var(--editor-border);
    height: 100%;
}

.preview-container {
    border-right: none;
}

.editor-header,
.preview-header {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    flex-shrink: 0;
}

/* ===================================
 에디터 스타일
=================================== */

#markdownEditor {
    background-color: var(--editor-bg);
    color: var(--editor-text);
    border: none !important;
    border-radius: 0 !important;
    resize: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    padding: 1rem;
    height: calc(100% - 40px) !important;
    outline: none !important;
    box-shadow: none !important;
}

#markdownEditor:focus {
    border: none !important;
    box-shadow: none !important;
}

#markdownEditor::placeholder {
    color: #6c757d;
    opacity: 0.6;
}

/* ===================================
 미리보기 스타일
=================================== */

.preview-content {
    background-color: var(--preview-bg);
    height: calc(100% - 40px);
    overflow-y: auto;
    border: none;
}

/* 마크다운 콘텐츠 스타일 */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
    line-height: 1.25;
}

.preview-content h1 {
    font-size: 2rem;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 0.5rem;
}

.preview-content h2 {
    font-size: 1.5rem;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 0.3rem;
}

.preview-content h3 {
    font-size: 1.25rem;
}

.preview-content p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.preview-content blockquote {
    border-left: 4px solid #0d6efd;
    padding-left: 1rem;
    margin-left: 0;
    background-color: rgba(13, 110, 253, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 0 0.375rem 0.375rem 0;
}

.preview-content ul,
.preview-content ol {
    padding-left: 2rem;
    margin-bottom: 1rem;
}

.preview-content li {
    margin-bottom: 0.25rem;
}

.preview-content code {
    background-color: #f8f9fa;
    color: #e83e8c;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

.preview-content pre {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 0.375rem;
    padding: 1rem;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.preview-content pre code {
    background-color: transparent;
    color: inherit;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

.preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    border: 1px solid #e9ecef;
}

.preview-content th,
.preview-content td {
    border: 1px solid #e9ecef;
    padding: 0.5rem;
    text-align: left;
}

.preview-content th {
    background-color: #f8f9fa;
    font-weight: 600;
}

.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: 0.375rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.preview-content a {
    color: #0d6efd;
    text-decoration: none;
}

.preview-content a:hover {
    text-decoration: underline;
}

.preview-content hr {
    border: none;
    border-top: 2px solid #e9ecef;
    margin: 2rem 0;
}

/* ===================================
 다크모드 미리보기 스타일
=================================== */

[data-bs-theme="dark"] .preview-content {
    color: #e2e8f0;
}

[data-bs-theme="dark"] .preview-content h1,
[data-bs-theme="dark"] .preview-content h2 {
    border-bottom-color: #4a5568;
}

[data-bs-theme="dark"] .preview-content blockquote {
    background-color: rgba(13, 110, 253, 0.2);
    border-left-color: #4a90e2;
}

[data-bs-theme="dark"] .preview-content code {
    background-color: #4a5568;
    color: #fbb6ce;
}

[data-bs-theme="dark"] .preview-content pre {
    background-color: #2d3748;
    border-color: #4a5568;
}

[data-bs-theme="dark"] .preview-content table,
[data-bs-theme="dark"] .preview-content th,
[data-bs-theme="dark"] .preview-content td {
    border-color: #4a5568;
}

[data-bs-theme="dark"] .preview-content th {
    background-color: #4a5568;
}

[data-bs-theme="dark"] .preview-content hr {
    border-top-color: #4a5568;
}

/* ===================================
 반응형 디자인
=================================== */

@media (max-width: 991.98px) {
    .editor-container {
        border-right: none;
        border-bottom: 1px solid var(--editor-border);
    }
    
    .row.g-0.h-100 {
        height: auto !important;
        flex-direction: column;
    }
    
    .editor-container,
    .preview-container {
        height: 50vh;
    }
    
    main {
        height: calc(100vh - var(--header-height) - var(--footer-height));
        overflow-y: auto;
    }
}

@media (max-width: 768px) {
    /* 모바일 도구바 최적화 */
    .btn-toolbar {
        flex-wrap: wrap;
        gap: 0.25rem;
        justify-content: flex-start;
    }
    
    .toolbar {
        height: auto;
        padding: 0.5rem !important;
    }
    
    /* 버튼 그룹 모바일 최적화 */
    .btn-group {
        flex-wrap: wrap;
        gap: 0.125rem;
        margin-bottom: 0.25rem;
    }
    
    .btn-group-sm .btn {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
        min-width: 32px;
        height: 32px;
    }
    
    /* 구분선 숨김 */
    .vr {
        display: none;
    }
    
    /* 모바일에서 에디터/미리보기 레이아웃 */
    .editor-container {
        height: 45vh;
    }
    
    .preview-container {
        height: 45vh;
        display: block !important; /* 강제로 표시 */
    }
    
    /* 모바일에서 미리보기가 숨겨진 경우 */
    .preview-container.mobile-hidden {
        display: none !important;
    }
    
    .editor-container.mobile-full {
        height: calc(100vh - var(--header-height) - var(--footer-height) - 80px);
    }
    
    /* 미리보기 토글 버튼 상태 표시 */
    #togglePreview.preview-hidden {
        background-color: var(--bs-success) !important;
        color: white !important;
        border-color: var(--bs-success) !important;
    }
    
    #togglePreview.preview-visible {
        background-color: var(--bs-secondary) !important;
        color: white !important;
        border-color: var(--bs-secondary) !important;
    }
}

@media (max-width: 576px) {
    /* 초소형 화면 최적화 */
    .btn-toolbar {
        justify-content: center;
    }
    
    .btn-group-sm .btn {
        font-size: 0.65rem;
        padding: 0.15rem 0.3rem;
        min-width: 28px;
        height: 28px;
    }
    
    /* 에디터 상태 텍스트 크기 조정 */
    #editorStatus {
        font-size: 0.7rem;
    }
    
    /* 네비게이션 브랜드 크기 조정 */
    .navbar-brand {
        font-size: 1.2rem;
    }
    
    .navbar-brand i {
        font-size: 1.4rem;
    }
    
    /* 모바일에서 에디터/미리보기 높이 조정 */
    .editor-container {
        height: 40vh;
    }
    
    .preview-container {
        height: 40vh;
    }
}

/* 모바일 도구바 아이콘 전용 스타일 */
@media (max-width: 768px) {
    .btn-group-sm .btn i {
        font-size: 0.8rem;
    }
    
    /* 텍스트가 있는 버튼들 (H1, H2, H3) 최적화 */
    .btn-group-sm .btn:not(:has(i)) {
        font-size: 0.6rem;
        font-weight: 600;
        padding: 0.15rem 0.25rem;
    }
}

/* ===================================
 전체화면 모드
=================================== */

/* 실제 전체화면 모드 */
:fullscreen main,
:-webkit-full-screen main,
:-moz-full-screen main {
    height: 100vh !important;
}

:fullscreen .navbar,
:-webkit-full-screen .navbar,
:-moz-full-screen .navbar {
    position: relative !important;
}

/* 의사 전체화면 모드 (대체 방법) */
.pseudo-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background: var(--bs-body-bg) !important;
    overflow: hidden !important;
}

.pseudo-fullscreen main {
    height: calc(100vh - var(--header-height)) !important;
}

.pseudo-fullscreen .navbar {
    position: relative !important;
}

/* 전체화면에서 스크롤바 숨김 */
:fullscreen,
:-webkit-full-screen,
:-moz-full-screen,
.pseudo-fullscreen {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

:fullscreen::-webkit-scrollbar,
:-webkit-full-screen::-webkit-scrollbar,
:-moz-full-screen::-webkit-scrollbar,
.pseudo-fullscreen::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* ===================================
 스크롤바 스타일
=================================== */

.preview-content::-webkit-scrollbar,
#markdownEditor::-webkit-scrollbar {
    width: 8px;
}

.preview-content::-webkit-scrollbar-track,
#markdownEditor::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.preview-content::-webkit-scrollbar-thumb,
#markdownEditor::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.preview-content::-webkit-scrollbar-thumb:hover,
#markdownEditor::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ===================================
 로딩 및 상태 표시
=================================== */

.loading {
    opacity: 0.6;
    pointer-events: none;
}

.status-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    z-index: 10;
}

/* ===================================
 애니메이션 효과
=================================== */

.editor-container,
.preview-container {
    transition: all 0.3s ease;
}

.btn {
    transition: all 0.2s ease;
}

.preview-content {
    transition: opacity 0.3s ease;
}

/* ===================================
 프린트 스타일
=================================== */

@media print {
    .navbar,
    .toolbar,
    .editor-container {
        display: none !important;
    }
    
    .preview-container {
        width: 100% !important;
        height: auto !important;
        border: none !important;
    }
    
    .preview-content {
        height: auto !important;
        overflow: visible !important;
        padding: 0 !important;
    }
}
