/* Gallery-specific popup layout and media selector. RelatedContent
   composes Unity's Accordion, Card and SoulmaxLink for panel content; those
   components own their styling. RelatedTabs uses Unity's MUI tabs/indicator;
   related.ts drives popup/panel state and media.
   Each page places the popup (see .related-deck in deck.css).

   It has three sizes. At rest it's a small glass pill, "Expand for
   resources". Hovered, tapped or tabbed into, the pill widens into the row
   of tab labels and lights up. Clicked, the same box turns white and grows
   upwards, so the row of labels rides up to become the panel's tab row and
   the panel reveals under it, widening to the panel's 585 across if the
   row of labels is narrower. */

.related {
  /* What 1rem was in the prototype page this sat on: 15px on the deck, 16px on the
     subindustry page. The deck sets --rem (see deck.css). */
  --ease: cubic-bezier(0.65, 0, 0.35, 1);
  --grow: 420ms;
  --widen: 380ms;
  --ink: var(--brand-deep-sea);
  --inset: 25px;
  /* What makes the row the panel's 585 across, set in Solmax — a little
     under the design's 25 a side, which comes out wider than the panel. */
  --tab-pad: 23.5px;
  /* How far up the window it sits. A page placing it differently sets this
     rather than `bottom`, so the panel knows how much room it has above. */
  --related-bottom: clamp(16px, 1.6vw, 30px);

  position: fixed;
  right: clamp(16px, 1.6vw, 30px);
  bottom: var(--related-bottom);
  z-index: 5;
  max-width: calc(100% - 32px);
  pointer-events: auto;
  font-family: inherit;
  font-weight: 300;
  color: var(--ink);
}

