/**
 * ATM Tarifes i zones — front styles.
 *
 * ATM brand: red #BF0001. Accessible (WCAG 2.2 AA): body text stays dark on white, red is used for
 * accents/headings and as a background only under white text. Class names kebab-case, variants with
 * a single underscore. All rules are scoped under .ic-atm-fares so nothing leaks to the theme.
 */

.ic-atm-fares {
	--ic-atm-red: #bf0001;
	--ic-atm-red-dark: #9c0001;
	--ic-atm-ink: #24272a;
	--ic-atm-muted: #5a5f63;
	--ic-atm-line: #e3e5e7;
	--ic-atm-panel: #f4f5f6;
	--ic-atm-card: #fff;
	color: var(--ic-atm-ink);
	font-size: 1.02rem;
	line-height: 1.5;
}

.ic-atm-fares *,
.ic-atm-fares *::before,
.ic-atm-fares *::after {
	box-sizing: border-box;
}

.screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

/* ---------------------------------------------------------------- shared form */

.ic-atm-fares-field {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	min-width: 0;
}

.ic-atm-fares-field > label {
	font-weight: 600;
}

.ic-atm-fares select,
.ic-atm-fares input[type="number"] {
	padding: 0.55rem 0.65rem;
	border: 1px solid #9aa0a4;
	border-radius: 6px;
	font-size: 1rem;
	line-height: 1.25;
	background: #fff;
	color: var(--ic-atm-ink);
}

.ic-atm-fares select:focus-visible,
.ic-atm-fares input:focus-visible {
	outline: 2px solid var(--ic-atm-red);
	outline-offset: 2px;
}

/* ---------------------------------------------------------------- zone counter */

.ic-atm-zc-fields {
	display: flex;
	align-items: flex-end;
	gap: 1rem;
	padding: 1.25rem 1rem;
	background: var(--ic-atm-panel);
	border-radius: 8px;
}

.ic-atm-zc-fields .ic-atm-fares-field {
	flex: 1 1 0;
}

.ic-atm-zc-arrow {
	font-size: 1.6rem;
	color: var(--ic-atm-red);
	padding-bottom: 0.45rem;
	font-weight: 700;
}

.ic-atm-zc-result:focus {
	outline: none;
}

