/* © 2026 MEK.txt. All rights reserved. Part of the MEK design system; not licensed for reuse. */
/* MEK design system · part: collapsible sidebar
   A page's side column that hides and shows (the art library's filters, mektxt.com/works' list): .sidebar-layout of
   a .sidebar-toggle, an aside.sidebar and a .sidebar-main. One toggle (the panel-left icon, an icon-only .link) sits at
   the page's edge on the first row's centre line, sticky as the sidebar is: it never moves or fades, only its name
   changes (js/sidebar.js). Hidden (.shut), the sidebar's column narrows to a strip as wide as the toggle, so the
   toggle never covers the content, and the sidebar fades out under the main as it widens over it: the glide
   (--dur-glide, --ease-glide), the one smooth curve, for layout that moves. Only once the page has drawn (.ready),
   so a remembered hidden sidebar doesn't glide in on load. On a phone (--bp-tablet and under) the columns stack, the
   toggle goes, and the page's own button opens the sidebar over the content ([data-sidebar-open], .open).
   .end puts the sidebar at the page's far right (the panel-right icon), its toggle fixed at the right edge.
   Opt-in: link it after mek.css, with js/sidebar.js. In the mek.parts layer, so a project's CSS wins. */

@layer mek.parts {

/* ---------- Dials ----------
   On the .sidebar-layout. --sidebar-row is the main column's first row's height (a search row with a switch: 50px),
   so the toggle and the sidebar's head (.sidebar-head) share its centre line; --sidebar-top is what's stuck above
   (a sticky top bar's height). */
.sidebar-layout {
  --sidebar-w: 288px;                          /* the sidebar's width, kept while its column closes: nothing in it reflows */
  --sidebar-gap: var(--space-8);               /* between the sidebar and the main */
  --sidebar-strip-gap: var(--space-6);         /* between the toggle and what follows it: the head's words, or, hidden, the main */
  --sidebar-toggle: var(--icon-text, 22.5px);  /* the toggle's width, and the strip's */
  --sidebar-top: 0px;
  --sidebar-pad: var(--space-6);               /* over the sidebar's head and the main's first row */
  --sidebar-row: 50px;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); column-gap: var(--sidebar-gap); overflow-x: clip;
}
.sidebar-layout.ready { transition: grid-template-columns var(--dur-glide) var(--ease-glide), column-gap var(--dur-glide) var(--ease-glide); }
.sidebar-layout.shut { grid-template-columns: var(--sidebar-toggle) minmax(0, 1fr); column-gap: var(--sidebar-strip-gap); }

/* The toggle: over the sidebar's first column, on the first row's centre line, above both columns. */
.sidebar-layout > .sidebar-toggle { grid-area: 1 / 1; justify-self: start; align-self: start; z-index: 2; position: sticky;
  top: calc(var(--sidebar-top) + var(--sidebar-pad) + var(--sidebar-row) / 2);
  margin-top: calc(var(--sidebar-pad) + var(--sidebar-row) / 2); translate: 0 -50%; }

/* The sidebar: its own width whatever its column's, sticky under what's stuck above, scrolling on its own. Its
   display is the part's (it hides on a phone): a sidebar that's a grid or a flex box says so in --sidebar-display. */
.sidebar-layout > .sidebar { display: var(--sidebar-display, block); grid-area: 1 / 1; box-sizing: border-box; width: var(--sidebar-w); align-self: start;
  position: sticky; top: var(--sidebar-top); max-height: calc(100dvh - var(--sidebar-top)); overflow-y: auto; scrollbar-gutter: stable;
  padding-top: var(--sidebar-pad); }
.sidebar-layout .sidebar-head { display: flex; align-items: center; gap: var(--sidebar-strip-gap); min-height: var(--sidebar-row);
  padding-left: calc(var(--sidebar-toggle) + var(--sidebar-strip-gap)); }   /* (the toggle's room: it sits over this) */
/* Hidden: faded, and hidden once it's out, so nothing in it takes focus; shown at once coming back. */
.sidebar-layout.ready > .sidebar { transition: opacity var(--dur-glide) var(--ease-glide), visibility 0s; }
.sidebar-layout.shut > .sidebar { opacity: 0; visibility: hidden; }
.sidebar-layout.ready.shut > .sidebar { transition: opacity var(--dur-glide) var(--ease-glide), visibility 0s var(--dur-glide); }

/* The main: over the sidebar while its column closes. */
.sidebar-layout > .sidebar-main { grid-area: 1 / 2; position: relative; z-index: 1; background: var(--bg); min-width: 0;
  padding-top: var(--sidebar-pad); }

/* ---------- .end: the sidebar at the right ----------
   The main takes the room, the sidebar the right edge; the toggle sits at the far right, held in by the sidebar's
   scrollbar room (--sidebar-bar, the scrollbar's 6px) so the bar never runs under it, and never moves. Hidden, the
   column narrows to the toggle's strip and the sidebar, held at its column's start and moved on by the strip's
   width, slides out to the right under the layout's clip: no fade, it moves away, then it's hidden. Shown, it slides
   back in from the right on the glide. The head keeps the toggle's room on its right. Over 900px only: the phone's
   stack is the same either way. */
@media (min-width: 901px) {   /* over --bp-tablet */
  .sidebar-layout.end { grid-template-columns: minmax(0, 1fr) var(--sidebar-w); }
  .sidebar-layout.end.shut { grid-template-columns: minmax(0, 1fr) var(--sidebar-toggle); }
  .sidebar-layout.end > .sidebar-main { grid-area: 1 / 1; }
  .sidebar-layout.end > .sidebar, .sidebar-layout.end > .sidebar-toggle { grid-area: 1 / 2; }
  .sidebar-layout.end { --sidebar-bar: 6px; }   /* the sidebar's scrollbar room (css/scrollbar.css) */
  .sidebar-layout.end > .sidebar-toggle { justify-self: end; margin-right: var(--sidebar-bar); }
  .sidebar-layout.end.shut > .sidebar { opacity: 1; translate: var(--sidebar-toggle) 0; }
  .sidebar-layout.end.ready > .sidebar { transition: translate var(--dur-glide) var(--ease-glide), visibility 0s; }
  .sidebar-layout.end.ready.shut > .sidebar { transition: translate var(--dur-glide) var(--ease-glide), visibility 0s var(--dur-glide); }
  .sidebar-layout.end .sidebar-head { padding-left: 0; padding-right: calc(var(--sidebar-toggle) + var(--sidebar-strip-gap)); }
}
@media (min-width: 901px) and (prefers-reduced-motion: reduce) { .sidebar-layout.end.ready > .sidebar { transition: none; } }

@media (prefers-reduced-motion: reduce) { .sidebar-layout.ready, .sidebar-layout.ready > .sidebar { transition: none; } }

/* ---------- Phone and tablet: stacked; the page's own button opens the sidebar (.open) ---------- */
@media (max-width: 900px) {   /* --bp-tablet */
  .sidebar-layout, .sidebar-layout.shut { grid-template-columns: minmax(0, 1fr); column-gap: 0; transition: none; }
  .sidebar-layout > .sidebar-toggle { display: none; }
  .sidebar-layout > .sidebar, .sidebar-layout.shut > .sidebar { grid-area: auto; display: none; width: auto; position: static; max-height: none;
    opacity: 1; visibility: visible; transition: none; }
  .sidebar-layout.open > .sidebar { display: var(--sidebar-display, block); }
  .sidebar-layout > .sidebar-main { grid-area: auto; }
  .sidebar-layout .sidebar-head { padding-left: 0; }
}

}
