/* Table helper classes for alternate styles */
/* MIT License | Copyright (c) Stephan Ango (@kepano) */

.table-small {
  --table-text-size: var(--font-smaller);
}
.table-tiny {
  --table-text-size: var(--font-smallest);
}

.row-hover {
  --table-row-background-hover: var(--background-modifier-hover);
  --table-row-alt-background-hover: var(--background-modifier-hover);
}

.row-alt {
  --table-row-alt-background: var(--background-primary);
  --table-row-alt-background-hover: var(--background-primary);
}
.col-alt .markdown-rendered:not(.cards) {
  --table-column-alt-background: var(--background-primary);
}

.table-tabular table:not(.calendar) {
  font-variant-numeric: tabular-nums;
}

.table-center {
  .markdown-preview-view .markdown-preview-sizer table,
  &.markdown-preview-view .markdown-preview-sizer table,
  .markdown-source-view.mod-cm6 .table-wrapper,
  &.markdown-source-view.mod-cm6 .table-wrapper {
    margin: 0 auto;
  }
}

.table-lines {
  --table-border-width: var(--border-width);
  --table-header-border-width: var(--border-width);
  --table-column-first-border-width: var(--border-width);
  --table-column-last-border-width: var(--border-width);
  --table-row-last-border-width: var(--border-width);
  --table-edge-cell-padding: 8px;
  --table-edge-cell-padding-first: 8px;
  --table-edge-cell-padding-last: 8px;
  --table-add-button-border-width: 1px;
}

.table-nowrap {
  --table-white-space: nowrap;
}
.table-nowrap-first {
  table {
    thead > tr > th:first-child,
    tbody > tr > td:first-child {
      --table-white-space: nowrap;
    }
  }
}

.trim-cols,
.table-nowrap .table-wrap {
  --table-white-space: normal;
}

.table-numbers {
  table:not(.calendar) {
    counter-reset: section;
    > thead > tr > th:first-child {
      white-space: nowrap;
      &::before {
        content: " ";
        padding-right: 0.5em;
        display: inline-block;
        min-width: 2em;
      }
      .table-cell-wrapper,
      .cm-s-obsidian {
        display: inline-block;
        min-width: 10px;
      }
    }
    &:not(.table-editor) tr > :first-child,
    &.table-editor tr > :first-child .table-cell-wrapper {
      > .node-insert-event,
      img {
        max-width: calc(100% - 2.5em);
      }
    }
    &:not(.table-editor) > tbody > tr > td:first-child,
    &.table-editor > tbody > tr > td:first-child .table-cell-wrapper {
      white-space: nowrap;
      &::before {
        counter-increment: section;
        content: counter(section) " ";
        text-align: center;
        padding-right: 0.5em;
        display: inline-block;
        min-width: 2em;
        color: var(--text-faint);
        font-variant-numeric: tabular-nums;
      }
      .cm-s-obsidian {
        display: inline-block;
        min-width: 10px;
      }
    }
  }
}

.row-lines div:not(.el-table):not(.table-wrapper) > table {
  > tbody > tr > td {
    border-bottom: var(--table-border-width) solid var(--table-border-color);
  }
  > tbody > tr:last-child > td {
    border-bottom: none;
  }
}

.col-lines div:not(.el-table):not(.table-wrapper) > table {
  > tbody > tr > td {
    border-right: var(--table-border-width) solid var(--table-border-color);
  }
  > tbody > tr > td:last-child {
    border-right: none;
  }
}

.table-lines div:not(.el-table):not(.table-wrapper) > table {
  > tbody > tr > td {
    border: var(--table-border-width) solid var(--table-border-color);
  }

  > tbody > tr:not(:last-child) > td {
    border-bottom: none;
  }

  > tbody > tr > td:not(:last-child) {
    border-right: none;
  }
}
