/*
 * Phantom IQ — Shared Navigation & Sidebar Standards
 * Injected globally into all content pages.
 * These styles unify nav appearance and add the left-panel TOC.
 */

/* ============================================================
   0. GLOBAL OVERFLOW — prevent horizontal scroll on mobile
   ============================================================ */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* ============================================================
   1. NAV STANDARDIZATION
   Overrides the per-page inlined nav styles to a single look.
   ============================================================ */

/* Logo mark — rounded square with purple gradient (matches brand) */
.logo-mark {
    background: linear-gradient(135deg, #7877c6, #5a59a8) !important;
    border-radius: 8px !important;
    color: #ffffff !important;
    width: 36px !important;
    height: 36px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.85rem !important;
    font-weight: 700 !important;
    flex-shrink: 0 !important;
}

/* Ensure main nav is always sticky with blur */
nav:not(.breadcrumb):not([aria-label="Breadcrumb"]):not(.piq-skip) {
    position: sticky;
    top: 0;
    z-index: 200 !important;
    background: rgba(10, 10, 10, 0.96) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
}

/* Nav container full-width on wider viewports */
.nav-container {
    max-width: 1280px !important;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* ---- Breadcrumb merged into nav right side ---- */
/* Hide the standalone breadcrumb nav that gets moved by JS */
nav.breadcrumb.piq-merged {
    display: none !important;
}

/* The breadcrumb injected into the nav right side */
.piq-breadcrumb-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.775rem;
    color: rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
    max-width: 340px;
    overflow: hidden;
}

.piq-breadcrumb-bar a {
    color: rgba(255, 255, 255, 0.55);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s;
}

.piq-breadcrumb-bar a:hover {
    color: rgba(255, 255, 255, 0.9);
}

.piq-breadcrumb-bar .sep {
    color: rgba(255, 255, 255, 0.25);
    font-size: 0.7rem;
}

.piq-breadcrumb-bar .current {
    color: rgba(255, 255, 255, 0.38);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   2. LEFT SIDEBAR — TABLE OF CONTENTS
   Fixed panel injected by shared.js when h2 headings exist.
   ============================================================ */

#piq-toc {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 236px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #0c0c0c;
    border-right: 1px solid rgba(255, 255, 255, 0.07);
    padding: 5rem 0 3rem;
    z-index: 90;
    scrollbar-width: thin;
    scrollbar-color: rgba(120, 119, 198, 0.3) transparent;
}

#piq-toc::-webkit-scrollbar { width: 3px; }
#piq-toc::-webkit-scrollbar-thumb { background: rgba(120, 119, 198, 0.3); border-radius: 2px; }

.piq-toc-inner {
    padding: 0 1.25rem;
}

.piq-toc-site {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.75rem;
    text-decoration: none;
    color: rgba(255,255,255,0.7);
}

.piq-toc-site-mark {
    width: 28px;
    height: 28px;
    background: var(--text-primary, #fff);
    color: var(--bg-primary, #0a0a0a) !important;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.piq-toc-site-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255,255,255,0.65);
}

.piq-toc-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.25);
    margin: 0 0 0.75rem;
    padding: 0;
}

.piq-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.piq-toc-list li {
    margin: 0;
    padding: 0;
}

.piq-toc-link {
    display: block;
    padding: 0.45rem 0 0.45rem 0.875rem;
    font-size: 0.78rem;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.4);
    text-decoration: none;
    border-left: 2px solid transparent;
    margin-left: -1px;
    transition: color 0.15s, border-color 0.15s;
    word-break: break-word;
}

.piq-toc-link:hover {
    color: rgba(255, 255, 255, 0.8);
    border-left-color: rgba(120, 119, 198, 0.5);
}

.piq-toc-link.active {
    color: #a5a4e3;
    border-left-color: #7877c6;
    font-weight: 500;
}

.piq-toc-link.piq-h3 {
    padding-left: 1.5rem;
    font-size: 0.73rem;
    color: rgba(255, 255, 255, 0.3);
}

.piq-toc-link.piq-h3:hover {
    color: rgba(255, 255, 255, 0.7);
}

.piq-toc-link.piq-h3.active {
    color: rgba(165, 164, 227, 0.8);
}

/* ---- Divider between TOC and back link ---- */
.piq-toc-footer {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.07);
}

.piq-toc-back {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.73rem;
    color: rgba(255, 255, 255, 0.3);
    text-decoration: none;
    transition: color 0.15s;
}

.piq-toc-back:hover { color: rgba(255, 255, 255, 0.7); }

.piq-toc-back svg {
    flex-shrink: 0;
    opacity: 0.6;
}

/* ---- Body offset when TOC is present ---- */
body.piq-has-toc {
    padding-left: 236px !important;
}

/* ---- Mobile: hide TOC, remove offset ---- */
@media (max-width: 1080px) {
    #piq-toc { display: none; }
    body.piq-has-toc { padding-left: 0 !important; }
    .piq-breadcrumb-bar { max-width: 200px; }
}

@media (max-width: 640px) {
    .piq-breadcrumb-bar { display: none; }
}

/* ---- Light mode support ---- */
[data-theme="light"] #piq-toc,
body.light-mode #piq-toc {
    background: #f4f4f5;
    border-right-color: rgba(0,0,0,0.08);
}

[data-theme="light"] .piq-toc-label,
body.light-mode .piq-toc-label {
    color: rgba(0,0,0,0.35);
}

[data-theme="light"] .piq-toc-link,
body.light-mode .piq-toc-link {
    color: rgba(0,0,0,0.45);
}

