/* ════════════════════════════════════════════════════════════════════════════════════════════════════
   Gerson Ltd — Shared Styles
   Common foundation for all documentation pages
   ════════════════════════════════════════════════════════════════════════════════════════════════════ */

:root {
    --primary-dark: #143e6f;
    --primary: #225cc7;
    --primary-light: #4d8dff;
    --accent: #49b0ff;
    --bg-color: #f6f8fc;
    --text-main: #2a2a2a;
    --text-muted: #4b5563;
    --border: #e1e4ec;
    --card: #ffffff;
    --code-bg: #0c1728;
    --code-text: #f8fafc;
    --sidebar-width: 250px;
    --bar-height: 55px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-main);
    background-color: var(--bg-color);
    margin: 0;
    padding: var(--bar-height) 0 0;
    display: flex;
    justify-content: center;
}

/* ──── Brand bar ──── */
.brand-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 250;
    background: white;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.brand-bar-inner {
    max-width: 66rem;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.brand-bar .bar-logo {
    font-weight: 900;
    font-size: 1.25rem;
    letter-spacing: -0.05em;
    line-height: 1;
    color: #0f172a;
    text-decoration: none;
}

.brand-bar .bar-logo .logo-name {
    color: var(--primary);
}

.brand-bar .bar-back {
    display: inline-block;
    padding: 8.5px 22.5px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    line-height: 1.33;
    text-decoration: none;
    color: var(--primary);
    border: 1.5px solid var(--primary);
    background: transparent;
    transition: background 0.18s, color 0.18s;
}

.brand-bar .bar-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50%;
    pointer-events: none;
}

.brand-bar .bar-title .bar-page {
    font-weight: 700;
    color: var(--text-main);
}

.brand-bar .bar-title .bar-section {
    color: var(--text-muted);
}

.brand-bar .bar-back:hover {
    background: var(--primary);
    color: #fff;
}

/* ──── Top navigation bar (shared, used on portfolio and other pages) ──── */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 999;
    background: white;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.nav-inner {
    max-width: 66rem;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.nav-logo {
    font-weight: 900;
    font-size: 1.25rem;
    letter-spacing: -0.05em;
    line-height: 1;
    color: #0f172a;
    text-decoration: none;
}

.nav-cta-outline {
    display: inline-block;
    padding: 10px 24px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-decoration: none;
    color: var(--primary);
    border: 1.5px solid var(--primary);
    background: transparent;
    transition: background 0.18s, color 0.18s;
}

.nav-cta-outline:hover {
    background: var(--primary);
    color: #fff;
}

.top-nav .bar-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 50%;
    pointer-events: none;
}

.top-nav .bar-title .bar-page { font-weight: 700; color: var(--text-main); }

.mobile-nav-toggle {
    display: none;
    position: fixed;
    top: 12px;
    right: 16px;
    z-index: 1001;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 7px;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
}

.mobile-nav-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #0f172a;
    border-radius: 2px;
}

.mobile-nav-panel {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 260px;
    background: white;
    z-index: 1000;
    padding: 80px 24px 24px;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
}

.mobile-nav-panel.open { display: block; }
.mobile-nav-panel ul { list-style: none; padding: 0; }
.mobile-nav-panel li { margin-bottom: 16px; }
.mobile-nav-panel a { text-decoration: none; color: var(--text-main); font-weight: 600; font-size: 1rem; }

/* ──── Scroll progress bar ──── */
.scroll-progress {
    position: fixed;
    top: var(--bar-height);
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light), var(--accent));
    z-index: 251;
    transition: width 0.12s ease-out, top 0.12s ease-out;
    border-radius: 0 2px 2px 0;
}

.container {
    display: flex;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
    gap: 3rem;
}

/* ──── Sidebar / TOC ──── */
aside {
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: calc(var(--bar-height) + 2rem);
    height: calc(100vh - var(--bar-height) - 4rem);
    overflow-y: auto;
    padding-right: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

aside h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 1rem;
}

aside h3::before {
    content: '';
    display: block;
    width: 28px;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 2px;
    margin-bottom: 0.75rem;
}

aside ul { list-style: none; padding: 0; margin: 0; }
aside li { margin-bottom: 0.25rem; }

