/*
 * Simple pill tabs for the GenerateBlocks Pro tabs block.
 *
 * Follows the flat house style of the Features block: a 1px outline in the
 * accent colour, a solid brand fill when active, no gradients or shadows, and
 * a softly rounded corner.
 *
 * Applies site wide. The selectors are built on the structural classes
 * (gb-tabs, gb-tabs__button, gb-tabs__item) instead of the hashed per-block
 * classes, so they survive block edits. They carry four or more classes on
 * purpose: the per-block CSS GenerateBlocks prints weighs a single class, so
 * this file wins without !important.
 *
 * Add the class sw-tabs-plain to a tabs block to keep its own styling.
 */

.gb-tabs:not(.sw-tabs-plain) {
	--sw-tabs-brand: #215390;
	--sw-tabs-on-brand: #ffffff;
	--sw-tabs-accent: #00838a;
	--sw-tabs-radius: 12px;
	--sw-tabs-rule: rgba(33, 83, 144, 0.12);
	--sw-tabs-rule-gap: 20px;
	--sw-tabs-gap: 48px;
	--sw-tabs-duration: 0.3s;
}

/* ------------------------------------------------------------------ reset
 *
 * GenerateBlocks may carry its own rule under the tab row on the wrapper or on
 * the panel container. Those are cleared so the only line left is the soft one
 * on the button row below, instead of two stacked borders.
 */

.gb-tabs:not(.sw-tabs-plain) {
	border-bottom: 0;
}

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__items {
	border-top: 0;
}

/* ---------------------------------------------------------------- buttons */

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	justify-content: flex-start;
	width: 100%;
	max-width: 100%;
	margin-inline: 0;
	margin-block: 0 var(--sw-tabs-gap);
	padding: 0 0 var(--sw-tabs-rule-gap);
	border: 0;
	border-bottom: 1px solid var(--sw-tabs-rule);
	background: none;
}

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons .gb-tabs__button {
	flex: 0 0 auto;
	margin: 0;
	padding: 12px 24px;
	border: 1px solid var(--sw-tabs-accent);
	/*
	 * Beats the underline written for the old text-only tabs, which still
	 * lives outside the theme:
	 *
	 *   .gb-container[role="tablist"] .gb-button:not(.gb-block-is-current) {
	 *       border-bottom: 2px solid #00838A !important;
	 *   }
	 *
	 * Drop !important here once that rule is gone.
	 */
	border-bottom-width: 1px !important;
	border-radius: var(--sw-tabs-radius);
	background-color: transparent;
	box-shadow: none;
	color: var(--sw-tabs-accent);
	font: inherit;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	cursor: pointer;
	transition:
		background-color var(--sw-tabs-duration) ease,
		border-color var(--sw-tabs-duration) ease,
		color var(--sw-tabs-duration) ease;
}

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons .gb-tabs__button:hover,
.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons .gb-tabs__button:focus {
	background-color: rgba(0, 131, 138, 0.08);
	color: var(--sw-tabs-accent);
}

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons .gb-tabs__button:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons .gb-tabs__button.gb-block-is-current,
.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons .gb-tabs__button[aria-selected="true"] {
	border-color: var(--sw-tabs-brand);
	background-color: var(--sw-tabs-brand);
	color: var(--sw-tabs-on-brand);
}

/* ---------------------------------------------------------------- panels
 *
 * GenerateBlocks toggles the panels with display: none, which cannot be
 * animated and makes the page jump when panels differ in height. The panels
 * are stacked in a single grid cell instead, so the block keeps the height of
 * its tallest panel and the switch can fade.
 */

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__items {
	display: grid;
	grid-template-areas: "panel";
	align-items: start;
}

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__items .gb-tabs__item {
	display: block;
	grid-area: panel;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition:
		opacity var(--sw-tabs-duration) ease,
		visibility 0s linear var(--sw-tabs-duration);
}

.gb-tabs:not(.sw-tabs-plain) .gb-tabs__items .gb-tabs__item.gb-tabs__item-open {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition-delay: 0s;
}

/* ---------------------------------------------------------------- mobile */

@media (max-width: 767px) {
	.gb-tabs:not(.sw-tabs-plain) {
		--sw-tabs-gap: 32px;
	}

	/*
	 * The fade on the right edge hints that the row scrolls. It is a mask, so
	 * it also softens the rule underneath and needs no extra element.
	 */
	.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons {
		--sw-tabs-fade: 36px;

		flex-wrap: nowrap;
		justify-content: flex-start;
		width: 100%;
		/* Room at the end so the last pill is never stuck under the fade. */
		padding-inline-end: var(--sw-tabs-fade);
		overflow-x: auto;
		-webkit-mask-image: linear-gradient(to right, #000 calc(100% - var(--sw-tabs-fade)), transparent);
		mask-image: linear-gradient(to right, #000 calc(100% - var(--sw-tabs-fade)), transparent);
		scroll-snap-type: x proximity;
		scrollbar-width: none;
		-ms-overflow-style: none;
		-webkit-overflow-scrolling: touch;
	}

	.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons::-webkit-scrollbar {
		display: none;
	}

	.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons .gb-tabs__button {
		padding: 10px 18px;
		white-space: nowrap;
		scroll-snap-align: center;
	}
}

/* -------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
	.gb-tabs:not(.sw-tabs-plain) .gb-tabs__buttons .gb-tabs__button,
	.gb-tabs:not(.sw-tabs-plain) .gb-tabs__items .gb-tabs__item {
		transition-duration: 0.01ms;
	}
}
