/* 全域樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --bg-color: #f5f7fa;
    --card-bg: #ffffff;
    --text-color: #333333;
    --border-color: #e1e8ed;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.7; /* 提升可讀性 */
    font-size: 16px; /* 基礎字體大小 */
}

.container {
    max-width: 1800px; /* 擴大佈局 */
    margin: 0 auto;
    padding: 20px;
}

/* 標題區 */
header {
    text-align: center;
    padding: 28px 0;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 2.5em; /* 標題加大 */
    margin-bottom: 8px;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

/* 導航列 */
.main-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.nav-btn {
    padding: 12px 28px;
    border: none;
    background: var(--card-bg);
    color: var(--text-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.05em;
    font-weight: 500;
    transition: all 0.3s;
    box-shadow: var(--shadow);
}

.nav-btn:hover {
    background: var(--secondary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.nav-btn.active {
    background: var(--secondary-color);
    color: white;
    box-shadow: var(--shadow-hover);
}

/* 上方篩選區 */
.filter-bar {
    background: var(--card-bg);
    padding: 20px 24px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.search-box {
    margin-bottom: 18px;
}

.search-box input {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1em;
    transition: all 0.3s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.15);
}

/* 篩選區域：彈性佈局 */
.filter-sections {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.filter-section {
    flex: 1;
    min-width: 220px;
}

.filter-section h3 {
    font-size: 0.9em;
    margin-bottom: 12px;
    color: var(--primary-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.stats-section {
    background: transparent;
    padding: 0;
    border-radius: 0;
    flex-basis: 200px; /* 固定寬度 */
}

.stats-section h3 {
    font-size: 0.9em;
    margin-bottom: 12px;
    color: var(--primary-color);
    font-weight: 600;
}

.stats-section #stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.9em;
    color: var(--text-color);
}

.stats-section #stats span {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stats-section #stats strong {
    color: var(--secondary-color);
    font-weight: 700;
    font-size: 1.1em;
}

.stats-section #stats select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 0.9em;
    width: 100%;
}

/* 主要內容區：三欄式佈局 */
.main-content {
    display: grid;
    grid-template-columns: 340px 1fr; /* 左側固定寬度 */
    gap: 20px;
    position: relative;
    min-height: 600px;
}

.tag-list, .category-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
}

.tag-item, .category-item {
    padding: 6px 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 15px; /* 圓角 */
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85em;
    white-space: nowrap;
}

.tag-item:hover, .category-item:hover {
    background: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
    transform: translateY(-1px);
}

.tag-item.active, .category-item.active {
    background: var(--secondary-color);
    color: white;
    border-color: var(--secondary-color);
    font-weight: 500;
}

.count {
    background: rgba(0, 0, 0, 0.1);
    color: var(--primary-color);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.8em;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

.stats-section {
    background: var(--bg-color);
    padding: 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

/* 左側：筆記列表面板 */
.notes-list-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    max-height: calc(100vh - 320px); /* 調整高度 */
    overflow-y: auto;
    position: sticky;
    top: 20px;
}

.notes-list-panel .panel-title {
    color: var(--primary-color);
    font-size: 1.2em;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.notes-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 右側：筆記詳情面板 */
.note-detail-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    max-height: calc(100vh - 280px); /* 調整高度 */
    overflow-y: auto;
    position: sticky;
    top: 20px;
}

.note-detail-panel .detail-content {
    line-height: 1.8;
}

.note-detail-panel .empty-state {
    text-align: center;
    padding: 80px 30px;
    color: #999;
}

.note-detail-panel .empty-state h2 {
    font-size: 1.5em;
    margin-bottom: 12px;
    color: #bbb;
}

.note-detail-panel .empty-state p {
    font-size: 1em;
    color: #ccc;
}

/* 筆記卡片（列表視圖）*/
.note-card {
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 14px;
    cursor: pointer;
    transition: all 0.25s;
    position: relative;
}

.note-card:hover {
    background: white;
    border-color: var(--secondary-color);
    box-shadow: var(--shadow);
    transform: translateX(4px);
}

.note-card.active {
    background: white;
    border-color: var(--secondary-color);
    box-shadow: var(--shadow);
}

.note-card .note-id {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--secondary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75em;
    font-weight: bold;
}

.note-card .note-type {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.75em;
    margin-bottom: 6px;
    font-weight: 500;
}

.note-card .note-type.permanent {
    background: #27ae60;
    color: white;
}

.note-card .note-type.literature {
    background: #f39c12;
    color: white;
}

.note-card .note-type.fleeting {
    background: #95a5a6;
    color: white;
}

.note-card h3 {
    margin: 6px 0;
    color: var(--primary-color);
    font-size: 1em;
    line-height: 1.4;
    padding-right: 60px;
}

.note-card .note-preview {
    color: #666;
    font-size: 0.85em;
    line-height: 1.4;
    margin: 6px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.note-card .note-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.note-card .tag {
    background: rgba(52, 152, 219, 0.1);
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 0.75em;
    color: var(--secondary-color);
}

.note-card .note-meta {
    margin-top: 8px;
    font-size: 0.75em;
    color: #999;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 詳情面板 */
.detail-panel {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.detail-panel.hidden {
    display: none;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--accent-color);
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5em;
    line-height: 1;
    transition: transform 0.3s;
}

.close-btn:hover {
    transform: rotate(90deg);
}

#detailContent h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

#detailContent .detail-section {
    margin: 20px 0;
}

#detailContent .detail-section h3 {
    color: var(--secondary-color);
    margin-bottom: 10px;
    font-size: 1.1em;
}

#detailContent .content-text {
    line-height: 1.8;
    color: var(--text-color);
}

#detailContent .links-list {
    list-style: none;
}

#detailContent .links-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

#detailContent .links-list a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color 0.3s;
}

#detailContent .links-list a:hover {
    color: var(--accent-color);
}