aside a {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.88rem;
    transition: color 0.2s, padding-left 0.2s, border-left-color 0.2s, background 0.2s;
    display: block;
    border-left: 2px solid transparent;
    padding: 0.3rem 0.5rem 0.3rem 10px;
    border-radius: 0 6px 6px 0;
}

aside a:hover { color: var(--primary); padding-left: 14px; }

aside a.active {
    color: var(--primary);
    font-weight: 600;
    border-left-color: var(--primary);
    padding-left: 14px;
    background: linear-gradient(90deg, rgba(34,92,199,0.07), transparent);
}

/* ──── Main Content ──── */
main {
    flex-grow: 1;
    max-width: 900px;
    background: var(--card);
    padding: 0 35px 45px 35px;
    border-radius: 18px;
    box-shadow: 0 10px 40px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,0.04);
    border: 1px solid rgba(225,228,236,0.6);
    overflow: hidden;
}

/* ──── Hero header ──── */
h1 {
    font-size: 2.4rem;
    line-height: 1.2;
    margin: 0 -35px 2.5rem -35px;
    padding: 3rem 35px 2.5rem 35px;
    background: linear-gradient(135deg, #0c1728, #1a2856 45%, #2d4bd9);
    color: #ffffff;
    border-bottom: none;
    font-family: 'Segoe UI', 'Inter', system-ui, sans-serif;
    font-weight: 700;
    position: relative;
    overflow: hidden;
}

h1::before {
    content: '';
    position: absolute;
    top: -60%;
    right: -15%;
    width: 420px;
    height: 420px;
    background: radial-gradient(circle, rgba(77,141,255,0.15) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

h1 .hero-sub {
    display: block;
    font-size: 1rem;
    font-weight: 400;
    color: rgba(255,255,255,0.65);
    margin-top: 0.5rem;
    letter-spacing: 0.02em;
}

/* ──── Section headings ──── */
h2 {
    font-size: 1.7rem;
    margin-top: 3.5rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.75rem;
    font-family: 'Segoe UI', 'Inter', system-ui, sans-serif;
    font-weight: 700;
    color: var(--primary);
    position: relative;
}

h2::before {
    content: '';
    display: block;
    width: 36px;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 2px;
    margin-bottom: 0.75rem;
}

h2::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 70px;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), transparent);
}

h3 { font-size: 1.35rem; margin-top: 2rem; color: var(--primary-dark); font-weight: 600; }
h4 { font-size: 1.15rem; margin-top: 1.5rem; color: var(--text-main); font-weight: 600; }
h5 { font-size: 1.05rem; margin-top: 1.25rem; color: var(--text-main); font-weight: 600; }

p, li { font-size: 1.05rem; margin-bottom: 1rem; color: var(--text-muted); }
ul, ol { margin-bottom: 1.5rem; }
strong { color: var(--text-main); }

/* ──── Tables ──── */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 2rem 0;
    font-size: 0.95rem;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    border: 1px solid var(--border);
}

