/**
 * Ecommerce Chatbot - Frontend Styles
 * Author: Sablu Hasan (https://sablu-hasan.vercel.app/)
 */

:root {
	--ecc-primary: #2563eb;
	--ecc-primary-hover: #1d4ed8;
	--ecc-accent: #10b981;
	--ecc-bg: #ffffff;
	--ecc-text: #1e293b;
	--ecc-muted: #64748b;
	--ecc-border: #e2e8f0;
	--ecc-bot-bubble: #f1f5f9;
	--ecc-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
	--ecc-radius: 16px;
}

#ecc-chatbot-root {
	position: fixed;
	bottom: 24px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	box-sizing: border-box;
}

#ecc-chatbot-root * {
	box-sizing: border-box;
}

.ecc-pos-bottom-right {
	right: 24px;
}

.ecc-pos-bottom-left {
	left: 24px;
}

/* Floating Toggle Button */
.ecc-toggle-btn {
	width: 58px;
	height: 58px;
	border-radius: 50%;
	background: var(--ecc-primary);
	color: #ffffff;
	border: none;
	outline: none;
	cursor: pointer;
	box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	position: relative;
}

.ecc-toggle-btn:hover {
	transform: scale(1.08);
	box-shadow: 0 8px 24px rgba(37, 99, 235, 0.45);
	background: var(--ecc-primary-hover);
}

.ecc-toggle-btn svg {
	transition: transform 0.25s ease;
}

.ecc-unread-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	background: #ef4444;
	color: #ffffff;
	font-size: 11px;
	font-weight: 700;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 2px solid #ffffff;
	animation: ecc-pulse 2s infinite;
}

@keyframes ecc-pulse {
	0% { transform: scale(1); }
	50% { transform: scale(1.15); }
	100% { transform: scale(1); }
}

