#treegrid {
  width: 100%;
  white-space: nowrap;
  border-collapse: collapse;
  table-layout: fixed;
}

#treegrid tr {
  display: table-row;
  cursor: default;
}

/* Extra space between columns for readability */
#treegrid th,
#treegrid td {
  padding-bottom: 3px;
  overflow-x: hidden;
  text-overflow: ellipsis;
}

#treegrid tbody td {
  cursor: default;
}

#treegrid-col1,
#treegrid-col3 {
  width: 30%;
}

#treegrid th {
  text-align: left;
  background-color: #eee;
}

#treegrid a {
  padding-left: 0.25ch;
  padding-right: 0.25ch;
}

#treegrid tr:focus,
#treegrid td:focus,
#treegrid a:focus {
  outline: 2px solid hsl(216deg 94% 70%);
  background-color: hsl(216deg 80% 97%);
}

#treegrid tr > td:not(:first-child),
#treegrid tr > th:not(:first-child) {
  padding-left: 3ch;
}

#treegrid a:focus {
  border-bottom: none;
}

/* Hide collapsed rows */
#treegrid tr.hidden {
  display: none;
}

/* Indents */
#treegrid tr[aria-level="2"] > td:first-child {
  padding-left: 2.5ch;
}

#treegrid tr[aria-level="3"] > td:first-child {
  padding-left: 5ch;
}

#treegrid tr[aria-level="4"] > td:first-child {
  padding-left: 7.5ch;
}

#treegrid tr[aria-level="5"] > td:first-child {
  padding-left: 10ch;
}

/* Collapse/expand icons */
#treegrid tr > td:first-child::before {
  font-family: monospace;
  content: " ";
  display: inline-block;
  width: 2ch;
  height: 11px;
  transition: transform 0.3s;
  transform-origin: 5px 5px;
}

#treegrid tr[aria-expanded] > td:first-child::before,
#treegrid td[aria-expanded]:first-child::before {
  cursor: pointer;

  /* Load both right away so there is no lag when we need the other */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Cpolygon fill='black' points='2,0 2,10 10,5'%3E%3C/polygon%3E%3C/svg%3E%0A"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Cpolygon fill='hsl(216, 94%25, 50%25)' points='2,0 2,10 10,5'%3E%3C/polygon%3E%3C/svg%3E%0A");
  background-repeat: no-repeat;
}

#treegrid tr[aria-expanded="true"] > td:first-child::before,
#treegrid td[aria-expanded="true"]:first-child::before {
  transform: rotate(90deg);
}

#treegrid tr[aria-expanded]:focus > td:first-child::before,
#treegrid tr[aria-expanded] > td:focus:first-child::before,
#treegrid tr:focus > td[aria-expanded]:first-child::before,
#treegrid tr > td[aria-expanded]:focus:first-child::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Cpolygon fill='hsl(216, 94%25, 50%25)' points='2,0 2,10 10,5'%3E%3C/polygon%3E%3C/svg%3E%0A");
}
