/**
 * CS Enhanced Booking Calendar Styles
 * Note: Works with existing custom CSS stored in DB
 */

.cs-ebc-calendar-wrapper {
	margin: 20px 0;
	padding: 20px;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 4px;
	width: 100%;
	max-width: 600px; /* Constrain calendar to reasonable width */
	box-sizing: border-box;
	overflow: hidden;
	display: block;
}

/* Ensure it works within the .cart container layout (from DB CSS) */
.cart .cs-ebc-calendar-wrapper {
	margin: 0;
	padding: 20px;
	width: 100%;
	max-width: 100%;
	box-sizing: border-box;
}

/* Work with existing product page layout */
.productContentFullBlock + .cart .cs-ebc-calendar-wrapper,
.cart .cs-ebc-calendar-wrapper {
	/* Respects the existing .cart container styling from DB */
	background: transparent;
	border: none;
	padding: 0;
	margin: 0;
	max-width: 100%;
	box-sizing: border-box;
}

/* Selected dates display */
.cs-ebc-selected-dates {
	display: flex;
	gap: 30px;
	margin-bottom: 20px;
	padding: 15px;
	background: #fff;
	border: 1px solid #ddd;
	border-radius: 4px;
	flex-wrap: wrap;
}

.cs-ebc-selected-checkin,
.cs-ebc-selected-checkout {
	flex: 1;
	min-width: 200px;
}

.cs-ebc-selected-checkin strong,
.cs-ebc-selected-checkout strong {
	display: block;
	margin-bottom: 5px;
	color: #333;
	font-size: 14px;
}

.cs-ebc-selected-checkin span,
.cs-ebc-selected-checkout span {
	color: #666;
	font-size: 16px;
}

/* Calendar container */
.cs-ebc-calendar-container {
	margin-top: 20px;
	width: 100%;
	max-width: 100%;
	overflow: hidden;
	box-sizing: border-box;
}

/* Calendar header */
.cs-ebc-calendar-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 15px;
	padding: 10px;
	background: #0073aa;
	color: #fff;
	border-radius: 4px 4px 0 0;
}

.cs-ebc-calendar-month-year {
	margin: 0;
	font-size: 18px;
	font-weight: 600;
	color: #fff;
}

.cs-ebc-calendar-prev,
.cs-ebc-calendar-next {
	background: rgba(255, 255, 255, 0.2);
	border: none;
	color: #fff;
	padding: 8px 15px;
	border-radius: 3px;
	cursor: pointer;
	font-size: 16px;
	transition: background 0.3s ease;
}

.cs-ebc-calendar-prev:hover,
.cs-ebc-calendar-next:hover {
	background: rgba(255, 255, 255, 0.3);
}

.cs-ebc-calendar-prev.cs-ebc-calendar-nav-disabled,
.cs-ebc-calendar-next.cs-ebc-calendar-nav-disabled,
.cs-ebc-calendar-prev:disabled,
.cs-ebc-calendar-next:disabled {
	opacity: 0.4;
	cursor: not-allowed;
	pointer-events: none;
}

.cs-ebc-calendar-prev.cs-ebc-calendar-nav-disabled:hover,
.cs-ebc-calendar-next.cs-ebc-calendar-nav-disabled:hover {
	background: rgba(255, 255, 255, 0.2);
}

/* Calendar table */
.cs-ebc-calendar-table {
	width: 100%;
	max-width: 100%;
	border-collapse: collapse;
	background: #fff;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
	table-layout: fixed;
	box-sizing: border-box;
}

.cs-ebc-calendar-table thead {
	background: #f5f5f5;
}

.cs-ebc-calendar-table th {
	padding: 12px 4px;
	text-align: center;
	font-weight: 600;
	color: #666;
	border-bottom: 2px solid #e0e0e0;
	font-size: 11px;
	text-transform: uppercase;
	width: 14.28%; /* Equal width for 7 days */
	box-sizing: border-box;
}

.cs-ebc-calendar-table td {
	padding: 0;
	border: 1px solid #e0e0e0;
	position: relative;
	height: 50px;
	vertical-align: middle;
	width: 14.28%; /* Equal width for 7 days */
	box-sizing: border-box;
	overflow: hidden;
}

.cs-ebc-calendar-day {
	cursor: pointer;
	transition: background-color 0.2s ease;
	text-align: center;
}

.cs-ebc-calendar-day:hover:not(.cs-ebc-past):not(.cs-ebc-booked):not(.cs-ebc-unavailable) {
	background: #f0f0f0;
}

