/*
 * Quick Chat Entry bar (Sprint 2).
 *
 * Reuses the design tokens emitted by Appearance_Service::css_variables()
 * (--handik-accent, --handik-surface, --handik-border, --handik-radius, etc.)
 * so the bar themes with the same controls as the main app.
 */

.handik-chat-entry {
	--handik-ce-radius: var( --handik-radius, 18px );
	box-sizing: border-box;
	position: relative;
	width: 100%;
	max-width: var( --handik-max-width, 720px );
	margin: 0 auto;
	font-family: var( --handik-font-family, inherit );
	color: var( --handik-text, #0f172a );
}

.handik-chat-entry *,
.handik-chat-entry *::before,
.handik-chat-entry *::after {
	box-sizing: border-box;
}

.handik-chat-entry__bar {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 8px 8px 8px 12px;
	background: var( --handik-surface, #fff );
	border: 1px solid var( --handik-border, #dbe3ea );
	border-radius: 1rem;
	box-shadow: var( --handik-shadow, 0 24px 60px rgba( 15, 23, 42, 0.12 ) );
}

.handik-chat-entry__attach,
.handik-chat-entry__send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 44px;
	height: 44px;
	border: none;
	cursor: pointer;
	border-radius: 1rem;
	background: transparent;
	color: var( --handik-muted-text, #64748b );
	transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.handik-chat-entry__attach:hover {
	background: var( --handik-background, #f1f5f9 );
	color: var( --handik-text, #0f172a );
}

.handik-chat-entry__attach.has-files {
	color: var( --handik-accent, #283618 );
}

.handik-chat-entry__send {
	/* Site-style: white halftone icon on a black square. */
	background: var( --handik-footer-button-active-bg, #1a1a1c );
	color: #fff;
}

.handik-chat-entry__send:hover {
	opacity: 0.9;
}

.handik-chat-entry__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.handik-chat-entry__input {
	flex: 1 1 auto;
	min-width: 0;
	border: none;
	outline: none;
	background: transparent;
	font: inherit;
	font-family: var( --handik-font-family, inherit );
	font-size: 16px; /* 16px avoids iOS zoom-on-focus */
	line-height: 1.4;
	color: var( --handik-text, #0f172a );
	padding: 9px 4px;
	/* Now a <textarea>: grows with the message (JS-capped to ~4 lines), then
	   scrolls. Enter inserts a newline; only the send button submits. */
	resize: none;
	max-height: 112px;
	overflow-y: hidden;
	/* Once the message grows past the cap and the textarea becomes scrollable,
	   keep the wheel/touch scroll inside it instead of chaining to the page
	   (desktop bug: "the page scrolls instead of the bar"). */
	overscroll-behavior: contain;
}

.handik-chat-entry__input::placeholder {
	color: var( --handik-muted-text, #94a3b8 );
}

/* On narrow phones a long placeholder wrapped to 2-3 lines and got clipped by
   the single-row height. Keep the placeholder on one clean line (ellipsis where
   supported) while the field is empty; typed text still wraps normally. */
.handik-chat-entry__input:placeholder-shown {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Selected-file chips — float ABOVE the bar so adding files never shifts it.
   Sit close to the bar (was 6px) so the thumbnails read as part of it. */
.handik-chat-entry__chips {
	position: absolute;
	left: 0;
	right: 0;
	bottom: calc( 100% + 2px );
	z-index: 2;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 6px;
}

.handik-chat-entry__chip {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* Default: a compact 50x50 image thumbnail so the user sees exactly what
	   they attached. The labelled fallback (video, or an image the browser
	   can't decode) re-adds the pill look via .is-fallback below. */
	width: 50px;
	height: 50px;
	border-radius: 10px;
}

.handik-chat-entry__chip-thumb {
	width: 50px !important;
	height: 50px !important;
	display: block;
	object-fit: cover;
	border-radius: 5px !important;
	border: 1px solid var( --handik-border, #dbe3ea );
}

/* Slightly smaller square thumbnails on phones. */
@media ( max-width: 480px ) {
	.handik-chat-entry__chip {
		width: 42px;
		height: 42px;
	}
	.handik-chat-entry__chip-thumb {
		width: 42px !important;
		height: 42px !important;
	}
}

.handik-chat-entry__chip.is-fallback {
	width: auto;
	height: auto;
	gap: 6px;
	max-width: 220px;
	padding: 4px 8px 4px 10px;
	font-size: 13px;
	line-height: 1.3;
	background: var( --handik-background, #f1f5f9 );
	border: 1px solid var( --handik-border, #dbe3ea );
	border-radius: 1rem;
	color: var( --handik-text, #0f172a );
}

.handik-chat-entry__chip-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Remove control — a small circular badge over the top-right of the thumbnail.
   The visible badge is 22px, but an invisible ::before expands the tap target
   to ~40px so it stays finger-friendly on mobile. */
.handik-chat-entry__chip-remove {
	position: absolute;
	top: -7px;
	right: -7px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	margin: 0;
	padding: 0;
	border: none;
	border-radius: 50%;
	cursor: pointer;
	background: var( --handik-text, #0f172a );
	color: #fff;
	font-size: 15px;
	line-height: 1;
	box-shadow: 0 1px 3px rgba( 15, 23, 42, 0.35 );
	z-index: 3;
}

.handik-chat-entry__chip-remove::before {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 40px;
	height: 40px;
	transform: translate( -50%, -50% );
	border-radius: 50%;
}

.handik-chat-entry__chip-remove:hover {
	background: #000;
}

/* The SPA panel host */
.handik-chat-entry__panel {
	margin-top: 16px;
}

.handik-chat-entry__panel .handik-booking-app {
	width: 100%;
}

/* --- Sticky mode -------------------------------------------------------- */
.handik-chat-entry--sticky {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 99990;
	max-width: none;
	margin: 0;
	padding: 12px 16px calc( 12px + env( safe-area-inset-bottom, 0px ) );
	pointer-events: none;
}

.handik-chat-entry--sticky .handik-chat-entry__bar {
	/* Collapsed bar = the narrower hero/heading width (the open window grows to
	   the nav-menu width, 1290px). Tune --handik-ce-bar to match the site. */
	max-width: var( --handik-ce-bar, 920px );
	margin: 0 auto;
	pointer-events: auto;
}

.handik-chat-entry--sticky .handik-chat-entry__chips {
	max-width: var( --handik-ce-bar, 920px );
	margin-left: auto;
	margin-right: auto;
	pointer-events: auto;
}

/* In sticky mode the SPA opens in a modal overlay, not inline. */
.handik-chat-entry--sticky .handik-chat-entry__panel {
	margin-top: 0;
}

.handik-chat-entry__overlay {
	position: fixed;
	inset: 0;
	z-index: 99991;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	padding: 0;
	/* Open-state backdrop: a green->blue gradient (replaces the dark scrim) so the
	   window reads as part of a richer scene as it grows out of the bar. */
	background: linear-gradient( 180deg, #122104 0%, #7BA7B5 100% );
	-webkit-overflow-scrolling: touch;
	opacity: 0;
	transition: opacity 260ms ease;
}

/* Smooth morph: the panel grows up from the bar (origin bottom-center) while the
   backdrop fades in, so the bar reads as expanding into one window. */
.handik-chat-entry__overlay.is-open {
	opacity: 1;
}

/* The grown (open) window. The panel animates its actual width + height from a
   bar-sized pill up to the full window (bottom-anchored), so the bar morphs into
   one window. Mobile = full screen; desktop width/height live in the >=720 block. */
.handik-chat-entry__overlay.is-open .handik-chat-entry__overlay-panel {
	width: 100%;
	height: 100vh;
	height: 100dvh;
	border-radius: 0;
	overflow: auto;
}

/* Claude single-window panel owns the full height so the chat thread is the only
   scroll container (the base panel's own overflow/padding fought .hcc-panel and
   broke wheel scrolling). */
.handik-chat-entry__overlay-panel.is-claude {
	padding: 0;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.handik-chat-entry__overlay-panel.is-claude .handik-claude-chat,
.handik-chat-entry__overlay-panel.is-claude .hcc-panel {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
}

.handik-chat-entry__overlay-panel.is-claude .hcc-panel {
	max-height: none;
	border-radius: inherit;
}

@media ( prefers-reduced-motion: reduce ) {
	.handik-chat-entry__overlay,
	.handik-chat-entry__overlay-panel {
		transition: none;
	}
}

/* Minimized "resume" pill — the collapsed window sitting where the bar was. */
.handik-chat-entry__resume {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 8px 8px 8px 20px;
	background: #1a1a1c;
	border: none;
	border-radius: 1rem;
	box-shadow: var( --handik-shadow, 0 24px 60px rgba( 15, 23, 42, 0.12 ) );
}

.handik-chat-entry--sticky .handik-chat-entry__resume {
	max-width: var( --handik-ce-bar, 920px );
	margin: 0 auto;
	/* The sticky root is pointer-events:none; the pill must opt back in or it
	   can't be clicked to reopen. */
	pointer-events: auto;
}

.handik-chat-entry__resume-open {
	flex: 1 1 auto;
	border: none;
	background: transparent;
	text-align: left;
	font: inherit;
	font-weight: 600;
	color: #fff;
	cursor: pointer;
	padding: 8px 0;
}

.handik-chat-entry__resume-discard {
	flex: 0 0 auto;
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 1rem;
	background: transparent;
	color: #fff;
	font-size: 20px;
	cursor: pointer;
}

.handik-chat-entry__resume-discard:hover {
	background: rgba( 255, 255, 255, 0.14 );
}

/* Keyboard focus visibility (WCAG 2.4.7). */
.handik-chat-entry__attach:focus-visible,
.handik-chat-entry__send:focus-visible,
.handik-chat-entry__chip-remove:focus-visible,
.handik-chat-entry__overlay-close:focus-visible,
.handik-chat-entry__resume-open:focus-visible,
.handik-chat-entry__resume-discard:focus-visible {
	outline: 2px solid var( --handik-accent, #283618 );
	outline-offset: 2px;
}

/* The text field gets a soft, light ring instead of the heavy accent outline. */
.handik-chat-entry__input:focus-visible {
	outline: 1px solid #e5e5e5;
	outline-offset: 2px;
	border-radius: 5px;
}

@media ( min-width: 720px ) {
	.handik-chat-entry__overlay {
		/* Desktop/tablet: symmetric 24px top + bottom; flex-end keeps the window
		   bottom-anchored so it grows up out of the bar. */
		align-items: flex-end;
		padding: 24px 24px calc( 24px + env( safe-area-inset-bottom, 0px ) );
	}
}

.handik-chat-entry__overlay-panel {
	position: relative;
	/* COLLAPSED state — a bar-sized pill. .is-open grows it (width + height,
	   bottom-anchored) into the full window, so the bar morphs into the window.
	   Mobile collapsed = full width, 64px tall. */
	width: 100%;
	max-width: none;
	height: 64px;
	overflow: hidden;
	background: var( --handik-surface, #fff );
	border-radius: 1rem;
	transition: width 480ms cubic-bezier( 0.22, 1, 0.36, 1 ), height 480ms cubic-bezier( 0.22, 1, 0.36, 1 ), border-radius 300ms ease;
	will-change: width, height;
	padding: 16px;
	padding-bottom: calc( 16px + env( safe-area-inset-bottom, 0px ) );
	box-shadow: var( --handik-shadow, 0 24px 60px rgba( 15, 23, 42, 0.2 ) );
}

@media ( min-width: 720px ) {
	/* COLLAPSED desktop = the narrow bar width, a 64px pill, bottom-anchored.
	   min(100%, …) clamps to the viewport so it never clips on narrow windows. */
	.handik-chat-entry__overlay-panel {
		width: min( 100%, var( --handik-ce-bar, 920px ) );
		max-width: var( --handik-ce-window, 1290px );
		height: 64px;
		border-radius: 1rem;
		padding-bottom: 16px;
	}
	/* OPEN desktop = the nav-menu width (1290px), full height minus the 24px
	   symmetric top + bottom gaps (and any bottom safe-area inset). */
	.handik-chat-entry__overlay.is-open .handik-chat-entry__overlay-panel {
		width: min( 100%, var( --handik-ce-window, 1290px ) );
		max-width: var( --handik-ce-window, 1290px );
		height: calc( 100vh - 48px );
		height: calc( 100dvh - 48px - env( safe-area-inset-bottom, 0px ) );
		border-radius: 1rem;
	}
}

/* The Claude window's scroll lives in .hcc-thread, never the panel itself — keep
   the panel a non-scrolling frame in every state (overrides the open-state
   overflow:auto the SPA uses). */
.handik-chat-entry__overlay .handik-chat-entry__overlay-panel.is-claude {
	overflow: hidden;
}

.handik-chat-entry__overlay-close {
	position: absolute;
	top: 8px;
	right: 8px;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* Audit fix: ≥44px tap target. */
	width: 44px;
	height: 44px;
	border: none;
	cursor: pointer;
	border-radius: 1rem;
	background: var( --handik-background, #f1f5f9 );
	color: var( --handik-text, #0f172a );
	font-size: 22px;
	line-height: 1;
}

.handik-chat-entry__overlay-close:hover {
	background: var( --handik-border, #e2e8f0 );
}

/* When the body is locked behind the sticky overlay */
body.handik-chat-entry-locked {
	overflow: hidden;
}

/* Audit fix: the Cal.com embed forces min-height 640–720px, which overflows
   the overlay panel (max-height 92dvh) on small phones and creates a nested
   scroll trap. Inside the overlay only, let the embed use the available panel
   height with a much smaller floor so the calendar fits and scrolls once. */
@media ( max-width: 719px ) {
	.handik-chat-entry__overlay-panel .handik-booking-app__booking-embed,
	.handik-chat-entry__overlay-panel .handik-booking-app__booking-frame-wrap,
	.handik-chat-entry__overlay-panel .handik-booking-app__booking-embed iframe,
	.handik-chat-entry__overlay-panel .handik-booking-app__booking-frame {
		min-height: 0;
		height: auto;
	}
	.handik-chat-entry__overlay-panel .handik-booking-app__booking-frame {
		min-height: 60vh;
	}
}

/* =====================================================================
 * Google Places dropdown — force above the quick-flow overlay (2.10.1.61).
 *
 * Google renders `.pac-container` directly under <body> with z-index
 * ~1000, far below this overlay (99991), so address suggestions rendered
 * BEHIND the chat window and autocomplete looked dead. The identical lift
 * used to live in booking-app.css, but since the 2.10.1.52 teardown bar
 * pages no longer enqueue the classic bundle — the rule must live HERE,
 * in the stylesheet the bar always loads.
 * ===================================================================== */
.pac-container {
	z-index: 2147483647 !important;
	pointer-events: auto !important;
	border-radius: 12px;
	box-shadow: 0 16px 32px rgba( 15, 23, 42, 0.18 );
	border: 1px solid var( --handik-border, #dbe3ea );
	font-family: inherit;
}

.pac-container .pac-item,
.pac-container .pac-item-query {
	cursor: pointer !important;
	pointer-events: auto !important;
	padding: 8px 12px;
	font-size: 0.95rem;
	line-height: 1.4;
	color: var( --handik-text, #0f172a );
}

.pac-container .pac-item:hover {
	background: #f1f5f9;
}
