/**
 * AI Chat Plugin — Frontend Widget Styles
 *
 * Uses CSS custom properties set by PHP via wp_add_inline_style.
 *
 * @package AIChatPlugin
 */

/* ── CSS custom-property defaults ───────────────────────────────────────── */

:root {
	--ai-chat-primary:       #4f46e5;
	--ai-chat-secondary:     #818cf8;
	--ai-chat-bg:            #f8fafc;
	--ai-chat-text:          #1e293b;
	--ai-chat-radius:        16px;
	--ai-chat-bubble-size:   58px;
	--ai-chat-panel-w:       380px;
	--ai-chat-panel-h:       600px;
	--ai-chat-shadow:        0 8px 32px rgba(0, 0, 0, .18);
	--ai-chat-z:             99999;
	--ai-chat-transition:    .3s cubic-bezier(.4, 0, .2, 1);
	--ai-chat-bubble-right:  24px;
	--ai-chat-bubble-left:   auto;
	--ai-chat-bubble-radius: 50%;
	--ai-chat-bubble-border-width: 0px;
	--ai-chat-bubble-border-color: #ffffff;
}

/* ── Floating bubble ─────────────────────────────────────────────────────── */

.ai-chat-bubble {
	position:         fixed;
	bottom:           24px;
	right:            var(--ai-chat-bubble-right);
	left:             var(--ai-chat-bubble-left);
	width:            var(--ai-chat-bubble-size);
	height:           var(--ai-chat-bubble-size);
	border-radius:    var(--ai-chat-bubble-radius);
	background:       var(--ai-chat-primary);
	color:            #fff;
	border:           var(--ai-chat-bubble-border-width) solid var(--ai-chat-bubble-border-color);
	cursor:           pointer;
	display:          flex;
	align-items:      center;
	justify-content:  center;
	box-shadow:       var(--ai-chat-shadow);
	z-index:          var(--ai-chat-z);
	transition:       transform var(--ai-chat-transition),
	                  box-shadow var(--ai-chat-transition);
	padding:          0;
	outline:          none;
	-webkit-tap-highlight-color: transparent;
}

.ai-chat-bubble:hover,
.ai-chat-bubble:focus-visible {
	transform:   scale(1.08);
	box-shadow:  0 12px 40px rgba(0, 0, 0, .22);
}

.ai-chat-bubble:active {
	transform: scale(.95);
}

.ai-chat-bubble svg {
	pointer-events: none;
	display:        block;
}

.ai-chat-bubble-icon-img {
	width:          62%;
	height:         62%;
	object-fit:     contain;
	display:        block;
	pointer-events: none;
}

/* ── Panel ───────────────────────────────────────────────────────────────── */

.ai-chat-panel {
	position:        fixed;
	bottom:          calc(var(--ai-chat-bubble-size) + 16px);
	right:           var(--ai-chat-bubble-right);
	left:            var(--ai-chat-bubble-left);
	width:           var(--ai-chat-panel-w);
	max-height:      var(--ai-chat-panel-h);
	background:      var(--ai-chat-bg);
	border-radius:   var(--ai-chat-radius);
	box-shadow:      var(--ai-chat-shadow);
	z-index:         var(--ai-chat-z);
	display:         flex;
	flex-direction:  column;
	overflow:        hidden;
	transform:       translateY(16px) scale(.97);
	opacity:         0;
	pointer-events:  none;
	transition:      transform var(--ai-chat-transition),
	                 opacity   var(--ai-chat-transition);
	font-family:     -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
	                 "Helvetica Neue", Arial, sans-serif;
	font-size:       15px;
	color:           var(--ai-chat-text);
	line-height:     1.5;
}

