:root {
  --table-padding: 0.5em;
}

// Spacing options
.table-spacing-condensed {
  --table-padding: 0.3em 0.7em;

  th {
    padding-left: 0.7em;
    padding-right: 0.7em;
  }

  td {
    font-size: 12px;
    height: 40px;
  }
}

// default
.table-spacing-regular {
  --table-padding: 0.5em;
}

.table-spacing-relaxed {
  --table-padding: 0.9em;
}

.p-datatable-thead > tr > th {
  box-shadow: inset 0 -2px 0 var(--grid-header-title-txt-color);
  padding: 0.5em;
  text-align: left;
  color: $grid-header-title-txt-color;
  font-weight: 600;
}

.p-datatable-tbody {
  > tr {
    background: $grid-main-row-bg-color;

    > td:not(.empty-message) {
      background: inherit;
      box-shadow: inset 1px -1px 0 $grid-item-border-color;

      &:last-child {
        border-right: 1px solid $grid-item-border-color;
      }

      &:not(.col-actions):not(.col-main-actions):not(.col-message) {
        white-space: pre-wrap;
        word-break: break-word; // Breaks down super long string in table
      }

      /*&.user-disabled {
        opacity: .4;
      }*/
    }

    &:nth-child(even) {
      background-color: $grid-child-row-bg-color;
    }

    &.user--disabled,
    &.vault--disabled {
      color: $grid-disabled-txt-color;
      background: $grid-disabled-row-bg-color;

      > td {
        &:not(.col-actions):not(.col-main-actions) {
          opacity: .4;
          pointer-events: none;
        }
      }
    }
  }

  > tr.p-highlight,
  > tr:nth-child(even).p-highlight {
    background-color: $paginator-active-bg-color;
    color: $secondary-text-color;
  }

  .p-datatable-hoverable-rows & > tr:not(.p-highlight):hover {
    cursor: default;
    background-color: $grid-row-hover-bg-color;
  }
}

.p-datatable div.icon-td-wrapper {
  display: flex;
  align-items: center;
}

// Cells styling
.p-datatable-thead th,
.p-datatable-tbody td,
.p-datatable-tfoot td {
  padding: var(--table-padding);
}

.p-datatable-thead,
.p-datatable-tfoot {
  background-color: $page-header-bg-color;
}

.p-datatable-thead > tr > th > *,
.p-datatable-tbody > tr > td > *{
  vertical-align: middle;
}

.p-datatable-thead > tr > th.col-checkboxes,
.p-datatable-tbody .p-table-row td.col-checkboxes {
  text-align: center;
  justify-content: center;
}

.p-datatable .p-paginator {
  text-align: center;
  background: transparent;
  border: none;
  margin-top: 10px;
}

.p-datatable .p-paginator-right-content {
  display: flex;
  margin-left: auto;
}

.col-checkboxes {
  flex: unset !important;
  width: 52px;
  text-align: center;
}

.col-flex-center {
  display: flex;
  align-items: center;

  hub-view-password-badge {
    margin-left: 5px;
  }
}

.col-main-actions,
.col-actions {
  --table-padding: 2px 4px;
  text-align: center;
}

.empty-message {
  font-style: italic;
  color: $disabled-text-color;
  margin: 0;
  border: none !important;
  white-space: nowrap;
  box-shadow: none;
}

.table-header-boolean-icon,
.table-boolean-icon,
.col-shrink,
.col-actions,
.col-main-actions {
  width: 1%;
  white-space: nowrap;
}

.table-header-boolean-icon,
.table-boolean-icon {
  justify-content: center;
}

.table-boolean-icon {
  text-align: center;
}

.table-header-boolean-icon {
  flex: unset !important;
}

body .edit-dialog-table {
  padding: 1px;
}

.p-datatable-caption,
.p-datatable-summary {
  padding: $headerPadding;
  text-align: center;
  font-weight: bold;
}

.p-datatable-caption {
  border-bottom: 0 none;
}

.p-datatable-summary {
  border-top: 0 none;
}

.p-datatable p-sortIcon {
  display: inline-block;
}

.p-sortable-column {
  color: $default-text-color;

  .p-sortable-column-icon {
    color: $lighter-default-text-color;
    font-size: 18px;
  }

  .p-datatable-tbody &.p-highlight {
    background-color: $default-btn-bg-color;
    color: $secondary-text-color;
    border-top-color: $default-btn-bg-color;

    .p-sortable-column-icon {
      color: $secondary-text-color;
    }
  }
}

.p-sortable-column:not(.p-highlight):hover {
  color: $grid-txt-color;

  .p-sortable-column-icon {
    background: transparent;
    color: $grid-txt-color;
  }

  a:hover {
    background-color: transparent;
    color: $grid-txt-color;
  }
}

