/*
Theme Name:   Kuraas Julegave
Description:  Child theme of Twenty Twenty-Five for julegave.kuraas.no. Colours and fonts live in theme.json; this file only styles markup that blocks can't (WooCommerce classic forms and the Smart Bundle table).
Author:       Riktig Spor
Template:     twentytwentyfive
Version:      1.0.10
Requires at least: 6.7
Requires PHP: 8.1
Text Domain:  kuraas-julegave
*/

/* ---------- Focus (WCAG 2.4.7 / 2.4.13) ---------- */
:where(.wp-site-blocks) :focus-visible {
	outline: 3px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}
:where(.has-primary-background-color, .has-black-background-color, .wp-block-cover) :focus-visible {
	outline-color: var(--wp--preset--color--base);
}

/* ---------- 50/50: "Bygg din egen" stays in view beside the ready-made boxes ---------- */
.kuraas-split__sticky > .wp-block-cover {
	position: sticky;
	top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--wp--preset--spacing--40));
}

/* ---------- Classic Woo forms (cart/checkout shortcodes) ---------- */
.woocommerce :is(input[type="text"], input[type="email"], input[type="tel"], input[type="number"], input[type="date"], input[type="search"], textarea, select, .input-text) {
	background: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--border); /* #767676 = 4.5:1, passes 1.4.11 */
	border-radius: 0.25rem;
	padding: 0.6rem 0.75rem;
	font: inherit;
	min-height: 44px;
}

/* Woo's block-theme CSS caps the cart and its title at 1000px, left-aligned in
   the wide container. Let them fill the container (wideSize, 1340px). */
.woocommerce-cart :is(.wp-block-post-title, main .woocommerce) { max-width: var(--wp--style--global--wide-size); }

/* Never split a price across lines ("kr 2 / 616"); the thousands separator is a plain space */
.woocommerce-Price-amount { white-space: nowrap; }

/* ---------- Smart Bundle: "Bygg din egen eske" ---------- */
.wcbp_product_addons table { width: 100%; border-collapse: collapse; }
.wcbp_product_addons :is(td, th) { padding: 0.625rem; text-align: left; vertical-align: top; }
.wcbp_product_addons tr :is(td, th):last-child { text-align: right; }
.wcbp_product_addons h3 { margin-block: var(--wp--preset--spacing--40) 0; }

.wcbp_product_addons .wcbp_prod_addon {
	display: grid;
	grid-template-columns: 80px 1fr auto;
	gap: 0.75rem;
	align-items: center;
}
.wcbp_product_addons .wcbp_prod_addon figure { margin: 0; }
.wcbp_product_addons .wcbp_prod_addon figure img {
	width: 80px;
	height: 80px;
	object-fit: cover;
	border-radius: 0.25rem;
}
.wcbp_product_addons .wcbp-title a { color: var(--wp--preset--color--contrast); text-decoration: none; }
.wcbp_product_addons .wcbp-title a:hover { text-decoration: underline; }

/*
 * Plugin ≥1.5.4 prints the checkbox inside <figure> next to the image. Unwrap
 * the figure so image, name and checkbox are each their own grid cell, whether
 * or not the checkbox sits in the figure.
 */
.wcbp_product_addons.table .wcbp_prod_addon { grid-template-areas: "img title check"; }
.wcbp_product_addons.table .wcbp_prod_addon figure { display: contents; }
.wcbp_product_addons.table .wcbp_prod_addon img { grid-area: img; }
.wcbp_product_addons.table .wcbp_prod_addon .details { grid-area: title; }
.wcbp_product_addons.table .wcbp_prod_addon .wcbp_show { grid-area: check; }

/*
 * Real checkbox stays in the a11y tree and tab order; the label draws the box.
 * The plugin's `figure …` rules absolutely position the box over the image,
 * collapse the label to 0×0 and set the input to display:none. The table's
 * ID (#wcbp_single_prod_qty) outranks them; the resets below undo the rest.
 */
#wcbp_single_prod_qty .wcbp_show { position: relative; }
#wcbp_single_prod_qty .wcbp_show input[type="checkbox"] {
	display: block;
	position: absolute;
	width: 1px;
	height: 1px;
	margin: 0;
	opacity: 0;
}
/* The label is the 44px target (2.5.5 AAA); the box drawn inside it is smaller */
#wcbp_single_prod_qty .wcbp_cbx {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	min-width: 2.75rem;
	min-height: 2.75rem;
	margin: 0;
	cursor: pointer;
	user-select: none;
}
#wcbp_single_prod_qty .wcbp_cbx > span {
	position: static;
	display: grid;
	flex: none;
	place-items: center;
	box-sizing: border-box;
	width: 1.75rem;
	height: 1.75rem;
	margin: 0;
	padding: 0;
	border: 2px solid var(--wp--preset--color--contrast);
	border-radius: 0.25rem;
	transform: none;
	animation: none;
	transition: background-color 0.2s, border-color 0.2s;
}
#wcbp_single_prod_qty .wcbp_cbx > span::before { content: none; } /* plugin's blue ripple */
#wcbp_single_prod_qty .wcbp_cbx svg {
	position: static;
	width: 1rem;
	height: 1rem;
	fill: none;
	stroke: var(--wp--preset--color--base);
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-dasharray: 16px;
	stroke-dashoffset: 16px;
	transition: stroke-dashoffset 0.3s 0.1s;
}
#wcbp_single_prod_qty .wcbp_cbx:hover > span { border-color: var(--wp--preset--color--primary); }
#wcbp_single_prod_qty input:checked + .wcbp_cbx > span {
	background: var(--wp--preset--color--primary);
	border-color: var(--wp--preset--color--primary);
}
#wcbp_single_prod_qty input:checked + .wcbp_cbx svg { stroke-dashoffset: 0; }
#wcbp_single_prod_qty input:focus-visible + .wcbp_cbx > span {
	outline: 3px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}

