.repository-history {
  margin-top: 24px;
}

.history-toolbar,
.history-filter,
.history-branch-tools,
.history-view-controls,
.history-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.history-filter {
  min-width: 0;
  font-size: 13px;
}

.history-view-controls {
  margin-left: auto;
  font-size: 13px;
}

.history-branch-selector summary,
.history-branch-tools input,
.history-filter button,
.history-color-toggle,
.history-pagination a {
  padding: 7px 10px;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--bg-1);
  color: var(--fg-1);
  font: inherit;
}

.history-branch-selector {
  position: relative;
  min-width: 0;
}

.history-branch-selector summary {
  min-width: 0;
  max-width: 260px;
  font-family: var(--font-mono);
  cursor: pointer;
}

.history-branch-menu {
  position: absolute;
  z-index: 2;
  top: calc(100% + 4px);
  left: 0;
  width: 280px;
  max-width: calc(100vw - 112px);
  max-height: 300px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: var(--bg-1);
}

.history-branch-menu p {
  margin: 0 4px 8px;
  color: var(--muted);
  font-size: 12px;
}

.history-branch-tools {
  position: sticky;
  top: -8px;
  padding-bottom: 8px;
  background: var(--bg-1);
}

.history-branch-tools input {
  width: 100%;
  min-width: 0;
}

.history-branch-menu [hidden] {
  display: none;
}

.history-branch-menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  cursor: pointer;
}

.history-branch-menu input[type="checkbox"] {
  flex: none;
  accent-color: var(--action);
}

.history-branch-menu label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
}

.history-filter button,
.history-color-toggle {
  cursor: pointer;
}

.history-page-number,
.history-row time {
  color: var(--muted);
  font: 12px/1.5 var(--font-mono);
}

.history-list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-row {
  --history-row-background: var(--history-branch-color);

  display: grid;
  grid-template-columns: minmax(140px, 240px) 110px minmax(0, 1fr) auto;
  align-items: start;
  align-content: start;
  gap: 16px;
  min-height: 41.6px;
  padding: 8px 12px;
  background: var(--history-row-background);
}

.history-row:hover,
.history-row:focus-within {
  --history-row-background: color-mix(in srgb, var(--history-branch-color) 92%, white);
}

.history-identity {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.history-identity .history-branch {
  flex: 0 0 auto;
  max-width: 50%;
}

.history-author {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-1);
  font: 12px/24px var(--font-ui);
}

.history-branch {
  justify-self: start;
  max-width: 100%;
  color: var(--fg-1);
  font: 12px/24px var(--font-mono);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history-row > time {
  line-height: 24px;
  white-space: nowrap;
}

.history-source {
  font-size: 12px;
}

.history-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
}

.history-expand {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 3px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}

.history-expand:hover {
  border-color: currentColor;
}

.history-expand:focus-visible {
  outline-color: currentColor;
}

.history-expand svg {
  width: 16px;
  height: 16px;
}

.history-expand[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.history-row a:hover {
  text-decoration: underline;
}

.history-message {
  min-width: 0;
  margin: 0;
  color: var(--fg-1);
  font: 14px/24px var(--font-ui);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history-row-expanded .history-message {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.history-details {
  display: none;
  grid-column: 1 / -1;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  min-width: 0;
  margin: 0;
  font: 12px/1.5 var(--font-mono);
}

.history-row-expanded .history-details {
  display: grid;
}

.history-details dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.history-no-message,
.history-empty {
  color: var(--muted);
}

.history-empty {
  padding: 32px 12px;
  text-align: center;
}

.history-row :is(.history-branch, .history-author, time, .history-message, .history-no-message, .history-source, .history-expand, .history-details) {
  color: white;
}

@supports (color: contrast-color(currentColor)) {
  .history-row :is(.history-branch, .history-author, time, .history-message, .history-no-message, .history-source, .history-expand, .history-details) {
    color: contrast-color(var(--history-row-background));
  }
}

.history-colors-off .history-row {
  --history-row-background: var(--bg-0);
}

.history-colors-off .history-row:is(:hover, :focus-within) {
  --history-row-background: var(--bg-1);
}

.history-colors-off .history-row :is(.history-branch, .history-author, time, .history-message, .history-no-message, .history-source, .history-expand, .history-details) {
  color: var(--fg-1);
}

.history-pagination {
  justify-content: space-between;
  margin-top: 20px;
  font-size: 13px;
}

.history-pagination a[rel="next"] {
  margin-left: auto;
}

.history-filter button:hover,
.history-color-toggle:hover,
.history-pagination a:hover {
  background: var(--bg-2);
}

.history-color-toggle[aria-pressed="true"] {
  border-color: var(--action);
  background: var(--action);
  color: var(--button-text);
}

@media (max-width: 600px) {
  .history-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-rows: 24px auto;
    gap: 6px 12px;
    min-height: 60.8px;
    padding: 3px 8px;
  }

  .history-identity { grid-column: 1 / 3; }

  .history-row > time {
    grid-column: 2;
    grid-row: 2;
    font-size: 11px;
  }

  .history-message {
    grid-column: 1;
    grid-row: 2;
  }

  .history-actions {
    grid-column: 3;
    grid-row: 1 / 3;
    align-self: start;
  }
}
