// Override dataTables.bootstrap4.css defaults
table.dataTable { border-collapse: collapse !important; }

// Override default hover effect
table.dataTable.table-striped > tbody > tr.odd > *,
table.dataTable.table-striped > tbody > tr.odd.selected > *,
table.dataTable.table-hover > tbody > tr:hover > *,
table.dataTable.table-hover > tbody > tr.selected:hover > * { 
  box-shadow: unset; 
}

// Override default sorting
table.dataTable thead > tr > th.sorting:before, 
table.dataTable thead > tr > th.sorting_asc:before, 
table.dataTable thead > tr > th.sorting_desc:before,
table.dataTable thead > tr > th.sorting_asc_disabled:before,
table.dataTable thead > tr > th.sorting_desc_disabled:before,
table.dataTable thead > tr > td.sorting:before,
table.dataTable thead > tr > td.sorting_asc:before,
table.dataTable thead > tr > td.sorting_desc:before,
table.dataTable thead > tr > td.sorting_asc_disabled:before,
table.dataTable thead > tr > td.sorting_desc_disabled:before {
  content: '';
}

table.dataTable thead > tr > th.sorting:after,
table.dataTable thead > tr > th.sorting_asc:after,
table.dataTable thead > tr > th.sorting_desc:after,
table.dataTable thead > tr > th.sorting_asc_disabled:after,
table.dataTable thead > tr > th.sorting_desc_disabled:after,
table.dataTable thead > tr > td.sorting:after,
table.dataTable thead > tr > td.sorting_asc:after,
table.dataTable thead > tr > td.sorting_desc:after,
table.dataTable thead > tr > td.sorting_asc_disabled:after,
table.dataTable thead > tr > td.sorting_desc_disabled:after {
  content: '';
}

table.dataTable thead > tr > th.sorting, table.dataTable thead > tr > th.sorting_asc, table.dataTable thead > tr > th.sorting_desc, table.dataTable thead > tr > th.sorting_asc_disabled, table.dataTable thead > tr > th.sorting_desc_disabled,
table.dataTable thead > tr > td.sorting,
table.dataTable thead > tr > td.sorting_asc,
table.dataTable thead > tr > td.sorting_desc,
table.dataTable thead > tr > td.sorting_asc_disabled,
table.dataTable thead > tr > td.sorting_desc_disabled {
  padding: 0.5em 0.5em 0.5em 0.5em;
}

table.dataTable.table-sm > thead > tr > th:not(.sorting_disabled) { padding-right: 0.5em; }
table.dataTable thead > tr > th.sorting_disabled { padding-bottom: 8px; }

table.dataTable > thead th {
  background-repeat: no-repeat;
  > span { padding-right: 1rem; }
}

table.dataTable > thead .sorting {
  background-image: asset-data-url('dataTables/sort.svg');
  background-position: right 0.25rem top 0.25rem;
}

table.dataTable > thead .sorting_asc {
  background-image: asset-data-url('dataTables/sort-up.svg');
  background-position: right 0.25rem top 0.25rem;
}

table.dataTable > thead .sorting_desc {
  background-image: asset-data-url('dataTables/sort-down.svg');
  background-position: right 0.25rem top 0.25rem;
}

// The New button
table.dataTable thead {
  th.col-actions {
    text-align: right;
    span { display: block; }
  }
}

// Turbolinks destroy fix
.dataTables_wrapper {
  table.dataTable {
    tr.effective-datatables-inline-row { visibility: collapse; }
  }
}

// When Inline Expanded
.dataTables_wrapper.effective-datatables-inline-expanded {
  .dt-buttons { opacity: 0.4; }
  .dataTables_entries { opacity: 0.4; }
  .dataTables_paginate { opacity: 0.4; }

  table.dataTable {
    tr { opacity: 0.4; }

    tr.effective-datatables-inline-row {
      tr { opacity: 1.0; }

      visibility: visible;
      opacity: 1.0;

      &:hover { background-color: inherit; }
    }
  }
}

// When Inline Expanded with Nested
.dataTables_wrapper.effective-datatables-inline-expanded {
  .dataTables_wrapper_nested {
    .dt-buttons { opacity: inherit; }
    .dataTables_entries { opacity: inherit; }
    .dataTables_paginate { opacity: inherit; }
  }
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
  color: #0275d8;
}
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control.arrow-right::before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control.arrow-right::before {
  color: #0275d8;
}
table.dataTable.dtr-inline.collapsed > tbody > tr.parent > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr.parent > th.dtr-control:before {
  color: #0275d8;
}

