/* SAL — widget styles v1.1
   All rules scoped under #sal-root. */

/* ============================================================
   Defensive resets. WordPress themes can be aggressive — they
   apply `* { box-sizing: content-box }`, `textarea { min-height:
   100px }`, `button { width: 100%; text-transform: uppercase }`,
   etc. without scoping. Those rules cascade into our widget and
   break the layout (textarea inflates to theme-imposed min-height,
   send button stretches, panel widens past its 400px design).
   These resets re-assert the widget's own layout invariants. The
   `!important` markers are scoped only to properties themes most
   commonly override, and only on layout-critical elements.
   ============================================================ */
#sal-root,
#sal-root *,
#sal-root *::before,
#sal-root *::after {
	box-sizing: border-box;
}
#sal-root button,
#sal-root input,
#sal-root textarea,
#sal-root select,
#sal-root a {
	font-family: inherit;
	font-size: inherit;
	color: inherit;
	line-height: inherit;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	margin: 0;
}
#sal-root button {
	border-radius: 0;  /* will be overridden by component-specific rules */
	box-shadow: none;
	appearance: none;
	-webkit-appearance: none;
}
/* Force visible placeholders. Themes commonly set ::placeholder { color:
   transparent } or { opacity: 0 } site-wide, which would render every text
   field in the widget as a blank rectangle — including the lead capture form
   fields (email, phone, name). The !important markers are scoped to the two
   properties themes overwhelmingly target. */
#sal-root input::placeholder,
#sal-root textarea::placeholder {
	color: var(--sal-muted) !important;
	opacity: 1 !important;
}
#sal-root input::-webkit-input-placeholder,
#sal-root textarea::-webkit-input-placeholder {
	color: var(--sal-muted) !important;
	opacity: 1 !important;
}
#sal-root input::-moz-placeholder,
#sal-root textarea::-moz-placeholder {
	color: var(--sal-muted) !important;
	opacity: 1 !important;
}
/* Force visible input text/background. Themes that do
   `input { color: transparent }` or set bizarre background colors break
   the widget's inputs in non-obvious ways. */
#sal-root input,
#sal-root textarea {
	color: var(--sal-fg);
	background: #fff;
}

#sal-root {
	--sal-accent: #0066ff;
	--sal-accent-fg: #fff;
	--sal-bg: #fff;
	--sal-fg: #111827;
	--sal-muted: #6b7280;
	--sal-border: #e5e7eb;
	--sal-user-bg: var(--sal-accent);
	--sal-user-fg: var(--sal-accent-fg);
	--sal-assistant-bg: #f3f4f6;
	--sal-assistant-fg: #111827;
	--sal-radius: 18px;
	--sal-shadow: 0 12px 32px rgba(0,0,0,.18);
	--sal-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

	position: fixed;
	z-index: 2147483000;
	bottom: 24px;
	font-family: var(--sal-font);
	font-size: 15px;
	line-height: 1.5;
	color: var(--sal-fg);
}
#sal-root[data-position="bottom-right"] { right: 24px; }
#sal-root[data-position="bottom-left"]  { left: 24px; }

/* === Launcher === */
/* Launcher wrap — positioning context for the notification badge so it can
   escape the launcher's overflow:hidden (which crops the optional custom icon
   image to the circular border-radius). The wrap is inline-block so it sizes
   to the launcher; .sal-hidden on the wrap hides the entire unit. */
#sal-root .sal-launcher-wrap {
	position: relative;
	display: inline-block;
	line-height: 0;
}
#sal-root .sal-launcher-wrap.sal-hidden { display: none; }

#sal-root .sal-launcher {
	position: relative;
	width: 64px;
	height: 64px;
	border-radius: 50%;
	border: none;
	background: var(--sal-accent);
	color: var(--sal-accent-fg);
	cursor: pointer;
	box-shadow: var(--sal-shadow);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform .2s ease, box-shadow .2s ease;
	overflow: hidden;
}
#sal-root .sal-launcher:hover {
	transform: scale(1.06);
	box-shadow: 0 16px 40px rgba(0,0,0,.24);
}
#sal-root .sal-launcher svg { width: 30px; height: 30px; }
#sal-root .sal-launcher-img {
	width: 100%; height: 100%; object-fit: cover;
}
/* Pulse on first visit */
@keyframes sal-pulse-ring {
	0%   { box-shadow: 0 0 0 0 var(--sal-accent), var(--sal-shadow); opacity: 1; }
	70%  { box-shadow: 0 0 0 18px rgba(0, 102, 255, 0), var(--sal-shadow); opacity: 1; }
	100% { box-shadow: 0 0 0 0 rgba(0, 102, 255, 0), var(--sal-shadow); }
}
#sal-root .sal-launcher.sal-pulse {
	animation: sal-pulse-ring 2s ease-out 3;
}

