/*
 * WooCommerce Store Chatbot v2 — namespaced frontend styles.
 * All values controlled by CSS custom properties injected from PHP (wp_head).
 */

/* ============================================================
   Token defaults (overridden at :root from PHP admin settings)
   ============================================================ */
:root {
	--wcsc-primary:      #0071a1;
	--wcsc-user-bubble:  #e9ecef;
	--wcsc-bg:           #f0f4f8;
	--wcsc-surface:      #ffffff;
	--wcsc-border:       #e2e8f0;
	--wcsc-text:         #1a202c;
	--wcsc-text-muted:   #718096;
	--wcsc-shadow:         0 12px 40px rgba(0,0,0,.18);
	--wcsc-bubble-text:    #ffffff;
	--wcsc-font-weight:    400;
	--wcsc-line-height:    1.55;
	--wcsc-letter-spacing: 0;
	--wcsc-panel-width:  350px;
	--wcsc-msg-height:   340px;
	--wcsc-radius:       18px;
	--wcsc-font-size:    14px;
	--wcsc-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	--wcsc-z:            99999;
}

/* ============================================================
   Box-model isolation — prevents Elementor from bleeding in
   ============================================================ */
.wcsc-chatbot,
.wcsc-chatbot *,
.wcsc-chatbot *::before,
.wcsc-chatbot *::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

/* ============================================================
   Root containers
   ============================================================ */
.wcsc-chatbot--floating {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: var(--wcsc-z);
	font-family: var(--wcsc-font);
	font-size: var(--wcsc-font-size);
	font-weight: var(--wcsc-font-weight);
	line-height: var(--wcsc-line-height);
	letter-spacing: var(--wcsc-letter-spacing);
}

.wcsc-chatbot--inline,
.wcsc-chatbot--embedded {
	position: relative;
	z-index: 1;
	font-family: var(--wcsc-font);
	font-size: var(--wcsc-font-size);
	font-weight: var(--wcsc-font-weight);
	line-height: var(--wcsc-line-height);
	letter-spacing: var(--wcsc-letter-spacing);
	width: 100%;
}

/* ============================================================
   Toggle button
   ============================================================ */
.wcsc-chatbot__toggle-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 58px;
	height: 58px;
	border-radius: 50%;
	background: var(--wcsc-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	box-shadow: 0 4px 18px rgba(0,0,0,.28);
	transition: transform .2s ease, box-shadow .2s ease;
	outline: none;
	-webkit-tap-highlight-color: transparent;
}

.wcsc-chatbot__toggle-btn:hover {
	transform: scale(1.08);
	box-shadow: 0 6px 24px rgba(0,0,0,.34);
}

.wcsc-chatbot__toggle-btn:focus-visible {
	outline: 3px solid var(--wcsc-primary);
	outline-offset: 3px;
}

.wcsc-chatbot__toggle-btn svg {
	width: 26px;
	height: 26px;
	fill: currentColor;
	pointer-events: none;
}

/* ============================================================
   Panel — width from admin, radius from admin
   ============================================================ */
.wcsc-chatbot__panel {
	display: flex;
	flex-direction: column;
	background: var(--wcsc-surface);
	border-radius: var(--wcsc-radius);
	box-shadow: var(--wcsc-shadow);
	overflow: hidden;
}

/* Floating: positioned above the toggle button */
.wcsc-chatbot--floating .wcsc-chatbot__panel {
	position: absolute;
	bottom: 70px;
	right: 0;
	width: var(--wcsc-panel-width);
	max-width: calc(100vw - 28px);
	/* Cap total panel height so it never leaves the viewport */
	max-height: calc(100vh - 110px);
}

/* Inline: full container width */
.wcsc-chatbot--inline .wcsc-chatbot__panel,
.wcsc-chatbot--embedded .wcsc-chatbot__panel {
	position: relative;
	width: 100%;
	box-shadow: 0 2px 16px rgba(0,0,0,.10);
}

/* !important is intentional — [hidden] must always win over any display rule */
.wcsc-chatbot__panel[hidden] { display: none !important; }

/* Panel entrance / exit animations */
.wcsc-chatbot__panel--enter {
	animation: wcsc-in .24s cubic-bezier(.34,1.56,.64,1) forwards;
}

.wcsc-chatbot__panel--exit {
	animation: wcsc-out .18s ease forwards;
}

@keyframes wcsc-in {
	from { opacity:0; transform:translateY(14px) scale(.96); }
	to   { opacity:1; transform:translateY(0) scale(1); }
}

@keyframes wcsc-out {
	from { opacity:1; transform:translateY(0) scale(1); }
	to   { opacity:0; transform:translateY(10px) scale(.97); }
}

/* ============================================================
   Header
   ============================================================ */
