/* Prevent layout shift from scrollbar appearing/disappearing */
html {
    overflow-y: scroll;
    scroll-behavior: smooth;
}

/* ================================================================
   Warm ivory + gold — scoped to sidebar
   ================================================================ */
.fixed-sidebar {
    --s-accent:        #a68a50;
    --s-accent-light:  #c9a96e;
    --s-bg:            #f7f4ef;
    --s-border:        #e4dfd6;
    --s-sub-border:    #d4c9b4;
    --s-hover-bg:      #f0ebe2;
    --s-active-bg:     #e8dfcf;
    --s-text:          #2d2d3a;
    --s-text-muted:    #7a7a8a;
    --s-text-faint:    #9a9aa8;
}

/* Fixed Sidebar Navigation */
.fixed-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 230px;
    height: 100vh;
    background: var(--s-bg);
    padding: 0;
    z-index: 1000;
    overflow-y: auto;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--s-border);
}

/* Sidebar header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--s-border);
    flex-shrink: 0;
}

.fixed-sidebar h2 {
    font-size: 0.88rem;
    color: var(--s-text);
    margin: 0;
    padding-bottom: 0;
    border-bottom: none;
    font-family: 'Inter', sans-serif;
    letter-spacing: 0.14em;
    text-transform: lowercase;
    font-weight: 400;
}

.fixed-sidebar h2::after {
    display: none;
}

/* Header actions group (search + hamburger) */
.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sidebar-search-btn,
.sidebar-print-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: var(--s-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

.sidebar-search-btn:hover,
.sidebar-print-btn:hover {
    color: var(--s-accent);
    background: var(--s-hover-bg);
}

.sidebar-search-btn:focus,
.sidebar-print-btn:focus {
    outline: none;
}

.sidebar-search-btn:focus-visible,
.sidebar-print-btn:focus-visible {
    outline: 2px solid var(--s-accent-light);
    outline-offset: 2px;
}

/* Hamburger - hidden on desktop */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    flex-direction: column;
    gap: 4px;
    outline: none;
}

.sidebar-toggle:focus-visible {
    outline: 2px solid var(--s-accent-light);
    outline-offset: 2px;
}

.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--s-text);
    border-radius: 2px;
    transition: transform 0.25s, opacity 0.25s;
}

/* Nav links container */
.fixed-sidebar .nav-links {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

/* Icon inside nav-btn */
.fixed-sidebar .nav-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    opacity: 0.55;
    transition: opacity 0.2s;
}

.fixed-sidebar .nav-btn:hover .nav-icon,
.fixed-sidebar .nav-btn.active .nav-icon {
    opacity: 1;
}

/* Main nav items */
.fixed-sidebar .nav-btn {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    font-size: 0.84rem;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--s-text);
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    font-weight: 400;
    text-align: left;
    text-decoration: none;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    line-height: 1.3;
}

.fixed-sidebar .nav-btn:focus {
    outline: none;
}

.fixed-sidebar .nav-btn:focus-visible {
    outline: 2px solid var(--s-accent-light);
    outline-offset: 2px;
}

.fixed-sidebar .nav-btn:hover {
    color: var(--s-accent);
    background: var(--s-hover-bg);
}

.fixed-sidebar .nav-btn.active {
    color: var(--s-accent);
    background: var(--s-active-bg);
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(166, 138, 80, 0.08);
}

/* Dark mode toggle button */
.sidebar-theme-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: var(--s-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}

.sidebar-theme-btn:hover {
    color: var(--s-accent);
    background: var(--s-hover-bg);
}

.sidebar-theme-btn:focus {
    outline: none;
}

.sidebar-theme-btn:focus-visible {
    outline: 2px solid var(--s-accent-light);
    outline-offset: 2px;
}

/* ================================================================
   Dark Mode Sidebar — warm dark
   ================================================================ */

[data-theme="dark"] .fixed-sidebar {
    --s-accent:        #c9a96e;
    --s-accent-light:  #dcc08a;
    --s-bg:            #13131a;
    --s-border:        #2a2a34;
    --s-sub-border:    #3a3528;
    --s-hover-bg:      #1e1e28;
    --s-active-bg:     #26241e;
    --s-text:          #b0aca4;
    --s-text-muted:    #6a6a78;
    --s-text-faint:    #505060;
    background: var(--s-bg);
    border-right-color: var(--s-border);
}

[data-theme="dark"] .sidebar-header {
    border-bottom-color: var(--s-border);
}

[data-theme="dark"] .sidebar-toggle span {
    background: var(--s-text);
}

@media (max-width: 860px) {
    [data-theme="dark"] .fixed-sidebar {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    }

    [data-theme="dark"] .fixed-sidebar .nav-links {
        border-top-color: var(--s-border);
    }
}

/* ================================================================ */

/* Push page content to the right of the sidebar */
body.has-sidebar {
    margin-left: 230px;
}

/* Scroll offset for anchored sections */
body.has-sidebar .section[id] {
    scroll-margin-top: 20px;
}

/* ============================================================ */
/* Mobile: collapsible sidebar                                   */
/* ============================================================ */
@media (max-width: 860px) {
    .fixed-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: auto;
        flex-direction: column;
        padding: 0;
        border-right: none;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
        overflow: hidden;
    }

    /* Quando aperto: altezza piena viewport, scrollabile */
    .fixed-sidebar.open {
        height: 100%;
        bottom: 0;
    }

    .sidebar-header {
        padding: 12px 16px;
        border-bottom: none;
        flex-shrink: 0;
    }

    .sidebar-toggle {
        display: flex;
    }

    /* Collapsed by default on mobile */
    .fixed-sidebar .nav-links {
        display: none;
        flex-direction: column;
        padding: 8px 12px 14px;
        border-top: 1px solid var(--s-border);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-height: 0;
    }

    .fixed-sidebar.open .nav-links {
        display: flex;
    }

    /* Animate hamburger when open */
    .fixed-sidebar.open .sidebar-toggle span:nth-child(1) {
        transform: rotate(45deg) translate(4px, 4px);
    }

    .fixed-sidebar.open .sidebar-toggle span:nth-child(2) {
        opacity: 0;
    }

    .fixed-sidebar.open .sidebar-toggle span:nth-child(3) {
        transform: rotate(-45deg) translate(4px, -4px);
    }

    .fixed-sidebar .nav-btn {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    body.has-sidebar {
        margin-left: 0;
        margin-top: 56px;
    }

    body.has-sidebar .section[id] {
        scroll-margin-top: 70px;
    }
}