/* Notification badge (2.3.3 refresh) — sits on the launcher's edge, scales
   cleanly from a single digit up to "9+". Hidden when empty (the JS doesn't
   append the element at all in that case; this rule is belt-and-braces). */
#sal-root .sal-notification-dot {
	position: absolute;
	top: -2px;
	right: -2px;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	font-weight: 600;
	line-height: 1;
	letter-spacing: -0.02em;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	border-radius: 9px;
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 0 0 2px var(--sal-accent), 0 1px 2px rgba(0,0,0,.15);
	pointer-events: none;
	animation: sal-badge-pop .25s cubic-bezier(.34, 1.56, .64, 1) both;
}
#sal-root .sal-notification-dot:empty { display: none; }

@keyframes sal-badge-pop {
	0%   { transform: scale(0); opacity: 0; }
	60%  { transform: scale(1.15); opacity: 1; }
	100% { transform: scale(1); opacity: 1; }
}

/* === Panel === */
#sal-root .sal-panel {
	position: absolute;
	bottom: 0;
	width: 400px !important;
	max-width: calc(100vw - 32px) !important;
	height: 600px;
	max-height: calc(100vh - 48px);
	background: var(--sal-bg);
	border-radius: var(--sal-radius);
	box-shadow: var(--sal-shadow);
	display: none;
	flex-direction: column;
	overflow: hidden;
	transform-origin: bottom right;
}
#sal-root[data-position="bottom-right"] .sal-panel { right: 0; }
#sal-root[data-position="bottom-left"]  .sal-panel { left: 0; transform-origin: bottom left; }

@keyframes sal-panel-in {
	0%   { opacity: 0; transform: scale(.92) translateY(8px); }
	100% { opacity: 1; transform: scale(1) translateY(0); }
}
#sal-root .sal-panel.sal-open {
	display: flex;
	animation: sal-panel-in .22s cubic-bezier(.4,.0,.2,1);
}

/* Minimized state — collapses to header only.
 *
 * 2.3.5.4: Transition BOTH `height` AND `max-height` together with the
 * same easing + duration, with explicit pixel targets on each state
 * (no `height: auto`).
 *
 * Why the rewrite: earlier builds (2.3.5.1 → 2.3.5.3) transitioned ONLY
 * `max-height` while flipping `height: 600px → auto` on minimize. The
 * `height: auto` resolved instantly to the natural content height
 * (~60px, since `.sal-messages`/`.sal-input-row`/`.sal-footer` are
 * `display: none` when minimized), making `rendered = min(height,
 * max-height) = min(60, animating) = 60` snap to 60px immediately
 * while `max-height` ran its own 280ms animation that produced no
 * visible movement. At the END of that orphaned animation, the browser
 * triggered a final layout reconciliation — visible as a subtle bump
 * right before the pill settled. With explicit pixel heights and both
 * properties on the transition, `min(height, max-height)` evaluates
 * smoothly along a single continuous path from 600px → 60px (and back
 * on expand).
 *
 * 60px is the exact natural header height (14px top padding + 32px
 * avatar + 14px bottom padding). The pill renders compact like the
 * 2.3.0-era Linda/GSK widget. `cursor: pointer` on the entire header
 * advertises the wider click target wired up in widget.js.
 */
#sal-root .sal-panel {
	transition: height .28s cubic-bezier(.4, 0, .2, 1),
	            max-height .28s cubic-bezier(.4, 0, .2, 1);
}
#sal-root .sal-panel.sal-minimized {
	height: 60px;
	max-height: 60px;
}
#sal-root .sal-panel.sal-minimized .sal-header { cursor: pointer; }
#sal-root .sal-panel.sal-minimized .sal-messages,
#sal-root .sal-panel.sal-minimized .sal-input-row,
#sal-root .sal-panel.sal-minimized .sal-footer { display: none; }

