/**
 * Course page components (.ce-*), plus layout refinements for course pages
 * that use them. Built on the theme's brand tokens only (theme.css :root).
 */

/* ---------- Shared ---------- */
.ce-section {
  --ce-gap: clamp(16px, 2vw, 30px);
  --ce-accent: var(--colour-orange-500, #FD5108);
  --ce-ink: var(--colour-near-black, #333);
  --ce-tint: var(--colour-grey-100, #EEEFF1);
  --ce-line: var(--colour-grey-300, #CBD1D6);
}
.ce-section h2 {
  margin-top: 0;
}
.ce-section h3 {
  margin: 0 0 0.5em;
  font-size: var(--font-size-h4);
  line-height: var(--line-height-h3);
}
.ce-section p:last-child {
  margin-bottom: 0;
}
.ce-lead {
  max-width: var(--text-max-width);
  font-size: 1.1em;
  margin-bottom: 1.6em;
}
.ce-grid {
  display: grid;
  gap: var(--ce-gap);
  margin: 0;
  padding: 0;
  list-style: none;
}
.ce-grid > li {
  margin: 0;
}
.ce-card {
  position: relative;
  padding: 1.6em 1.5em 1.5em;
  background: white;
  border-top: 4px solid var(--ce-accent);
  box-sizing: border-box;
}
.ce-badge {
  display: inline-block;
  margin-top: 0.4em;
  padding: 0.35em 0.8em;
  background: var(--ce-ink);
  color: white;
  font-size: 0.9em;
  font-weight: 600;
}
.ce-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-top: auto;
  padding-top: 1.2em;
  color: var(--ce-accent);
  font-weight: 600;
  text-decoration: none;
}
.ce-link::after {
  content: "";
  width: 0.45em;
  height: 0.45em;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--transition-duration-regular, 0.4s);
}
.ce-link:is(:hover, :focus-visible) {
  text-decoration: underline;
}
.ce-link:is(:hover, :focus-visible)::after {
  transform: translateX(3px) rotate(45deg);
}

@media (min-width: 700px) {
  .ce-grid--3 {
    grid-template-columns: repeat(3, 1fr);
  }
  .ce-grid--outcomes,
  .ce-grid--reasons {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 1000px) {
  /* Five cards: three on top, two centred below. */
  .ce-grid--outcomes,
  .ce-grid--reasons {
    grid-template-columns: repeat(6, 1fr);
  }
  .ce-grid--outcomes > li,
  .ce-grid--reasons > li {
    grid-column: span 2;
  }
  .ce-grid--outcomes > li:nth-child(4):nth-last-child(2),
  .ce-grid--reasons > li:nth-child(4):nth-last-child(2) {
    grid-column: 2 / span 2;
  }
}

/* ---------- Section rhythm inside "further info" ---------- */
.ce-outcomes,
.ce-audience,
.ce-pathways {
  width: calc(100% - var(--gutter-regular) * 2);
  max-width: var(--site-max-width);
  margin-left: auto;
  margin-right: auto;
  padding-top: var(--section-padding);
  padding-bottom: var(--section-padding);
}
.ce-audience {
  border-top: 1px solid var(--ce-line);
  border-bottom: 1px solid var(--ce-line);
}

/* ---------- Learning outcomes ---------- */
.ce-grid--outcomes {
  counter-reset: ce-outcome;
}
.ce-grid--outcomes > .ce-card {
  counter-increment: ce-outcome;
  background: var(--ce-tint);
}
.ce-grid--outcomes > .ce-card::before {
  content: counter(ce-outcome, decimal-leading-zero);
  display: block;
  margin-bottom: 0.4em;
  color: var(--ce-accent);
  font-family: var(--font-headings);
  font-size: 2em;
  line-height: 1;
}

/* ---------- Who should register ---------- */
.ce-audience__roles {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ce-audience__roles > li {
  display: flex;
  align-items: center;
  gap: 1em;
  margin: 0;
  padding: 1.2em 1.4em;
  background: var(--ce-ink);
  color: white;
  font-weight: 600;
  font-size: 1.1em;
}
.ce-audience__roles > li::before {
  content: "";
  flex: none;
  width: 12px;
  height: 12px;
  background: var(--ce-accent);
}
@media (min-width: 800px) {
  .ce-audience {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 6%;
    align-items: center;
  }
}

/* ---------- Learning pathways ---------- */
.ce-pathway {
  display: flex;
  flex-direction: column;
  padding: 1.8em 1.6em 1.6em;
  background: white;
  border: 1px solid var(--ce-line);
  border-top: 4px solid var(--ce-accent);
}
.ce-pathway__meta {
  margin: 1.2em 0 0;
  padding-top: 1em;
  border-top: 1px solid var(--ce-line);
  font-weight: 600;
}
.ce-pathway__meta span {
  display: block;
  margin-bottom: 0.2em;
  color: var(--colour-dark_grey);
  font-size: 0.8em;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ce-pathway--combined {
  background: var(--ce-ink);
  border-color: var(--ce-ink);
  border-top-color: var(--ce-accent);
  color: white;
}
.ce-pathway--combined .ce-pathway__meta {
  border-top-color: rgba(255, 255, 255, 0.25);
}
.ce-pathway--combined .ce-pathway__meta span {
  color: var(--colour-grey-300);
}
.ce-pathway--combined .ce-link {
  color: var(--colour-orange-300);
}

/* ---------- Course structure headings ---------- */
.ce-structure-head {
  max-width: 60rem;
}
.ce-structure-head--carf {
  margin-top: 1.5em;
  padding-top: 2em;
  border-top: 1px solid var(--colour-grey-400);
}
.ce-structure-head h3 {
  font-size: var(--font-size-h3);
}

/* Flip-card back: what you'll explore + learning outcome */
.paragraph--type--course-part .side-secondary h4 {
  margin: 0 0 0.6em;
  font-size: 1em;
}
.paragraph--type--course-part .side-secondary ul {
  margin: 0 0 1em;
  padding-left: 1.1em;
}
.paragraph--type--course-part .side-secondary li {
  margin-bottom: 0.35em;
}
.ce-outcome {
  margin: 0;
  padding-top: 0.9em;
  border-top: 1px solid rgba(255, 255, 255, 0.4);
}

/* ---------- Why choose ---------- */
.ce-reasons h2 {
  margin-bottom: 1em;
}

/* ---------- Course page layout refinements (only pages using .ce-*) ---------- */
article.course:has(.ce-section) {
  /* Course structure: headings span the whole grid. */
  & .field--name-field-parts {
    align-items: start;
  }
  & .field--name-field-parts > .paragraph--type--formated-text {
    grid-column: 1 / -1;
  }

  /* Programme overview highlights: full-width bar with label + detail. */
  & section.highlights .field--name-field-highlights {
    max-width: none;
    padding: 36px var(--gutter-regular);
  }
  & section.highlights .field--name-field-highlights > div {
    max-width: var(--site-max-width);
    margin-left: auto;
    margin-right: auto;
  }
  & section.highlights .field--name-field-short-description {
    margin-top: 0.3em;
    color: var(--colour-grey-300);
  }

  /* Why choose: text-only picture/text block uses the full width. */
  & .paragraph--type--picture-text:not(:has(.show img)) .show {
    display: none;
  }
  & .paragraph--type--picture-text:not(:has(.show img)) .node-body {
    width: 100%;
    max-width: none;
  }
}

@media (min-width: 900px) {
  /* Course structure: three cards per row, four after the CARF heading. */
  article.course:has(.ce-section) .field--name-field-parts {
    grid-template-columns: repeat(12, 1fr);
    gap: 40px 30px;
  }
  article.course:has(.ce-section) .field--name-field-parts > .paragraph {
    grid-column: span 4;
  }
  article.course:has(.ce-section) .field--name-field-parts > .paragraph--type--formated-text:has(.ce-structure-head--carf) ~ .paragraph {
    grid-column: span 3;
  }
  article.course:has(.ce-section) .field--name-field-parts > .paragraph--type--formated-text {
    grid-column: 1 / -1;
  }
}

@media (min-width: 700px) {
  /* Intro image sits on the right of the overview text. */
  article.course:has(.ce-section) section.intro > div {
    flex-direction: row-reverse;
  }
}

/* Flipped structure cards grow to fit "What you'll explore" instead of clipping it. */
article.course:has(.ce-section) .paragraph--type--course-part.flipped,
article.course:has(.ce-section) .paragraph--type--course-part.flipped .side-secondary {
  height: auto;
  min-height: 100%;
  overflow: visible;
}

/* Picture/text sections ("Who should register?", "Why choose"): the wrapper
   provides width and padding; an editor-added image takes one column. */
.paragraph--type--picture-text .ce-audience {
  width: auto;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
}
.paragraph--type--picture-text:has(.show img) .ce-audience {
  display: block;
}
.paragraph--type--picture-text:has(.show img) .ce-audience__roles {
  margin-top: 1.4em;
}
.paragraph--type--picture-text:has(.show img) .ce-grid--reasons {
  grid-template-columns: 1fr;
}
.paragraph--type--picture-text:has(.show img) .ce-grid--reasons > li {
  grid-column: auto;
}
@media (min-width: 700px) {
  .paragraph--type--picture-text:has(.show img) .ce-grid--reasons {
    grid-template-columns: repeat(2, 1fr);
  }
}
