/**
 * Layout Utilities
 * ================
 * Container, flexbox, grid, and common layout patterns
 * Built on design tokens from variables.css
 */

/* ─────────────────────────────────────────────────────────────
 * CONTAINERS
 * ───────────────────────────────────────────────────────────── */

.container {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

.container-sm {
  max-width: var(--container-sm);
}

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

.container-lg {
  max-width: var(--container-lg);
}

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

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

/* Fluid container - full width with padding */
.container-fluid {
  width: 100%;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

/* ─────────────────────────────────────────────────────────────
 * FLEXBOX - Base
 * ───────────────────────────────────────────────────────────── */

.flex {
  display: flex;
}

.inline-flex {
  display: inline-flex;
}

.flex-col {
  flex-direction: column;
}

.flex-row {
  flex-direction: row;
}

.flex-row-reverse {
  flex-direction: row-reverse;
}

.flex-col-reverse {
  flex-direction: column-reverse;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-nowrap {
  flex-wrap: nowrap;
}

/* ─────────────────────────────────────────────────────────────
 * FLEXBOX - Alignment
 * ───────────────────────────────────────────────────────────── */

/* Justify content (main axis) */
.justify-start {
  justify-content: flex-start;
}

.justify-end {
  justify-content: flex-end;
}

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

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

.justify-around {
  justify-content: space-around;
}

.justify-evenly {
  justify-content: space-evenly;
}

/* Align items (cross axis) */
.items-start {
  align-items: flex-start;
}

.items-end {
  align-items: flex-end;
}

.items-center {
  align-items: center;
}

.items-baseline {
  align-items: baseline;
}

.items-stretch {
  align-items: stretch;
}

/* Align self */
.self-start {
  align-self: flex-start;
}

.self-end {
  align-self: flex-end;
}

.self-center {
  align-self: center;
}

.self-stretch {
  align-self: stretch;
}

/* ─────────────────────────────────────────────────────────────
 * FLEXBOX - Flex Items
 * ───────────────────────────────────────────────────────────── */

.flex-1 {
  flex: 1 1 0%;
}

.flex-auto {
  flex: 1 1 auto;
}

.flex-initial {
  flex: 0 1 auto;
}

.flex-none {
  flex: none;
}

.flex-grow {
  flex-grow: 1;
}

.flex-grow-0 {
  flex-grow: 0;
}

.flex-shrink {
  flex-shrink: 1;
}

.flex-shrink-0 {
  flex-shrink: 0;
}

/* ─────────────────────────────────────────────────────────────
 * FLEXBOX - Gap
 * ───────────────────────────────────────────────────────────── */

.gap-0 {
  gap: 0;
}

.gap-1 {
  gap: var(--space-1);
}

.gap-2 {
  gap: var(--space-2);
}

.gap-3 {
  gap: var(--space-3);
}

.gap-4 {
  gap: var(--space-4);
}

.gap-5 {
  gap: var(--space-5);
}

.gap-6 {
  gap: var(--space-6);
}

.gap-8 {
  gap: var(--space-8);
}

.gap-10 {
  gap: var(--space-10);
}

.gap-12 {
  gap: var(--space-12);
}

/* Column gap */
.gap-x-1 { column-gap: var(--space-1); }
.gap-x-2 { column-gap: var(--space-2); }
.gap-x-3 { column-gap: var(--space-3); }
.gap-x-4 { column-gap: var(--space-4); }
.gap-x-6 { column-gap: var(--space-6); }
.gap-x-8 { column-gap: var(--space-8); }

/* Row gap */
.gap-y-1 { row-gap: var(--space-1); }
.gap-y-2 { row-gap: var(--space-2); }
.gap-y-3 { row-gap: var(--space-3); }
.gap-y-4 { row-gap: var(--space-4); }
.gap-y-6 { row-gap: var(--space-6); }
.gap-y-8 { row-gap: var(--space-8); }

/* ─────────────────────────────────────────────────────────────
 * GRID - Base
 * ───────────────────────────────────────────────────────────── */

.grid {
  display: grid;
}

.inline-grid {
  display: inline-grid;
}

/* Grid columns */
.grid-cols-1 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid-cols-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.grid-cols-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.grid-cols-12 {
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

/* Auto-fit/auto-fill patterns */
.grid-auto-fit {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.grid-auto-fill {
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

/* Grid rows */
.grid-rows-1 {
  grid-template-rows: repeat(1, minmax(0, 1fr));
}

.grid-rows-2 {
  grid-template-rows: repeat(2, minmax(0, 1fr));
}

.grid-rows-3 {
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

/* ─────────────────────────────────────────────────────────────
 * GRID - Span
 * ───────────────────────────────────────────────────────────── */

.col-span-1 { grid-column: span 1 / span 1; }
.col-span-2 { grid-column: span 2 / span 2; }
.col-span-3 { grid-column: span 3 / span 3; }
.col-span-4 { grid-column: span 4 / span 4; }
.col-span-6 { grid-column: span 6 / span 6; }
.col-span-full { grid-column: 1 / -1; }

.row-span-1 { grid-row: span 1 / span 1; }
.row-span-2 { grid-row: span 2 / span 2; }
.row-span-3 { grid-row: span 3 / span 3; }
.row-span-full { grid-row: 1 / -1; }

/* ─────────────────────────────────────────────────────────────
 * GRID - Alignment
 * ───────────────────────────────────────────────────────────── */

.place-items-center {
  place-items: center;
}

.place-items-start {
  place-items: start;
}

.place-items-end {
  place-items: end;
}

.place-content-center {
  place-content: center;
}

.place-content-between {
  place-content: space-between;
}

/* ─────────────────────────────────────────────────────────────
 * COMMON LAYOUT PATTERNS
 * ───────────────────────────────────────────────────────────── */

/* Center content horizontally and vertically */
.center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Stack children vertically with gap */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack-sm {
  gap: var(--space-2);
}

.stack-lg {
  gap: var(--space-6);
}

/* Cluster - horizontal items that wrap */
.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

/* Sidebar layout - sidebar + main content */
.with-sidebar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
}

.with-sidebar > :first-child {
  flex-basis: 250px;
  flex-grow: 1;
}

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

/* Split - two equal columns */
.split {
  display: flex;
  gap: var(--space-4);
}

.split > * {
  flex: 1;
}

/* Holy grail layout - header, sidebar, main, sidebar, footer */
.holy-grail {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

/* ─────────────────────────────────────────────────────────────
 * ASPECT RATIOS
 * ───────────────────────────────────────────────────────────── */

.aspect-square {
  aspect-ratio: 1 / 1;
}

.aspect-video {
  aspect-ratio: 16 / 9;
}

.aspect-portrait {
  aspect-ratio: 3 / 4;
}

.aspect-landscape {
  aspect-ratio: 4 / 3;
}

/* ─────────────────────────────────────────────────────────────
 * RESPONSIVE GRID (Mobile-first)
 * ───────────────────────────────────────────────────────────── */

/* Small screens and up (640px) */
@media (min-width: 640px) {
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sm\:flex-row { flex-direction: row; }
}

/* Medium screens and up (768px) */
@media (min-width: 768px) {
  .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .md\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .md\:flex-row { flex-direction: row; }
}

/* Large screens and up (1024px) */
@media (min-width: 1024px) {
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lg\:grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .lg\:grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* Extra large screens (1280px) */
@media (min-width: 1280px) {
  .xl\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .xl\:grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .xl\:grid-cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* ─────────────────────────────────────────────────────────────
 * GALLERY GRID
 * Responsive grid for painting cards with auto-fit sizing
 * ───────────────────────────────────────────────────────────── */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
  width: 100%;
}

/* Larger minimum size on wider screens */
@media (min-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-5);
  }
}

@media (min-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: var(--space-6);
  }
}

@media (min-width: 1280px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }
}

/* ─────────────────────────────────────────────────────────────
 * GALLERY WITH PANEL
 * Gallery grid + side panel layout for Summary/Overlaps
 * ───────────────────────────────────────────────────────────── */

.gallery-with-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.gallery-with-panel .gallery-grid {
  flex: 1;
  min-width: 0;
}

.family-panel {
  background: var(--color-surface);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  min-width: 0;
  max-height: 600px;
  overflow-y: auto;
}

/* Desktop: Side-by-side layout */
@media (min-width: 1280px) {
  .gallery-with-panel {
    flex-direction: row;
  }

  .gallery-with-panel .gallery-grid {
    flex: 1;
  }

  .family-panel {
    flex: 0 0 450px;
    position: sticky;
    top: var(--space-4);
    max-height: calc(100vh - var(--space-8));
  }
}

/* Wide screens: Larger panel */
@media (min-width: 1536px) {
  .family-panel {
    flex: 0 0 520px;
  }
}

/* ─────────────────────────────────────────────────────────────
 * TOP SECTION - 2 COLUMN LAYOUT
 * Filters (40% LEFT) | Tabs + Content (60% RIGHT)
 * When Draft tab selected, expands to 100% width
 * ───────────────────────────────────────────────────────────── */

.top-section {
  display: flex;
  gap: var(--space-6);
  padding: var(--space-4) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--gray-200);
  min-height: 300px;
}

/* LEFT: Filters Column (40%) */
.filters-column {
  flex: 0 0 40%;
  min-width: 280px;
  max-width: 400px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  overflow: hidden;
  transition: opacity 150ms ease-out,
              flex 250ms ease-out,
              min-width 250ms ease-out,
              max-width 250ms ease-out,
              padding 250ms ease-out;
}

.filters-column__title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--gray-800);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--gray-200);
}

