// Cards/Widgets
//=======================================================

.card,
.small-widget,
.widget {
  border-radius: 8px;
  box-shadow: 0 0 4px $cardlist-box-shadow-color-hover;
  height: 368px;
  min-height: 368px;

  &.bordered {
    border: none;

    &:hover {
      outline: 1px solid $card-border-color-hover;
      box-shadow: 0 2px 4px 1px $cardlist-box-shadow-color-hover;
      transition: box-shadow 0.3s cubic-bezier(.17, .04, .03, .94) !important;
    }
  }

  .card-header,
  .widget-header {
    &.is-shadow-scrolling {
      border-bottom: 1px solid $card-scrolling-border-color;
      border-top-left-radius: 8px;
      border-top-right-radius: 8px;
      box-shadow: $card-scrolling-box-shadow;
    }
  }

  .card-content,
  .widget-content {
    .listview-search.is-scrolling {
      .searchfield-wrapper {
        z-index: 10;
      }
    }
  }

  .card-buttonset {
    .card-content-action {
      button.btn-actions:hover {
        background-color: $button-color-tertiary-hover-background-new;

        .icon {
          color: $button-color-tertiary-hover-text-new;
        }
      }
    }
  }

  .is-scrolling {
    position: relative;

    &::before {
      background: $cardlist-bg-color;
      bottom: 1px;
      content: '';
      display: block;
      height: 10px;
      position: absolute;
      width: 100%;
      z-index: 7;
    }

    &::after {
      border-bottom: 1px solid $card-scrolling-border-color;
      box-shadow: $card-scrolling-box-shadow;
      bottom: 0;
      content: '';
      height: 2px;
      left: 0;
      position: absolute;
      z-index: 6;
      width: 100%;
    }
  }

  &:not(.show-buttons) button.btn-actions:not(.list-button) {
    opacity: 0;
  }

  &:hover {
    button.btn-actions:not(.list-button) {
      opacity: 1;
    }
  }

  // Always show buttons for listview cards
  &:has(.listview) {
    .card-header button.btn-actions,
    .widget-header button.btn-actions,
    .listview button.btn-actions {
      opacity: 1;
    }
  }

  .btn-actions.floating-actions {
    border: 1px solid $ids-color-palette-slate-40;
    background-color: $ids-color-palette-white !important;
  }

  .btn-actions.is-open,
  .btn-actions.has-open-tooltip {
    opacity: 1 !important;
  }

  &.is-empty {
    .widget-content,
    .card-content {
      -ms-transform: translateY(-50%);
      transform: translateY(-50%);
      // stylelint-disable-next-line scss/at-extend-no-missing-placeholder
      @extend .flex-center;
    }

    .card-header + .card-content {
      padding-top: 48px;
    }
  }

  .card-content,
  .widget-content {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    position: relative;

    &.has-back-button {
      overflow-x: hidden;
    }

    &.padding-x-16 {
      .content-main,
      .content-detail {
        width: calc(100% - 32px); // Calculate the width of the card/widget considering padding (to prevent overflow when using position: absolute)
      }
    }
  }

  &.show-buttons button:not([disabled]) {
    opacity: 1;
  }

  .widget-header,
  .card-header {
    &.has-subtitle {
      align-items: flex-start;
      height: 60px; // was 64 but need to be flush so for better visuals
      padding-top: 8px;

      + .card-content,
      + .widget-content {
        height: 304px;
        min-height: 304px;
      }
    }

    &.has-back-button {
      padding-left: 8px;

      .widget-header-section,
      .card-header-section {
        &.title,
        &.more,
        &.custom-action {
          display: none;
        }
      }
    }

    &:not(.has-back-button) {
      .widget-header-section,
      .card-header-section {
        &.detail-title,
        &.detail-more,
        &.detail-custom-action {
          display: none;
        }
      }
    }
  }

  &.show-card-detail {
    .content-main {
      transform: translateX(-110%);
    }

    .content-detail {
      transform: translateX(0);
    }
  }

  .content-main {
    transform: translateX(0);
    width: 100%;
  }

  .content-detail {
    transform: translateX(110%);
  }

  .content-detail,
  .content-main {
    @include transform-transition-list(300ms cubic-bezier(0.17, 0.04, 0.03, 0.94));

    position: absolute;
  }
}