/* Chat Box Window */
.ecc-chat-box {
	position: absolute;
	bottom: 74px;
	width: 375px;
	max-width: calc(100vw - 32px);
	height: 540px;
	max-height: calc(100vh - 110px);
	background: var(--ecc-bg);
	border-radius: var(--ecc-radius);
	box-shadow: var(--ecc-shadow);
	border: 1px solid var(--ecc-border);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transform-origin: bottom right;
	animation: ecc-scale-up 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.ecc-pos-bottom-left .ecc-chat-box {
	transform-origin: bottom left;
	left: 0;
}

.ecc-pos-bottom-right .ecc-chat-box {
	right: 0;
}

@keyframes ecc-scale-up {
	from {
		opacity: 0;
		transform: scale(0.85) translateY(20px);
	}
	to {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

/* Header */
.ecc-chat-header {
	background: var(--ecc-primary);
	color: #ffffff;
	padding: 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.ecc-header-info {
	display: flex;
	align-items: center;
	gap: 12px;
}

.ecc-avatar-wrap {
	position: relative;
	width: 38px;
	height: 38px;
	background: rgba(255, 255, 255, 0.2);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
}

.ecc-status-dot {
	position: absolute;
	bottom: 0;
	right: 0;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--ecc-accent);
	border: 2px solid var(--ecc-primary);
}

.ecc-bot-title {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	color: #ffffff;
	line-height: 1.2;
}

.ecc-bot-sub {
	font-size: 11px;
	color: rgba(255, 255, 255, 0.85);
	line-height: 1.2;
	display: block;
	margin-top: 2px;
}

.ecc-header-actions {
	display: flex;
	gap: 6px;
}

.ecc-icon-btn {
	background: transparent;
	border: none;
	color: rgba(255, 255, 255, 0.85);
	cursor: pointer;
	padding: 6px;
	border-radius: 6px;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s, color 0.2s;
}

.ecc-icon-btn:hover {
	background: rgba(255, 255, 255, 0.2);
	color: #ffffff;
}

/* Message List */
.ecc-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: #f8fafc;
	scroll-behavior: smooth;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
}

.ecc-message {
	display: flex;
	flex-direction: column;
	max-width: 82%;
	animation: ecc-fade-in 0.2s ease;
}

@keyframes ecc-fade-in {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: translateY(0); }
}

.ecc-message-bot {
	align-self: flex-start;
}

.ecc-message-user {
	align-self: flex-end;
}

.ecc-bubble {
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 13.5px;
	line-height: 1.45;
	word-break: break-word;
}

.ecc-message-bot .ecc-bubble {
	background: #ffffff;
	color: var(--ecc-text);
	border: 1px solid var(--ecc-border);
	border-bottom-left-radius: 4px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.ecc-message-user .ecc-bubble {
	background: var(--ecc-primary);
	color: #ffffff;
	border-bottom-right-radius: 4px;
}

.ecc-message-time {
	font-size: 10px;
	color: var(--ecc-muted);
	margin-top: 4px;
	padding: 0 4px;
}

.ecc-message-user .ecc-message-time {
	align-self: flex-end;
}

/* Markdown styling inside bot bubbles */
.ecc-bubble p {
	margin: 0 0 8px 0;
}
.ecc-bubble p:last-child {
	margin-bottom: 0;
}
.ecc-bubble strong {
	font-weight: 600;
}
.ecc-bubble ul {
	margin: 4px 0 6px 18px;
	padding: 0;
}
.ecc-bubble li {
	margin-bottom: 4px;
}
.ecc-bubble a {
	color: var(--ecc-primary);
	text-decoration: underline;
}

/* Order Status Card */
.ecc-order-card {
	background: #ffffff;
	border: 1px solid #e2e8f0;
	border-left: 4px solid var(--ecc-primary);
	border-radius: 10px;
	padding: 12px;
	margin-top: 8px;
	font-size: 12.5px;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

/* Order Status Card - Modern Delivery Slip Design */
.ecc-order-card {
	background: #ffffff;
	border: 1px solid #e2e8f0;
	border-left: 4px solid var(--ecc-primary);
	border-radius: 10px;
	padding: 12px 14px;
	margin-top: 8px;
	font-size: 13px;
	line-height: 1.4;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
	width: 100%;
}

.ecc-card-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 10px;
	border-bottom: 1px solid #f1f5f9;
	padding-bottom: 8px;
}

.ecc-card-order-id {
	font-weight: 700;
	font-size: 14px;
	color: var(--ecc-text);
}

.ecc-card-badge {
	font-size: 11px;
	font-weight: 600;
	padding: 3px 9px;
	border-radius: 12px;
	background: #e0f2fe;
	color: #0369a1;
	text-transform: capitalize;
}

.ecc-card-badge.ecc-status-completed {
	background: #dcfce7;
	color: #15803d;
}

.ecc-card-badge.ecc-status-processing {
	background: #fef3c7;
	color: #b45309;
}

.ecc-card-badge.ecc-status-cancelled,
.ecc-card-badge.ecc-status-failed {
	background: #fee2e2;
	color: #b91c1c;
}

/* Customer Details Section (Admin View) */
.ecc-customer-box {
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	padding: 8px 10px;
	margin-bottom: 10px;
}

/* Public Customer Status & Condition Box */
.ecc-status-condition-box {
	background: #f0fdf4;
	border: 1px solid #bbf7d0;
	border-radius: 8px;
	padding: 8px 10px;
	margin-bottom: 10px;
	font-size: 12.5px;
	color: #166534;
	line-height: 1.4;
	display: flex;
	align-items: flex-start;
	gap: 6px;
}

.ecc-status-condition-icon {
	flex-shrink: 0;
	font-size: 14px;
}

.ecc-status-condition-text {
	flex: 1;
}

.ecc-status-condition-text strong {
	color: #14532d;
}

.ecc-card-row-clean {
	display: flex;
	align-items: baseline;
	gap: 6px;
	margin-bottom: 4px;
	font-size: 12px;
	line-height: 1.35;
	word-break: break-word;
}

.ecc-card-row-clean:last-child {
	margin-bottom: 0;
}

.ecc-label {
	color: #64748b;
	font-weight: 600;
	flex-shrink: 0;
	min-width: 65px;
}

.ecc-val {
	color: #1e293b;
}

/* Items Section */
.ecc-items-box {
	margin-bottom: 10px;
}

.ecc-items-header-title {
	font-size: 12px;
	font-weight: 700;
	color: #475569;
	margin-bottom: 6px;
	text-transform: uppercase;
	letter-spacing: 0.3px;
}

.ecc-items-list {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.ecc-item-card-entry {
	background: #ffffff;
	border: 1px solid #f1f5f9;
	border-radius: 6px;
	padding: 6px 8px;
}

.ecc-item-main-row {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 8px;
	font-size: 12.5px;
}

.ecc-item-name {
	color: #1e293b;
	word-break: break-word;
}

.ecc-item-price-pill {
	font-weight: 700;
	color: var(--ecc-primary);
	flex-shrink: 0;
	white-space: nowrap;
	font-size: 12px;
}

.ecc-item-sku-tag {
	font-size: 11px;
	color: #0284c7;
	background: #f0f9ff;
	display: inline-block;
	padding: 1px 6px;
	border-radius: 4px;
	margin-top: 3px;
	margin-right: 4px;
	font-weight: 600;
}

.ecc-item-meta-tag {
	font-size: 11px;
	color: #475569;
	background: #f1f5f9;
	display: inline-block;
	padding: 1px 6px;
	border-radius: 4px;
	margin-top: 3px;
}

.ecc-item-raw-text {
	font-size: 12px;
	color: #334155;
	background: #f8fafc;
	padding: 6px 8px;
	border-radius: 6px;
	white-space: pre-line;
}

/* Footer Total & Date */
.ecc-card-footer {
	border-top: 1px solid #e2e8f0;
	padding-top: 8px;
	margin-top: 8px;
}

.ecc-footer-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 4px;
}

.ecc-footer-total-label {
	font-weight: 600;
	color: #334155;
	font-size: 13px;
}

.ecc-footer-total-price {
	font-size: 15px;
	font-weight: 800;
	color: #059669;
}

.ecc-footer-date-row {
	display: flex;
	justify-content: space-between;
	font-size: 11px;
	color: #94a3b8;
	margin-top: 4px;
}

/* Quick Suggestion Chips */
.ecc-quick-chips {
	padding: 8px 12px;
	background: #ffffff;
	border-top: 1px solid var(--ecc-border);
	display: flex;
	gap: 6px;
	overflow-x: auto;
	white-space: nowrap;
	scrollbar-width: none;
}
.ecc-quick-chips::-webkit-scrollbar {
	display: none;
}

.ecc-chip-btn {
	background: #f1f5f9;
	border: 1px solid #e2e8f0;
	color: #334155;
	font-size: 12px;
	padding: 5px 10px;
	border-radius: 16px;
	cursor: pointer;
	transition: all 0.2s;
	flex-shrink: 0;
}

.ecc-chip-btn:hover {
	background: var(--ecc-primary);
	color: #ffffff;
	border-color: var(--ecc-primary);
}

/* Typing Indicator */
.ecc-typing-indicator {
	padding: 8px 16px;
	background: #f8fafc;
	display: flex;
	align-items: center;
	gap: 4px;
}

.ecc-dot {
	width: 6px;
	height: 6px;
	background: var(--ecc-muted);
	border-radius: 50%;
	animation: ecc-bounce 1.4s infinite ease-in-out both;
}

.ecc-dot:nth-child(1) { animation-delay: -0.32s; }
.ecc-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes ecc-bounce {
	0%, 80%, 100% { transform: scale(0); }
	40% { transform: scale(1); }
}

/* Chat Form */
.ecc-chat-form {
	padding: 10px 12px;
	background: #ffffff;
	border-top: 1px solid var(--ecc-border);
	display: flex;
	align-items: center;
	gap: 8px;
}

.ecc-chat-form input {
	flex: 1;
	border: 1px solid var(--ecc-border);
	border-radius: 20px;
	padding: 8px 14px;
	font-size: 13.5px;
	outline: none;
	color: var(--ecc-text);
	transition: border-color 0.2s;
}

.ecc-chat-form input:focus {
	border-color: var(--ecc-primary);
}

/* Send Button - Bulletproof against WordPress theme styles */
#ecc-chatbot-root .ecc-chat-form button.ecc-send-btn {
	all: unset !important;
	box-sizing: border-box !important;
	width: 38px !important;
	min-width: 38px !important;
	max-width: 38px !important;
	height: 38px !important;
	min-height: 38px !important;
	max-height: 38px !important;
	padding: 0 !important;
	margin: 0 !important;
	border-radius: 50% !important;
	background: var(--ecc-primary) !important;
	color: #ffffff !important;
	border: none !important;
	outline: none !important;
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	cursor: pointer !important;
	flex-shrink: 0 !important;
	line-height: 1 !important;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15) !important;
	transition: background 0.2s, transform 0.15s !important;
	text-align: center !important;
	vertical-align: middle !important;
}

