/**
 * WP ChatAssist - Frontend Styles
 *
 * @package WP_ChatAssist
 */

/* Container */
.wp-chatassist-container {
	position: fixed;
	z-index: 9999;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

.wp-chatassist-container[data-position="bottom-right"] {
	bottom: 20px;
	right: 20px;
}

.wp-chatassist-container[data-position="bottom-left"] {
	bottom: 20px;
	left: 20px;
}

.wp-chatassist-container[data-position="top-right"] {
	top: 20px;
	right: 20px;
}

.wp-chatassist-container[data-position="top-left"] {
	top: 20px;
	left: 20px;
}

/* Chat Button */
.wp-chatassist-button {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background-color: #0073aa;
	color: #fff;
	border: none;
	cursor: pointer;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.3s ease;
	position: relative;
}

.wp-chatassist-button:hover {
	transform: scale(1.05);
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.wp-chatassist-button:active {
	transform: scale(0.95);
}

.wp-chatassist-button svg {
	width: 28px;
	height: 28px;
}

/* Tooltip */
.wp-chatassist-tooltip {
	position: absolute;
	background: #333;
	color: #fff;
	padding: 8px 14px;
	border-radius: 8px;
	font-size: 13px;
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.3s ease, transform 0.3s ease;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
	z-index: 10000;
}

.wp-chatassist-tooltip::after {
	content: '';
	position: absolute;
	width: 0;
	height: 0;
	border-style: solid;
}

/* Tooltip positioning for different button positions */
.wp-chatassist-container[data-position="bottom-right"] .wp-chatassist-tooltip,
.wp-chatassist-container[data-position="bottom-left"] .wp-chatassist-tooltip {
	bottom: 70px;
	transform: translateY(10px);
}

.wp-chatassist-container[data-position="bottom-right"] .wp-chatassist-tooltip {
	right: 0;
}

.wp-chatassist-container[data-position="bottom-left"] .wp-chatassist-tooltip {
	left: 0;
}

.wp-chatassist-container[data-position="bottom-right"] .wp-chatassist-tooltip::after,
.wp-chatassist-container[data-position="bottom-left"] .wp-chatassist-tooltip::after {
	top: 100%;
	border-width: 6px 6px 0 6px;
	border-color: #333 transparent transparent transparent;
}

.wp-chatassist-container[data-position="bottom-right"] .wp-chatassist-tooltip::after {
	right: 20px;
}

.wp-chatassist-container[data-position="bottom-left"] .wp-chatassist-tooltip::after {
	left: 20px;
}

.wp-chatassist-container[data-position="top-right"] .wp-chatassist-tooltip,
.wp-chatassist-container[data-position="top-left"] .wp-chatassist-tooltip {
	top: 70px;
	transform: translateY(-10px);
}

.wp-chatassist-container[data-position="top-right"] .wp-chatassist-tooltip {
	right: 0;
}

.wp-chatassist-container[data-position="top-left"] .wp-chatassist-tooltip {
	left: 0;
}

.wp-chatassist-container[data-position="top-right"] .wp-chatassist-tooltip::after,
.wp-chatassist-container[data-position="top-left"] .wp-chatassist-tooltip::after {
	bottom: 100%;
	border-width: 0 6px 6px 6px;
	border-color: transparent transparent #333 transparent;
}

.wp-chatassist-container[data-position="top-right"] .wp-chatassist-tooltip::after {
	right: 20px;
}

.wp-chatassist-container[data-position="top-left"] .wp-chatassist-tooltip::after {
	left: 20px;
}

.wp-chatassist-button:hover .wp-chatassist-tooltip {
	opacity: 1;
	transform: translateY(0);
}

/* Chat Window */
.wp-chatassist-window {
	position: relative;
	width: 380px;
	height: 600px;
	max-height: 85vh;
	background: #fff;
	border-radius: 12px;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: slideUp 0.3s ease;
}

/* Window Size Variations */
.wp-chatassist-window.size-small {
	width: 380px;
	height: 600px;
}

.wp-chatassist-window.size-large {
	width: 500px;
	height: 700px;
}

.wp-chatassist-window.size-custom {
	/* Custom size set by drag resize */
}

/* Resize Handles */
.wp-chatassist-resize-handle {
	position: absolute;
	z-index: 10;
}

/* Edge handles */
.wp-chatassist-resize-handle.resize-top {
	top: 0;
	left: 8px;
	right: 8px;
	height: 8px;
	cursor: n-resize;
}

.wp-chatassist-resize-handle.resize-right {
	top: 8px;
	right: 0;
	bottom: 8px;
	width: 8px;
	cursor: e-resize;
}

.wp-chatassist-resize-handle.resize-bottom {
	bottom: 0;
	left: 8px;
	right: 8px;
	height: 8px;
	cursor: s-resize;
}

.wp-chatassist-resize-handle.resize-left {
	top: 8px;
	left: 0;
	bottom: 8px;
	width: 8px;
	cursor: w-resize;
}

/* Corner handles */
.wp-chatassist-resize-handle.resize-top-left {
	top: 0;
	left: 0;
	width: 16px;
	height: 16px;
	cursor: nw-resize;
}

.wp-chatassist-resize-handle.resize-top-right {
	top: 0;
	right: 0;
	width: 16px;
	height: 16px;
	cursor: ne-resize;
}

.wp-chatassist-resize-handle.resize-bottom-left {
	bottom: 0;
	left: 0;
	width: 16px;
	height: 16px;
	cursor: sw-resize;
}

.wp-chatassist-resize-handle.resize-bottom-right {
	bottom: 0;
	right: 0;
	width: 16px;
	height: 16px;
	cursor: se-resize;
}

/* Visual indicator for bottom-right corner (most common resize point) */
.wp-chatassist-resize-handle.resize-bottom-right::after {
	content: '';
	position: absolute;
	bottom: 4px;
	right: 4px;
	width: 8px;
	height: 8px;
	border-right: 2px solid #ccc;
	border-bottom: 2px solid #ccc;
	opacity: 0.5;
}

@keyframes slideUp {
	from {
		opacity: 0;
		transform: translateY(20px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Header */
.wp-chatassist-header {
	background-color: #0073aa;
	color: #fff;
	padding: 16px 20px;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.wp-chatassist-header-title {
	display: flex;
	align-items: center;
	gap: 10px;
	font-weight: 600;
	font-size: 16px;
}

.wp-chatassist-header-actions {
	display: flex;
	gap: 8px;
}

.wp-chatassist-icon-button {
	background: transparent;
	border: none;
	color: #fff;
	cursor: pointer;
	padding: 4px;
	border-radius: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s;
}

.wp-chatassist-icon-button:hover {
	background: rgba(255, 255, 255, 0.1);
}

/* Messages Area */
.wp-chatassist-messages {
	flex: 1;
	overflow-y: auto;
	padding: 20px;
	display: flex;
	flex-direction: column;
	gap: 16px;
	background: #f9f9f9;
}

.wp-chatassist-messages::-webkit-scrollbar {
	width: 6px;
}

.wp-chatassist-messages::-webkit-scrollbar-track {
	background: transparent;
}

.wp-chatassist-messages::-webkit-scrollbar-thumb {
	background: #ccc;
	border-radius: 3px;
}

.wp-chatassist-messages::-webkit-scrollbar-thumb:hover {
	background: #aaa;
}

/* Message */
.wp-chatassist-message {
	max-width: 80%;
	animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

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

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

.wp-chatassist-message-content {
	padding: 12px 16px;
	border-radius: 12px;
	font-size: 14px;
	line-height: 1.5;
	word-wrap: break-word;
}

.wp-chatassist-message.user .wp-chatassist-message-content {
	background: #0073aa;
	color: #fff;
	border-bottom-right-radius: 4px;
}

.wp-chatassist-message.bot .wp-chatassist-message-content {
	background: #e8e8e8;
	color: #333;
	border-bottom-left-radius: 4px;
	padding: 12px 16px;
}

/* Markdown support in bot messages */
.wp-chatassist-message.bot .wp-chatassist-message-content ul {
	margin: 8px 0;
	padding-left: 20px;
	list-style-type: disc;
}

.wp-chatassist-message.bot .wp-chatassist-message-content li {
	margin: 4px 0;
	line-height: 1.5;
}

.wp-chatassist-message.bot .wp-chatassist-message-content strong {
	font-weight: 600;
	color: #0073aa;
}

.wp-chatassist-message.bot .wp-chatassist-message-content br {
	line-height: 1.8;
}

.wp-chatassist-message.error .wp-chatassist-message-content {
	background: #fee;
	color: #c33;
	border-left: 3px solid #c33;
}

.wp-chatassist-message.welcome {
	opacity: 0.9;
}

/* Loading Dots */
.wp-chatassist-typing-dots {
	display: flex;
	gap: 4px;
	padding: 8px 0;
}

.wp-chatassist-typing-dots span {
	width: 8px;
	height: 8px;
	background: #999;
	border-radius: 50%;
	animation: bounce 1.4s infinite ease-in-out;
}

.wp-chatassist-typing-dots span:nth-child(1) {
	animation-delay: -0.32s;
}

.wp-chatassist-typing-dots span:nth-child(2) {
	animation-delay: -0.16s;
}

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

/* Sources */
.wp-chatassist-sources {
	margin-top: 12px;
	padding: 8px 12px;
	font-size: 12px;
	background: rgba(0, 0, 0, 0.02);
	border-radius: 8px;
}

.wp-chatassist-sources-title {
	font-weight: 600;
	margin-bottom: 6px;
	color: #666;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.wp-chatassist-sources-list {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.wp-chatassist-sources-list a {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 10px;
	background: linear-gradient(135deg, #f0f7ff 0%, #e6f2ff 100%);
	color: #0073aa;
	text-decoration: none;
	border-radius: 12px;
	border: 1px solid rgba(0, 115, 170, 0.2);
	font-size: 11px;
	font-weight: 500;
	transition: all 0.2s ease;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.wp-chatassist-sources-list a::before {
	content: '📄';
	font-size: 12px;
	flex-shrink: 0;
}

.wp-chatassist-sources-list a:hover {
	background: linear-gradient(135deg, #e6f2ff 0%, #d9ecff 100%);
	border-color: rgba(0, 115, 170, 0.4);
	transform: translateY(-1px);
	box-shadow: 0 2px 4px rgba(0, 115, 170, 0.15);
}

.wp-chatassist-sources-list a:active {
	transform: translateY(0);
}

/* Feedback */
.wp-chatassist-feedback {
	display: flex;
	gap: 8px;
	margin-top: 12px;
	padding: 8px 12px;
}

.wp-chatassist-feedback-button {
	background: rgba(0, 0, 0, 0.05);
	border: 1px solid rgba(0, 0, 0, 0.1);
	border-radius: 6px;
	padding: 4px 8px;
	font-size: 14px;
	cursor: pointer;
	transition: all 0.2s;
}

.wp-chatassist-feedback-button:hover:not(:disabled) {
	background: rgba(0, 0, 0, 0.1);
	transform: scale(1.1);
}

.wp-chatassist-feedback-button:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.wp-chatassist-feedback-button.selected {
	background: #0073aa;
	border-color: #0073aa;
	transform: scale(1.2);
}

/* Input Area */
.wp-chatassist-input-area {
	border-top: 1px solid #e0e0e0;
	background: #fff;
	padding: 16px;
}

.wp-chatassist-input-wrapper {
	display: flex;
	gap: 8px;
	align-items: center;
}

.wp-chatassist-input {
	flex: 1;
	border: 1px solid #ddd;
	border-radius: 8px;
	padding: 8px 12px;
	font-size: 14px;
	font-family: inherit;
	resize: none;
	height: 40px;
	min-height: 40px;
	max-height: 120px;
	overflow-y: auto;
	line-height: 1.5;
	box-sizing: border-box;
}

.wp-chatassist-input:focus {
	outline: none;
	border-color: #0073aa;
	box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.1);
}

.wp-chatassist-input:disabled {
	background: #f5f5f5;
	cursor: not-allowed;
}

.wp-chatassist-send-button {
	width: 40px;
	height: 40px;
	background: #0073aa;
	color: #fff;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background 0.2s;
	box-sizing: border-box;
}

.wp-chatassist-send-button:hover:not(:disabled) {
	background: #005a87;
}

.wp-chatassist-send-button:active:not(:disabled) {
	transform: scale(0.95);
}

.wp-chatassist-send-button:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* Footer */
.wp-chatassist-footer {
	margin-top: 8px;
	display: flex;
	justify-content: center;
}

.wp-chatassist-text-button {
	background: transparent;
	border: none;
	color: #666;
	font-size: 12px;
	cursor: pointer;
	padding: 4px 8px;
	display: flex;
	align-items: center;
	gap: 4px;
	border-radius: 4px;
	transition: all 0.2s;
}

.wp-chatassist-text-button:hover {
	background: #f0f0f0;
	color: #0073aa;
}

/* Disclaimer Icon */
.wp-chatassist-disclaimer-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	margin-left: 4px;
	opacity: 0.7;
	cursor: help;
	position: relative;
}

.wp-chatassist-disclaimer-icon svg {
	width: 14px;
	height: 14px;
}

.wp-chatassist-disclaimer-icon:hover {
	opacity: 1;
}

/* Custom tooltip for disclaimer */
.wp-chatassist-disclaimer-icon::after {
	content: attr(title);
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	margin-top: 8px;
	padding: 10px 14px;
	background: rgba(0, 0, 0, 0.9);
	color: #fff;
	font-size: 11px;
	font-weight: normal;
	line-height: 1.5;
	white-space: normal;
	width: 220px;
	border-radius: 6px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s, visibility 0.2s;
	z-index: 10001;
	pointer-events: none;
}

.wp-chatassist-disclaimer-icon::before {
	content: '';
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	margin-top: 2px;
	border: 6px solid transparent;
	border-bottom-color: rgba(0, 0, 0, 0.9);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s, visibility 0.2s;
	z-index: 10001;
}

.wp-chatassist-disclaimer-icon:hover::after,
.wp-chatassist-disclaimer-icon:hover::before {
	opacity: 1;
	visibility: visible;
}

/* Language Selector */
.wp-chatassist-lang-selector {
	display: flex;
	align-items: center;
	gap: 4px;
}

.wp-chatassist-lang-icon {
	color: rgba(255, 255, 255, 0.8);
	flex-shrink: 0;
}

.wp-chatassist-lang-selector select {
	background: rgba(255, 255, 255, 0.15);
	border: 1px solid rgba(255, 255, 255, 0.3);
	border-radius: 6px;
	color: #fff;
	font-size: 12px;
	padding: 4px 8px;
	cursor: pointer;
	outline: none;
	appearance: none;
	-webkit-appearance: none;
	-moz-appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 6px center;
	padding-right: 24px;
	min-width: 75px;
}

.wp-chatassist-lang-selector select:hover {
	background-color: rgba(255, 255, 255, 0.25);
	border-color: rgba(255, 255, 255, 0.5);
}

.wp-chatassist-lang-selector select:focus {
	border-color: rgba(255, 255, 255, 0.7);
	box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.wp-chatassist-lang-selector select option {
	background: #333;
	color: #fff;
	padding: 8px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
	.wp-chatassist-window,
	.wp-chatassist-window.size-small,
	.wp-chatassist-window.size-large,
	.wp-chatassist-window.size-custom {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100% !important;
		height: 100vh !important;
		max-height: 100vh;
		border-radius: 0;
	}

	.wp-chatassist-container[data-position] {
		bottom: 20px;
		right: 20px;
		left: auto;
		top: auto;
	}

	/* Hide resize handles on mobile */
	.wp-chatassist-resize-handle {
		display: none;
	}

	/* Adjust disclaimer tooltip on mobile */
	.wp-chatassist-disclaimer-icon::after {
		left: auto;
		right: -10px;
		transform: none;
		width: 200px;
	}

	.wp-chatassist-disclaimer-icon::before {
		left: auto;
		right: 10px;
		transform: none;
	}
}
