/* Content Layout */
.tech-layout {
    margin: 0 auto;
    padding: var(--space-md);
    max-width: 100%;
}

.tech-main {
    width: 100%;
}

.tech-sidebar {
    display: none;
}

/* TOC collapsed behavior */
.toc-list ul.collapsed { display: none; }

/* Responsive TOC burger and panel (structure classes; styling matches site variables) */
.toc-burger { position: fixed; top: 12px; right: 12px; z-index: var(--z-toc-toggle); display: none; background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
.toc-panel { position: fixed; top: 0; right: -320px; width: 300px; max-width: 85vw; height: 100vh; background: var(--bg-secondary); border-left: 1px solid var(--border); z-index: var(--z-toc-panel); transition: right 0.25s ease; box-shadow: -8px 0 16px rgba(0,0,0,0.3); }
.toc-panel.open { right: 0; }
.toc-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: var(--z-toc-overlay); opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
.toc-overlay.visible { opacity: 1; pointer-events: auto; }
.toc-inner { padding: 16px; overflow-y: auto; height: 100%; }
.toc-entry { display: inline-flex; align-items: center; gap: 6px; }
.toc-toggle { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 0 2px; font-size: 0.9em; }

@media (max-width: 767px) {
    .toc-burger { display: block; }
}

/* Project page hero overrides */
/* Allow project hero to use full column width instead of 600px default */
.hero.tech-section .hero-content {
    max-width: 100% !important;
    width: 100%;
    margin: 0 auto;
}

/* Ensure description centers within wider hero */
.hero.tech-section .hero-content .hero-description {
    margin-left: auto;
    margin-right: auto;
}

/* Give the immediate hero inner card natural full width and prevent overflow */
.hero.tech-section .hero-content > div {
    max-width: 100%;
}

/* Diagram Styles */
.mermaid-diagram {
    background: #0f172a;
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.mermaid-diagram svg {
    display: block;
    width: 100%;
    height: auto;
    background: #0f172a !important;
}

.architecture-diagram {
    background: #0f172a;
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin: var(--space-xl) 0;
    width: 100%;
    overflow-x: auto;
}

/* Desktop Layout */
@media (min-width: 1200px) {
    .tech-layout {
        display: grid;
        grid-template-columns: 1fr 300px;
        gap: var(--space-2xl);
        max-width: 1400px;
        padding: var(--space-xl);
    }

    .tech-sidebar {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        position: sticky;
        top: 2rem;
        height: fit-content;
        max-height: calc(100vh - 4rem);
        overflow-y: auto;
        padding: var(--space-lg);
    }
}

/* Wide Desktop Layout */
@media (min-width: 1497px) {
    .tech-layout {
        grid-template-columns: minmax(800px, 1fr) 300px;
    }
}

/* ==========================
   Wiki Layout (single page)
   ========================== */

.wiki-main {
    box-sizing: border-box;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
    max-width: 1200px;
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: var(--space-2xl);
}

.wiki-toc {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    position: sticky;
    top: 2rem;
    align-self: start;
    height: fit-content;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    /* Hide scrollbar but keep scrollability */
    -ms-overflow-style: none; /* IE and old Edge */
    scrollbar-width: none;    /* Firefox */
}

/* WebKit scrollbar hide */
.wiki-toc::-webkit-scrollbar { width: 0; height: 0; }

.toc-title {
    margin: 0 0 var(--space-md) 0;
    font-size: 1rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.toc-nav a {
    display: block;
    padding: 6px 8px;
    margin: 2px 0;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 6px;
}

.toc-nav a:hover {
    background: var(--bg-secondary);
}

.toc-nav a.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 600;
}

.wiki-content {
    min-width: 0; /* prevent overflow from long code lines */
}

/* Hide scrollbar in mobile TOC panel while preserving scroll */
.mobile-toc-panel {
    -ms-overflow-style: none; /* IE and old Edge */
    scrollbar-width: none;    /* Firefox */
}
.mobile-toc-panel::-webkit-scrollbar { width: 0; height: 0; }

/* ==========================
   Mermaid external theme (CSP-safe)
   Applies colors via site CSS so production CSP can remain strict.
   ========================== */

/* Base text color inside diagrams */
.mermaid { color: #e2e8f0; }

/* Nodes */
.mermaid .node rect,
.mermaid .node polygon,
.mermaid .node circle {
    fill: #0f172a !important;
    stroke: #0b52e0 !important;
}

/* Node labels */
.mermaid .node text,
.mermaid .label,
.mermaid text { fill: #e2e8f0 !important; }

/* Clusters (subgraphs) */
.mermaid .cluster rect { fill: #0f172a !important; stroke: #3b3e46 !important; }
.mermaid .cluster text { fill: #e2e8f0 !important; }

/* Edges and arrows */
.mermaid .edgePath .path,
.mermaid .flowchart-link { stroke: #0b52e0 !important; }
.mermaid .arrowheadPath,
.mermaid .marker { fill: #0b52e0 !important; stroke: #0b52e0 !important; }

/* Edge labels */
.mermaid .edgeLabel text { fill: #e2e8f0 !important; }
.mermaid .edgeLabel rect { fill: transparent !important; stroke: transparent !important; }

.wiki-content article {
    margin-bottom: var(--space-2xl);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    scroll-margin-top: 96px; /* prevent header overlap on anchor jump */
}

.wiki-content h1 {
    margin-bottom: var(--space-sm);
}

.wiki-content h2 {
    margin-top: var(--space-xl);
}

.wiki-content h3 {
    margin-top: var(--space-lg);
}

.lede {
    font-size: 1.05rem;
    color: var(--text-muted);
    margin-bottom: var(--space-md);
}

/* ==========================
   Hero banner styling
   ========================== */
.wiki-hero {
    padding: var(--space-lg) var(--space-lg) 0 var(--space-lg);
}

.wiki-hero-inner {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    border-radius: var(--radius-xl);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface);
}

.wiki-hero-image {
    width: 100%;
    height: clamp(140px, 24vw, 260px); /* dynamic height; center-cropped */
    display: block;
    object-fit: cover;
    object-position: center center;
}

.wiki-hero-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: clamp(12px, 2vw, 20px) clamp(12px, 3vw, 28px);
    background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.55) 65%, rgba(0,0,0,0.8) 100%);
    color: #eef2f7;
}

.wiki-hero-overlay h1 {
    margin: 0 0 4px 0;
    color: #ffffff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.35);
    font-size: clamp(20px, 3vw, 28px);
}

.wiki-hero-overlay .lede {
    margin: 0;
    color: #dbe4ee;
}

/* Collapsible diagram/code block styling */
details.diagram {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
}

details.diagram > summary {
    cursor: pointer;
    padding: 10px 12px;
    font-weight: 600;
    list-style: none;
}

details.diagram[open] > summary {
    border-bottom: 1px solid var(--border);
}

details.diagram pre {
    margin: 0;
    padding: var(--space-md);
    background: #0f172a;
    color: #e2e8f0;
    overflow-x: auto;
}

details.diagram code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.9rem;
}

/* Subtle alternating backgrounds for readability */
.wiki-content article:nth-of-type(odd) {
    background: var(--surface);
}

.wiki-content article:nth-of-type(even) {
    background: var(--bg-secondary);
}

/* Responsive: stack layout on small screens */
@media (max-width: 991px) {
    .wiki-main {
        grid-template-columns: 1fr;
        padding: var(--space-lg) var(--space-md);
    }

    .wiki-toc {
        position: static;
        max-height: none;
    }
}
