/**
 * @file
 * Collapsible details.
 */

@import "../base/variables.pcss.css";

:root {
  --details-border-width: 1px;
  --details-summary-transition: background-color 0.12s ease-in-out;
}

.olivero-details {
  display: block;
  margin-block: var(--sp1);
  color: inherit;
  border: var(--details-border-width) solid var(--color--gray-80);
  border-radius: var(--border-radius-base);
  box-shadow: 0 1px 4px var(--color--gray-70);
}

/* Details summary styles */
.olivero-details__summary {
  position: relative;
  padding-block: var(--sp1);
  padding-inline-start: var(--sp2);
  padding-inline-end: var(--sp1);
  list-style: none;
  cursor: pointer;
  transition: var(--details-summary-transition);
  word-wrap: break-word;
  hyphens: auto;
  color: inherit;
  background-color: var(--color--gray-95);
  font-size: var(--line-height-s);
  font-weight: 700;
  line-height: var(--sp1);
}

/* Arrow icon */
.olivero-details__summary:before,
.collapse-processed > .olivero-details__summary .details-title:before {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: var(--sp0-75);
  display: block;
  width: 10px;
  height: 10px;
  content: "";
  transform: translateY(-50%) rotate(45deg); /* LTR */
  border-top: solid 2px currentColor;
  border-right: solid 2px currentColor;
}

[dir="rtl"] {
  & .olivero-details__summary:before,
  & .collapse-processed > .olivero-details__summary .details-title:before {
    transform: translateY(-50%) rotate(-135deg);
  }
}

/* Pseudo-selector to manage focus styles */
.olivero-details__summary:after,
.collapse-processed > .olivero-details__summary .details-title:after {
  position: absolute;
  inset: calc(var(--details-border-width) * -1);
  content: "";
  pointer-events: none;
  opacity: 0;
  border-radius: var(--border-radius-base);
  box-shadow: inset 0 0 0 2px var(--color--blue-70);
}

/* Hide the marker */
.olivero-details__summary::-webkit-details-marker {
  display: none;
}

/* Disable default outline for summary, since we have own implementation */
.olivero-details__summary:focus {
  outline: none;
}

/* Details summary, hover state */
.olivero-details__summary:hover {
  background-color: var(--color--gray-80);
}

/* Details summary, focus and active states */
.olivero-details__summary:focus:after,
.olivero-details__summary:active:after,
.collapse-processed > .olivero-details__summary .details-title:focus:after,
.collapse-processed > .olivero-details__summary .details-title:active:after {
  opacity: 1;
}

/* Rotate arrow icon of the details summary, when details expanded */
.olivero-details[open] > .olivero-details__summary::before,
.collapse-processed[open] > .olivero-details__summary .details-title::before {
  margin-block-start: -2px;
  transform: translateY(-50%) rotate(135deg);
}

/* Collapse processed for non-supporting browsers like IE or Edge */
.collapse-processed > .olivero-details__summary {
  padding-block: 0;
  padding-inline-start: 0;
  padding-inline-end: 0;

  &:before {
    content: none;
  }

  &:after {
    content: none;
  }
}

.collapse-processed > .olivero-details__summary .details-title {
  position: relative;
  display: block;
  padding-block: var(--sp1);
  padding-inline-start: var(--sp2);
  padding-inline-end: var(--sp1);
  transition: var(--details-summary-transition);
  text-decoration: none;
  color: inherit;
  background-color: var(--color--gray-95);
}

.collapse-processed > .olivero-details__summary .details-title:focus {
  outline: none;
}

.collapse-processed > .olivero-details__summary .details-title:hover {
  background-color: var(--color--gray-80);
}

@media screen and (-ms-high-contrast: active) {
  .collapse-processed > .olivero-details__summary .details-title::after {
    inset: -5px;
    border: 2px dotted;
  }
}

/* Details content wrapper */
.olivero-details__wrapper {
  margin: var(--sp1);

  @media (--lg) {
    margin-block-start: var(--sp1-5);
    margin-block-end: var(--sp1-5);
    margin-inline-start: var(--sp2);
    margin-inline-end: var(--sp2);
  }
}

/* Description */
.olivero-details__description {
  margin-block-end: var(--sp1);
  color: var(--color--gray-10);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-s);
}
