.toc {
    position: relative;
}

.toc-layout h2 {
    border-bottom: 1px solid var(--black-alpha-2);
    padding-bottom: .5rem;
    margin-top: var(--spacing-large);
}

.toc-layout .side-menu-wrapper {
    position: relative;
    height: 100%;
}

.toc-layout .side-menu-wrapper .side-menu {
    top: 10rem;
    position: sticky;
}

.toc-item {
    display: flex;
    flex-direction: column;
    position: relative;
}

/* 🔹 Lägg till en linje mellan H2-sektionerna */
.toc-item:not(:last-child)::after {
    content: "";
    display: block;
    height: 1px;
    background: rgba(0, 0, 0, 0.1);
}

/* Lista för H3-rubriker under en H2 */
.toc ul {
    list-style: none;
    padding-left: 10px;
    margin-left: 0px;
    margin-top: 0px;  /* 🔥 Minskar avståndet mellan H2 och dess H3 */
    margin-bottom: 5px;
}

/* Styling för alla länkar */
.toc a {
    text-decoration: none;
    color: rgba(0,0,0,.55);
    display: inline-flex;
    align-items: flex-start; /* Justerar så att bollen inte påverkar textlayouten */
    line-height: 1.3;
    font-size: .85rem;
    position: relative;
}

/* 🔥 H2-länkar ska alltid ha font-weight 600 och behålla sin padding */
.toc-item > a {
    font-weight: 600;
    padding: 0.5rem 0;
    margin-bottom: 0px; /* 🔥 Minskar avståndet mellan H2 och H3 */
}

/* 🔥 H3-länkar får mindre padding */
.toc ul a {
    border: none;
    padding: 0.2rem 0;  /* 🔥 Minskar vertikal padding endast för H3 */
    padding-left: 12px;
}

/* 🔹 Lägg till en tunn vertikal linje för att gruppera H3-länkar */
.toc ul {
    padding-left: 0;
}

/* Lägger till bindestreck till vänster om H3-länkarna */
.toc ul a::before {
    content: "-";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
    color: $primary-color;
}

/* 🔥 Justerar bollen så att den alltid är centrerad med första raden */
.toc-item.has-active > a::before {
    content: "●";
    position: absolute;
    left: -15px;
    top: 0.4em; /* 🔥 Justerar så att bollen alltid hamnar i linje med första raden */
    font-size: 1rem;
    color: $primary-color;
}

/* 🔹 Lägger till 10px bottom margin på sista H3-länken i varje H2-sektion */
.toc ul li:last-child a {
    margin-bottom: 10px;
}

/* Aktiv H3-länk får en bakgrund */
.toc ul a.active {
    transition: background 0.3s ease-in-out; /* Mjuk övergång */
    text-decoration: underline;
}

/* Aktiv länk */
.toc a.active {
    border-color: $primary-color;
    color: $black;
}

/* Tar bort linjen under sista huvudrubriken */
.toc-item:last-child::after {
    display: none;
}

/* 🚀 Dölj desktop TOC på mobil */
@media (max-width: 978px) {
    .side-menu-wrapper {
        display: none;
    }
}

/* 🚀 Dölj mobil TOC på desktop */
@media (min-width: 979px) {
    .mobile-toc {
        display: none;
    }
}

/* 🚀 Mobil TOC - fast i botten */
.mobile-toc {
    position: fixed;
    bottom: 15px;
    left: 10px;
    right: 10px;
    background: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    z-index: 1000;
    overflow: hidden;
    transition: all 0.2s ease-in-out;
}

/* 🚀 Knappen för att öppna TOC */
.mobile-toc-toggle {
    width: 100%;
    padding: 1.2rem 1.2rem;
    font-size: 1rem;
    font-weight: var(--font-weight-semi-bold);
    background: var(--light);
    border: none;
    cursor: pointer;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease-in-out;
    border-radius: var(--border-radius-small);
    color: var(--black);
}


/* 🚀 Snabb och smidig animation */
.mobile-toc-content {
    max-height: 0;
    overflow: hidden;
    background: white;
    padding: 0;
    opacity: 0;
    transform: translateY(-3px);
    transition: max-height 0.2s ease-out, opacity 0.2s ease-out, transform 0.2s ease-out;

}

/* 🚀 När TOC är öppen */
.mobile-toc-content.open {
    max-height: 350px;
    padding: 8px 0;
    overflow-y: auto;
    opacity: 1;
    transform: translateY(0);
}

/* 🚀 H2-länkar */
.mobile-toc-item {
    background: white;
    padding: 10px 0;
    border-bottom: 1px solid #ddd;
    font-weight: $bold-weight;
    text-align: left;
    transition: background 0.2s ease-in-out;
}

.mobile-toc-item a {
    color: var(--black);
}

/* 🚀 H3-länkar (underlänkar) */
.mobile-toc-sub {
    display: flex;
    flex-direction: column;
    margin-top: 2px;
}

/* 🚀 H3-länkar mindre och tydligare */
.mobile-toc-sub a {
    padding: .25rem 0;
    font-size: 0.85rem;
    font-weight: normal;
    text-align: left;
    display: block;
    color: $black;
}

/* 🚀 Chevron-ikon */
.chevron {
    display: flex;
    transition-duration: $transition-duration;
    
}

.chevron svg {
    width: 1rem;
}

.chevron svg path {
    fill: $white;
}

/* 🚀 Roterar chevron vid öppning */
.chevron.open {
    transform: rotate(180deg);
}

.mobile-toc-list {
    padding: 0 2rem;
}

/* Tar bort linjen under sista huvudrubriken */
.mobile-toc-item:last-child {
    border-bottom: 0;
}

.mobile-toc {
    opacity: 0;
    transform: translateY(5px);
}

.scrolled .mobile-toc {
    opacity: 1;
    transform: translateY(0);
}