/*
  @classreference
  content-card:
    Content card:
      .p-content-card:
        Main element of the content card component.
      "&.p-content-card--cols-2":
        Modifier for a 2-column width vertical layout. Applied ONLY to the parent .p-content-card.
      "&.p-content-card--cols-4":
        Modifier for a 4-column width horizontal layout. Applied ONLY to the parent .p-content-card.
      "&.p-content-card--cols-6":
        Modifier for a 6-column width horizontal layout. Applied ONLY to the parent .p-content-card.
      "&.has-image":
        State class applied to the parent when the card includes an image.
      "&.has-desc":
        State class applied to the parent when the card includes a description that appears on hover.
    Links:
      .p-content-card__overlay-link:
        Invisible absolute link spanning the entire card to make it clickable.
      .p-content-card__main-link:
        The primary text link, typically wrapping the heading.
      .p-content-card__author-link:
        Interactive link for the author name.
    Media:
      .p-content-card__image-wrapper:
        Container for the card's image. Styled contextually by parent modifiers.
      .p-content-card__image:
        The image element, maintaining a 16/9 aspect ratio. Styled contextually by parent modifiers.
    Content:
      .p-content-card__content:
        Flex container wrapping the main body and footer of the card.
      .p-content-card__body:
        Grid container holding both the primary and hover content areas. Styled contextually by parent modifiers.
      .p-content-card__primary-content:
        The default visible content area (heading, author, date).
      .p-content-card__hover-content:
        The content area that slides up on hover (description).
      .p-content-card__heading:
        The card's title element. Styled contextually by parent modifiers.
      .p-content-card__description:
        The text description that appears on hover. Styled contextually by parent modifiers.
      .p-content-card__author-and-date:
        Container for the author and publication date. Styled contextually by parent modifiers.
    Footer:
      .p-content-card__footer-outer:
        Outer container for the footer section. Styled contextually by parent modifiers.
      .p-content-card__footer-inner:
        Horizontally scrollable inner container for footer metadata (chips, icons).
      .p-content-card__icon:
        Icon element utilized within the footer.
      .p-content-card__small:
        Small text element utilized within the footer.
*/

@import 'settings';

// =========================================
// CONTENT CARD VARIABLES
// =========================================
$card-height-vertical: 23.75rem; // 380px
$card-height-default: 12rem; // 192px

$card-image-width: 17.75rem; // 284px
// Horizontal image heights are explicit to preserve the tuned text/image balance at each breakpoint
$card-image-height-horizontal: 9.703125rem; // 155.25px
$card-image-height-horizontal-large: 9.984375rem; // 159.75px

// Horizontal card heights are image height plus vertical spacing budget.
$card-height-horizontal: $card-image-height-horizontal + $sp-x-large;
$card-height-horizontal-large: $card-image-height-horizontal-large + $sp-x-large;

$card-footer-outer-height: $sp-x-large + ($sp-small * 0.5);
$card-footer-inner-height: $sp-x-large - ($sp-small * 0.5);

$card-nudge-negative: map-get($settings-text-h4, nudge);
$card-chip-margin-right: 1.5625rem; // 25px
$card-author-padding-bottom: $sp-small;

$card-fallback-spacing-large: $sp-x-large;
$card-fallback-image-gap: $sp-small + $sp-xx-small;

@mixin mq-min($breakpoint) {
  @media screen and (width >= $breakpoint) {
    @content;
  }
}

@mixin mq-max($breakpoint) {
  @media screen and (width < $breakpoint) {
    @content;
  }
}

@mixin mq-between($min, $max) {
  @media screen and ($min <= width < $max) {
    @content;
  }
}