th, td { text-align: left; padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
th {
    background: linear-gradient(135deg, #e8eef8, #eff5ff);
    font-weight: 600;
    color: var(--primary-dark);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
tbody tr:nth-child(even) { background-color: rgba(246,248,252,0.6); }
tbody tr { transition: background-color 0.15s ease; }
tbody tr:hover { background-color: rgba(77,141,255,0.06); }
tbody tr:last-child td { border-bottom: none; }

/* ──── Code blocks ──── */
pre {
    background-color: var(--code-bg);
    color: var(--code-text);
    padding: 1.5rem;
    border-radius: 12px;
    overflow-x: auto;
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 2rem 0;
    position: relative;
    border: 1px solid rgba(255,255,255,0.08);
}

pre[data-lang]::before {
    content: attr(data-lang);
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.45);
    padding: 0.25rem 0.75rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-radius: 0 12px 0 8px;
    font-family: 'Inter', sans-serif;
}

code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
:not(pre) > code {
    background-color: #eff5ff;
    color: var(--primary-dark);
    padding: 0.2rem 0.45rem;
    border-radius: 5px;
    font-size: 0.88em;
    border: 1px solid rgba(34,92,199,0.08);
}

/* ──── Callouts / Blockquotes ──── */
blockquote {
    background: linear-gradient(135deg, #eff5ff, rgba(77,141,255,0.05));
    border-left: 4px solid var(--primary);
    margin: 2rem 0;
    padding: 1.25rem 1.5rem;
    border-radius: 0 12px 12px 0;
}
blockquote p { margin: 0; color: var(--primary-dark); }

/* ──── Slide figures (presentation images) ──── */
.slide-figure { margin: 1.5rem 0; text-align: center; }
.slide-figure img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10), 0 1px 4px rgba(0, 0, 0, 0.06); }
.slide-figure figcaption { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.5rem; }

/* ──── Testimonial quotes ──── */
.testimonial {
    background: linear-gradient(135deg, #f8fafb, rgba(77,141,255,0.03));
    border-left: 3px solid var(--border);
    margin: 2rem 0;
    padding: 1.25rem 1.5rem;
    border-radius: 0 12px 12px 0;
    font-size: 0.95rem;
    line-height: 1.65;
}
.testimonial p {
    margin: 0;
    color: var(--text-muted);
    font-style: italic;
}
.testimonial .testimonial-attribution {
    margin-top: 0.75rem;
    font-style: normal;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
}
.testimonial .testimonial-attribution span {
    font-weight: 400;
    color: var(--text-muted);
}
.testimonial .testimonial-source {
    display: inline-block;
    margin-top: 0.4rem;
    font-size: 0.75rem;
    font-style: normal;
    color: var(--text-muted);
    opacity: 0.6;
}
.testimonial .testimonial-source a {
    color: var(--text-muted);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}
.testimonial .testimonial-source a:hover {
    color: var(--primary);
}

hr {
    border: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), var(--primary-light), var(--border), transparent);
    margin: 3rem 0;
}

