/* components-docs.css - Documentation explorer styles */

/* ============================================
   Doc Explorer Layout
   ============================================ */

/* Constrain body to viewport when doc explorer is present */
body:has(.doc-explorer) {
    height: 100vh;
    overflow: hidden;
}

.doc-explorer {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.doc-tree-panel {
    min-width: 220px;
    max-width: 50%;
    width: 280px;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* clip content so .doc-tree-content scrollbar engages */
    background: var(--bg-color-secondary, #f5f5f5);
    border-right: 1px solid var(--border-color, #dbdbdb);
}

.doc-tree-header {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color, #dbdbdb);
    flex-shrink: 0;
}

.doc-tree-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.35rem;
}

.doc-tree-content {
    flex: 1;
    min-height: 0; /* flex-child must declare min-height:0 for overflow:auto to scroll */
    overflow: auto;
    padding: 0.25rem;
}

.doc-content-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    overflow: hidden;
    position: relative;
}


.doc-breadcrumbs {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color, #dbdbdb);
    font-size: 0.85rem;
    flex-shrink: 0;
    min-height: 2rem;
    color: var(--text-color, #363636);
    position: relative;
    z-index: 1;
}

.doc-breadcrumbs a {
    color: var(--link-color, #3273dc);
    text-decoration: none;
}

.doc-breadcrumbs a:hover {
    text-decoration: underline;
}

.doc-breadcrumbs .separator {
    margin: 0 0.35rem;
    color: var(--text-muted, #666666);
}

.doc-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    position: relative;
    z-index: 1;
}

/* ============================================
   Doc Splitter (reuses editor pattern)
   ============================================ */
.doc-splitter {
    width: 6px;
    background: linear-gradient(to right, #e0e0e0, #f0f0f0, #e0e0e0);
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    transition: background 0.2s;
}

.doc-splitter:hover,
.doc-splitter.dragging {
    background: linear-gradient(to right, var(--primary-color, #3273dc), var(--link-color, #4a90e2), var(--primary-color, #3273dc));
}

.doc-splitter::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 30px;
    background: #999;
    border-radius: 1px;
}

.doc-splitter:hover::before,
.doc-splitter.dragging::before {
    background: #fff;
}

/* ============================================
   Markdown Content Styling
   ============================================ */
.doc-content h1 { font-size: 1.75rem; margin-bottom: 1rem; }
.doc-content h2 { font-size: 1.4rem; margin-top: 1.5rem; margin-bottom: 0.75rem; border-bottom: 1px solid var(--border-color, #dbdbdb); padding-bottom: 0.3rem; }
.doc-content h3 { font-size: 1.15rem; margin-top: 1.25rem; margin-bottom: 0.5rem; }

.doc-content pre {
    position: relative;
    background: var(--bg-color-secondary, #f5f5f5);
    border-radius: 4px;
    padding: 1rem;
    overflow-x: auto;
}

.doc-code-copy {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background: transparent;
    border: none;
    color: var(--text-color-light, #595959);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.25rem 0.4rem;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.15s;
}

.doc-content pre:hover .doc-code-copy {
    opacity: 1;
}

.doc-code-copy:hover {
    color: var(--text-color, #363636);
    background: var(--bg-color, rgba(0,0,0,0.06));
}

.doc-content code {
    background: var(--bg-color-secondary, #f5f5f5);
    padding: 0.15em 0.35em;
    border-radius: 3px;
    font-size: 0.9em;
}

.doc-content pre code {
    background: transparent;
    padding: 0;
}

.doc-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 1rem 0;
    border: 1px solid var(--border-color, #dbdbdb);
}

.doc-content table th,
.doc-content table td {
    border: 1px solid var(--border-color, #dbdbdb);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.doc-content table th {
    background: var(--bg-color-secondary, #f5f5f5);
    font-weight: 600;
}

.doc-content blockquote {
    border-left: 4px solid var(--primary-color, #3273dc);
    padding: 0.5rem 1rem;
    margin: 1rem 0;
    background: var(--bg-color-secondary, #f5f5f5);
}

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

/* ============================================
   Search Results Dropdown
   ============================================ */
.doc-search-results {
    max-height: 300px;
    overflow-y: auto;
    border-top: 1px solid var(--border-color, #dbdbdb);
    background: var(--bg-color, #fff);
}

.doc-search-results-header {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted, #666);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.doc-search-result {
    display: block;
    padding: 0.35rem 0.5rem;
    text-decoration: none;
    border-bottom: 1px solid var(--border-color-light, #eee);
    color: var(--text-color, #363636);
}

.doc-search-result:hover {
    background: var(--bg-color-hover, #e8f4ff);
}

.doc-search-result-title {
    font-weight: 600;
    font-size: 0.85rem;
}

.doc-search-result-snippet {
    font-size: 0.75rem;
    color: var(--text-muted, #666);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-search-result-snippet mark {
    background: #fff3bf;
    padding: 0;
}

mark.doc-search-highlight {
    background: #fff3bf;
    padding: 0.1em 0;
    border-radius: 2px;
}

/* ============================================
   Folder Index Page
   ============================================ */
.doc-folder-index {
    list-style: none;
    padding-left: 0;
}

.doc-folder-index li {
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border-color-light, #eee);
}

.doc-folder-index li:last-child {
    border-bottom: none;
}

.doc-folder-index a {
    color: var(--link-color, #3273dc);
    text-decoration: none;
    font-weight: 500;
}

.doc-folder-index a:hover {
    text-decoration: underline;
}

/* ============================================
   FancyTree Overrides for Doc Explorer
   ============================================ */
.doc-tree-content ul.fancytree-container {
    font-family: inherit;
    font-size: 0.9rem;
    border: none;
    background: transparent;
    padding: 0.25rem;
}

.doc-tree-content .fancytree-node {
    padding: 1px 0;
}

.doc-tree-content .fancytree-active .fancytree-title {
    background-color: var(--primary-color-dark, #2457a8) !important;
    color: white !important;
    border-color: var(--primary-color-dark, #2457a8) !important;
    border-radius: 4px;
    box-shadow: inset 3px 0 0 rgba(255,255,255,0.3);
}

.doc-tree-content .fancytree-node:hover .fancytree-title {
    background-color: var(--bg-color-hover, #e8f4ff);
    border-color: var(--border-color, #b5d5ff);
}

.doc-tree-content .fancytree-match .fancytree-title {
    font-weight: bold;
}

.doc-tree-content span.fancytree-node.fancytree-match {
    background-color: #fffde7;
}

/* ============================================
   Section Accent Colors
   ============================================ */
:root {
    --doc-section-0: #3498db;
    --doc-section-1: #27ae60;
    --doc-section-2: #e67e22;
    --doc-section-3: #8e44ad;
    --doc-section-4: #e74c3c;
    --doc-section-5: #16a085;
    --doc-section-6: #f39c12;
    --doc-section-7: #607d8b;
}

/* Custom FA icon styling for leaf page icons */
.doc-tree-content .fancytree-custom-icon {
    display: inline-block;
    width: 1.1em;
    text-align: center;
    font-size: 0.85rem;
}

/* Hide default folder sprite icons — colored expander triangles replace them */
.doc-tree-content .fancytree-folder > .fancytree-icon {
    display: none;
}

/* Replace expander sprites with FA caret icons (folders only) */
.doc-tree-content .fancytree-expander {
    background-image: none !important;
    width: 1em;
    text-align: center;
}

.doc-tree-content .fancytree-has-children > .fancytree-expander {
    cursor: pointer;
}

.doc-tree-content .fancytree-has-children > .fancytree-expander::before {
    content: '\f0da';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.8rem;
    transition: transform 0.15s ease;
    display: inline-block;
}

.doc-tree-content .fancytree-expanded > .fancytree-expander::before {
    transform: rotate(90deg);
}

/* Section typography hierarchy */
span.fancytree-node.doc-section {
    margin-top: 0.6rem;
}

span.fancytree-node.doc-section:first-child {
    margin-top: 0;
}

span.fancytree-node.doc-section > .fancytree-title {
    font-weight: 600;
    font-size: 0.92rem;
    letter-spacing: 0.01em;
}

/* Section accent: colored expanders, page icons, and title borders */
span.fancytree-node.doc-section-0 > .fancytree-expander { color: var(--doc-section-0); }
span.fancytree-node.doc-section-0 > .fancytree-custom-icon { color: var(--doc-section-0); }
span.fancytree-node.doc-section-0:not(.doc-section-root) > .fancytree-title { border-left: 3px solid var(--doc-section-0); padding-left: 4px; }

span.fancytree-node.doc-section-1 > .fancytree-expander { color: var(--doc-section-1); }
span.fancytree-node.doc-section-1 > .fancytree-custom-icon { color: var(--doc-section-1); }
span.fancytree-node.doc-section-1:not(.doc-section-root) > .fancytree-title { border-left: 3px solid var(--doc-section-1); padding-left: 4px; }

span.fancytree-node.doc-section-2 > .fancytree-expander { color: var(--doc-section-2); }
span.fancytree-node.doc-section-2 > .fancytree-custom-icon { color: var(--doc-section-2); }
span.fancytree-node.doc-section-2:not(.doc-section-root) > .fancytree-title { border-left: 3px solid var(--doc-section-2); padding-left: 4px; }

span.fancytree-node.doc-section-3 > .fancytree-expander { color: var(--doc-section-3); }
span.fancytree-node.doc-section-3 > .fancytree-custom-icon { color: var(--doc-section-3); }
span.fancytree-node.doc-section-3:not(.doc-section-root) > .fancytree-title { border-left: 3px solid var(--doc-section-3); padding-left: 4px; }

span.fancytree-node.doc-section-4 > .fancytree-expander { color: var(--doc-section-4); }
span.fancytree-node.doc-section-4 > .fancytree-custom-icon { color: var(--doc-section-4); }
span.fancytree-node.doc-section-4:not(.doc-section-root) > .fancytree-title { border-left: 3px solid var(--doc-section-4); padding-left: 4px; }

span.fancytree-node.doc-section-5 > .fancytree-expander { color: var(--doc-section-5); }
span.fancytree-node.doc-section-5 > .fancytree-custom-icon { color: var(--doc-section-5); }
span.fancytree-node.doc-section-5:not(.doc-section-root) > .fancytree-title { border-left: 3px solid var(--doc-section-5); padding-left: 4px; }

span.fancytree-node.doc-section-6 > .fancytree-expander { color: var(--doc-section-6); }
span.fancytree-node.doc-section-6 > .fancytree-custom-icon { color: var(--doc-section-6); }
span.fancytree-node.doc-section-6:not(.doc-section-root) > .fancytree-title { border-left: 3px solid var(--doc-section-6); padding-left: 4px; }

span.fancytree-node.doc-section-7 > .fancytree-expander { color: var(--doc-section-7); }
span.fancytree-node.doc-section-7 > .fancytree-custom-icon { color: var(--doc-section-7); }
span.fancytree-node.doc-section-7:not(.doc-section-root) > .fancytree-title { border-left: 3px solid var(--doc-section-7); padding-left: 4px; }

/* ============================================
   Dark Mode
   ============================================ */
html.dark-mode .doc-tree-panel {
    background: var(--bg-color-secondary, #1a1a2e);
}

html.dark-mode .doc-splitter {
    background: linear-gradient(to right, #333, #444, #333);
}

html.dark-mode .doc-splitter:hover,
html.dark-mode .doc-splitter.dragging {
    background: linear-gradient(to right, var(--primary-color, #3273dc), var(--link-color, #4a90e2), var(--primary-color, #3273dc));
}

html.dark-mode .doc-content pre {
    background: var(--bg-color-secondary, #1a1a2e);
}

html.dark-mode .doc-code-copy:hover {
    color: #f5f5f5;
    background: rgba(255,255,255,0.1);
}

html.dark-mode .doc-content code {
    background: var(--bg-color-secondary, #1a1a2e);
}

html.dark-mode .doc-content table th {
    background: var(--bg-color-secondary, #1a1a2e);
}

html.dark-mode .doc-content blockquote {
    background: var(--bg-color-secondary, #1a1a2e);
}

html.dark-mode .doc-tree-content .fancytree-title {
    color: #f5f5f5;
}

html.dark-mode .doc-tree-content .fancytree-active .fancytree-title {
    background-color: var(--primary-color-dark, #2457a8) !important;
    color: white !important;
}

html.dark-mode .doc-tree-content .fancytree-node:hover .fancytree-title {
    background-color: #4a4a4a;
    border-color: #666;
}

html.dark-mode .doc-tree-content span.fancytree-node.fancytree-match {
    background-color: #4a4020;
}

/* Expanders use FA font color (no filter needed); leaf sprite icons still need invert */
html.dark-mode .doc-tree-content .fancytree-icon {
    filter: invert(0.8);
}

/* Brighter section accent colors for dark mode */
html.dark-mode {
    --doc-section-0: #5dade2;
    --doc-section-1: #58d68d;
    --doc-section-2: #f0b27a;
    --doc-section-3: #bb8fce;
    --doc-section-4: #ec7063;
    --doc-section-5: #48c9b0;
    --doc-section-6: #f7dc6f;
    --doc-section-7: #90a4ae;
}

html.dark-mode .doc-search-results {
    background: var(--bg-color-secondary, #1a1a2e);
}

html.dark-mode .doc-search-result:hover {
    background: #4a4a4a;
}

html.dark-mode .doc-search-result-snippet mark {
    background: #665d20;
    color: #f5f5f5;
}

html.dark-mode mark.doc-search-highlight {
    background: #665d20;
    color: #f5f5f5;
}

/* ============================================
   Mobile Responsive
   ============================================ */
@media screen and (max-width: 768px) {
    .doc-explorer {
        flex-direction: column;
        height: auto;
    }

    .doc-tree-panel {
        width: 100% !important;
        max-width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color, #dbdbdb);
    }

    .doc-splitter {
        display: none;
    }

    .doc-content-panel {
        min-width: unset;
    }

    .doc-content {
        padding: 1rem;
    }
}

/* ============================================
   Doc Source Toggle
   ============================================ */
.doc-source-toggle {
    display: flex;
    align-items: center;
}

.doc-source-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-color-light, #7a7a7a);
    user-select: none;
}

.doc-source-icon {
    font-size: 0.7rem;
    width: 1rem;
    text-align: center;
}

.doc-source-label input[type="checkbox"] {
    display: none;
}

.doc-source-slider {
    position: relative;
    display: inline-block;
    width: 28px;
    height: 16px;
    background-color: var(--border-color, #dbdbdb);
    border-radius: 16px;
    transition: background-color 0.2s;
}

.doc-source-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.doc-source-label input:checked + .doc-source-slider {
    background-color: var(--primary-color, #3273dc);
}

.doc-source-label input:checked + .doc-source-slider::after {
    transform: translateX(12px);
}

.doc-source-text {
    min-width: 4rem;
}

.doc-source-toggle.loading .doc-source-text::after {
    content: '...';
}
