/* =========================================================
   WP AI Haggle Bot — Frontend Chat UI  v2.1
   Theme-agnostic isolation + premium polish
   Only class/id names that already exist in chat-widget.php
   ========================================================= */

/* ── CSS Variables ── */
:root {
	--hg-primary:      #2563eb;
	--hg-primary-dk:   #1d4ed8;
	--hg-primary-lt:   #eff6ff;
	--hg-green:        #16a34a;
	--hg-green-dk:     #15803d;
	--hg-bg:           #ffffff;
	--hg-surface:      #f8fafc;
	--hg-border:       #e2e8f0;
	--hg-text:         #0f172a;
	--hg-muted:        #64748b;
	--hg-bot-bubble:   #f1f5f9;
	--hg-radius:       14px;
	--hg-radius-sm:    10px;
	--hg-shadow:       0 8px 32px rgba(0,0,0,.12), 0 1px 4px rgba(0,0,0,.06);
	--hg-transition:   0.24s cubic-bezier(0.4,0,0.2,1);
}

/* ══════════════════════════════════════════════
   OPEN BUTTON
   Scoped to .haggle-open-btn so theme won't override
══════════════════════════════════════════════ */
.haggle-button-wrap {
	margin-top: 12px;
	width: 100%;
}

.haggle-open-btn {
	display: inline-flex !important;
	align-items: center !important;
	gap: 9px !important;
	width: 100% !important;
	justify-content: center !important;
	padding: 13px 22px !important;
	background: var(--hg-primary) !important;
	color: #fff !important;
	border: none !important;
	border-radius: var(--hg-radius-sm) !important;
	font-size: 14.5px !important;
	font-weight: 700 !important;
	cursor: pointer !important;
	letter-spacing: 0.02em !important;
	transition: background var(--hg-transition), transform 0.15s, box-shadow 0.15s !important;
	box-shadow: 0 2px 10px rgba(37,99,235,.28) !important;
	font-family: inherit !important;
	line-height: 1.3 !important;
	text-decoration: none !important;
}

.haggle-open-btn:hover {
	background: var(--hg-primary-dk) !important;
	transform: translateY(-1px) !important;
	box-shadow: 0 6px 20px rgba(37,99,235,.32) !important;
}
.haggle-open-btn:active { transform: translateY(0) !important; }

.haggle-btn-icon  { font-size: 17px; line-height: 1; }
.haggle-btn-arrow { margin-left: auto; font-size: 18px; line-height: 1; transition: transform var(--hg-transition); }
.haggle-open-btn.haggle-btn-active .haggle-btn-arrow { transform: rotate(90deg); }

/* ══════════════════════════════════════════════
   INLINE PANEL — slide-down animation
══════════════════════════════════════════════ */
.haggle-inline-panel {
	overflow: hidden;
	max-height: 0;
	opacity: 0;
	transition: max-height 0.44s cubic-bezier(0.4,0,0.2,1),
	            opacity 0.28s ease,
	            margin-top 0.28s ease;
	margin-top: 0;
}
.haggle-inline-panel.haggle-panel-open {
	max-height: 620px;
	opacity: 1;
	margin-top: 10px;
}

