/*
 * Copyright 2021 The Chromium Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

.data-grid {
  position: relative;
  border: 1px solid var(--sys-color-divider) !important; /* stylelint-disable-line declaration-no-important */
  /* See: crbug.com/1152736 for color variable migration. */
  line-height: 120%;

  :focus-visible {
    outline: 2px solid var(--sys-color-state-focus-ring);
    outline-offset: -2px;
  }
}

.data-grid table {
  table-layout: fixed;
  border-spacing: 0;
  border-collapse: separate;
  height: 100%;
  width: 100%;
}

.data-grid .data-container {
  position: absolute;
  inset: 0;
  overflow: hidden auto;
  transform: translateZ(0);
  background-color: var(--sys-color-cdt-base-container);
}

.data-grid thead {
  position: sticky;
  top: 0;
  height: 21px;
  z-index: 1;
}

.data-grid .aria-live-label {
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.data-grid.inline .data-container {
  position: static;
}

.data-grid .corner {
  width: 14px;
  padding-right: 0;
  padding-left: 0;
  border-left: 0 none transparent !important; /* stylelint-disable-line declaration-no-important */
}

.data-grid.inline .corner {
  display: none;
}

.data-grid.data-grid-fits-viewport .corner {
  display: none;
}

.data-grid .top-filler-td,
.data-grid .bottom-filler-td {
  height: auto !important; /* stylelint-disable-line declaration-no-important */
  padding: 0 !important; /* stylelint-disable-line declaration-no-important */
}

.data-grid table.data {
  position: absolute;
  inset: 0;
  border-top: 0 none transparent;
  table-layout: fixed;
}

.data-grid.inline table.data {
  position: static;
}

.data-grid tbody tr {
  display: none;
  height: 20px;

  &:has(td.show-more) {
    height: var(--sys-size-13);
  }
}

.data-grid tbody tr.revealed {
  display: table-row;
}

.striped-data-grid .revealed.data-grid-data-grid-node:nth-child(odd):not(.dirty, .selected),
.striped-data-grid-starts-with-odd .revealed.data-grid-data-grid-node:nth-child(even):not(.dirty, .selected) {
  background-color: var(--sys-color-surface1);
}

.data-grid td,
.data-grid th {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  line-height: 18px;
  height: 18px;
  border-left: 1px solid var(--sys-color-divider);
  padding: 1px 4px;
}

.data-grid td {
  vertical-align: top;
  user-select: text;
}

.data-grid tr {
  background-color: var(--sys-color-surface);

  &:has(th) {
    background-color: var(--sys-color-surface1);
  }
}

.data-grid th {
  border-bottom: 1px solid var(--sys-color-divider);
  text-align: left;
  font-weight: normal;
  vertical-align: middle;
}

.data-grid th:first-child,
.data-grid td:first-child {
  border-left-width: 0;
}

.data-grid:focus-within tr.selected td,
.data-grid:focus-within tr.selected th {
  border-left-color: var(--sys-color-divider-on-tonal-container);
}

.data-grid td > div,
.data-grid th > div {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  min-width: 8px;
}

.data-grid td.editing > div {
  text-overflow: clip;
}

.data-grid .center {
  text-align: center;
}

.data-grid .right {
  text-align: right;
}

.data-grid th.sortable {
  position: relative;
}

.data-grid th .sort-order-icon-container {
  min-width: 0;
  position: absolute;
  top: 1px;
  right: 0;
  bottom: 1px;
  display: flex;
  align-items: center;
}

.data-grid th .sort-order-icon {
  margin-right: 4px;
  margin-bottom: -2px;
  width: 14px;
  height: 14px;
  display: none;
  background-color: var(--icon-default);
}

.data-grid th.sort-ascending .sort-order-icon {
  display: inline-block;
  mask-image: var(--image-file-triangle-up);
}

.data-grid th.sort-descending .sort-order-icon {
  display: inline-block;
  mask-image: var(--image-file-triangle-down);
}

.data-grid th.sort-ascending,
.data-grid th.sort-descending {
  padding-right: 14px;
}

.data-grid th.sortable:hover,
.data-grid th.sortable:focus-within {
  background-color: var(--sys-color-state-hover-on-subtle);
}

.data-grid .top-filler-td {
  border-bottom: 0 none transparent;
  line-height: 0;
}

.data-grid button {
  line-height: 18px;
  color: inherit;
}

.data-grid td.disclosure::before {
  user-select: none;
  mask-image: var(--image-file-triangle-right);
  float: left;
  width: 14px;
  height: 14px;
  margin-right: 2px;
  content: "";
  position: relative;
  top: 3px;
  background-color: var(--icon-default);
  transition: transform 200ms;
}

.data-grid tr:not(.parent) td.disclosure::before {
  background-color: transparent;
}

.data-grid tr.expanded td.disclosure::before {
  transform: rotate(90deg);
}

.data-grid tbody tr.revealed.selected {
  background-color: var(--sys-color-neutral-container);
  color: inherit;

  & ::selection {
    background-color: var(--sys-color-state-focus-select);
    color: currentcolor;
  }
}

.data-grid:focus-within tbody tr.revealed.selected {
  background-color: var(--sys-color-tonal-container);
}

.data-grid tbody tr.revealed:not(.data-grid-filler-row, .selected):hover {
  background-color: var(--sys-color-state-hover-on-subtle);
}

.data-grid tbody tr.revealed.selected.dirty {
  color: var(--sys-color-on-tonal-container);
}

.data-grid.no-selection:focus-visible {
  outline: 2px solid var(--sys-color-state-focus-ring);
  outline-offset: -2px;
}

.data-grid:focus tbody tr.selected {
  background-color: var(--sys-color-tonal-container);
  color: var(--sys-color-on-tonal-container);
}

.data-grid tbody tr.selected.dirty {
  --override-data-grid-dirty-background-color: var(--sys-color-error);

  background-color: var(--override-data-grid-dirty-background-color);
}

.data-grid:focus tr.selected.dirty {
  --override-data-grid-dirty-background-color: var(--sys-color-error-container);
}

.data-grid:focus tr.selected .devtools-link {
  color: var(--sys-color-on-tonal-container);
}

.data-grid:focus tr.parent.selected td.disclosure::before {
  background-color: var(--sys-color-on-tonal-container);
}

.data-grid tr.inactive {
  color: var(--sys-color-state-disabled);
  font-style: italic;
}

.data-grid tr.dirty {
  --override-data-grid-dirty-background-color: var(--sys-color-surface-error);

  background-color: var(--override-data-grid-dirty-background-color);
  color: var(--sys-color-error);
  font-style: normal;
}

.data-grid tr.highlighted:not(.selected) {
  background-color: var(--sys-color-surface-yellow);
}

.striped-data-grid .revealed.data-grid-data-grid-node.highlighted:nth-child(odd):not(.dirty, .selected),
.striped-data-grid-starts-with-odd .revealed.data-grid-data-grid-node.highlighted:nth-child(even):not(.dirty, .selected) {
  background-color: var(--sys-color-surface-yellow-high);
}

.data-grid td.show-more {
  white-space: normal;
  gap: var(--sys-size-3);

  devtools-button {
    margin-right: var(--sys-size-6);
    position: relative;
    margin-top: 3px;
    margin-bottom: 3px;
  }
}

.data-grid td.show-more::before {
  display: none;
}

.data-grid-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 5px;
  z-index: 500;
}

