/**
 * Makepedia Modern Table of Contents (TOC) Styles
 * 
 * 1. Large screens (>= 1200px): Trafee-style sticky left sidebar with:
 *    - "Back to blog/category" link
 *    - "Table of Contents ˅" header with collapse toggle
 *    - Clean vertical list with active orange indicator line
 *    - "Up to top" button
 * 2. Mobile & Tablets (< 1200px): Compact inline collapsible card.
 * 3. Full dark mode support.
 */

:root {
  --mp-toc-bg: var(--background);
  --mp-toc-card: var(--card);
  --mp-toc-border: var(--border);
  --mp-toc-text: var(--foreground);
  --mp-toc-text-muted: var(--muted-foreground);
  --mp-toc-primary: var(--primary);
  --mp-toc-primary-hover: var(--primary-hover);
  --mp-toc-primary-soft: var(--muted);
  --mp-toc-radius: var(--radius);
}

/* Headings anchor offset for smooth scrolling under sticky headers */
.entry-content h2.mp-heading-anchor,
.entry-content h3.mp-heading-anchor,
.entry-content h4.mp-heading-anchor,
h2.mp-heading-anchor,
h3.mp-heading-anchor,
h4.mp-heading-anchor {
  scroll-margin-top: 85px;
}

@media screen and (min-width: 1200px) {
  .layout--toc > .layout-toc > * {
    position: sticky;
    top: var(--layout-sticky-top);
    z-index: 20;
    max-height: var(--layout-sticky-max-height);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
    padding-bottom: 0;
  }

  /* Trailing margins would stretch the row below the article and leave the sticky TOC hanging past it */
  .layout--toc > .layout-main > .entry,
  .layout--toc > .layout-main .entry-footer {
    margin-bottom: 0;
  }

  .single-has-toc .makepedia-toc-inline {
    display: none !important;
  }
}

@media screen and (max-width: 1199px) {
  .makepedia-toc-inline {
    display: block !important;
  }
}

/* ==========================================================================
   Trafee-Style Sticky Left Sidebar TOC
   ========================================================================== */

.trafee-toc-sidebar {
  font-family: var(--font-sans, 'Golos Text', -apple-system, BlinkMacSystemFont, sans-serif);
  color: var(--mp-toc-text);
  padding: 4px 0 16px 0;
  user-select: none;
}

/* Back Link */
.trafee-toc-back-wrap {
  margin-bottom: 22px;
}

.trafee-toc-back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--mp-toc-text-muted) !important;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none !important;
  transition: color 0.15s ease;
}

.trafee-toc-back-link:hover {
  color: var(--mp-toc-text) !important;
}

/* Header */
.trafee-toc-header {
  margin-bottom: 12px;
}

.trafee-toc-toggle-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.trafee-toc-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--mp-toc-text);
  letter-spacing: -0.2px;
}

.trafee-toc-chevron {
  color: var(--mp-toc-text-muted);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Collapsed State */
.trafee-toc-sidebar.is-collapsed .trafee-toc-chevron {
  transform: rotate(-90deg);
}

.trafee-toc-sidebar.is-collapsed .trafee-toc-body,
.trafee-toc-sidebar.is-collapsed .trafee-toc-footer {
  display: none !important;
}

/* Navigation List */
.trafee-toc-body {
  margin: 0;
  padding: 0;
}

.trafee-toc-list {
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border-left: 1px solid var(--mp-toc-border);
}

.trafee-toc-item {
  margin: 0 !important;
  padding: 0 !important;
  line-height: 1.45;
}

.trafee-toc-link {
  display: block;
  position: relative;
  margin-left: -1px;
  padding: 6px 0 6px 14px;
  border-left: 2px solid transparent;
  color: var(--mp-toc-text-muted) !important;
  font-size: 14px;
  line-height: 1.45;
  text-decoration: none !important;
  transition: color 0.15s ease, border-color 0.15s ease;
  word-break: break-word;
}

.trafee-toc-link:hover {
  color: var(--mp-toc-text) !important;
}

.trafee-toc-link:focus:not(:focus-visible) {
  outline: none;
}

.trafee-toc-link.is-active {
  border-left: 2px solid var(--mp-toc-primary) !important;
  color: var(--mp-toc-text) !important;
  font-weight: 500;
}

.trafee-toc-item.level-3 .trafee-toc-link {
  padding-left: 26px;
  font-size: 13.5px;
}

.trafee-toc-item.level-4 .trafee-toc-link {
  padding-left: 38px;
  font-size: 13px;
}

/* Footer / Up to Top Button */
.trafee-toc-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--mp-toc-border);
}

.trafee-toc-top-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--mp-toc-text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s ease;
}

.trafee-toc-top-btn:hover {
  color: var(--mp-toc-text);
}

/* ==========================================================================
   Inline TOC Card (Mobile & Tablets < 1200px)
   ========================================================================== */

.makepedia-toc {
  background: var(--mp-toc-card);
  border: 1px solid var(--mp-toc-border);
  border-radius: var(--mp-toc-radius);
  margin: 24px 0 32px;
  padding: 16px 20px;
  font-family: var(--font-sans, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  max-width: 100%;
}

.makepedia-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  user-select: none;
}

.makepedia-toc-title-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.makepedia-toc-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--mp-toc-text-muted);
}

.makepedia-toc-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--mp-toc-text);
  letter-spacing: -0.2px;
}

.makepedia-toc-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--mp-toc-text-muted);
  font-size: 12.5px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.makepedia-toc-toggle-btn:hover {
  background: var(--muted);
  color: var(--mp-toc-text);
}

.toc-toggle-chevron {
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.makepedia-toc-body {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--mp-toc-border);
  max-height: 380px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.makepedia-toc-list {
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

.makepedia-toc-item {
  margin: 4px 0 !important;
  padding: 0 !important;
  line-height: 1.45;
}

.makepedia-toc-item.toc-level-3 {
  margin-left: 18px !important;
}

.makepedia-toc-item.toc-level-4 {
  margin-left: 32px !important;
}

.makepedia-toc-link {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--mp-toc-text) !important;
  font-size: 15px;
  text-decoration: none !important;
  transition: background-color 0.15s ease;
}

.makepedia-toc-link:hover {
  background: var(--muted);
}

.toc-item-number {
  font-size: 13px;
  font-weight: 500;
  color: var(--mp-toc-text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 18px;
}

.makepedia-toc-link.is-active {
  background: var(--muted) !important;
  font-weight: 500;
}

.makepedia-toc.is-collapsed .makepedia-toc-body {
  display: none !important;
}

.makepedia-toc.is-collapsed .toc-toggle-chevron {
  transform: rotate(-90deg);
}

@media screen and (max-width: 768px) {
  .makepedia-toc {
    padding: 10px 12px;
    margin: 16px 0 20px;
  }

  .makepedia-toc-toggle-btn {
    padding: 2px 6px;
  }

  .makepedia-toc-body {
    margin-top: 8px;
    padding-top: 6px;
  }

  .makepedia-toc-item {
    margin: 0 !important;
    line-height: 1.35;
  }

  .makepedia-toc-item.toc-level-3 {
    margin-left: 10px !important;
  }

  .makepedia-toc-item.toc-level-4 {
    margin-left: 16px !important;
  }

  .makepedia-toc-link {
    font-size: 14.5px;
    line-height: 1.35;
    padding: 4px 6px;
  }
}