/* RIGHT: Content Column (60%) - Tabs + Panel */
.content-column {
  flex: 1 1 60%;
  min-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: flex 250ms ease-out,
              min-width 250ms ease-out;
}

/* Family panel inside content column - no extra border */
.content-column .family-panel {
  border: none;
  border-radius: 0;
  max-height: none;
}

/* ─────────────────────────────────────────────────────────────
 * DRAFT MODE - Full Width Expansion
 * When Draft tab is selected, filters hide and content expands
 * ───────────────────────────────────────────────────────────── */

.top-section.draft-mode .filters-column {
  opacity: 0;
  flex: 0 0 0;
  min-width: 0;
  max-width: 0;
  padding: 0;
  border-width: 0;
  pointer-events: none;
}

.top-section.draft-mode .content-column {
  flex: 1 1 100%;
  min-width: 100%;
}

/* ─────────────────────────────────────────────────────────────
 * GALLERY SECTION - Full Width Below Top Section
 * Always visible, never moves side-by-side
 * ───────────────────────────────────────────────────────────── */

.gallery-section {
  padding: var(--space-6);
  background: var(--color-background);
}

/* ─────────────────────────────────────────────────────────────
 * RESPONSIVE - Top Section
 * ───────────────────────────────────────────────────────────── */

/* Tablet: Narrower columns */
@media (max-width: 1024px) {
  .top-section {
    gap: var(--space-4);
    padding: var(--space-4);
  }

  .filters-column {
    flex: 0 0 35%;
    min-width: 240px;
    max-width: 320px;
  }

  .content-column {
    min-width: 320px;
  }
}

/* Mobile: Stack vertically */
@media (max-width: 768px) {
  .top-section {
    flex-direction: column;
    min-height: auto;
  }

  .filters-column {
    flex: none;
    width: 100%;
    min-width: auto;
    max-width: none;
  }

  .content-column {
    flex: none;
    width: 100%;
    min-width: auto;
  }

  /* In draft mode on mobile, still hide filters */
  .top-section.draft-mode .filters-column {
    display: none;
  }
}
