/* ==========================================================================
  Additions to bootstrap/table
   ========================================================================== */

/* Variables
   ========================================================================== */

$selected-row-color: #FFC !default;

/* Basic setup
   ========================================================================== */

table th {
  color: $gray-dark;
  font-weight: $headings-font-weight;
}

.table > thead > tr > th {
  vertical-align: middle;
}

.table {
  tbody {
    background: #FFF;
  }
}

.table {
  tbody .selected td {
    background-color: $selected-row-color;
  }
}

/* Actions column
   ========================================================================== */

.table-actions-column {
  > .btn,
  > .btn-toolbar,
  > .dropdown > .btn {
    float: right;
  }
}

/* Table modifiers
   ========================================================================== */

.table {
  &.table-align-middle {
    td {
      vertical-align: middle;
    }
  }
}

/* Enhanced clickability
   ========================================================================== */

.table.table-enhanced-clickability {
  td, th {
    padding: 0;
  }

  td,
  th {
    > a,
    > .holder {
      display: block;
      width: 100%;
      cursor: pointer;
      padding: $table-condensed-cell-padding;;
      color: $gray;
    }
  }
  
  tbody {
    tr{
      &:hover,
      &:active,
      &:focus {
        background-color: $gray-lighter;
      }
      > td > a {
        &:hover,
        &:active,
        &:focus {
          text-decoration: none;
        }
      }
    }
  }

  th {
    > a,
    > .holder {
      color: $gray-dark;
    }
  }

  tbody .selected {
    > td .holder,
    &:hover > td .holder,
    .table-checkbox-column > .holder
    > td a,
    > td a:hover {
      background-color: $selected-row-color;
    }
  }

}

/* Columns with specific widths
   ========================================================================== */

.table-reorderable-column,
.table-checkbox-column {
  width: 30px;
  text-align: center;
}

.table-reorderable-column {
  svg {
    &:hover * {
      fill: $brand-primary;
    }
  }
}

.table-thumbnail-column {
  width: 100px;
}

.table-thumbnail-column-sm {
  width: 30px;
}

/* ==========================================================================
   Sortable table
   ========================================================================== */

.table-sortable {

  .sortable-label {
    padding-right: 12px;
  }

  th {
    padding: 0;
  }

  th.unsortable {
    padding: $table-cell-padding;
  }

  &.table-condensed th {
    padding: $table-condensed-cell-padding;
  }

  &.table-enhanced-clickability th {
    padding: 0;
  }

  // Extends caret with a flipped caret, to make a sortable indicator composed of .caret and .caret.flipped
  .caret.flipped {
    border-bottom: $caret-width-base solid $dropdown-caret-color;
    border-right: $caret-width-base solid transparent;
    border-left:  $caret-width-base solid transparent;
    // Firefox fix for https://github.com/twbs/bootstrap/issues/9538. Once fixed,
    // we can just straight up remove this.
    border-top: 0 dotted;
  }

  .sort-indicator {
    position: absolute;
    right: 5px;
    top: 5px;
    width: 12px;
    display: inline-block;
    height: 10px;
    white-space: nowrap;
    .caret {
      @include opacity(0.3);
      position: absolute;
      top: auto;
      bottom: 0;
    }
    .caret.flipped {
      top: 0;
    }
  }
  
  &.table-enhanced-clickability .sort-indicator {
    top: 12px;
  }

  .sortable {
    a {
      position: relative;
      white-space: nowrap;
      display: block;
      color: $gray-dark;
    }
  }

  .sorted-asc,
  .sorted-desc,
  .sortable {
    a {
      text-decoration: none;
    }
  }

  .sortable:hover {
    background: darken($table-border-color, 20%);
    border-bottom-color: darken($table-border-color, 30%);
    a {
      color: #FFF;
    }
  }

  .sorted-asc,
  .sorted-desc {
    &, &:hover {
      background: lighten($table-border-color, 10%);
      border-bottom-color: darken($table-border-color, 10%);
      a {
        color: $gray-dark;
      }
    }
  }

  .sorted-asc a {
    cursor: s-resize;
  }

  .sorted-desc a {
    cursor: n-resize;
  }

  .sorted-asc .sort-indicator {
    .caret {
      @include opacity(1);
    }
    .caret.flipped {
      @include opacity(0.3);
    }
  }

  .sorted-desc .sort-indicator {
    .caret {
      @include opacity(0.3);
    }
    .caret.flipped {
      @include opacity(1);
    }
  }

}

/* Resetted table
   ========================================================================== */

.table.table-reset {
  tr > td,
  tr > th {
    padding: $table-condensed-cell-padding/3 $table-condensed-cell-padding;
    border: none;
  }
}

/* Table with left aligned labels (table headings)
   ========================================================================== */

.table-data-labels-left {
  th {
    width: 200px;
  }
}

.table .table-field-group-header-row th {
  background: $gray-lighter;
  font-size: 12px;
  padding-top: $table-condensed-cell-padding/2;
  padding-bottom: $table-condensed-cell-padding/2;
}