/**
 * Center Hours calendar view.
 *
 * Layout responds to the CONTAINER width, not the viewport. A calendar dropped into
 * an Elementor column can be 747px wide on a 1440px screen; keying off the viewport
 * put two months in that space and gave each day a 50px cell, which overflowed the
 * hours text across cell boundaries.
 *
 *   < 640px    condensed: colored date + dot, hours via tap tooltip
 *   >= 640px   full cells (>= ~90px per day, enough for "10am - 6pm")
 *   >= 1300px  two months side by side
 *
 * The width is measured in JS, which sets data-chm-size on the wrapper. CSS container
 * queries are NOT usable here: `container-type: inline-size` applies inline-size
 * containment, and page builders commonly place the widget in a content-sized flex
 * item. The container then reports zero content width, the flex item collapses to 0,
 * and the calendar disappears entirely. Measured on a real Elementor page.
 *
 * Every mode-dependent property is declared exactly once and driven by a custom
 * property, so a mode is just a handful of variables on the wrapper.
 *
 * Defaults are the full-cell layout, which needs no JS -- if the script never runs,
 * the hours are still printed in every cell. A viewport media query pre-selects the
 * condensed mode on phones so there is no flash before JS measures.
 *
 * Cell colors arrive as the inline custom properties --chm-cell / --chm-cell-ink,
 * written by PHP from the admin color rules.
 *
 * Many declarations are !important on purpose. This markup renders inside arbitrary
 * themes, and themes style bare `button`, `td` and `ul` aggressively -- one shipped a
 * pink 1px border on every button and a gray tint on every table cell.
 */

.chm-cal {
	/* Full-cell mode: the no-JS-safe default. */
	--chm-body-display: block;
	--chm-dot-display: none;
	--chm-tip-display: none;
	--chm-num-align: left;
	--chm-caption-size: 1.3rem;
	--chm-btn-cursor: default;
	--chm-legend-dir: row;
	--chm-months-cols: 1fr;

	--chm-pad: #E0D8CD;
	--chm-panel: #F4EEE5;
	--chm-ink: #5B5452;
	--chm-heading: #111111;
	--chm-gap: #FFFFFF;
	--chm-radius: 3px;

	box-sizing: border-box;
	margin: 0 0 1.5rem;
	color: var(--chm-ink);
	font-size: 16px;
	line-height: 1.4;
	text-align: left;
}

.chm-cal *,
.chm-cal *::before,
.chm-cal *::after {
	box-sizing: border-box;
}

/* ---------- Modes ----------
   Pre-JS hint for phones, then the measured attribute (higher specificity, so it
   wins over the media query in either direction). */

@media (max-width: 639px) {
	.chm-cal {
		--chm-body-display: none;
		--chm-dot-display: block;
		--chm-tip-display: block;
		--chm-num-align: center;
		--chm-caption-size: 1.15rem;
		--chm-btn-cursor: pointer;
		--chm-legend-dir: column;
	}
}

.chm-cal[data-chm-size="sm"] {
	--chm-body-display: none;
	--chm-dot-display: block;
	--chm-tip-display: block;
	--chm-num-align: center;
	--chm-caption-size: 1.15rem;
	--chm-btn-cursor: pointer;
	--chm-legend-dir: column;
	--chm-months-cols: 1fr;
}

.chm-cal[data-chm-size="md"] {
	--chm-body-display: block;
	--chm-dot-display: none;
	--chm-tip-display: none;
	--chm-num-align: left;
	--chm-caption-size: 1.3rem;
	--chm-btn-cursor: default;
	--chm-legend-dir: row;
	--chm-months-cols: 1fr;
}

.chm-cal[data-chm-size="lg"] {
	--chm-body-display: block;
	--chm-dot-display: none;
	--chm-tip-display: none;
	--chm-num-align: left;
	--chm-caption-size: 1.3rem;
	--chm-btn-cursor: default;
	--chm-legend-dir: row;
}

.chm-cal--multi[data-chm-size="lg"] {
	--chm-months-cols: repeat(2, minmax(0, 1fr));
}

.chm-cal__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ---------- Legend ---------- */