/*
 * Column heading over the checkboxes. The plugin only prints "Produkt" and
 * "Antall i esken", and the checkbox has to stay in the product cell for the
 * plugin's JS, so the heading is drawn here, centred over the 44px label.
 * `/ ""` hides it from screen readers; each checkbox already announces
 * "Legg i esken: <produkt>".
 */
#wcbp_single_prod_qty th:first-child { position: relative; }
#wcbp_single_prod_qty th:first-child::after {
	content: "Legg i esken";
	content: "Legg i esken" / "";
	position: absolute;
	right: calc(0.625rem + 1.375rem); /* cell padding + half the label */
	transform: translateX(50%);
	white-space: nowrap;
}

/* Quantity looks inactive until the product is ticked (replaces old custom.js) */
/* 0.62 keeps the number at ≥4.5:1 so it stays readable before ticking */
.wcbp_product_addons .quantity .qty { box-sizing: border-box; width: 5rem; opacity: 0.62; transition: opacity 0.3s; }
.wcbp_product_addons tr:has(.wcbp_show input:checked) .quantity .qty { opacity: 1; }

/* Reflow at 320px (WCAG 1.4.10) */
.wcbp_product_addons .details { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) {
	.wcbp_product_addons :is(td, th) { padding: 0.375rem 0.25rem; }
	.wcbp_product_addons .wcbp_prod_addon { grid-template-columns: 48px 1fr auto; gap: 0.5rem; }
	.wcbp_product_addons .wcbp_prod_addon figure img { width: 48px; height: 48px; }
	.wcbp_product_addons .quantity .qty { width: 3.5rem; }
}

/* Build-your-own table on phones: image + name, checkbox under the name, quantity right */
@media (max-width: 600px) {
	.wcbp_product_addons.table :is(table, tbody) { display: block; }
	.wcbp_product_addons.table tr:has(th) { display: none; } /* "Produkt / Antall" header; qty inputs have their own labels */
	.wcbp_product_addons.table tr.wcbp_loop {
		display: grid;
		grid-template-columns: 1fr auto;
		align-items: center;
		gap: 0.5rem;
		padding-block: 0.5rem;
		border-bottom: 1px solid var(--wp--preset--color--surface);
	}
	.wcbp_product_addons.table tr.wcbp_loop td { display: block; width: auto; padding: 0; }
	/* Plugin: `float: right !important` + td width 30% push the input over the name */
	.wcbp_product_addons.table tr.wcbp_loop td .quantity { float: none !important; margin: 0; }
	.wcbp_product_addons.table .wcbp_prod_addon {
		grid-template-columns: 56px 1fr;
		grid-template-areas: "img title" "img check";
		row-gap: 0.25rem;
	}
	.wcbp_product_addons.table .wcbp_prod_addon img { align-self: start; }
	.wcbp_product_addons.table .wcbp_prod_addon figure img { width: 56px; height: 56px; }
	.wcbp_product_addons.table .wcbp_prod_addon .details { overflow-wrap: normal; }
	.wcbp_product_addons.table .wcbp_prod_addon .wcbp_show { justify-self: start; }
	/* No header row here, so the label carries the text (and the text is clickable) */
	#wcbp_single_prod_qty .wcbp_cbx::after { content: "Legg i esken"; content: "Legg i esken" / ""; }
}

/* Fixed boxes (plugin "grid" view): one product per row, image left, name right */
.wcbp_product_addons.grid .wcbp_row {
	display: grid;
	gap: 0.375rem;
	margin: var(--wp--preset--spacing--30) 0 0;
}
.wcbp_product_addons.grid .wcbp_row > [class*="wcbp_col_"] {
	flex: none;
	max-width: none;
	padding: 0;
}
.wcbp_product_addons.grid .wcbp_prod_addon {
	grid-template-columns: 4.5rem 1fr;
	gap: 0.875rem;
	margin: 0;
	padding: 0.375rem 0.75rem 0.375rem 0.375rem;
	border: 0;
	border-radius: 0.375rem;
	background: var(--wp--preset--color--surface);
}
.wcbp_product_addons.grid .wcbp_prod_addon figure { position: relative; }
.wcbp_product_addons.grid .wcbp_prod_addon figure img {
	display: block;
	width: 4.5rem !important; /* plugin forces 100%/auto with !important */
	height: 3.25rem !important;
	object-fit: cover;
	border-radius: 0.25rem;
}
.wcbp_product_addons.grid .wcbp_prod_addon .details { padding: 0; text-align: left; }
.wcbp_product_addons.grid .wcbp_prod_addon span.wcbp-title {
	font-size: var(--wp--preset--font-size--medium);
	font-weight: 500;
	line-height: 1.35;
	color: var(--wp--preset--color--contrast);
}
.wcbp_product_addons.grid .wcbp-title br { display: none; }

/* Fixed boxes have no per-product quantity; only "Bygg din egen eske" does */
.single-product:not(.postid-484) form.cart .wcbp_qty_box { display: none !important; }

@media (prefers-reduced-motion: reduce) {
	#wcbp_single_prod_qty .wcbp_cbx > span,
	#wcbp_single_prod_qty .wcbp_cbx svg,
	.wcbp_product_addons .quantity .qty { transition: none; }
}
