/* Sticky TOC Sidebar - Dennis Woerner */

/* -----------------------------------------------------------------------
   Shared custom properties
----------------------------------------------------------------------- */
#sticky-toc-sidebar,
#sticky-toc-sheet {
    --toc-accent:  #1D4ED8;
    --toc-width:   220px;
    --toc-bg:      #ffffff;
    --toc-border:  #e5e7eb;
    --toc-text:    #374151;
    --toc-muted:   #9ca3af;
    --toc-radius:  10px;
    --toc-shadow:  0 4px 16px rgba(0, 0, 0, 0.08);
}

/* =======================================================================
   DESKTOP SIDEBAR
======================================================================= */
#sticky-toc-sidebar {
    position: fixed;
    top: 50%; /* fallback only - overridden by JS immediately */
    transform: none;
    width: var(--toc-width);
    max-height: 72vh;
    overflow-y: auto;
    overflow-x: hidden;

    background: var(--toc-bg);
    border: 1px solid var(--toc-border);
    border-radius: var(--toc-radius);
    box-shadow: var(--toc-shadow);
    padding: 18px 14px;

    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    line-height: 1.45;
    color: var(--toc-text);
    z-index: 9999;

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, top 0.18s ease;
    will-change: opacity, top;
}

#sticky-toc-sidebar.sticky-toc--visible {
    opacity: 1;
    pointer-events: auto;
}

/* Hidden on mobile - JS also hides, CSS is the safety net */
@media (max-width: 1199px) {
    #sticky-toc-sidebar {
        display: none !important;
    }
}

/* -----------------------------------------------------------------------
   Shared list styles (used by both desktop sidebar and mobile sheet)
----------------------------------------------------------------------- */
.sticky-toc__title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--toc-muted);
    margin: 0 0 12px 0;
    padding: 0 0 10px 8px;
    border-bottom: 1px solid var(--toc-border);
}

.sticky-toc__list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sticky-toc__item {
    margin: 0;
    padding: 0;
    border-left: 2px solid transparent;
    transition: border-color 0.2s ease;
}

.sticky-toc__link {
    display: block;
    padding: 5px 8px;
    color: var(--toc-text);
    text-decoration: none !important;
    word-break: break-word;
    hyphens: auto;
    transition: color 0.2s ease;
    line-height: 1.4;
}

.sticky-toc__link:hover {
    color: var(--toc-accent) !important;
    text-decoration: none !important;
}

/* Post title entry - above the numbered headings */
.sticky-toc__item--post-title {
    border-left: none;
    margin-bottom: 6px;
    padding-bottom: 4px;
}

.sticky-toc__link--post-title {
    font-size: 13px !important;
    font-weight: 700 !important;
    color: #111827 !important;
    padding-left: 8px !important;
    line-height: 1.35;
}

.sticky-toc__link--post-title:hover {
    color: var(--toc-accent) !important;
}

/* H2 number badge in accent colour */
.sticky-toc__num {
    color: var(--toc-accent);
    font-weight: 700;
}

/* Extra top spacing before H2 items (except the very first one) */
.sticky-toc__item--h2 + .sticky-toc__item--h2,
.sticky-toc__item--h3 + .sticky-toc__item--h2,
.sticky-toc__item--h4 + .sticky-toc__item--h2,
.sticky-toc__item--h5 + .sticky-toc__item--h2,
.sticky-toc__item--h6 + .sticky-toc__item--h2 {
    margin-top: 8px;
}

