/* ========================================
   CSS VARIABLES (THEME)
   ======================================== */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-code: #f6f8fa;
    --text-primary: #24292e;
    --text-secondary: #586069;
    --border-color: #e1e4e8;
    --accent-color: #0366d6;
    --sidebar-width: 280px;
    --toc-width: 220px;
}

[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-code: #1c2128;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --border-color: #30363d;
    --accent-color: #58a6ff;
}

/* ========================================
   LAYOUT
   ======================================== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: background 0.3s, color 0.3s;
}

.header {
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
    flex-shrink: 0;
}

.header h1 {
    margin: 0;
    font-size: 20px;
    white-space: nowrap;
}

.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 20px;
    flex-shrink: 0;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
}

.content-inner {
    max-width: 800px;
    margin: 0 auto;
}

.toc-panel {
    width: var(--toc-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 20px;
    flex-shrink: 0;
}

/* ========================================
   HEADER COMPONENTS
   ======================================== */
.search-container {
    flex: 1;
    max-width: 500px;
}

#search-input {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

#search-input:focus {
    border-color: var(--accent-color);
}

.theme-toggle {
    padding: 8px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    transition: background 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
}

/* ========================================
   MOBILE MENU
   ======================================== */
.menu-button {
    display: none;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-primary);
    transition: background 0.2s;
}

.menu-button:hover {
    background: var(--bg-secondary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

/* ========================================
   SIDEBAR - SPECIAL LINKS
   ======================================== */
.special-links {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.special-link {
    display: block;
    padding: 10px 12px;
    background: var(--accent-color);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: opacity 0.2s;
}

.special-link:hover {
    opacity: 0.9;
}

/* ========================================
   SIDEBAR - CATEGORY & FILES
   ======================================== */
.category {
    margin-bottom: 20px;
}

.category-title {
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    user-select: none;
}

.category-title:hover {
    color: var(--text-primary);
}

.category-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.category-arrow.expanded {
    transform: rotate(90deg);
}

.category-count {
    margin-left: auto;
    font-size: 12px;
    opacity: 0.7;
}

.file-list {
    display: block;
}

.file-list.collapsed {
    display: none;
}

.file-item {
    padding: 8px 12px;
    margin: 4px 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-item:hover {
    background: var(--bg-primary);
}

.file-item.active {
    background: var(--accent-color);
    color: white;
}

/* ========================================
   MARKDOWN CONTENT STYLING
   ======================================== */
.content-area h1 {
    font-size: 2em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
    margin-top: 0;
    margin-bottom: 16px;
}

.content-area h2 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
    margin-top: 24px;
    margin-bottom: 16px;
}

.content-area h3 {
    font-size: 1.25em;
    margin-top: 24px;
    margin-bottom: 16px;
}

.content-area h4 {
    font-size: 1em;
    margin-top: 24px;
    margin-bottom: 16px;
}

.content-area code {
    background: var(--bg-code);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.content-area pre {
    background: var(--bg-code);
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    line-height: 1.45;
}

.content-area pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
}

.content-area table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
}

.content-area th,
.content-area td {
    border: 1px solid var(--border-color);
    padding: 8px 13px;
    text-align: left;
}

.content-area th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.content-area tr:nth-child(even) {
    background: var(--bg-secondary);
}

.content-area blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 16px;
    color: var(--text-secondary);
    margin: 16px 0;
}

.content-area a {
    color: var(--accent-color);
    text-decoration: none;
}

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

.content-area img {
    max-width: 100%;
    height: auto;
}

.content-area ul,
.content-area ol {
    padding-left: 2em;
}

.content-area li {
    margin: 4px 0;
}

.content-area hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 24px 0;
}

/* ========================================
   TOC PANEL
   ======================================== */
.toc-panel h4 {
    margin-top: 0;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.toc-item {
    padding: 4px 0;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toc-item:hover {
    color: var(--accent-color);
}

.toc-item.active {
    color: var(--accent-color);
    font-weight: 600;
}

.toc-item.toc-h2 { padding-left: 0; }
.toc-item.toc-h3 { padding-left: 15px; }
.toc-item.toc-h4 { padding-left: 30px; }

/* ========================================
   LOADING & EMPTY STATES
   ======================================== */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.search-results-header {
    padding: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 10px;
}

.search-result-item {
    padding: 12px;
    margin: 4px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: var(--bg-primary);
}

.search-result-title {
    font-weight: 500;
    margin-bottom: 4px;
}

.search-result-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 1200px) {
    .toc-panel {
        display: none;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 60px;
        bottom: 0;
        z-index: 100;
        transition: left 0.3s;
        box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    }

    .sidebar.open {
        left: 0;
    }

    .content-area {
        padding: 20px;
    }

    .menu-button {
        display: block;
    }
}
