/**
 * Window Fixers — modern chat widget (Apple-style).
 * Design tokens from docs/08: primary #0b62b4, deep #073b6d, surfaces #eef6ff.
 * Notes:
 *  - All inputs use font-size:16px so iOS Safari never zooms on focus.
 *  - The thread scrolls inside its own container (overscroll contained), never the page.
 *  - Launcher mode is a clean bottom-anchored sheet that respects iOS safe areas (dvh).
 */

.wfai-cw {
	--wf-primary: #0b62b4;
	--wf-primary-d: #095596;
	--wf-deep: #073b6d;
	--wf-surface: #eef4fb;
	--wf-assistant: #eef2f8;
	--wf-border: #e3e9f1;
	--wf-input-border: #d4deeb;
	--wf-text: #1f2a37;
	--wf-muted: #8a97a8;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: var(--wf-text);
	-webkit-font-smoothing: antialiased;
	box-sizing: border-box;
}
.wfai-cw *, .wfai-cw *::before, .wfai-cw *::after { box-sizing: border-box; }

/* ---- layout modes ---- */
.wfai-cw--inline .wfai-cw__panel {
	max-width: 480px;
	height: 640px;
	max-height: 80vh;
	margin: 0 auto;
}
.wfai-cw--launcher {
	position: fixed;
	right: max(16px, env(safe-area-inset-right));
	bottom: max(16px, env(safe-area-inset-bottom));
	z-index: 2147483000;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
}
.wfai-cw--launcher .wfai-cw__panel {
	width: 400px;
	max-width: calc(100vw - 32px);
	height: 640px;
	/* --wf-kb is the on-screen keyboard inset (set from JS via the VisualViewport API),
	   so the panel shrinks to keep the composer above the iOS/Android keyboard. */
	max-height: min(720px, calc(100dvh - 112px - var(--wf-kb, 0px)));
}
.wfai-cw__launcher {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	border: none;
	background: linear-gradient(160deg, var(--wf-primary), var(--wf-deep));
	color: #fff;
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 10px 30px rgba(11, 98, 180, 0.4);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
	flex: none;
}
.wfai-cw__launcher:hover { transform: translateY(-2px) scale(1.04); }
.wfai-cw__launcher:active { transform: scale(0.96); }