/* === Header === */
#sal-root .sal-header {
	background: var(--sal-accent);
	color: var(--sal-accent-fg);
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	flex-shrink: 0;
}
#sal-root .sal-header-title {
	display: flex;
	align-items: center;
	gap: 10px;
	cursor: pointer;
	min-width: 0;
}
#sal-root .sal-header-avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: rgba(255,255,255,.18);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	overflow: hidden;
}
#sal-root .sal-header-avatar img,
#sal-root .sal-header-avatar svg {
	width: 22px; height: 22px;
}
#sal-root .sal-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
#sal-root .sal-title { font-weight: 600; font-size: 16px; }

#sal-root .sal-header-actions {
	display: flex;
	align-items: center;
	gap: 4px;
	flex-shrink: 0;
}
#sal-root .sal-icon-btn {
	background: transparent;
	border: none;
	color: inherit;
	font-size: 16px;
	cursor: pointer;
	width: 30px;
	height: 30px;
	border-radius: 8px;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: .85;
	line-height: 1;
}
#sal-root .sal-icon-btn:hover { background: rgba(255,255,255,.15); opacity: 1; }

/* === Sub-header (persistent action bar with Callback + WhatsApp) === */
#sal-root .sal-subheader {
	display: flex;
	gap: 8px;
	padding: 10px 12px;
	background: #f9fafb;
	border-bottom: 1px solid var(--sal-border);
	flex-shrink: 0;
}
#sal-root .sal-sub-btn {
	flex: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 9px 10px;
	border-radius: 10px;
	border: 1px solid var(--sal-border);
	background: #fff;
	cursor: pointer;
	font: inherit;
	font-size: 13px;
	font-weight: 500;
	color: var(--sal-fg);
	text-decoration: none;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	transition: border-color .15s ease, background .15s ease;
}
#sal-root .sal-sub-btn:hover {
	border-color: var(--sal-accent);
	background: #fff;
}
#sal-root .sal-sub-btn svg { display: block; flex-shrink: 0; }
#sal-root .sal-sub-callback svg { color: var(--sal-accent); }
#sal-root .sal-sub-wa { color: var(--sal-fg); }
#sal-root .sal-sub-wa svg { color: #25d366; }
#sal-root .sal-sub-wa:hover { border-color: #25d366; color: var(--sal-fg); }

/* Hide sub-header in minimized state */
#sal-root .sal-panel.sal-minimized .sal-subheader { display: none; }

/* WhatsApp inline auto-suggest card */
#sal-root .sal-wa-card {
	background: #ecfdf5;
	border: 1px solid #a7f3d0;
	border-radius: 14px;
	padding: 12px;
	margin: 6px 0;
	display: flex;
	gap: 12px;
	align-items: flex-start;
}
#sal-root .sal-wa-icon {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: #25d366;
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
#sal-root .sal-wa-icon svg { width: 18px; height: 18px; }
#sal-root .sal-wa-body { flex: 1; }
#sal-root .sal-wa-title {
	font-weight: 600;
	font-size: 14px;
	color: #065f46;
	margin-bottom: 2px;
}
#sal-root .sal-wa-sub {
	font-size: 13px;
	color: #047857;
	margin-bottom: 10px;
}
#sal-root .sal-wa-actions {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}
#sal-root .sal-wa-go {
	background: #25d366;
	color: #fff;
	border: none;
	border-radius: 8px;
	padding: 8px 14px;
	font: inherit;
	font-weight: 600;
	font-size: 13px;
	text-decoration: none;
	display: inline-block;
}
#sal-root .sal-wa-go:hover { background: #1ebe5d; color: #fff; }
#sal-root .sal-wa-dismiss {
	background: transparent;
	color: #047857;
	border: 1px solid #a7f3d0;
	border-radius: 8px;
	padding: 8px 14px;
	cursor: pointer;
	font: inherit;
	font-size: 13px;
}
#sal-root .sal-wa-dismiss:hover { background: #d1fae5; }

/* === Messages === */
#sal-root .sal-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: #fafafa;
}
#sal-root .sal-msg { display: flex; gap: 8px; }
#sal-root .sal-msg-user { justify-content: flex-end; }
#sal-root .sal-msg-assistant { justify-content: flex-start; align-items: flex-end; }

