/*
 * The Reference Data UI, built on the EveryMatrix design system: ds/tokens.css holds the colours, type, spacing,
 * radii and shadows, and ds/components/bundle.css the type sizes, motion and element defaults. The controls below
 * recreate the system's React components (InputRounded, Dropdown, FilterTabs, PaginationNumber, PaginationButton,
 * Button) as plain HTML, because these pages are rendered on the server.
 */

/*
 * The accent is OddsMatrix red, the system's sports ramp, in place of the EveryMatrix green. As the system asks of a
 * sub-brand, it is a pair of roles that the accented controls read explicitly, rather than a new value for the
 * system's brand roles: links, the stroke button, the current page and search matches.
 */
:root {
	--product-accent: var(--sports-500);
	--product-accent-quiet: var(--sports-50);
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

body {
	margin: 0;
	background: var(--surface-muted);
	color: var(--text-primary);
	font-family: var(--font-body);
	font-size: var(--text-small-size);
	line-height: var(--text-small-lh);
}

a {
	color: var(--product-accent);
}

code,
pre {
	font-family: var(--font-mono);
}

.icon {
	flex: none;
	display: block;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.skip-link {
	position: absolute;
	top: var(--space-md);
	left: var(--space-md);
	z-index: 10;
	padding: var(--space-md) var(--space-xl);
	border-radius: var(--radius-full);
	background: var(--surface-card);
	box-shadow: var(--shadow-md);
	color: var(--text-primary);
	font-weight: var(--weight-semibold);
	transform: translateY(-200%);
}

.skip-link:focus {
	transform: none;
}

:focus-visible {
	outline: 2px solid var(--focus-border);
	outline-offset: 2px;
}

.muted {
	color: var(--text-secondary);
}

/* Header */

.app-header {
	background: var(--surface-card);
	border-bottom: 1px solid var(--border-default);
}

.app-header__inner {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-lg) var(--space-3xl);
	max-width: var(--width-4xl);
	margin: 0 auto;
	padding: var(--space-lg) var(--grid-padding);
}

.brand {
	display: flex;
	align-items: center;
	gap: var(--space-xl);
	min-height: 44px;
	color: var(--text-primary);
}

.brand:hover {
	text-decoration: none;
}

.brand img {
	display: block;
	width: auto;
	height: 30px;
}

.brand__divider {
	width: 1px;
	height: 24px;
	background: var(--border-default);
}

.brand__name {
	font-weight: var(--weight-semibold);
}

.app-header__tools {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-xl);
}

.refresh-note {
	display: flex;
	align-items: center;
	gap: var(--space-sm);
	margin: 0;
	color: var(--text-secondary);
	font-size: var(--text-meta-size);
	line-height: var(--text-meta-lh);
}

/* Buttons: the system's Button in its sm size, stroke and link fills */

.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-md);
	height: 40px;
	padding: 0 22px;
	border: 0;
	border-radius: var(--radius-full);
	background: var(--surface-card);
	box-shadow: inset 0 0 0 1px var(--product-accent);
	color: var(--text-primary);
	font: inherit;
	font-size: var(--text-small-size);
	font-weight: var(--weight-semibold);
	line-height: var(--text-small-lh);
	white-space: nowrap;
	cursor: pointer;
	transition: background-color var(--transition-default);
}

.button:hover {
	background: var(--hover-surface);
	text-decoration: none;
}

.text-link {
	display: inline-flex;
	align-items: center;
	min-height: 44px;
	color: var(--text-primary);
	font-size: var(--text-meta-size);
	font-weight: var(--weight-semibold);
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.icon-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: var(--radius-full);
	background: transparent;
	color: var(--text-secondary);
	cursor: pointer;
	transition: background-color var(--transition-default);
}

.icon-button:hover {
	background: var(--hover-surface);
	color: var(--text-primary);
}

/* Shell: navigation beside the content, stacking on a phone */

.shell {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	gap: var(--space-4xl);
	width: 100%;
	max-width: var(--width-4xl);
	margin: 0 auto;
	padding: var(--space-4xl) var(--grid-padding);
}

.shell--narrow {
	max-width: var(--width-xl);
}

.content {
	flex: 999 1 560px;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: var(--space-3xl);
}

