/*
 * The date field of every booking bar and the enquiry form — Task 005-4.
 * Reasoning: includes/booking/date-field.php. Loaded only where a bar or
 * the enquiry form draws its fields.
 *
 * Section 1 — today's browser field, fixed (always on, also with the
 *             switch off).
 * Section 2 — the typed-or-picked field (only where the script has built
 *             it: everything is keyed off `.vm-date`, which exists only then).
 */

/* ==================================================================
   1. The browser's own field
   ================================================================== */

/* Never wider than its column. A grid or flex item's default minimum is
   its content's width; for a date field on an iPhone that is the
   browser's own minimum, which is what pushed Departure out of the white
   card on Villa Filaus (Ana's iPhone, 17.11.). */
.vma-stay__input[type="date"],
.vm-offer-stay__input[type="date"],
.vme__control[type="date"] {
	max-width: 100%;
	min-width: 0;
}

/* iPhone and iPad only (`-webkit-touch-callout` exists nowhere else), so
   a computer's browser is untouched. Without its native look the field
   takes the width it is given; an empty field keeps its height (Safari
   otherwise collapses the empty value to nothing); the date sits on the
   left like every other field; and an empty field shows the hint. */
@supports ( -webkit-touch-callout: none ) {
	.vma-stay__input[type="date"],
	.vm-offer-stay__input[type="date"],
	.vme__control[type="date"] {
		-webkit-appearance: none;
		appearance: none;
		display: block;
	}

	.vma-stay__input[type="date"]::-webkit-date-and-time-value,
	.vm-offer-stay__input[type="date"]::-webkit-date-and-time-value,
	.vme__control[type="date"]::-webkit-date-and-time-value {
		margin: 0;
		min-height: 1.3em;
		text-align: left;
	}

	/* `:invalid` = empty, because the bars' fields are `required`; `[value=""]`
	   = the page drew it empty. Picking a date makes it valid and the hint
	   goes. The enquiry form's dates are optional, so they never match and
	   show no hint here — section 2 gives them one. */
	.vma-stay__input[type="date"][data-vm-date-hint][value=""]:not(:focus):invalid::before,
	.vm-offer-stay__input[type="date"][data-vm-date-hint][value=""]:not(:focus):invalid::before {
		color: var( --wp--preset--color--muted );
		content: attr( data-vm-date-hint );
	}
}

/* ==================================================================
   2. The typed-or-picked field (assets/js/date-field.js)

   The text field keeps the bar's own class (`vma-stay__input`,
   `vm-offer-stay__input`, `vme__control`), so it looks exactly like the
   field it replaces; only what is new is drawn here. Tokens only; the
   plain numbers are sizes (the button, a day cell, the calendar's
   width, the 2px corners the bars already use).
   ================================================================== */

.vm-date {
	display: block;
	min-width: 0;
	position: relative;
}

/* In the house card the field is a grid of label / box / message (subgrid,
   house-booking-row.css): the box's row is now this wrapper's. */
.vma-stay__field > .vm-date {
	grid-column: 1;
	grid-row: 2;
}

/* The house card's boxes were 44px — the touch height its button is
   matched to (house-booking-row.css); a text field is 2px shorter than
   the browser's date field, so the card asks for it. */
.vm-property-facts__book .vma-stay__field > .vm-date > input.vm-date__input {
	min-height: 2.75rem;
}

/* Room for the calendar button inside the box. */
.vm-date > input.vm-date__input {
	padding-inline-end: 2.75rem;
	text-overflow: ellipsis;
}

.vm-date > input.vm-date__input::placeholder {
	color: var( --wp--preset--color--muted );
	opacity: 1;
}

/* iPhone: Safari zooms the whole page into any field under 16px when it
   is focused. The bars' boxes are 14px; on an iPhone only, 16px. */
@supports ( -webkit-touch-callout: none ) {
	.vm-date > input.vm-date__input {
		font-size: max( 1rem, 16px );
	}
}

/* The house card drew its own calendar icon over the browser's picker
   (house-booking-row.css). The button below replaces it — one icon. */
.vm-property-facts__book .vma-stay__field.has-vm-date::after {
	content: none;
	display: none;
}

.vm-date__open {
	align-items: center;
	background: none;
	border: 0;
	border-radius: 2px;
	color: var( --vm-color-primary, var( --wp--preset--color--accent ) );
	cursor: pointer;
	display: flex;
	inset-block: 0;
	inset-inline-end: 0;
	justify-content: center;
	margin: 0;
	padding: 0;
	position: absolute;
	width: 2.75rem;
}

.vm-date__open:hover {
	color: var( --vm-color-deep, var( --wp--preset--color--contrast ) );
}

.vm-date__open:focus-visible,
.vm-date__pop button:focus-visible {
	outline: 2px solid var( --vm-color-deep, var( --wp--preset--color--accent ) );
	outline-offset: 1px;
}

.vm-date__error[hidden] {
	display: none;
}

/* -- The calendar ------------------------------------------------------- */