#sal-root .sal-avatar {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: var(--sal-accent);
	color: var(--sal-accent-fg);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	overflow: hidden;
}
#sal-root .sal-avatar img { width: 100%; height: 100%; object-fit: cover; }
#sal-root .sal-avatar svg { width: 16px; height: 16px; }

#sal-root .sal-bubble {
	max-width: 80%;
	padding: 10px 14px;
	border-radius: 14px;
	word-wrap: break-word;
	overflow-wrap: break-word;
}
#sal-root .sal-msg-user .sal-bubble {
	background: var(--sal-user-bg);
	color: var(--sal-user-fg);
	border-bottom-right-radius: 4px;
}
#sal-root .sal-msg-assistant .sal-bubble {
	background: var(--sal-assistant-bg);
	color: var(--sal-assistant-fg);
	border-bottom-left-radius: 4px;
}
#sal-root .sal-bubble p { margin: 0 0 8px 0; }
#sal-root .sal-bubble p:last-child { margin-bottom: 0; }
#sal-root .sal-bubble a { color: inherit; text-decoration: underline; }
#sal-root .sal-bubble code {
	background: rgba(0,0,0,.08);
	padding: 1px 5px;
	border-radius: 4px;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: .9em;
}
#sal-root .sal-msg-user .sal-bubble code { background: rgba(255,255,255,.2); }
#sal-root .sal-bubble ul { padding-left: 20px; margin: 6px 0; }
#sal-root .sal-bubble li { margin-bottom: 2px; }
#sal-root .sal-error { color: #b91c1c; font-style: normal; }

/* Typing */
#sal-root .sal-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
#sal-root .sal-typing span {
	width: 7px; height: 7px; border-radius: 50%;
	background: var(--sal-muted);
	animation: sal-bounce 1.2s infinite ease-in-out;
}
#sal-root .sal-typing span:nth-child(2) { animation-delay: .15s; }
#sal-root .sal-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes sal-bounce {
	0%, 80%, 100% { transform: translateY(0); opacity: .4; }
	40%           { transform: translateY(-5px); opacity: 1; }
}

/* === Lead capture card === */
#sal-root .sal-lead-card {
	background: #fff;
	border: 1px solid var(--sal-border);
	border-radius: 14px;
	padding: 14px;
	margin: 6px 0;
	display: flex;
	flex-direction: column;
	gap: 8px;
}
#sal-root .sal-lead-title { font-weight: 600; font-size: 14px; }
#sal-root .sal-lead-sub { font-size: 13px; color: var(--sal-muted); margin-bottom: 4px; }
#sal-root .sal-lead-card input {
	width: 100%;
	min-height: 36px !important;
	min-width: 0 !important;
	max-width: none;
	border: 1px solid var(--sal-border);
	border-radius: 8px;
	padding: 8px 10px;
	font: inherit;
	font-size: 14px;
	outline: none;
	box-shadow: none;
	appearance: none;
	-webkit-appearance: none;
}
#sal-root .sal-lead-card input:focus { border-color: var(--sal-accent); }
#sal-root .sal-lead-phone-row {
	display: flex;
	gap: 6px;
	position: relative; /* anchor for the absolute dropdown panel */
}
#sal-root .sal-lead-phone-row .sal-lead-phone { flex: 1 1 auto; min-width: 0; }

/* Custom country dropdown */
#sal-root .sal-cc-wrap {
	position: relative;
	flex: 0 0 auto;
	width: 160px;
}
#sal-root .sal-cc-button {
	width: 100%;
	border: 1px solid var(--sal-border);
	border-radius: 8px;
	padding: 8px 8px;
	font: inherit;
	font-size: 13px;
	background: #fff;
	text-align: left;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 4px;
	color: inherit;
}
#sal-root .sal-cc-button:focus { border-color: var(--sal-accent); outline: none; }
#sal-root .sal-cc-current {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	flex: 1 1 auto;
	min-width: 0;
}
#sal-root .sal-cc-arrow { color: #9ca3af; flex-shrink: 0; font-size: 11px; }
#sal-root .sal-cc-panel {
	position: absolute;
	top: calc(100% + 4px);
	left: 0;
	width: 260px;
	max-width: calc(100vw - 32px);
	z-index: 100;
	background: #fff;
	border: 1px solid var(--sal-border);
	border-radius: 8px;
	box-shadow: 0 6px 16px rgba(0,0,0,0.12);
	overflow: hidden;
}
#sal-root .sal-cc-panel[hidden] { display: none !important; }
#sal-root .sal-cc-search {
	width: 100%;
	border: none;
	border-bottom: 1px solid var(--sal-border);
	padding: 8px 10px;
	font: inherit;
	font-size: 13px;
	outline: none;
	box-sizing: border-box;
	border-radius: 0;
}
#sal-root .sal-cc-list {
	max-height: 220px;
	overflow-y: auto;
	margin: 0;
	padding: 4px 0;
	list-style: none;
}
#sal-root .sal-cc-item {
	padding: 6px 10px;
	cursor: pointer;
	font-size: 13px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