.side-nav {
	flex: 1 1 240px;
	display: flex;
	flex-direction: column;
	gap: var(--space-lg);
	padding: var(--space-lg);
	border-radius: var(--radius-2xl);
	background: var(--surface-card);
	box-shadow: var(--shadow-xs);
}

.side-nav__heading {
	margin: 0;
	padding: var(--space-md) var(--space-lg) var(--space-xs);
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
	font-weight: var(--weight-semibold);
	line-height: var(--text-xs-lh);
}

.side-nav__list {
	display: flex;
	flex-direction: column;
	gap: var(--space-xxs);
	margin: 0;
	padding: 0;
	list-style: none;
}

.side-nav__link {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-md);
	min-height: 44px;
	padding: 0 var(--space-lg);
	border-radius: var(--radius-md);
	color: var(--text-primary);
	font-size: var(--text-meta-size);
	line-height: var(--text-meta-lh);
	text-decoration: none;
	transition: background-color var(--transition-default);
}

.side-nav__link:hover {
	background: var(--hover-surface);
	text-decoration: none;
}

.side-nav__link[aria-current] {
	background: var(--surface-selected);
	font-weight: var(--weight-semibold);
}

.side-nav__size {
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
	font-weight: var(--weight-regular);
	font-variant-numeric: tabular-nums;
}

.side-nav__link[aria-current] .side-nav__size {
	color: var(--text-primary);
}

/* Page intro */

.page-intro {
	display: flex;
	flex-direction: column;
	gap: var(--space-md);
}

.page-intro__text {
	max-width: var(--width-xl);
	margin: 0;
	color: var(--text-secondary);
}

.page-intro__text code {
	color: var(--text-primary);
	font-size: 0.9em;
}

.endpoint {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-xs);
}

.endpoint__path {
	display: inline-flex;
	align-items: center;
	gap: var(--space-xs);
	min-height: 32px;
	padding: var(--space-xs) var(--space-lg);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-full);
	background: var(--surface-card);
	font-size: var(--text-meta-size);
	line-height: var(--text-meta-lh);
	overflow-wrap: anywhere;
}

.endpoint__method {
	font-weight: var(--weight-semibold);
}

.endpoint__status {
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
}

/* Card holding the filters, the table and the pagination */

.card {
	display: flex;
	flex-direction: column;
	min-width: 0;
	border-radius: var(--radius-2xl);
	background: var(--surface-card);
	box-shadow: var(--shadow-sm);
}

.filters {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: var(--space-xl);
	margin: 0;
	padding: var(--space-2xl) var(--space-2xl) var(--space-lg);
}

.field {
	display: flex;
	flex-direction: column;
	gap: var(--space-sm);
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

.field--search {
	flex: 2 1 280px;
}

.field--sport {
	flex: 1 1 220px;
}

.field__label {
	padding: 0;
	color: var(--text-primary);
	font-size: var(--text-meta-size);
	font-weight: var(--weight-semibold);
	line-height: var(--text-meta-lh);
}

/* A legend does not take part in its fieldset's flex layout, so it gets its own spacing. */
legend.field__label {
	margin-bottom: var(--space-sm);
}

/* InputRounded: the system's search field */
.search {
	display: flex;
	align-items: center;
	gap: var(--space-md);
	height: 44px;
	padding: 0 20px;
	border-radius: var(--radius-full);
	background: var(--surface-card);
	box-shadow: inset 0 0 0 1px var(--border-default);
	color: var(--text-secondary);
	transition: box-shadow var(--transition-default);
}

.search:hover {
	box-shadow: inset 0 0 0 1px var(--focus-border);
}

.search:focus-within {
	box-shadow: var(--shadow-focus);
}

.search input {
	flex: 1;
	min-width: 0;
	height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	outline: none;
	background: transparent;
	color: var(--text-primary);
	font-size: var(--text-small-size);
	line-height: 1;
}

.search__clear {
	display: flex;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--text-secondary);
	opacity: 0.6;
	cursor: pointer;
	transition: opacity var(--transition-default);
}

.search__clear:hover {
	opacity: 1;
}

.search input:placeholder-shown + .search__clear {
	display: none;
}

/* Dropdown: the system's select field */
.select {
	position: relative;
	color: var(--text-secondary);
}

