.request-history,
.history-panel,
.history-detail {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.history-panel,
.history-detail {
  padding: 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
  background: linear-gradient(145deg, rgba(16, 34, 58, 0.92), rgba(7, 20, 38, 0.96));
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12);
}

.history-heading,
.history-toolbar,
.history-actions,
.history-metrics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.history-heading {
  justify-content: space-between;
  align-items: flex-start;
}

.history-heading h2 {
  margin-bottom: 0.35rem;
}

.history-heading p {
  margin-bottom: 0;
}

.history-toolbar {
  align-items: end;
  padding: 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  background: rgba(4, 12, 24, 0.42);
}

.history-toolbar label {
  display: grid;
  gap: 0.3rem;
  color: var(--color-text-muted);
  font-size: 0.84rem;
  font-weight: 650;
}

.history-toolbar input,
.history-toolbar select {
  min-height: 2.45rem;
}

.history-search {
  flex: 1 1 14rem;
}

.history-search input {
  width: 100%;
}

.history-table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  background: rgba(4, 12, 24, 0.35);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.history-table th,
.history-table td {
  padding: 0.72rem 0.8rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.history-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-size: 0.8rem;
  white-space: nowrap;
}

.history-table td {
  color: var(--color-text-muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.history-table tbody tr:hover {
  background: rgba(95, 159, 215, 0.08);
}

.history-table tbody tr:last-child td {
  border-bottom: 0;
}

.history-request-id,
.history-model,
.history-token-count {
  font-family: var(--font-mono);
  font-size: 0.84em;
  overflow-wrap: anywhere;
}

.history-status {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  padding: 0.12rem 0.55rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  background: rgba(182, 204, 226, 0.07);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 750;
  white-space: nowrap;
}

.history-status[data-status="completed"],
.history-status[data-status="success"] {
  border-color: rgba(125, 227, 172, 0.4);
  background: rgba(125, 227, 172, 0.09);
  color: var(--color-success);
}

.history-status[data-status="in_progress"],
.history-status[data-status="pending"] {
  border-color: rgba(240, 198, 116, 0.4);
  color: var(--color-warning);
}

.history-status[data-status="failed"],
.history-status[data-status="cancelled"] {
  border-color: rgba(240, 138, 138, 0.42);
  background: rgba(240, 138, 138, 0.08);
  color: var(--color-danger);
}

.history-metrics {
  align-items: stretch;
}

.history-metric {
  flex: 1 1 8rem;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  background: rgba(4, 12, 24, 0.4);
}

.history-metric dt {
  color: var(--color-text-quiet);
  font-size: 0.76rem;
  font-weight: 700;
}

.history-metric dd {
  margin: 0.2rem 0 0;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.history-detail summary {
  color: var(--color-accent);
  font-weight: 700;
  cursor: pointer;
}

.history-error {
  padding: 0.75rem 0.9rem;
  border-left: 3px solid var(--color-danger);
  border-radius: 0 var(--radius-small) var(--radius-small) 0;
  background: rgba(240, 138, 138, 0.08);
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

.history-empty {
  padding: 1.2rem;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-small);
  color: var(--color-text-quiet);
  text-align: center;
}

@media (max-width: 680px) {
  .history-panel,
  .history-detail {
    padding: 1rem;
  }

  .history-heading {
    flex-direction: column;
  }

  .history-table th,
  .history-table td {
    padding: 0.58rem;
  }
}