#ecc-chatbot-root .ecc-chat-form button.ecc-send-btn:hover {
	background: var(--ecc-primary-hover) !important;
	transform: scale(1.05) !important;
}

#ecc-chatbot-root .ecc-chat-form button.ecc-send-btn:active {
	transform: scale(0.92) !important;
}

#ecc-chatbot-root .ecc-chat-form button.ecc-send-btn svg,
#ecc-chatbot-root .ecc-chat-form button.ecc-send-btn svg.ecc-send-icon {
	display: block !important;
	width: 18px !important;
	height: 18px !important;
	min-width: 18px !important;
	min-height: 18px !important;
	max-width: 18px !important;
	max-height: 18px !important;
	stroke: #ffffff !important;
	stroke-width: 2.2 !important;
	fill: none !important;
	opacity: 1 !important;
	visibility: visible !important;
	margin: 0 auto !important;
	padding: 0 !important;
	transform: translate(-1px, 1px) !important;
}

#ecc-chatbot-root .ecc-chat-form button.ecc-send-btn:disabled {
	opacity: 0.6 !important;
	cursor: not-allowed !important;
}

/* Footer Attribution */
.ecc-chat-footer {
	text-align: center;
	font-size: 10.5px;
	color: var(--ecc-muted);
	padding: 4px 0 6px;
	background: #ffffff;
	border-top: 1px solid #f8fafc;
}

