/* =========================================================
   layout.css — .layout block
   Flat 3-column CSS Grid: sidebar occupies col 1, rows 1–3 (sticky).
   Cards auto-place: rows 1–3 → cols 2–3 (2 per row);
   rows 4+ → cols 1–3 (3 per row, sidebar done).
   Technique: <main class="layout__main"> uses display:contents so
   card elements become direct grid children of .layout.
   ========================================================= */

/* ---------------------------------------------------------
   .layout
   --------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: row;
  align-items: start;
  max-width: 1600px;
  margin: 0 auto;
  background-color: var(--color-bg);
  gap: 1px;
}

.mobile-topbar {
  display: none;
}

/* ---------------------------------------------------------
   .layout__sidebar-slot
   Grid area for first 3 rows of the left column.
   This slot constrains sticky sidebar lifetime to rows 1-3.
   --------------------------------------------------------- */
.layout__sidebar-slot {
  grid-column: 1;
  grid-row: 1 / 4;
  align-self: stretch;
}

/* ---------------------------------------------------------
   .layout__main
   display:contents removes the box from layout so child
   cards (.card) become direct grid children and auto-place
   into the 3-col grid (cols 2–3 for rows 1–3, then 1–3).
   --------------------------------------------------------- */
.layout__main {
  display: contents;
}

/* ---------------------------------------------------------
   Desktop card placement contract (phases 3.5/3.6)
   Rows 1-3: cards only in columns 2 and 3 (6 cards total).
   Row 4+: normal auto-placement in columns 1-3.
   --------------------------------------------------------- */
.layout > .card:nth-of-type(1),
.layout > .card:nth-of-type(3),
.layout > .card:nth-of-type(5) {
  grid-column: 2;
}

.layout > .card:nth-of-type(2),
.layout > .card:nth-of-type(4),
.layout > .card:nth-of-type(6) {
  grid-column: 3;
}

.layout > .card:nth-of-type(n + 7) {
  grid-column: auto;
}

/* ---------------------------------------------------------
   Responsive — tablet (≤ 1200px)
   Narrow sidebar, still 3 cols
   --------------------------------------------------------- */
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: clamp(200px, 25vw, 320px) 1fr 1fr;
  }
}

/* ---------------------------------------------------------
   Responsive — tablet portrait (≤ 900px)
   2 columns: sidebar + 1 painting column
   --------------------------------------------------------- */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: clamp(180px, 35vw, 260px) 1fr;
    gap: 1px;
  }

  .layout > .card {
    grid-column: auto;
  }

  .layout__sidebar-slot {
    grid-column: 1;
    grid-row: 1 / 3;
  }
}

/* ---------------------------------------------------------
   Responsive — mobile nav mode (≤ 809px)
   Top white strip + off-canvas sidebar.
   --------------------------------------------------------- */
@media (max-width: 809px) {
  .layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
  }

  .mobile-topbar {
    grid-column: 1 / -1;
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 2px 16px;
    background-color: var(--color-sidebar-bg);
    border-bottom: 1px solid var(--color-border);
    z-index: calc(var(--z-sidebar) + 2);
  }

  .mobile-topbar__logo-link {
    display: inline-flex;
    align-items: center;
    min-width: 0;
  }

  .mobile-topbar__logo-img {
    display: block;
    width: auto;
    height: 44px;
    max-width: 100%;
    filter: var(--logo-filter);
  }

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

  .mobile-topbar__burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 10px 8px;
  }

  .mobile-topbar__burger-line {
    width: 100%;
    height: 2px;
    background-color: var(--color-text-primary);
    transition: transform var(--transition-base), opacity var(--transition-base);
  }

  .layout__sidebar-slot {
    display: contents;
  }
}

/* ---------------------------------------------------------
   Responsive — mobile (≤ 640px)
   Two columns: at least 2 cards per row
   --------------------------------------------------------- */
@media (max-width: 640px) {
  .layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
  }

  .layout__sidebar-slot {
    grid-column: 1;
    grid-row: 1;
  }
}