.related-functions img:focus-visible {
  outline: 2px solid var(--brand-deep-sea, #112a3f);
  outline-offset: 3px;
  border-radius: 50%;
}

.related-post-date {
  color: #506579;
}

/* What it's on while closed: glass over the deck's near-black, or clear
   white glass over the subindustry page. */
.related-dark {
  --bar-bg: rgba(255, 255, 255, 0.07);
  --bar-line: rgba(255, 255, 255, 0.1);
  --bar-ink: rgba(255, 255, 255, 0.82);
  --bar-hover: #fff;
  --bar-lit-bg: rgba(255, 255, 255, 0.16);
  --bar-lit-line: rgba(255, 255, 255, 0.34);
  --bar-lit-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.related-light {
  --bar-bg: rgba(255, 255, 255, 0.42);
  --bar-line: rgba(255, 255, 255, 0.7);
  --bar-ink: rgba(17, 42, 63, 0.85);
  --bar-hover: var(--brand-deep-sea);
  --bar-lit-bg: rgba(255, 255, 255, 0.82);
  --bar-lit-line: rgba(255, 255, 255, 0.95);
  --bar-lit-shadow: 0 10px 30px rgba(17, 42, 63, 0.2);
}

.related-box {
  overflow: hidden;
  border: 1px solid var(--bar-line);
  border-radius: 33px;
  background: var(--bar-bg);
  color: var(--bar-ink);
  box-shadow: 0 6px 20px rgba(4, 12, 20, 0.08);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  transition:
    background 300ms ease,
    border-color 300ms ease,
    border-radius var(--grow) var(--ease),
    box-shadow var(--grow) ease,
    color 300ms ease,
    transform 300ms ease;
}

/* Widened: under the pointer, tapped open on a touch screen (is-expanded,
   from related.ts), or with a label focused from the keyboard. Keyboard
   focus only — a label keeps focus after a click, and that would hold the
   bar wide once the pointer had gone. Lit up while it is: brighter glass, a
   sharper edge, full-strength labels, lifted a touch off the page. */
.related:not(.is-open):is(:hover, .is-expanded, :has(:focus-visible)) .related-box {
  border-color: var(--bar-lit-line);
  background: var(--bar-lit-bg);
  color: var(--bar-hover);
  box-shadow: var(--bar-lit-shadow);
  transform: translateY(-2px);
}

.related.is-open .related-box {
  border-color: rgba(17, 42, 63, 0.08);
  border-radius: 30px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(4, 12, 20, 0.28);
}

/* The pill and the row side by side, each in a one-column grid run between
   0fr and 1fr: one folds away as the other opens, so the bar's width eases
   from the pill's to the row's rather than jumping. Anchored on the right,
   it grows leftwards. What folds is padding-free (.related-teaser,
   .related-row-clip), with the padding a level in: a box can't be folded
   narrower than its own padding. */
.related-head {
  display: flex;
  justify-content: flex-end;
}

.related-teaser-fold,
.related-row-fold {
  display: grid;
  min-width: 0;
  transition: grid-template-columns var(--widen) var(--ease);
}

.related-teaser-fold {
  grid-template-columns: 1fr;
}

.related-row-fold {
  grid-template-columns: 0fr;
}

.related:is(:hover, .is-expanded, .is-open, :has(:focus-visible)) .related-teaser-fold {
  grid-template-columns: 0fr;
}

.related:is(:hover, .is-expanded, .is-open, :has(:focus-visible)) .related-row-fold {
  grid-template-columns: 1fr;
}

.related-teaser {
  appearance: none;
  min-width: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: none;
  font: inherit;
  font-size: calc(1 * var(--rem, 16px));
  line-height: 1.5;
  color: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity 200ms ease;
}

.related:is(:hover, .is-expanded, .is-open, :has(:focus-visible)) .related-teaser {
  opacity: 0;
}

.related-teaser-short {
  display: none;
}

.related-teaser-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 24px 20px 18px;
}

.related-row-clip {
  min-width: 0;
  overflow: hidden;
}

/* The ⊕, drawn, as on the product rows. */
.related-mark {
  position: relative;
  flex: none;
  width: 22px;
  height: 22px;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: 0.7;
}

.related-mark::before,
.related-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 1px;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.related-mark::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

/* MUI owns tab scrolling, keyboard handling and the moving indicator. The
   row's width and reveal belong here. Expanded, it's as wide as its tabs,
   (--related-row-width, measured in RelatedTabs so it fits each language's
   labels), scrolling only when the viewport is too narrow. Open, it's at
   least the panel's width, 585 across as designed, easing out leftwards as
   the panel grows. */
.related .related-tabs {
  width: max-content;
  min-width: 0;
  max-width: min(var(--related-row-width, 100vw), calc(100vw - 32px));
  opacity: 0;
  transition:
    opacity 200ms ease,
    min-width var(--grow) var(--ease);
}

.related.is-open .related-tabs {
  min-width: min(585px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
}

/* Keep labels at their natural width on phones. Fade only the edges with
   more tabs off-screen; the mask works over either light or dark glass. */
.related .related-tabs .MuiTabs-scroller {
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.related:not(.is-open) .related-tabs .MuiTabs-scroller {
  --fade-left: 0px;
  --fade-right: 0px;
  mask-image: linear-gradient(
    to right,
    transparent,
    #000 var(--fade-left),
    #000 calc(100% - var(--fade-right)),
    transparent
  );
}

.related:not(.is-open) .related-tabs[data-overflow-left="true"] .MuiTabs-scroller {
  --fade-left: 20px;
}

.related:not(.is-open) .related-tabs[data-overflow-right="true"] .MuiTabs-scroller {
  --fade-right: 20px;
}

.related:is(:hover, .is-expanded, .is-open, :has(:focus-visible)) .related-tabs {
  opacity: 1;
  transition-delay: 120ms, 0ms;
}

/* With the bar lit, the label under the pointer is underlined in the labels'
   own colour: white on the deck, navy on the light page, where white would
   vanish into the lit glass. Green is kept for the open panel's tab. Thinner
   than that tab's, one shared underline slides between the hovered labels
   without changing the selected tab or opening a panel. It sits inside the
   scrolling list so it stays aligned when the tabs scroll sideways. */
.related .related-tabs .MuiTabs-flexContainer {
  position: relative;
}

.related .related-tabs .MuiTabs-flexContainer::after {
  content: "";
  position: absolute;
  left: 0;
  width: var(--related-hover-width, 0px);
  bottom: 0;
  height: 4px;
  background: var(--bar-hover);
  opacity: 0;
  transform: translateX(var(--related-hover-x, 0px));
  transition:
    transform 300ms cubic-bezier(0.4, 0, 0.2, 1),
    width 300ms cubic-bezier(0.4, 0, 0.2, 1),
    opacity 200ms ease;
  pointer-events: none;
}

.related:not(.is-open) .related-tabs[data-hovering="true"] .MuiTabs-flexContainer::after {
  opacity: 1;
}

/* The panel's growth: the grid row runs 0fr to 1fr, so it opens to exactly
   the tallest tab's height. The rule along its top is the tab row's
   underline, showing once it's a tab row. Zero wide as far as the box's own
   width goes, then stretched to it: the panels' content (the blog cards' row,
   especially) would otherwise widen the bar to fit it. */
.related-body {
  display: grid;
  grid-template-rows: 0fr;
  width: 0;
  min-width: calc(100% - 2 * var(--inset));
  margin: 0 var(--inset);
  border-top: 1px solid transparent;
  transition:
    grid-template-rows var(--grow) var(--ease),
    border-color 300ms ease;
}

.related.is-open .related-body {
  grid-template-rows: 1fr;
  border-top-color: var(--brand-soft-grey);
}

.related-clip {
  min-height: 0;
  overflow: hidden;
}

/* Every tab's content in the one cell, so the panel is the tallest of them
   whichever is showing, and the tabs don't move under the pointer. Kept clear
   of the nav on a short window, scrolling inside instead: the room is what's
   above the bar, less the tab row (about 66px) and some air under the nav. */
.related-panels {
  display: grid;
  max-height: calc(100dvh - var(--related-bottom) - var(--nav-h) - 66px - 24px);
  padding: var(--inset) 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.related-panel {
  grid-area: 1 / 1;
  min-width: 0;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 220ms ease,
    visibility 0s linear 220ms;
}

.related-panel.is-active {
  opacity: 1;
  visibility: visible;
  transition-delay: 120ms, 0s;
}

.related-panels:has(.related-panel-media) {
  overflow: hidden;
}

/* Application layout; link appearance comes from SoulmaxLink. */
.related-application {
  display: flex;
  align-items: center;
  gap: 25px;
}

.related-functions {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

/* Media: the still in view, and the row to pick it from. */
.related-media-main {
  display: block;
  width: 100%;
  height: 300px;
  object-fit: cover;
}

.related-media-thumbs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-top: 7px;
}

.related-media-thumb {
  appearance: none;
  padding: 0;
  border: 2px solid transparent;
  background: none;
  cursor: pointer;
}

.related-media-thumb[aria-pressed="true"] {
  border-color: var(--brand-deep-sea);
}

.related-media-thumb img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 173 / 97;
  object-fit: cover;
}

/* Blogs: cards running off the panel's edge, scrolled sideways. */
.related-posts {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
}

.related-post {
  flex: none;
  display: block;
  width: 320px;
  color: inherit;
  text-decoration: none;
  scroll-snap-align: start;
}

/* A phone: across the width, the labels scrolling within it. */
@media (max-width: 640px) {
  /* Tapped open, the row runs the width of the screen and scrolls within
     it (capped by .related's max-width). */
  .related {
    --inset: 16px;
    --tab-pad: 16px;
  }

  .related-media-main {
    height: auto;
    aspect-ratio: 535 / 300;
  }

  .related-post {
    width: 260px;
  }

  .related-application {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .related-box,
  .related-body,
  .related-panel,
  .related-teaser-fold,
  .related-row-fold,
  .related-teaser,
  .related-tabs,
  .related-tabs .MuiTabs-flexContainer::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }
}

/* Sub-page server content is an ordinary resources section until enhanced. */
:is(.sub-page, .gallery-deck).is-enhanced .related-static-heading,
:is(.sub-page, .gallery-deck).is-enhanced .related-static-media {
  display: none;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related {
  position: static;
  opacity: 1;
  pointer-events: auto;
  transform: none;
  max-width: 1780px;
  margin: 26px var(--gutter);
  padding: clamp(24px, 4vw, 60px);
  border-radius: var(--card-radius);
  background: white;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-head,
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-media-thumbs {
  display: none;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-box {
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
  color: var(--brand-deep-sea);
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-body,
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-panels {
  display: block;
  width: auto;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: visible;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-panel {
  visibility: visible;
  opacity: 1;
  margin-top: 32px;
  transition: none;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-static-heading {
  margin: 16px 0;
  font-size: 1.5rem;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-posts {
  flex-wrap: wrap;
  overflow: visible;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-post {
  max-width: 100%;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-static-media figure {
  margin: 24px 0;
}
:is(.sub-page, .gallery-deck):not(.is-enhanced) #related .related-static-media img {
  width: 100%;
  height: auto;
}
