/*
	Card entry frame styling.

	Notes:
	- The Content-Security-Policy served from this application forbids inline styles (style-src 'self' covers
	  style attributes as well as style elements), so every rule lives here and state is expressed by toggling
	  classes and the hidden attribute.
	- Theming is driven entirely by custom properties, selected by the data-theme attribute the server
	  writes onto the html element from the "theme" query parameter.
*/

/* #region Theme tokens */
:root,
[data-theme="light"] {
	color-scheme: light;

	--cf-surface: #ffffff;
	--cf-text: #1a1c1e;
	--cf-text-muted: #5a6068;
	--cf-border: #c4c7cb;
	--cf-border-hover: #8a9099;
	--cf-focus: #1565c0;
	--cf-error: #b3261e;
}

[data-theme="dark"] {
	color-scheme: dark;

	--cf-surface: #16181a;
	--cf-text: #e6e8ea;
	--cf-text-muted: #a8aeb5;
	--cf-border: #4a4f55;
	--cf-border-hover: #767c83;
	--cf-focus: #8ab4f8;
	--cf-error: #f2b8b5;
}
/* #endregion */

/* #region Layout */
*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	/*
		The frame is sized by the host page's iframe element, so the document fills whatever it is given
		rather than imposing a height of its own. No min-width: content reflows all the way down (WCAG 1.4.10).
	*/
	height: 100%;
}

body {
	margin: 0;
	padding: 0;
	background-color: var(--cf-surface);
	color: var(--cf-text);
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 1rem;
	line-height: 1.5;
	text-rendering: optimizeLegibility;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

.card-frame {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	padding: 1rem;
	margin: 0;
	width: 100%;
}

.card-frame__row {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
	gap: 1rem;
}
/* #endregion */

/* #region Fields */
.field {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	min-width: 0;
}

.field__label {
	font-size: 0.875rem;
	font-weight: 500;
	color: var(--cf-text);
}

.field__control {
	position: relative;
	display: flex;
	align-items: center;
}

.field__input {
	width: 100%;
	min-width: 0;
	padding: 0.625rem 0.75rem;
	border: 1px solid var(--cf-border);
	border-radius: 0.25rem;
	background-color: var(--cf-surface);
	color: var(--cf-text);
	font-family: inherit;
	font-size: 1rem;
	line-height: 1.5;
	/* Tabular figures keep the digit groups from shifting horizontally as the user types: */
	font-variant-numeric: tabular-nums;
}

.field__input:hover {
	border-color: var(--cf-border-hover);
}

.field__input:focus-visible {
	outline: 2px solid var(--cf-focus);
	outline-offset: 1px;
	border-color: var(--cf-focus);
}

.field__input[aria-invalid="true"] {
	border-color: var(--cf-error);
}

/* Reserve room for the brand strip so long card numbers never run underneath it: */
.field__input--card-number {
	padding-right: 5.5rem;
}

.field__errors {
	display: flex;
	flex-direction: column;
	min-height: 1.25rem;
}

.field__error {
	margin: 0;
	color: var(--cf-error);
	font-size: 0.8125rem;
	line-height: 1.25rem;
}
/* #endregion */

/* #region Accepted card brands */
.brands {
	position: absolute;
	right: 0.5rem;
	display: flex;
	align-items: center;
	gap: 0.25rem;
	list-style: none;
	margin: 0;
	padding: 0;
	/* Purely informational, and sits over the input: never intercept clicks meant for the field. */
	pointer-events: none;
}

.brands__item {
	display: flex;
	align-items: center;
}

.brands__item img {
	display: block;
	height: 1.1875rem;
	width: auto;
}

.brands__icon {
	display: block;
	height: 1.1875rem;
	width: 1.1875rem;
	color: var(--cf-text-muted);
}

/*
	Every accepted brand is listed while the field is empty; once the user starts typing only the matching
	brand remains (the generic icon standing in for anything unrecognised). Script toggles this class.
*/
.brands__item--hidden {
	display: none;
}
/* #endregion */

/* #region Utilities */
/*
	Visually hidden but exposed to assistive technology; used for the page heading and the live region
	that announces the detected card brand.
*/
.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}
/* #endregion */

/* #region Preferences */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}

@media (prefers-contrast: more) {
	:root,
	[data-theme="light"] {
		--cf-border: #6b7077;
		--cf-text-muted: #3f444a;
	}

	[data-theme="dark"] {
		--cf-border: #9aa0a7;
		--cf-text-muted: #ccd1d6;
	}
}
/* #endregion */
