/*
 * AI Support Agent — Chat Widget Styles
 * Scoped under #asa-launcher and #asa-panel to avoid theme conflicts.
 */

/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
	--asa-primary:       #2563eb;
	--asa-primary-dark:  #1d4ed8;
	--asa-primary-light: #dbeafe;
	--asa-bg:            #ffffff;
	--asa-surface:       #f8fafc;
	--asa-border:        #e2e8f0;
	--asa-text:          #1e293b;
	--asa-text-muted:    #64748b;
	--asa-bot-bg:        #f1f5f9;
	--asa-user-bg:       #2563eb;
	--asa-user-text:     #ffffff;
	--asa-error-bg:      #fef2f2;
	--asa-error-border:  #fecaca;
	--asa-error-text:    #991b1b;
	--asa-radius:        12px;
	--asa-radius-sm:     8px;
	--asa-shadow:        0 4px 24px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.08);
	--asa-z:             99999;
}

/* ── Launcher button ──────────────────────────────────────────────────────── */
#asa-launcher {
	position:         fixed;
	bottom:           24px;
	right:            24px;
	z-index:          var(--asa-z);
	display:          flex;
	align-items:      center;
	gap:              8px;
	padding:          12px 20px;
	background:       var(--asa-primary);
	color:            #fff;
	border:           none;
	border-radius:    50px;
	font-family:      inherit;
	font-size:        14px;
	font-weight:      600;
	cursor:           pointer;
	box-shadow:       0 4px 16px rgba(37, 99, 235, 0.35);
	transition:       background 0.15s, transform 0.15s, box-shadow 0.15s;
	outline-offset:   3px;
}

#asa-launcher:hover {
	background:   var(--asa-primary-dark);
	transform:    translateY(-1px);
	box-shadow:   0 6px 20px rgba(37, 99, 235, 0.45);
}

#asa-launcher:focus-visible {
	outline: 2px solid var(--asa-primary);
}

#asa-launcher.asa-launcher--active {
	background: var(--asa-primary-dark);
}

#asa-launcher svg {
	flex-shrink: 0;
}

/* ── Panel ────────────────────────────────────────────────────────────────── */
#asa-panel {
	position:       fixed;
	bottom:         90px;
	right:          24px;
	z-index:        var(--asa-z);
	width:          380px;
	max-width:      calc(100vw - 32px);
	max-height:     calc(100vh - 120px);
	display:        flex;
	flex-direction: column;
	background:     var(--asa-bg);
	border:         1px solid var(--asa-border);
	border-radius:  var(--asa-radius);
	box-shadow:     var(--asa-shadow);
	/* Default: invisible and non-interactive.
	   Always display:flex so transitions work correctly.
	   Visibility is controlled ONLY by .asa-panel--open below.
	   We intentionally do NOT use the [hidden] attribute or
	   display:none — some themes inject [hidden]{display:none!important}
	   which breaks CSS transitions entirely. */
	opacity:        0;
	transform:      translateY(12px) scale(0.97);
	pointer-events: none;
	transition:     opacity 0.18s ease, transform 0.18s ease;
}

#asa-panel.asa-panel--open {
	opacity:        1;
	transform:      translateY(0) scale(1);
	pointer-events: auto;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.asa-header {
	display:          flex;
	align-items:      center;
	justify-content:  space-between;
	padding:          14px 16px;
	background:       var(--asa-primary);
	border-radius:    var(--asa-radius) var(--asa-radius) 0 0;
	color:            #fff;
	flex-shrink:      0;
}

.asa-title {
	font-size:   15px;
	font-weight: 700;
	letter-spacing: 0.01em;
}

.asa-header-actions {
	display: flex;
	gap:     4px;
}

.asa-btn-icon {
	display:          flex;
	align-items:      center;
	justify-content:  center;
	width:            30px;
	height:           30px;
	padding:          0;
	background:       rgba(255, 255, 255, 0.15);
	color:            #fff;
	border:           none;
	border-radius:    6px;
	cursor:           pointer;
	transition:       background 0.12s;
	outline-offset:   2px;
}

.asa-btn-icon:hover {
	background: rgba(255, 255, 255, 0.28);
}

.asa-btn-icon:focus-visible {
	outline: 2px solid rgba(255, 255, 255, 0.8);
}

/* ── Message list ─────────────────────────────────────────────────────────── */
.asa-messages {
	flex:       1;
	overflow-y: auto;
	padding:    16px 14px;
	display:    flex;
	flex-direction: column;
	gap:        10px;
	min-height: 200px;
	background: var(--asa-surface);
	scroll-behavior: smooth;
}

.asa-messages::-webkit-scrollbar {
	width: 5px;
}
.asa-messages::-webkit-scrollbar-thumb {
	background: var(--asa-border);
	border-radius: 99px;
}

/* ── Message rows ─────────────────────────────────────────────────────────── */
.asa-row {
	display:   flex;
	max-width: 100%;
}