@mixin vf-p-content-card {
  /* =========================================
     GRID WRAPPER 
     (Handles spanning and invisible bottom spacing)
     ========================================= */
  .p-content-card-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-bottom: var(--spacing-vertical-large, $card-fallback-spacing-large);
    width: 100%;

    /* 2-Column Spanning */
    &--2 {
      grid-column: 1 / -1; /* Mobile */
      @include mq-between($breakpoint-small, $breakpoint-large) {
        grid-column: span 2; /* Medium */
      }
      @include mq-min($breakpoint-large) {
        grid-column: span 2; /* Desktop */
      }
    }

    /* 4-Column Spanning */
    &--4 {
      grid-column: 1 / -1;
      @include mq-min($breakpoint-large) {
        grid-column: span 4;
      }
    }

    /* 6-Column Spanning */
    &--6 {
      grid-column: 1 / -1;
      @include mq-min($breakpoint-large) {
        grid-column: span 6;
      }
    }
  }

  /* =========================================
     CARD COMPONENT
     ========================================= */
  .p-content-card {
    align-items: flex-start;
    border: 1px solid var(--color-border-low-contrast, rgba(0, 0, 0, 0.1));
    display: flex;
    flex: 1;
    flex-direction: column;
    height: 100%;
    justify-content: space-between;
    max-width: 100%;

    min-height: $card-height-vertical;
    overflow: hidden;
    padding-top: var(--spacing-vertical-large, $sp-medium);
    position: relative;
    text-decoration: none !important;
    transition: all 0.4s ease-in-out;
    width: 100%;

    &:not(.has-image) {
      height: $card-height-default;
      min-height: $card-height-default;
    }

    /* Shrink-to-fit for cards without footers on mobile */
    @include mq-max($breakpoint-small) {
      &:not(:has(.p-content-card__footer-outer)) {
        height: auto;
        min-height: 0;
        padding-bottom: var(--spacing-vertical-large, $sp-medium); /* Keeps spacing balanced */
      }
    }

    /* 2-Column Modifier Internal Resets */
    &.p-content-card--cols-2 {
      @include mq-between($breakpoint-small, $breakpoint-large) {
        .p-content-card__author-and-date {
          display: none !important;
        }
      }
    }

    /* 4 and 6 Column Horizontal Cards (Medium/Large Screens) */
    @include mq-min($breakpoint-small) {
      &.p-content-card--cols-4,
      &.p-content-card--cols-6 {
        align-items: flex-start;
        align-self: stretch;

        flex: 0 0 auto;
        flex-direction: row;
        gap: $sp-medium;
        height: $card-height-horizontal;

        max-width: 100%;
        min-height: $card-height-horizontal;
        padding: $sp-medium $sp-medium 0;
      }

      &.p-content-card--cols-4:not(.has-image),
      &.p-content-card--cols-6:not(.has-image) {
        height: $card-height-default;
        min-height: $card-height-default;
      }

      &.p-content-card--cols-4:not(.has-image) .p-rule--muted,
      &.p-content-card--cols-6:not(.has-image) .p-rule--muted {
        margin-left: -$sp-medium;
        margin-right: -$sp-medium;
        max-width: none;
        width: calc(100% + (#{$sp-medium} * 2));
      }
    }

    @include mq-min($breakpoint-large) {
      &.p-content-card--cols-6 {
        height: $card-height-horizontal-large;
        max-width: 100%;
        min-height: $card-height-horizontal-large;
      }
    }

    &__overlay-link {
      inset: 0;
      position: absolute;
      z-index: 1;
    }

    &__main-link {
      -webkit-box-orient: vertical;
      color: inherit !important;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      line-clamp: 3;
      outline: none !important;
      overflow: hidden;
      text-decoration: none !important;

      .p-content-card--cols-6 & {
        -webkit-line-clamp: 2;
        line-clamp: 2;
      }

      &:hover,
      &:focus,
      &:active,
      &:visited {
        color: inherit !important;
        text-decoration: none !important;
      }
    }

    &__author-link {
      pointer-events: auto;
      position: relative;
      z-index: 2;

      &:focus-visible {
        border-radius: 2px;
        outline: 2px solid var(--color-focus, #0066cc);
        outline-offset: 2px;
      }
    }

    &__heading {
      -webkit-box-orient: vertical;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      line-clamp: 3;
      line-height: 1.5;
      margin-top: 0 !important;
      max-height: 4.5em;
      max-width: none;
      overflow: hidden;
      padding-top: 0 !important;
      text-wrap: wrap;
      width: 100%;

      .p-content-card--cols-6 & {
        -webkit-line-clamp: 2;
        line-clamp: 2;
        max-height: 3em;
      }

      @include mq-min($breakpoint-large) {
        .p-content-card--cols-6 & {
          margin-top: $card-nudge-negative !important;
        }
      }
    }

    &__content {
      display: flex;
      flex: 1;
      flex-direction: column;
      height: 100%;
      justify-content: space-between;
      min-width: 0;
      width: 100%;
    }

    &__body {
      align-items: flex-start;
      align-self: stretch;
      display: grid;
      grid-template-columns: 1fr;
      grid-template-rows: 1fr;
      overflow: hidden;
      padding: 0 $sp-medium;

      @include mq-min($breakpoint-small) {
        .p-content-card--cols-4 &,
        .p-content-card--cols-6 & {
          padding: 0;
        }
      }
    }

    &__primary-content,
    &__hover-content {
      display: flex;
      flex-direction: column;
      grid-area: 1 / 1 / 2 / 2;
      transition:
        transform 0.4s ease-in-out,
        opacity 0.4s ease-in-out;
    }

    &__primary-content {
      opacity: 1;
      transform: translateY(0);
    }

    &__hover-content {
      opacity: 0;
      transform: translateY(150px);
    }

    &__description {
      -webkit-box-orient: vertical;
      display: -webkit-box;
      -webkit-line-clamp: 4;
      line-clamp: 4;
      margin: 0;
      overflow: hidden;

      .p-content-card--cols-6 & {
        -webkit-line-clamp: 2;
        line-clamp: 2;
      }

      @include mq-min($breakpoint-large) {
        .p-content-card--cols-6 & {
          margin-top: $card-nudge-negative !important;
        }
      }
    }

    &__footer-container {
      /* Structural grouping element.
        Because the parent (.p-content-card__content) uses flexbox space-between, 
        this wrapper prevents the <hr> from floating awkwardly in the middle of the card.
      */
    }

    &__footer-outer {
      align-items: center;
      align-self: stretch;
      display: flex;
      height: $card-footer-outer-height;
      overflow: hidden;
      padding: 0 $sp-medium var(--spacing-vertical-small, $sp-small) $sp-medium;
      position: relative;

      @include mq-min($breakpoint-small) {
        .p-content-card--cols-4 &,
        .p-content-card--cols-6 & {
          padding: 0 0 var(--spacing-vertical-small, $sp-small) 0;
        }
      }
    }

    &__footer-inner {
      align-items: center;
      display: flex;
      gap: $sp-small;
      height: $card-footer-inner-height;
      mask-image: linear-gradient(to right, black 85%, transparent 100%);
      -ms-overflow-style: none;
      overflow-x: auto;
      pointer-events: auto;
      position: relative;
      scrollbar-width: none;
      width: 100%;
      z-index: 2;

      &::-webkit-scrollbar {
        display: none;
      }

      > * {
        flex-shrink: 0;
        white-space: nowrap;
      }

      .p-chip--information {
        margin: 0 $card-chip-margin-right 0 0;
        vertical-align: baseline;
      }

      .u-has-icon {
        align-items: center;
        display: flex;
        gap: $sp-x-small;

        .p-content-card__icon[class*='p-icon--'],
        .p-content-card__small {
          margin: 0;
        }

        .p-content-card__small {
          line-height: normal !important;
        }
      }
    }

    &__image {
      aspect-ratio: 16/9;
      display: block;
      flex-shrink: 0;
      height: auto;
      object-fit: cover;
      width: 100%;

      @include mq-min($breakpoint-small) {
        .p-content-card--cols-4 &,
        .p-content-card--cols-6 & {
          height: $card-image-height-horizontal;
        }
      }

      @include mq-min($breakpoint-large) {
        .p-content-card--cols-6 & {
          height: $card-image-height-horizontal-large;
        }
      }
    }

    &__image-wrapper {
      align-items: flex-start;
      display: flex;
      flex-direction: column;
      gap: var(--spacing-vertical-image-container, $card-fallback-image-gap);
      max-width: 100%;
      padding-bottom: var(--spacing-vertical-large, $sp-medium);

      width: 100%;

      @include mq-min($breakpoint-small) {
        .p-content-card--cols-4 &,
        .p-content-card--cols-6 & {
          align-self: stretch;
          flex: 0 0 auto;
          width: $card-image-width;
        }
      }
    }

    &__author-and-date {
      align-items: flex-start;
      align-self: stretch;
      display: flex;
      padding-bottom: $card-author-padding-bottom;

      > :first-child {
        margin-bottom: 0 !important;
      }

      @include mq-between($breakpoint-small, $breakpoint-large) {
        .p-content-card--cols-6 & {
          display: none;
        }
      }

      @include mq-min($breakpoint-large) {
        .p-content-card--cols-6 & {
          display: flex;
        }
      }
    }

    &.has-image {
      padding-top: 0;

      @include mq-min($breakpoint-small) {
        &.p-content-card--cols-4,
        &.p-content-card--cols-6 {
          padding-top: $sp-medium;
        }
      }
    }

    &:hover,
    &:focus-within {
      border-color: var(--color-border-high-contrast, #707070);
      text-decoration: none;
    }

    @include mq-min($breakpoint-large) {
      &.has-desc:hover .p-content-card__primary-content,
      &.has-desc:focus-within .p-content-card__primary-content {
        opacity: 0;
        transform: translateY(-150px);
      }

      &.has-desc:hover .p-content-card__hover-content,
      &.has-desc:focus-within .p-content-card__hover-content {
        opacity: 1;
        transform: translateY(0);
      }
    }

    &:has(.p-content-card__main-link:focus-visible) {
      outline: 3px solid var(--color-focus, #0066cc);
      outline-offset: 2px;
    }
  }
}