.wcsc-chatbot__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 13px 15px;
	background: var(--wcsc-primary);
	color: #fff;
	flex-shrink: 0;
	gap: 8px;
}

.wcsc-chatbot__header-info {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
}

.wcsc-chatbot__avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: rgba(255,255,255,.2);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	overflow: hidden;
}

.wcsc-chatbot__avatar svg { width:18px; height:18px; fill:#fff; }

/* Site icon avatar */
.wcsc-chatbot__avatar img {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	object-fit: cover;
	display: block;
}

/* Text / initials avatar */
.wcsc-chatbot__avatar--text {
	font-size: .72em;
	font-weight: 700;
	color: #fff;
	letter-spacing: .04em;
	line-height: 1;
}

.wcsc-chatbot__bot-name {
	font-weight: 700;
	font-size: 1em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.wcsc-chatbot__status {
	font-size: .8em;
	opacity: .8;
	display: flex;
	align-items: center;
	gap: 4px;
}

.wcsc-chatbot__status::before {
	content: '';
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #4ade80;
	display: inline-block;
	flex-shrink: 0;
}

.wcsc-chatbot__close-btn {
	background: transparent;
	border: none;
	color: #fff;
	cursor: pointer;
	padding: 4px;
	border-radius: 6px;
	opacity: .75;
	transition: opacity .15s;
	line-height: 1;
	flex-shrink: 0;
}

.wcsc-chatbot__close-btn:hover { opacity:1; }

.wcsc-chatbot__close-btn svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	display: block;
}

/* ============================================================
   Messages area — fixed height so overflow-y scroll always works.
   Using a hard height (not flex:1 + max-height) is the only
   approach that works reliably across all browsers / panel types.
   ============================================================ */
.wcsc-chatbot__messages {
	height: var(--wcsc-msg-height);  /* hard fixed height — scroll triggers automatically */
	flex-shrink: 0;                  /* flex parent must not compress this */
	overflow-y: auto;
	overflow-x: hidden;
	padding: 14px 12px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--wcsc-bg);
	scroll-behavior: smooth;
	overscroll-behavior: contain;
}

.wcsc-chatbot__messages::-webkit-scrollbar       { width: 4px; }
.wcsc-chatbot__messages::-webkit-scrollbar-track  { background: transparent; }
.wcsc-chatbot__messages::-webkit-scrollbar-thumb  { background:rgba(0,0,0,.12); border-radius:4px; }

/* ---- Message rows ---- */
.wcsc-chatbot__msg {
	display: flex;
	align-items: flex-end;
	gap: 6px;
	max-width: 92%;
	animation: wcsc-msg .18s ease;
}

@keyframes wcsc-msg {
	from { opacity:0; transform:translateY(5px); }
	to   { opacity:1; transform:translateY(0); }
}

.wcsc-chatbot__msg--bot  { align-self: flex-start; }
.wcsc-chatbot__msg--user { align-self: flex-end; flex-direction: row-reverse; }

/* ---- Bubbles ---- */
.wcsc-chatbot__bubble {
	padding: 10px 14px;
	border-radius: 18px;
	font-size: 1em;
	line-height: 1.55;
	word-break: break-word;
}

.wcsc-chatbot__msg--bot .wcsc-chatbot__bubble {
	background: var(--wcsc-primary);
	color: var(--wcsc-bubble-text);
	border-bottom-left-radius: 4px;
}

.wcsc-chatbot__msg--bot .wcsc-chatbot__bubble a { color: var(--wcsc-bubble-text); text-decoration:underline; }

.wcsc-chatbot__msg--user .wcsc-chatbot__bubble {
	background: var(--wcsc-user-bubble);
	color: var(--wcsc-text);
	border-bottom-right-radius: 4px;
}

/* ============================================================
   Product cards — standalone, outside the bot bubble
   ============================================================ */

/* Container that holds all cards for one response */
.wcsc-product-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
	align-self: flex-start;
	width: 100%;
	max-width: 96%;
	animation: wcsc-msg .2s ease;
}

/* Individual product card */
.wcsc-card {
	display: flex;
	align-items: center;
	gap: 12px;
	background: var(--wcsc-surface);
	border: 1px solid var(--wcsc-border);
	border-radius: 12px;
	padding: 10px 12px;
	box-shadow: 0 1px 5px rgba(0,0,0,.06);
	transition: box-shadow .15s, transform .12s;
	text-decoration: none;
}

.wcsc-card:hover {
	box-shadow: 0 4px 16px rgba(0,0,0,.11);
	transform: translateY(-1px);
}

.wcsc-card__img {
	width: 54px;
	height: 54px;
	border-radius: 8px;
	object-fit: cover;
	flex-shrink: 0;
	background: var(--wcsc-bg);
	display: block;
}

.wcsc-card__body {
	flex: 1;
	min-width: 0;
}

