/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

:host {
  display: flex;
  flex-direction: column;
  border: var(--card-border);
  border-radius: var(--card-border-radius);
  background-color: var(--card-background-color);
  box-shadow: var(--card-box-shadow);
  box-sizing: border-box;
}

:host([type="accordion"]) {
  summary {
    padding-block: var(--card-padding-block, var(--card-padding));
  }
  #content {
    padding-block-end: var(--card-padding-block, var(--card-padding));
  }
}

:host(:not([type="accordion"])) {
  .moz-card {
    padding-block: var(--card-padding-block, var(--card-padding));
  }
  #moz-card-details {
    display: flex;
    flex-direction: column;
    gap: var(--card-gap-article);
  }
}

.moz-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--card-gap-article);
  overflow-wrap: anywhere;
}

#moz-card-details {
  width: 100%;
}

.moz-card,
#moz-card-details,
#content {
  flex: 1;
}

summary {
  cursor: pointer;
}

#heading-wrapper {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--card-gap);
  padding-inline: var(--card-heading-padding-inline, var(--card-padding));
  border-radius: var(--card-border-radius);

  .chevron-icon {
    background-image: var(--card-accordion-closed-icon, url("chrome://global/skin/icons/arrow-down.svg"));

    details[open] & {
      background-image: var(--card-accordion-open-icon, url("chrome://global/skin/icons/arrow-up.svg"));
    }
  }

  .chevron-icon {
    background-position: center;
    background-repeat: no-repeat;
  }

  .chevron-icon,
  #heading-icon {
    -moz-context-properties: fill;
    fill: currentColor;
    width: var(--icon-size);
    height: var(--icon-size);
    min-width: var(--icon-size);
    min-height: var(--icon-size);
    padding: 0;
    flex-shrink: 0;
  }
}

#heading {
  font-size: var(--font-size-root);
  font-weight: var(--font-weight-heading);
}

#content {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  padding-inline: var(--card-padding-inline, var(--card-padding));
  border-end-start-radius: var(--card-border-radius);
  border-end-end-radius: var(--card-border-radius);

  @media (prefers-contrast) {
    :host([type="accordion"]) & {
      border-block-start: 0;
      padding-block-start: var(--card-padding-block, var(--card-padding));
    }
  }
}

details {
  > summary {
    list-style: none;
    border-radius: var(--card-border-radius);
    cursor: pointer;

    &:hover {
      background-color: var(--button-background-color-hover);
    }

    &:focus-visible {
      outline: var(--card-focus-outline);
    }

    @media (prefers-contrast) {
      outline: var(--button-border-color) solid var(--border-width);
    }

    @media (forced-colors) {
      color: var(--button-text-color);
      background-color: var(--button-background-color);

      &:hover {
        background-color: var(--button-background-color-hover);
        color: var(--button-text-color-hover);
      }

      &:active {
        background-color: var(--button-background-color-active);
        color: var(--button-text-color-active);
      }
    }
  }

  &[open] {
    summary {
      border-end-start-radius: 0;
      border-end-end-radius: 0;
    }
    @media not (prefers-contrast) {
      #content {
        /*
        There is a border shown above this element in prefers-contrast.
        When there isn't a border, there's no need for the extra space.
         */
        padding-block-start: 0;
      }
    }
  }
}
