/*
  Cognispace | Canon Reader Stylesheet
  STD-001 Premium Reading Environment
  Aligned with site design system (style.css)
*/

/* ── Canon Reader Layout ───────────────────────────────────── */
body.canon-reader {
    background-color: var(--bg-base);
    overflow-x: hidden;
}

.canon-layout {
    display: block;
    min-height: 100vh;
    padding-top: 60px;
}

/* ── Progress Bar ──────────────────────────────────────────── */
.canon-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-teal));
    z-index: 1001;
    transition: width 0.1s linear;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.canon-sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    width: 280px;
    height: calc(100vh - 60px);
    overflow-y: auto;
    border-right: 1px solid rgba(0,0,0,0.06);
    background-color: #FAFAFA;
    padding: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.canon-sidebar::-webkit-scrollbar {
    width: 4px;
}
.canon-sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.canon-sidebar::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
    border-radius: 2px;
}

.sidebar-header {
    padding: 1.25rem 1.5rem 1rem;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    background-color: #FAFAFA;
    flex-shrink: 0;
}

.sidebar-header .doc-id {
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-blue);
    margin-bottom: 0.25rem;
}

.sidebar-header .doc-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    margin: 0;
}

.sidebar-header .doc-version {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 0.2rem;
}

/* Search */
.sidebar-search {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    flex-shrink: 0;
}

.search-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 0.625rem;
    color: var(--text-tertiary);
    pointer-events: none;
    flex-shrink: 0;
}

#canon-search {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2rem;
    font-size: 0.75rem;
    font-family: inherit;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 6px;
    background: #fff;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

#canon-search:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.08);
}

#canon-search::placeholder {
    color: var(--text-tertiary);
}

/* TOC Navigation */
.sidebar-toc {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0 1.5rem;
}

.sidebar-toc::-webkit-scrollbar {
    width: 3px;
}
.sidebar-toc::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
}

.toc-group {
    margin-bottom: 0.25rem;
}

.toc-chapter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.01em;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s, background-color 0.15s;
    line-height: 1.3;
    border-left: 2px solid transparent;
}

.toc-chapter:hover {
    color: var(--text-primary);
    background-color: rgba(0,0,0,0.03);
}

.toc-chapter.active {
    color: var(--accent-blue);
    border-left-color: var(--accent-blue);
    background-color: rgba(37,99,235,0.04);
}

.toc-chapter .toc-chapter-num {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: rgba(0,0,0,0.06);
    padding: 0.1em 0.4em;
    border-radius: 3px;
    flex-shrink: 0;
    color: var(--text-tertiary);
}

.toc-chapter.active .toc-chapter-num {
    background: rgba(37,99,235,0.12);
    color: var(--accent-blue);
}

.toc-section {
    display: block;
    padding: 0.3rem 1.25rem 0.3rem 2.5rem;
    font-size: 0.74rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s;
    line-height: 1.4;
}

.toc-section:hover {
    color: var(--text-secondary);
}

.toc-section.active {
    color: var(--accent-blue);
}

.toc-divider {
    height: 1px;
    background: rgba(0,0,0,0.06);
    margin: 0.5rem 1.25rem;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

.sidebar-action {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,0.08);
    background: #fff;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
    justify-content: center;
}

.sidebar-action:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
    background: #fff;
}

.sidebar-action svg {
    flex-shrink: 0;
}

/* ── Main Content ──────────────────────────────────────────── */
.canon-main {
    margin-left: 280px;
    padding: 3rem 5rem 6rem 4rem;
    overflow-x: hidden;
}

.canon-content-wrap {
    max-width: 820px;
    margin: 0;
}

/* ── Document Header ───────────────────────────────────────── */
.canon-doc-header {
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid rgba(0,0,0,0.08);
}

.canon-lock-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.3rem 0.75rem;
    background: linear-gradient(135deg, rgba(37,99,235,0.08), rgba(13,148,136,0.08));
    border: 1px solid rgba(37,99,235,0.2);
    border-radius: 100px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent-blue);
    margin-bottom: 1rem;
}

.canon-doc-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.canon-doc-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 1.25rem;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.meta-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

.meta-value {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Canon Lock Statement ──────────────────────────────────── */
.canon-lock-box {
    background: linear-gradient(135deg, rgba(37,99,235,0.04), rgba(13,148,136,0.04));
    border: 1px solid rgba(37,99,235,0.15);
    border-left: 3px solid var(--accent-blue);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin: 2rem 0;
}

.canon-lock-box .box-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-blue);
    margin-bottom: 0.5rem;
}

.canon-lock-box p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.65;
    margin: 0;
}

/* ── Governance Notes ──────────────────────────────────────── */
.governance-note {
    background: rgba(13,148,136,0.04);
    border: 1px solid rgba(13,148,136,0.15);
    border-left: 3px solid var(--accent-teal);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin: 1.5rem 0;
}

.governance-note .box-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-teal);
    margin-bottom: 0.375rem;
}

.governance-note p {
    font-size: 0.825rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

/* ── Canon Section Styling ─────────────────────────────────── */
.canon-section {
    margin-bottom: 4rem;
    scroll-margin-top: 80px;
}

.canon-section + .canon-section {
    border-top: 1px solid rgba(0,0,0,0.06);
    padding-top: 3rem;
}

.section-eyebrow {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 0.5rem;
}

.canon-section h2 {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.25;
    margin-bottom: 1rem;
}

.canon-section h2 .chapter-accent {
    color: var(--accent-blue);
}

.canon-section h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 2rem;
    margin-bottom: 0.625rem;
    letter-spacing: -0.01em;
}

