/* ==========================================================================
   Predictive search: header layout, dropdown and results-page extras.

   Loaded AFTER td-utility-style.css (see inc/theme-setup.php), so where a
   rule here has the same weight as one there, this file wins. It uses the
   main stylesheet's colour and font variables (--tdup-red, --tdup-charcoal
   ...) and never hard-codes a brand colour, so when the brand colours
   change in :root this follows.

   Contents
   1. Header: search always visible (own row below 1024px, sticky header)
   2. The search box itself (focus ring, button)
   3. The dropdown
   4. Matching sizes on a results card, and the no-results help
   ========================================================================== */

/* ==========================================================================
   1. Header layout
   ========================================================================== */

/* Sticky, and below the notch on phones. (The main stylesheet already makes
   the header sticky; this keeps the notch gap and a stacking order above the
   dropdown's page content.) */
.tdup-header {
	position: sticky;
	top: env(safe-area-inset-top, 0px);
	z-index: 50;
}

/* Desktop (nav showing): the field is at least 280px wide so a code or a size
   fits, and grows a little when there's room. margin-left:auto pushes search
   and the Quote link to the right edge. The main stylesheet clipped the box
   (overflow:hidden), which would also clip the dropdown, so that's undone. */
.tdup-header__search {
	position: relative;
	overflow: visible;
	flex: 1 1 280px;
	min-width: 280px;
	max-width: 420px;
	margin-left: auto;
	background: var(--tdup-white);
	border: 0;
}

/* Tighter header spacing between 1025px and 1599px. At the main stylesheet's
   spacing the logo, the six-item menu (set in wide Archivo), a 280px search
   box and the Quote link need about 1570px. Tightening the gaps and the
   letter-spacing brings the single-row header down to ~1390px, so a 1440px
   screen (about 1423px once a scrollbar takes its share) still fits on one
   row. From 1600px up the main stylesheet's roomier spacing is used as it was. */
@media (min-width: 1025px) and (max-width: 1599px) {
	.tdup-header__inner { gap: 16px; padding: 0 20px; }
	.tdup-header__logo { padding-right: 16px; }
	.tdup-primary-nav ul { gap: 12px; }
	.tdup-primary-nav a { letter-spacing: 0.06em; }
	.tdup-header__quote-link { padding: 9px 10px; letter-spacing: 0.1em; }
}

/* Between 1025px and 1409px the menu and a 280px search box cannot share one
   row. The menu stays visible (it is never hidden); search moves to its own
   row under it, the same way it does on a phone, so nothing overlaps and the
   page never scrolls sideways. It is capped at 640px wide, which is plenty for
   a code or a size, and sits at the right under the Quote link. */
@media (min-width: 1025px) and (max-width: 1409px) {
	.tdup-header__inner { flex-wrap: wrap; row-gap: 10px; }
	.tdup-header .tdup-header__search { order: 4; flex: 0 0 100%; max-width: 640px; }
}

/* Under 1025px the main stylesheet collapses nav, search and Quote into the
   menu. Search must never hide, so the header becomes two rows:
     row 1: logo ........ Quote  [menu button]
     row 2: [ search, full width ]
   and the nav (when the menu button is opened) drops in below row 2.
   `order` rearranges the flex items without changing the HTML. */
@media (max-width: 1024px) {
	.tdup-header__inner {
		flex-wrap: wrap;
		row-gap: 10px;
		column-gap: 8px;
		padding: 0 16px;
		align-items: center;
	}
	.tdup-header .tdup-header__logo { order: 1; border-right: 0; padding-right: 0; margin-right: auto; }
	.tdup-header .tdup-header__logo .tdup-logo-image,
	.tdup-header .tdup-header__logo .tdup-wordmark { height: 34px; }
	/* The Quote link now stays in row 1 at every width (it used to live in the
	   collapsed menu). Compact: the word "Quote" and the count. */
	.tdup-header .tdup-header__quote-link {
		order: 2;
		display: inline-flex;
		width: auto;
		min-height: 44px;
		margin: 0;
		padding: 0 14px;
		border: 1px solid rgba(255, 255, 255, 0.16);
		justify-content: center;
	}
	.tdup-header .tdup-header__menu-toggle { order: 3; margin-left: 0; min-width: 44px; min-height: 44px; }
	.tdup-header .tdup-header__search {
		order: 4;
		display: flex;
		flex: 0 0 100%;
		width: 100%;
		min-width: 0;
		max-width: none;
		margin: 0;
	}
	.tdup-header .tdup-primary-nav { order: 5; }
}