// Collapsed Responsive View
table.dataTable > tbody > tr.child {
  td, th { border: none; }

  ul.dtr-details > li {
    border-bottom: none;
    padding-left: 0.5em;

    &:hover { background-color: rgba(0, 0, 0, 0.075); }

    span.dtr-title { min-width: 175px; margin-bottom: 0.25em; }
    span.dtr-data { white-space: nowrap; }
    .col-resource_item { margin-bottom: 0.25em; }
  }
}

table.dataTable.collapsed  {
  th.col-bulk_actions:first-child { div { margin-left: 18px; } }
}

// Buttons
.dataTables_buttons {
  text-align: right;
  .btn { font-size: 0.75rem; }
}

div.dt-button-collection-title { padding: 0px; }

.dt-button.buttons-colvisGroup-first {
  padding-top: 0.5rem;
  border-top: 1px solid #dee2e6;
}

// Search bar
table.dataTable > thead {
  tr th {
    border-bottom: none;
    white-space: nowrap;

    .form-group {
      font-weight: normal;
      margin-bottom: 0em;

      input { max-height: 38px; }
    }

    &.col-bulk_actions {
      label {
        cursor: pointer;
      }
    }
  }
}

// Filters
.effective-datatables-filter { 
  p { margin-bottom: 0; }
}

.form-group.datatables-filters-present {
  margin-top: 1.75em;
}

// Processing div
div.dataTables_wrapper div.dataTables_processing {
  margin: -26px 25% 0px 25%;

  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  text-align: center;
  padding: 1em;
}

// Processing success
div.dataTables_wrapper div.dataTables_processing.alert-success {
  margin: -26px 10% 0px 10%;
  width: 80%;
}

// Processing error
div.dataTables_wrapper div.dataTables_processing.alert-danger {
  margin: -26px 10% 0px 10%;
  width: 80%;
}

// Simple styles
table.dataTable.hide-sort > thead {
  .sorting { background-image: none; cursor: default; }
  .sorting_asc { background-image: none; cursor: default; }
  .sorting_desc { background-image: none; cursor: default; }
}

table.dataTable.hide-search > thead {
  .form-group { display: none; }
}

table.dataTable.hide-buttons {
  .col-bulk_actions { display: none; }
}

// Datatables entries
@media screen and (max-width: 767px) {
  div.dataTables_wrapper div.dataTables_entries { text-align: center; }
}

// Showing x to y of z entries with 25 per page
.dataTables_wrapper .dataTables_entries {
  color: #909090;
  font-size: 12px;

  // Showing 1 to 2 of 2 entries (filtered from 10 total entries)
  div.dataTables_info {
    display: inline-block;
    padding: 0.25em 0em 0.25em 0.25em;
  }

  // with 25 per page
  div.dataTables_length {
    display: inline-block;

    // Apply custom style to the inline x per page select
    span.select2-container {
      margin: 0 1em;
      max-width: 6.0rem;
      min-width: 3.0rem;

      .select2-selection__rendered { padding: 0em; color: #909090; }
    }

    span.select2-container.select2-container--open { min-width: 3.0rem; max-width: 6.0rem; }
    span.select2-container.select2-container--focus { border: none; box-shadow: none; }
    span.select2-selection.select2-selection--single:focus { outline: none; }
  }
}

// Column specific adjustments
table.dataTable {
  th.col-price, td.col-price { text-align: right; }
  th.col-decimal, td.col-decimal { text-align: right; }
  th.col-right, td.col-right { text-align: right; }

  th.col-th-left { text-align: left !important; }
  td.col-td-left { text-align: left !important; }

  th.col-th-center { text-align: center !important; }
  td.col-td-center { text-align: center !important; }

  th.col-th-right { text-align: right !important; }
  td.col-td-right { text-align: right !important; }

  td.col-bulk_actions {
    label {
      cursor: pointer;
      vertical-align: top;
    }
  }

  tfoot {
    .col-price { text-align: right; }
    .col-decimal { text-align: right; }
    .col-right { text-align: right; }
  }

  td.col-actions {
    white-space: nowrap;
    text-align: right;
  }

  td.col-reorder {
    cursor: move;
  }

  td.col-resource_item { word-break: keep-all; }
}

// show/hide adjustments
.dropdown-menu-right {
  border-top-right-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

.dt-button.dropdown-item {
  padding: 0.25rem 0 0.25rem 1.5rem;
  font-size: 12px !important;
}

div.dt-button.dropdown-item::after {
  margin-top: -9px;
}

div.dt-button-collection .dt-button-active {
  padding-right: 0;
}

div.dt-button-collection .dt-button-active:after {
  right: auto;
  left: 0.5rem;
}

// Nested Datatables
.nested-datatable-container-parent {
  padding-left: 0.25em;
  padding-right: 0.25em;
  container-type: inline-size;
}

.nested-datatable-container {
  width: 100%;
}