/* Result: a clean white card with a red accent, big red number. Accessible on white. */
.ic-atm-zc-card {
	margin-top: 1.1rem;
	padding: 1.5rem 1.75rem;
	border: 1px solid var(--ic-atm-line);
	border-top: 4px solid var(--ic-atm-red);
	border-radius: 8px;
	background: var(--ic-atm-card);
	text-align: center;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.ic-atm-zc-trip {
	margin: 0 0 0.75rem;
	font-size: 1.1rem;
	color: var(--ic-atm-ink);
}

.ic-atm-zc-card .ic-atm-zc-trip strong {
	font-weight: 700;
}

.ic-atm-zc-big {
	display: inline-flex;
	align-items: baseline;
	justify-content: center;
	gap: 0.5rem;
	padding: 0.4rem 1.4rem;
	border-radius: 999px;
	background: var(--ic-atm-red);
}

.ic-atm-zc-num {
	font-size: 3.4rem;
	font-weight: 800;
	line-height: 1;
	color: #fff;
}

.ic-atm-zc-num-lbl {
	font-size: 1.25rem;
	font-weight: 600;
	text-transform: lowercase;
	color: #fff;
}

/* Warning variant (same stop twice): white card, red framing and message. */
.ic-atm-zc-card_warn {
	border: 1px solid var(--ic-atm-red);
	border-top: 4px solid var(--ic-atm-red);
}

.ic-atm-zc-msg {
	margin: 0;
	font-weight: 600;
	color: var(--ic-atm-red);
	font-size: 1.1rem;
}

/* ---------------------------------------------------------------- fare finder */

.ic-atm-ff-fields {
	display: flex;
	flex-wrap: wrap;
	gap: 1rem;
	padding: 1.25rem 1rem;
	background: var(--ic-atm-panel);
	border-radius: 8px;
}

.ic-atm-ff-fields .ic-atm-fares-field {
	flex: 0 1 auto;
}

/* Monthly trips: as wide as its label (which varies by language), not narrower. */
.ic-atm-ff-viatges {
	width: 100%;
	min-width: 6rem;
}

.ic-atm-ff-bonuses {
	margin: 1rem 0 0;
	padding: 1rem 1.1rem;
	border: 1px solid var(--ic-atm-line);
	border-radius: 8px;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1.5rem;
	align-items: flex-start;
}

.ic-atm-ff-bonuses legend {
	font-weight: 600;
	padding: 0 0.4rem;
}

.ic-atm-ff-check {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
}

/* The "large family" option flows inline like the other checkboxes; only its General/Special category
   sits right below it. */
.ic-atm-ff-fmn-group {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
}

/* The FM/FN General/Special switch: hidden until "large family" is ticked, and indented so it reads
   as belonging to it. The [hidden] rule must win over the inline-flex layout. */
.ic-atm-ff-fmnt {
	display: inline-flex;
	align-items: center;
	gap: 0.75rem;
	margin-left: 1.7rem;
}

.ic-atm-ff-fmnt[hidden] {
	display: none;
}

.ic-atm-fares-field-label {
	font-weight: 600;
}

/* Zones as an accessible 4-position switch: native radios (arrow-key navigation and screen-reader
   support) hidden but focusable, styled as segments; the selected number fills with the brand colour. */
.ic-atm-ff-zonesel {
	display: inline-flex;
	align-self: flex-start;
	border: 1px solid #9aa0a4;
	border-radius: 6px;
	overflow: hidden;
}

.ic-atm-ff-zone-radio {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.ic-atm-ff-zone-btn {
	display: block;
	min-width: 2.6rem;
	/* Same font, line-height and vertical padding as the number input, so the switch is exactly as
	   tall (the label would otherwise inherit the wrapper's line-height: 1.5). */
	padding: 0.55rem 0.9rem;
	font-size: 1rem;
	line-height: 1.25;
	text-align: center;
	font-weight: 700;
	color: var(--ic-atm-ink);
	background: #fff;
	border-left: 1px solid #9aa0a4;
	cursor: pointer;
}

.ic-atm-ff-zonesel .ic-atm-ff-zone-btn:first-of-type {
	border-left: 0;
}

.ic-atm-ff-zone-radio:checked + .ic-atm-ff-zone-btn {
	background: var(--ic-atm-red);
	color: #fff;
}

.ic-atm-ff-zone-radio:focus-visible + .ic-atm-ff-zone-btn {
	outline: 2px solid var(--ic-atm-red);
	outline-offset: -2px;
}

/* Sort bar above the results: "Order by:" then links, the active one in red. Hidden until there are
   results (JS), with room above it. */
.ic-atm-ff-sort {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.35rem 0.9rem;
	margin: 1.75rem 0 1rem;
}

/* The [hidden] attribute must win over display:flex, so it stays hidden until there are results. */
.ic-atm-ff-sort[hidden] {
	display: none;
}

.ic-atm-ff-sort-label {
	font-weight: 600;
}

.ic-atm-ff-sort-link {
	background: none;
	border: 0;
	padding: 0;
	font: inherit;
	color: var(--ic-atm-ink);
	cursor: pointer;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.ic-atm-ff-sort-link:hover {
	color: var(--ic-atm-red);
}

.ic-atm-ff-sort-link_active {
	color: var(--ic-atm-red);
	font-weight: 700;
	text-decoration: none;
	cursor: default;
}

.ic-atm-ff-sort-link:focus-visible {
	outline: 2px solid var(--ic-atm-red);
	outline-offset: 2px;
}

.ic-atm-ff-result {
	margin-top: 1.4rem;
}

.ic-atm-ff-result:focus {
	outline: none;
}

.ic-atm-ff-empty {
	font-style: italic;
	color: var(--ic-atm-muted);
}

.ic-atm-ff-h {
	margin: 1.6rem 0 0.9rem;
	padding-bottom: 0.35rem;
	border-bottom: 2px solid var(--ic-atm-red);
	color: var(--ic-atm-red);
	font-size: 1.35rem;
}

/* Responsive grid, left-aligned. Up to 4 columns that always fill the width (no right margin): on a
   wide screen the min track grows to a quarter of the row so a 5th column never appears and the cards
   stay wide; on narrower screens it falls back to a 17rem min and wraps. min( ,100%) avoids overflow. */
.ic-atm-ff-group {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(max(min(17rem, 100%), (100% - 3.75rem) / 4), 1fr));
	gap: 1.25rem;
	align-items: start;
}

/* A group with no cards is hidden along with its heading (display:grid would beat [hidden]). */
.ic-atm-ff-group[hidden] {
	display: none;
}

/* Each result: the fixed-shape card, and below it any requirements. */
.ic-atm-ff-item {
	display: flex;
	flex-direction: column;
}

/* A card that has just appeared (a bonus was ticked) grows in from its centre. */
@keyframes ic-atm-ff-grow {
	from {
		transform: scale(0.2);
		opacity: 0;
	}
	to {
		transform: scale(1);
		opacity: 1;
	}
}

.ic-atm-ff-item_enter {
	animation: ic-atm-ff-grow 0.4s cubic-bezier(0.34, 1.15, 0.64, 1) both;
}

/* A card being removed (a bonus was unticked) shrinks back into its centre before it goes. */
@keyframes ic-atm-ff-shrink {
	from {
		transform: scale(1);
		opacity: 1;
	}
	to {
		transform: scale(0.2);
		opacity: 0;
	}
}

.ic-atm-ff-item_leave {
	animation: ic-atm-ff-shrink 0.32s cubic-bezier(0.36, 0, 0.66, -0.2) both;
	pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
	.ic-atm-ff-item_enter,
	.ic-atm-ff-item_leave {
		animation: none;
	}
}

/* Each result echoes the physical ATM card: the neutral card art as a faint background, the name
   top-left and the characteristic icons top-right, prices along the bottom. A flex column with the
   card proportion; the content is laid out to fit so the shape is kept. */
.ic-atm-ff-titol {
	display: flex;
	flex-direction: column;
	position: relative;
	aspect-ratio: 248 / 159;
	padding: 1.15rem 1.3rem;
	border: 1px solid var(--ic-atm-line);
	border-radius: 12px;
	background-color: var(--ic-atm-card);
	background-image: url( ../img/card-neutral.svg );
	background-repeat: no-repeat;
	background-position: center;
	background-size: cover;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
	transition: box-shadow 0.15s ease, transform 0.15s ease;
	/* A single wide card is capped and left-aligned instead of stretching huge; the cap is above the
	   4-column track width so the cards still fill the row on large screens. */
	max-width: 26rem;
	margin-inline: 0;
}

.ic-atm-ff-titol:hover {
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
	transform: translateY(-2px);
}

.ic-atm-ff-titol_avis {
	opacity: 0.72;
}

/* Header row: name on the left, icons on the right. */
.ic-atm-ff-head {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 0.75rem;
}

/* Characteristic icons: the red brand badges, top-right (up to 2 per row, as on the card). */
.ic-atm-ff-specs {
	list-style: none;
	margin: 0.1rem 0 0;
	padding: 0;
	flex: 0 0 auto;
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	gap: 0.35rem;
	max-width: 5rem;
}

.ic-atm-ff-spec {
	display: inline-flex;
	width: 2.1rem;
	height: 2.1rem;
	filter: drop-shadow( 1px 1px 0 rgba(0, 0, 0, 0.18) );
}

.ic-atm-ff-spec-ico {
	width: 100%;
	height: 100%;
	display: block;
}

/* Dades block (name, zones, quantity), top-left. */
.ic-atm-ff-dades {
	flex: 1 1 auto;
	min-width: 0;
}

.ic-atm-ff-nom {
	margin: 0 0 0.3rem;
	color: var(--ic-atm-ink);
	font-size: 1.4rem;
	font-weight: 700;
	line-height: 1.15;
}

/* The "T-" prefix in brand red, the rest of the name in ink (as on the fare range). */
.ic-atm-ff-t {
	color: var(--ic-atm-red);
}

.ic-atm-ff-zones {
	margin: 0;
	font-weight: 700;
	font-size: 1.1rem;
}

.ic-atm-ff-q {
	margin: 0.1rem 0 0;
	font-weight: 700;
	font-size: 0.95rem;
	color: var(--ic-atm-muted);
}

/* Notes below the card, so they never clip the figures inside it. */
.ic-atm-ff-avis {
	margin: 0.4rem 0.2rem 0;
	font-size: 0.85rem;
	line-height: 1.3;
	color: var(--ic-atm-red);
}

.ic-atm-ff-cond {
	margin: 0.4rem 0.2rem 0;
	font-size: 0.85rem;
	line-height: 1.3;
	color: var(--ic-atm-muted);
}

/* Prices: three columns along the bottom of the card (label over value). */
.ic-atm-ff-preus {
	list-style: none;
	margin: auto 0 0;
	padding: 0.55rem 0 0;
	display: flex;
	gap: 0.6rem;
	border-top: 1px solid var(--ic-atm-line);
}

.ic-atm-ff-col {
	flex: 1 1 0;
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.ic-atm-ff-plbl {
	color: var(--ic-atm-muted);
	font-size: 0.88rem;
	line-height: 1.2;
	margin-bottom: 0.25rem;
}

.ic-atm-ff-v {
	font-weight: 700;
	font-size: 1.15rem;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

/* Total: emphasised, aligned to the inner edge of its column. */
.ic-atm-ff-total {
	text-align: right;
}

.ic-atm-ff-total .ic-atm-ff-v {
	color: var(--ic-atm-red);
	font-size: 1.3rem;
}

.ic-atm-ff-pcalc {
	display: block;
	font-size: 0.78rem;
	color: var(--ic-atm-muted);
	font-weight: 400;
	white-space: nowrap;
}

/* Card-issue-fees note, always shown below the results. */
.ic-atm-ff-note {
	margin: 1.5rem 0 0;
	font-size: 0.9rem;
	color: var(--ic-atm-muted);
}

.ic-atm-ff-note a {
	color: var(--ic-atm-red);
}

/* Tom Select: match the field height and the brand focus. */
.ic-atm-fares .ts-control {
	border: 1px solid #9aa0a4;
	border-radius: 6px;
	padding: 0.45rem 0.65rem;
}

/* Tom Select ships a 13px font on the control, its input and the dropdown; bump all three so the
   stop names read at the same size as the rest of the form. */
.ic-atm-fares .ts-control,
.ic-atm-fares .ts-control input,
.ic-atm-fares .ts-dropdown {
	font-size: 1rem;
}

.ic-atm-fares .ts-control.focus {
	outline: 2px solid var(--ic-atm-red);
	outline-offset: 2px;
	border-color: var(--ic-atm-red);
	box-shadow: none;
}

@media (max-width: 640px) {
	.ic-atm-zc-fields {
		flex-direction: column;
		align-items: stretch;
	}
	.ic-atm-zc-arrow {
		transform: rotate(90deg);
		align-self: center;
		padding: 0;
	}
	/* The bonus options stack one per line. */
	.ic-atm-ff-bonuses {
		flex-direction: column;
	}
}