.vm-date__pop {
	background: var( --wp--preset--color--white );
	border: 1px solid var( --wp--preset--color--border );
	border-radius: 4px;
	box-shadow: 0 var( --wp--preset--spacing--10 ) var( --wp--preset--spacing--30 ) color-mix( in srgb, var( --wp--preset--color--contrast ) 16%, transparent );
	box-sizing: border-box;
	color: var( --wp--preset--color--contrast );
	font-family: var( --wp--preset--font-family--body );
	font-size: var( --wp--preset--font-size--small );
	left: 0;
	max-width: calc( 100vw - 1rem );
	padding: calc( var( --wp--preset--spacing--10 ) * 1.25 );
	position: absolute;
	text-align: left;
	text-transform: none;
	letter-spacing: normal;
	top: calc( 100% + 0.375rem );
	width: 19rem;
	z-index: 60;
}

.vm-date__pop[hidden] {
	display: none;
}

.vm-date__head {
	align-items: center;
	display: flex;
	justify-content: space-between;
	margin-bottom: calc( var( --wp--preset--spacing--10 ) * 0.5 );
}

.vm-date__month {
	font-weight: 600;
	margin: 0;
	text-align: center;
}

.vm-date__pop button {
	font: inherit;
	letter-spacing: normal;
	text-transform: none;
}

.vm-date__nav {
	align-items: center;
	background: none;
	border: 0;
	border-radius: 2px;
	color: var( --wp--preset--color--contrast );
	cursor: pointer;
	display: flex;
	height: 2.5rem;
	justify-content: center;
	padding: 0;
	width: 2.5rem;
}

.vm-date__nav:hover:not( :disabled ) {
	background: var( --wp--preset--color--surface );
}

.vm-date__nav:disabled {
	cursor: default;
	opacity: 0.3;
}

.vm-date__grid {
	border: 0;
	border-collapse: collapse;
	margin: 0;
	table-layout: fixed;
	width: 100%;
}

.vm-date__grid th,
.vm-date__grid td {
	border: 0;
	padding: 1px;
	text-align: center;
}

.vm-date__grid th {
	color: var( --wp--preset--color--muted );
	font-size: 0.75rem;
	font-weight: 400;
	padding-block: 0.25rem;
}

.vm-date__day {
	background: none;
	border: 0;
	border-radius: 2px;
	color: var( --wp--preset--color--contrast );
	cursor: pointer;
	display: block;
	height: 2.5rem;
	line-height: 2.5rem;
	margin: 0;
	padding: 0;
	width: 100%;
}

.vm-date__day:hover:not( [aria-disabled="true"] ) {
	background: var( --wp--preset--color--surface );
}

.vm-date__day.is-today {
	box-shadow: inset 0 0 0 1px var( --wp--preset--color--muted );
}

.vm-date__day[aria-pressed="true"],
.vm-date__day[aria-pressed="true"]:hover {
	background: var( --vm-color-deep, var( --wp--preset--color--primary ) );
	color: var( --vm-color-on-accent, var( --wp--preset--color--white ) );
}

.vm-date__day[aria-disabled="true"] {
	color: var( --wp--preset--color--muted );
	cursor: default;
	opacity: 0.45;
	text-decoration: line-through;
	text-decoration-thickness: 1px;
}

.vm-date__foot {
	border-top: 1px solid var( --wp--preset--color--border );
	margin: calc( var( --wp--preset--spacing--10 ) * 0.75 ) 0 0;
	padding-top: calc( var( --wp--preset--spacing--10 ) * 0.75 );
	text-align: center;
}

.vm-date__foot[hidden] {
	display: none;
}

.vm-date__type {
	background: none;
	border: 0;
	color: var( --vm-color-deep, var( --wp--preset--color--contrast ) );
	cursor: pointer;
	min-height: 2.75rem;
	padding: 0 var( --wp--preset--spacing--10 );
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

/* ==================================================================
   3. The homepage search (19.11.) — what changes now that Guests is left
   out at render (includes/booking/availability-handoff.php), and where
   its messages go. Its look is the block's own stylesheet.
   ================================================================== */

/* Departure is now the last field before the button: it takes the place
   Guests had — no hairline after it, the button's gap instead. */
.vmas__row > .vmas__field--departure:nth-last-child( 2 ) {
	border-right: 0;
	margin-right: var( --vmas-submit-gap );
	padding-right: 0;
}

.vmas__error {
	color: var( --wp--preset--color--contrast );
	font-family: var( --wp--preset--font-family--body );
	font-size: 0.8rem;
	letter-spacing: normal;
	line-height: 1.4;
	margin: 0;
	text-transform: none;
}

.vmas__error[hidden] {
	display: none;
}

/* The bar hangs across the hero with a `transform`, which makes it its own
   layer; the next section, later in the page, is painted over that layer —
   and over an open calendar (seen 19.11.: "Each property…" through the
   days). While a calendar is open the bar is lifted above the page. */
.vmas:has( .vm-date.is-open ) {
	z-index: 60;
}

/* The no-JavaScript reason, under the whole bar. */
.vmas__error--form {
	margin-top: calc( var( --wp--preset--spacing--10 ) * 0.75 );
}

@media ( max-width: 599px ) {
	.vmas__row > .vmas__field--departure:nth-last-child( 2 ) {
		border-bottom: 0;
		margin-right: 0;
	}
}