/* ──── Flow diagram ──── */
.flow-diagram { display: flex; align-items: center; justify-content: center; gap: 0; margin: 1.5rem 0 2rem; flex-wrap: wrap; }
.flow-node {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff; padding: 0.65rem 1.1rem; border-radius: 10px;
    font-weight: 600; font-size: 0.9rem; text-align: center; white-space: nowrap;
    box-shadow: 0 2px 8px rgba(20,62,111,0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.flow-node:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(20,62,111,0.3); }
.flow-arrow { display: flex; align-items: center; padding: 0 0.35rem; }
.flow-arrow svg { width: 24px; height: 24px; fill: none; stroke: var(--primary-light); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ──── Layer stack ──── */
.layer-stack { display: flex; flex-direction: column; gap: 0.6rem; margin: 2rem 0; }
.layer-item { display: flex; align-items: center; gap: 0.85rem; padding: 0.7rem 1.15rem; background: var(--card); border: 1px solid var(--border); border-radius: 10px; position: relative; transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease; }
.layer-item:hover { transform: translateX(4px); box-shadow: 0 2px 12px rgba(20,62,111,0.1); border-color: var(--primary-light); }
.layer-num { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #fff; border-radius: 8px; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; }
.layer-label { font-weight: 600; color: var(--text-main); font-size: 0.98rem; }
.layer-desc { font-size: 0.85rem; color: var(--text-muted); margin-left: auto; }

/* ──── Feature cards ──── */
.feature-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 1.15rem 1.35rem; margin: 1.25rem 0; border-left: 4px solid var(--primary); transition: box-shadow 0.25s ease, transform 0.25s ease; }
.feature-card:hover { box-shadow: 0 4px 20px rgba(20,62,111,0.08); transform: translateY(-1px); }
.feature-card h4 { margin-top: 0; }
.feature-card p:last-child { margin-bottom: 0; }
.feature-card[data-domain="workspace"]  { border-left-color: #3b82f6; }
.feature-card[data-domain="ai"]         { border-left-color: #8b5cf6; }
.feature-card[data-domain="advisor"]    { border-left-color: #10b981; }
.feature-card[data-domain="security"]   { border-left-color: #f59e0b; }
.feature-card[data-domain="data"]       { border-left-color: #06b6d4; }
.feature-card[data-domain="infra"]      { border-left-color: #ef4444; }
.feature-card[data-domain="signals"]    { border-left-color: #f97316; }
.feature-card[data-domain="design"]     { border-left-color: #0ea5a4; }
.feature-card[data-domain="extension"]  { border-left-color: #7c3aed; }

/* ──── Reference callouts ──── */
.reference-callout { margin: 1.75rem 0 2.25rem; padding: 1.35rem 1.5rem; border-radius: 14px; background: linear-gradient(135deg, rgba(20,62,111,0.06), rgba(73,176,255,0.09)); border: 1px solid rgba(34,92,199,0.16); box-shadow: 0 8px 24px rgba(20,62,111,0.06); }
.reference-kicker { display: block; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--primary); margin-bottom: 0.45rem; }
.reference-callout p:last-child { margin-bottom: 0; }
.reference-link { display: inline-flex; align-items: center; gap: 0.45rem; margin-top: 0.4rem; font-weight: 700; color: var(--primary-dark); text-decoration: none; }
.reference-link:hover { color: var(--primary); text-decoration: underline; }

/* ──── Feedback loops ──── */
.feedback-loop { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0; margin: 2rem 0; padding: 1.5rem 1rem; background: linear-gradient(135deg, rgba(12,23,40,0.03), rgba(45,75,217,0.04)); border-radius: 14px; border: 1px solid var(--border); position: relative; }
.loop-step { display: flex; align-items: center; gap: 0; }
.loop-node { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.loop-num { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 0.82rem; box-shadow: 0 2px 8px rgba(34,92,199,0.2); transition: transform 0.2s ease; }
.loop-node:hover .loop-num { transform: scale(1.1); }
.loop-num.c1 { background: linear-gradient(135deg, #143e6f, #225cc7); }
.loop-num.c2 { background: linear-gradient(135deg, #225cc7, #4d8dff); }
.loop-num.c3 { background: linear-gradient(135deg, #4d8dff, #49b0ff); }
.loop-num.c4 { background: linear-gradient(135deg, #49b0ff, #2d4bd9); }
.loop-num.c5 { background: linear-gradient(135deg, #2d4bd9, #143e6f); }
.loop-text { font-size: 0.82rem; font-weight: 600; color: var(--primary-dark); }
.loop-arrow { padding: 0 0.35rem; color: var(--primary-light); font-size: 1.2rem; margin-bottom: 1.2rem; }
.loop-return { display: block; width: 100%; text-align: center; margin-top: 0.75rem; font-size: 0.78rem; color: var(--text-muted); letter-spacing: 0.04em; }

/* ──── Stat rows ──── */
.stat-row { display: flex; gap: 1rem; margin: 2rem 0; flex-wrap: wrap; }
.stat-box { flex: 1; min-width: 120px; background: linear-gradient(135deg, rgba(12,23,40,0.03), rgba(45,75,217,0.04)); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; text-align: center; transition: transform 0.2s ease, box-shadow 0.2s ease; }
.stat-box:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(20,62,111,0.08); }
.stat-num { font-size: 2rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.stat-label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 0.35rem; }

/* ──── Transition chains ──── */
.transition-chain { display: flex; align-items: center; justify-content: center; gap: 0.45rem; margin: 0.85rem 0; flex-wrap: wrap; }
.t-state { display: inline-flex; align-items: center; justify-content: center; padding: 0.5rem 0.85rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text-main); font-size: 0.9rem; font-weight: 600; }
.t-state.data { background: linear-gradient(135deg, rgba(59,130,246,0.12), rgba(59,130,246,0.04)); border-color: rgba(59,130,246,0.22); }
.t-state.ai { background: linear-gradient(135deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04)); border-color: rgba(139,92,246,0.22); }
.t-arrow { color: var(--primary-light); font-weight: 700; }

/* ──── Scroll reveal animations ──── */
.reveal { opacity: 0; transform: translateY(20px); transition: opacity 0.55s ease-out, transform 0.55s ease-out; }
.reveal.visible { opacity: 1; transform: translateY(0); }
.toc-panel .reveal { opacity: 1; transform: none; transition: none; }

/* ──── Accessibility ──── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ──── Mobile TOC ──── */
.toc-fab {
    display: none; position: fixed; bottom: 1.25rem; right: 1.25rem;
    width: 48px; height: 48px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff; border: none; box-shadow: 0 4px 16px rgba(20,62,111,0.35);
    z-index: 200; cursor: pointer; align-items: center; justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.toc-fab:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(20,62,111,0.45); }
.toc-fab:active { transform: scale(0.95); }
.toc-fab svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; }

.toc-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 299; opacity: 0; transition: opacity 0.25s ease; }
.toc-overlay.visible { opacity: 1; }

.toc-panel {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; max-height: 70vh;
    background: var(--card); border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.15); z-index: 300; overflow-y: auto;
    padding: 0.75rem 1.25rem 1.5rem; transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.toc-panel.visible { transform: translateY(0); }
.toc-panel-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0.25rem auto 1rem; }
.toc-panel h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; color: var(--primary-dark); margin: 0 0 0.75rem 0; }
.toc-panel ul { list-style: none; padding: 0; margin: 0; }
.toc-panel li { margin-bottom: 0.15rem; }
.toc-panel a { text-decoration: none; color: var(--text-muted); font-size: 0.92rem; display: block; padding: 0.5rem 0.6rem; border-radius: 8px; transition: background 0.15s ease, color 0.15s ease; }
.toc-panel a:hover { background: rgba(34,92,199,0.06); color: var(--primary); }
.toc-panel a.active { background: rgba(34,92,199,0.1); color: var(--primary); font-weight: 600; }

/* ──── Back to top ──── */
.back-to-top {
    position: fixed; bottom: 1.25rem; left: 1.25rem; width: 44px; height: 44px;
    border-radius: 50%; background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff; border: none; box-shadow: 0 4px 16px rgba(20,62,111,0.3);
    z-index: 200; cursor: pointer; display: flex; align-items: center; justify-content: center;
    opacity: 0; transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.2s ease;
    pointer-events: none;
}
.back-to-top.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.back-to-top:hover { box-shadow: 0 6px 20px rgba(20,62,111,0.45); }
.back-to-top svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ──── Start-a-brief FAB (centre) ──── */
.start-brief-fab {
    position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 22px 10px 16px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: #fff; font-family: inherit; font-size: 0.85rem; font-weight: 600;
    text-decoration: none; border: none; border-radius: 50px;
    box-shadow: 0 4px 16px rgba(20,62,111,0.35);
    z-index: 200; cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.start-brief-fab:hover { transform: translateX(-50%) scale(1.05); box-shadow: 0 6px 22px rgba(20,62,111,0.45); color: #fff; text-decoration: none; }
.start-brief-fab:active { transform: translateX(-50%) scale(0.97); }
.start-brief-fab svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ──── Heading anchor links ──── */
h2 .heading-anchor { opacity: 0; color: var(--primary-light); text-decoration: none; margin-left: 0.4rem; font-size: 0.7em; transition: opacity 0.2s ease; vertical-align: middle; }
h2:hover .heading-anchor { opacity: 0.6; }
h2 .heading-anchor:hover { opacity: 1; color: var(--primary); }

/* ──── Footer ──── */
.doc-footer { margin-top: 3rem; padding: 1.5rem 0 0.5rem; border-top: 1px solid var(--border); text-align: center; }
.doc-footer p { font-size: 0.88rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.doc-footer a { color: var(--primary); text-decoration: none; }
.doc-footer a:hover { text-decoration: underline; }

/* ════════════════════════════════════════════════════════════════════════════════════════════════════
   Responsive
   ════════════════════════════════════════════════════════════════════════════════════════════════════ */

/* ──── Tablet ──── */
@media (max-width: 1024px) {
    .brand-bar .bar-back { display: none; }
    .top-nav { display: none; }
    .mobile-nav-toggle { display: flex; }
    .container { flex-direction: column; padding: 1rem; gap: 0; }
    aside { display: none; }
    .toc-fab { display: flex; }
    .toc-panel { display: none; }
    .toc-overlay { display: none; }
    main { padding: 0 24px 30px 24px; max-width: 100%; }
    h1 { margin: 0 -24px 2rem -24px; padding: 2.5rem 24px 2rem; font-size: 2rem; }
    .feedback-loop { padding: 1.25rem 0.75rem; }
    .loop-text { font-size: 0.75rem; }
    .feature-card { padding: 1rem 1.15rem; }
    table { font-size: 0.88rem; }
    th, td { padding: 0.6rem 0.75rem; }
}

/* ──── Large phone ──── */
@media (max-width: 768px) {
    .container { padding: 0; }
    main { padding: 0 16px 24px 16px; border-radius: 0; border-left: none; border-right: none; }
    .scroll-progress { top: var(--bar-height); }
    h1 { display: none; }
    h1 + h2 { margin-top: 1rem; }
    h2 { font-size: 1.4rem; margin-top: 2.5rem; scroll-margin-top: calc(var(--bar-height) + 1rem); }
    h3 { font-size: 1.15rem; }
    p, li { font-size: 0.98rem; }
    .flow-diagram { flex-direction: column; gap: 0; }
    .flow-arrow { padding: 0.15rem 0; }
    .flow-arrow svg { transform: rotate(90deg); width: 20px; height: 20px; }
    .flow-node { padding: 0.55rem 1rem; font-size: 0.85rem; }
    .layer-item { padding: 0.55rem 0.85rem; gap: 0.65rem; }
    .layer-num { width: 22px; height: 22px; font-size: 0.7rem; border-radius: 6px; }
    .layer-label { font-size: 0.9rem; }
    .feedback-loop { padding: 1rem 0.5rem; }
    .loop-num { width: 30px; height: 30px; font-size: 0.75rem; }
    .loop-text { font-size: 0.7rem; }
    .loop-arrow { font-size: 1rem; padding: 0 0.2rem; }
    .feature-card { padding: 0.85rem 1rem; margin: 1rem 0; border-radius: 12px; }
    pre { padding: 1rem; font-size: 0.82rem; border-radius: 10px; }
    pre[data-lang]::before { font-size: 0.6rem; padding: 0.2rem 0.5rem; }
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .stat-row { gap: 0.5rem; }
    .stat-box { min-width: 80px; padding: 0.75rem; }
    .stat-num { font-size: 1.5rem; }
    .signal-tool { grid-template-columns: 1fr; }
    .transition-chain { flex-direction: column; gap: 0.35rem; }
    .t-arrow { transform: rotate(90deg); }
}

@media (max-width: 500px) {
    :root { --bar-height: 80px; }
    .brand-bar-inner { flex-wrap: wrap; }
    .brand-bar .bar-title {
        position: static;
        transform: none;
        width: 100%;
        max-width: 100%;
        order: 3;
        margin-top: 2px;
        font-size: 0.78rem;
        text-align: left;
    }
}

/* ──── Small phone ──── */
@media (max-width: 480px) {
    main { padding: 0 12px 20px 12px; border-radius: 0; }
    h1 { padding: calc(0.95rem + env(safe-area-inset-top)) 12px 0.9rem; font-size: 1.4rem; }
    h1 .hero-sub { font-size: 0.78rem; }
    h2 { font-size: 1.25rem; }
    .flow-node { padding: 0.5rem 0.85rem; font-size: 0.8rem; }
    .feedback-loop { flex-direction: column; align-items: center; gap: 0.25rem; }
    .loop-arrow { transform: rotate(90deg); margin-bottom: 0; }
    .loop-return { margin-top: 0.5rem; }
    .feature-card { padding: 0.75rem 0.85rem; }
    .toc-panel a { font-size: 0.88rem; padding: 0.45rem 0.5rem; }
    .toc-fab { bottom: 1rem; right: 1rem; width: 44px; height: 44px; }
    .start-brief-fab { bottom: 1rem; padding: 8px 18px 8px 14px; font-size: 0.8rem; }
    .start-brief-fab svg { width: 16px; height: 16px; }
    .toc-fab svg { width: 20px; height: 20px; }
}

/* ──── Reduce motion ──── */
@media (prefers-reduced-motion: reduce) {
    .reveal { opacity: 1; transform: none; transition: none; }
    .flow-node, .layer-item, .feature-card, .loop-num, .stat-box { transition: none; }
    .scroll-progress, .back-to-top { transition: none; }
    html { scroll-behavior: auto; }
}

/* ──── Dark mode ──── */
@media (prefers-color-scheme: dark) {
    :root {
        --primary-dark: #7db4ff;
        --primary: #5a9cf5;
        --primary-light: #4d8dff;
        --accent: #49b0ff;
        --bg-color: #0f1219;
        --text-main: #e2e8f0;
        --text-muted: #94a3b8;
        --border: #2d3748;
        --card: #1a202c;
        --code-bg: #0c1728;
        --code-text: #f8fafc;
    }
    .brand-bar { background: var(--card); border-bottom-color: var(--border); }
    .brand-bar .bar-logo { color: var(--text-main); }
    .brand-bar .bar-back { color: var(--primary-light); border-color: var(--primary-light); }
    .brand-bar .bar-back:hover { background: var(--primary-light); color: #0c1728; }
    .top-nav { background: var(--card); border-bottom-color: var(--border); }
    .nav-logo { color: var(--text-main); }
    .nav-cta-outline { color: var(--primary-light); border-color: var(--primary-light); }
    .nav-cta-outline:hover { background: var(--primary-light); color: #0c1728; }
    .mobile-nav-toggle { background: var(--card); border-color: var(--border); }
    .mobile-nav-toggle span { background: var(--text-main); }
    .mobile-nav-panel { background: var(--card); }
    h1 { background: linear-gradient(135deg, #0c1728, #1a2856 45%, #2d4bd9); }
    th { background: linear-gradient(135deg, #1e293b, #1a2856); }
    :not(pre) > code { background-color: #1e293b; border-color: rgba(77,141,255,0.15); }
    blockquote { background: linear-gradient(135deg, #1e293b, rgba(77,141,255,0.08)); }
    .testimonial { background: linear-gradient(135deg, #1a202c, rgba(77,141,255,0.04)); border-left-color: var(--border); }
    .feature-card, .signal-result { background: var(--card); }
    .feedback-loop, .signal-tool, .stat-box { background: linear-gradient(135deg, rgba(30,41,59,0.5), rgba(45,75,217,0.1)); }
    .signal-inputs input[type="range"] { background: var(--border); }
    tbody tr:nth-child(even) { background-color: rgba(30,41,59,0.4); }
    tbody tr:hover { background-color: rgba(77,141,255,0.1); }
    main { box-shadow: 0 10px 40px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.2); border-color: var(--border); }
    .toc-panel { background: var(--card); }
    .toc-overlay { background: rgba(0,0,0,0.6); }
    hr { background: linear-gradient(90deg, transparent, var(--border), var(--primary-light), var(--border), transparent); }
    main a:not([class]) { color: var(--primary-light); }
    main a:not([class]):hover { color: var(--accent); }
    .modal-dialog { background: #1e2028; box-shadow: 0 20px 60px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.08); }
    .modal-icon { background: rgba(220,38,38,0.12); }
    .modal-title { color: #f0f0f0; }
    .modal-body { color: #9ca3af; }
    .modal-btn-cancel { background: rgba(255,255,255,0.08); color: #e0e0e0; border-color: rgba(255,255,255,0.12); }
    .modal-btn-cancel:hover { background: rgba(255,255,255,0.14); }
}

/* ──── Print ──── */
/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}
.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}
.modal-dialog {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.05);
    max-width: 380px;
    width: calc(100% - 32px);
    padding: 28px 28px 22px;
    transform: scale(0.95) translateY(8px);
    transition: transform 0.2s ease;
}
.modal-overlay.visible .modal-dialog {
    transform: scale(1) translateY(0);
}
.modal-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fef2f2;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.modal-icon svg {
    width: 22px;
    height: 22px;
    stroke: #dc2626;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main, #2a2a2a);
    margin: 0 0 6px 0;
}
.modal-body {
    font-size: 0.9rem;
    color: var(--text-muted, #4b5563);
    line-height: 1.55;
    margin: 0 0 22px 0;
}
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.modal-btn {
    padding: 9px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid var(--border, #e1e4ec);
}
.modal-btn-cancel {
    background: #fff;
    color: var(--text-main, #2a2a2a);
}
.modal-btn-cancel:hover { background: #f3f4f6; }
.modal-btn-primary {
    background: var(--primary, #225cc7);
    color: #fff;
    border-color: var(--primary, #225cc7);
}
.modal-btn-primary:hover { background: #1a4f8a; border-color: #1a4f8a; }

@media print {
    .brand-bar, aside, .toc-fab, .toc-overlay, .toc-panel, .scroll-progress, .back-to-top, .start-brief-fab, .signal-tool { display: none !important; }
    body { padding-top: 0; }
    body { background: #fff; color: #000; display: block; }
    main { box-shadow: none; border: none; max-width: 100%; padding: 0 20px; border-radius: 0; }
    .container { max-width: 100%; padding: 0; display: block; }
    h1 { background: #143e6f !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; margin: 0 -20px 2rem -20px; padding: 2rem 20px; }
    .reveal { opacity: 1 !important; transform: none !important; }
    a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #666; }
    a[href^="#"]::after { content: ""; }
    .heading-anchor { display: none !important; }
    .doc-footer { border-top: 1px solid #ccc; }
}