.small-widget {
  min-height: 260px;
}

.widget,
.card {
  &.no-header {
    .card-content,
    .widget-content {
      min-height: 368px;

      .content-top,
      .content-center {
        display: flex;
      }

      .content-center {
        flex-direction: column;
        align-items: flex-start;
      }
    }
  }
}

.card-header,
.widget-header {
  border-bottom: none;
  height: 48px;
  line-height: normal;

  .card-title,
  .widget-title {
    font-size: $ids-size-font-px-20;
    font-weight: $ids-number-font-weight-base;
    line-height: $ids-number-font-line-height-sm;

    ~ svg.icon {
      top: 1px;
    }

    + p {
      line-height: 1.4rem;
    }
  }
}

.card-content,
.widget-content {
  .card-group-action,
  .widget-group-action {
    border-top: 1px solid $listview-border-color;
  }

  .listview:not(.card-list):not(.link-list) li:first-child {
    border-top: 1px solid $listview-border-color;
  }

  .listview-search {
    display: flex;

    .listview-filter-wrapper {
      background-color: transparent;
      border: none;
      display: flex;
      z-index: 10;
    }

    .searchfield-wrapper {
      .btn-icon:hover {
        background-color: $button-color-tertiary-hover-background-new;
      }
    }
  }

  .listview {
    overflow: hidden;
    height: auto;

    ul li:last-child {
      border-bottom-color: transparent;
    }
  }
}

.card-header,
.widget-header {
  &:not(.expandable-card-header) {
    align-items: center;
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    margin: 0;
    padding-bottom: 0;
    padding-inline-start: 16px;
    padding-inline-end: 8px;
    padding-top: 0;
    width: 100%;

    &:has(+ .card-content .instance-count) {
      height: 40px;
      padding-top: 8px;
    }
  }

  > button.btn-actions:not(.has-toolbar) {
    position: relative;

    svg.icon {
      top: 0;
    }
  }

  .widget-title {
    margin: 0;
  }

  &:not(.has-toolbar) {
    > .btn-actions {
      inset-inline-end: 8px;
      top: 7px;
      position: absolute !important
    }
  }
}

.card-header-section,
.widget-header-section {
  white-space: nowrap;
  width: auto;

  &.title,
  &.custom-action,
  &.detail-title,
  &.detail-custom-action {
    flex-grow: 1;
  }

  &.custom-action button
  &.detail-custom-action button {
    margin: 0;
  }

  &.title {
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
      display: inline;
      font-size: $ids-size-font-px-20;
      font-weight: $ids-number-font-weight-base;
      line-height: $ids-number-font-line-height-sm;
    }

    .badge {
      left: 4px;
      padding: 1px;
      position: relative;
      top: -6px;
    }
  }

  &.title,
  &.detail-title {
    overflow: ellipsis;
    overflow-x: hidden;
    overflow-y: auto;
    text-overflow: ellipsis;
  }

  &.title + &.custom-action {
    text-align: right;
  }

  &.detail-title+&.detail-custom-action {
    text-align: right;
    margin-top: -1px;
  }

  &.custom-action > .btn-icon,
  &.detail-custom-action > .btn-icon {
    margin: 0;
  }
}

html[dir='rtl'] {
  .card-header,
  .widget-header {
    &:not(.expandable-card-header) {
      margin: unset;
    }


    h2 ~ svg.icon.has-tooltip {
      margin-right: 5px;
      top: -1px;
    }

    .widget-header-section.title .badge {
      left: -4px;
    }

    .widget-header-section.custom-action,
    .widget-header-section.detail-custom-action {
      display: flex;
      justify-content: flex-end;
    }
  }

  .widget-content {
    .searchfield-wrapper.has-close-icon-button.has-text .btn-icon.close {
      top: 8px;
      right: 315px;
    }

    .listview-search input {
      padding: 9px 34px 9px 28px !important
    }
  }
}

// Show Actions button on touch devices
@media all and (any-pointer: coarse) {
  /* This rule will only apply to touch devices */
  .card:not(.show-buttons) button.btn-actions {
    opacity: 1;
  }
}