.cs-ebc-day-number {
	display: inline-block;
	padding: 8px;
	min-width: 30px;
	border-radius: 3px;
}

/* Past dates */
.cs-ebc-past {
	background: #f5f5f5;
	color: #ccc;
	cursor: not-allowed;
}

.cs-ebc-past .cs-ebc-day-number {
	color: #ccc;
}

/* Booked dates */
.cs-ebc-booked {
	background: #ffebee;
	cursor: not-allowed;
}

.cs-ebc-booked .cs-ebc-day-number {
	color: #c62828;
	text-decoration: line-through;
}

/* Unavailable dates - light red background */
/* Unavailable dates - light red background */
.cs-ebc-calendar-table .cs-ebc-calendar-day.cs-ebc-unavailable {
	background: #ffebee !important;
	color: #999;
	cursor: not-allowed;
}

.cs-ebc-calendar-table .cs-ebc-calendar-day.cs-ebc-unavailable .cs-ebc-day-number {
	color: #999;
}

/* Check-in dates that can be used as check-out (half grey/half red) */
.cs-ebc-calendar-table .cs-ebc-calendar-day.cs-ebc-checkin-available-for-checkout {
	position: relative;
	background: linear-gradient(to right, #f5f5f5 50%, #ffebee 50%) !important;
	background-image: linear-gradient(to right, #f5f5f5 50%, #ffebee 50%) !important;
	cursor: pointer !important;
}

.cs-ebc-calendar-table .cs-ebc-calendar-day.cs-ebc-checkin-available-for-checkout .cs-ebc-day-number {
	position: relative;
	z-index: 1;
	color: #424242 !important;
	font-weight: 500;
}

/* Override unavailable styling when it's also a check-in date available for check-out */
.cs-ebc-calendar-table .cs-ebc-calendar-day.cs-ebc-checkin-available-for-checkout.cs-ebc-unavailable {
	background: linear-gradient(to right, #f5f5f5 50%, #ffebee 50%) !important;
	background-image: linear-gradient(to right, #f5f5f5 50%, #ffebee 50%) !important;
	cursor: pointer !important;
}

/* Note: Selected dates (dark blue) should take precedence over split style */
.cs-ebc-calendar-table .cs-ebc-calendar-day.cs-ebc-checkin-available-for-checkout.cs-ebc-selected {
	background: #0073aa !important;
	background-image: none !important;
}

.cs-ebc-calendar-table .cs-ebc-calendar-day.cs-ebc-checkin-available-for-checkout.cs-ebc-selected .cs-ebc-day-number {
	color: #fff !important;
}

/* Note: Past and booked dates should take precedence over split style, so no override needed */

/* Ensure partially booked dates are clickable when selecting check-out */
.cs-ebc-calendar-table .cs-ebc-calendar-day.cs-ebc-checkin-available-for-checkout:hover:not(.cs-ebc-past):not(.cs-ebc-booked):not(.cs-ebc-selected) {
	background: linear-gradient(to right, #e0e0e0 50%, #ffcdd2 50%) !important;
}

/* Available dates - only apply if NOT partially booked */
.cs-ebc-calendar-day:not(.cs-ebc-past):not(.cs-ebc-booked):not(.cs-ebc-unavailable):not(.cs-ebc-checkin-available-for-checkout) .cs-ebc-day-number {
	color: #424242;
	font-weight: 500;
}

/* Selected dates - check-in and check-out should always have dark blue background */
.cs-ebc-selected {
	background: #0073aa !important;
}

.cs-ebc-selected .cs-ebc-day-number {
	color: #fff !important;
	font-weight: 600;
	background: transparent;
}

/* Ensure selected dates keep their background even when in range */
.cs-ebc-selected.cs-ebc-in-range {
	background: #0073aa !important;
}

.cs-ebc-selected.cs-ebc-in-range .cs-ebc-day-number {
	color: #fff !important;
}

/* Dates in range - but not if they're selected */
.cs-ebc-in-range:not(.cs-ebc-selected) {
	background: #e3f2fd !important;
}

.cs-ebc-in-range:not(.cs-ebc-selected) .cs-ebc-day-number {
	color: #1976d2;
	background: transparent;
}

/* Today */
.cs-ebc-today:not(.cs-ebc-selected) {
	background: #fff3cd;
}

.cs-ebc-today:not(.cs-ebc-selected) .cs-ebc-day-number {
	color: #856404;
	font-weight: 600;
	border: 2px solid #ffc107;
}

/* Empty cells */
.cs-ebc-calendar-empty {
	background: #fafafa;
	border: none;
}

/* Loading indicator */
.cs-ebc-loading {
	display: flex !important;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 40px 20px;
	min-height: 300px;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 4px;
	position: relative;
	z-index: 1;
	margin-bottom: 20px; /* Add spacing to prevent overlap */
	clear: both;
	overflow: hidden;
}

/* Ensure loader doesn't overlap person fields */
.cs-ebc-calendar-container {
	position: relative;
	z-index: 1;
}

.cs-ebc-calendar-container .cs-ebc-loading {
	position: relative;
	z-index: 1;
}

.cs-ebc-spinner {
	width: 40px;
	height: 40px;
	border: 4px solid #f3f3f3;
	border-top: 4px solid #0073aa;
	border-radius: 50%;
	animation: cs-ebc-spin 1s linear infinite;
	margin-bottom: 15px;
}

@keyframes cs-ebc-spin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

.cs-ebc-loading p {
	margin: 0;
	color: #666;
	font-size: 14px;
}

.cs-ebc-loading.hidden {
	display: none;
}

/* Error message */
.cs-ebc-error-message {
	margin-top: 15px;
	padding: 12px;
	background: #f8d7da;
	color: #721c24;
	border: 1px solid #f5c6cb;
	border-radius: 4px;
	font-size: 14px;
}

/* Responsive design */
@media (max-width: 768px) {
	.cs-ebc-selected-dates {
		flex-direction: column;
		gap: 15px;
	}

	.cs-ebc-selected-checkin,
	.cs-ebc-selected-checkout {
		min-width: 100%;
	}

	.cs-ebc-calendar-table {
		font-size: 12px;
	}

	.cs-ebc-calendar-table th {
		padding: 8px 4px;
		font-size: 10px;
	}

	.cs-ebc-calendar-table td {
		height: 40px;
	}

	.cs-ebc-day-number {
		padding: 5px;
		min-width: 25px;
	}
}

/* Hide default WooCommerce Bookings calendar elements */
/* Important: Must override existing DB-stored CSS, including:
   - fieldset.wc-bookings-date-picker.wc-bookings-date-picker-booking.wc_bookings_field_start_date (from DB)
   - Any other date picker related styles
*/
.wc-bookings-booking-form fieldset.wc-bookings-date-picker,
.wc-bookings-booking-form fieldset:first-of-type.wc-bookings-date-picker,
fieldset.wc-bookings-date-picker.wc-bookings-date-picker-booking.wc_bookings_field_start_date,
fieldset.wc-bookings-date-picker {
	display: none !important;
	visibility: hidden !important;
	height: 0 !important;
	overflow: hidden !important;
	margin: 0 !important;
	padding: 0 !important;
	width: 0 !important;
	position: absolute !important;
	left: -9999px !important;
}

.wc-bookings-booking-form .wc-bookings-date-picker-date-fields,
.wc-bookings-booking-form .wc-bookings-date-picker .picker,
.wc-bookings-booking-form .wc-bookings-date-picker,
.wc-bookings-date-picker .picker,
.wc-bookings-date-picker-date-fields {
	display: none !important;
	visibility: hidden !important;
	height: 0 !important;
	overflow: hidden !important;
	width: 0 !important;
	position: absolute !important;
	left: -9999px !important;
}

/* WooCommerce Bookings cost element - ensure left alignment */
.wc-bookings-booking-cost {
	text-align: left !important;
}

/* Completely hide WooCommerce error messages - we'll display them in our error box */
.wc-bookings-booking-cost .booking-error,
.wc-bookings-booking-cost span.booking-error {
	display: none !important;
	visibility: hidden !important;
	opacity: 0 !important;
	height: 0 !important;
	overflow: hidden !important;
	position: absolute !important;
	left: -9999px !important;
	width: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
}

/* Hide WooCommerce booking cost when marked as hidden by our plugin */
.wc-bookings-booking-cost.cs-ebc-hidden-cost {
	display: none !important;
	visibility: hidden !important;
	opacity: 0 !important;
	height: 0 !important;
	overflow: hidden !important;
	position: absolute !important;
	left: -9999px !important;
	width: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
}

/* Subtotal line in cost breakdown */
.cs-ebc-discount-line {
	color: #d32f2f !important;
}

.cs-ebc-discount-line .cs-ebc-cost-label strong,
.cs-ebc-discount-line .cs-ebc-cost-value {
	color: #d32f2f !important;
	font-weight: bold !important;
}

.cs-ebc-subtotal-line {
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid #e0e0e0;
}

.cs-ebc-subtotal-line .cs-ebc-cost-label strong {
	font-weight: 600;
}

/* Cost Breakdown Styles */
.cs-ebc-cost-breakdown {
	margin: 20px 0;
	padding: 20px;
	background: #f9f9f9;
	border: 1px solid #e0e0e0;
	border-radius: 4px;
	max-width: 600px;
	clear: both;
	overflow: hidden;
	position: relative;
}

/* Cost breakdown loading indicator */
.cs-ebc-cost-breakdown-loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 20px;
	color: #666;
}

.cs-ebc-spinner-small {
	width: 20px;
	height: 20px;
	border: 2px solid #f3f3f3;
	border-top: 2px solid #0073aa;
	border-radius: 50%;
	animation: cs-ebc-spin 1s linear infinite;
}

/* Ensure persons fields are above cost breakdown and outside the grey box */
.wc-bookings-booking-form p[class*="wc_bookings_field_persons"] {
	margin-bottom: 20px !important;
	margin-top: 20px !important;
	margin-right: 20px !important;
	position: relative !important;
	z-index: 1 !important;
	display: inline-block !important;
	vertical-align: top !important;
	background: #fff !important;
	padding: 15px 0 !important;
	pointer-events: auto !important;
	width: auto !important;
}


/* Ensure select dropdowns in person fields are clickable */
.wc-bookings-booking-form p[class*="wc_bookings_field_persons"] select,
.wc-bookings-booking-form p[class*="wc_bookings_field_persons"] label {
	pointer-events: auto !important;
	z-index: 2 !important;
	position: relative !important;
}

/* Ensure person fields are NOT inside cost breakdown - override any parent styles */
.wc-bookings-booking-form > p[class*="wc_bookings_field_persons"] {
	background: #fff !important;
}

/* Force persons fields OUT of cost breakdown box - hide if inside */
.cs-ebc-cost-breakdown p[class*="wc_bookings_field_persons"],
.cs-ebc-cost-breakdown .wc_bookings_field_persons {
	display: none !important;
	visibility: hidden !important;
	height: 0 !important;
	overflow: hidden !important;
	margin: 0 !important;
	padding: 0 !important;
	line-height: 0 !important;
	font-size: 0 !important;
}

/* Ensure cost breakdown has proper spacing and doesn't visually contain person fields */
.cs-ebc-cost-breakdown {
	margin-top: 30px !important;
	margin-bottom: 20px !important;
	clear: both !important;
	overflow: hidden !important;
	position: relative !important;
	background: #f9f9f9 !important;
}

/* Ensure cost breakdown background doesn't extend to person fields */
.wc-bookings-booking-form p[class*="wc_bookings_field_persons"] + #cs-ebc-cost-breakdown,
.wc-bookings-booking-form p[class*="wc_bookings_field_persons"] ~ #cs-ebc-cost-breakdown {
	margin-top: 30px !important;
	border-top: 2px solid #e0e0e0 !important;
	padding-top: 20px !important;
}

/* Add visual separator - ensure person fields are clearly outside the grey box */
.wc-bookings-booking-form p[class*="wc_bookings_field_persons"]:last-of-type {
	margin-bottom: 30px !important;
	padding-bottom: 20px !important;
	position: relative !important;
}

.wc-bookings-booking-form p[class*="wc_bookings_field_persons"]:last-of-type::after {
	content: '';
	display: block;
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	height: 1px;
	background: #e0e0e0;
}

/* Ensure cost breakdown starts fresh after person fields */
#cs-ebc-cost-breakdown {
	border-top: 2px solid #e0e0e0 !important;
	padding-top: 20px !important;
	margin-top: 30px !important;
}

/* Ensure loader doesn't overlap person fields */
.cs-ebc-loading {
	clear: both;
	overflow: hidden;
}

.cs-ebc-cost-breakdown h4 {
	margin: 0 0 15px 0;
	font-size: 18px;
	font-weight: 600;
	color: #333;
}

.cs-ebc-cost-line {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10px 0;
	border-bottom: 1px solid #e0e0e0;
}

.cs-ebc-cost-line:last-child {
	border-bottom: none;
}

.cs-ebc-cost-line-note {
	font-size: 0.9em;
	color: #666;
	font-style: italic;
	border-bottom: none;
	padding-top: 5px;
	margin-top: 5px;
}

.cs-ebc-cost-line-note .cs-ebc-cost-label {
	width: 100%;
	text-align: left;
}

.cs-ebc-cost-label {
	flex: 1;
	text-align: left;
}

.cs-ebc-cost-value {
	flex: 0 0 auto;
	text-align: right;
	font-weight: 500;
}
