@mixin grid() {
  .esri-grid {
    background-color: var(--calcite-color-foreground-1);
    width: 100%;
    height: 100%;

    a {
      text-decoration: underline;
      color: var(--calcite-color-text-link);

      &:hover,
      &:focus {
        color: var(--calcite-color-text-highlight);
      }
    }

    vaadin-grid {
      border-block-end: none;
      border-inline: none;
      background-color: inherit;
      color: inherit;
      font-family: inherit;
      font-size: var(--calcite-font-size);
    }

    vaadin-grid::part(cell editing) {
      z-index: 2;
    }

    vaadin-grid::part(frozen-cell),
    vaadin-grid::part(frozen-to-end-cell) {
      z-index: 4;
    }

    vaadin-grid::part(cell last-frozen-cell) {
      overflow: visible;
    }

    vaadin-grid::part(cell text-wrap) {
      text-wrap: wrap;
    }

    vaadin-grid-cell-content {
      box-sizing: border-box !important;
      align-items: center;
      padding: var(--calcite-spacing-xxs) var(--calcite-spacing-sm);
      height: 100%;
      min-height: var(--calcite-font-line-height-fixed-3xl);
    }

    vaadin-grid::part(cell) {
      border-inline-end: var(--calcite-border-width-sm) solid;
      border-color: var(--calcite-color-foreground-3);
      line-height: 28px;
      color: var(--calcite-color-text-1);
    }

    vaadin-grid::part(cell):focus::after {
      outline-color: var(--calcite-color-brand);
    }

    [dir="rtl"]vaadin-grid::part(cell) {
      border-inline-start: var(--calcite-border-width-sm) solid;
    }

    // Adds darkened border to selection column on scroll
    vaadin-grid[overflow~="start"]::part(cell last-frozen-cell) {
      border-inline-end: var(--calcite-border-width-sm) solid var(--calcite-color-text-3);
    }

    [dir="rtl"]vaadin-grid[overflow~="start"]::part(cell last-frozen-cell) {
      border-inline-start: var(--calcite-border-width-sm) solid var(--calcite-color-text-3);
    }

    // Adds darkened border to action column on overflow
    vaadin-grid[overflow~="end"]::part(cell first-frozen-to-end-cell) {
      border-inline-start: var(--calcite-border-width-sm) solid var(--calcite-color-text-3);
    }

    [dir="rtl"]vaadin-grid[overflow~="end"]::part(cell first-frozen-to-end-cell) {
      border-inline-end: var(--calcite-border-width-sm) solid var(--calcite-color-text-3);
    }

    vaadin-grid::part(body-cell) {
      background-color: var(--calcite-color-foreground-1);
    }

    vaadin-grid::part(body-cell):hover {
      background-color: var(--calcite-color-foreground-2);
    }

    vaadin-grid::part(body-cell invalid) {
      color: var(--calcite-color-text-3);
      font-style: italic;
    }

    vaadin-grid::part(header-cell) {
      background-color: var(--calcite-color-background);
    }

    vaadin-grid::part(header-cell invalid) {
      font-weight: var(--calcite-font-weight-bold);
    }

    // Adds darkened bottom border to header cells on overflow
    vaadin-grid[overflow~="top"]::part(header-cell) {
      border-bottom: var(--calcite-border-width-sm) solid var(--calcite-color-text-3);
    }

    // Adds brand border to sorted header cell
    vaadin-grid::part(header-cell direction) {
      border-bottom: var(--calcite-border-width-sm) solid var(--calcite-color-brand);
      background-color: var(--calcite-color-foreground-1);
    }

    // Adds darkened border to sorted header cell on overflow
    vaadin-grid[overflow~="top"]::part(header-cell direction) {
      border-bottom: var(--calcite-border-width-sm) solid var(--calcite-color-brand);
    }

    vaadin-grid::part(body-cell highlight) {
      background-color: var(--calcite-color-foreground-3);
    }

    // For specific cells with valid pending edits
    vaadin-grid::part(body-cell pending-edit) {
      border: var(--calcite-border-width-md) solid var(--calcite-color-status-success);
      background-color: color-mix(in sRGB, var(--calcite-color-status-success) 20%, var(--calcite-color-foreground-1));

      &:hover {
        background-color: color-mix(
          in sRGB,
          var(--calcite-color-status-success-hover) 20%,
          var(--calcite-color-foreground-1)
        );
      }
    }

    // For specific cells with invalid pending edits
    vaadin-grid::part(body-cell pending-edit-invalid) {
      border: var(--calcite-border-width-md) dashed var(--calcite-color-status-danger);
      background-color: color-mix(in sRGB, var(--calcite-color-status-danger) 20%, var(--calcite-color-foreground-1));
      font-weight: var(--calcite-font-weight-bold);

      &:hover {
        background-color: color-mix(
          in sRGB,
          var(--calcite-color-status-danger-hover) 20%,
          var(--calcite-color-foreground-1)
        );
      }
    }

    // For all cells when a different row has invalid pending edits
    // Does not apply to 'valid' cells in the invalid row itself
    vaadin-grid::part(body-cell pending-edit-other) {
      cursor: not-allowed;
      color: var(--calcite-color-text-3);
    }

    vaadin-grid::part(selected-row-cell) {
      background-color: color-mix(in sRGB, var(--calcite-color-brand) 10%, var(--calcite-color-foreground-1));
    }

    vaadin-grid::part(selected-row-cell):hover {
      background-color: color-mix(in sRGB, var(--calcite-color-brand) 20%, var(--calcite-color-foreground-1));
    }

    vaadin-checkbox {
      line-height: var(--calcite-font-line-height-relative-snug);
    }

    vaadin-checkbox::part(checkbox) {
      background-color: var(--calcite-color-text-3);
      line-height: var(--calcite-font-line-height-relative-snug);
    }

    vaadin-checkbox[checked]::part(checkbox) {
      background-color: var(--calcite-color-brand);
    }

    .esri-grid__content {
      background-color: inherit;
      width: 100%;
      height: 100%;
    }

    .esri-grid__grid {
      width: 100%;
      height: 100%;
    }

    .esri-column__content--full {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }

    .esri-column__header {
      &-content {
        display: flex;
        align-items: flex-start;
        width: 100%;
        height: 100%;
        overflow: hidden;
        text-align: start;
        font-weight: var(--calcite-font-weight-normal);

        &:has(calcite-icon:only-child) {
          align-items: center;
          justify-content: center;
        }

        div {
          display: flex;
          flex-flow: column wrap;
          width: 100%;
          min-height: var(--calcite-spacing-xxxl);
          overflow: hidden;

          span {
            width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            line-height: var(--calcite-font-line-height-fixed-xl);
          }
        }

        calcite-icon {
          margin-inline-end: var(--calcite-spacing-xxs);
          height: var(--calcite-spacing-xxl);
          color: var(--calcite-color-text-1);
        }

        calcite-dropdown {
          float: inline-end;
          max-height: 180px;

          // Avoid issues with menu growing outside of the viewport
          calcite-dropdown-group {
            max-width: 200px;
            overflow-x: auto;

            &:only-of-type {
              max-height: 180px;
              overflow: visible;
            }
          }

          &[open] {
            calcite-dropdown-item {
              display: flex;
            }
          }

          // Prevents frozen columns from appearing offset from the table edge on load.
          // This is because VaadinGrid's positioning logic accounts for 'hidden' calcite dropdown items,
          // since they use 'visibility: hidden' instead of 'display: none'.
          calcite-dropdown-item,
          calcite-dropdown-item[hidden] {
            display: none;
          }
        }
      }

      &-description {
        color: var(--calcite-color-text-3);
        font-size: var(--calcite-font-size-sm);
      }
    }

    .esri-column__sorter:hover {
      cursor: pointer;
    }

    .esri-column__sorter,
    .esri-column__header-label {
      display: flex;
      flex-grow: 1;
      align-items: center;
      height: var(--calcite-font-line-height-fixed-xl);
      overflow: hidden;
      color: var(--calcite-color-text-1);
    }
  }

  .esri-column__header-menu-icon {
    margin-inline-end: $side-spacing;
  }

  .esri-column__cell-input {
    flex: 1 1 0;
    border: none;
    width: 100%;
    height: 100%;
  }

  .esri-column__cell__input-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;

    input,
    select {
      position: absolute;
      top: 0;
      left: 0;
      padding: 0;
    }

    div,
    input,
    select {
      display: flex;
      width: 100%;
    }

    calcite-action-bar {
      --calcite-action-bar-background-color: transparent;
    }

    div:first-child {
      flex-direction: column;
    }

    calcite-input-time-zone {
      --calcite-dropdown-width: 200px;
    }

    calcite-combobox {
      position: absolute;
      font-weight: var(--calcite-font-weight-normal);
    }

    // Remove top border between stacked components for cleaner look.
    // Only remove border on TimePicker when it's not the only visible component (2nd or last).
    // Always remove the top border from TimeZone component (always displayed last)
    calcite-input-time-picker:last-child,
    calcite-input-time-picker:nth-child(2),
    calcite-input-time-zone {
      margin-top: -1px;
    }
  }
}

@if $include_Grid == true {
  @include grid();
}