.p-column-filter-overlay {
  background-color: $overlay-panel-bg-color;
  color: var(--side-panel-text-color);
  border-radius: $borderRadius;
  box-shadow: $defaultBoxShadow;
  min-width: 12.5rem;
  margin-top: 10px;
  margin-left: -30px;

  .p-column-filter-operator {
    margin: 13px 13px 0 13px;
    padding: 0 0 10px 0;
    border-bottom: 1px solid var(--hr-color);
  }

  .p-dropdown {
    overflow: visible;
  }

  &.p-column-filter-overlay-menu {
    .p-column-filter-constraints {
      padding: 0 13px;

      .p-column-filter-constraint {
        margin: 16px 0;

        &:first-child {
          margin-top: 25px;
        }

        &:last-child {
          margin-bottom: 25px;
        }

        .p-column-filter-matchmode-dropdown {
          margin-bottom: 13px;
        }

        .p-column-filter-remove-button {
          margin-top: 13px
        }
      }
    }

    .p-column-filter-add-rule {
      padding: 0 13px 13px 13px;
    }

    .p-column-filter-buttonbar {
      background-color: var(--dialog-footer-bg-color);
      padding: 13px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }
}

p-columnfilter {
  .p-column-filter {
    position: relative;

    .p-inputtext {
      width: 100%;
    }

    .p-column-filter-clear-button {
      display: none;
    }

    .p-column-filter-menu-button {
      position: absolute;
      right: 10px;

      cursor: pointer;
      color: var(--lighter-default-text-color);

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

      .pi-filter-icon {
        font-size: 18px;
      }
    }
  }
}

.p-column-filter-row {
  p-columnfilterformelement {
    text-align: center;

    p-dropdown {
      .p-dropdown {
        min-width: 0;
        overflow: visible;
        text-align: left;

        .p-dropdown-clear-icon {
          font-size: 13px;
          right: 28px;
        }
      }
    }

    p-multiselect {
      .p-multiselect {
        text-align: left;
      }
    }
  }
}

.p-column-filter-overlay {
  border: 0 none;
  border-radius: $borderRadius;
  box-shadow: $defaultBoxShadow;
  min-width: 12.5rem;
}

.p-column-filter-overlay .p-column-filter-row-items {
  padding: 0;
}

.p-column-filter-overlay .p-column-filter-row-items .p-column-filter-row-item {
  margin: 0;
  padding: 0.5rem;
  border: 0 none;
  transition: none;
}

.p-column-filter-overlay .p-column-filter-row-items .p-column-filter-row-item.p-highlight {
  background-color: var(--action-btn-popup-pressed-bg-color);
}

.p-column-filter-overlay .p-column-filter-row-items .p-column-filter-row-item:not(.p-highlight):not(.p-disabled):hover {
  background-color: var(--action-btn-popup-hover-bg-color);
}

.p-column-filter-overlay .p-column-filter-row-items .p-column-filter-separator {
  border-top: 1px solid var(--hr-color);
}

.p-column-filter-overlay-menu .p-column-filter-operator {
  padding: 1rem;
  border-bottom: 1px solid var(--hr-color);
  margin: 0;
  border-top-right-radius: $borderRadius;
  border-top-left-radius: $borderRadius;
}

.p-column-filter-row-item:hover:first-child {
  border-top-right-radius: $borderRadius;
  border-top-left-radius: $borderRadius;
}

.p-column-filter-row-item:hover:last-child {
  border-bottom-right-radius: $borderRadius;
  border-bottom-left-radius: $borderRadius;
}

.p-column-filter-overlay-menu .p-column-filter-constraint {
  padding: 1rem;
  border-bottom: 1px solid var(--hr-color);
}

.p-column-filter-overlay-menu .p-column-filter-constraint .p-column-filter-matchmode-dropdown {
  margin-bottom: 0.5rem;
}

.p-column-filter-overlay-menu .p-column-filter-constraint .p-column-filter-remove-button {
  margin-top: 0.5rem;
}

.p-column-filter-overlay-menu .p-column-filter-constraint:last-child {
  border-bottom: 0 none;
}

.p-column-filter-overlay-menu .p-column-filter-add-rule {
  padding: 1rem 1rem;
}

.p-column-filter-overlay-menu .p-column-filter-buttonbar {
  padding: 1rem;
}

@media screen and (-webkit-min-device-pixel-ratio: 0) {
  .p-datatable-scrollable-body > table {
    width: calc(100% + 6px);
  }
}

/* Sticky header */
.sticky-header .p-datatable-table {
  border-spacing: 0;

  .p-datatable-thead > tr {
    th {
      background-color: var(--layout-container-bg-color);
      @include sticky();
    }

    &.secondary-color > th {
      background-color: var(--entry-container-overview-bg-color);
    }
  }
}

/* Flex sticky header */
.flex-sticky-header {
  .p-datatable {
    height: 100%;
    display: flex;
    flex-direction: column;

    .p-datatable-wrapper {
      @include custom-scrollbar();

      thead {
        @include sticky();

        // Change table header background color when in dialog
        .p-dialog & {
          background-color: var(--dialog-bg-color);
          box-shadow: -1px 0 0 var(--dialog-bg-color);
        }

        // Change table header background color when in dialog
        .dashboard-content & {
          background-color: var(--entry-container-bg-color);
          box-shadow: -1px 0 0 var(--entry-container-bg-color);
        }
      }

      tbody:nth-of-type(1) tr:nth-of-type(1) td {
        border-top: none !important;
      }
    }
  }
}

.p-dialog {
  .p-datatable-scrollable .p-datatable-thead {
    background-color: var(--dialog-bg-color);
  }

  .table-style-v2 {
    .p-datatable-header {
      background-color: var(--grid-header-bg-color);
      border-color: $grid-item-border-color;
    }

    .p-datatable-thead,
    .p-datatable-tfoot {
      background-color: var(--grid-header-bg-color);
    }
  }
}
