/**
 * Allied Tabs — styles for the dependency-free tab controller.
 *
 * Colours resolve from theme.json presets where available and fall back to the
 * literal brand values, so the same file works on a site whose theme.json has
 * not defined them (e.g. the Bricks build on machineenclosure).
 */

.allied-tabs {
	--allied-tabs-gap: 12px;
	--allied-tabs-radius: 5px;
	--allied-tabs-border: var( --wp--preset--color--gray-300, #d0d0d0 );
	--allied-tabs-surface: var( --wp--preset--color--white, #fff );
	--allied-tabs-panel-bg: var( --wp--preset--color--gray-200, #e7e7e7 );
	--allied-tabs-text: var( --wp--preset--color--body-color, #494949 );
	--allied-tabs-accent: var( --wp--preset--color--primary, #006390 );
	--allied-tabs-focus: var( --wp--preset--color--secondary, #ffbd1c );
}

/* Tab list ---------------------------------------------------------------- */

.allied-tabs__list {
	display: flex;
	flex-wrap: wrap;
	gap: var( --allied-tabs-gap );
	margin: 0 0 var( --allied-tabs-gap );
	padding: 0;
}

/* wpautop turns the newlines between hand-written buttons into <br> tags, which
   become flex/grid items and add phantom rows. The markup is authored for
   readability, so drop them here rather than demanding single-line HTML. */
.allied-tabs > br,
.allied-tabs__list > br {
	display: none;
}

/* Same reason: an empty <p> wrapper injected between the list and the panels
   would otherwise occupy a grid cell in the vertical layout. */
.allied-tabs > p:empty {
	display: none;
}

.allied-tabs__tab {
	flex: 1 1 220px;
	display: flex;
	align-items: center;
	gap: 12px;
	/* Trailing space is wider so the two-line label never crowds the edge. */
	padding: 10px 30px 10px 10px;
	border: 1px solid var( --allied-tabs-border );
	border-radius: var( --allied-tabs-radius );
	background: var( --allied-tabs-surface );
	color: var( --allied-tabs-text );
	font: inherit;
	line-height: 1.35;
	text-align: left;
	cursor: pointer;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.allied-tabs__tab:hover {
	border-color: var( --allied-tabs-accent );
}

/* Keyboard-only ring; :focus-visible keeps it off mouse clicks. */
.allied-tabs__tab:focus-visible {
	outline: 2px solid var( --allied-tabs-focus );
	outline-offset: 2px;
}

.allied-tabs__tab.is-active {
	border-color: var( --allied-tabs-accent );
	box-shadow: inset 0 -3px 0 0 var( --allied-tabs-accent );
}

.allied-tabs__tab img,
.allied-tabs__tab svg {
	flex: 0 0 auto;
	width: 48px;
	height: auto;
}

/* Panels ------------------------------------------------------------------ */

/* [hidden] alone loses to `display:flex` from a builder's utility class. */
.allied-tabs__panel[hidden] {
	display: none !important;
}

.allied-tabs__panel {
	padding: 24px;
	border: 1px solid var( --allied-tabs-border );
	border-radius: var( --allied-tabs-radius );
	background: var( --allied-tabs-panel-bg );
}

.allied-tabs__panel:focus-visible {
	outline: 2px solid var( --allied-tabs-focus );
	outline-offset: 2px;
}

/* Vertical variant -------------------------------------------------------- */

.allied-tabs[data-allied-orientation="vertical"] {
	display: grid;
	grid-template-columns: minmax(200px, 280px) 1fr;
	gap: var( --allied-tabs-gap );
	align-items: start;
}

.allied-tabs[data-allied-orientation="vertical"] .allied-tabs__list {
	flex-direction: column;
	margin-bottom: 0;
}

.allied-tabs[data-allied-orientation="vertical"] .allied-tabs__tab {
	flex: 0 0 auto;
}

.allied-tabs[data-allied-orientation="vertical"] .allied-tabs__tab.is-active {
	box-shadow: inset 3px 0 0 0 var( --allied-tabs-accent );
}

@media ( max-width: 781px ) {
	/* Collapse to the stacked layout the horizontal variant already uses. */
	.allied-tabs[data-allied-orientation="vertical"] {
		grid-template-columns: 1fr;
	}

	.allied-tabs[data-allied-orientation="vertical"] .allied-tabs__list {
		margin-bottom: var( --allied-tabs-gap );
	}
}

/* Before the script runs, show the first panel and hide the rest so the
   content is readable and there is no flash of every panel at once. */
.allied-tabs:not([data-allied-tabs-ready]) .allied-tabs__panel:not(:first-of-type) {
	display: none;
}

@media ( prefers-reduced-motion: reduce ) {
	.allied-tabs__tab {
		transition: none;
	}
}

/* Shortcode output ------------------------------------------------------- */

.allied-tabs__tab-subtitle {
	display: inline-block;
	font-size: 0.9em;
	opacity: 0.8;
}

/* Sites with a fixed/sticky header (e.g. the Bricks builds) would otherwise
   hide a tab that the browser scrolls to — on page load with a #hash, or when
   focus moves during keyboard navigation. Reserve room above the scroll target.
   Override --allied-tabs-scroll-offset per site if the header is taller. */
.allied-tabs,
.allied-tabs__tab,
.allied-tabs__panel {
	scroll-margin-top: var( --allied-tabs-scroll-offset, 120px );
}
