/* =============================================================================
   Doc Hub — Main Stylesheet
   Plugin-scoped, theme-agnostic, CSS-custom-property driven.
   ============================================================================= */

/* ── Variables (defaults; overridden by PHP inline vars from settings) ────── */
:root {
    --dh-primary:          #2563eb;
    --dh-primary-light:    #2563eb1a;
    --dh-sidebar-width:    280px;

    --dh-bg:               #ffffff;
    --dh-surface:          #f8f9fb;
    --dh-border:           #e5e7eb;
    --dh-text:             #111827;
    --dh-text-muted:       #6b7280;
    --dh-text-light:       #9ca3af;
    --dh-link:             var(--dh-primary);
    --dh-link-hover:       #1d4ed8;

    --dh-sidebar-bg:       #f8f9fb;
    --dh-sidebar-border:   #e5e7eb;

    --dh-radius:           6px;
    --dh-radius-sm:        4px;
    --dh-transition:       0.15s ease;

    --dh-header-height:    60px;
    --dh-right-sidebar:    240px;
    --dh-content-max:      760px;

    --dh-font-sans:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --dh-font-mono:        "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --dh-font-size:        15px;
    --dh-line-height:      1.7;
}

/* ── Reset (scoped) ─────────────────────────────────────────────────────────── */
.dh-layout *,
.dh-archive-wrap *,
.dh-layout *::before,
.dh-layout *::after {
    box-sizing: border-box;
}

/* ── Layout Shell ────────────────────────────────────────────────────────────── */
.dh-layout {
    display: grid;
    grid-template-columns: var(--dh-sidebar-width) 1fr var(--dh-right-sidebar);
    grid-template-rows: 1fr;
    min-height: calc(100vh - var(--dh-header-height));
    font-family: var(--dh-font-sans);
    font-size: var(--dh-font-size);
    line-height: var(--dh-line-height);
    color: var(--dh-text);
    background: var(--dh-bg);
    position: relative;
}

/* ── Left Sidebar ────────────────────────────────────────────────────────────── */
.dh-sidebar--left {
    grid-column: 1;
    background: var(--dh-sidebar-bg);
    border-right: 1px solid var(--dh-sidebar-border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--dh-border) transparent;
    padding: 0 0 40px;
    z-index: 100;
}

.dh-sidebar--left::-webkit-scrollbar { width: 4px; }
.dh-sidebar--left::-webkit-scrollbar-track { background: transparent; }
.dh-sidebar--left::-webkit-scrollbar-thumb { background: var(--dh-border); border-radius: 2px; }

/* Sidebar header / home link */
.dh-sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--dh-border);
    margin-bottom: 8px;
}

.dh-sidebar-home-link {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--dh-text);
    text-decoration: none;
    transition: color var(--dh-transition);
}
.dh-sidebar-home-link:hover { color: var(--dh-primary); text-decoration: none; }
.dh-sidebar-home-icon { color: var(--dh-primary); flex-shrink: 0; }

/* ── Search ──────────────────────────────────────────────────────────────────── */
.dh-search-wrap {
    padding: 12px 12px 4px;
    position: relative;
}

.dh-search-input {
    width: 100%;
    padding: 8px 12px 8px 40px;
    border: 1px solid var(--dh-border);
    border-radius: var(--dh-radius);
    font-family: var(--dh-font-sans);
    font-size: 13px;
    background: var(--dh-bg);
    color: var(--dh-text);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 10px center;
    transition: border-color var(--dh-transition), box-shadow var(--dh-transition);
}
.dh-search-input:focus {
    outline: none;
    border-color: var(--dh-primary);
    box-shadow: 0 0 0 3px var(--dh-primary-light);
}

