/* Light DOM link styles for footer */
:is(rh-footer, rh-footer-universal) a {
  /** Footer link default color */
  color: var(--rh-color-interactive-primary-default);
  text-decoration: none;
}

:is(rh-footer, rh-footer-universal) :is(rh-footer-block) a {
  text-decoration:
    underline
    /** Footer block link underline width */
    var(--rh-border-width-sm, 1px)
    dashed;
  text-decoration-color:
    light-dark(
        /** Footer block link underline in light mode */
        var(--rh-color-gray-50),
        /** Footer block link underline in dark mode */
        var(--rh-color-gray-40)
      ) !important;
  text-underline-offset: max(5px, 0.28em);
  transition-timing-function: ease;
  transition-property: text-underline-offset, color, text-decoration-color;
  transition-duration: 0.3s;
}

rh-footer [slot^='links'] a {
  gap:
    /** Footer link stack gap override */
    var(--rh-footer-links-gap,
      /** Footer link stack gap */
      var(--rh-space-md, 8px));
}

:is(rh-footer, rh-footer-universal) [slot^='links'] a {
  display: block;

  /** Footer link column text color */
  color: var(--rh-color-text-primary) !important;
  font-size:
    /** Footer link size override */
    var(--rh-footer-link-font-size,
      /** Footer link body size */
      var(--rh-font-size-body-text-sm, 0.875rem));
  width: fit-content;
}

rh-footer-universal [slot^='links'] a {
  font-size: inherit;
}

:is(rh-footer, rh-footer-universal) a:hover {
  /** Footer link hover color */
  color: var(--rh-color-interactive-primary-hover);
  text-decoration:
    underline
    /** Footer link hover underline width */
    var(--rh-border-width-sm, 1px)
    dashed;
  text-decoration-color: inherit;
  text-underline-offset: max(5px, 0.28em);
  transition-timing-function: ease;
  transition-property: text-underline-offset, color, text-decoration-color;
  transition-duration: 0.3s;
}

:is(rh-footer, rh-footer-universal) a:is(:focus, :focus-within) {
  /** Footer link focus color */
  color: var(--rh-color-interactive-primary-hover);
  text-decoration:
    underline
    dashed
    /** Footer link focus underline width */
    var(--rh-border-width-sm, 1px);
  text-decoration-color: inherit;
  text-underline-offset: max(5px, 0.28em);
  transition-timing-function: ease;
  transition-property: text-underline-offset, color, text-decoration-color;
  transition-duration: 0.3s;
}

:is(rh-footer, rh-footer-universal) a:visited {
  /** Footer link visited color */
  color: var(--rh-color-interactive-primary-hover);
  text-decoration: none;
}

/* Underlines on inline links in rh-footer-block */

:is(rh-footer, rh-footer-universal) :is(rh-footer-block) a:hover {
  text-decoration-color: inherit !important;
  text-underline-offset: max(6px, 0.33em);
}

:is(rh-footer, rh-footer-universal) :is(rh-footer-block) a:is(:focus, :focus-within) {
  text-decoration-color: inherit !important;
  text-underline-offset: max(6px, 0.33em);
}

:is(rh-footer, rh-footer-universal) :is(rh-footer-block) a:visited {
  text-decoration-color: inherit;
}

/* Logo links wrap image content */
:is(rh-footer, rh-footer-universal) a[slot^='logo'] {
  display: block;
}

:is(rh-footer) a[slot^='logo'] > img {
  display: block;
  width: auto;

  /** Logo image height */
  height: var(--rh-size-icon-04, 40px);
}

:is(rh-footer, rh-footer-universal) :is(h1, h2, h3, h4, h5, h6) {
  /** Footer heading text color */
  color: var(--rh-color-text-primary);

  /** Footer typeface */
  font-family: var(--rh-font-family-heading, RedHatDisplay, 'Red Hat Display', Helvetica, Arial, sans-serif);

  /** Footer line height */
  line-height: var(--rh-line-height-heading, 1.3);
}

rh-footer [slot='links']:is(h1, h2, h3, h4, h5):nth-of-type(n+5) {
  --_link-header-margin:
    calc(
        /** Link column header offset large */
        var(--rh-space-2xl, 32px) -
        /** Link column header offset small */
        var(--rh-space-lg, 16px));
}

:is(rh-footer, rh-footer-universal) [slot^='links'] li {
  margin: 0;
  padding: 0;
  display: contents;
}

/* Section horizontal gutter */
:is(rh-footer, rh-footer-universal) {
  /** Default footer horizontal gutter */
  --rh-footer-section-side-gap: var(--rh-space-lg, 16px);

  color-scheme: only dark;
  overflow-y: auto;
}