.select select {
	width: 100%;
	height: 44px;
	padding: 0 48px 0 16px;
	border: 0;
	border-radius: var(--radius-md);
	background: var(--surface-card);
	box-shadow: inset 0 0 0 1px var(--border-default);
	color: var(--text-primary);
	font-size: var(--text-small-size);
	text-overflow: ellipsis;
	cursor: pointer;
	appearance: none;
	transition: box-shadow var(--transition-default);
}

.select select:hover {
	box-shadow: inset 0 0 0 1px var(--focus-border);
}

.select select:focus-visible {
	outline: none;
	box-shadow: var(--shadow-focus);
}

.select .icon {
	position: absolute;
	top: 50%;
	right: 16px;
	transform: translateY(-50%);
	pointer-events: none;
}

/* FilterTabs: the system's filter bar, with radio buttons so it also works without JavaScript */
.segmented {
	display: flex;
	gap: 4px;
	width: fit-content;
	padding: 4px;
	border-radius: var(--radius-full);
	background: var(--surface-muted);
}

.segmented__option {
	position: relative;
	display: flex;
}

.segmented__option input {
	position: absolute;
	inset: 0;
	margin: 0;
	opacity: 0;
	cursor: pointer;
}

.segmented__option span {
	display: flex;
	align-items: center;
	height: 36px;
	padding: 0 18px;
	border-radius: var(--radius-full);
	color: var(--text-primary);
	font-size: var(--text-small-size);
	line-height: var(--text-small-lh);
	white-space: nowrap;
	opacity: 0.6;
	transition: opacity var(--transition-default), background-color var(--transition-default),
		box-shadow var(--transition-default);
}

.segmented__option:hover span,
.segmented__option input:checked + span {
	opacity: 1;
}

.segmented__option input:checked + span {
	background: var(--surface-card);
	box-shadow: var(--shadow-sm);
}

.segmented__option input:focus-visible + span {
	outline: 2px solid var(--focus-border);
	outline-offset: 2px;
}

/* Results */

.results {
	transition: opacity var(--duration-fast) var(--ease-default);
}

/* htmx sets htmx-request while a search or a page link is on its way. */
.results.htmx-request {
	opacity: 0.55;
}

.results-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-md);
	min-height: 44px;
	padding: 0 var(--space-2xl) var(--space-md);
}

.results-bar__summary {
	margin: 0;
	color: var(--text-secondary);
	font-size: var(--text-meta-size);
	line-height: var(--text-meta-lh);
}

.table-scroll {
	overflow-x: auto;
	border-top: 1px solid var(--border-default);
}

.data-table {
	width: 100%;
	min-width: 720px;
	border-collapse: collapse;
	font-size: var(--text-meta-size);
	line-height: var(--text-meta-lh);
}

.data-table th {
	padding: var(--space-md) var(--space-lg);
	background: var(--surface-subtle);
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
	font-weight: var(--weight-semibold);
	line-height: var(--text-xs-lh);
	text-align: left;
	white-space: nowrap;
}

.data-table td {
	height: 52px;
	padding: var(--space-md) var(--space-lg);
	border-top: 1px solid var(--border-default);
	vertical-align: middle;
}

.data-table th:first-child,
.data-table td:first-child {
	padding-left: var(--space-2xl);
}

.data-table th:last-child,
.data-table td:last-child {
	padding-right: var(--space-2xl);
}

.data-table tbody tr {
	transition: background-color var(--transition-default);
}

.data-table tbody tr:hover {
	background: var(--hover-surface);
}

.data-table--compact {
	min-width: 0;
}

.data-table--compact th:first-child,
.data-table--compact td:first-child {
	padding-left: 0;
}

.data-table--compact th:last-child,
.data-table--compact td:last-child {
	padding-right: 0;
}

.data-table--compact th {
	background: transparent;
}

.col-id,
.col-code,
.col-pills,
.col-count {
	width: 1%;
	white-space: nowrap;
}

.col-name {
	width: 40%;
	min-width: 200px;
}

.col-wide {
	width: 30%;
	min-width: 160px;
}