/* ==========================================================================
   2. The search box
   ========================================================================== */
.tdup-header__search input[type="search"] {
	flex: 1;
	min-width: 0;
	min-height: 44px;                    /* a 44px touch target */
	padding: 0 14px;
	border: 0;
	background: transparent;
	font-size: 15px;
	color: var(--tdup-charcoal);
	-webkit-appearance: none;
	appearance: none;
	border-radius: 0;
}
.tdup-header__search input::placeholder { color: var(--tdup-grey-3); opacity: 1; }
.tdup-header__search button {
	flex: none;
	width: 48px;
	height: 44px;
	background: var(--tdup-red);
	color: var(--tdup-white);
}
/* Hover darkens the red button but keeps the white icon: the icon never takes
   a colour that matches the button behind it. */
.tdup-header__search button:hover { background: var(--tdup-red-dark); color: var(--tdup-white); }

/* Focus: a white outline with a dark ring outside it. The header is dark, so
   white is what shows against it; the dark ring keeps the outline visible even
   when the header sits over a light page. Never a red ring: red disappears
   against the red button and the dark header. */
.tdup-header__search { outline: 3px solid transparent; outline-offset: 2px; transition: none; }
.tdup-header__search:focus-within {
	outline-color: var(--tdup-white);
	box-shadow: 0 0 0 8px var(--tdup-charcoal-deep);
}
.tdup-header__search input:focus,
.tdup-header__search input:focus-visible { outline: none; box-shadow: none; }
.tdup-header__search button:focus-visible { outline: 3px solid var(--tdup-white); outline-offset: -6px; box-shadow: none; }
/* Hide the browser's own clear (x) so it doesn't sit beside the red button. */
.tdup-header__search input[type="search"]::-webkit-search-cancel-button,
.tdup-header__search input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

/* The quote count gives a short nudge when a code is added from the dropdown. */
@keyframes ts-bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.tdup-quote-count.ts-bump { animation: ts-bump 0.5s; }
@media (prefers-reduced-motion: reduce) { .tdup-quote-count.ts-bump { animation: none; } }

/* ==========================================================================
   3. The dropdown
   White panel with a red top edge. Rows are at least 48px tall for touch.
   The active row is marked with a red bar AND a grey fill (not colour alone).
   ========================================================================== */
