/**
 * @file
 * Claro styles for Tables.
 */

table {
  width: 100%;
  margin-block: var(--space-l);
  border-collapse: collapse;
}

.sticky-header {
  min-width: 0;
}

caption {
  text-align: start;
}

th {
  position: relative;
  box-sizing: border-box;
  height: var(--space-xl);
  padding: var(--space-xs) var(--space-m);
  text-align: start;
  color: var(--color-text);
  background: var(--color-gray-050);
  line-height: 1.25rem; /* 20px */
}

/* The actual sort link. */
.sortable-heading {
  padding: 0 var(--space-m);
  & > a {
    display: block;
    padding-block: var(--space-xs);
    padding-inline: 0 1.5rem;
    text-decoration: none;
    color: inherit;

    &:focus,
    &:hover {
      text-decoration: none;

      &::before {
        border-color: inherit;
      }

      &::after {
        opacity: 1;
      }
    }

    &::before {
      position: absolute;
      z-index: 0;
      inset-block-start: 0;
      inset-inline-end: 1rem;
      inset-block-end: 0;
      inset-inline-start: 1rem;
      display: block;
      content: "";
      border-bottom: 0.125rem solid transparent;
    }

    &::after {
      position: absolute;
      inset-block-start: 50%;
      inset-inline-end: 1rem;
      width: 0.875rem;
      height: 1rem;
      margin-block-start: -0.5rem;
      content: "";
      opacity: 0.5;
      background: url(../../images/icons/000f33/sort--inactive.svg) no-repeat 50% 50%;
      background-size: contain;

      [dir="rtl"] & {
        /* Horizontally flip the element. */
        transform: scaleX(-1);
        background-image: url(../../images/icons/000f33/sort--inactive.svg);

        @media (forced-colors: active) {
          mask: url(../../images/icons/000f33/sort--inactive.svg) no-repeat 50% 50%;
        }
      }

      @media (forced-colors: active) {
        opacity: 1;
        background: linktext;
        mask: url(../../images/icons/000f33/sort--inactive.svg) no-repeat 50% 50%;
      }
    }
  }

  &.is-active > a {
    color: var(--color-absolutezero);

    &::before {
      border-bottom: 0.1875rem solid var(--color-absolutezero);
    }

    &::after {
      content: none;
    }
  }
}

tr {
  border-bottom: 0.0625rem solid var(--color-gray-200);
  &:hover,
  &:focus-within {
    color: var(--color-text);
    background: var(--color-bgblue-hover);
  }
  &.color-warning:hover,
  &.color-warning:focus {
    color: var(--color-text);
    background: #fdf8ed;
  }
  &.color-error:hover,
  &.color-error:focus {
    color: var(--color-text);
    background: #fcf4f2;
  }
}
tr,
.draggable-table.tabledrag-disabled tr {
  color: var(--color-text);
  background: var(--color-white);
}
thead tr {
  border: 0;
}

td {
  box-sizing: border-box;
  height: 4rem;
  padding: var(--space-xs) var(--space-m);
  text-align: start;

  & .item-list ul {
    margin: 0;
  }

  &.is-active {
    background: none;
  }
}

/**
 * Target every .form-element input that parent is a form-item of a table cell.
 * This ignores the filter format select of the textarea editor.
 */
td {
  & > .form-item > .form-element,
  & > .ajax-new-content > .form-item > .form-element,
  & > .form-item > .claro-autocomplete,
  & > .form-item > .claro-autocomplete > .form-element,
  & > .ajax-new-content > .form-item > .claro-autocomplete,
  & > .ajax-new-content > .form-item > .claro-autocomplete > .form-element {
    width: 100%;
  }

  & > .form-item > .form-element--type-select,
  & > .ajax-new-content > .form-item > .form-element--type-select {
    width: max-content;
    min-width: 100%;
  }
}

/* Win over table-file-multiple-widget. */
th.is-disabled.is-disabled {
  color: var(--input--disabled-fg-color);
}
/* Force browsers to calculate the width of a 'select all' <th> element. */
th.select-all {
  width: 1px;
}

/**
 * Captions.
 */
.caption {
  margin-block-end: 1.25rem; /* 20px */
}

tfoot {
  font-weight: bold;
  & tr {
    &:last-child {
      border-bottom: 0;
    }
    &:first-child td {
      border-top: 0.0625rem solid var(--color-gray-500);
    }
  }
}

/**
 * Responsive table cells.
 */
th.priority-low,
th.priority-medium,
td.priority-low,
td.priority-medium {
  display: none;
}

@media screen and (min-width: 38em) {
  th.priority-medium,
  td.priority-medium {
    display: table-cell;
  }
}

@media screen and (min-width: 60em) {
  th.priority-low,
  td.priority-low {
    display: table-cell;
  }
}

.tabledrag-toggle-weight-wrapper {
  margin-block-start: var(--space-l);
  line-height: calc(28rem / 16);

  & + table,
  & + .tableresponsive-toggle-columns + table {
    margin-block-start: 0;
  }
}