/* ══════════════════════════════════════════════
   WIDGET SHELL
   Full reset so ANY theme's CSS can't leak in
══════════════════════════════════════════════ */
.haggle-widget {
	all: initial;          /* nuclear reset */
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	background: var(--hg-bg);
	border: 1.5px solid var(--hg-border);
	border-radius: var(--hg-radius);
	box-shadow: var(--hg-shadow);
	overflow: hidden;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
	font-size: 14px;
	color: var(--hg-text);
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

/* Restore box-sizing for every child */
.haggle-widget *,
.haggle-widget *::before,
.haggle-widget *::after {
	box-sizing: border-box;
	font-family: inherit;
}

/* ══════════════════════════════════════════════
   HEADER
══════════════════════════════════════════════ */
.haggle-inline-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 13px 16px;
	background: linear-gradient(135deg, #1e40af 0%, #2563eb 60%, #3b82f6 100%);
	color: #fff;
	flex-shrink: 0;
	position: relative;
	overflow: hidden;
}
/* subtle gloss */
.haggle-inline-header::after {
	content: '';
	position: absolute;
	inset: 0;
	background: linear-gradient(180deg, rgba(255,255,255,.07) 0%, transparent 60%);
	pointer-events: none;
}

.haggle-inline-header-left {
	display: flex;
	align-items: center;
	gap: 11px;
}

.haggle-inline-avatar {
	width: 38px;
	height: 38px;
	background: rgba(255,255,255,.18);
	border: 2px solid rgba(255,255,255,.25);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 18px;
	flex-shrink: 0;
}

.haggle-inline-title-wrap { display: flex; flex-direction: column; }

.haggle-inline-title {
	display: block;
	font-size: 14px;
	font-weight: 700;
	color: #fff;
	line-height: 1.2;
}

.haggle-inline-subtitle {
	display: flex;
	align-items: center;
	gap: 5px;
	font-size: 11px;
	color: rgba(255,255,255,.82);
	margin-top: 2px;
}

.haggle-status-dot {
	width: 7px;
	height: 7px;
	background: #4ade80;
	border-radius: 50%;
	display: inline-block;
	flex-shrink: 0;
	animation: haggle-pulse 2.4s ease infinite;
}
@keyframes haggle-pulse {
	0%,100% { opacity:1; box-shadow: 0 0 0 0 rgba(74,222,128,.5); }
	50%      { opacity:.7; box-shadow: 0 0 0 4px rgba(74,222,128,0); }
}

.haggle-inline-header-right {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-shrink: 0;
}

.haggle-ai-badge {
	background: rgba(255,255,255,.2);
	border: 1px solid rgba(255,255,255,.3);
	color: #fff;
	font-size: 10px;
	font-weight: 700;
	padding: 3px 8px;
	border-radius: 20px;
	letter-spacing: .04em;
}

/* Timer */
.haggle-timer-wrap {
	display: flex;
	align-items: center;
	gap: 4px;
	background: rgba(255,255,255,.15);
	border-radius: 20px;
	padding: 4px 10px;
	font-size: 12px;
	font-weight: 700;
	color: #fff;
}
.haggle-countdown { font-variant-numeric: tabular-nums; letter-spacing: .04em; }

/* Close Button */
.haggle-close-btn {
	all: unset;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: rgba(255,255,255,.15);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background var(--hg-transition);
	flex-shrink: 0;
}
.haggle-close-btn:hover { background: rgba(255,255,255,.3); }

/* ══════════════════════════════════════════════
   PRODUCT STRIP
══════════════════════════════════════════════ */
.haggle-product-strip {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 9px 16px;
	background: #f0f4ff;
	border-bottom: 1px solid #dde8ff;
	gap: 8px;
	flex-shrink: 0;
}
.haggle-product-strip-name {
	font-size: 12px;
	font-weight: 600;
	color: var(--hg-text);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 62%;
}
.haggle-product-strip-price {
	font-size: 12px;
	color: var(--hg-muted);
	white-space: nowrap;
}
.haggle-product-strip-price del { color: #94a3b8; margin-right: 4px; }
.haggle-product-strip-price ins { color: var(--hg-green); font-weight: 700; text-decoration: none; }
/* WC price inside strip */
.haggle-product-strip-price .woocommerce-Price-amount { font-size: 12px !important; }

/* ══════════════════════════════════════════════
   MESSAGES
══════════════════════════════════════════════ */
.haggle-messages {
	flex: 1;
	overflow-y: auto;
	padding: 14px 14px 8px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-height: 240px;
	scroll-behavior: smooth;
	background: #fff;
}
.haggle-messages::-webkit-scrollbar { width: 4px; }
.haggle-messages::-webkit-scrollbar-thumb { background: var(--hg-border); border-radius: 4px; }

.haggle-msg {
	display: flex;
	flex-direction: column;
	animation: haggle-msg-in .22s ease;
}
@keyframes haggle-msg-in {
	from { opacity:0; transform: translateY(7px); }
	to   { opacity:1; transform: translateY(0); }
}
.haggle-msg-bot  { align-items: flex-start; }
.haggle-msg-user { align-items: flex-end; }

.haggle-msg-bubble {
	max-width: 82%;
	padding: 9px 13px;
	border-radius: 14px;
	line-height: 1.55;
	font-size: 13.5px;
	word-break: break-word;
}
.haggle-msg-bot .haggle-msg-bubble {
	background: var(--hg-bot-bubble);
	color: var(--hg-text);
	border-bottom-left-radius: 3px;
	border: 1px solid #e8edf4;
}
.haggle-msg-user .haggle-msg-bubble {
	background: var(--hg-primary);
	color: #fff;
	border-bottom-right-radius: 3px;
}
.haggle-msg-meta {
	font-size: 10px;
	color: #94a3b8;
	margin-top: 3px;
	padding: 0 2px;
}
.haggle-msg-user .haggle-msg-meta { text-align: right; }

/* ══════════════════════════════════════════════
   TYPING INDICATOR
══════════════════════════════════════════════ */
.haggle-typing { padding: 6px 16px 4px; flex-shrink: 0; }

.haggle-typing-bubble {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	background: var(--hg-bot-bubble);
	border: 1px solid #e8edf4;
	padding: 9px 13px;
	border-radius: 14px;
	border-bottom-left-radius: 3px;
}
.haggle-typing-bubble span {
	width: 7px;
	height: 7px;
	background: #94a3b8;
	border-radius: 50%;
	animation: haggle-bounce 1.2s infinite;
	display: block;
}
.haggle-typing-bubble span:nth-child(2) { animation-delay: .2s; }
.haggle-typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes haggle-bounce {
	0%,60%,100% { transform: translateY(0); }
	30%         { transform: translateY(-6px); }
}

/* ══════════════════════════════════════════════
   QUICK OFFER CHIPS
══════════════════════════════════════════════ */
.haggle-quick-offers {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
	padding: 8px 14px 0;
}
.haggle-quick-chip {
	all: unset;
	display: inline-block;
	background: var(--hg-primary-lt);
	border: 1.5px solid #bfdbfe;
	color: var(--hg-primary);
	font-size: 12px;
	font-weight: 600;
	padding: 5px 12px;
	border-radius: 20px;
	cursor: pointer;
	transition: background .15s, transform .12s;
}
.haggle-quick-chip:hover { background: #dbeafe; transform: translateY(-1px); }

/* ══════════════════════════════════════════════
   INPUT AREA
══════════════════════════════════════════════ */
.haggle-input-area {
	border-top: 1px solid var(--hg-border);
	background: #fff;
	flex-shrink: 0;
}
.haggle-input-row {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px 12px;
}
.haggle-input-field-wrap {
	flex: 1;
	display: flex;
	align-items: center;
	background: var(--hg-surface);
	border: 1.5px solid var(--hg-border);
	border-radius: var(--hg-radius-sm);
	padding: 0 12px;
	transition: border-color .18s, box-shadow .18s;
	min-width: 0;
}
.haggle-input-field-wrap:focus-within {
	border-color: var(--hg-primary);
	box-shadow: 0 0 0 3px rgba(37,99,235,.10);
	background: #fff;
}
.haggle-currency {
	color: var(--hg-muted);
	font-size: 14px;
	font-weight: 700;
	margin-right: 5px;
	user-select: none;
	flex-shrink: 0;
	white-space: nowrap;
}

/* Input — heavy isolation */
input.haggle-offer-input,
.haggle-widget input.haggle-offer-input,
input#haggle-offer-input {
	all: unset !important;
	display: block !important;
	flex: 1 !important;
	min-width: 0 !important;
	padding: 10px 0 !important;
	font-size: 15px !important;
	font-weight: 600 !important;
	color: var(--hg-text) !important;
	background: transparent !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
	-moz-appearance: textfield !important;
	-webkit-appearance: none !important;
	font-family: inherit !important;
	line-height: 1.4 !important;
}
input.haggle-offer-input::-webkit-outer-spin-button,
input.haggle-offer-input::-webkit-inner-spin-button { -webkit-appearance: none !important; margin: 0 !important; }
input.haggle-offer-input::placeholder { color: #c0ccda !important; font-weight: 400 !important; opacity: 1 !important; }

/* Send Button */
button.haggle-send-btn,
.haggle-widget button#haggle-send-btn {
	all: unset !important;
	width: 42px !important;
	height: 42px !important;
	min-width: 42px !important;
	border-radius: var(--hg-radius-sm) !important;
	background: var(--hg-primary) !important;
	color: #fff !important;
	border: none !important;
	cursor: pointer !important;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	transition: background .18s, transform .12s, opacity .18s !important;
	flex-shrink: 0 !important;
	box-shadow: 0 2px 8px rgba(37,99,235,.25) !important;
}
button.haggle-send-btn:hover:not(:disabled) {
	background: var(--hg-primary-dk) !important;
	transform: scale(1.05) !important;
}
button.haggle-send-btn:disabled { opacity: .42 !important; cursor: not-allowed !important; transform: none !important; }

/* ══════════════════════════════════════════════
   DEAL BANNER
══════════════════════════════════════════════ */
.haggle-deal-banner {
	text-align: center;
	padding: 22px 18px;
	background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
	border-top: 1px solid #bbf7d0;
	animation: haggle-msg-in .3s ease;
	flex-shrink: 0;
}
.haggle-deal-confetti {
	font-size: 34px;
	line-height: 1;
	margin-bottom: 8px;
	display: block;
	animation: haggle-pop .5s cubic-bezier(.34,1.56,.64,1);
}
@keyframes haggle-pop {
	0%   { transform: scale(0) rotate(-10deg); }
	100% { transform: scale(1) rotate(0deg); }
}
.haggle-deal-text {
	font-size: 15px;
	font-weight: 700;
	color: #15803d;
	margin-bottom: 14px;
}

button.haggle-goto-cart-btn,
.haggle-widget button#haggle-goto-cart {
	all: unset !important;
	display: inline-flex !important;
	align-items: center !important;
	gap: 7px !important;
	background: var(--hg-green) !important;
	color: #fff !important;
	border: none !important;
	padding: 12px 24px !important;
	border-radius: var(--hg-radius-sm) !important;
	font-size: 14px !important;
	font-weight: 700 !important;
	cursor: pointer !important;
	transition: background .18s, transform .12s !important;
	box-shadow: 0 2px 10px rgba(22,163,74,.3) !important;
	font-family: inherit !important;
}
button.haggle-goto-cart-btn:hover { background: var(--hg-green-dk) !important; transform: translateY(-1px) !important; }

/* ══════════════════════════════════════════════
   COLOUR THEMES
══════════════════════════════════════════════ */
/* Minimal */
.haggle-theme-minimal .haggle-inline-header { background: #1e293b; }
.haggle-theme-minimal .haggle-msg-bot .haggle-msg-bubble { background: #f8f8f8; border-color: #e5e5e5; }
.haggle-theme-minimal button.haggle-send-btn { background: #1e293b !important; box-shadow: none !important; }
.haggle-theme-minimal .haggle-input-field-wrap:focus-within { border-color: #1e293b; box-shadow: 0 0 0 3px rgba(30,41,59,.1); }
.haggle-theme-minimal .haggle-product-strip { background: #f8f8f8; border-color: #e5e5e5; }

/* Bold */
.haggle-theme-bold { border-radius: 18px; overflow: hidden; }
.haggle-theme-bold .haggle-inline-header { background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%); }
.haggle-theme-bold button.haggle-send-btn { background: #7c3aed !important; box-shadow: 0 2px 8px rgba(124,58,237,.3) !important; }
.haggle-theme-bold .haggle-msg-user .haggle-msg-bubble { background: #7c3aed; }
.haggle-theme-bold .haggle-quick-chip { background: #f5f3ff; border-color: #ddd6fe; color: #7c3aed; }
.haggle-theme-bold .haggle-input-field-wrap:focus-within { border-color: #7c3aed; box-shadow: 0 0 0 3px rgba(124,58,237,.12); }
.haggle-theme-bold .haggle-product-strip { background: #f5f3ff; border-color: #e9d5ff; }

/* ══════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════ */
@media (max-width: 480px) {
	.haggle-messages { max-height: 195px; }
	.haggle-open-btn { font-size: 13.5px !important; padding: 12px 16px !important; }
	.haggle-inline-panel.haggle-panel-open { max-height: 540px; }
	.haggle-msg-bubble { font-size: 13px; padding: 8px 12px; }
}

/* ══════════════════════════════════════════════
   SHORTCODES & CART
══════════════════════════════════════════════ */
.haggle-stats-shortcode {
	display: inline-flex;
	gap: 12px;
	flex-wrap: wrap;
	font-size: 13px;
	color: #64748b;
}
.haggle-deal-badge-shortcode {
	display: inline-block;
	background: var(--hg-primary-lt);
	color: var(--hg-primary);
	border: 1px solid #bfdbfe;
	padding: 3px 10px;
	border-radius: 20px;
	font-size: 12px;
	font-weight: 600;
}
tr.haggle-cart-savings th,
tr.haggle-cart-savings td { color: var(--hg-green); font-weight: 700; }
