/*!
 * Copyright (c) 2024 Eclipse Foundation, Inc.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0
*/

.rollover-tile {
  box-sizing: border-box;
  position: relative;
  padding: 1rem;
  outline: none;
  // Set transparent borders so page content doesn't get pushed down when the
  // rollover-tile is hovered.
  border: 2px solid transparent;
  border-bottom-width: 0;

  @media (min-width: @screen-sm-min) {
    &-content {
      position: absolute;
      top: 100%;
      left: 0;
      // Borders take up space so we need to account for the parent's width plus
      // its borders widths. This is why there are width calculations and negative
      // margins.
      width: calc(100% + 4px);
      max-height: 0;
      padding: 1rem;
      // Surround the parent and child element in a border for accessibility. We
      // need to use border instead of outline so we can omit certain sides (e.g.
      // parent's bottom edge or child's top edge) 
      border: 2px solid transparent;
      border-top-width: 0;
      margin-left: -2px;
      outline: none;
      // Use visibility instead of display none so screen-readers can still pick
      // up the text.
      visibility: hidden;
      background-color: inherit;
      // Transitions do not work with "height: auto", so max-height is used
      // instead.
      transition: max-height .5s ease-in;
      overflow: hidden; // Required to the text doesn't overflow mid-animation.
    }

    // Set the visibility of the content to visible when the user hovers, or
    // focuses.
    &:hover &-content,
    &:focus-within &-content, 
    &:active &-content {
      visibility: unset;
      // An arbitrarily large value. It only needs to be larger than the content.
      max-height: 999rem;
    }

    &:focus-within {
      border-color: black;
    }
    &:focus-within &-content {
      border-color: black;
    }
  }
}
