/* --- History panel ---
   The sidebar is an icon rail, so History opens as a panel beside it (a sheet
   above the tab bar on phones). Every class that sets display and is toggled
   with the hidden attribute restates [hidden] — an author display rule beats
   the UA's. */

.history-panel {
  position: absolute;
  top: var(--space-lg);
  left: calc(100% + var(--space-sm));
  width: 300px;
  max-height: calc(100vh - 2 * var(--space-lg));
  display: flex;
  flex-direction: column;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}
.history-panel[hidden] {
  display: none;
}

.history-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border);
}
.history-panel__title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--font-semibold);
  color: var(--color-text);
}
.history-panel__close {
  border: none;
  background: none;
  color: var(--color-text-secondary);
  font-size: var(--text-lg);
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.history-panel__close:hover {
  background: var(--color-ghost-hover);
}

.history-panel__status {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
.history-panel__status:empty {
  display: none;
}
.history-panel__status--error {
  color: var(--color-error-text);
}
.history-panel__retry {
  margin-left: var(--space-xs);
}

.history-panel__list {
  list-style: none;
  margin: 0;
  padding: var(--space-xs);
  overflow-y: auto;
}
.history-panel__list:empty {
  display: none;
}

.history-item {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-sm);
}
.history-item:hover,
.history-item:focus-within {
  background: var(--color-ghost-hover);
}
/* The held run: a left accent as well as the tint, so it is not colour alone
   and differs from the hover tint. */
.history-item--current {
  background: var(--color-info-bg);
  box-shadow: inset 3px 0 0 var(--color-primary-text);
}

.history-item__open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-xs) var(--space-sm);
  border: none;
  background: none;
  text-align: left;
  color: var(--color-text);
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.history-item__open:focus-visible,
.history-item__delete:focus-visible,
.history-panel__close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.history-item__hosts {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item__meta {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
.history-item__status--running {
  color: var(--color-primary-text);
}
.history-item__status--completed {
  color: var(--color-success-text);
}
.history-item__status--failed,
.history-item__status--cancelled {
  color: var(--color-error-text);
}

.history-item__delete {
  flex-shrink: 0;
  width: 32px;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.history-item__delete:hover {
  color: var(--color-error-text);
}

/* The detail card a failed or cancelled run opens in the main area. */
.history-run-status__error {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 767px) {
  .history-panel {
    position: fixed;
    top: auto;
    left: var(--space-md);
    right: var(--space-md);
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 60vh;
  }
}
