/**
 * Bengal SSG - Layout Compositions
 * Following CUBE CSS methodology
 *
 * These are structural compositions that define relationships
 * between elements. They should be layout-agnostic and reusable.
 */

/* ============================================
   THREE-COLUMN DOCUMENTATION LAYOUT
   ============================================ */

/**
 * Main documentation layout with sidebar navigation,
 * content area, and table of contents.
 *
 * Usage:
 * <div class="docs-layout">
 *   <aside class="docs-sidebar">...</aside>
 *   <main class="docs-main">...</main>
 *   <aside class="docs-toc">...</aside>
 * </div>
 */

.docs-layout {
  display: grid;
  grid-template-columns:
    [sidebar-start] minmax(240px, 280px)
    [content-start] minmax(0, 1fr)
    [toc-start] minmax(200px, 260px)
    [end];
  gap: 2rem;
  max-width: 1600px;
  margin: 0 auto;
  padding: 2rem 0;
  align-items: start;
}

/* Remove container constraints for docs layout */
.container > .docs-layout {
  max-width: 100%;
  margin: 0;
  padding: 2rem;
}

/* Left Sidebar (Navigation) */
.docs-sidebar {
  grid-column: sidebar-start / content-start;
  position: sticky;
  top: 80px; /* Account for fixed header */
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 1rem;
}

/* Main Content */
.docs-main {
  grid-column: content-start / toc-start;
  min-width: 0; /* Prevent grid blowout */
  /* max-width removed - let grid control width */
}

/* Right Sidebar (TOC) */
.docs-toc {
  grid-column: toc-start / end;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-left: 1rem;
}

/* ============================================
   RESPONSIVE: TABLET (Hide TOC)
   ============================================ */

@media (max-width: 1024px) {
  .docs-layout {
    grid-template-columns:
      [sidebar-start] minmax(240px, 260px)
      [content-start] minmax(0, 1fr)
      [end];
    gap: 2rem;
  }

  .docs-main {
    grid-column: content-start / end;
  }

  .docs-toc {
    display: none;
  }
}

/* ============================================
   RESPONSIVE: MOBILE (Sidebar Becomes Drawer)
   ============================================ */

@media (max-width: 768px) {
  .docs-layout {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 1rem;
  }

  .docs-main {
    grid-column: 1;
  }

  .docs-sidebar {
    /* Convert to mobile drawer */
    position: fixed;
    top: 60px; /* Mobile header height */
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    max-height: calc(100vh - 60px);
    padding: 1rem;
    background: var(--color-bg-primary);
    border-right: 1px solid var(--color-border);
    box-shadow: var(--elevation-high);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    z-index: var(--z-sticky);
    overflow-y: auto;
  }

  .docs-sidebar[data-open] {
    transform: translateX(0);
  }

  .docs-toc {
    display: none;
  }
}

/* ============================================
   SIDEBAR OVERLAY (Mobile)
   ============================================ */

.docs-sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-bg-overlay);
  z-index: calc(var(--z-sticky) - 1);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.docs-sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

@media (min-width: 769px) {
  .docs-sidebar-overlay {
    display: none !important;
  }
}

/* ============================================
   MOBILE SIDEBAR TOGGLE BUTTON
   ============================================ */

.docs-sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 2rem;
  left: 1rem;
  width: 48px;
  height: 48px;
  padding: 0;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border: none;
  border-radius: var(--radius-full);
  box-shadow: var(--elevation-high);
  cursor: pointer;
  z-index: var(--z-fixed);
  transition: all var(--transition-fast);
}

.docs-sidebar-toggle:hover {
  background: var(--color-primary-hover);
  transform: scale(1.05);
}

.docs-sidebar-toggle:active {
  transform: scale(0.95);
}

.docs-sidebar-toggle svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

@media (max-width: 768px) {
  .docs-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ============================================
   SCROLLBAR STYLING (Sidebars)
   ============================================ */

.docs-sidebar::-webkit-scrollbar,
.docs-toc::-webkit-scrollbar {
  width: 6px;
}

.docs-sidebar::-webkit-scrollbar-track,
.docs-toc::-webkit-scrollbar-track {
  background: transparent;
}

.docs-sidebar::-webkit-scrollbar-thumb,
.docs-toc::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

.docs-sidebar::-webkit-scrollbar-thumb:hover,
.docs-toc::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-tertiary);
}

/* ============================================
   STACK LAYOUT (Vertical Flow)
   ============================================ */

/**
 * Simple vertical stack with consistent gap
 *
 * Usage:
 * <div class="stack">
 *   <div>Item 1</div>
 *   <div>Item 2</div>
 * </div>
 */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap, var(--space-component-gap));
}

.stack-small {
  --stack-gap: var(--size-2);
}

.stack-large {
  --stack-gap: var(--space-section-gap);
}

/* ============================================
   CLUSTER LAYOUT (Horizontal Flow)
   ============================================ */

/**
 * Horizontal layout with wrapping
 *
 * Usage:
 * <div class="cluster">
 *   <button>Action 1</button>
 *   <button>Action 2</button>
 * </div>
 */

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cluster-gap, var(--space-component-gap));
  align-items: var(--cluster-align, center);
  justify-content: var(--cluster-justify, flex-start);
}

.cluster-small {
  --cluster-gap: var(--size-2);
}

.cluster-large {
  --cluster-gap: var(--space-section-gap);
}

.cluster-center {
  --cluster-justify: center;
}

.cluster-between {
  --cluster-justify: space-between;
}

/* ============================================
   GRID LAYOUT (Auto-Fit Grid)
   ============================================ */

/**
 * Responsive grid that auto-fits items
 *
 * Usage:
 * <div class="grid">
 *   <div class="card">...</div>
 *   <div class="card">...</div>
 * </div>
 */

.grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(var(--grid-min, 280px), 1fr)
  );
  gap: var(--grid-gap, var(--space-component-gap));
}

.grid-2 {
  --grid-min: calc(50% - var(--grid-gap) / 2);
}

.grid-3 {
  --grid-min: calc(33.333% - var(--grid-gap) * 2 / 3);
}

.grid-4 {
  --grid-min: calc(25% - var(--grid-gap) * 3 / 4);
}

/* ============================================
   CENTER LAYOUT (Max-Width Container)
   ============================================ */

/**
 * Center content with max-width
 *
 * Usage:
 * <div class="center">
 *   <article>...</article>
 * </div>
 */

.center {
  box-sizing: content-box;
  max-width: var(--center-max-width, var(--container-xl));
  margin-inline: auto;
  padding-inline: var(--center-padding, var(--space-content-padding));
}

.center-narrow {
  --center-max-width: var(--container-md);
}

.center-wide {
  --center-max-width: var(--container-2xl);
}

/* ============================================
   SIDEBAR LAYOUT (Asymmetric)
   ============================================ */

/**
 * Sidebar layout with flexible content
 *
 * Usage:
 * <div class="with-sidebar">
 *   <aside>Sidebar</aside>
 *   <main>Content</main>
 * </div>
 */

.with-sidebar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sidebar-gap, var(--space-section-gap));
}

.with-sidebar > * {
  flex-grow: 1;
}

.with-sidebar > :first-child {
  flex-basis: var(--sidebar-width, 300px);
  flex-grow: 0;
}

.with-sidebar > :last-child {
  flex-basis: 0;
  flex-grow: 999;
  min-width: 50%;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  .docs-layout {
    display: block;
  }

  .docs-sidebar,
  .docs-toc,
  .docs-sidebar-toggle {
    display: none !important;
  }

  .docs-main {
    max-width: 100%;
  }
}