.dh-search-results {
    background: var(--dh-bg);
    border: 1px solid var(--dh-border);
    border-radius: var(--dh-radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    margin-top: 4px;
    display: none;
    max-height: 320px;
    overflow-y: auto;
    z-index: 200;
    position: relative;
}
.dh-search-results.is-visible { display: block; }

.dh-search-result-item {
    display: block;
    padding: 10px 14px;
    border-bottom: 1px solid var(--dh-border);
    text-decoration: none;
    color: var(--dh-text);
    transition: background var(--dh-transition);
}
.dh-search-result-item:last-child { border-bottom: none; }
.dh-search-result-item:hover { background: var(--dh-primary-light); text-decoration: none; }
.dh-search-result-item strong { display: block; font-size: 13px; }
.dh-search-result-item small { font-size: 11px; color: var(--dh-text-muted); display: block; margin-top: 2px; }
.dh-search-result-item .dh-result-cat { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--dh-primary); }
.dh-search-no-results { padding: 14px; font-size: 13px; color: var(--dh-text-muted); text-align: center; }

/* ── Sidebar Nav Groups ───────────────────────────────────────────────────────── */
.dh-sidebar-nav { padding: 8px 0; }

.dh-nav-group { margin-bottom: 2px; }

.dh-nav-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--dh-font-sans);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--dh-text-muted);
    text-align: left;
    transition: color var(--dh-transition);
}
.dh-nav-group-toggle:hover { color: var(--dh-primary) !important; }

.dh-nav-group-arrow {
    display: inline-block;
    width: 14px;
    height: 14px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpolyline points='9 18 15 12 9 6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
    transition: transform var(--dh-transition);
    flex-shrink: 0;
}

.dh-nav-group.is-open .dh-nav-group-arrow {
    transform: rotate(90deg);
}

/* Nav list */
.dh-nav-list {
    list-style: none;
    margin: 0;
    padding: 0 0 4px;
}
.dh-nav-list--root { padding-top: 8px; }

.dh-nav-item a {
    display: block;
    padding: 6px 16px 6px 20px;
    font-size: 13.5px;
    color: var(--dh-text-muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: color var(--dh-transition), background var(--dh-transition), border-color var(--dh-transition);
    border-radius: 0 var(--dh-radius-sm) var(--dh-radius-sm) 0;
    line-height: 1.4;
}
.dh-nav-item a:hover {
    color: var(--dh-text);
    background: var(--dh-primary-light);
    border-left-color: var(--dh-primary);
    text-decoration: none;
}
.dh-nav-item.is-current > a {
    color: var(--dh-primary);
    background: var(--dh-primary-light);
    border-left-color: var(--dh-primary);
    font-weight: 600;
}

/* ── Main Content Area ───────────────────────────────────────────────────────── */
.dh-main {
    grid-column: 2;
    padding: 40px 48px;
    max-width: 100%;
    overflow: hidden;
    min-width: 0;
}

/* ── Breadcrumbs ─────────────────────────────────────────────────────────────── */
.dh-breadcrumbs { margin-bottom: 24px; }
.dh-breadcrumbs ol {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 13px;
    color: var(--dh-text-muted);
}
.dh-breadcrumbs li + li::before { content: '/'; margin-right: 6px; color: var(--dh-text-light); }
.dh-breadcrumbs a { color: var(--dh-text-muted); text-decoration: none; }
.dh-breadcrumbs a:hover { color: var(--dh-primary); }
.dh-breadcrumbs [aria-current="page"] { color: var(--dh-text); }

/* ── Document Header ─────────────────────────────────────────────────────────── */
.dh-document-header { margin-bottom: 32px; }

.dh-document-title {
    font-size: clamp(24px, 4vw, 36px);
    font-weight: 700;
    line-height: 1.25;
    color: var(--dh-text);
    margin: 0 0 12px;
}

.dh-document-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--dh-text-muted);
}
.dh-document-meta a { color: var(--dh-primary); text-decoration: none; }
.dh-document-meta a:hover { text-decoration: underline; }
.dh-sep { color: var(--dh-text-light); }

/* ── Document Content Typography ─────────────────────────────────────────────── */
.dh-document-content {
    max-width: var(--dh-content-max);
    color: var(--dh-text);
}

.dh-document-content h2,
.dh-document-content h3,
.dh-document-content h4,
.dh-document-content h5 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--dh-text);
    margin: 2em 0 0.6em;
    scroll-margin-top: 20px;
}
.dh-document-content h2 { font-size: 1.5rem; border-bottom: 1px solid var(--dh-border); padding-bottom: .5em; }
.dh-document-content h3 { font-size: 1.2rem; }
.dh-document-content h4 { font-size: 1rem; }

