/* Layout and arrows for the samsar-circular-economy-flow pattern.
   See spec: docs/superpowers/specs/2026-05-20-circular-economy-flow-design.md

   Arrows are rendered entirely as CSS pseudo-elements with inline-SVG
   data-URL backgrounds so the same arrows appear in both the block editor
   and the frontend, with no SVG/HTML blocks in the pattern markup. */

/* ===== Diagram container ===== */

.samsar-flow__diagram {
  display: grid;
  grid-template-columns: 1fr;
  gap: 30px;
  max-width: var(--wp--style--global--wide-size, 1260px);
  margin-left: auto;
  margin-right: auto;
}

.samsar-flow__card {
  position: relative;
  width: 100%;
  /* WP's is-layout-flex sets flex-wrap: wrap, which causes overflowing
     content (e.g., the Recycle card's long eyebrow wrapping to 2 lines at
     narrower breakpoints) to spill into a second visual column to the right
     of the card. Force nowrap so items stay stacked vertically. */
  flex-wrap: nowrap !important;
}

/* The wp:group flex-vertical layout sizes children to their content,
   so short text (e.g., locations) sits in a narrow box and `has-text-align-center`
   centers within that narrow box instead of the card. Stretch all direct
   block children to full card width, except the eyebrow badges which
   intentionally have `width: fit-content` to render as pills. */
.samsar-flow__card > .wp-block-heading,
.samsar-flow__card > p:not(.is-style-eyebrow) {
  width: 100%;
}

/* Section divider inside cards with multiple body+location groups (e.g., card 2).
   Each location except the last gets a thin line below it. */
