/* =============================================================
   TOC + Reading Progress Bar — easyabogado.com
   CSS standalone (sin Tailwind). Portable a cualquier blog PHP.
   ============================================================= */

:root {
  /* === Paleta — ajusta aquí los colores de marca === */
  --toc-accent:        #1d4ed8; /* azul corporativo (links activos, barra) */
  --toc-accent-soft:   #3b82f6; /* azul claro para gradiente */
  --toc-accent-bg:     rgba(29, 78, 216, 0.08); /* fondo activo */
  --toc-bg:            #ffffff;
  --toc-bg-card:       #f8fafc;
  --toc-border:        #e2e8f0;
  --toc-text:          #1e293b;
  --toc-text-muted:    #64748b;
  --toc-text-strong:   #0f172a;
  --toc-backdrop:      rgba(15, 23, 42, 0.55);

  /* === Tamaños === */
  --toc-width:         260px;     /* ancho sidebar desktop */
  --toc-top-offset:    89px;      /* header 73px + 16px de margen */
  --toc-progress-h:    3px;       /* alto de la barra superior */
  --toc-radius:        12px;
  --toc-z-progress:    9998;
  --toc-z-sidebar:     40;
  --toc-z-mobile-btn:  9997;
  --toc-z-drawer:      9999;

  /* === Breakpoint desktop === */
  /* lg en Tailwind = 1024px. Cambia si quieres otro punto de corte. */
}

/* ===== Scroll suave global (necesario para los anchors) ===== */
html { scroll-behavior: smooth; }

/* Compensa el header fijo cuando saltas a un anchor.
   Si tu web NO tiene header fijo, pon scroll-margin-top: 16px. */
#article-content h2,
#article-content h3 {
  scroll-margin-top: 100px;
}

/* =============================================================
   1) BARRA DE PROGRESO SUPERIOR (fija arriba del viewport)
   ============================================================= */
.toc-progress-top {
  position: fixed;
  top: 0;
  left: 0;
  height: var(--toc-progress-h);
  width: 0%;
  background: linear-gradient(90deg, var(--toc-accent), var(--toc-accent-soft));
  z-index: var(--toc-z-progress);
  transition: width 0.1s linear;
  pointer-events: none;
}

/* =============================================================
   2) SIDEBAR TOC — DESKTOP (sticky a la derecha o izquierda)
   ============================================================= */
.toc-sidebar {
  display: none; /* oculto en móvil; @media abajo lo activa */
  width: var(--toc-width);
  flex-shrink: 0;
  position: sticky;
  top: var(--toc-top-offset);
  align-self: flex-start;
  max-height: calc(100vh - var(--toc-top-offset));
  overflow-y: auto;
}

.toc-sidebar-inner {
  background: var(--toc-bg);
  border: 1px solid var(--toc-border);
  border-radius: var(--toc-radius);
  padding: 18px 18px 16px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
  opacity: 1;
  max-height: calc(100vh - var(--toc-top-offset) - 24px);
  overflow-y: auto;
}

/* aparece tras scroll > 300px (lo activa el JS) */
.toc-sidebar-inner.is-visible { opacity: 1; }

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.toc-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--toc-text-strong);
  margin: 0;
}

.toc-title svg { width: 16px; height: 16px; color: var(--toc-accent); }

.toc-toggle {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px;
  color: var(--toc-text-muted);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, color 0.2s ease;
}
.toc-toggle:hover { color: var(--toc-text-strong); }
.toc-toggle svg { width: 16px; height: 16px; transition: transform 0.2s ease; }
.toc-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }

/* Mini barra de progreso dentro del sidebar */
.toc-mini-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 11px;
  color: var(--toc-text-muted);
}
.toc-mini-progress-track {
  flex: 1;
  height: 4px;
  background: var(--toc-border);
  border-radius: 999px;
  overflow: hidden;
}
.toc-mini-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--toc-accent), var(--toc-accent-soft));
  border-radius: 999px;
  transition: width 0.1s linear;
}
.toc-mini-progress-text {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--toc-text);
  min-width: 32px;
  text-align: right;
}

/* Lista del TOC */
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.toc-list[hidden] { display: none; }

.toc-list a {
  display: block;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--toc-text-muted);
  text-decoration: none;
  padding: 7px 10px 7px 12px;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.toc-list a:hover {
  color: var(--toc-text-strong);
  background: var(--toc-bg-card);
}
.toc-list a.is-active {
  color: var(--toc-accent);
  font-weight: 600;
  border-left-color: var(--toc-accent);
  background: var(--toc-accent-bg);
}
/* Indentación para h3 (si decidieras incluirlos) */
.toc-list a.toc-level-3 { padding-left: 24px; font-size: 13px; }

/* =============================================================
   3) BOTÓN FLOTANTE MÓVIL
   ============================================================= */
.toc-mobile-btn {
  display: inline-flex;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 999px;
  background: var(--toc-accent);
  color: #fff;
  border: 0;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(29, 78, 216, 0.35);
  z-index: var(--toc-z-mobile-btn);
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.toc-mobile-btn:hover { transform: translateY(-2px); }
.toc-mobile-btn svg { width: 22px; height: 22px; }
.toc-mobile-btn[hidden] { display: none !important; }

/* =============================================================
   4) DRAWER MÓVIL (bottom sheet)
   ============================================================= */
.toc-mobile-overlay {
  position: fixed;
  inset: 0;
  background: var(--toc-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: var(--toc-z-drawer);
}
.toc-mobile-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.toc-mobile-drawer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--toc-bg);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  padding: 16px 18px 24px;
  max-height: 75vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.18);
}
.toc-mobile-overlay.is-open .toc-mobile-drawer {
  transform: translateY(0);
}

.toc-mobile-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--toc-border);
  margin: 0 auto 14px;
}

.toc-mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.toc-mobile-close {
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--toc-text-muted);
  padding: 4px;
  border-radius: 6px;
}
.toc-mobile-close:hover { color: var(--toc-text-strong); }
.toc-mobile-close svg { width: 18px; height: 18px; }

.toc-mobile-list a {
  display: block;
  font-size: 15px;
  line-height: 1.45;
  color: var(--toc-text-muted);
  text-decoration: none;
  padding: 12px 12px;
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}
.toc-mobile-list a:hover { color: var(--toc-text-strong); background: var(--toc-bg-card); }
.toc-mobile-list a.is-active {
  color: var(--toc-accent);
  font-weight: 600;
  background: var(--toc-accent-bg);
}
.toc-mobile-list a.toc-level-3 { padding-left: 24px; font-size: 14px; }

/* =============================================================
   RESPONSIVE
   ============================================================= */
@media (min-width: 1024px) {
  .toc-sidebar { display: block; }
  .toc-mobile-btn { display: none; }
}

/* Bloquea scroll del body cuando el drawer móvil está abierto */
body.toc-scroll-lock { overflow: hidden; }

/* =============================================================
   LAYOUT SUGERIDO (opcional) — wrapper artículo + sidebar
   Si tu plantilla ya tiene su propio grid, ignora este bloque.
   ============================================================= */
.toc-layout {
  display: flex;
  gap: 40px;
  align-items: flex-start;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}
.toc-layout > .toc-main { flex: 1; min-width: 0; }