/* Indentation by heading level */
.sticky-toc__item--h2 .sticky-toc__link { padding-left:  8px; font-size: 13px; }
.sticky-toc__item--h3 .sticky-toc__link { padding-left: 18px; font-size: 12.5px; }
.sticky-toc__item--h4 .sticky-toc__link { padding-left: 28px; font-size: 12px; color: #6b7280; }
.sticky-toc__item--h5 .sticky-toc__link { padding-left: 38px; font-size: 11.5px; color: #9ca3af; }
.sticky-toc__item--h6 .sticky-toc__link { padding-left: 48px; font-size: 11px; color: #9ca3af; }

/* Desktop scrollbar */
#sticky-toc-sidebar::-webkit-scrollbar        { width: 4px; }
#sticky-toc-sidebar::-webkit-scrollbar-track  { background: transparent; }
#sticky-toc-sidebar::-webkit-scrollbar-thumb  { background: var(--toc-border); border-radius: 2px; }
#sticky-toc-sidebar::-webkit-scrollbar-thumb:hover { background: var(--toc-muted); }


/* =======================================================================
   MOBILE FLOATING BUTTON
======================================================================= */
#sticky-toc-btn {
    display: none; /* hidden on desktop, shown on mobile via media query */
    position: fixed;
    bottom: 24px;
    right: 22px;
    z-index: 10000;

    align-items: center;
    gap: 8px;
    padding: 10px 16px;

    background: var(--toc-accent, #1D4ED8);
    color: #fff;
    border: none;
    border-radius: 50px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

#sticky-toc-btn:active {
    transform: scale(0.95);
}

#sticky-toc-btn span {
    line-height: 1;
}

/* Show button on mobile only */
@media (max-width: 1199px) {
    #sticky-toc-btn {
        display: flex;
    }
}


/* =======================================================================
   BACKDROP
======================================================================= */
#sticky-toc-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 10001;
    opacity: 0;
    transition: opacity 0.25s ease;
}

#sticky-toc-backdrop.is-open {
    display: block;
    opacity: 1;
}

@media (min-width: 1200px) {
    #sticky-toc-backdrop { display: none !important; }
}


/* =======================================================================
   MOBILE BOTTOM SHEET
======================================================================= */
#sticky-toc-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10002;
    max-height: 75vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    background: var(--toc-bg);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.16);

    /* Slide up animation */
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

#sticky-toc-sheet.is-open {
    transform: translateY(0);
}

/* Drag handle */
#sticky-toc-sheet::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 10px auto 0;
    flex-shrink: 0;
}

/* Sheet header */
.sticky-toc-sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px 12px;
    border-bottom: 1px solid var(--toc-border);
    flex-shrink: 0;
}

.sticky-toc-sheet__title {
    font-size: 15px;
    font-weight: 700;
    color: #111827;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.sticky-toc-sheet__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: #f3f4f6;
    border: none;
    border-radius: 50%;
    color: #6b7280;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.sticky-toc-sheet__close:hover {
    background: #e5e7eb;
}

/* Sheet nav / list */
#sticky-toc-sheet nav {
    overflow-y: auto;
    padding: 12px 8px 32px;
    flex: 1 1 auto;
}

/* Bigger tap targets in sheet */
#sticky-toc-sheet .sticky-toc__link {
    padding-top:    9px;
    padding-bottom: 9px;
    font-size: 14px;
}

/* Sub-chapter prefix (dash or sub-number) - injected by JS as a span */

/* Flex layout so wrapped text stays right of the prefix, never below it */
.sticky-toc__item--h3 .sticky-toc__link,
.sticky-toc__item--h4 .sticky-toc__link,
.sticky-toc__item--h5 .sticky-toc__link,
.sticky-toc__item--h6 .sticky-toc__link {
    display: flex;
    align-items: flex-start;
}

.sticky-toc__dash {
    flex-shrink: 0;
    color: var(--toc-accent);
    margin-right: 5px;
}
.sticky-toc__item--h3 .sticky-toc__dash { opacity: 0.6; font-size: 0.95em; }
.sticky-toc__item--h4 .sticky-toc__dash { opacity: 0.4; font-size: 0.9em; }

.sticky-toc__sub-num {
    flex-shrink: 0;
    color: var(--toc-accent);
    font-weight: 700;
    margin-right: 4px;
}

#sticky-toc-sheet .sticky-toc__item--h3 .sticky-toc__link { font-size: 13.5px; }
#sticky-toc-sheet .sticky-toc__item--h4 .sticky-toc__link { font-size: 13px; }

/* Hide sheet on desktop */
@media (min-width: 1200px) {
    #sticky-toc-sheet,
    #sticky-toc-btn  { display: none !important; }
}
