/**
 * The collapsed sidebar bar, shared by the finder and the measure pages.
 *
 * Below the two-column breakpoint both of those screens stop having a sidebar: it becomes a
 * full-width block stacked on top of the content, which is the whole problem. A screenful of
 * controls between the visitor and what they came to read, and once scrolled past, unreachable
 * without scrolling all the way back up.
 *
 * So below that breakpoint the sidebar's panels collapse behind this bar, which sticks under
 * the site header while the content scrolls beneath it, and they open over the content rather
 * than pushing it down - pushing would move whatever was being read at the moment of the tap,
 * and move it back on close.
 *
 * Registered as its own style handle and listed in both blocks' block.json, the way
 * ceip-favourites is for the script. What belongs to a particular screen - which panels exist,
 * where they float to - stays in that block's own stylesheet, keyed off the [data-ceip-open]
 * attribute favourites.js sets. This file owns only the bar itself.
 *
 * 64em is deliberately each layout's own breakpoint rather than a third one of its own: the
 * question "is the sidebar a sidebar?" has one answer, and this is it.
 */

.ceip-bar {
	/* Defaults, not a theme: both blocks happen to want the same values, and either can
	   override them on its own root without touching this file. */
	--ceip-bar-rule: rgba(0, 0, 0, 0.12);
	--ceip-bar-surface: #fff;
	--ceip-bar-accent: #1c5d8a;
	--ceip-bar-accent-fg: #fff;
	--ceip-bar-badge: #007847;
	--ceip-bar-badge-fg: #fff;

	display: none;
}

@media (prefers-color-scheme: dark) {
	.ceip-bar {
		--ceip-bar-rule: rgba(255, 255, 255, 0.22);
		--ceip-bar-surface: #1b1b1b;
	}
}

@media (max-width: 63.99em) {
	/* The bar and its buttons ship hidden and are revealed by the block's own script as each
	   panel behind them is. The display declarations below are class rules, which outrank the
	   UA sheet's [hidden] - so the attribute has to be honoured explicitly here or it does
	   nothing inside this media query. */
	.ceip-bar[hidden],
	.ceip-bar__button[hidden] {
		display: none;
	}

	.ceip-bar {
		display: flex;
		gap: 0.375rem;
		padding: 0.375rem;
		border: 1px solid var(--ceip-bar-rule);
		border-radius: 4px;
		background: var(--ceip-bar-surface);
		/* Enough to read as floating above the content passing under it, no more. */
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
	}

	/* Equal shares at a zero basis, so no button's label decides the split and a long
	   translation cannot push another one off the bar. A bar with a single button gets the
	   whole width, which is what one button should have. */
	.ceip-bar__button {
		flex: 1 1 0;
		display: flex;
		align-items: center;
		justify-content: center;
		gap: 0.375rem;
		min-width: 0;
		/* Tall enough to be a comfortable touch target at this font size. */
		padding: 0.625rem 0.375rem;
		border: 0;
		border-radius: 3px;
		background: transparent;
		color: inherit;
		font-family: inherit;
		font-size: 0.875rem;
		font-weight: 600;
		line-height: 1.2;
		cursor: pointer;
	}

	/* The open panel's button is filled, so the bar says which one is showing. */
	.ceip-bar__button[aria-expanded="true"] {
		background: var(--ceip-bar-accent);
		color: var(--ceip-bar-accent-fg);
	}

	.ceip-bar__icon {
		flex: none;
		display: inline-flex;
	}

	/* Outline by default, filled when the panel is open or when the thing behind it has
	   something in it - filters applied, upgrades saved. Both faces are in the markup for the
	   same reason the cards carry both: a :hover or [aria-expanded] rule cannot repaint an
	   inline SVG, and encoding each glyph twice as a background image puts the colours
	   somewhere they cannot follow the button's own. */
	.ceip-bar__icon .ceip-icon--funnel-filled,
	.ceip-bar__icon .ceip-icon--bookmark-saved {
		display: none;
	}

	.ceip-bar__button[aria-expanded="true"] .ceip-icon--funnel,
	.ceip-bar__button[aria-expanded="true"] .ceip-icon--bookmark,
	.ceip-bar__button[data-ceip-bar-active] .ceip-icon--funnel,
	.ceip-bar__button[data-ceip-bar-active] .ceip-icon--bookmark {
		display: none;
	}

	.ceip-bar__button[aria-expanded="true"] .ceip-icon--funnel-filled,
	.ceip-bar__button[aria-expanded="true"] .ceip-icon--bookmark-saved,
	.ceip-bar__button[data-ceip-bar-active] .ceip-icon--funnel-filled,
	.ceip-bar__button[data-ceip-bar-active] .ceip-icon--bookmark-saved {
		display: inline-flex;
	}

	/* The label is the one part that may give way: on the narrowest phones two buttons, two
	   icons and a count do not leave room for two labels on one line each. It wraps rather than
	   truncating - "Search &" over "filter" is still the label, where "Search &..." is a guess
	   the icon has to rescue. The buttons centre their contents, so one wrapping and another
	   not costs nothing. */
	.ceip-bar__label {
		min-width: 0;
		text-align: center;
	}

	/* "Something is on behind here", which is all a bar has room to say; the panel it opens
	   spells out what. */
	.ceip-bar__dot {
		flex: none;
		width: 0.4375rem;
		height: 0.4375rem;
		border-radius: 50%;
		background: var(--ceip-bar-badge);
	}

	.ceip-bar__button[aria-expanded="true"] .ceip-bar__dot {
		background: currentColor;
	}

	.ceip-bar__count {
		flex: none;
		min-width: 1.25rem;
		padding: 0 0.25rem;
		border-radius: 0.625rem;
		background: var(--ceip-bar-badge);
		color: var(--ceip-bar-badge-fg);
		font-size: 0.8125rem;
		line-height: 1.25rem;
		text-align: center;
	}

	.ceip-bar__button[aria-expanded="true"] .ceip-bar__count {
		background: var(--ceip-bar-accent-fg);
		color: var(--ceip-bar-accent);
	}
}