.ecc-chat-footer a {
	color: var(--ecc-muted);
	text-decoration: none;
	font-weight: 600;
}

.ecc-chat-footer a:hover {
	color: var(--ecc-primary);
}

/* ==========================================================================
   RESPONSIVE DESIGN SYSTEM (Desktop, Tablet & Mobile)
   ========================================================================== */

/* Prevent page scrolling when chatbot modal is open on mobile */
body.ecc-mobile-chat-open {
	overflow: hidden !important;
	overscroll-behavior: none !important;
}

/* --------------------------------------------------------------------------
   1. Desktop & Large Screens (min-width: 1025px)
   -------------------------------------------------------------------------- */
@media (min-width: 1025px) {
	.ecc-chat-box {
		width: 385px;
		height: 560px;
		max-height: calc(100vh - 110px);
		max-height: calc(100dvh - 110px);
	}
}

/* --------------------------------------------------------------------------
   2. Tablet Screens (769px to 1024px)
   -------------------------------------------------------------------------- */
@media (min-width: 769px) and (max-width: 1024px) {
	#ecc-chatbot-root {
		bottom: 20px;
	}

	.ecc-pos-bottom-right {
		right: 20px;
	}

	.ecc-pos-bottom-left {
		left: 20px;
	}

	.ecc-toggle-btn {
		width: 56px;
		height: 56px;
	}

	.ecc-chat-box {
		width: 370px;
		max-width: calc(100vw - 40px);
		height: 520px;
		max-height: calc(100vh - 95px);
		max-height: calc(100dvh - 95px);
		bottom: 72px;
	}

	.ecc-chat-messages {
		padding: 14px;
		gap: 10px;
	}
}

