.card.has-history .badge-stack {
  z-index: 7;
  pointer-events: none;
}

.card-favorite {
  position: absolute;
  inset: 0;
  z-index: 5;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.card-favorite:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -3px;
}

.card-history {
  max-width: 100%;
  padding: 2px 4px;
  color: var(--green);
  background: #111a14;
  border: 1px solid #46594c;
  border-radius: 3px;
  font-size: .69rem;
  font-weight: 850;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
}

.card-history:hover { border-color: var(--green); }
.card-history:focus-visible { outline: 2px solid var(--green); }
.card-history.is-candidate {
  color: var(--amber);
  background: #312617;
  border-color: #745a2b;
}

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

.history-heading h2, .history-toolbar h3 {
  margin: 0;
  line-height: 1.25;
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.history-stats dt { color: var(--muted); font-size: .7rem; }
.history-stats dd {
  margin: 2px 0 0;
  font-size: .86rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sell-net-change {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: .68rem;
  font-variant-numeric: tabular-nums;
}

.history-summary {
  margin: 14px 0 10px;
  color: var(--muted);
  font-size: .81rem;
  line-height: 1.5;
}

.sell-history {
  width: min(700px, calc(100% - 24px));
  max-height: min(760px, calc(100dvh - 24px));
  padding: clamp(12px, 3vw, 24px);
  color: var(--text);
  background: var(--panel);
  border: 1px solid #495b4e;
  border-radius: 6px;
  box-shadow: 0 16px 80px #0009;
  overflow: auto;
}
.sell-history::backdrop { background: #090d0bd9; }

.history-heading, .history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.history-heading > div { min-width: 0; }
.history-heading h2 {
  font-size: clamp(1rem, 3vw, 1.55rem);
  overflow-wrap: anywhere;
}
.history-mode {
  margin: 0 0 5px;
  color: var(--green);
  font-size: .73rem;
  font-weight: 750;
}
.history-heading form { flex: none; }

.history-stats { margin: 16px 0; }
.history-stats div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 8px;
}

.history-toolbar h3 { font-size: .94rem; }
.history-toolbar .field {
  min-width: 0;
  grid-template-columns: auto auto;
  align-items: center;
}
.history-toolbar .field > span { color: var(--muted); font-size: .75rem; }

.history-chart {
  display: block;
  width: 100%;
  height: clamp(150px, 36vw, 245px);
  background: #111813;
  border: 1px solid var(--line);
}
.history-details {
  margin-top: 10px;
  color: var(--muted);
  font-size: .82rem;
}
.history-details summary { width: fit-content; cursor: pointer; }
.history-details table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  color: var(--text);
}
.history-details td, .history-details th {
  padding: 5px 8px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.history-details td:last-child, .history-details th:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .card-history { font-size: .6rem; }
  .history-stats dd { font-size: .79rem; }
}

@media (max-width: 460px) {
  .history-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-toolbar .field > span { display: none; }
}