.col-count {
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.data-table th.col-count {
	text-align: right;
}

.cell-code {
	color: var(--text-secondary);
	font-family: var(--font-mono);
}

.cell-code--strong {
	color: var(--text-primary);
	font-weight: var(--weight-semibold);
}

.cell-name {
	color: var(--text-primary);
	font-weight: var(--weight-semibold);
}

a.cell-name:hover {
	text-decoration: underline;
}

.cell-description {
	display: block;
	margin-top: var(--space-xxs);
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
	line-height: var(--text-xs-lh);
}

mark {
	background: var(--product-accent-quiet);
	box-shadow: inset 0 -2px 0 var(--product-accent);
	color: inherit;
}

.cell-names {
	display: flex;
	align-items: center;
	gap: var(--space-sm);
}

.cell-names__shown {
	max-width: 280px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.pills,
.keys {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-xs);
}

.col-pills .pills {
	flex-wrap: nowrap;
}

.pill {
	display: inline-flex;
	align-items: center;
	padding: var(--space-xxs) var(--space-md);
	border-radius: var(--radius-full);
	background: var(--surface-muted);
	color: var(--text-primary);
	font-size: var(--text-xs-size);
	font-weight: var(--weight-semibold);
	line-height: var(--text-xs-lh);
	white-space: nowrap;
}

.pill--more {
	flex: none;
	color: var(--text-secondary);
}

.key {
	display: inline-flex;
	padding: var(--space-xxs) var(--space-md);
	border: 1px solid var(--border-default);
	border-radius: var(--radius-sm);
	background: var(--surface-subtle);
	color: var(--text-primary);
	font-size: var(--text-xs-size);
	line-height: var(--text-xs-lh);
}

.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-lg);
	padding: var(--space-8xl) var(--space-2xl);
	border-top: 1px solid var(--border-default);
	text-align: center;
}

.empty-state h2 {
	margin: 0;
}

.empty-state p {
	max-width: var(--width-sm);
	margin: 0;
	color: var(--text-secondary);
	font-size: var(--text-meta-size);
}

.empty-state__icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 48px;
	height: 48px;
	border-radius: var(--radius-full);
	background: var(--surface-muted);
	color: var(--text-secondary);
}

/* Pagination: the system's PaginationNumber and PaginationButton */

.pagination {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-lg);
	padding: var(--space-xl) var(--space-2xl);
	border-top: 1px solid var(--border-default);
}

.pagination__summary {
	margin: 0;
	color: var(--text-secondary);
	font-size: var(--text-meta-size);
}

.pagination__pages {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-sm);
	margin: 0;
	padding: 0;
	list-style: none;
}

.page-link {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border-radius: var(--radius-md);
	background: var(--surface-card);
	box-shadow: inset 0 0 0 1px var(--border-default);
	color: var(--text-primary);
	font-size: var(--text-small-size);
	font-weight: var(--weight-semibold);
	line-height: var(--text-small-lh);
	text-decoration: none;
	transition: background-color var(--transition-default), box-shadow var(--transition-default),
		color var(--transition-default);
}

.page-link:hover {
	background: var(--hover-surface);
	text-decoration: none;
}

.page-link[aria-current="page"] {
	background: var(--product-accent);
	box-shadow: inset 0 0 0 1px var(--product-accent);
	color: var(--text-on-brand);
}

.page-link--disabled {
	opacity: 0.3;
}

.page-gap {
	display: block;
	width: 24px;
	color: var(--text-secondary);
	text-align: center;
}

/* Market type page */

.breadcrumb ol {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-sm);
	margin: 0;
	padding: 0;
	list-style: none;
	color: var(--text-secondary);
	font-size: var(--text-meta-size);
}

.breadcrumb li {
	display: flex;
	align-items: center;
	gap: var(--space-sm);
}

.breadcrumb a {
	color: var(--text-primary);
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.breadcrumb [aria-current] {
	color: var(--text-primary);
}

.facts {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-xl) var(--space-5xl);
	margin: var(--space-xs) 0 0;
}

.facts div {
	display: flex;
	flex-direction: column;
	gap: var(--space-xs);
}

.facts dt {
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
	font-weight: var(--weight-semibold);
}

.facts dd {
	margin: 0;
	font-size: var(--text-meta-size);
}

.panels {
	display: flex;
	flex-wrap: wrap;
	align-items: stretch;
	gap: var(--space-3xl);
}

.panel {
	flex: 1 1 360px;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: var(--space-xl);
	padding: var(--space-3xl);
	border-radius: var(--radius-2xl);
	background: var(--surface-card);
	box-shadow: var(--shadow-sm);
}

