:root {
  --itf-primary: #1A4A97;
  --itf-table-header-font-size: 12px;
  --itf-table-content-font-size: 16px;
  --itf-table-selected-bg: #f9fafc;
  --itf-table-active-bg: #d4dbec;
  --itf-table-alt-bg: #F9FAFB;
  --itf-table-alt-selected-bg: #eff1f3;
  --itf-table-header-bg: #f5f7f8;
  --itf-table-header-color: #7A818EA5;
  --itf-table-mirror-bg: #F2F4F7;
  --itf-table-border-color: transparent; //var(--itf-table-header-bg);
  --itf-table-header-border-color: #7A818E33;
  --itf-table-border-base-color: var(--itf-table-header-bg); // кольори границь таблиці без внутрішніх рядків
  --itf-table-border-base-width: 2px;
  --itf-table-hover-header-bg: #dfe5ef;
  --itf-table-hover-bg: #e9edf5;
  --itf-table-bg: var(--bs-body-bg);
  --itf-table-min-width: 45px;
  --itf-table-input-border-color: #aaaba6;
  --itf-table-input-focus-border-color: #0028aa;
  --itf-table-header-subtitle-color: #aeafaa;
  --itf-table-summary-text: var(--bs-tertiary-color);
  --itf-table-table-border-radius: 1rem;
  --itf-table-header-height: 2.25rem;

  --group-title-height: 40px;
  --table-row-height: none;
  --table-small-row-size: 3rem;
  --shadow-area-width: 12px;
  --indicator-area-width: 38px;
  --bs-dropdown-item-border-radius: .5rem;
}
// dark
body[data-theme="dark"] {
  --itf-table-bg: var(--bs-body-bg);
  --itf-table-alt-bg: #121212;
  --itf-table-hover-bg: #393b41;
  --itf-table-header-bg: #0f0f0f;
  --itf-table-hover-header-bg: #252525;
  --itf-table-border-color: #383b41;
  --itf-table-input-focus-border-color: #252525;
  --itf-table-selected-bg: #011534;
  --itf-table-active-bg: #022e72;
  --itf-table-summary-text: #82909d80;
}
.itf-table2 {
  font-size: var(--itf-table-content-font-size, var(--itf-table-font-size));
  position: relative;

  .itf-cell-center {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
  }
  .scrollable {
    -webkit-overflow-scrolling: touch;
    overflow: hidden scroll;
    height: 100%;
  }
  .scroller {
    margin-bottom: 12px;
  }
  .scrollable-x {
    overflow-x: scroll;
    padding-right: 4px;
    padding-top: 10px; // щоб drag для колонок був видимий
  }
  &.table-absolute {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
  }
  &.table-striped {
    .table-view-item:nth-child(even) {
      --itf-table2-row-bg: var(--itf-table-alt-bg);
    }
  }
  &.table-clickable {
    .table-view-item {
      cursor: pointer;
    }
  }

  &_mass-operations {
    .btn-default {
      color: #fff !important;
      background-color: #494A55;
    }
  }

  .table-view-item-actions {
    background-image: linear-gradient(90deg, transparent 0, var(--itf-table2-row-bg) 10px);
    position: sticky;
    top: 0;
    bottom: 0;
    right: -.5rem;
    z-index: 8;
    display: flex;
    align-items: center;

    @media (max-width: 768px) {
      position: relative;
      opacity: 1;
    }
  }
  .on-hover {
    opacity: 0;
    width: 0;
    padding: 4px .5rem;
    overflow: hidden;
    pointer-events: none;
    position: absolute;
    right: 0;
    background: linear-gradient(90deg, transparent 0, var(--itf-table2-row-bg) 10px);

    @media (max-width: 768px) {
      width: max-content;
      opacity: 1;
      position: relative;
    }
  }
  .table-row-template:hover .on-hover {
    width: max-content;
    opacity: 1;
    pointer-events: all;
  }
  .table-row-template:hover .hide-hover {
    opacity: 0;
    pointer-events: none;
  }
  .table-header-add-column {
    border-top-right-radius: var(--itf-table-table-border-radius);
    background-image: linear-gradient(90deg, var(--itf-table2-row-bg) 0, var(--itf-table-header-bg) 10px);
  }

  &__header-icon {
    margin-top: -1px;
  }
  &__drag-column {
    position: absolute;
    top: -.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.2s;
    cursor: move;
    height: 1.5rem !important;
    padding: 0 !important;
    min-height: auto !important;
  }
  .last-sticky-column {
    position: relative;
    border-right: 0 none !important;
    &:after {
      content: "";
      position: absolute;
      right: 0;
      top: 0;
      width: 20px;
      z-index: 1;
      bottom: 5px;
      box-shadow: 0px 4px 20px 0px #0000001A;
    }
  }
  .table-group-wrapper {
    .table-row-template {
      &:after {
        content: "";
        position: absolute;
        display: block;
        height: 12px;
        left: 0;
        right: 0;
        top: -12px;
        z-index: 4;
        background: var(--itf-table-bg);
      }
    }
  }
  &__header {
    --itf-table2-row-bg: var(--itf-table-header-bg);
    //background-color: var(--itf-table-header-bg);
    position: sticky;
    top: 0;
    z-index: calc(var(--row-count) + 1);
    font-size: var(--itf-table-header-font-size, var(--itf-table-font-size));
    color: var(--itf-table-header-color);
    text-transform: uppercase;

    .table-view-header-value:hover {
      .itf-table2__drag-column {
        opacity: 1;
      }
    }

    .table-view-item-value.extra {
      border-top-right-radius: var(--itf-table-table-border-radius);
    }
    &.no-header {
      --table-row-height: 0px;
      --table-small-row-size: 0px;

      .table-view-header-value {
        border-top: 0 none;
        border-bottom: 0 none;
      }
    }
    .table-header.draggable-mirror{
      z-index: 100000001;
      border-radius: .25rem;
      border: 1px solid var(--itf-primary);
      color: var(--itf-primary);
      background-color: var(--itf-table-hover-header-bg);

      .itf-table2__drag-column {
        opacity: 1;
        display: block;
      }
    }
    .itf-table2 & .boundary.right {
      top: var(--itf-table-table-border-radius);
    }
    .itf-table2 & .boundary.top, .itf-table2 & .boundary.bottom {
      border-color: transparent;// var(--itf-table-border-color)
    }
    .table-row-template {
      display: flex;
      position: relative;
      align-items: stretch;
      height: auto;
      user-select: none;
      background: var(--itf-table-bg);
      min-height: var(--itf-table-header-height);

      &:not(.draggable-container--is-dragging):hover .table-view-header-value {
        z-index: 39;
      }
      &:not(.draggable-container--is-dragging):hover .sticky {
        z-index: 40;
      }
      &:after {
        content: "";
        position: absolute;
        display: block;
        height: 12px;
        left: 0;
        right: 0;
        top: -12px;
        z-index: 4;
        background: var(--itf-table-bg);
      }
    }
    .table-view-header-value {
      cursor: pointer;
      align-items: center;
      justify-content: center;
      height: auto;
      white-space: nowrap;
      //border-top: 0;
      //border-top: 1px solid var(--itf-table-border-color);
      border-left: 0;
      //border-bottom: 1px solid var(--itf-table-border-color);
      position: relative;
      display: flex;
      min-width: var(--itf-table-min-width);
      background-color: var(--itf-table-header-bg);
      //background-color: var(--bs-body-bg);
      //background-color: rgb(238 238 238 / 1);
      //font-weight: 500;
      &:not(.reserved) {
        border-right: 1px solid var(--itf-table-header-border-color);
      }
      &.active .table-header {
        color: var(--itf-primary);
        background-color: var(--itf-table-hover-header-bg);
      }

      //&.last-sticky-column {
      //  border-right-color: var(--bs-border-color);
      //}
      &.reserved {
        border-left: var(--itf-table-border-base-width) solid var(--itf-table-border-base-color);
        left: var(--shadow-area-width);
        width: var(--indicator-area-width);
        min-width: 1rem;

        &.sticky {
          border-top-left-radius: var(--itf-table-table-border-radius);
          z-index: 13;
        }
      }
      &.sticky {
        position: sticky;
        position: -webkit-sticky;
        z-index: calc(var(--row-count) + 4);
      }
    }
    .table-header {
      flex: 0 0 auto;
      //overflow: hidden;
      width: 100%;
      height: 100%;
      text-overflow: ellipsis;
      gap: 0.25rem;
      align-items: center;
      position: relative;
      z-index: 2;
      background: var(--itf-table-header-bg);

      & > div {
        padding: .5rem .75rem;
        height: 100%;
        min-height: var(--table-row-height);
        align-items: start;
        justify-content: space-between;
        display: flex;
      }

      &.table-header-add-column {
        text-overflow: clip;
      }
    }
    .resize-handle {
      width: 2px;
      bottom: 0;
      position: absolute;
      right: -1px;
      top: 0;
      background: var(--itf-primary);
      border-radius: 2px;
      z-index: 100;
      opacity: 0;
      cursor: ew-resize;
      transition: .2s;

      &:hover {
        opacity: 1;
      }
    }
    .context-menu-toggle {
      flex: 1 1 auto;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;

      span {
        font-size: 12px;
        line-height: 36px;
      }
    }
    .itf-sortable-list {
      display: flex;
    }
    .table-view-header-space {
      height: 100%;
      position: absolute;
      left: 0;
      display: none;
      background: transparent;
      z-index: 100;
      width: 2px;
      margin-left: -1px;

      &.right {
        left: auto;
        right: 0;
        top: 0;
      }
      &.active {
        display: block;

        .drag-handle {
          opacity: 1;
        }
        &.over {
          background: var(--itf-primary);
        }
      }
    }
    .draggable-container--over .table-view-header-space {
      display: block;
    }
    .draggable-container--over .draggable--over .table-view-header-space {
      background: var(--itf-primary);
    }
    .table-view-header-space > .table-view-header-dropzone {
      position: absolute;
      top: 0;
      right: -50px;
      bottom: 0;
      left: -50px;
    }
    .table-view-header-value:not(.reserved):hover .table-header {
      color: var(--itf-primary);
      //background-color: var(--itf-table-hover-header-bg);
    }
    .draggable-source--is-dragging {
      z-index: 1000;
      color: transparent;
      background: var(--itf-table-mirror-bg);
    }
    .draggable-container--is-dragging {
      .itf-table2__drag-column, .resize-handle {
        display: none;
      }
    }
  }

  &__title-container, &__header-title, &__title, &__subtitle {
    min-width: 0; // for text ellipsis
  }
  &__subtitle {
    color: var(--itf-table-header-subtitle-color);

    .draggable-source--is-dragging & {
      color: transparent;
    }
  }

  .table-view-item {
    --itf-table2-row-bg: var(--itf-table-bg);
    --itf-table2-border-color: var(--itf-table-border-base-color);

    background-color: var(--itf-table2-row-bg);

    &.selected {
      --itf-table2-border-color: var(--bs-body-color);
    }
    &:hover {
      --itf-table2-row-bg: var(--itf-table-hover-bg) !important;
    }
    &.selected {
      --itf-table2-row-bg: var(--itf-table-selected-bg) !important;
      &:nth-child(even) {
        --itf-table2-row-bg: var(--itf-table-alt-selected-bg) !important;
      }

      &:hover {
        --itf-table2-row-bg: var(--itf-table-hover-bg) !important;
      }
    }
    &.active {
      --itf-table2-row-bg: var(--itf-table-active-bg) !important;
    }

    .indicator {
      border-left: var(--itf-table-border-base-width) solid var(--itf-table2-border-color);
    }

    &.disabled {
      .table-view-item-value {
        opacity: 0.5;
      }
    }
  }

  &__row-divider {
    background-color: #F7F8FA;
    height: 5px;
    padding: 0;
    border-top: 1px solid rgba(238, 238, 238, 1);
    border-bottom: 1px solid rgba(238, 238, 238, 1);
  }
  //&:hover, &.permanent-editable-border {
  //  .table-view-item-value.editable {
  //    .form-control {
  //      border: 1px solid var(--itf-table-input-border-color);
  //    }
  //  }
  //}
  .table-view-item-value-content {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    background: var(--itf-table2-row-bg)
  }
  .table-view-item-value {
    text-overflow: ellipsis;
    align-items: stretch;
    display: flex;
    position: relative;
    min-width: var(--itf-table-min-width);
    background: var(--itf-table2-row-bg);

    .itf-table2__striped & {
      border-right: 1px solid var(--bs-border-color);
      border-bottom: 1px solid var(--bs-border-color);
    }
    &.editable {
      padding: 2px;

      //.form-control {
      //  border-radius: 0;
      //  border: 1px solid transparent;
      //  background-color: transparent;
      //  box-shadow: none;
      //
      //  &:focus {
      //    border-color: var(--itf-table-input-focus-border-color);
      //  }
      //}
    }

    &.highlight-drop-column {
      position: relative;

      &:after {
        content: "";
        height: 100%;
        z-index: 1000;
        width: 2px;
        background: var(--itf-primary);
        margin-left: -1px;
        position: absolute;
        left: 0;
      }
      &.right:after {
        left: auto;
        right: 0;
      }
    }

    &.sticky {
      z-index: 4;
      position: -webkit-sticky;
      position: sticky;
    }
  }


  .boundary {
    z-index: 3;
    position: absolute;

    &.top, &.bottom {
      width: 100%;
      border-top: thin solid #0000;
      top: 0;
    }

    &.left, &.right {
      height: 100%;
      border-left: thin solid #0000;
      left: 0;
    }

    &.right {
      left: auto;
      border-right: var(--itf-table-border-base-width) solid var(--itf-table-border-base-color);
      right: 0;
    }

    &.bottom {
      top: auto;
      bottom: 0;
    }
  }

  .table-group-operations {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    height: 2rem;
    transform: rotateX(90deg);
    transition: transform 0.3s;

    &.visible {
      transform: rotateX(0deg);
    }
  }
}