.chm-cal .chm-cal__legend {
	display: flex;
	flex-direction: var(--chm-legend-dir);
	flex-wrap: wrap;
	gap: 0.35rem 1.25rem;
	margin: 0 0 1.25rem !important;
	padding: 0.85rem 1rem !important;
	list-style: none !important;
	background: var(--chm-panel);
	border: 0;
	border-radius: var(--chm-radius);
}

.chm-cal .chm-cal__legend-item {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin: 0 !important;
	padding: 0 !important;
	border: 0;
	font-size: 0.875rem;
	line-height: 1.3;
	list-style: none !important;
	text-indent: 0;
}

.chm-cal .chm-cal__legend-item::before,
.chm-cal .chm-cal__legend-item::after {
	content: none !important;
}

.chm-cal .chm-cal__legend-item::marker {
	content: none;
}

.chm-cal__legend-dot {
	flex: 0 0 auto;
	width: 0.6rem;
	height: 0.6rem;
	border-radius: 50%;
	background: var(--chm-cell, var(--chm-pad));
}

/* ---------- Month layout ---------- */

.chm-cal__months {
	display: grid;
	grid-template-columns: var(--chm-months-cols);
	gap: 1.75rem 2.5rem;
	/* Without this, a 5-week month stretches to match a 6-week month beside it and
	   distributes the slack across its rows, so side-by-side months end up with
	   different cell heights. */
	align-items: start;
}

.chm-cal .chm-cal__month {
	width: 100% !important;
	max-width: none;
	margin: 0 !important;
	border: 0 !important;
	border-collapse: collapse !important;
	border-spacing: 0 !important;
	table-layout: fixed !important;
	background: none !important;
	font-size: inherit;
}

.chm-cal .chm-cal__caption {
	caption-side: top !important;
	margin: 0 0 0.5rem;
	padding: 0 !important;
	background: none !important;
	color: var(--chm-heading);
	font-size: var(--chm-caption-size);
	font-weight: 800;
	letter-spacing: 0.04em;
	text-align: left !important;
	text-transform: uppercase;
}

/* Shown when a whole month came back with no hours -- a grid of em dashes on its
   own reads as broken rather than "not published yet". */
.chm-cal__note {
	display: block;
	margin-top: 0.15rem;
	color: var(--chm-ink);
	font-size: 0.75rem;
	font-weight: 400;
	letter-spacing: 0;
	text-transform: none;
}

.chm-cal .chm-cal__wd {
	padding: 0 0 0.3rem !important;
	border: 0 !important;
	background: none !important;
	color: var(--chm-ink);
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-align: center !important;
	text-transform: uppercase;
	opacity: 0.75;
}

/* ---------- Cells ---------- */

.chm-cal .chm-cal__month td {
	padding: 0 !important;
	border: 1px solid var(--chm-gap) !important;
	background-color: #FFFFFF !important;
	background-image: none !important;
	vertical-align: top !important;
	text-align: center;
}

.chm-cal .chm-cal__pad {
	background-color: var(--chm-pad) !important;
}

.chm-cal .chm-cal__cell {
	position: relative;
}

.chm-cal .chm-cal__btn {
	display: block;
	width: 100%;
	min-width: 0 !important;
	min-height: 0 !important;
	max-width: none;
	height: auto;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
	border-radius: 0 !important;
	background: none !important;
	background-image: none !important;
	box-shadow: none !important;
	color: inherit;
	font: inherit !important;
	line-height: inherit !important;
	text-align: center;
	text-decoration: none;
	text-transform: none !important;
	letter-spacing: normal !important;
	transform: none !important;
	transition: none;
	cursor: var(--chm-btn-cursor);
	-webkit-appearance: none;
	appearance: none;
}

.chm-cal .chm-cal__btn--static {
	cursor: default;
}

.chm-cal .chm-cal__btn:hover,
.chm-cal .chm-cal__btn:focus,
.chm-cal .chm-cal__btn:active {
	border: 0 !important;
	background: none !important;
	box-shadow: none !important;
	color: inherit;
	transform: none !important;
}

.chm-cal .chm-cal__btn:focus-visible {
	outline: 2px solid var(--chm-heading) !important;
	outline-offset: -2px;
}

