body {
    line-height: 1.6;
    overflow: hidden;
}

.app-wrapper {
    display: grid;
    /* 사이드바, 리사이저, 콘텐츠 뷰어 */
    grid-template-columns: 320px 5px 1fr;
    height: 100vh;
}

.resizer {
    background-color: var(--border-color);
    cursor: col-resize;
    transition: background-color 0.2s;
}
.resizer:hover {
    background-color: var(--primary-color);
}

/* 기본 파일 인풋 숨기기 */
#md-input {
    display: none;
}

/* --- Sidebar --- */
.sidebar {
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.sidebar-title-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
    font-size: 1.5rem;
    margin: 0;
    color: var(--text-color);
}

.search-container {
    position: relative;
}

.search-container .fa-search {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

#search-input {
    width: 90%; /* 사용자 요청에 따라 가로 사이즈 추가 축소 */
    box-sizing: border-box; /* 패딩을 너비에 포함하여 계산 */
    padding: 0.75rem 0.75rem 0.75rem 2.5rem;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-color-hover);
}

.file-upload-area {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.custom-file-upload {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem;
    transition: background-color 0.2s, transform 0.2s;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.custom-file-upload:hover, .sidebar.dragover .custom-file-upload {
    background-color: var(--primary-hover);
    transform: scale(1.02);
    border-color: var(--primary-hover);
}

.custom-file-upload span {
    font-weight: 600;
    font-size: 1.1rem;
}

.custom-file-upload small {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 0.25rem;
}

.custom-file-upload .fa-cloud-upload-alt {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.file-list-nav {
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

#file-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

/* Drag and Drop Ghost Class */
.sortable-ghost {
    opacity: 0.4;
    background-color: var(--primary-hover);
}

#file-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 1rem; /* 세로 여백 축소 */
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
    cursor: grab;
}

#file-list li.active {
    background-color: var(--primary-color);
}

#file-list li.active a, #file-list li.active .file-date {
    color: white;
}

#file-list li:hover {
    background-color: var(--card-bg);
}

#file-list a {
    text-decoration: none;
    color: var(--text-color);
    cursor: pointer;
    flex-grow: 1;
    min-width: 0; /* Important for flexbox truncation */
}

.file-info .highlight {
    background-color: var(--primary-hover);
    color: white;
    padding: 2px 0;
    border-radius: 3px;
}

.file-select-checkbox {
    flex-shrink: 0;
    margin-right: 0.75rem;
    display: flex;
    align-items: center;
}

.file-link {
    text-decoration: none;
    color: var(--text-color);
    cursor: pointer;
    flex-grow: 1;
}

.file-info {
    display: block;
    font-weight: 500;
    font-size: 0.9rem; /* 폰트 사이즈 축소 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-date {
    display: block;
    font-size: 0.7rem; /* 폰트 사이즈 축소 */
    color: var(--text-muted);
    margin-top: 2px;
}

.file-item-actions {
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.btn-delete-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    font-size: 0.9rem;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    line-height: 1;
    transition: color 0.2s, background-color 0.2s;
}

.btn-delete-icon:hover {
    color: var(--error-color);
    background-color: rgba(220, 53, 69, 0.1);
}

/* --- Content Viewer --- */
.content-viewer {
    background-color: var(--bg-color);
    padding: 0;
    overflow-y: auto;
    height: 100vh;
    box-sizing: border-box; /* 패딩과 테두리를 높이에 포함하여 스크롤 문제 해결 */
    display: flex;
    flex-direction: column;
}

.content-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#content-body-wrapper {
    flex-grow: 1;
    position: relative; /* For positioning welcome screen */
    overflow-y: auto;
    padding: 0 3rem 2rem 3rem;
}

#welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    text-align: center;
    color: var(--text-muted);
    position: absolute;
    top: 0;
    left: 0;
}

.welcome-icon {
    font-size: 5rem;
    margin-bottom: 2rem;
    opacity: 0.5;
}

#content-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 3rem;
    border-bottom: 1px solid var(--border-color);
    gap: 1rem;
    flex-shrink: 0;
    background-color: var(--bg-color);
}

.content-header-main {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-grow: 1;
    min-width: 0; /* for text truncation */
}

#md-title {
    font-size: 1.8rem;
    margin: 0;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#md-output-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* --- Editor Toolbar --- */
#editor-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

#editor-toolbar button {
    background: none;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    font-size: 0.9rem;
    border-radius: 5px;
    width: 36px;
    height: 36px;
    line-height: 1;
    transition: color 0.2s, background-color 0.2s;
}

#editor-toolbar button:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* --- Split View for Editor --- */
#content-body.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: 100%;
}

#content-body.split-view #editor-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#content-body.split-view #md-editor {
    resize: none; /* Disable resizing in split view */
    height: auto;
    flex-grow: 1;
}

#content-body.split-view #md-output {
    height: 100%;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
}

.md-editor-textarea {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 1rem;
    line-height: 1.6;
    background-color: var(--bg-color);
    color: var(--text-color);
    resize: vertical;
}

#editor-wrapper .md-editor-textarea {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    height: 100%;
}

.md-editor-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 25%, transparent);
}

#md-output {
    color: var(--text-color);
}

/* --- Buttons --- */
.btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--card-bg);
    white-space: nowrap; /* 버튼 내 텍스트 줄바꿈 방지 */
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.9rem;
    margin-left: 0.5rem;
    transition: background-color 0.2s, border-color 0.2s;
}

.btn-icon {
    display: none; /* Hidden by default, shown on mobile */
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    font-size: 1.2rem;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    line-height: 1;
    transition: color 0.2s, background-color 0.2s;
}