.ts-drop {
	position: absolute;
	top: calc(100% + 8px);
	right: 0;
	width: min(640px, calc(100vw - 32px));
	max-height: calc(100vh - 150px);
	max-height: calc(100dvh - 150px);
	overflow-y: auto;
	padding: 6px 0 0;
	background: var(--tdup-white);
	color: var(--tdup-charcoal);
	border-top: 4px solid var(--tdup-red);
	box-shadow: 0 22px 48px rgba(0, 0, 0, 0.38);
	text-align: left;
	z-index: 60;
}
.ts-drop[hidden] { display: none; }
.ts-h {
	margin: 0;
	padding: 10px 16px 4px;
	font-family: var(--tdup-font-title);
	font-stretch: 118%;
	font-weight: 700;
	font-size: 11px;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--tdup-grey-3);
}
.ts-opt {
	display: flex;
	align-items: center;
	gap: 12px;
	min-height: 48px;
	padding: 6px 16px;
	cursor: pointer;
	font-family: var(--tdup-font-body);
}
.ts-opt.is-hover { background: var(--tdup-off-white); }
.ts-opt[aria-selected="true"] { background: var(--tdup-surface); box-shadow: inset 4px 0 0 var(--tdup-red); }
.ts-txt { flex: 1; min-width: 0; font-size: 15px; line-height: 1.3; }
.ts-txt b { font-weight: 700; }
.ts-txt .ts-typed { font-weight: 400; }
.ts-txt small { display: block; margin-top: 1px; font-size: 13px; color: var(--tdup-body-grey); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ts-in { color: var(--tdup-grey-3); }
.ts-ph { flex: none; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 40%, var(--tdup-white), var(--tdup-surface)); }
.ts-ph img { max-width: 40px; max-height: 40px; object-fit: contain; }
.ts-cls { flex: none; padding: 3px 7px; background: var(--tdup-charcoal); color: var(--tdup-white); font-family: var(--tdup-font-title); font-stretch: 110%; font-weight: 800; font-size: 12px; }
.ts-ico { flex: none; width: 44px; height: 28px; display: flex; align-items: center; justify-content: center; color: var(--tdup-body-grey); font-size: 16px; }
.ts-ico--add { height: 44px; background: var(--tdup-red); color: var(--tdup-white); font-size: 22px; font-weight: 700; }
.ts-ico--cls { background: var(--tdup-charcoal); color: var(--tdup-white); font: 800 11px var(--tdup-font-title); }
.ts-ico--pdf { border: 2px solid var(--tdup-charcoal); color: var(--tdup-charcoal); font: 800 10px var(--tdup-font-title); }
.ts-n { flex: none; font-size: 13px; color: var(--tdup-grey-3); }
.ts-opt--all { justify-content: space-between; min-height: 52px; margin-top: 6px; border-top: 1px solid var(--tdup-rule); color: var(--tdup-red); }
.ts-fix, .ts-tip { margin: 0; padding: 10px 16px; font-size: 14px; color: var(--tdup-body-grey); background: var(--tdup-off-white); border-bottom: 1px solid var(--tdup-rule); }
.ts-tip { margin-top: 6px; border-top: 1px solid var(--tdup-rule); border-bottom: 0; }
.ts-fix b, .ts-tip b { color: var(--tdup-charcoal); }
/* Visually hidden message area for screen readers */
.ts-live { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* On a phone the dropdown spans the search row's full width, and may scroll
   inside itself (the on-screen keyboard leaves little height). */
@media (max-width: 700px) {
	.ts-drop { left: 0; right: 0; width: auto; max-height: calc(100vh - 140px); max-height: calc(100dvh - 140px); }
	.ts-txt { font-size: 14px; }
}

/* ==========================================================================
   4. Results page extras
   ========================================================================== */

/* The order codes / sizes that matched, under a product card's title. */
.tdup-search-match { padding: 8px 12px 10px; border-top: 1px solid var(--tdup-rule); background: var(--tdup-off-white); font-size: 13px; }
.tdup-search-match__title { margin: 0 0 4px; font-family: var(--tdup-font-title); font-weight: 700; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--tdup-body-grey); }
.tdup-search-match ul { list-style: none; margin: 0; padding: 0; }
.tdup-search-match li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.tdup-search-match li span { min-width: 0; overflow-wrap: anywhere; color: var(--tdup-charcoal); }
.tdup-search-match code { flex: none; font: 700 12px var(--tdup-font-body); color: var(--tdup-body-grey); }
.tdup-search-match__more { margin: 4px 0 0; }
.tdup-search-match__more a { color: var(--tdup-charcoal); text-decoration: underline; text-underline-offset: 2px; }
.tdup-search-match__more a:hover { color: var(--tdup-red); }

/* "Showing results for ..." and other one-line notices above the results */
.tdup-search-notice { grid-column: 1 / -1; margin: 0 0 16px; padding: 12px 14px; background: var(--tdup-off-white); border-left: 4px solid var(--tdup-red); font-size: 15px; color: var(--tdup-charcoal); }
.tdup-search-count { grid-column: 1 / -1; margin: 0; font-size: 15px; color: var(--tdup-body-grey); }

/* No results: tips and where to go next */
.tdup-search-empty { grid-column: 1 / -1; padding: 24px; background: var(--tdup-off-white); border: 1px solid var(--tdup-rule); }
.tdup-search-empty h2 { margin: 0 0 8px; font-size: 20px; }
.tdup-search-empty p { margin: 0 0 12px; max-width: 60ch; }
.tdup-search-empty ul { margin: 0 0 16px; padding-left: 20px; }
.tdup-search-empty li { margin-bottom: 4px; }
.tdup-search-empty__actions { display: flex; flex-wrap: wrap; gap: 12px; }