.panel__intro {
	display: flex;
	flex-direction: column;
	gap: var(--space-xs);
}

.panel__intro h2 {
	margin: 0;
}

.panel__intro p {
	margin: 0;
	color: var(--text-secondary);
	font-size: var(--text-meta-size);
}

.panel__intro code {
	color: var(--text-primary);
}

.panel__source {
	margin: auto 0 0;
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
}

.panel--wide {
	flex-basis: 100%;
}

/* A labelled part of a panel, such as an item's sports. */
.panel__part {
	display: flex;
	flex-direction: column;
	gap: var(--space-md);
}

.panel__label {
	margin: 0;
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
	font-weight: var(--weight-semibold);
}

.panel__part > .muted {
	margin: 0;
	font-size: var(--text-meta-size);
}

.sport-names {
	margin: 0;
	font-size: var(--text-meta-size);
	line-height: 1.6;
}

/* An item's periods, grouped by the sports they belong to, each group a disclosure, in as many columns as fit. */
.period-groups {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
	gap: 0 var(--space-3xl);
	align-items: start;
}

.period-groups__group {
	border-top: 1px solid var(--border-default);
}

.period-groups__group summary {
	display: flex;
	align-items: center;
	gap: var(--space-md);
	min-height: 44px;
	font-size: var(--text-meta-size);
	list-style: none;
	cursor: pointer;
}

.period-groups__group summary::-webkit-details-marker {
	display: none;
}

.period-groups__sports {
	flex: 1;
	font-weight: var(--weight-semibold);
}

.period-groups__count {
	flex: none;
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
}

.period-groups__group summary .icon {
	flex: none;
	color: var(--text-secondary);
	transition: transform var(--transition-default);
}

.period-groups__group[open] summary .icon {
	transform: rotate(90deg);
}

.period-groups__group .rows {
	margin: 0 0 var(--space-md);
	font-size: var(--text-meta-size);
}

.rows,
.variants {
	margin: 0;
	padding: 0;
	list-style: none;
}

.rows li {
	display: flex;
	justify-content: space-between;
	gap: var(--space-md);
	padding: var(--space-md) 0;
	border-top: 1px solid var(--border-default);
	font-size: var(--text-meta-size);
}

.rows code {
	color: var(--text-secondary);
}

.variants li {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-sm);
	padding: var(--space-lg) 0;
	border-top: 1px solid var(--border-default);
}

.variants__number {
	width: 20px;
	color: var(--text-secondary);
	font-size: var(--text-xs-size);
	font-weight: var(--weight-semibold);
}

.variants .pill {
	margin-left: auto;
}

.json {
	margin: 0;
	padding: var(--space-xl);
	overflow-wrap: anywhere;
	white-space: pre-wrap;
	border: 1px solid var(--border-default);
	border-radius: var(--radius-xl);
	background: var(--surface-subtle);
	font-size: var(--text-meta-size);
	line-height: 1.6;
}

/* Loading and error pages */

.message {
	flex: 1 1 auto;
	align-items: flex-start;
	gap: var(--space-lg);
	padding: var(--space-4xl);
}

.message h1,
.message p {
	margin: 0;
}

.message p {
	max-width: var(--width-md);
	color: var(--text-secondary);
}

/*
 * Below 880px the content no longer fits beside the navigation (240px, a 32px gap, 560px and the insets), so the
 * navigation becomes one scrolling row of links above it.
 */

@media (max-width: 879px) {
	.shell {
		gap: var(--space-xl);
		padding-top: var(--space-xl);
	}

	.side-nav {
		flex-basis: 100%;
		flex-direction: row;
		gap: var(--space-xxs);
		padding: var(--space-sm);
		overflow-x: auto;
	}

	.side-nav__heading {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0, 0, 0, 0);
	}

	.side-nav__list {
		flex-direction: row;
	}

	.side-nav__link {
		white-space: nowrap;
	}

	.side-nav__size {
		display: none;
	}
}

/* Phone */

@media (max-width: 767px) {
	.filters,
	.results-bar,
	.pagination {
		padding-inline: var(--space-xl);
	}

	.panel,
	.message {
		padding: var(--space-2xl);
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		transition: none !important;
	}
}