.btn-icon:hover {
    color: var(--text-color);
    background-color: var(--bg-color);
}

.btn:hover {
    background-color: var(--border-color);
}

.btn-danger {
    border-color: var(--error-color);
    color: var(--error-color);
}

.btn-danger-outline {
    background-color: transparent;
    border: 1px solid var(--error-color);
    color: var(--error-color);
}

.btn-danger:hover {
    background-color: var(--error-color);
    color: white;
}
.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}
.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}
.btn-primary:disabled {
    background-color: var(--text-muted);
    border-color: var(--text-muted);
    cursor: not-allowed;
}

/* --- Rendered Markdown Styles --- */
#md-output h1, #md-output h2, #md-output h3,
#fullscreen-output h1, #fullscreen-output h2, #fullscreen-output h3 {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
}
#md-output a,
#fullscreen-output a { color: var(--primary-hover); }
#md-output code,
#fullscreen-output code {
    background-color: var(--card-bg);
    padding: 0.2em 0.4em;
    margin: 0;
    font-size: 85%;
    border-radius: 6px;
}
#md-output pre,
#fullscreen-output pre {
    background-color: var(--card-bg);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
}
#md-output pre code,
#fullscreen-output pre code {
    padding: 0;
    background: none;
}
#md-output blockquote,
#fullscreen-output blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1rem;
    color: var(--text-muted);
    margin-left: 0;
}
#md-output table,
#fullscreen-output table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
}
#md-output th, #md-output td,
#fullscreen-output th, #fullscreen-output td {
    border: 1px solid var(--border-color);
    padding: 0.75rem;
}
#md-output th,
#fullscreen-output th {
    background-color: var(--card-bg);
}

/* Other styles (modal, upload progress) remain similar but should be adapted to the dark theme */

/* --- Fullscreen Modal --- */
.modal {
    display: none; /* 기본적으로 숨김 */
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: var(--card-bg);
    margin: 2.5% auto; /* 세로 마진 조정 */
    padding: 2rem;
    border: 1px solid var(--border-color);
    width: 90%; /* 가로 사이즈 증가 */
    max-width: 1600px; /* 최대 가로 사이즈 증가 */
    border-radius: 12px;
    position: relative;
    height: 90vh; /* 세로 사이즈 증가 */
    display: flex;
    flex-direction: column;
}

#fullscreen-output {
    flex-grow: 1;
    overflow-y: auto; /* 모달 내부 콘텐츠 스크롤 */
    padding-right: 1.5rem; /* 스크롤바가 콘텐츠를 가리지 않도록 공간 확보 */
}

.close-btn {
    color: var(--text-muted);
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
}
.close-btn:hover { color: var(--text-color); }

/* Pagination Styles */
#pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
}

.pagination-btn {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 0.8rem;
}

.pagination-btn:hover:not(:disabled) {
    background-color: var(--primary-color);
    color: white;
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.no-results {
    padding: 1rem 1.5rem;
    color: var(--text-muted);
    text-align: center;
    justify-content: center;
}

/* Upload Progress List Styles */
#upload-list-container {
    width: 100%;
    padding: 0 1.5rem;
    box-sizing: border-box;
    margin-top: 1rem;
}

.upload-item {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    background-color: var(--card-bg);
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.upload-item-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
    font-size: 0.85rem;
}

.progress-container {
    width: 80px;
    background-color: var(--bg-color);
    border-radius: 8px;
    overflow: hidden;
    height: 16px; /* 높이 축소 */
}

.progress-bar {
    height: 100%;
    width: 0%;
    background-color: var(--primary-color);
    text-align: center;
    line-height: 16px; /* 높이에 맞게 수정 */
    color: white;
    font-size: 0.7rem; /* 폰트 크기 축소 */
    font-weight: bold;
    transition: width 0.3s ease-in-out;
}

.upload-status {
    width: 30px;
    text-align: center;
    font-size: 1rem;
    margin-left: 10px;
    color: var(--primary-color);
}

/* File Action Bar */
.file-actions-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    /* min-height는 버튼 토글 로직으로 대체되어 더 이상 불필요합니다. */
}

.action-buttons-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#delete-count-display {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.select-all-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}
.action-button-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .app-wrapper {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: fixed; top: 0; left: 0; width: 300px; max-width: 85%;
        z-index: 3000; transform: translateX(-100%);
        transition: transform 0.3s ease-in-out; box-shadow: 0 0 20px rgba(0,0,0,0.2);
    }
    .sidebar.visible { transform: translateX(0); }
    .resizer { display: none; }
    #content-viewer-header { padding: 1rem; }
    #content-body-wrapper { padding: 1.5rem; }
    .btn-icon { display: inline-flex; }
    .sidebar-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); z-index: 2999; }
    .sidebar-overlay.visible { display: block; }
}

/* Custom Checkbox */
.custom-checkbox {
    position: relative;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    user-select: none;
}
.custom-checkbox input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}
.checkmark {
    position: relative;
    height: 18px;
    width: 18px;
    background-color: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    transition: background-color 0.2s, border-color 0.2s;
    margin-right: 0.75rem;
}
.custom-checkbox:hover input ~ .checkmark { border-color: var(--primary-color); }
.custom-checkbox input:checked ~ .checkmark { background-color: var(--primary-color); border-color: var(--primary-color); }
.checkmark:after { content: ""; position: absolute; display: none; }
.custom-checkbox input:checked ~ .checkmark:after { display: block; }
.custom-checkbox .checkmark:after { left: 5px; top: 1px; width: 5px; height: 10px; border: solid white; border-width: 0 3px 3px 0; transform: rotate(45deg); }

.select-all-label input { margin-right: 0.5rem; }
