.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #161310 0%, #0f0d0b 100%);
    color: #efeae2;
    border-right: 1px solid rgba(196, 165, 116, 0.14);
    z-index: 35;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    gap: 2px;
}

.sidebar-logo {
    font-family: var(--font-serif);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--color-accent-soft);
    line-height: 1;
}

.sidebar-title {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--chrome-muted);
}

.sidebar-toggle {
    appearance: none;
    border: 1px solid rgba(255,255,255,0.12);
    background: transparent;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.sidebar-sheets {
    padding: 0.75rem 1rem 0.25rem;
}
.sidebar-sheets-label {
    display: block;
    margin-bottom: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-accent);
    font-weight: 700;
}
.sidebar-sheets-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.sheet-chip {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: none;
    color: #efeae2;
    border: 1px solid rgba(196, 165, 116, 0.28);
    border-radius: 999px;
    padding: 0.22rem 0.55rem;
    background: rgba(196, 165, 116, 0.08);
}
.sheet-chip:hover {
    background: rgba(196, 165, 116, 0.2);
    color: #fff;
}

.sidebar-search {
    padding: 0.75rem 1rem;
    position: relative;
}
.sidebar-search form { display: flex; gap: 6px; }
.sidebar-search input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.28);
    color: #fff;
    font-family: var(--font-sans);
    font-size: 0.88rem;
}
.search-btn {
    appearance: none;
    border: none;
    background: var(--color-accent);
    color: #1a1612;
    width: 38px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 700;
}

.sidebar-search-live {
    position: absolute;
    left: 1rem;
    right: 1rem;
    top: calc(100% - 4px);
    background: #221e18;
    border: 1px solid rgba(196, 165, 116, 0.25);
    border-radius: var(--radius-md);
    max-height: 280px;
    overflow: auto;
    z-index: 20;
    box-shadow: var(--shadow-lg);
}
.sidebar-search-live a {
    display: block;
    padding: 0.55rem 0.75rem;
    color: #eee;
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sidebar-search-live a:hover { background: rgba(196, 165, 116, 0.12); }

.sidebar-progress { padding: 0 1rem 0.85rem; }
.progress-track {
    height: 5px;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-accent), #8a7355);
    width: 0;
    transition: width 0.25s ease;
}
.progress-text {
    display: block;
    margin-top: 0.35rem;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    color: var(--chrome-muted);
}

.sidebar-bookmarks {
    padding: 0 0.65rem 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    margin: 0 0.35rem 0.35rem;
}
.sidebar-bookmarks-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.35rem 0.35rem;
}
.bookmarks-clear {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--chrome-muted);
    font-family: var(--font-sans);
    font-size: 0.68rem;
    cursor: pointer;
    padding: 0;
}
.bookmarks-clear:hover { color: var(--color-accent-soft); }
.sidebar-bookmarks-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 9.5rem;
    overflow: auto;
}
.bookmark-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.25rem;
    border-radius: var(--radius-sm);
}
.bookmark-row:hover,
.bookmark-row.is-active {
    background: rgba(196, 165, 116, 0.12);
}
.bookmark-link {
    min-width: 0;
    padding: 0.4rem 0.5rem;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    line-height: 1.3;
    color: #efeae2;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bookmark-link:hover { color: var(--color-accent-soft); }
.bookmark-remove {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--chrome-muted);
    width: 1.6rem;
    height: 1.6rem;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    border-radius: var(--radius-sm);
}
.bookmark-remove:hover {
    color: #fff;
    background: rgba(255,255,255,0.08);
}

.sidebar-nav {
    flex: 1;
    overflow: auto;
    padding: 0.25rem 0.65rem 1rem;
}

.toc-section { margin-bottom: 0.45rem; }
.toc-section--archive .toc-section-title { color: rgba(154, 146, 136, 0.85); }
.toc-section--module .toc-section-title {
    color: var(--color-accent-soft);
    font-size: 0.78rem;
    letter-spacing: 0.02em;
}

.toc-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.5rem;
}
.toc-section-title {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-accent-soft);
}
.toc-section-toggle {
    appearance: none;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.45);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}
.toc-section-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
}
.toc-section.open .toc-section-content { max-height: 5000px; }

.toc-link {
    display: grid;
    grid-template-columns: 2.2rem 1fr;
    gap: 0.4rem;
    align-items: baseline;
    padding: 0.38rem 0.5rem;
    border-radius: var(--radius-sm);
    color: rgba(239, 234, 226, 0.82);
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 0.86rem;
    line-height: 1.35;
}
.toc-link--solo {
    grid-template-columns: 1fr auto;
}
.toc-link:hover { background: rgba(255,255,255,0.05); color: #fff; }
.toc-link.active {
    background: rgba(196, 165, 116, 0.16);
    color: #fff;
    box-shadow: inset 2px 0 0 var(--color-accent);
}
.toc-number {
    font-variant-numeric: tabular-nums;
    color: rgba(239, 234, 226, 0.4);
    font-size: 0.76rem;
    min-width: 2.1rem;
    text-align: right;
}
.toc-number--empty {
    visibility: hidden;
}
.toc-count {
    font-variant-numeric: tabular-nums;
    color: rgba(239, 234, 226, 0.38);
    font-size: 0.72rem;
    padding-left: 0.35rem;
}
.toc-sublabel {
    margin: 0.55rem 0.5rem 0.15rem;
    font-family: var(--font-sans);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(239, 234, 226, 0.38);
}
.toc-catalog-btn {
    /* Under chapter title column; width tracks the label, not the full row */
    display: inline-block;
    box-sizing: border-box;
    max-width: calc(100% - 0.5rem - 2.2rem - 0.4rem - 0.5rem);
    margin: 0.1rem 0.5rem 0.4rem calc(0.5rem + 2.2rem + 0.4rem);
    padding: 0.28rem 0.5rem;
    border-radius: 4px;
    border: 1px solid rgba(196, 165, 116, 0.28);
    background: rgba(196, 165, 116, 0.08);
    color: rgba(239, 234, 226, 0.78);
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}
.toc-catalog-btn:hover {
    border-color: rgba(196, 165, 116, 0.5);
    background: rgba(196, 165, 116, 0.14);
    color: #fff;
}
.toc-catalog-btn.active {
    border-color: rgba(196, 165, 116, 0.55);
    color: #fff;
    box-shadow: inset 2px 0 0 var(--color-accent);
}

.sidebar-footer {
    padding: 0.75rem 1rem 1rem;
    display: grid;
    gap: 6px;
    border-top: 1px solid rgba(255,255,255,0.06);
}
.sidebar-action {
    appearance: none;
    display: block;
    text-align: center;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.03);
    color: #efeae2;
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
}
.sidebar-action:hover {
    border-color: var(--color-accent);
    color: var(--color-accent-soft);
}

body.sidebar-collapsed .sidebar { transform: translateX(calc(-1 * var(--sidebar-width) + 12px)); }
body.sidebar-collapsed .shell-main { margin-left: 12px; }

@media (max-width: 1024px) {
    body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
    body.sidebar-collapsed .shell-main { margin-left: 0; }
}