#sal-root .sal-cc-item.sal-cc-highlighted { background: #f3f4f6; }
#sal-root .sal-cc-empty {
	padding: 12px 10px;
	color: var(--sal-muted);
	font-size: 13px;
	font-style: italic;
	list-style: none;
}
#sal-root .sal-lead-actions { display: flex; gap: 8px; margin-top: 4px; }
#sal-root .sal-lead-submit {
	background: var(--sal-accent); color: var(--sal-accent-fg);
	border: none; border-radius: 8px; padding: 8px 14px;
	cursor: pointer; font: inherit; font-weight: 600;
}
#sal-root .sal-lead-dismiss {
	background: transparent; color: var(--sal-muted);
	border: 1px solid var(--sal-border); border-radius: 8px;
	padding: 8px 14px; cursor: pointer; font: inherit;
}
#sal-root .sal-lead-status { font-size: 12px; min-height: 16px; }
#sal-root .sal-lead-success {
	color: #047857;
	font-weight: 600;
	text-align: center;
	padding: 8px;
}

/* === Input === */
#sal-root .sal-input-row {
	display: flex !important;
	flex-direction: row !important;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	background: var(--sal-bg);
	border-top: 1px solid var(--sal-border);
	flex-shrink: 0;
	width: auto;
	max-width: none;
}
#sal-root .sal-input {
	flex: 1 1 auto;
	/* Theme overrides like `textarea { min-height: 100px }` or
	   `width: 100% !important` would otherwise inflate this.
	   height: auto !important fights themes that hard-pin
	   `textarea { height: 200px !important }`. Pairs with the
	   widget.js autosize, which uses setProperty('height', X,
	   'important') so inline-with-important can still win over
	   external-with-important when the user types. */
	min-width: 0 !important;
	min-height: 36px !important;
	width: auto;
	max-width: none;
	height: auto !important;
	line-height: 1.5 !important;
	resize: none;
	border: 1px solid var(--sal-border);
	border-radius: 12px;
	padding: 10px 12px;
	font: inherit;
	color: inherit;
	background: #fff;
	max-height: 120px !important;
	outline: none;
	appearance: none;
	-webkit-appearance: none;
}
#sal-root .sal-input:focus { border-color: var(--sal-accent); }
#sal-root .sal-input:disabled { opacity: .6; cursor: not-allowed; }

#sal-root .sal-send {
	width: 40px !important;
	height: 40px !important;
	min-width: 40px !important;
	flex: 0 0 40px;
	border-radius: 10px;
	border: none;
	background: var(--sal-accent);
	color: var(--sal-accent-fg);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity .15s ease;
	padding: 0;
}
#sal-root .sal-send:disabled { opacity: .5; cursor: not-allowed; }
#sal-root .sal-send.sal-loading svg { animation: sal-spin 1s linear infinite; }
@keyframes sal-spin { to { transform: rotate(360deg); } }

#sal-root .sal-footer {
	font-size: 11px;
	color: var(--sal-muted);
	text-align: center;
	padding: 6px;
	background: var(--sal-bg);
	flex-shrink: 0;
}
#sal-root .sal-footer a {
	color: var(--sal-muted);
	text-decoration: none;
	font-weight: 600;
}
#sal-root .sal-footer a:hover {
	color: var(--sal-fg);
	text-decoration: underline;
}

/* Mobile */
@media (max-width: 480px) {
	#sal-root[data-position="bottom-right"],
	#sal-root[data-position="bottom-left"] {
		bottom: 16px;
		right: 16px;
		left: auto;
	}
	#sal-root .sal-panel {
		width: calc(100vw - 32px);
		height: calc(100vh - 100px);
		right: 0 !important;
		left: auto !important;
	}
}