[data-theme="light"] .piq-toc-link:hover,
body.light-mode .piq-toc-link:hover {
    color: rgba(0,0,0,0.85);
    border-left-color: rgba(120, 119, 198, 0.6);
}

[data-theme="light"] .piq-toc-link.active,
body.light-mode .piq-toc-link.active {
    color: #5a59a8;
    border-left-color: #7877c6;
}

[data-theme="light"] .piq-toc-back,
body.light-mode .piq-toc-back {
    color: rgba(0,0,0,0.4);
}

[data-theme="light"] nav:not(.breadcrumb):not([aria-label="Breadcrumb"]):not(.piq-skip),
body.light-mode nav:not(.breadcrumb):not([aria-label="Breadcrumb"]):not(.piq-skip) {
    background: rgba(255, 255, 255, 0.96) !important;
    border-bottom-color: rgba(0,0,0,0.08) !important;
}

[data-theme="light"] .piq-breadcrumb-bar a,
body.light-mode .piq-breadcrumb-bar a {
    color: rgba(0,0,0,0.5);
}

[data-theme="light"] .piq-breadcrumb-bar .current,
body.light-mode .piq-breadcrumb-bar .current {
    color: rgba(0,0,0,0.35);
}

[data-theme="light"] #piq-toc,
body.light-mode #piq-toc {
    scrollbar-color: rgba(120, 119, 198, 0.4) transparent;
}

/* ============================================================
   3. UNIFORM CARD GRIDS — prevent orphan "3 + 1" rows
   Applied by shared.js after counting children per grid.
   Column logic:
     1 item  → 1 col
     2 items → 2 cols
     3 items → 3 cols  (skip 2-col intermediate state → no 2+1)
     4 items → 2 cols  (2×2) or 4 cols at wide (never 3+1)
     5 items → 3 cols  (2+3 on last row, centered)
     6 items → 3 cols  (3×2) or 2 cols (3×2 same shape)
     7 items → 4 cols  (4+3, better than 3+3+1)
     8+ even → 4 cols  (even rows)
     other   → 4 cols  (best general case)
   ============================================================ */

/* Base grid classes - applied by JS */
.piq-cols-1 { grid-template-columns: repeat(1, 1fr) !important; }
.piq-cols-2 { grid-template-columns: repeat(2, 1fr) !important; }
.piq-cols-3 { grid-template-columns: repeat(3, 1fr) !important; }
.piq-cols-4 { grid-template-columns: repeat(4, 1fr) !important; }

/* ---- Responsive scaling ---- */

/* At ≤1100px: 4-col → 2-col (2+2 for 4 items = always even) */
@media (max-width: 1100px) {
    .piq-cols-4 { grid-template-columns: repeat(2, 1fr) !important; }
}

/* At ≤820px: 3-col → still 3 if cards fit, else 1-col.
   We keep 3 cols down to 660px to avoid 2+1 intermediate state */
@media (max-width: 660px) {
    .piq-cols-3 { grid-template-columns: repeat(1, 1fr) !important; }
    .piq-cols-4 { grid-template-columns: repeat(1, 1fr) !important; }
}

/* At ≤480px: everything single column */
@media (max-width: 480px) {
    .piq-cols-2 { grid-template-columns: repeat(1, 1fr) !important; }
}

/* ---- Orphan centering for odd-count last rows ---- */
/* For 5-item and 7-item grids, the last row item(s) left-align by default.
   Flex centering makes it look intentional rather than broken. */
.piq-cols-3.piq-orphan-center,
.piq-cols-4.piq-orphan-center {
    display: flex !important;
    flex-wrap: wrap;
}

.piq-cols-3.piq-orphan-center > *,
.piq-cols-4.piq-orphan-center > * {
    flex: 1 1 0;
    min-width: 220px;
    max-width: none;
}

/* For 3-item grids that are actually flex-based */
.piq-cols-3.piq-orphan-center {
    justify-content: flex-start;
}

/* ============================================================
   4. LOGO MARK — global brand consistency
   Brand: "Phantom [●IQ]" — text before circle, never duplicated.
   Works on dark and light backgrounds via CSS variable inversion.
   ============================================================ */

/* Ensure all logo containers are flex rows */
a.logo,
a.nav-logo,
.nav-logo,
.footer-logo {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    text-decoration: none !important;
    color: inherit !important;
}

/* "Phantom" text — always before the circle */
.logo-text {
    order: 0 !important;
    font-weight: 700 !important;
    font-size: 1.1rem !important;
    letter-spacing: -0.03em !important;
    color: var(--text-primary, #fff) !important;
    white-space: nowrap !important;
}

/* "IQ" circle — always after the text */
.logo-mark {
    order: 1 !important;
    width: 2rem !important;
    height: 2rem !important;
    border-radius: 50% !important;
    background: var(--text-primary, #fff) !important;   /* white circle on dark bg */
    color: var(--bg-primary, #0a0a0a) !important;       /* dark IQ text inside */
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 800 !important;
    font-size: 0.7rem !important;
    letter-spacing: -0.02em !important;
    flex-shrink: 0 !important;
    line-height: 1 !important;
    font-style: normal !important;
    text-decoration: none !important;
    -webkit-font-smoothing: antialiased !important;
}

/* Footer brand row — spacing above copyright line */
.footer-brand-row {
    margin-bottom: 0.75rem;
}
.footer-copy {
    font-size: 0.8rem;
    color: var(--text-muted, rgba(255,255,255,0.35));
    margin: 0;
}

/* Mobile: hide "Phantom" text, show IQ circle only */
@media (max-width: 380px) {
    .logo-text {
        display: none !important;
    }
}