.ai-chat-panel--open {
	transform:      translateY(0) scale(1);
	opacity:        1;
	pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.ai-chat-header {
	background:      var(--ai-chat-primary);
	color:           #fff;
	padding:         14px 16px;
	display:         flex;
	align-items:     center;
	justify-content: space-between;
	gap:             12px;
	flex-shrink:     0;
}

.ai-chat-header-brand {
	display:     flex;
	align-items: center;
	gap:         12px;
	min-width:   0;
}

.ai-chat-logo {
	width:         40px;
	height:        40px;
	border-radius: 50%;
	object-fit:    cover;
	background:    rgba(255, 255, 255, .18);
	flex-shrink:   0;
	border:        2px solid rgba(255, 255, 255, .3);
}

.ai-chat-logo-placeholder {
	width:         40px;
	height:        40px;
	border-radius: 50%;
	background:    rgba(255, 255, 255, .18);
	flex-shrink:   0;
	display:       flex;
	align-items:   center;
	justify-content: center;
}

.ai-chat-logo-placeholder::after {
	content:  "💬";
	font-size: 20px;
}

.ai-chat-header-info {
	display:         flex;
	flex-direction:  column;
	min-width:       0;
}

.ai-chat-company-name {
	font-size:     15px;
	font-weight:   700;
	line-height:   1.2;
	white-space:   nowrap;
	overflow:      hidden;
	text-overflow: ellipsis;
}

.ai-chat-company-subtitle {
	font-size:     12px;
	opacity:       .85;
	white-space:   nowrap;
	overflow:      hidden;
	text-overflow: ellipsis;
	margin-top:    2px;
}

.ai-chat-header-actions {
	display:     flex;
	align-items: center;
	gap:         10px;
	flex-shrink: 0;
}

.ai-chat-online-badge {
	display:     flex;
	align-items: center;
	gap:         5px;
	font-size:   12px;
	opacity:     .9;
	white-space: nowrap;
}

.ai-chat-online-dot {
	width:         8px;
	height:        8px;
	border-radius: 50%;
	background:    #4ade80;
	display:       inline-block;
	animation:     ai-chat-pulse 2s infinite;
}

@keyframes ai-chat-pulse {
	0%, 100% { opacity: 1; }
	50%       { opacity: .5; }
}

.ai-chat-close-btn {
	background:      transparent;
	border:          none;
	color:           rgba(255, 255, 255, .9);
	cursor:          pointer;
	padding:         5px;
	border-radius:   6px;
	display:         flex;
	align-items:     center;
	justify-content: center;
	transition:      background .2s;
	line-height:     1;
}

.ai-chat-close-btn:hover,
.ai-chat-close-btn:focus-visible {
	background: rgba(255, 255, 255, .18);
	outline:    none;
}

/* ── Messages area ───────────────────────────────────────────────────────── */

.ai-chat-messages {
	flex:            1;
	overflow-y:      auto;
	padding:         16px 14px;
	display:         flex;
	flex-direction:  column;
	gap:             10px;
	scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar       { width: 4px; }
.ai-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ai-chat-messages::-webkit-scrollbar-thumb {
	background:    rgba(0, 0, 0, .12);
	border-radius: 4px;
}

.ai-chat-message {
	display:        flex;
	flex-direction: column;
	max-width:      82%;
	animation:      ai-chat-msg-in .2s ease-out;
}

@keyframes ai-chat-msg-in {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: translateY(0); }
}

.ai-chat-message--user  { align-self: flex-end;  align-items: flex-end; }
.ai-chat-message--bot   { align-self: flex-start; align-items: flex-start; }

.ai-chat-message-bubble {
	padding:       10px 14px;
	border-radius: 16px;
	line-height:   1.55;
	word-break:    break-word;
	hyphens:       auto;
}

.ai-chat-message--user .ai-chat-message-bubble {
	background:                 var(--ai-chat-primary);
	color:                      #fff;
	border-bottom-right-radius: 4px;
}

.ai-chat-message--bot .ai-chat-message-bubble {
	background:                #fff;
	color:                     var(--ai-chat-text);
	border-bottom-left-radius: 4px;
	box-shadow:                0 1px 4px rgba(0, 0, 0, .07);
}

/* ── Typing indicator ────────────────────────────────────────────────────── */

.ai-chat-typing-bubble {
	display:     flex;
	align-items: center;
	gap:         5px;
	padding:     14px 16px !important;
}

.ai-chat-typing-dot {
	width:         7px;
	height:        7px;
	border-radius: 50%;
	background:    var(--ai-chat-primary);
	opacity:       .45;
	display:       inline-block;
	animation:     ai-chat-typing 1.2s infinite;
}

.ai-chat-typing-dot:nth-child(2) { animation-delay: .2s; }
.ai-chat-typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes ai-chat-typing {
	0%, 60%, 100% { opacity: .45; transform: translateY(0); }
	30%            { opacity: 1;   transform: translateY(-4px); }
}

/* ── Error message ───────────────────────────────────────────────────────── */

.ai-chat-error-msg {
	align-self:    center;
	background:    #fee2e2;
	color:         #b91c1c;
	border-radius: 8px;
	padding:       8px 14px;
	font-size:     13px;
	max-width:     90%;
	text-align:    center;
	animation:     ai-chat-msg-in .2s ease-out;
}

/* ── Input area ──────────────────────────────────────────────────────────── */

.ai-chat-input-area {
	padding:      12px 14px;
	border-top:   1px solid rgba(0, 0, 0, .07);
	background:   #fff;
	flex-shrink:  0;
}

.ai-chat-input-row {
	display:       flex;
	align-items:   flex-end;
	gap:           8px;
	background:    var(--ai-chat-bg);
	border:        1.5px solid rgba(0, 0, 0, .1);
	border-radius: calc(var(--ai-chat-radius) - 4px);
	padding:       6px 6px 6px 12px;
	transition:    border-color .2s;
}

.ai-chat-input-row:focus-within {
	border-color: var(--ai-chat-primary);
}

.ai-chat-input {
	flex:        1;
	background:  transparent;
	border:      none;
	outline:     none;
	resize:      none;
	font-size:   14px;
	color:       var(--ai-chat-text);
	font-family: inherit;
	line-height: 1.5;
	max-height:  120px;
	min-height:  24px;
	padding:     4px 0;
	overflow-y:  auto;
}

.ai-chat-input::placeholder {
	color: rgba(0, 0, 0, .35);
}

.ai-chat-send-btn {
	background:      var(--ai-chat-primary);
	color:           #fff;
	border:          none;
	border-radius:   calc(var(--ai-chat-radius) - 8px);
	width:           36px;
	height:          36px;
	min-width:       36px;
	display:         flex;
	align-items:     center;
	justify-content: center;
	cursor:          pointer;
	flex-shrink:     0;
	transition:      background .2s, transform .1s, opacity .2s;
	padding:         0;
}

.ai-chat-send-btn:hover:not(:disabled) {
	background: var(--ai-chat-secondary);
}

.ai-chat-send-btn:active:not(:disabled) {
	transform: scale(.92);
}

.ai-chat-send-btn:disabled {
	opacity: .4;
	cursor:  not-allowed;
}

.ai-chat-send-btn:focus-visible {
	outline:        2px solid var(--ai-chat-primary);
	outline-offset: 2px;
}

.ai-chat-disclaimer {
	font-size:   11px;
	color:       rgba(0, 0, 0, .4);
	margin:      8px 2px 0;
	text-align:  center;
	line-height: 1.4;
}

/* ── Shortcode trigger button ────────────────────────────────────────────── */

.ai-chat-shortcode-trigger {
	display:       inline-flex;
	align-items:   center;
	gap:           8px;
	background:    var(--ai-chat-primary);
	color:         #fff;
	border:        none;
	border-radius: var(--ai-chat-radius);
	padding:       10px 20px;
	font-size:     15px;
	font-family:   inherit;
	cursor:        pointer;
	transition:    background .2s, transform .1s;
}

.ai-chat-shortcode-trigger:hover {
	background: var(--ai-chat-secondary);
}

/* ── Mobile responsive ───────────────────────────────────────────────────── */

@media (max-width: 480px) {
	.ai-chat-panel {
		position:      fixed;
		inset:         0;
		width:         100%;
		max-height:    100%;
		border-radius: 0;
	}

	.ai-chat-bubble {
		bottom: 20px;
		right:  var(--ai-chat-bubble-right);
		left:   var(--ai-chat-bubble-left);
	}
}

/* ── RTL support ─────────────────────────────────────────────────────────── */

[dir="rtl"] .ai-chat-bubble {
	right: var(--ai-chat-bubble-left);
	left:  var(--ai-chat-bubble-right);
}

[dir="rtl"] .ai-chat-panel {
	right: var(--ai-chat-bubble-left);
	left:  var(--ai-chat-bubble-right);
}

[dir="rtl"] .ai-chat-message--user { align-items: flex-start; }
[dir="rtl"] .ai-chat-message--bot  { align-items: flex-end; }

[dir="rtl"] .ai-chat-message--user .ai-chat-message-bubble {
	border-bottom-right-radius: 16px;
	border-bottom-left-radius:  4px;
}

[dir="rtl"] .ai-chat-message--bot .ai-chat-message-bubble {
	border-bottom-left-radius:  16px;
	border-bottom-right-radius: 4px;
}

/* ── Noscript fallback ───────────────────────────────────────────────────── */

.ai-chat-noscript {
	display:    block;
	padding:    12px;
	background: #fef9c3;
	color:      #713f12;
	border:     1px solid #fde047;
	border-radius: 6px;
	font-size:  14px;
	margin:     8px;
}