.asa-row--user {
	justify-content: flex-end;
}

.asa-row--bot {
	justify-content: flex-start;
}

/* ── Bubbles ──────────────────────────────────────────────────────────────── */
.asa-bubble {
	max-width:    78%;
	padding:      10px 14px;
	border-radius: var(--asa-radius);
	font-size:    14px;
	line-height:  1.55;
	word-break:   break-word;
}

.asa-bubble--user {
	background:    var(--asa-user-bg);
	color:         var(--asa-user-text);
	border-radius: var(--asa-radius) var(--asa-radius) 4px var(--asa-radius);
}

.asa-bubble--bot {
	background:    var(--asa-bot-bg);
	color:         var(--asa-text);
	border-radius: var(--asa-radius) var(--asa-radius) var(--asa-radius) 4px;
	border:        1px solid var(--asa-border);
}

.asa-bubble--error {
	background:  var(--asa-error-bg);
	color:       var(--asa-error-text);
	border:      1px solid var(--asa-error-border);
}

/* Bot bubble content formatting */
.asa-bubble--bot strong {
	font-weight: 600;
}

.asa-bubble--bot em {
	font-style: italic;
}

.asa-bubble--bot code {
	background:    rgba(0, 0, 0, 0.07);
	padding:       1px 5px;
	border-radius: 4px;
	font-size:     12.5px;
	font-family:   'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.asa-bubble--bot a {
	color:           var(--asa-primary);
	text-decoration: underline;
	word-break:      break-all;
}

.asa-bubble--bot a:hover {
	color: var(--asa-primary-dark);
}

/* ── Typing indicator ─────────────────────────────────────────────────────── */
.asa-bubble--typing {
	display:     flex;
	align-items: center;
	gap:         5px;
	padding:     12px 16px;
	flex-wrap:   wrap;
}

.asa-dot {
	display:       inline-block;
	width:         7px;
	height:        7px;
	background:    var(--asa-text-muted);
	border-radius: 50%;
	animation:     asa-bounce 1.2s ease-in-out infinite;
}

.asa-dot:nth-child(2) { animation-delay: 0.2s; }
.asa-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes asa-bounce {
	0%, 80%, 100% { transform: translateY(0);    opacity: 0.5; }
	40%           { transform: translateY(-6px); opacity: 1;   }
}

/* ── Input area ───────────────────────────────────────────────────────────── */
.asa-input-row {
	display:     flex;
	align-items: flex-end;
	gap:         8px;
	padding:     12px 14px;
	background:  var(--asa-bg);
	border-top:  1px solid var(--asa-border);
	border-radius: 0 0 var(--asa-radius) var(--asa-radius);
	flex-shrink: 0;
}

.asa-input {
	flex:          1;
	padding:       9px 12px;
	background:    var(--asa-surface);
	color:         var(--asa-text);
	border:        1px solid var(--asa-border);
	border-radius: var(--asa-radius-sm);
	font-family:   inherit;
	font-size:     14px;
	line-height:   1.5;
	resize:        none;
	min-height:    38px;
	max-height:    120px;
	overflow-y:    auto;
	transition:    border-color 0.15s, box-shadow 0.15s;
	outline:       none;
}

.asa-input:focus {
	border-color: var(--asa-primary);
	box-shadow:   0 0 0 3px var(--asa-primary-light);
}

.asa-input:disabled {
	opacity:  0.6;
	cursor:   not-allowed;
}

.asa-input::placeholder {
	color: var(--asa-text-muted);
}

.asa-send {
	display:          flex;
	align-items:      center;
	justify-content:  center;
	width:            38px;
	height:           38px;
	flex-shrink:      0;
	padding:          0;
	background:       var(--asa-primary);
	color:            #fff;
	border:           none;
	border-radius:    var(--asa-radius-sm);
	cursor:           pointer;
	transition:       background 0.12s, transform 0.12s;
	outline-offset:   2px;
}

.asa-send:hover:not(:disabled) {
	background:  var(--asa-primary-dark);
	transform:   scale(1.05);
}

.asa-send:focus-visible {
	outline: 2px solid var(--asa-primary);
}

.asa-send:disabled {
	opacity:  0.5;
	cursor:   not-allowed;
	transform: none;
}

/* ── Login notice (from shortcode when logged out) ───────────────────────── */
.asa-login-notice {
	padding:     10px 14px;
	background:  #fff7ed;
	border:      1px solid #fed7aa;
	border-radius: var(--asa-radius-sm);
	color:       #9a3412;
	font-size:   14px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
	#asa-panel {
		width:         calc(100vw - 16px);
		max-height:    65vh;
		right:         8px;
		bottom:        76px;
	}

	#asa-launcher {
		right:  16px;
		bottom: 16px;
	}
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
	#asa-panel,
	#asa-launcher,
	.asa-dot {
		transition: none;
		animation:  none;
	}
	.asa-dot {
		opacity: 0.5;
	}
}
