/* Modern Tree Viewer CSS */

:root {
    --sidebar-width: 320px;
    --header-height: 120px;
}

/* Light theme (default) */
:root, [data-theme="light"] {
    --bg-color: #f5f5f5;
    --sidebar-bg: #fafafa;
    --border-color: #e0e0e0;
    --text-color: #333;
    --text-muted: #666;
    --primary-color: #1976d2;
    --primary-hover: #1565c0;
    --selected-bg: #e3f2fd;
    --hover-bg: #f0f0f0;
    --tree-line-color: #ccc;
    --article-bg: #fff;
    --input-bg: #fff;
    --shadow: rgba(0, 0, 0, 0.1);
}

/* Dark theme */
[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --sidebar-bg: #242424;
    --border-color: #3a3a3a;
    --text-color: #e0e0e0;
    --text-muted: #a0a0a0;
    --primary-color: #64b5f6;
    --primary-hover: #90caf9;
    --selected-bg: #263238;
    --hover-bg: #2d2d2d;
    --tree-line-color: #444;
    --article-bg: #1e1e1e;
    --input-bg: #2a2a2a;
    --shadow: rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    color: var(--text-color);
    background: var(--bg-color);
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

#app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    min-width: 200px;
    max-width: 500px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background 0.3s ease, border-color 0.3s ease;
}

#tree-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--sidebar-bg);
    transition: background 0.3s ease, border-color 0.3s ease;
}

#tree-header h1 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-color);
    transition: color 0.3s ease;
}

.tree-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tree-controls button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.15s ease;
}

.tree-controls button:hover {
    background: var(--hover-bg);
    color: var(--text-color);
}

.tree-controls button svg {
    width: 16px;
    height: 16px;
}

#search {
    flex: 1;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    background: var(--input-bg);
    color: var(--text-color);
    transition: border-color 0.15s ease, background 0.3s ease, color 0.3s ease;
}

#search:focus {
    border-color: var(--primary-color);
}

#search::placeholder {
    color: var(--text-muted);
}

/* Tree Container */
#tree-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

#tree-container::-webkit-scrollbar {
    width: 8px;
}

#tree-container::-webkit-scrollbar-track {
    background: transparent;
}

#tree-container::-webkit-scrollbar-thumb {
    background: var(--tree-line-color);
    border-radius: 4px;
}

#tree-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Tree Nodes */
.tree-node {
    display: flex;
    align-items: flex-start;
    padding: 4px 8px;
    cursor: pointer;
    user-select: none;
    position: relative;
}

.tree-node:hover {
    background: var(--hover-bg);
}

.tree-node.selected {
    background: var(--selected-bg);
}

.tree-node.selected .tree-node-title {
    color: var(--primary-color);
    font-weight: 500;
}

/* Indentation */
.tree-node-children {
    display: none;
}

.tree-node-children.expanded {
    display: block;
}

/* Toggle Icon */
.tree-toggle {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 4px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.15s ease, color 0.15s ease;
}

.tree-toggle:hover {
    color: var(--text-color);
}

.tree-toggle svg {
    width: 12px;
    height: 12px;
}

.tree-toggle.expanded {
    transform: rotate(90deg);
}

.tree-toggle.empty {
    visibility: hidden;
}

/* Tree Lines */
.tree-node {
    position: relative;
}

.tree-node::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--tree-line-color);
    display: none;
}

.tree-node-with-children::after {
    content: '';
    position: absolute;
    left: 10px;
    top: 50%;
    width: 10px;
    height: 1px;
    background: var(--tree-line-color);
    display: none;
}

/* Node Title */
.tree-node-title {
    flex: 1;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.tree-node-title.empty {
    color: #999;
    font-style: italic;
}

/* Search Highlight */
.highlight {
    background: #ffeb3b;
    border-radius: 2px;
    color: #333;
}

[data-theme="dark"] .highlight {
    background: #f9a825;
    color: #000;
}

/* Main Content */
#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--article-bg);
    transition: background 0.3s ease;
}

#article-viewer {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

#article-viewer::-webkit-scrollbar {
    width: 8px;
}

#article-viewer::-webkit-scrollbar-track {
    background: var(--bg-color);
}

#article-viewer::-webkit-scrollbar-thumb {
    background: var(--tree-line-color);
    border-radius: 4px;
}

#article-viewer::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

#article-content {
    line-height: 1.7;
    color: var(--text-color);
}

#article-content .placeholder {
    color: var(--text-muted);
    text-align: center;
    margin-top: 100px;
    font-size: 16px;
}

/* Article content styling */
#article-content h1,
#article-content h2,
#article-content h3,
#article-content h4,
#article-content h5,
#article-content h6 {
    margin: 24px 0 16px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-color);
}

#article-content h1 { font-size: 28px; }
#article-content h2 { font-size: 24px; }
#article-content h3 { font-size: 20px; }
#article-content h4 { font-size: 18px; }

#article-content p {
    margin: 12px 0;
}

#article-content ul,
#article-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

#article-content li {
    margin: 6px 0;
}

#article-content a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.15s ease;
}

#article-content a:hover {
    text-decoration: underline;
}

#article-content code {
    background: var(--hover-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

#article-content pre {
    background: var(--hover-bg);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 16px 0;
}

#article-content pre code {
    background: none;
    padding: 0;
}

#article-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--text-muted);
}

#article-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 16px 0;
}

#article-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
}

#article-content th,
#article-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

#article-content th {
    background: var(--bg-color);
    font-weight: 600;
}

/* Loading state */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    margin-left: 12px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error state */
.error {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
}

.error p {
    margin: 8px 0;
}

.error small {
    font-size: 12px;
    opacity: 0.7;
}

/* Theme toggle button specific */
#theme-toggle svg {
    width: 16px;
    height: 16px;
}

/* Responsive */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        max-width: none;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    #article-viewer {
        padding: 16px;
    }
}
