.history-view {
  margin-top: 18px;
}

.history-shell {
  display: grid;
  gap: 14px;
}

.history-topline {
  display: block;
}

.history-date-box {
  display: grid;
  align-content: center;
  gap: 7px;
  min-width: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.history-date-box > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.history-date-control,
.history-market-search,
.history-market-toolbar select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--soft);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.history-date-control {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0 12px;
  cursor: pointer;
}

.history-date-control svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.history-date-control input {
  min-width: 0;
  user-select: none;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.history-summary,
.history-market-summary,
.history-detail-stats,
.history-outcome-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.history-detail-stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.history-market-summary,
.history-outcome-stats {
  gap: 8px;
}

.history-summary {
  height: 100%;
}

.history-summary div {
  min-height: 58px;
}

.history-summary div,
.history-market-summary div,
.history-detail-stats div,
.history-outcome-stats div {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.history-market-summary div,
.history-outcome-stats div {
  padding: 10px;
  border-radius: 8px;
  background: var(--soft);
}

.history-summary strong,
.history-market-summary strong,
.history-detail-stats b,
.history-outcome-stats b {
  display: block;
  color: var(--text);
  font-size: 18px;
  font-weight: 950;
  line-height: 1;
}

.history-market-summary strong {
  font-size: 16px;
}

.history-outcome-stats b {
  display: grid;
  place-items: center;
  min-height: 28px;
  border-radius: 7px;
  background: var(--panel);
  font-size: 13px;
}

.history-summary span,
.history-market-summary span,
.history-detail-stats span,
.history-outcome-stats span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.history-market-summary span,
.history-outcome-stats span {
  margin-top: 3px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(430px, 0.95fr) minmax(500px, 1.25fr);
  gap: 14px;
  align-items: start;
}

.history-list-panel,
.history-details {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.history-list-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 420px;
}

.history-table-head,
.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px 96px;
  align-items: center;
  gap: 12px;
}

.history-table-head {
  min-height: 42px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel-2);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.3px;
  text-transform: uppercase;
}

.history-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding: 10px;
  background: var(--panel-2);
}

.history-row {
  width: 100%;
  min-height: 86px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--panel);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
}

.history-row:hover,
.history-row.active {
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--panel) 78%, var(--soft));
}

.history-row.active {
  border-color: color-mix(in srgb, var(--green) 46%, var(--line-strong));
  background: color-mix(in srgb, var(--panel) 62%, var(--soft));
  box-shadow:
    inset 4px 0 0 var(--green),
    inset 0 0 0 1px color-mix(in srgb, var(--green) 24%, transparent);
}

.history-row-match,
.history-row-score,
.history-row-counts {
  display: grid;
  min-width: 0;
}

.history-league {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
}

.history-league > span:last-child {
  min-width: 0;
  overflow: hidden;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.1px;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.history-row-match strong {
  overflow: hidden;
  margin-top: 9px;
  color: var(--text);
  font-size: 14px;
  font-weight: 950;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-row-match i,
.history-detail-head i {
  color: var(--muted);
  font-style: normal;
}

.history-row-match small,
.history-row-score small,
.history-row-counts small,
.history-detail-head small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.history-row-score,
.history-row-counts {
  justify-items: center;
}

.history-row-score b {
  color: var(--text);
  font-size: 18px;
  font-weight: 950;
}

.history-row-score small {
  color: var(--green);
}

.history-row-score small.finished {
  color: var(--muted);
  text-transform: uppercase;
}

.history-row-counts b {
  color: var(--text);
  font-size: 17px;
  font-weight: 950;
}

.history-details {
  display: grid;
  position: sticky;
  top: 16px;
  align-content: start;
  gap: 12px;
  min-height: 420px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 18px;
}

.history-detail-head,
.history-outcome-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.history-detail-head div,
.history-outcome-head div {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.history-detail-head span,
.history-outcome-head span {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.2px;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.history-detail-head strong,
.history-outcome-head strong {
  overflow: hidden;
  font-size: 16px;
  font-weight: 950;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-detail-head > b,
.history-outcome-head > b {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 9px;
  color: var(--text);
  background: var(--soft);
  font-size: 17px;
  font-weight: 950;
}

.history-market-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(148px, 176px);
  gap: 10px;
}

.history-market-search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--panel);
}

.history-market-search svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.history-market-search input,
.history-market-toolbar select {
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
}

.history-market-toolbar select {
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 12px;
  font-weight: 800;
}

.history-market-categories {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.history-market-categories::-webkit-scrollbar {
  display: none;
}

.history-market-categories button {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.history-market-categories button.active {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--soft);
  box-shadow: none;
}

.history-markets-list {
  display: grid;
  gap: 7px;
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}

.history-market-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}

.history-market-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

.history-market-title span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-market-title small {
  flex: 0 0 auto;
  color: var(--muted);
  font-weight: 700;
}

.history-outcomes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(188px, 1fr));
  gap: 6px;
}

.history-outcomes[data-outcome-count="2"],
.history-outcomes[data-outcome-count="3"] {
  grid-template-columns: repeat(var(--outcome-columns, 3), minmax(0, 1fr));
}

.history-outcomes[data-outcome-count="2"] {
  --outcome-columns: 2;
}

.history-outcomes[data-outcome-count="3"] {
  --outcome-columns: 3;
}

.history-outcome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--soft);
  text-align: left;
  cursor: pointer;
}

.history-outcome:hover,
.history-outcome.active {
  border-color: var(--line-strong);
}

.history-outcome.active {
  background: color-mix(in srgb, var(--soft) 82%, var(--panel));
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

body.dark-theme .history-outcome.active {
  background: color-mix(in srgb, var(--soft) 82%, var(--panel));
}

.history-outcome span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.history-outcome strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.15;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
  white-space: normal;
}

.history-outcome small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-outcome b {
  display: grid;
  flex: 0 0 58px;
  gap: 2px;
  justify-items: end;
  color: var(--text);
  font-size: 13px;
  font-weight: 950;
}

body.dark-theme .history-outcome b {
  color: var(--text);
}

.history-outcome em {
  font-style: normal;
  font-size: 10px;
  font-weight: 900;
}

.history-outcome .positive,
.history-outcome-stats .positive,
.history-snapshot-table .positive {
  color: var(--green);
}

.history-outcome .negative,
.history-outcome-stats .negative,
.history-snapshot-table .negative {
  color: var(--red);
}

.history-outcome .neutral {
  color: var(--muted);
}

.history-sparkline {
  width: 100%;
  height: 54px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.history-sparkline polyline {
  fill: none;
  stroke: var(--green);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.history-outcome-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel);
}

.history-outcome-panel[hidden] {
  display: none;
}

.history-snapshot-table {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-snapshot-table div {
  display: grid;
  grid-template-columns: 1fr 58px 72px;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0;
  background: transparent;
}

.history-snapshot-table span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.history-snapshot-table b {
  display: grid;
  place-items: center;
  min-height: 28px;
  border-radius: 7px;
  color: var(--text);
  background: var(--soft);
  font-size: 13px;
  font-weight: 950;
}

.history-market-limit {
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: var(--panel);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

@media (max-width: 1450px) {
  .history-layout {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .history-list-panel {
    min-height: 0;
  }

  .history-details {
    position: static;
    max-height: none;
  }

  .history-list {
    max-height: 420px;
    min-height: 320px;
  }
}