.wcsc-card__name {
	display: block;
	color: var(--wcsc-text);
	font-weight: 600;
	font-size: .93em;
	text-decoration: none;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	margin-bottom: 2px;
}

.wcsc-card__name:hover { color: var(--wcsc-primary); }

.wcsc-card__price {
	display: block;
	color: var(--wcsc-text-muted);
	font-size: .88em;
}

.wcsc-card__price del { opacity: .6; margin-right: 3px; }
.wcsc-card__price ins { text-decoration:none; color: var(--wcsc-primary); font-weight: 600; }

.wcsc-card__btn {
	display: inline-flex;
	align-items: center;
	background: var(--wcsc-primary);
	color: #fff !important;
	padding: 5px 13px;
	border-radius: 20px;
	font-size: .82em;
	font-weight: 600;
	text-decoration: none !important;
	white-space: nowrap;
	flex-shrink: 0;
	transition: opacity .15s;
}

.wcsc-card__btn:hover { opacity: .85; }

/* ============================================================
   Action buttons — links rendered as pills in bot bubbles
   ============================================================ */
.wcsc-btn-group {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 10px;
}

.wcsc-chatbot__bubble .wcsc-action-btn {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: rgba(255,255,255,.22);
	color: #fff !important;
	padding: 6px 14px;
	border-radius: 20px;
	font-size: .9em;
	font-weight: 600;
	text-decoration: none !important;
	border: 1px solid rgba(255,255,255,.3);
	transition: background .15s, transform .1s;
	margin-top: 6px;
	margin-right: 4px;
	white-space: nowrap;
	-webkit-tap-highlight-color: transparent;
}

.wcsc-chatbot__bubble .wcsc-action-btn:hover {
	background: rgba(255,255,255,.38);
	transform: translateY(-1px);
}

.wcsc-btn-group .wcsc-action-btn { margin-top: 0; margin-right: 0; }

/* ============================================================
   Quick-reply chips
   ============================================================ */
.wcsc-quick-replies {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 10px;
}

.wcsc-quick-reply {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: rgba(255,255,255,.18);
	border: 1px solid rgba(255,255,255,.3);
	color: #fff;
	padding: 5px 12px;
	border-radius: 20px;
	font-size: .86em;
	font-weight: 500;
	cursor: pointer;
	transition: background .15s;
	-webkit-tap-highlight-color: transparent;
	white-space: nowrap;
}

.wcsc-quick-reply:hover { background:rgba(255,255,255,.32); }

/* ============================================================
   Typing indicator
   ============================================================ */
.wcsc-chatbot__typing {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 11px 14px;
	background: var(--wcsc-primary);
	border-radius: 18px;
	border-bottom-left-radius: 4px;
	width: fit-content;
}

.wcsc-chatbot__typing span {
	width: 7px;
	height: 7px;
	background: rgba(255,255,255,.7);
	border-radius: 50%;
	display: inline-block;
	animation: wcsc-bounce 1.2s infinite ease-in-out;
}

.wcsc-chatbot__typing span:nth-child(2) { animation-delay:.2s; }
.wcsc-chatbot__typing span:nth-child(3) { animation-delay:.4s; }

@keyframes wcsc-bounce {
	0%,80%,100% { transform:scale(.65); opacity:.45; }
	40%         { transform:scale(1);   opacity:1; }
}

/* ============================================================
   Input row
   ============================================================ */
.wcsc-chatbot__footer {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--wcsc-border);
	background: var(--wcsc-surface);
	flex-shrink: 0;
}

.wcsc-chatbot__input {
	flex: 1;
	min-width: 0;
	border: 1.5px solid var(--wcsc-border);
	border-radius: 22px;
	padding: 8px 14px;
	font-size: 1em;
	font-family: var(--wcsc-font);
	outline: none;
	background: var(--wcsc-bg);
	color: var(--wcsc-text);
	transition: border-color .15s, background .15s;
	height: 40px;
	line-height: 1.4;
}

.wcsc-chatbot__input:focus {
	border-color: var(--wcsc-primary);
	background: var(--wcsc-surface);
}

.wcsc-chatbot__input::placeholder { color: var(--wcsc-text-muted); }

/* Menu / back-to-menu button (left side of footer) */
.wcsc-chatbot__menu-btn {
	width: 36px;
	height: 36px;
	flex-shrink: 0;
	border: 1.5px solid var(--wcsc-border);
	border-radius: 50%;
	background: var(--wcsc-surface);
	color: var(--wcsc-primary);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background .15s, border-color .15s, transform .12s;
	padding: 0;
	outline: none;
	-webkit-tap-highlight-color: transparent;
}

.wcsc-chatbot__menu-btn:hover {
	background: var(--wcsc-bg);
	border-color: var(--wcsc-primary);
	transform: scale(1.08);
}