.chm-cal__num {
	display: block;
	padding: 0.15rem 0.35rem;
	background: var(--chm-cell, var(--chm-pad));
	color: var(--chm-cell-ink, #FFFFFF);
	font-size: 0.8rem;
	font-weight: 700;
	line-height: 1.5;
	text-align: var(--chm-num-align);
}

/* A real date the API had no hours for -- must not be mistaken for an out-of-month
   padding cell, which is the same beige. */
.chm-cal .chm-cal__cell[data-state="none"] .chm-cal__num {
	background: #FFFFFF;
	color: var(--chm-ink);
	box-shadow: inset 0 -1px 0 #E2DED7;
	opacity: 0.8;
}

.chm-cal__body {
	display: var(--chm-body-display);
	padding: 0.4rem 0.25rem 0.5rem;
	color: var(--chm-ink);
	font-size: 0.7rem;
	line-height: 1.35;
	/* Reserve two lines so single-line days (Closed, no data) keep the grid even. */
	min-height: 4em;
}

.chm-cal__status {
	display: block;
	font-weight: 700;
}

.chm-cal__time {
	display: block;
	white-space: nowrap;
}

/* Special-hours days print their label and time in the accent color, per mockup. */
.chm-cal .chm-cal__cell[data-state="special"] .chm-cal__body {
	color: var(--chm-cell);
}

/* An open pattern with no matching color rule.
   Flagged by its own color plus its "Hours not configured" legend entry. The diagonal
   hatching and trailing "!" were removed in 1.1.3 -- with a whole month unmatched they
   dominated the view, and a guest should not be shown what reads as an error state. */

/* Elapsed days. Kept legible but recessed -- the view is for planning ahead.
   Toggle in Center Hours > Calendar Colors. */
.chm-cal .chm-cal__cell.is-past .chm-cal__num,
.chm-cal .chm-cal__cell.is-past .chm-cal__body,
.chm-cal .chm-cal__cell.is-past .chm-cal__dotwrap {
	opacity: 0.4;
}

/* Today's outline.
   Drawn as an overlay rather than an inset box-shadow on the cell: an inset shadow
   paints beneath the cell's children, so the colored date bar covered its top edge
   and the ring only appeared around the white hours area. */
.chm-cal .chm-cal__cell.is-today::after {
	content: "";
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	box-shadow: inset 0 0 0 2px var(--chm-heading);
	pointer-events: none;
	z-index: 5;
}

/* ---------- Condensed mode: dots + tooltip ---------- */

.chm-cal__dotwrap {
	display: var(--chm-dot-display);
	padding: 0.4rem 0;
	text-align: center;
}

.chm-cal__dot {
	display: inline-block;
	width: 0.5rem;
	height: 0.5rem;
	border-radius: 50%;
	background: var(--chm-cell, var(--chm-pad));
}

.chm-cal .chm-cal__cell[data-state="none"] .chm-cal__dot {
	background: transparent;
}

.chm-cal .chm-cal__tip {
	position: absolute;
	bottom: calc(100% + 6px);
	left: 50%;
	z-index: 20;
	display: none;
	min-width: 8.5rem;
	max-width: 12rem;
	padding: 0.5rem 0.65rem !important;
	margin: 0 !important;
	transform: translateX(-50%);
	background: #FFFFFF !important;
	border: 0;
	border-radius: var(--chm-radius);
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
	color: var(--chm-ink);
	font-size: 0.75rem;
	line-height: 1.35;
	text-align: left;
	white-space: normal;
}

/* Only ever visible in condensed mode -- in full-cell mode --chm-tip-display is
   `none`, so even a stuck is-open class cannot show a redundant tooltip. */
.chm-cal .chm-cal__cell.is-open > .chm-cal__tip {
	display: var(--chm-tip-display);
}

.chm-cal .chm-cal__tip[data-align="start"] {
	left: 0;
	transform: none;
}

.chm-cal .chm-cal__tip[data-align="end"] {
	left: auto;
	right: 0;
	transform: none;
}

.chm-cal__tip-date {
	display: block;
	font-weight: 700;
}

.chm-cal__tip-status,
.chm-cal__tip-hours {
	display: block;
}

.chm-cal .chm-cal__cell[data-state="special"] .chm-cal__tip-status,
.chm-cal .chm-cal__cell[data-state="special"] .chm-cal__tip-hours {
	color: var(--chm-cell);
}

@media (prefers-reduced-motion: reduce) {
	.chm-cal * {
		transition: none !important;
	}
}