/* --------------------------------------------------------------------------
   3. Mobile Screens (<= 768px) - Fullscreen App Experience
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
	/* Floating button positioning when closed */
	#ecc-chatbot-root {
		bottom: 16px;
	}

	.ecc-pos-bottom-right {
		right: 16px;
	}

	.ecc-pos-bottom-left {
		left: 16px;
	}

	.ecc-toggle-btn {
		width: 52px;
		height: 52px;
		box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
	}

	.ecc-toggle-btn svg {
		width: 24px;
		height: 24px;
	}

	/* When open on mobile: take full viewport modal mode */
	#ecc-chatbot-root.ecc-is-open {
		position: fixed !important;
		top: 0 !important;
		left: 0 !important;
		right: 0 !important;
		bottom: 0 !important;
		width: 100vw !important;
		height: 100vh !important;
		height: 100dvh !important;
		max-width: 100vw !important;
		max-height: 100vh !important;
		max-height: 100dvh !important;
		margin: 0 !important;
		padding: 0 !important;
		z-index: 9999999 !important;
		border-radius: 0 !important;
	}

	/* Hide the floating toggle button when chat is open so it doesn't block inputs */
	#ecc-chatbot-root.ecc-is-open .ecc-toggle-btn {
		display: none !important;
	}

	/* Fullscreen Chat Box */
	#ecc-chatbot-root.ecc-is-open .ecc-chat-box {
		position: fixed !important;
		top: 0 !important;
		left: 0 !important;
		right: 0 !important;
		bottom: 0 !important;
		width: 100% !important;
		max-width: 100% !important;
		height: 100% !important;
		height: 100dvh !important;
		max-height: 100% !important;
		max-height: 100dvh !important;
		border-radius: 0 !important;
		border: none !important;
		box-shadow: none !important;
		animation: ecc-mobile-slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
	}

	@keyframes ecc-mobile-slide-up {
		from {
			opacity: 0.8;
			transform: translateY(18px);
		}
		to {
			opacity: 1;
			transform: translateY(0);
		}
	}

	/* Header with safe-area notch support & larger tap targets */
	.ecc-chat-header {
		padding-top: max(12px, env(safe-area-inset-top));
		padding-left: max(14px, env(safe-area-inset-left));
		padding-right: max(14px, env(safe-area-inset-right));
		padding-bottom: 12px;
		border-radius: 0;
	}

	.ecc-header-actions .ecc-icon-btn {
		width: 38px;
		height: 38px;
		padding: 8px;
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}

	.ecc-header-actions .ecc-icon-btn svg {
		width: 20px;
		height: 20px;
	}

	/* Messages area */
	.ecc-chat-messages {
		padding: 14px 12px;
		gap: 10px;
	}

	.ecc-message {
		max-width: 88%;
	}

	.ecc-bubble {
		font-size: 14px;
		line-height: 1.45;
		padding: 10px 14px;
	}

	/* Input field font-size 16px is required to stop iOS Safari automatic zoom */
	.ecc-chat-form input {
		font-size: 16px !important;
		padding: 9px 14px;
	}

	.ecc-chat-form {
		padding: 10px 12px;
		padding-left: max(12px, env(safe-area-inset-left));
		padding-right: max(12px, env(safe-area-inset-right));
	}

	/* Send button touch hit target */
	#ecc-chatbot-root .ecc-chat-form button.ecc-send-btn {
		width: 40px !important;
		min-width: 40px !important;
		height: 40px !important;
		min-height: 40px !important;
	}

	/* Quick suggestions */
	.ecc-quick-chips {
		padding: 8px 12px;
		-webkit-overflow-scrolling: touch;
	}

	.ecc-chip-btn {
		font-size: 12px;
		padding: 6px 12px;
	}

	/* Footer safe area */
	.ecc-chat-footer {
		padding-bottom: max(6px, env(safe-area-inset-bottom));
		padding-left: max(12px, env(safe-area-inset-left));
		padding-right: max(12px, env(safe-area-inset-right));
	}
}

/* --------------------------------------------------------------------------
   4. Extra Small Mobile Screens (<= 380px, e.g. iPhone SE / Fold outer screen)
   -------------------------------------------------------------------------- */
@media (max-width: 380px) {
	.ecc-avatar-wrap {
		width: 34px;
		height: 34px;
	}

	.ecc-avatar-wrap svg {
		width: 18px;
		height: 18px;
	}

	.ecc-bot-title {
		font-size: 14px;
	}

	.ecc-bot-sub {
		font-size: 10.5px;
	}

	.ecc-message {
		max-width: 92%;
	}

	.ecc-bubble {
		padding: 9px 12px;
		font-size: 13.5px;
	}

	.ecc-order-card {
		padding: 10px 10px;
	}

	.ecc-card-order-id {
		font-size: 13px;
	}

	.ecc-card-badge {
		font-size: 10px;
		padding: 2px 7px;
	}

	.ecc-card-row-clean {
		font-size: 11.5px;
	}

	.ecc-label {
		min-width: 55px;
	}

	.ecc-item-main-row {
		font-size: 12px;
		flex-wrap: wrap;
	}

	.ecc-footer-total-price {
		font-size: 14px;
	}

	.ecc-chip-btn {
		font-size: 11px;
		padding: 5px 9px;
	}
}