.wcsc-chatbot__menu-btn:focus-visible {
	outline: 3px solid var(--wcsc-primary);
	outline-offset: 2px;
}

.wcsc-chatbot__menu-btn svg {
	width: 15px;
	height: 15px;
	fill: currentColor;
	pointer-events: none;
}

.wcsc-chatbot__send-btn {
	width: 40px;
	height: 40px;
	flex-shrink: 0;
	border: none;
	border-radius: 50%;
	background: var(--wcsc-primary);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity .15s, transform .12s;
	padding: 0;
}

.wcsc-chatbot__send-btn:hover:not(:disabled) { opacity:.88; transform:scale(1.07); }
.wcsc-chatbot__send-btn:disabled { opacity:.35; cursor:not-allowed; transform:none; }
.wcsc-chatbot__send-btn:focus-visible { outline:3px solid var(--wcsc-primary); outline-offset:2px; }
.wcsc-chatbot__send-btn svg { width:17px; height:17px; fill:currentColor; pointer-events:none; }

/* ============================================================
   Resume chip — appears below the toggle btn after first conversation
   ============================================================ */
.wcsc-chatbot__resume-chip {
	position: absolute;
	top: calc(100% + 8px);   /* just below the 58 px toggle circle */
	right: 0;
	display: flex;
	align-items: center;
	gap: 6px;
	background: #fff;
	border: 1.5px solid var(--wcsc-border);
	border-radius: 20px;
	padding: 6px 14px 6px 10px;
	font-size: 12px;
	font-weight: 600;
	color: var(--wcsc-primary);
	white-space: nowrap;
	box-shadow: 0 3px 14px rgba(0,0,0,.13);
	cursor: pointer;
	animation: wcsc-in .22s cubic-bezier(.34,1.56,.64,1);
	-webkit-tap-highlight-color: transparent;
	user-select: none;
	transition: box-shadow .15s, transform .12s;
	/* font family inherits from the floating root */
}

.wcsc-chatbot__resume-chip:hover {
	box-shadow: 0 5px 20px rgba(0,0,0,.18);
	transform: translateY(-1px);
}

.wcsc-chatbot__resume-chip[hidden] { display: none !important; }

.wcsc-chatbot__resume-chip__dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4ade80;
	flex-shrink: 0;
	display: inline-block;
	box-shadow: 0 0 0 2px rgba(74,222,128,.3);
}

/* ============================================================
   Disabled links in past bot messages
   ============================================================ */
.wcsc-link--disabled {
	pointer-events: none !important;
	cursor: default !important;
	opacity: 0.45 !important;
	text-decoration: line-through !important;
}

/* Product "View" buttons in past cards — fade but no strikethrough */
.wcsc-link--disabled.wcsc-card__btn,
.wcsc-product-list .wcsc-link--disabled {
	text-decoration: none !important;
	opacity: 0.35 !important;
}

/* Quick-reply chips in past welcome / bot turns */
.wcsc-link--disabled.wcsc-quick-reply {
	text-decoration: none !important;
	opacity: 0.35 !important;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 640px) {
	.wcsc-chatbot--floating .wcsc-chatbot__panel {
		width: min(var(--wcsc-panel-width), calc(100vw - 28px));
	}
}

@media (max-width: 500px) {
	.wcsc-chatbot--floating {
		bottom: 16px;
	}

	.wcsc-chatbot--floating .wcsc-chatbot__panel {
		position: fixed;
		bottom: 84px;
		left: 10px;
		right: 10px;
		width: auto;
		max-width: none;
		border-radius: calc(var(--wcsc-radius) * 0.85);
		max-height: calc(100dvh - 110px);
		/* display: flex is already set by the base rule — do NOT repeat it
		   here because it would override display:none from [hidden] */
	}

	.wcsc-chatbot--floating .wcsc-chatbot__messages {
		/* On mobile the panel is fixed-height (100dvh - 110px), so let
		   messages fill remaining space instead of the desktop fixed height */
		height: auto;
		flex: 1;
		min-height: 0;
		min-height: 120px;
	}

	.wcsc-chatbot__input  { height: 44px; font-size: 16px; }
	.wcsc-chatbot__send-btn { width:44px; height:44px; }
	.wcsc-quick-reply     { padding: 7px 14px; font-size: .9em; }
}

@media (max-width: 360px) {
	.wcsc-chatbot--floating {
		bottom: 12px;
		right: 12px;
	}

	.wcsc-chatbot--floating .wcsc-chatbot__panel {
		left: 6px;
		right: 6px;
		bottom: 78px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.wcsc-chatbot__panel--enter,
	.wcsc-chatbot__panel--exit,
	.wcsc-chatbot__msg,
	.wcsc-product-list,
	.wcsc-chatbot__typing span { animation: none; }
}
