/* ============================================================
 * Article TOC sidebar + back-to-top
 * ------------------------------------------------------------
 * - Desktop ≥1280px : sidebar fixed à droite (.article-toc)
 * - Mobile/tablette  : bottom-sheet drawer (.article-toc-drawer)
 *                      + FAB "Sommaire" allongé bas-gauche (.article-toc-fab)
 * - Toutes plateformes : back-to-top rond bas-droite (.back-to-top)
 * - Mobile-first : touch targets ≥48px, safe-area iOS, swipe-close
 * Piloté par assets/article-toc.js
 * ============================================================ */

/* ---------- Sidebar desktop (≥1400px) ----------
   Calcul du breakpoint : contenu max 880px + sidebar 220px + gap 32px
   + 2×24px marges = 1180px minimum théorique. Marge confort : 1400px.
   Position : alignée à GAUCHE du contenu max 880px avec gap 32px minimum.
   Si l'écran est étroit, la sidebar tombe à 24px du bord (pas d'overlap
   car cachée < 1400px). Background + border : card lisible visuellement. */
.article-toc {
  position: fixed;
  top: 110px;
  left: max(24px, calc((100vw - 880px) / 2 - 220px - 32px));
  width: 220px;
  max-height: calc(100vh - 160px);
  z-index: 40;
  font-family: 'Archivo', sans-serif;
  background: color-mix(in srgb, var(--bg, #FBF7F0) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line, rgba(10,10,10,.10));
  border-radius: 10px;
  padding: 18px 16px;
  display: none;
  overflow: hidden;
}
@media (min-width: 1400px) {
  .article-toc.is-ready {
    display: flex;
    flex-direction: column;
  }
}

.article-toc-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: .22em;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-muted, #6E6E6E);
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line, rgba(10,10,10,.10));
  display: flex; align-items: center; gap: 8px;
}
.article-toc-label::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--fuchsia, #EF426F);
}

.article-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong, rgba(10,10,10,.18)) transparent;
}
.article-toc-list::-webkit-scrollbar { width: 4px; }
.article-toc-list::-webkit-scrollbar-thumb { background: var(--line-strong, rgba(10,10,10,.18)); border-radius: 2px; }