/* ---- panel ---- */
.wfai-cw__panel {
	display: flex;
	flex-direction: column;
	min-height: 0;
	background: #fff;
	border: 1px solid var(--wf-border);
	border-radius: 22px;
	overflow: hidden;
	box-shadow: 0 24px 60px rgba(13, 38, 76, 0.24), 0 2px 8px rgba(13, 38, 76, 0.08);
	animation: wfai-cw-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes wfai-cw-pop { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

.wfai-cw__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 14px 14px 18px;
	background: linear-gradient(135deg, var(--wf-primary), var(--wf-deep));
	color: #fff;
	flex: none;
}
.wfai-cw__title { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 16px; letter-spacing: 0.2px; }
.wfai-cw__dot { width: 9px; height: 9px; border-radius: 50%; background: #43d18a; box-shadow: 0 0 0 4px rgba(67, 209, 138, 0.25); flex: none; }
.wfai-cw__header-actions { display: flex; gap: 6px; }
.wfai-cw__header-btn {
	width: 36px; height: 36px;
	display: inline-flex; align-items: center; justify-content: center;
	border: none; border-radius: 50%;
	background: rgba(255, 255, 255, 0.16);
	color: #fff; font-size: 17px; line-height: 1; cursor: pointer;
	transition: background 0.15s ease;
}
.wfai-cw__header-btn:hover { background: rgba(255, 255, 255, 0.3); }

/* ---- thread ---- */
.wfai-cw__thread {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	padding: 18px 16px 8px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background:
		radial-gradient(120% 60% at 50% 0%, #f7faff 0%, #ffffff 60%);
	scrollbar-width: thin;
}
.wfai-cw__thread::-webkit-scrollbar { width: 6px; }
.wfai-cw__thread::-webkit-scrollbar-thumb { background: rgba(13, 38, 76, 0.16); border-radius: 99px; }

.wfai-cw__msg {
	max-width: 78%;
	padding: 11px 15px;
	border-radius: 20px;
	line-height: 1.45;
	font-size: 15px;
	white-space: pre-wrap;
	word-wrap: break-word;
	animation: wfai-cw-msg 0.18s ease;
}
@keyframes wfai-cw-msg { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.wfai-cw__msg--assistant {
	align-self: flex-start;
	background: var(--wf-assistant);
	color: var(--wf-deep);
	border-bottom-left-radius: 7px;
}
.wfai-cw__msg--customer {
	align-self: flex-end;
	background: linear-gradient(135deg, var(--wf-primary), var(--wf-primary-d));
	color: #fff;
	border-bottom-right-radius: 7px;
	box-shadow: 0 4px 12px rgba(11, 98, 180, 0.22);
}
.wfai-cw__typing { display: inline-flex; gap: 4px; align-items: center; }
.wfai-cw__typing { letter-spacing: 2px; color: var(--wf-muted); animation: wfai-cw-pulse 1.2s infinite; }
@keyframes wfai-cw-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ---- estimate card ---- */
.wfai-cw__estimate {
	margin: 6px 16px 10px;
	padding: 16px 18px;
	border-radius: 18px;
	background: linear-gradient(135deg, var(--wf-primary), var(--wf-deep));
	color: #fff;
	box-shadow: 0 10px 24px rgba(11, 98, 180, 0.28);
	flex: none;
}
.wfai-cw__estimate-eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.85; }
.wfai-cw__estimate-total { font-size: 2rem; font-weight: 700; margin: 2px 0; letter-spacing: -0.5px; }
.wfai-cw__estimate-note { font-size: 12px; opacity: 0.9; line-height: 1.4; }

/* ---- evidence bar ---- */
.wfai-cw__evidence { margin: 0 16px 12px; flex: none; }
.wfai-cw__evidence-label { font-size: 12px; color: var(--wf-muted); margin-bottom: 5px; }
.wfai-cw__bar { height: 8px; border-radius: 99px; background: #e6ecf5; overflow: hidden; }
.wfai-cw__bar-fill { height: 100%; background: linear-gradient(90deg, #34c77b, #2e8b57); transition: width 0.35s ease; }

/* ---- chips ---- */
.wfai-cw__chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 16px 12px; flex: none; }
.wfai-cw__chip {
	border: 1px solid rgba(11, 98, 180, 0.45);
	background: #fff;
	color: var(--wf-primary);
	border-radius: 999px;
	padding: 9px 16px;
	font-size: 14px;
	min-height: 40px;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.1s ease;
}
.wfai-cw__chip:hover:not(:disabled) { background: var(--wf-surface); }
.wfai-cw__chip:active:not(:disabled) { transform: scale(0.97); }
.wfai-cw__chip:disabled { opacity: 0.5; cursor: default; }

/* ---- attachments ---- */
.wfai-cw__attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 10px; }
.wfai-cw__thumb { position: relative; width: 56px; height: 56px; border-radius: 12px; overflow: hidden; border: 1px solid var(--wf-border); }
.wfai-cw__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.wfai-cw__thumb.is-uploading img { opacity: 0.5; }
.wfai-cw__thumb-spin { position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border: 2px solid #fff; border-top-color: var(--wf-primary); border-radius: 50%; animation: wfai-cw-spin 0.8s linear infinite; }
@keyframes wfai-cw-spin { to { transform: rotate(360deg); } }
.wfai-cw__thumb-remove {
	position: absolute; top: 3px; right: 3px;
	width: 18px; height: 18px; border: none; border-radius: 50%;
	background: rgba(7, 38, 76, 0.78); color: #fff; font-size: 12px; line-height: 1; cursor: pointer;
	display: inline-flex; align-items: center; justify-content: center;
}

/* ---- contact form ---- */
.wfai-cw__contact { padding: 2px 16px 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; flex: 1 1 auto; min-height: 0; }
.wfai-cw__invoice { padding-top: 4px; }
.wfai-cw__subhead { font-weight: 600; color: var(--wf-deep); margin: 12px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.wfai-cw__field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 9px; font-size: 12px; color: var(--wf-muted); }
.wfai-cw__field input {
	min-height: 46px;
	border: 1px solid var(--wf-input-border);
	border-radius: 12px;
	padding: 10px 14px;
	font-size: 16px; /* iOS: prevents focus zoom */
	color: var(--wf-text);
	background: #fbfcfe;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.wfai-cw__field input:focus { outline: none; border-color: var(--wf-primary); box-shadow: 0 0 0 3px rgba(11, 98, 180, 0.14); background: #fff; }
.wfai-cw__row { display: flex; gap: 9px; }
.wfai-cw__row .wfai-cw__field { flex: 1; }
.wfai-cw__check { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; line-height: 1.4; color: #5b6776; margin: 8px 0; cursor: pointer; }
.wfai-cw__check input { width: 20px; height: 20px; margin-top: 1px; flex: none; accent-color: var(--wf-primary); }

/* ---- composer ---- */
.wfai-cw__composer {
	border-top: 1px solid var(--wf-border);
	padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
	background: #fff;
	flex: none;
}
.wfai-cw__photo-consent { padding: 2px 4px 8px; margin: 0; }
.wfai-cw__composer-row { display: flex; align-items: center; gap: 8px; }
.wfai-cw__icon-btn {
	display: inline-flex; align-items: center; justify-content: center;
	width: 44px; height: 44px; min-width: 44px; flex: none;
	border: 1px solid var(--wf-border); border-radius: 50%;
	background: #fff; font-size: 18px; cursor: pointer; color: var(--wf-deep);
	transition: background 0.15s ease;
}
.wfai-cw__icon-btn:hover { background: var(--wf-surface); }
.wfai-cw__voice.is-disabled { opacity: 0.4; cursor: not-allowed; }
.wfai-cw__input {
	flex: 1 1 auto;
	min-width: 0;
	min-height: 44px;
	border: 1px solid var(--wf-input-border);
	border-radius: 999px;
	padding: 10px 18px;
	font-size: 16px; /* iOS: prevents focus zoom */
	background: #f5f8fc;
	color: var(--wf-text);
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.wfai-cw__input:focus { outline: none; border-color: var(--wf-primary); box-shadow: 0 0 0 3px rgba(11, 98, 180, 0.14); background: #fff; }
.wfai-cw__send {
	width: 44px; height: 44px; min-width: 44px; flex: none;
	border: none; border-radius: 50%;
	background: linear-gradient(135deg, var(--wf-primary), var(--wf-primary-d));
	color: #fff; font-size: 17px; cursor: pointer;
	display: inline-flex; align-items: center; justify-content: center;
	transition: transform 0.12s ease, opacity 0.15s ease;
}
.wfai-cw__send:hover:not(:disabled) { transform: scale(1.06); }
.wfai-cw__send:disabled { opacity: 0.35; cursor: default; }

.wfai-cw__primary {
	width: 100%;
	min-height: 50px;
	border: none;
	border-radius: 14px;
	background: linear-gradient(135deg, var(--wf-primary), var(--wf-primary-d));
	color: #fff;
	font-weight: 600;
	font-size: 16px;
	cursor: pointer;
	margin-top: 10px;
	box-shadow: 0 8px 20px rgba(11, 98, 180, 0.26);
	transition: transform 0.12s ease, opacity 0.15s ease;
}
.wfai-cw__primary:active:not(:disabled) { transform: scale(0.99); }
.wfai-cw__primary:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

/* ---- notices ---- */
.wfai-cw__error { margin: 0 16px 10px; padding: 11px 14px; background: #fff2f2; color: #b3261e; border-radius: 12px; font-size: 13px; flex: none; }
.wfai-cw__error a { color: #b3261e; font-weight: 600; }
.wfai-cw__done { margin: 8px 16px 14px; padding: 14px 16px; background: #eafaf0; color: #176b39; border-radius: 14px; font-size: 14px; flex: none; }

/* ---- mobile: full-height sheet ---- */
@media (max-width: 520px) {
	.wfai-cw--launcher {
		right: 12px;
		left: 12px;
		bottom: max(12px, env(safe-area-inset-bottom));
		align-items: stretch;
	}
	.wfai-cw--launcher .wfai-cw__panel {
		width: 100%;
		max-width: 100%;
		height: calc(100dvh - 96px - var(--wf-kb, 0px));
		max-height: calc(100dvh - 96px - var(--wf-kb, 0px));
		border-radius: 24px;
	}
	.wfai-cw__launcher { align-self: flex-end; }
	.wfai-cw__msg { max-width: 84%; font-size: 15px; }
}

/* When the contact form is on screen it is the task at hand: cap the chat history so the
   form (and its submit button) always have room, instead of the two splitting the panel. */
.wfai-cw__panel.is-contact .wfai-cw__thread {
	flex: 0 1 auto;
	max-height: 32%;
}
