/**
 * myLogbook 3-column grid — Zone 2.
 *
 * Sidebar scroll-trapping uses overscroll-behavior: contain, not custom
 * JS wheel-event hijacking. Once a sidebar is scrolling, reaching its own
 * top/bottom does NOT chain into scrolling the page — exactly the
 * "trapped" behavior requested, native to the browser, works correctly
 * with trackpads/touch/mouse wheel alike.
 *
 * Sticky offset math: sidebars stick just below the site header, using
 * --ml-toolbar-height + --ml-menubar-height from tokens.css. Their max
 * height is the remaining viewport height, so overflow (and therefore
 * internal scrolling) only kicks in when a sidebar's content is actually
 * taller than the visible space — never a forced scroll area for short
 * content.
 */

.ml-grid {
  display: grid;
  grid-template-columns: var(--ml-sidebar-width) minmax(0, 1fr) var(--ml-sidebar-width);
  gap: var(--ml-space-lg);
  max-width: calc(var(--ml-grid-overhead) + (100vw - var(--ml-grid-overhead)) * var(--ml-width-percent) / 100);
  margin: 0 auto;
  padding: 0 var(--ml-space-lg);
}

.ml-sidebar {
  position: sticky;
  top: calc(var(--ml-toolbar-height) + var(--ml-menubar-height) + var(--ml-space-lg));
  max-height: calc(100vh - var(--ml-toolbar-height) - var(--ml-menubar-height) - (var(--ml-space-lg) * 2));
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: var(--ml-space-md);
  padding-bottom: var(--ml-space-lg);

  /* Thin, unobtrusive scrollbar — visible on hover/scroll, not a heavy
     permanent UI element. Falls back silently to default scrollbars in
     browsers that don't support these properties. */
  scrollbar-width: thin;
  scrollbar-color: var(--ml-border-strong) transparent;
}

.ml-sidebar::-webkit-scrollbar {
  width: 8px;
}

.ml-sidebar::-webkit-scrollbar-thumb {
  background-color: var(--ml-border-strong);
  border-radius: var(--ml-radius-pill);
}

.ml-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.ml-main-content {
  min-width: 0; /* prevents grid blowout from long unbreakable content */
  display: flex;
  flex-direction: column;
  gap: var(--ml-space-lg);
  padding-bottom: var(--ml-space-2xl);
}

/* Responsive collapse — below this width, three columns of fixed
   sidebars stop making sense; stack into one column instead. Sidebars
   lose their sticky/scroll-trap behavior here too, since a stacked
   layout has no "beside the content" concept for them to stick within. */
@media (max-width: 992px) {
  .ml-grid {
    grid-template-columns: 1fr;
    padding: 0 var(--ml-space-md);
  }

  .ml-sidebar {
    position: static;
    max-height: none;
    overflow-y: visible;
  }
}

/* Same rules as above, forced on regardless of actual viewport width —
   toggled by the toolbar's "Mobile" preview button (assets/js/toolbar.js),
   so the responsive layout can be inspected on a desktop monitor. */
html[data-force-mobile] .ml-grid {
  grid-template-columns: 1fr;
  /* Ignore any leftover 80%/60% desktop width preset — a real phone has
     no such setting, so forcing it should always go edge-to-edge like
     an actual mobile viewport does, not stay boxed to a percentage of
     the monitor. */
  max-width: none;
  padding: 0 var(--ml-space-md);
}

html[data-force-mobile] .ml-sidebar {
  position: static;
  max-height: none;
  overflow-y: visible;
}