/* 關聯圖 */
.graph-container {
    width: 100%;
    height: 600px;
    position: relative;
    background: var(--bg-color);
    border-radius: 12px;
    overflow: hidden;
}

#graphCanvas {
    width: 100%;
    height: 100%;
}

.graph-info {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9em;
}

/* 響應式設計 */
@media (max-width: 768px) {
    /* 篩選區改為單欄 */
    .filter-sections {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .filter-bar {
        padding: 12px 16px;
    }

    .search-box {
        margin-bottom: 10px;
    }

    .filter-section h3,
    .stats-section h3 {
        font-size: 0.8em;
    }

    /* 主內容改為單欄 */
    .main-content {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .notes-list-panel {
        position: static;
        max-height: 300px;
        order: 1;
    }

    .note-detail-panel {
        position: static;
        max-height: 500px;
        order: 2;
    }

    .note-detail-panel .empty-state {
        padding: 40px 20px;
    }

    .note-detail-panel .empty-state h2 {
        font-size: 1.3em;
    }

    /* 導航和標題 */
    header h1 {
        font-size: 1.8em;
    }

    .main-nav {
        flex-direction: column;
    }

    .nav-btn {
        width: 100%;
    }

    /* 筆記卡片 */
    .note-card h3 {
        font-size: 0.95em;
    }

    .note-card .note-preview {
        font-size: 0.8em;
    }

    /* 標籤和分類 */
    .tag-item, .category-item {
        font-size: 0.8em;
        padding: 5px 10px;
    }
}

/* 空狀態 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.empty-state h3 {
    font-size: 1.5em;
    margin-bottom: 10px;
}

/* Markdown 內容樣式 */
.markdown-content {
    line-height: 1.8;
    color: var(--text-color);
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--primary-color);
}

.markdown-content h1 {
    font-size: 2em;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

.markdown-content h2 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.markdown-content h3 {
    font-size: 1.25em;
}

.markdown-content h4 {
    font-size: 1.1em;
}

.markdown-content p {
    margin-bottom: 16px;
}

.markdown-content strong {
    font-weight: 600;
    color: var(--primary-color);
}

.markdown-content em {
    font-style: italic;
}

.markdown-content ul,
.markdown-content ol {
    margin-bottom: 16px;
    padding-left: 2em;
}

.markdown-content ul {
    list-style-type: disc;
}

.markdown-content ol {
    list-style-type: decimal;
}

.markdown-content li {
    margin-bottom: 8px;
}

.markdown-content li > ul,
.markdown-content li > ol {
    margin-top: 8px;
    margin-bottom: 8px;
}

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

.markdown-content pre {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 16px;
    overflow-x: auto;
    margin-bottom: 16px;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    color: var(--text-color);
    font-size: 0.95em;
}

.markdown-content blockquote {
    border-left: 4px solid var(--secondary-color);
    margin: 16px 0;
    padding: 8px 16px;
    background: var(--bg-color);
    color: #666;
}

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

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

.markdown-content table th {
    background: var(--bg-color);
    font-weight: 600;
    color: var(--primary-color);
}

.markdown-content table tr:nth-child(even) {
    background: var(--bg-color);
}

.markdown-content a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color 0.3s;
}

.markdown-content a:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

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

.markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 16px 0;
}

/* GitHub 同步按鈕 */
.github-btn {
    background: linear-gradient(135deg, #24292e, #444d56) !important;
    color: white !important;
}

.github-btn:hover {
    background: linear-gradient(135deg, #444d56, #586069) !important;
}

/* 模態視窗 */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    max-width: 700px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    position: relative;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    transition: color 0.3s;
}

.close-modal:hover {
    color: var(--accent-color);
}

.modal-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-section:last-child {
    border-bottom: none;
}

.modal-section h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.1em;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95em;
    transition: all 0.3s;
    background: var(--bg-color);
    color: var(--text-color);
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.modal-btn.primary {
    background: var(--secondary-color);
    color: white;
}

.modal-btn.primary:hover {
    background: #2980b9;
}

.modal-btn.warning {
    background: #f39c12;
    color: white;
}

.modal-btn.warning:hover {
    background: #e67e22;
}

.modal-btn.danger {
    background: var(--accent-color);
    color: white;
}

.modal-btn.danger:hover {
    background: #c0392b;
}

.status-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* 備份歷史列表 */
.backup-list {
    list-style: none;
    padding: 0;
}

.backup-item {
    padding: 10px;
    margin: 5px 0;
    background: var(--bg-color);
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.backup-item:hover {
    background: #e8f4f8;
}

.backup-item button {
    padding: 5px 10px;
    font-size: 0.85em;
}