.article-toc-item {
  position: relative;
  margin: 0;
  padding: 0;
}
.article-toc-item a {
  display: block;
  padding: 7px 0 7px 14px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-muted, #6E6E6E);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color .15s, border-color .2s, padding-left .2s;
}
.article-toc-item a:hover {
  color: var(--ink, #0A0A0A);
  border-left-color: var(--line-strong, rgba(10,10,10,.18));
}
.article-toc-item.is-active a {
  color: var(--ink, #0A0A0A);
  font-weight: 700;
  border-left-color: var(--fuchsia, #EF426F);
  padding-left: 18px;
}
.article-toc-item.is-h3 a {
  padding-left: 26px;
  font-size: 11.5px;
  color: var(--ink-muted, #6E6E6E);
  opacity: .85;
}
.article-toc-item.is-h3.is-active a {
  padding-left: 30px;
  border-left-color: var(--teal, #00B2A9);
}

/* ---------- Mobile FAB "Sommaire" allongé (bas-gauche, ≤1279px) ---------- */
.article-toc-fab {
  position: fixed;
  bottom: 24px;
  left: 24px;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0 20px 0 16px;
  min-height: 52px;
  background: var(--ink, #0A0A0A);
  color: var(--bg, #FBF7F0);
  border: none;
  border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
  cursor: pointer;
  z-index: 90;
  box-shadow: 0 12px 32px rgba(0,0,0,.28);
  opacity: 0;
  transform: translateY(20px) scale(.96);
  transition: opacity .25s, transform .25s, background .15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.article-toc-fab.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
@media (max-width: 1279px) {
  .article-toc-fab.is-ready { display: inline-flex; }
}
.article-toc-fab:active { background: var(--fuchsia, #EF426F); }
.article-toc-fab svg { width: 18px; height: 18px; flex: 0 0 auto; }

/* ---------- Mobile bottom-sheet drawer ---------- */
.article-toc-drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  visibility: hidden;
}
.article-toc-drawer.is-open {
  pointer-events: auto;
  visibility: visible;
}
.article-toc-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10,10,10,.5);
  opacity: 0;
  transition: opacity .3s ease;
  -webkit-tap-highlight-color: transparent;
}
.article-toc-drawer.is-open .article-toc-drawer-backdrop { opacity: 1; }

.article-toc-drawer-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 80dvh;
  background: var(--bg, #FBF7F0);
  border-radius: 18px 18px 0 0;
  padding: 8px 20px 24px;
  transform: translateY(100%);
  transition: transform .35s cubic-bezier(.2,.7,.2,1);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0,0,0,.22);
  touch-action: pan-y;
}
.article-toc-drawer.is-open .article-toc-drawer-panel {
  transform: translateY(0);
}

.article-toc-drawer-grab {
  width: 44px;
  height: 5px;
  background: var(--line-strong, rgba(10,10,10,.18));
  border-radius: 4px;
  margin: 10px auto 14px;
  flex: 0 0 auto;
}

.article-toc-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line, rgba(10,10,10,.10));
  flex: 0 0 auto;
}
.article-toc-drawer-header .article-toc-label {
  margin: 0;
  padding: 0;
  border: 0;
}
.article-toc-drawer-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line-strong, rgba(10,10,10,.18));
  background: transparent;
  color: var(--ink, #0A0A0A);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.article-toc-drawer-close svg { width: 14px; height: 14px; }
.article-toc-drawer-close:active { background: var(--bg-2, #F2EDE2); }

/* Liste mobile : touch targets généreux ≥44px */
.article-toc-drawer-panel .article-toc-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  padding: 6px 0 4px;
  max-height: none;
}
.article-toc-drawer-panel .article-toc-item a {
  padding: 12px 0 12px 16px;
  font-size: 15px;
  min-height: 44px;
  display: flex;
  align-items: center;
  line-height: 1.4;
  color: var(--ink-soft, #3A3A3A);
}
.article-toc-drawer-panel .article-toc-item.is-h3 a {
  padding-left: 30px;
  font-size: 14px;
  color: var(--ink-muted, #6E6E6E);
}
.article-toc-drawer-panel .article-toc-item.is-active a {
  padding-left: 20px;
  color: var(--ink, #0A0A0A);
  font-weight: 700;
  border-left: 3px solid var(--fuchsia, #EF426F);
}
.article-toc-drawer-panel .article-toc-item.is-h3.is-active a {
  padding-left: 34px;
  border-left-color: var(--teal, #00B2A9);
}

/* iOS safe-area */
@supports (padding: env(safe-area-inset-bottom)) {
  .article-toc-drawer-panel {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .article-toc-fab {
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: calc(24px + env(safe-area-inset-left));
  }
}

/* Bloque le scroll du body quand le drawer est ouvert */
body.article-toc-open { overflow: hidden; }

/* ---------- Back to top button (bas-droite, toujours) ---------- */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--ink, #0A0A0A);
  color: var(--bg, #FBF7F0);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  box-shadow: 0 12px 32px rgba(0,0,0,.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(.92);
  transition: opacity .25s, transform .25s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.back-to-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}
.back-to-top:hover,
.back-to-top:active { background: var(--fuchsia, #EF426F); }
.back-to-top svg { width: 20px; height: 20px; }

@supports (padding: env(safe-area-inset-bottom)) {
  .back-to-top {
    bottom: calc(24px + env(safe-area-inset-bottom));
    right: calc(24px + env(safe-area-inset-right));
  }
}

/* Quand le drawer est ouvert, on cache le FAB et le back-to-top (recouverts visuellement) */
body.article-toc-open .article-toc-fab,
body.article-toc-open .back-to-top {
  opacity: 0;
  pointer-events: none;
}

/* ---------- Dark mode ---------- */
[data-theme="dark"] .article-toc-label { border-bottom-color: rgba(255,255,255,.10); }
[data-theme="dark"] .article-toc-item a { color: rgba(244,239,230,.55); }
[data-theme="dark"] .article-toc-item a:hover { color: #F4EFE6; }
[data-theme="dark"] .article-toc-item.is-active a { color: #F4EFE6; }
[data-theme="dark"] .article-toc-fab { background: #F4EFE6; color: #0A0A0A; }
[data-theme="dark"] .article-toc-fab:active { background: var(--fuchsia, #EF426F); color: #F4EFE6; }
[data-theme="dark"] .back-to-top { background: #F4EFE6; color: #0A0A0A; }
[data-theme="dark"] .back-to-top:hover,
[data-theme="dark"] .back-to-top:active { background: var(--fuchsia, #EF426F); color: #F4EFE6; }
[data-theme="dark"] .article-toc-drawer-panel { background: #0A0A0A; }
[data-theme="dark"] .article-toc-drawer-grab { background: rgba(255,255,255,.22); }
[data-theme="dark"] .article-toc-drawer-panel .article-toc-item a { color: rgba(244,239,230,.7); }
[data-theme="dark"] .article-toc-drawer-panel .article-toc-item.is-active a { color: #F4EFE6; }
[data-theme="dark"] .article-toc-drawer-close { border-color: rgba(255,255,255,.22); color: #F4EFE6; }
