/* ==========================================================================
   Roam Morocco — Dynamic Sticky & Mobile-Friendly Table of Contents (TOC)
   ========================================================================== */

/* Layout Grid for Desktop */
.roam-article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 48px;
  align-items: start;
  position: relative;
}

@media (min-width: 1025px) {
  .article-wrap,
  .roam-article-wrapper,
  .roam-tour-wrapper {
    max-width: 1220px !important;
  }
}

@media (max-width: 1024px) {
  .roam-article-layout {
    display: block;
  }
}

/* Ensure smooth scrolling with offset for sticky navbar */
html {
  scroll-behavior: smooth;
}

/* CRITICAL: Ensure html and body never break position:sticky across all browsers */
html, body {
  overflow-x: clip !important;
  overflow-y: visible !important;
  height: auto !important;
}

h2[id], h3[id] {
  scroll-margin-top: 96px;
}

/* ==========================================================================
   Desktop Sticky Sidebar
   ========================================================================== */
.roam-toc-sidebar {
  position: -webkit-sticky;
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  padding: 24px 20px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.03);
  z-index: 50;
  user-select: none;
}

@media (max-width: 1024px) {
  .roam-toc-sidebar {
    display: none !important;
  }
}

.roam-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.roam-toc-title {
  font-family: "Courier New", monospace;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #000000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.roam-toc-title::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--gold, #C8A45C);
}

.roam-toc-progress-text {
  font-family: "Courier New", monospace;
  font-size: 11px;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.45);
}

/* Progress Bar Line */
.roam-toc-progress-track {
  width: 100%;
  height: 2px;
  background: rgba(0, 0, 0, 0.08);
  margin-bottom: 16px;
  overflow: hidden;
}

.roam-toc-progress-bar {
  height: 100%;
  width: 0%;
  background: #000000;
  transition: width .15s ease-out;
}

/* TOC Links Scrollable List */
.roam-toc-list {
  list-style: none !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
  padding-right: 4px;
}

/* Custom minimal scrollbar */
.roam-toc-list::-webkit-scrollbar {
  width: 3px;
}
.roam-toc-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.18);
}

.roam-toc-item {
  margin-bottom: 4px;
}

.roam-toc-link {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: rgba(0, 0, 0, 0.62) !important;
  text-decoration: none !important;
  padding: 8px 12px;
  border-left: 2px solid transparent;
  transition: all .2s ease;
}

.roam-toc-link:hover {
  color: #000000 !important;
  background: rgba(0, 0, 0, 0.03);
}

.roam-toc-link.active {
  color: #000000 !important;
  font-weight: 700;
  border-left: 2px solid #000000;
  background: rgba(0, 0, 0, 0.04);
}

/* ==========================================================================
   Mobile Floating TOC Capsule & Drawer
   ========================================================================== */
.roam-mobile-toc-btn {
  display: none;
  position: fixed;
  bottom: 74px;
  left: 14px;
  right: auto;
  z-index: 185;
  height: 48px;
  background: rgba(18, 18, 18, 0.92) !important;
  backdrop-filter: blur(30px) saturate(1.8) !important;
  -webkit-backdrop-filter: blur(30px) saturate(1.8) !important;
  border: 1px solid rgba(255, 255, 255, 0.16) !important;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.32) !important;
  border-radius: 9999px !important;
  padding: 0 18px 0 16px;
  color: #ffffff !important;
  font-family: Helvetica, Arial, sans-serif;
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  cursor: pointer;
  align-items: center;
  gap: 8px;
  box-sizing: border-box;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.roam-mobile-toc-btn:hover {
  transform: translateY(-2px);
  background: rgba(30, 30, 30, 0.96) !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
  box-shadow: 0 20px 52px rgba(0, 0, 0, 0.5) !important;
}

.roam-mobile-toc-btn:active {
  transform: scale(0.97);
}

@media (max-width: 1024px) {
  .roam-mobile-toc-btn {
    display: inline-flex;
  }
}

@media (max-width: 850px) {
  .roam-mobile-toc-btn {
    bottom: 74px !important;
    left: 14px !important;
    height: 42px !important;
    padding: 0 16px 0 14px !important;
    font-size: 11px !important;
  }
}

/* Mobile Drawer Overlay */
.roam-toc-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 250;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

.roam-toc-modal-overlay.open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

/* Mobile Slide-Up Bottom Sheet — Frosted Glass Match */
.roam-toc-modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 80vh;
  background: rgba(14, 14, 14, 0.96);
  backdrop-filter: blur(30px) saturate(1.8);
  -webkit-backdrop-filter: blur(30px) saturate(1.8);
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 20px 20px 0 0 !important;
  z-index: 260;
  display: flex;
  flex-direction: column;
  padding: 24px 20px 32px;
  transform: translateY(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform .35s cubic-bezier(.16, 1, .3, 1), visibility .35s ease;
  box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.5);
}

.roam-toc-modal.open {
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
}

.roam-toc-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.roam-toc-modal-title {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #ffffff;
}

.roam-toc-modal-close {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 14px;
  font-weight: 700;
  width: 32px;
  height: 32px;
  border-radius: 50% !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #ffffff;
  transition: all .2s ease;
}

.roam-toc-modal-close:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: #ffffff;
}

.roam-toc-modal-list {
  list-style: none !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow-y: auto;
  max-height: 60vh;
}

.roam-toc-modal-list li {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.roam-toc-modal-list li:last-child {
  border-bottom: none;
}

.roam-toc-modal-list a {
  display: block;
  padding: 14px 8px;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85) !important;
  text-decoration: none !important;
  line-height: 1.4;
  transition: all .2s ease;
}

.roam-toc-modal-list a:hover,
.roam-toc-modal-list a.active {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.05);
  padding-left: 14px;
}