.dh-document-content p { margin: 0 0 1.2em; }

.dh-document-content a { color: var(--dh-primary); }
.dh-document-content a:hover { color: var(--dh-link-hover); }

.dh-document-content ul,
.dh-document-content ol { margin: 0 0 1.2em 1.4em; padding: 0; }
.dh-document-content li { margin-bottom: .4em; }

.dh-document-content code {
    font-family: var(--dh-font-mono);
    font-size: .875em;
    background: var(--dh-surface);
    padding: .15em .4em;
    border-radius: var(--dh-radius-sm);
    border: 1px solid var(--dh-border);
}

.dh-document-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 20px;
    border-radius: var(--dh-radius);
    overflow-x: auto;
    margin: 0 0 1.5em;
    font-size: .875em;
    line-height: 1.6;
}
.dh-document-content pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    color: inherit;
}

.dh-document-content blockquote {
    border-left: 4px solid var(--dh-primary);
    margin: 1.5em 0;
    padding: 12px 20px;
    background: var(--dh-primary-light);
    border-radius: 0 var(--dh-radius) var(--dh-radius) 0;
    font-style: italic;
    color: var(--dh-text-muted);
}

.dh-document-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 1.5em;
    font-size: .9em;
}
.dh-document-content th,
.dh-document-content td {
    text-align: left;
    padding: 10px 14px;
    border: 1px solid var(--dh-border);
}
.dh-document-content th { background: var(--dh-surface); font-weight: 600; }
.dh-document-content tr:nth-child(even) td { background: var(--dh-surface); }

.dh-document-content img { max-width: 100%; height: auto; border-radius: var(--dh-radius); }

/* Anchor link next to headings */
.dh-anchor-link {
    opacity: 0;
    margin-left: 8px;
    font-size: .75em;
    color: var(--dh-text-light);
    text-decoration: none;
    vertical-align: middle;
    transition: opacity var(--dh-transition);
}
.dh-document-content h2:hover .dh-anchor-link,
.dh-document-content h3:hover .dh-anchor-link,
.dh-document-content h4:hover .dh-anchor-link { opacity: 1; }

/* ── Prev / Next Navigation ──────────────────────────────────────────────────── */
.dh-prevnext {
    display: flex;
    gap: 16px;
    margin-top: 60px;
    padding-top: 32px;
    border-top: 1px solid var(--dh-border);
    max-width: var(--dh-content-max);
}

.dh-prevnext-prev,
.dh-prevnext-next {
    flex: 1;
}
.dh-prevnext-next { text-align: right; }

.dh-prevnext-link {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border: 1px solid var(--dh-border);
    border-radius: var(--dh-radius);
    text-decoration: none;
    color: var(--dh-text);
    transition: border-color var(--dh-transition), box-shadow var(--dh-transition), background var(--dh-transition);
    max-width: 100%;
}
.dh-prevnext-link:hover {
    border-color: var(--dh-primary);
    background: var(--dh-primary-light);
    text-decoration: none;
    color: var(--dh-text);
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.dh-prevnext-next .dh-prevnext-link { flex-direction: row-reverse; }

.dh-prevnext-arrow {
    font-size: 1.25rem;
    color: var(--dh-primary);
    flex-shrink: 0;
    line-height: 1;
}

.dh-prevnext-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.dh-prevnext-meta small { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--dh-text-muted); margin-bottom: 3px; }
.dh-prevnext-meta strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Right Sidebar TOC ───────────────────────────────────────────────────────── */
.dh-sidebar--right {
    grid-column: 3;
    padding: 40px 20px 40px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    scrollbar-width: none;
    border-left: 1px solid var(--dh-border);
}
.dh-sidebar--right::-webkit-scrollbar { display: none; }

