/**
 * The consent banner and its reopen control.
 *
 * Plain by design (DECISIONS.md, "register by function" — legal and consent surfaces stay
 * flat). Colours come from the theme's own palette so it does not introduce a second one;
 * Dana or Félix are free to restyle it, this is the boring baseline that already meets
 * contrast and works with no JavaScript-driven animation to fight `prefers-reduced-motion`.
 */

.daylon-consent-banner {
	position: fixed;
	inset-inline: 0;
	bottom: 0;
	z-index: 100000;
	box-sizing: border-box;
	max-width: 100%;
	/* The height rule of the header/footer spec (v25 §8b.4): at most 85 % of the viewport, and
	   it scrolls inside itself, its top edge always on screen. Text at 200 % falls under this
	   rule rather than under a width rule: at 320×568 the banner had grown to 534px with no way
	   to scroll it (DAY-603). At 100 % text it is far below the cap, so nothing changes there. */
	max-height: 85vh;
	max-height: 85dvh;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 1rem 1.25rem;
	background: var( --wp--preset--color--base, #f8f3e8 );
	color: var( --wp--preset--color--main, #221d17 );
	border-top: 1px solid var( --wp--preset--color--border-light, #ecdfc4 );
	box-shadow: 0 -2px 12px rgba( 0, 0, 0, 0.08 );
}

.daylon-consent-banner__row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 1rem;
	max-width: 64rem;
	margin-inline: auto;
}

.daylon-consent-banner__text {
	--daylon-consent-leading: 1.5;
	flex: 1 1 20rem;
	margin: 0;
	font-size: var( --wp--preset--font-size--small, 0.95rem );
	line-height: var( --daylon-consent-leading );
	/* Rule 9 (§8b.4a, DAY-631): «no horizontal scroll inside the banner». With text at 400 % on
	   320, one word of the message is wider than the line (403px of 288) and pushed the banner
	   196px sideways. A word breaks only when it cannot fit on a line of its own, so at 100 % and
	   200 % nothing breaks that did not before. */
	overflow-wrap: anywhere;
}

/* The link moves to the next line whole whenever it fits there — what `nowrap` did — but, as an
   inline block, it wraps inside itself once it is wider than the line: «Política de cookies»
   was 480px at 400 % on a 288px line (DAY-631). Same font and leading as the message, so its
   lines sit on the message's grid and the line cuts in consent.js still land mid-line. */
.daylon-consent-banner__text a {
	display: inline-block;
	color: inherit;
	text-decoration: underline;
	margin-inline-start: 0.35em;
}

/* Aceptar todo, Rechazar and Personalizar are one tier, the same width at every width — the widest
   label sets all three (spec v45 §8b.3, P3; DAY-630, DAY-703). As flex items each took its own
   label's width plus an equal share of the free space, so at 320 they stood 79px and 97px. `1fr`
   tracks are equal by construction: where the row has a definite width they split it; where the
   actions shrink to fit beside the message, each track is sized to the widest label. On a phone
   the pair shares the first row and Personalizar takes the second (below, max-width 599px). */
.daylon-consent-banner {
	container-type: inline-size;
}

.daylon-consent-banner__actions {
	display: grid;
	grid-template-columns: repeat( 3, 1fr );
	gap: 0.5rem;
}

/* Wider than a phone, when the three do not fit beside the message they drop under it,
   right-aligned (spec §8b.4, 768); beside it, the message takes the free space and this does
   nothing. Not on a capped banner, whose column layout stretches the actions full width. */
@media (min-width: 600px) {
	.daylon-consent-banner:not( .is-capped ) .daylon-consent-banner__actions {
		margin-inline-start: auto;
	}
}

/* The message and node A travel together (DAY-622). Below 768px, and whenever the banner is
   capped, the wrapper is not a box at all: the message, the notice and the actions are the row's
   own children, so every rule written for the message before it existed still holds. */
.daylon-consent-banner__lead {
	display: contents;
}

/* When the server does not confirm a choice — header/footer spec §8b.10 (DAY-622). One quiet
   line in the banner's own ink and size, set off by the banner's hairline on its start edge —
   a shape, not a colour, so forced colours and greyscale see it too. Node A sits between the
   message and the actions, node B above «Guardar preferencias»; both are live regions in the
   page, empty, from the first paint, and an empty one takes no space and no gap. */
.daylon-consent-banner__notice {
	--daylon-consent-leading: 1.5;
	flex: 1 1 100%;
	margin: 0;
	padding-inline-start: 0.5rem;
	border-inline-start: 2px solid var( --wp--preset--color--border-light, #ecdfc4 );
	font-size: var( --wp--preset--font-size--small, 0.95rem );
	line-height: var( --daylon-consent-leading );
}

/* Out of the layout while empty, but rendered — a region that is `display: none` and then filled
   is as unreliably announced as one inserted already filled. The saved-choice status (spec §8b.7,
   §9.7c, DAY-628) is clipped the same way, always: heard, never seen — no toast, no fixed element. */
.daylon-consent-banner__notice:empty,
.daylon-consent-status {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip-path: inset( 50% );
	white-space: nowrap;
}

/* From 768px node A is under the message, in the message's own column and no wider than 60
   characters; the actions stay on the right exactly as they were. */
@media (min-width: 768px) {
	.daylon-consent-banner:not( .is-capped ) .daylon-consent-banner__lead {
		display: flex;
		flex: 1 1 20rem;
		flex-direction: column;
		gap: 0.5rem;
	}

	.daylon-consent-banner:not( .is-capped ) .daylon-consent-banner__lead > .daylon-consent-banner__text {
		flex: none;
	}

	.daylon-consent-banner__lead > .daylon-consent-banner__notice {
		flex: none;
		max-inline-size: 60ch;
	}
}

/* Every button is a 44px target, the studio's floor (spec §8b.6, F5): at 14.4px type the panel's
   «Guardar preferencias» and «Cerrar sin cambios» stood 40.9px (DAY-630). */
.daylon-consent-banner__button {
	appearance: none;
	cursor: pointer;
	min-height: 44px;
	padding: 0.6em 1.1em;
	font: inherit;
	font-size: var( --wp--preset--font-size--small, 0.95rem );
	border-radius: 2px;
	border: 1px solid var( --wp--preset--color--main, #221d17 );
	background: transparent;
	color: var( --wp--preset--color--main, #221d17 );
	/* The same reflow rule as the message (DAY-631): at 400 % on 320, «Personalizar» in Mona Sans
	   is 21px wider than its button and scrolled the banner sideways. It breaks only there. */
	overflow-wrap: anywhere;
}

.daylon-consent-banner__button--primary {
	background: var( --wp--preset--color--primary, #8a5a12 );
	border-color: var( --wp--preset--color--primary, #8a5a12 );
	color: var( --wp--preset--color--base, #f8f3e8 );
}

.daylon-consent-banner__button:focus-visible,
.daylon-consent-reopen:focus-visible {
	outline: 2px solid var( --wp--preset--color--primary, #8a5a12 );
	outline-offset: 2px;
}

.daylon-consent-banner__panel {
	max-width: 64rem;
	margin: 1rem auto 0;
	padding-top: 1rem;
	border-top: 1px solid var( --wp--preset--color--border-light, #ecdfc4 );
	display: grid;
	gap: 0.85rem;
}

/* `display: grid` above outranks the UA's `[hidden] { display: none }`, so the panel was
   never hidden: its three checkboxes and "Guardar preferencias" sat in the tab order, and
   the banner grew to ~420px at 1440×900, covering the focused control underneath (DAY-21,
   WCAG 2.4.11). */
.daylon-consent-banner__panel[hidden] {
	display: none;
}

.daylon-consent-banner__category label {
	display: flex;
	align-items: center;
	gap: 0.5em;
	font-weight: 600;
}

.daylon-consent-banner__category p {
	margin: 0.2em 0 0;
	font-size: var( --wp--preset--font-size--x-small, 0.9rem );
	color: var( --wp--preset--color--secondary, #706352 );
}

/* On a phone the first visit met a banner a quarter of the screen tall — 227px of 844 at 390
   (DAY-325, point 4). Tighter, and the actions take the row's full width: Aceptar todo and
   Rechazar 50/50 on the first row, then Personalizar alone on the second, full width, with the
   same style and height (spec v45 §8b.4, DAY-703). Still a 44px target each.

   With text at 200 % the three did not fit, and «Aceptar todo» sat at x=578 on a 320 screen
   (DAY-603, WCAG 1.4.10); the container query below stacks them instead. */
@media (max-width: 599px) {
	.daylon-consent-banner {
		padding: 0.75rem 1rem;
	}

	.daylon-consent-banner__row {
		gap: 0.625rem;
	}

	.daylon-consent-banner__text {
		--daylon-consent-leading: 1.4;
		flex-basis: 100%;
	}

	.daylon-consent-banner__notice {
		--daylon-consent-leading: 1.4;
	}

	.daylon-consent-banner__actions {
		flex: 1 1 100%;
		grid-template-columns: repeat( 2, 1fr );
	}

	.daylon-consent-banner__actions [data-daylon-consent-action="customize"] {
		grid-column: 1 / -1;
	}

	.daylon-consent-banner__actions .daylon-consent-banner__button {
		padding: 0.4em 0.5em;
		font-size: 0.8125rem;
	}
}

/* When even the pair cannot share one row — the reader's text is large, so the banner's content
   is narrower than 17.5 of her own rems (280px; at 320 and 100 % it is 288px) — the three stack one
   per row, full width, as the wrapping row used to leave them at 200 % on a phone (DAY-603): still
   the same width and height, in the DOM's order. A container query, because its rem follows her
   text size; a media query's does not. After the phone rule, so it wins over its two columns. */
@container (width < 17.5rem) {
	.daylon-consent-banner__actions {
		grid-template-columns: minmax( 0, 1fr );
	}
}

/* Tight viewports — header/footer spec v26 §8b.4a (DAY-607). When the collapsed banner would
   pass 45 % of the viewport height (text at 200 % on a phone, a short screen), consent.js adds
   `is-capped`: what yields is the message, never the actions and never the bar standing on the
   banner. The message scrolls inside its own region, at least two and a half lines tall so the
   last visible line is cut and reads as "there is more"; the actions keep their layout and
   their 44px targets, pinned at the bottom. `is-capped-wide` is rule 3: the actions and those
   lines do not fit in 45dvh, so the cap rises to 50dvh and no further. Below the cap the banner
   is exactly as before, so 100 % text on 320×568 never reaches this. The open panel is not
   capped (rule 8): consent.js only caps a collapsed banner. */
.daylon-consent-banner.is-capped {
	display: flex;
	flex-direction: column;
	max-height: 45vh;
	max-height: 45dvh;
}

.daylon-consent-banner.is-capped-wide {
	max-height: 50vh;
	max-height: 50dvh;
}

.daylon-consent-banner.is-capped .daylon-consent-banner__row {
	flex: 1 1 auto;
	flex-direction: column;
	flex-wrap: nowrap;
	align-items: stretch;
	min-height: 0;
	width: 100%;
}

.daylon-consent-banner.is-capped .daylon-consent-banner__text {
	flex: 0 1 auto;
	min-height: calc( 2.5em * var( --daylon-consent-leading ) );
	overflow-y: auto;
	overscroll-behavior: contain;
}

.daylon-consent-banner.is-capped .daylon-consent-banner__text:focus-visible {
	outline: 2px solid var( --wp--preset--color--primary, #8a5a12 );
	outline-offset: 2px;
}

.daylon-consent-banner.is-capped .daylon-consent-banner__actions,
.daylon-consent-banner.is-capped .daylon-consent-banner__notice {
	flex: none;
}

/* Rule 9 (header/footer spec v27, DAY-611): text at 400 %, where even 50dvh does not hold the
   actions and two lines of message (at 320×568 the actions alone were ~300px of a 284px cap).
   The cap stands and the pinning of rule 2 is suspended: the banner is one scroll region —
   message, Aceptar todo, Rechazar, Personalizar, the same DOM and tab order — and the page behind
   does not scroll through it (`overscroll-behavior: contain`, above). Tabbing to a control
   scrolls it whole into the banner with room around it at least a target tall. The actions are
   one column: «Aceptar todo» wraps to two lines at 400 % and stood 137px against Rechazar's 75px,
   and the two are the decision pair, the same height and width (§8b.3, P2–P3; §8b.4a R9-e) — so
   their two rows share one flexible size, the taller label's; Personalizar, same style, is as
   tall as its own label makes it (R9-e). consent.js lowers the banner if its edge would fall in
   a gap, so a line or a button is always cut. */
.daylon-consent-banner.is-capped-scroll {
	display: block;
	scroll-padding-block: 48px;
}

.daylon-consent-banner.is-capped-scroll .daylon-consent-banner__row {
	min-height: auto;
}

.daylon-consent-banner.is-capped-scroll .daylon-consent-banner__text {
	min-height: 0;
	overflow: visible;
}

.daylon-consent-banner.is-capped-scroll .daylon-consent-banner__actions {
	display: grid;
	grid-template-columns: minmax( 0, 1fr );
	/* Aceptar todo, Rechazar, Personalizar — the annex's order (§8b.2, v45). */
	grid-template-rows: 1fr 1fr auto;
}

/* On a phone, a capped banner's air stays at its 100 % size, in px, and only the words grow
   with the reader's text — the rule DAY-603 gave the product bar. With text at 200 % on 320×568
   the rem paddings and gaps doubled with it, and the three actions alone stood 217px tall, so
   «Aceptar todo» sat below the 50dvh cap; the labels' inherited body leading added 7px more to
   each. The font is never reduced (§8b.4a sets that aside).
   At 100 % each min() equals the value it caps, and a banner only gets here once capped. */
@media (max-width: 599px) {
	.daylon-consent-banner.is-capped {
		padding: min( 0.75rem, 12px ) min( 1rem, 16px );
	}

	.daylon-consent-banner.is-capped .daylon-consent-banner__row {
		gap: min( 0.625rem, 10px );
	}

	.daylon-consent-banner.is-capped .daylon-consent-banner__actions {
		gap: min( 0.5rem, 8px );
	}

	.daylon-consent-banner.is-capped .daylon-consent-banner__actions .daylon-consent-banner__button {
		padding: min( 0.4em, 5.2px ) min( 0.5em, 6.5px );
		line-height: 1.2;
	}
}

/* It stands on top of whichever bar is fixed to the bottom (`--daylon-bottom-bar`, published by
   the theme's cart-checkout.js and product.js while one shows). At a bare `1rem` it sat over
   the cart's "Finalizar compra", the checkout's "Realizar el pedido" and the product buy bar at
   320px, and a tap on the left of the button opened the cookie preferences (DAY-21, 2.4.11).
   A 44px target like the banner's buttons: its padding alone stood it 35px (DAY-654). The UA
   centres a button's label in the extra height, and the offset and keep-clear rules in
   consent.js read its live box, so they follow. */
.daylon-consent-reopen {
	position: fixed;
	inset-block-end: calc(1rem + var(--daylon-bottom-bar, 0px));
	inset-inline-start: 1rem;
	z-index: 99999;
	appearance: none;
	cursor: pointer;
	min-height: 44px;
	padding: 0.5em 0.9em;
	font-size: var( --wp--preset--font-size--x-small, 0.9rem );
	border-radius: 2px;
	border: 1px solid var( --wp--preset--color--border-light, #ecdfc4 );
	background: var( --wp--preset--color--base, #f8f3e8 );
	color: var( --wp--preset--color--main, #221d17 );
}

/* Out of the way while the page's own purchase button, in flow, crosses its band — see
   keepReopenClear() in consent.js. `visibility` rather than `hidden`, which is the pill's
   "no choice made yet" state and belongs to showReopen()/hideReopen(). */
.daylon-consent-reopen.is-yielding {
	visibility: hidden;
}