.canon-section h3::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 0.85em;
    background: var(--accent-teal);
    border-radius: 2px;
    margin-right: 0.5rem;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

.canon-section h4 {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 1.5rem;
    margin-bottom: 0.375rem;
}

.canon-section p {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.canon-section ul,
.canon-section ol {
    padding-left: 1.375rem;
    margin-bottom: 1rem;
}

.canon-section li {
    font-size: 0.975rem;
    line-height: 1.75;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

/* ── Term / Monospace ──────────────────────────────────────── */
.canon-term {
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.8em;
    background: rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.08);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    color: var(--text-primary);
}

/* ── Example Pathway Box ───────────────────────────────────── */
.example-pathway {
    background: var(--bg-alt);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin: 1rem 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    border: 1px solid rgba(0,0,0,0.06);
}

.example-pathway strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* ── Healthy/Dysregulated Table-style boxes ─────────────────── */
.state-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin: 1rem 0;
}

.state-box {
    padding: 0.875rem 1rem;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.07);
}

.state-box.healthy {
    background: rgba(13,148,136,0.04);
    border-color: rgba(13,148,136,0.15);
}

.state-box.dysregulated {
    background: rgba(239,68,68,0.03);
    border-color: rgba(239,68,68,0.1);
}

.state-box .state-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.state-box.healthy .state-label { color: var(--accent-teal); }
.state-box.dysregulated .state-label { color: #dc2626; }

.state-box ul {
    margin: 0;
    padding-left: 1.1rem;
}

.state-box li {
    font-size: 0.8rem;
    line-height: 1.55;
    margin-bottom: 0.2rem;
    color: var(--text-secondary);
}

/* ── Ontology Lexicon Table ────────────────────────────────── */
.canon-table-wrap {
    overflow-x: auto;
    margin: 1.5rem 0;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.08);
}

.canon-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.canon-table th {
    background: var(--bg-alt);
    padding: 0.625rem 1rem;
    text-align: left;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    border-bottom: 1px solid rgba(0,0,0,0.08);
    white-space: nowrap;
}

.canon-table td {
    padding: 0.625rem 1rem;
    color: var(--text-secondary);
    vertical-align: top;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    line-height: 1.55;
}

.canon-table tr:last-child td {
    border-bottom: none;
}

.canon-table tr:hover td {
    background: rgba(0,0,0,0.015);
}

.canon-table .impl-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--accent-blue);
    background: rgba(37,99,235,0.06);
    padding: 0.1em 0.4em;
    border-radius: 4px;
    white-space: nowrap;
}

/* ── Conceptual Summary ────────────────────────────────────── */
.conceptual-summary {
    background: var(--bg-dark);
    border-radius: 10px;
    padding: 1.5rem;
    margin-top: 2rem;
}

.conceptual-summary .sum-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-dark-secondary);
    margin-bottom: 0.625rem;
}

.conceptual-summary p {
    font-size: 0.875rem;
    color: var(--text-dark-secondary);
    line-height: 1.7;
    margin: 0;
}

/* ── Search Highlight ──────────────────────────────────────── */
mark.search-highlight {
    background: rgba(250,204,21,0.4);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

/* ── Floating Controls ─────────────────────────────────────── */
.canon-floating-controls {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 200;
}

.float-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-dark);
    color: #fff;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.float-btn:hover {
    transform: translateY(-2px);
    opacity: 0.9;
}

.float-btn-label {
    position: absolute;
    right: 48px;
    white-space: nowrap;
    background: var(--bg-dark);
    color: #fff;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.float-btn:hover .float-btn-label {
    opacity: 1;
}

/* ── Search Results Count ──────────────────────────────────── */
.search-results-count {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    padding: 0.25rem 1.25rem;
    display: none;
}

.search-results-count.visible {
    display: block;
}

/* ── No Results ────────────────────────────────────────────── */
.canon-no-results {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-tertiary);
    font-size: 0.875rem;
    display: none;
}

/* ── Back to top ───────────────────────────────────────────── */
#back-to-top {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

#back-to-top.visible {
    opacity: 1;
    pointer-events: all;
}

/* ── Revision table ────────────────────────────────────────── */
.revision-table th { width: 15%; }
.revision-table td:first-child { font-family: 'JetBrains Mono', monospace; font-size: 0.75rem; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 960px) {
    .canon-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s;
    }
    .canon-sidebar.open {
        transform: translateX(0);
    }
    .canon-main {
        margin-left: 0;
        width: 100%;
        padding: 2rem 1.5rem 4rem;
    }
    .mobile-sidebar-toggle {
        display: flex !important;
    }
    .state-grid {
        grid-template-columns: 1fr;
    }
}

.mobile-sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 2rem;
    left: 1rem;
    z-index: 300;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    background: var(--bg-dark);
    color: #fff;
    border: none;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

@media print {
    .canon-sidebar,
    .canon-progress-bar,
    .canon-floating-controls,
    .mobile-sidebar-toggle,
    .navbar { display: none !important; }
    .canon-main { margin-left: 0; padding: 1rem; }
    .canon-section { page-break-inside: avoid; }
}