.dh-toc { }
.dh-toc-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--dh-text-muted);
    margin: 0 0 12px;
}
.dh-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.dh-toc-list li { margin-bottom: 4px; }
.dh-toc-list a {
    display: block;
    font-size: 13px;
    color: var(--dh-text-muted);
    text-decoration: none;
    padding: 4px 0 4px 10px;
    border-left: 2px solid var(--dh-border);
    transition: color var(--dh-transition), border-color var(--dh-transition);
    line-height: 1.4;
}
.dh-toc-list a:hover,
.dh-toc-list li.is-active a {
    color: var(--dh-primary);
    border-left-color: var(--dh-primary);
    text-decoration: none;
}
.dh-toc-list .dh-toc-h3 a { padding-left: 22px; font-size: 12px; }
.dh-toc-list .dh-toc-h4 a { padding-left: 34px; font-size: 12px; }

/* ── Archive Landing ─────────────────────────────────────────────────────────── */
.dh-archive-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 48px 24px;
    font-family: var(--dh-font-sans);
}

.dh-archive-header { text-align: center; margin-bottom: 48px; }
.dh-archive-title { font-size: clamp(28px, 5vw, 48px); font-weight: 700; margin: 0 0 16px; color: #ffffff; }
.dh-archive-description { font-size: 18px; color: rgba(255, 255, 255, 0.75); max-width: 560px; margin: 0 auto 28px; }

.dh-standalone-search { max-width: 480px; margin: 0 auto; position: relative; }
.dh-standalone-search .dh-search-results { position: absolute; width: 100%; z-index: 200; }

.dh-archive-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.dh-archive-card {
    border: 1px solid var(--dh-border);
    border-radius: var(--dh-radius);
    padding: 24px;
    background: var(--dh-bg);
    transition: border-color var(--dh-transition), box-shadow var(--dh-transition);
}
.dh-archive-card:hover { border-color: var(--dh-primary); box-shadow: 0 4px 20px rgba(0,0,0,.06); }

.dh-archive-card-title { margin: 0 0 8px; font-size: 17px; }
.dh-archive-card-title a { color: var(--dh-text); text-decoration: none; }
.dh-archive-card-title a:hover { color: var(--dh-primary); }

.dh-archive-card-desc { font-size: 14px; color: var(--dh-text-muted); margin: 0 0 14px; }

.dh-archive-card-list { list-style: none; margin: 0 0 16px; padding: 0; }
.dh-archive-card-list li { border-bottom: 1px solid var(--dh-border); }
.dh-archive-card-list li:last-child { border-bottom: none; }
.dh-archive-card-list a { display: block; padding: 7px 0; font-size: 13.5px; color: var(--dh-text-muted); text-decoration: none; transition: color var(--dh-transition); }
.dh-archive-card-list a:hover { color: var(--dh-primary); }

.dh-archive-card-link { font-size: 13px; font-weight: 600; color: var(--dh-primary); text-decoration: none; }
.dh-archive-card-link:hover { text-decoration: underline; }

/* ── Mobile Toggle Button ────────────────────────────────────────────────────── */
.dh-mobile-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 500;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--dh-primary);
    color: #fff;
    border: none;
    border-radius: 50px;
    font-family: var(--dh-font-sans);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
    transition: background var(--dh-transition), transform var(--dh-transition);
}
.dh-mobile-toggle:hover { background: var(--dh-link-hover); }

/* ── Overlay ─────────────────────────────────────────────────────────────────── */
.dh-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 150;
    backdrop-filter: blur(2px);
}
.dh-overlay.is-active { display: block; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .dh-layout {
        grid-template-columns: var(--dh-sidebar-width) 1fr;
    }
    .dh-sidebar--right { display: none; }
    .dh-main { padding: 32px 36px; }
}

@media (max-width: 820px) {
    .dh-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .dh-sidebar--left {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: var(--dh-sidebar-width);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 200;
        box-shadow: 4px 0 24px rgba(0,0,0,.12);
    }
    .dh-sidebar--left.is-open { transform: translateX(0); }

    .dh-mobile-toggle { display: flex; }

    .dh-main { grid-column: 1; padding: 24px 20px; }

    .dh-prevnext { flex-direction: column; }
    .dh-prevnext-next { text-align: left; }
    .dh-prevnext-next .dh-prevnext-link { flex-direction: row; }
}

@media (max-width: 480px) {
    .dh-archive-grid { grid-template-columns: 1fr; }
    .dh-document-title { font-size: 1.6rem; }
    .dh-main { padding: 16px; }
}

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.dh-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}
