/* ==========================================================================
   Legal Portal — Advanced Navigation
   Sidebar, prev/next, table of contents, scroll progress
   ========================================================================== */

/* ---------- Top Progress Bar ---------- */

.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent-warm);
  z-index: 200;
  transition: width 0.1s linear;
  width: 0%;
}

/* ---------- Sidebar Navigation (Desktop) ---------- */

.legal-sidebar {
  display: none;
}

@media (max-width: 1099px) {
  .legal-sidebar {
    display: block;
    position: fixed;
    left: 0;
    top: var(--nav-height, 64px);
    bottom: 0;
    width: 260px;
    background: var(--bg-primary, #fafaf8);
    border-right: 1px solid var(--border, #e5e3df);
    overflow-y: auto;
    padding: 1rem 0;
    z-index: 105;
    font-size: 0.75rem;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.08);
  }

  .legal-sidebar.sidebar-open {
    transform: translateX(0);
  }
}

@media (min-width: 1100px) {
  .legal-sidebar {
    display: block;
    position: fixed;
    left: 0;
    top: var(--nav-height, 64px);
    bottom: 0;
    width: 230px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: var(--space-md) 0;
    z-index: 50;
    font-size: var(--text-xs);
  }

  .legal-sidebar::-webkit-scrollbar {
    width: 3px;
  }

  .legal-sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
  }

  /* Push main content right when sidebar is present */
  body.has-sidebar .legal-main,
  .has-sidebar .legal-main {
    margin-left: 230px;
  }

  body.has-sidebar .site-nav .nav-inner,
  .has-sidebar .site-nav .nav-inner {
    padding-left: 240px;
  }
}

/* ---------- Sidebar Sections ---------- */

.sidebar-section {
  padding: 0 var(--space-sm);
  margin-bottom: 0.15rem;
}

.sidebar-brand {
  border-bottom: 1px solid var(--border, #e5e3df);
  padding-bottom: 0.75rem;
  margin-bottom: 0.5rem;
}

/* Non-collapsible section headings (e.g. overview on legal/index.html) */
.sidebar-heading {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-sm);
  opacity: 0.8;
  line-height: 1.4;
}

/* "Permission sought" subtext under Appeal and JR */
.sidebar-subtext {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  opacity: 0.5;
  padding: 0 var(--space-sm);
  margin-top: -0.15rem;
  margin-bottom: 0.2rem;
}

/* ---------- Sidebar Links ---------- */

.sidebar-link {
  display: block;
  padding: 0.3rem var(--space-sm);
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 4px;
  transition: all 0.1s;
  font-size: var(--text-xs);
  line-height: 1.5;
  border-left: 2px solid transparent;
}

.sidebar-link:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
}

.sidebar-link.active {
  color: var(--accent-warm);
  border-left-color: var(--accent-warm);
  background: rgba(184, 134, 11, 0.05);
  font-weight: 500;
}

/* Strong links: the most important in each section */
.sidebar-link-strong {
  font-weight: 600;
  color: var(--text-primary);
}

/* Gold highlight: "No Time Bar" */
.sidebar-link-gold {
  color: #f4c856;
  font-weight: 600;
}

/* ---------- Sidebar Badges ---------- */

.sidebar-badge {
  float: right;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  background: var(--bg-surface);
  padding: 0.1em 0.3em;
  border-radius: 2px;
  color: var(--text-secondary);
}