/* (min-width: --rh-breakpoint-sm) */
@media screen and (min-width: 768px) {
  :is(rh-footer, rh-footer-universal) {
    /** Footer horizontal gutter at viewport >= md */
    --rh-footer-section-side-gap: var(--rh-space-2xl, 32px);
  }
}

/* (min-width: --rh-breakpoint-xl) */
@media screen and (min-width: 1440px) {
  :is(rh-footer, rh-footer-universal) {
    /** Footer horizontal gutter at viewport >= 2xl */
    --rh-footer-section-side-gap: var(--rh-space-4xl, 64px);
  }
}

/* No-JS experience */
rh-footer:not(:defined) {
  /** No-JS section horizontal inset */
  --_section-side-gap: var(--rh-space-lg, 16px);

  /** Footer surface without JS */
  background-color: var(--rh-color-surface-darker, #1f1f1f);
  width: 100%;
  display: grid;
  grid-template-areas:
    'footer'
    'global';
  grid-template-rows: 1fr auto;

  /** Minimum height without JS; prefer `rh-footer:not(:defined)` in CSS */
  min-height: var(--rh-footer-nojs-min-height);

  & > *:not(rh-footer-universal) {
    padding-inline: var(--_section-side-gap);
  }

  a[slot='logo'] {
    /** Footer vertical spacing */
    padding-block: var(--rh-space-2xl, 32px);
  }

  ul[slot='links'] {
    display: flex;
    flex-direction: column;
    gap:
      /** No-JS link stack gap override */
      var(--rh-footer-links-gap,
        /** No-JS link stack gap */
        var(--rh-space-md, 8px));

    /** Link list bottom margin without JS */
    margin-block-end: var(--rh-space-3xl, 48px);
  }

  [slot='links'] a {
    font-size:
      /** No-JS link size override */
      var(--rh-footer-link-font-size,
        /** No-JS link body size */
        var(--rh-font-size-body-text-sm, 0.875rem));
  }
}

rh-footer-social-link:not(:defined),
rh-footer:not(:defined) [slot='social-links'] {
  /* Hide social links before JS */
  display: none;
}

:is(rh-footer, rh-footer-universal):not(:defined) {
  p {
    /** Footer secondary text on dark */
    color: var(--rh-color-text-secondary-on-dark, #c7c7c7);
  }

  & :is(h1, h2, h3, h4, h5, h6) {
    &[slot='links'],
    &[slot='header'] {
      font-size:
        /** Link column header size override */
        var(--rh-footer-link-header-font-size,
          /** Link column header size */
          var(--rh-font-size-body-text-sm, 0.875rem));

      /** Footer font weight */
      font-weight: var(--rh-font-weight-heading-medium, 500);
    }
  }
}

rh-footer-universal:not(:defined) {
  /** Universal footer surface without JS */
  background-color: var(--rh-color-surface-darkest, #151515);
  display: block;
  width: 100%;
  padding:
    /** Universal footer block padding without JS */
    var(--rh-space-2xl, 32px)
    /** Universal footer inline padding without JS */
    var(--rh-space-lg, 16px);

  &:before {
    grid-area: global;
  }

  & [slot='links-primary'],
  & [slot='links-secondary'] {
    display: flex;
    flex-flow: column wrap;

    /** Footer content gap */
    gap: var(--rh-space-md, 8px);

    /** Footer text size */
    font-size: var(--rh-font-size-body-text-xs, 0.75rem);
    margin: 0;
    padding: 0;
  }

  /* No-JS + DSD */
  &[ssr-hint-has-slotted] :is(h2, h3, h4)[hidden] {
    border: 0;
    clip: rect(0, 0, 0, 0);
    block-size: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    white-space: nowrap;
    inline-size: 1px;
  }

  & rh-footer-copyright:not(:defined) {
    grid-column: -1/1;
    padding-block:
      /** Copyright block-start padding without JS */
      var(--rh-space-2xl, 32px)
      /** Copyright block-end padding without JS */
      var(--rh-space-md, 8px);

    /** Copyright text size */
    font-size: var(--rh-font-size-body-text-xs, 0.75rem);

    /** Copyright text on dark */
    color: var(--rh-color-text-secondary-on-dark, #c7c7c7);
  }
}

rh-footer-block:not(:defined) {
  :is(h1, h2, h3, h4, h5, h6) {
    font-size:
      /** Footer block header size override */
      var(--rh-footer-link-header-font-size,
        /** Footer block header size */
        var(--rh-font-size-body-text-sm, 0.875rem));

    /** Footer font weight */
    font-weight: var(--rh-font-weight-heading-medium, 500);

    /** Footer bottom margin */
    margin-block-end: var(--rh-space-lg, 16px);

    &:not(:first-of-type) {
      /** Footer top margin */
      margin-block-start: var(--rh-space-lg, 16px);
    }
  }

  &:not(:first-of-type) {
    /** Footer top margin */
    margin-block-start: var(--rh-space-2xl, 32px);
  }
}

rh-footer:not(:defined) rh-footer-universal:not(:defined) {
  /* Spacing when universal footer is nested in rh-footer */

  /** Nested universal footer top margin */
  margin-block-start: var(--rh-space-2xl, 32px);
}

/* (min-width: --rh-breakpoint-sm) */
@media screen and (min-width: 768px) {
  rh-footer:not(:defined) {
    /** No-JS section horizontal inset at viewport >= md */
    --_section-side-gap: var(--rh-space-2xl, 32px);
  }
}

/* (min-width: --rh-breakpoint-md) */
@media screen and (min-width: 992px) {
  rh-footer:not(:defined) {
    gap:
      /** No-JS footer grid row gap at viewport >= lg */
      var(--rh-space-lg, 16px)
      /** No-JS footer grid column gap at viewport >= lg */
      var(--rh-space-2xl, 32px);
    grid-template-columns: repeat(12, minmax(0, 1fr));

    a[slot='logo'] {
      position: relative;

      &:before {
        /** Logo divider color at viewport >= lg */
        background-color: var(--rh-color-border-subtle-on-dark, #707070);

        /** Logo divider thickness at viewport >= lg */
        block-size: var(--rh-length-4xs, 1px);
        content: '';
        inline-size: calc(100% - var(--_section-side-gap) * 2);
        inset-block-end: 0;
        position: absolute;
      }
    }

    & > *:not(rh-footer-universal) {
      padding: 0;
    }

    a[slot='logo'],
    :is(h2, h3)[slot='links']:first-of-type,
    ul[slot='links']:first-of-type {
      padding-inline-start: var(--_section-side-gap);
    }

    :is(h2, h3)[slot='links'] {
      grid-row-start: 2;
    }

    :is(h2, h3)[slot='links'],
    ul[slot='links'] {
      grid-column-start: span 2;
    }

    ul[slot='links'] {
      gap:
        /** No-JS link column gap override at viewport >= lg */
        var(--rh-footer-links-gap,
          /** No-JS link column gap at viewport >= lg */
          var(--rh-space-lg, 16px));
      grid-row: 3 / span 2;
      margin: 0;
    }
  }

  rh-footer:not(:defined) a[slot='logo'],
  rh-footer-universal:not(:defined) {
    grid-column-start: span 12;
  }

  rh-footer-block:not(:defined) {
    grid-column: 9 / span 4;
    grid-row: 2 / 4;

    &:not(:first-of-type) {
      margin-block-start: 0;
    }

    &[slot='main-secondary'] {
      padding-inline-end: var(--_section-side-gap);
    }

    &:nth-of-type(2) {
      --_grid-row-max: 5;

      grid-row: 4 / 5;
    }

    &:nth-of-type(3) {
      --_grid-row-max: 7;

      grid-row: 6 / 7;
    }

    &:nth-of-type(4) {
      --_grid-row-max: 8;

      grid-row: 7 / 8;
    }
  }

  rh-footer:not(:defined) :is(h2, h3)[slot='links'],
  rh-footer-block:not(:defined):first-of-type {
    /** Link column header top margin at viewport >= lg */
    margin-block-start: var(--rh-space-lg, 16px);
  }

  rh-footer-universal:not(:defined) {
    /** Universal footer block padding at viewport >= lg */
    padding-block: var(--rh-space-2xl, 32px);
    padding-inline:
      /** Universal footer inline padding start at viewport >= lg */
      var(--rh-space-7xl, 128px)
      /** Universal footer inline padding end at viewport >= lg */
      var(--rh-space-4xl, 64px);

    &[ssr-hint-has-slotted] {
      padding-inline: 0;
    }

    & ul[slot='links-primary'],
    & ul[slot='links-secondary'] {
      flex-direction: row;
      gap:
        /** Global link row gap at viewport >= lg */
        var(--rh-space-md, 8px)
        /** Global link column gap at viewport >= lg */
        var(--rh-space-xl, 24px);
    }

    & ul[slot='links-primary'] {
      /** Primary link list bottom margin at viewport >= lg */
      margin-block-end: var(--rh-space-xl, 24px);
    }

    & rh-footer-copyright:not(:defined) {
      /** Copyright block padding at viewport >= lg */
      padding-block: var(--rh-space-md, 8px);
    }
  }

  rh-footer:not(:defined) rh-footer-universal:not(:defined) {
    --_grid-row-max: 8;

    grid-row: var(--_grid-row-max) / var(--_grid-row-max);
  }
}

/* (min-width: --rh-breakpoint-xl) */
@media screen and (min-width: 1440px) {
  rh-footer:not(:defined) {
    /** No-JS section horizontal inset at viewport >= 2xl */
    --_section-side-gap: var(--rh-space-4xl, 64px);
  }
}