@media (forced-colors: active) {
  .sort-order-icon-container .sort-order-icon {
    forced-color-adjust: none;
    background-color: ButtonText;
  }

  .data-grid td.disclosure::before {
    forced-color-adjust: none;
    color: ButtonText;
  }

  .data-grid.no-selection:focus-visible * {
    color: ButtonText;
  }

  .data-grid tbody tr.revealed:not(.data-grid-filler-row, .selected):hover,
  .data-grid:focus-within tbody tr.revealed.selected {
    background-color: Highlight;
  }

  .data-grid th.sortable:hover *,
  .data-grid tr.parent.selected td.disclosure::before,
  .data-grid:focus tr.parent.selected td.disclosure::before,
  .data-grid tbody tr.parent.revealed:hover td.disclosure::before {
    color: HighlightText;
  }

  .data-grid th.sortable:hover .sort-order-icon-container .sort-order-icon {
    background-color: HighlightText;
  }

  .striped-data-grid .revealed.data-grid-data-grid-node:nth-child(odd):not(.dirty, .selected),
  .striped-data-grid-starts-with-odd .revealed.data-grid-data-grid-node:nth-child(even):not(.dirty, .selected),
  .request-cookies-view tr.revealed.data-grid-data-grid-node.flagged-cookie-attribute-row:not(.selected):nth-child(2n),
  .cookies-table tr.revealed.data-grid-data-grid-node.flagged-cookie-attribute-row:not(.selected):nth-child(odd) {
    background-color: canvas;
  }

  .data-grid.no-selection:focus-visible {
    forced-color-adjust: none;
    border-color: Highlight;
  }

  .data-grid th.sortable:hover,
  .data-grid tbody tr.revealed:hover,
  .data-grid tbody tr.revealed.selected,
  .striped-data-grid .revealed:hover.data-grid-data-grid-node:nth-child(odd):not(.dirty, .selected),
  .striped-data-grid-starts-with-odd .revealed:hover.data-grid-data-grid-node:nth-child(even):not(.dirty, .selected),
  .request-cookies-view tr.revealed:hover.data-grid-data-grid-node.flagged-cookie-attribute-row:not(.selected):nth-child(2n),
  .cookies-table tr.revealed:hover.data-grid-data-grid-node.flagged-cookie-attribute-row:not(.selected):nth-child(odd) {
    forced-color-adjust: none;
    background-color: Highlight;
  }

  .data-grid tbody tr.revealed:hover *,
  .data-grid tbody tr.revealed.selected *,
  .data-grid tbody tr.revealed:focus *,
  .data-grid tbody tr.revealed:hover .heap-object-tag {
    color: HighlightText;
  }

  .data-grid th {
    background-color: canvas;
    border-color: Highlight;
  }
}