/* Hot badge: red-tinted for alarming stats */
.sidebar-badge-hot {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* ---------- Prev/Next Navigation ---------- */

.prev-next {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: var(--space-md);
  padding: var(--space-xl) 0;
  border-top: 1px solid var(--border);
  margin-top: var(--space-xl);
}

.prev-next a {
  display: flex;
  flex-direction: column;
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  flex: 1;
  transition: border-color 0.15s;
  max-width: 48%;
}

.prev-next a:hover {
  border-color: var(--accent-warm);
}

.prev-next .pn-dir {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.prev-next .pn-title {
  font-family: var(--font-display);
  font-size: var(--text-sm);
  color: var(--text-primary);
  margin-top: 0.25rem;
}

.prev-next .next {
  text-align: right;
  margin-left: auto;
}

/* ---------- Table of Contents (floating) ---------- */

.page-toc {
  display: none;
}

@media (min-width: 1300px) {
  .page-toc {
    display: block;
    position: fixed;
    right: 1.5rem;
    top: calc(var(--nav-height, 64px) + 2rem);
    width: 180px;
    font-size: var(--text-xs);
    z-index: 40;
  }

  .page-toc-title {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
    opacity: 0.7;
  }

  .page-toc a {
    display: block;
    padding: 0.2rem 0 0.2rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 1px solid var(--border);
    transition: all 0.15s;
    line-height: 1.4;
  }

  .page-toc a:hover {
    color: var(--text-primary);
  }

  .page-toc a.toc-active {
    color: var(--accent-warm);
    border-left-color: var(--accent-warm);
  }
}

/* ---------- Collapsible Sections (<details>/<summary>) ---------- */

/* Each collapsible section is a distinct bordered card */
.sidebar-details {
  padding: 0;
  margin: 0 0.4rem 0.4rem;
  border: 1px solid var(--border, #e5e3df);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.sidebar-details[open] {
  border-color: rgba(0, 0, 0, 0.15);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Section header (clickable summary) */
.sidebar-summary {
  display: flex;
  align-items: center;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  padding: 0.55rem 0.6rem;
  line-height: 1.3;
  transition: background 0.15s;
  background: var(--bg-surface, #f5f4f0);
  border-bottom: 1px solid transparent;
  gap: 0.3rem;
}

.sidebar-details[open] > .sidebar-summary {
  border-bottom-color: var(--border, #e5e3df);
}

.sidebar-summary:hover {
  background: rgba(0, 0, 0, 0.04);
}

.sidebar-summary::-webkit-details-marker { display: none; }
.sidebar-summary::marker { display: none; content: ''; }

.sidebar-summary-title {
  flex: 1;
  min-width: 0;
}

/* Colour variants with strong backgrounds */
.sidebar-summary-accent {
  color: var(--accent-warm, #b8860b);
  font-weight: 700;
  background: rgba(184, 134, 11, 0.08);
  border-left: 3px solid var(--accent-warm, #b8860b);
}

.sidebar-summary-void {
  color: #dc2626;
  font-weight: 700;
  background: rgba(239, 68, 68, 0.06);
  border-left: 3px solid #ef4444;
}

.sidebar-summary-appeal {
  color: #2563eb;
  font-weight: 700;
  background: rgba(59, 130, 246, 0.06);
  border-left: 3px solid #3b82f6;
}

.sidebar-summary-jr {
  color: #7c3aed;
  font-weight: 700;
  background: rgba(139, 92, 246, 0.06);
  border-left: 3px solid #8b5cf6;
}

/* Void section: stronger outer border */
.sidebar-details-void {
  border-left: 3px solid #ef4444;
  border-color: rgba(239, 68, 68, 0.2);
}

/* Standalone gold link (No Time Bar) */
.sidebar-standalone-gold {
  margin: 0.4rem 0.4rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: rgba(244, 200, 86, 0.06);
  border: 1px solid rgba(244, 200, 86, 0.25);
  border-left: 3px solid #f4c856;
}

.sidebar-badge-gold { background: rgba(244, 200, 86, 0.15); color: #f4c856; }
.sidebar-badge-appeal { background: rgba(59, 130, 246, 0.1); color: #3b82f6; }
.sidebar-badge-jr { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }

/* Chevron indicator */
.sidebar-chevron {
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  opacity: 0.4;
}

details[open] > .sidebar-summary .sidebar-chevron {
  transform: rotate(45deg);
}

/* Collapsible content area */
.sidebar-section-content {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
  overflow: hidden;
}

details[open] > .sidebar-section-content {
  grid-template-rows: 1fr;
}

.sidebar-section-content > div {
  overflow: hidden;
  padding: 0.3rem 0.4rem 0.4rem;
}

/* Visual divider between arguments and evidence sections */
.sidebar-divider {
  border: none;
  height: 0;
  margin: 0.6rem 0.8rem;
  border-top: 2px dashed var(--border, #e5e3df);
  opacity: 0.4;
}

/* ---------- Sidebar Search Filter ---------- */

.sidebar-search-wrap {
  padding: 0.4rem 0.4rem;
  margin-bottom: 0.2rem;
  position: relative;
}

.sidebar-search {
  width: 100%;
  padding: 0.35rem 2rem 0.35rem 0.6rem;
  font-family: var(--font-body, sans-serif);
  font-size: 0.7rem;
  border: 1px solid var(--border, #e5e3df);
  border-radius: 4px;
  background: var(--bg-surface, #f5f4f0);
  color: var(--text-primary, #1a1a1a);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sidebar-search:focus {
  border-color: var(--accent-warm, #b8860b);
  box-shadow: 0 0 0 2px rgba(184, 134, 11, 0.15);
}

.sidebar-search::placeholder {
  color: var(--text-secondary, #5a5a5a);
  opacity: 0.6;
}

.sidebar-search-key {
  position: absolute;
  right: calc(var(--space-sm) + 0.5rem);
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-secondary);
  background: var(--bg-primary, #fafaf8);
  border: 1px solid var(--border, #e5e3df);
  padding: 0.05em 0.3em;
  border-radius: 3px;
  opacity: 0.5;
  pointer-events: none;
}

.sidebar-search:focus ~ .sidebar-search-key {
  display: none;
}

.sidebar-search-count {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--text-secondary);
  opacity: 0.5;
  display: block;
  text-align: center;
  margin-top: 0.2rem;
  min-height: 0.7rem;
}

/* Hide links and sections that don't match filter */
.sidebar-link.filter-hidden { display: none; }
.sidebar-section.filter-hidden { display: none; }

/* ---------- Reading Progress ---------- */

.sidebar-link.visited::before {
  content: '\2713';
  display: inline-block;
  width: 1em;
  margin-left: -0.2em;
  margin-right: 0.15em;
  color: var(--accent-warm, #b8860b);
  opacity: 0.4;
  font-size: 0.65em;
  vertical-align: middle;
}

.sidebar-progress-wrap {
  padding: 0.4rem var(--space-sm) 0.6rem;
}

.sidebar-progress-bar {
  height: 2px;
  background: var(--border, #e5e3df);
  border-radius: 1px;
  overflow: hidden;
}

.sidebar-progress-fill {
  height: 100%;
  background: var(--accent-warm, #b8860b);
  border-radius: 1px;
  transition: width 0.3s ease;
  width: 0%;
}

.sidebar-progress-text {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--text-secondary);
  opacity: 0.5;
  margin-top: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.sidebar-progress-count {
  font-weight: 600;
}

.sidebar-progress-meta {
  flex: 1;
}

.sidebar-visited-icon {
  color: var(--accent-warm, #b8860b);
  opacity: 0.6;
}

.sidebar-progress-clear {
  font-family: var(--font-mono);
  font-size: 0.45rem;
  color: var(--text-secondary);
  opacity: 0.4;
  text-decoration: none;
  cursor: pointer;
}

.sidebar-progress-clear:hover {
  opacity: 0.8;
  color: #ef4444;
}

/* ---------- Keyboard focus ring for j/k nav ---------- */

.sidebar-link.kb-focus {
  outline: 2px solid var(--accent-warm, #b8860b);
  outline-offset: -1px;
  background: rgba(184, 134, 11, 0.06);
}

/* ---------- Mobile Bottom Nav ---------- */

.mobile-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    z-index: 100;
    padding: var(--space-xs) 0;
    justify-content: space-around;
  }

  .mobile-nav a,
  .mobile-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.6rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    font-family: var(--font-mono);
    background: none;
    border: none;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
  }

  .mobile-nav a.active,
  .mobile-nav button.active {
    color: var(--accent-warm);
  }

  .mobile-nav .nav-icon {
    font-size: 1.1rem;
    margin-bottom: 0.1rem;
  }

  /* Sidebar search on mobile needs 16px to prevent iOS zoom */
  .sidebar-search {
    font-size: 16px;
    min-height: 44px;
    padding: 0.5rem 2rem 0.5rem 0.8rem;
  }

  /* Add bottom padding to page for mobile nav */
  .legal-page,
  .legal-wrapper {
    padding-bottom: 4rem;
  }
}
