/* ==========================================================================
   History — File Explorer "Details" view of the team's runs.
   Root: .app.app--history (flex column, @container "app", from shell.css).
   Rows use .list / .list__head / .list__row / .list__sort from components.
   Below 660 px of window width the rows become two-line items.
   ========================================================================== */

/* ---- Address bar --------------------------------------------------------- */
.hist__bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--c-stroke);
}

.hist__address {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--s-1);
  height: var(--control-h);
  padding: 0 var(--s-2);
  border: 1px solid var(--c-stroke-control);
  border-top-color: var(--c-stroke-control-top);
  border-radius: var(--r-sm);
  background: var(--c-control);
  font: var(--type-body);
  user-select: none;
}

.hist__address-icon {
  flex: none;
  width: 16px;
  height: 16px;
  margin-right: var(--s-1);
}

.hist__crumb {
  padding: 2px var(--s-1);
  border-radius: var(--r-sm);
  white-space: nowrap;
}

.hist__crumb--team {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--c-text-2);
}

.hist__crumb--here {
  flex: none;
  color: var(--c-text);
}

.hist__chevron {
  flex: none;
  width: 6px;
  height: 6px;
  margin: 0 var(--s-1) 0 2px;
  border-top: 1.5px solid var(--c-text-tertiary);
  border-right: 1.5px solid var(--c-text-tertiary);
  transform: rotate(45deg);
}

.hist__refresh {
  flex: none;
}

.hist__refresh.is-busy .icon {
  animation: hist-spin 0.9s linear infinite;
}

@keyframes hist-spin {
  to { transform: rotate(1turn); }
}

/* ---- Details grid -------------------------------------------------------- */
.hist__pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.hist__list {
  --list-cols: minmax(152px, 1.4fr) minmax(120px, 1fr) minmax(104px, 0.9fr) minmax(104px, 0.9fr) minmax(72px, 0.6fr);
  flex: 0 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 var(--s-1) var(--s-2);
  scroll-padding-top: 40px;
}

.hist__head {
  margin: 0 calc(-1 * var(--s-1));
  padding-inline: calc(var(--s-3) + var(--s-1));
}

.hist__th {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hist__rows {
  display: flex;
  flex-direction: column;
  gap: inherit;
}

.hist__cell {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  color: var(--c-text-2);
}

.hist__cell--time {
  color: var(--c-text);
}

.hist__when,
.hist__result {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hist__cell--run {
  gap: 2px;
}

.hist__id {
  color: var(--c-text);
}

/* Explorer reveals per-item actions on hover in the details view; touch and
   the two-line layout always show them. */
.hist__copy {
  transition: opacity var(--dur-fast) linear, background-color var(--dur-fast) linear, color var(--dur-fast) linear;
}

@media (hover: hover) and (pointer: fine) {
  @container app (min-width: 660px) {
    .hist__row:not(:hover):not(.is-selected):not(:focus-within) .hist__copy {
      opacity: 0;
    }
  }
}

.hist__cell--charged.is-charged {
  color: var(--c-text);
}

.hist__long {
  display: none;
}

.hist__none {
  color: var(--c-text-3);
}

/* Result glyph: a tiny monitor; a blue one for a bugcheck. */
.hist__glyph {
  position: relative;
  flex: none;
  width: 16px;
  height: 11px;
  margin-bottom: 3px;
  border: 1.5px solid var(--c-text-2);
  border-radius: 2px;
  background: var(--c-card);
}

.hist__glyph::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 7px;
  height: 1.5px;
  border-radius: 1px;
  background: var(--c-text-2);
  transform: translateX(-50%);
}

.hist__glyph--bsod {
  background: var(--c-bsod);
}

/* ---- Empty and loading states -------------------------------------------- */
.hist__empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-10) var(--s-4) var(--s-6);
  text-align: center;
}

.hist__dots {
  --spinner-size: 28px;
  margin-bottom: var(--s-2);
  color: var(--c-accent);
}

.hist__empty-title {
  color: var(--c-text-2);
}

.hist__empty-text {
  font: var(--type-caption);
  color: var(--c-text-tertiary);
}

.hist__empty .btn {
  margin-top: var(--s-3);
}

/* ---- Status bar ---------------------------------------------------------- */
.hist__status {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--s-3);
  row-gap: 2px;
  min-height: 28px;
  padding: var(--s-1) var(--s-4);
  border-top: 1px solid var(--c-stroke);
  color: var(--c-text-2);
  font: var(--type-caption);
  white-space: nowrap;
  user-select: none;
}

.hist__sel::before {
  content: "";
  display: inline-block;
  width: 1px;
  height: 12px;
  margin-right: var(--s-3);
  background: var(--c-stroke-strong);
  vertical-align: -2px;
}

.hist__count[hidden] + .hist__sel::before {
  display: none;
}

.hist__quota {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  margin-left: auto;
}

.hist__pips {
  display: inline-flex;
  gap: 3px;
}

.hist__pip {
  width: 12px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--c-stroke-strong);
}

.hist__pip.is-used {
  background: var(--c-accent);
}

.hist__quota.is-exhausted .hist__pip.is-used {
  background: var(--c-warning);
}

/* ---- Narrow windows and tablet mode: two-line items ---------------------- */
@container app (max-width: 659px) {
  .hist__list {
    --list-cols: auto auto minmax(0, 1fr) auto;
  }

  .hist__head {
    grid-template-columns: minmax(0, 1fr);
  }

  .hist__th:not(.hist__th--time) {
    display: none;
  }

  .hist__row {
    grid-template-areas:
      "time time time status"
      "run result charged charged";
    column-gap: var(--s-2);
    row-gap: 0;
    padding-block: var(--s-2);
  }

  /* No result yet (or none at all): skip the "—" in the second line. */
  .hist__row--noresult {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "time time status"
      "run charged charged";
  }

  .hist__row--noresult .hist__cell--result {
    display: none;
  }

  .hist__cell--time {
    grid-area: time;
    font: var(--type-body-strong);
  }

  .hist__cell--status {
    grid-area: status;
    justify-content: flex-end;
  }

  .hist__cell--run {
    grid-area: run;
  }

  .hist__cell--result {
    grid-area: result;
  }

  .hist__cell--charged {
    grid-area: charged;
  }

  .hist__cell--run,
  .hist__cell--result,
  .hist__cell--charged {
    font: var(--type-caption);
  }

  .hist__cell--result::before,
  .hist__cell--charged::before {
    content: "\00b7";
    color: var(--c-text-3);
  }

  .hist__short {
    display: none;
  }

  .hist__long {
    display: inline;
  }

  .hist__copy {
    margin-block: -4px;
  }
}

/* Touch: keep the 44 px copy target from stretching the two-line item. */
@media (pointer: coarse) {
  .hist__copy {
    margin-block: -8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hist__refresh.is-busy .icon {
    animation: none;
    opacity: 0.5;
  }
}