.samsar-flow__card .samsar-flow__location:not(:last-of-type) {
  border-bottom: 1px solid var(--wp--preset--color--border-dark, #2d3345);
  padding-bottom: 20px;
}

/* ===== Inner arrows (mobile-first) =====
   Each card 1..5 gets a down-pointing chevron below it via ::after.
   Card 1 also gets a loop-back chevron above it via ::before (the 6→1 indicator). */

.samsar-flow__card--step-1::before,
.samsar-flow__card--step-1::after,
.samsar-flow__card--step-2::after,
.samsar-flow__card--step-3::after,
.samsar-flow__card--step-4::after,
.samsar-flow__card--step-5::after {
  content: '';
  position: absolute;
  left: 50%;
  width: 24px;
  height: 30px;
  transform: translateX(-50%);
  background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 30' preserveAspectRatio='none'><defs><linearGradient id='g' x1='0' x2='1' y1='0' y2='0'><stop offset='0.0374' stop-color='%2359edcd'/><stop offset='0.5067' stop-color='%233a72ff'/></linearGradient></defs><path d='M12 0 V22 M5 18 L12 25 L19 18' stroke='url(%23g)' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>") no-repeat center / contain;
  pointer-events: none;
}

.samsar-flow__card--step-1::before { top: -30px; }

.samsar-flow__card--step-1::after,
.samsar-flow__card--step-2::after,
.samsar-flow__card--step-3::after,
.samsar-flow__card--step-4::after,
.samsar-flow__card--step-5::after { bottom: -30px; }

/* ===== Mobile right-column wrapper =====
   The wrapper just stacks its cards with the same 30px gap as the outer grid. */
.samsar-flow__col--right {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

/* ===== Mobile loop-back arrow =====
   Wraps from card 6 (bottom of flow) around the right side back to card 1
   (top of flow). Built from 3 pieces so the corners and arrowhead stay at
   FIXED pixel sizes while the connecting lines stretch with the diagram:
     - Top piece (stage::before):    chevron+stem+top-left curve | line | top-right curve
     - Bottom piece (stage::after):  exit-from-card-6+curve      | line | bottom-right curve
     - Vertical line (diagram::after): stretchy line on the right edge
   Wrapped in a max-width media query so it doesn't apply on desktop. */

@media (max-width: 767px) {
  .samsar-flow__stage {
    position: relative;
    padding: 60px 60px;
  }

  .samsar-flow__diagram {
    position: relative;
  }

  /* Hide the simple loop-back chevron above card 1 — replaced by the
     chevron drawn inside the top piece of the loop. */
  .samsar-flow__card--step-1::before {
    display: none;
  }

  /* TOP piece. Spans from the cards' centerline (where the chevron sits)
     to the vertical line position (30px from stage right). Backgrounds:
       1. Top-left piece (30×60): chevron (14×7 — matches other down arrows)
          + stem + top-left curve, anchored LEFT
       2. Top-right curve (30×60): top-right curve + vertical line extending
          down to bottom of stage::before so it meets the vertical line below.
          Anchored RIGHT.
       3. Horizontal line: stretchy 2px gradient at y=0..2 (matches SVG
          horizontal stroke centered at y=1) between the two SVG pieces. */
  .samsar-flow__stage::before {
    content: '';
    position: absolute;
    top: 0;
    left: calc(50% - 18px);
    right: 30px;
    height: 60px;
    background:
      url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 60' overflow='visible' fill='none' stroke='%2359edcd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M30 1 H24 A6 6 0 0 0 18 7 V47 M11 43 L18 50 L25 43'/></svg>") left top / 30px 60px no-repeat,
      url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 60' overflow='visible' fill='none' stroke='%233a72ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M0 1 H23 A6 6 0 0 1 29 7 V60'/></svg>") right top / 30px 60px no-repeat,
      linear-gradient(to right, #59edcd, #3a72ff) 30px 0 / calc(100% - 60px) 2px no-repeat;
    pointer-events: none;
  }

  /* BOTTOM piece. Mirrors the top:
       1. Bottom-left piece (30×60): vertical stub from card 6 + bottom-left
          curve. Horizontal stroke centered at y=59 (so the 2px stroke fits
          inside the SVG instead of clipping past y=60). Anchored LEFT.
       2. Bottom-right curve (30×60): bottom-right curve + vertical line
          extending UP to top of stage::after so it meets the vertical line
          above. Horizontal stroke at y=59. Anchored RIGHT.
       3. Horizontal line: gradient at the bottom 2px of stage::after,
          centered at y=59 to match the SVGs' horizontal strokes. */
  .samsar-flow__stage::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: calc(50% - 18px);
    right: 30px;
    height: 60px;
    background:
      url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 60' overflow='visible' fill='none' stroke='%2359edcd' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M18 0 V53 A6 6 0 0 0 24 59 H30'/></svg>") left bottom / 30px 60px no-repeat,
      url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 60' overflow='visible' fill='none' stroke='%233a72ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M0 59 H23 A6 6 0 0 0 29 53 V0'/></svg>") right bottom / 30px 60px no-repeat,
      linear-gradient(to right, #59edcd, #3a72ff) left 30px bottom 0 / calc(100% - 60px) 2px no-repeat;
    pointer-events: none;
  }

  /* VERTICAL line. Spans from the top piece's bottom (= top of diagram)
     to the bottom piece's top (= bottom of diagram), sitting 30px outside
     the diagram's right edge so it aligns with the loop's vertical track. */
  .samsar-flow__diagram::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    right: -30px;
    width: 2px;
    background: linear-gradient(to bottom, #59edcd, #3a72ff);
    pointer-events: none;
  }
}

/* ===== Desktop: 2-col zigzag with equal-height right-col cards ===== */

@media (min-width: 768px) {
  .samsar-flow__stage {
    position: relative;
    padding: 80px 0;  /* reserve room for the top/bottom U-wraps */
  }

  .samsar-flow__diagram {
    display: grid !important;
    position: relative;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 30px auto;
    column-gap: 80px;
    row-gap: 0;
  }

  /* Override WP flow-layout block-start margins inside the grid and the
     right-column flex wrapper. */
  .samsar-flow__diagram > *,
  .samsar-flow__col--right > * {
    margin-block-start: 0 !important;
  }

  /* Left column: card 1 in row 1, card 2 in row 3 (with the 30px gap as row 2).
     Cards stretch to fill their rows so they have consistent top/bottom edges. */
  .samsar-flow__card--step-1 { grid-column: 1; grid-row: 1; align-self: stretch; }
  .samsar-flow__card--step-2 { grid-column: 1; grid-row: 3; align-self: stretch; }

  /* Right column wrapper spans the full grid height. Flex column-reverse so
     DOM order 3,4,5,6 displays visually as 6,5,4,3 (top → bottom in the right
     column, matching the flow's reverse direction on this side).
     `flex: 1` on each card divides the wrapper height into 4 equal parts;
     `gap: 30px` between them matches the row gap on the left side. */
  .samsar-flow__col--right {
    grid-column: 2;
    grid-row: 1 / -1;
    flex-direction: column-reverse;
  }

  .samsar-flow__col--right .samsar-flow__card {
    flex: 1;
    min-height: 0;
  }

  /* Vertical-center the card content so it sits in the middle of each
     equal-height card. */
  .samsar-flow__card {
    justify-content: center;
  }

  /* On desktop, the mobile loop-back above card 1 is replaced by the
     stage::before U-wrap, and the down arrow below card 2 is replaced
     by the stage::after U-wrap. Hide them here. */
  .samsar-flow__card--step-1::before,
  .samsar-flow__card--step-2::after { display: none; }

  /* Right column: arrows go UP from each card to the card visually above it.
     Hide the mobile ::after (which would sit below) and render ::before
     (above the card, rotated 180° to point up). */
  .samsar-flow__card--step-3::after,
  .samsar-flow__card--step-4::after,
  .samsar-flow__card--step-5::after { display: none; }

  .samsar-flow__card--step-3::before,
  .samsar-flow__card--step-4::before,
  .samsar-flow__card--step-5::before {
    content: '';
    position: absolute;
    top: -30px;
    left: 50%;
    width: 24px;
    height: 30px;
    transform: translateX(-50%) rotate(180deg);
    background: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 30' preserveAspectRatio='none'><defs><linearGradient id='g' x1='0' x2='1' y1='0' y2='0'><stop offset='0.0374' stop-color='%2359edcd'/><stop offset='0.5067' stop-color='%233a72ff'/></linearGradient></defs><path d='M12 0 V22 M5 18 L12 25 L19 18' stroke='url(%23g)' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>") no-repeat center / contain;
    pointer-events: none;
  }

  /* ===== U-wraps as stage pseudo-elements =====
     SVG path x-coords (295, 965) are calibrated for the 1260px wide-size
     with 1fr 1fr columns and 80px column-gap. Changing column-gap or
     diagram max-width without updating the path data will misalign the
     U-wrap endpoints with the card column centers. */

  .samsar-flow__stage::before,
  .samsar-flow__stage::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 80px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 100% 100%;
    pointer-events: none;
  }

  .samsar-flow__stage::before {
    top: 0;
    background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1260 80' preserveAspectRatio='none'><defs><linearGradient id='g' x1='0' x2='1' y1='0' y2='0'><stop offset='0.0374' stop-color='%2359edcd'/><stop offset='0.5067' stop-color='%233a72ff'/></linearGradient></defs><path d='M965 80 V30 A30 30 0 0 0 935 0 H325 A30 30 0 0 0 295 30 V60 M288 56 L295 63 L302 56' stroke='url(%23g)' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  }

  .samsar-flow__stage::after {
    bottom: 0;
    background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1260 80' preserveAspectRatio='none'><defs><linearGradient id='g' x1='0' x2='1' y1='0' y2='0'><stop offset='0.0374' stop-color='%2359edcd'/><stop offset='0.5067' stop-color='%233a72ff'/></linearGradient></defs><path d='M295 0 V50 A30 30 0 0 0 325 80 H935 A30 30 0 0 0 965 50 V20 M958 24 L965 17 L972 24' stroke='url(%23g)' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  }
}
