/*
 * Card component
 * The bg-color value should inherit from the .bg-color-- classes in the utilities--layout.css file
*/

.card {
  --card-heading-size: 1.2rem;
  --card-corner-size: 5rem;
  padding: 0;
  position: relative;

  /* Makes sure the heights align in grids */
  display: grid;
  grid-template-rows: auto 1fr;
}

.card-media {
  clip-path: polygon(
    0 0,
    0 100%,
    100% 100%,
    100% var(--card-corner-size),
    calc(100% - var(--card-corner-size)) 0
  );
  img {
    display: block;
    transition: all 0.15s ease-in-out;
    width: 100%;
  }
}

.card-linked:hover .card-media img {
  transform: scale(1.1);
}

/* Horizontal variation */

@media (min-width: 767px) {
  .card--horizontal {
    display: grid;
    grid-template-columns: 33% auto;

    .card-media {
      clip-path: polygon(
        calc(100% - 23px) 0,
        100% 55px,
        100% 100%,
        0 100%,
        0 0
      );
    }

    &.bg-color {
      .card-media {
        display: grid;
        height: 100%;

        div {
          display: grid;
          height: 100%;
        }

        img {
          height: 100%;
          object-fit: cover;
          width: 100%;
        }
      }
    }
  }

  .card--horizontal-no-image {
    display: grid;
    grid-template-columns: auto;
  }
}

/* Content fields */

.card-category {
  display: block;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.card-heading {
  font-size: var(--card-heading-size);
  font-weight: 500;
  margin-bottom: 0.5em;

  a {
    color: var(--color-black);
    color: var(--fg-color);
  }
}

.card:not(.card-no-link):is(:hover, :focus) .card-heading {
  /* Use link colour variable to accommodate different background colours */
  color: var(--link-color);
}

.card-content {
  padding: 1.2rem;
}

.card-content.bg-color,
.card.block-pattern {
  .card-content {
    padding-left: 1.2rem;
    padding-right: 1.2rem;
  }
}

.card.block-pattern {
  grid-template-rows: max-content;
  --card-corner-size: 2rem;
  clip-path: polygon(
    0 0,
    0 100%,
    100% 100%,
    100% var(--card-corner-size),
    calc(100% - var(--card-corner-size)) 0
  );
}

/* Make the arrow in the corner */
.card-linked .card-arrow-icon {
  clip-path: polygon(0 0, 100% 100%, 100% 0);
  height: calc(var(--card-corner-size) - 1rem);
  width: calc(var(--card-corner-size) - 1rem);
  position: absolute;
  right: 0;
  top: 0;

  display: grid;
  align-items: start;
  justify-content: end;
  padding: 0.7rem 0.6rem 1rem 1rem;

  svg {
    fill: var(--color-grey-dk);
  }

  a:is(:hover, :focus) {
    color: inherit;
  }
}

.card-no-link .card-arrow-icon {
  display: none;
}

/* Hover arrow behaviour */
.card-linked:is(:hover, :focus) {
  .card-link {
    text-decoration: none;
    /* This needs to use the --link-colour variable to accommodate different background colours  */
    color: var(--link-color);
  }

  .card-arrow-icon {
    background-color: var(--bg-color);

    svg {
      fill: var(--fg-color);
    }
  }
}

/* Fake the full card link */
.card-link::after {
  content: "";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Fix last item optional clas
   Ensures the last item aligns horizontally in a row of cards
 */
.fix-last-item {
  display: flex;
  flex-direction: column;
  justify-content: start;

  > *:last-child {
    margin-top: auto;
  }
}

/* Card grid alterations */

.grid > *:nth-child(even) .card.block-pattern {
  background-image: url(../../../assets/block-pattern-light.svg);
  --bg-color: var(--color-white);
  --fg-color: var(--color-blue);
  color: var(--color-black);
  a {
    color: var(--color-black);
  }
}

/* Adjustment for sdc demo */

.card.sdc-demo {
  max-width: 25rem;
  overflow: hidden;
}
