/* ============================================
   AI ASSISTANT CHAT BUBBLE STYLES

   The AI chat offcanvas uses the shared .msg-* template
   (see style.css "MESSAGE BUBBLE TEMPLATE" section) so it
   feels like a cousin of the Driver Messages and User Chat
   offcanvases. The styles below are limited to:
   - the floating edge-tab toggle button
   - the offcanvas shell + gradient header (the "this is AI"
     signal so users don't confuse it with a human chat)
   - a third .msg-bubble--ai variant + bot avatar
   - the typing indicator dots
   ============================================ */

/* Floating toggle button removed. .ai-chat-toggle was a 14px edge tab
   pinned to right:0, so it sat on top of .main's scrollbar on every page.
   The offcanvas is opened from the header Help menu (#helpMenu) and from the
   Ask row in quick search, both targeting #aiChatOffcanvas. */

/* Offcanvas shell — wider than the driver messages offcanvas (420px) because
   AI replies often include markdown tables / lists that need horizontal room. */
.ai-chat-offcanvas {
	width: 600px !important;
	max-width: 90vw;
}

.ai-chat-offcanvas .offcanvas-body {
	background-color: #f6f8fb;
}

/* Flex-scroll fix — same trick as #chatMessages in style.css; without this
   the message thread can blow past the offcanvas height on long conversations. */
#aiChatMessages {
	min-height: 0;
}

/* Slate header with cyan accent — the primary "you're talking to AI" cue.
   Distinct from the primary navy used by the messaging offcanvas so the
   two surfaces don't get confused. */
.ai-chat-header {
	background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
	color: white;
	padding: 0.65rem 1rem;
	border-bottom: 2px solid #06b6d4;
}

.ai-chat-header .offcanvas-title i {
	font-size: 1.05rem;
	color: #67e8f9;
}

.ai-chat-header__subtitle {
	font-size: 0.65rem;
	opacity: 0.75;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	font-weight: 500;
	display: block;
	line-height: 1.1;
	color: #67e8f9;
}

/* AI bubble variant — sits alongside .msg-bubble--in / --out */
.msg-bubble--ai {
	background-color: #f0f9ff;
	color: #0f172a;
	border: 1px solid #bae6fd;
	border-bottom-left-radius: 4px;
}

.msg-bubble--ai .msg-bubble__sender {
	color: #0c4a6e;
}

.msg-bubble--ai .msg-bubble__tag {
	background-color: #cffafe;
	color: #0e7490;
}

.msg-bubble--ai .msg-bubble__footer {
	color: #64748b;
}

/* Robot avatar that flags every AI message — strongest visual
   "this is not a real person" signal inside the thread */
.ai-msg-row {
	gap: 0.5rem;
}

.ai-msg-avatar {
	flex-shrink: 0;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
	color: #67e8f9;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.8rem;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.35);
	margin-top: 2px;
}

/* Links inside AI bubbles */
.msg-bubble--ai a {
	color: #0e7490;
	text-decoration: none;
	font-weight: 500;
	border-bottom: 1px dashed #0e7490;
}

.msg-bubble--ai a:hover {
	color: #155e75;
	border-bottom-color: #155e75;
}

.msg-bubble--ai code {
	background: rgba(14, 116, 144, 0.1);
	padding: 1px 5px;
	border-radius: 4px;
	font-size: 0.8rem;
}

/* Markdown tables rendered from assistant responses (lane comparisons, AR aging,
   reports). Kept compact so they read well inside the chat bubble. */
.msg-bubble--ai .ai-table {
	width: 100%;
	border-collapse: collapse;
	margin: 0.5rem 0;
	font-size: 0.78rem;
}
.msg-bubble--ai .ai-table th,
.msg-bubble--ai .ai-table td {
	padding: 0.35rem 0.5rem;
	border-bottom: 1px solid #bae6fd;
	text-align: left;
	vertical-align: top;
}
.msg-bubble--ai .ai-table th {
	font-weight: 600;
	background: rgba(14, 116, 144, 0.06);
	white-space: nowrap;
}
[data-bs-theme="dark"] .msg-bubble--ai .ai-table th,
[data-bs-theme="dark"] .msg-bubble--ai .ai-table td {
	border-bottom-color: rgba(148, 163, 184, 0.25);
}
[data-bs-theme="dark"] .msg-bubble--ai .ai-table th {
	background: rgba(148, 163, 184, 0.12);
}

/* Beta-warning callout shown in the welcome message */
.ai-beta-warning {
	margin-top: 0.4rem;
	padding-top: 0.4rem;
	border-top: 1px dashed #bae6fd;
	font-size: 0.72rem;
	color: #0e7490;
	line-height: 1.35;
}

/* Typing indicator — three dots inside an AI bubble */
.ai-typing-indicator .msg-bubble__body {
	display: flex;
	gap: 4px;
	padding: 4px 2px;
}

.typing-dot {
	width: 7px;
	height: 7px;
	background: #0e7490;
	border-radius: 50%;
	animation: typingBounce 1.4s infinite ease-in-out both;
}

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

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

/* Dark-mode tweaks for the AI bubble variant */
[data-bs-theme="dark"] .ai-chat-offcanvas .offcanvas-body {
	background-color: #1e2228;
}

[data-bs-theme="dark"] .msg-bubble--ai {
	background-color: #1e2a3a;
	color: #e6edf3;
	border-color: #1e4a5e;
}

[data-bs-theme="dark"] .msg-bubble--ai .msg-bubble__sender { color: #67e8f9; }

[data-bs-theme="dark"] .msg-bubble--ai .msg-bubble__tag {
	background-color: #1e4a5e;
	color: #a5f3fc;
}

[data-bs-theme="dark"] .msg-bubble--ai .msg-bubble__footer { color: #768390; }

[data-bs-theme="dark"] .msg-bubble--ai a { color: #67e8f9; border-bottom-color: #67e8f9; }

[data-bs-theme="dark"] .ai-beta-warning {
	color: #67e8f9;
	border-top-color: #1e4a5e;
}

/* Resend (on the user's own messages) and Retry (on a failed turn).

   Resend is hover-revealed so a long thread doesn't become a column of buttons;
   (hover: none) pins it visible on touch, where there is no hover to reveal it.
   Retry is always visible — it only exists on a turn that failed. */
.ai-user-row {
	align-items: center;
	gap: 0.35rem;
}

.ai-resend-btn {
	border: 0;
	background: transparent;
	color: #94a3b8;
	font-size: 0.75rem;
	line-height: 1;
	padding: 0.25rem;
	border-radius: 4px;
	opacity: 0;
	transition: opacity 0.12s ease-in-out, color 0.12s ease-in-out;
}

.ai-user-row:hover .ai-resend-btn,
.ai-resend-btn:focus-visible {
	opacity: 1;
}

.ai-resend-btn:hover {
	color: var(--color-primary);
}

@media (hover: none) {
	.ai-resend-btn { opacity: 0.55; }
}

/* A failed turn reads as a warning, not as an answer */
.ai-error-row .msg-bubble--ai {
	background-color: #fff7ed;
	border-color: #fed7aa;
}

.ai-error-actions {
	margin-top: 0.5rem;
}

.ai-retry-btn {
	border: 1px solid #fdba74;
	background-color: #ffffff;
	color: #9a3412;
	font-size: 0.75rem;
	padding: 0.15rem 0.6rem;
}

.ai-retry-btn:hover {
	background-color: #ffedd5;
	color: #7c2d12;
}

[data-bs-theme="dark"] .ai-error-row .msg-bubble--ai {
	background-color: #3a2416;
	border-color: #7c4a21;
}

[data-bs-theme="dark"] .ai-retry-btn {
	background-color: #2d1e12;
	border-color: #7c4a21;
	color: #fdba74;
}

[data-bs-theme="dark"] .ai-retry-btn:hover {
	background-color: #3a2416;
	color: #fed7aa;
}

/* Clear sits flush, like the fullscreen toggle this header's other action
   uses (.btn-offcanvas-fullscreen in style.css): transparent, no border, and
   an opacity lift instead of a box. Outlined, it read as the loudest control
   in a header whose subject is the conversation below it. */
#aiChatClear {
	background: transparent;
	border: 0;
	color: #fff;
	opacity: 0.85;
	padding: 0.25rem 0.5rem;
	transition: opacity 0.15s ease;
}

#aiChatClear:hover,
#aiChatClear:focus {
	color: #fff;
	opacity: 1;
	box-shadow: none;
}

/* Responsive */
@media (max-width: 768px) {
	.ai-chat-offcanvas {
		width: 100vw !important;
		max-width: 100vw;
	}
}

/* Scrollbar styling for the message thread inside the AI offcanvas */
.ai-chat-offcanvas .msg-thread::-webkit-scrollbar { width: 6px; }
.ai-chat-offcanvas .msg-thread::-webkit-scrollbar-track { background: transparent; }
.ai-chat-offcanvas .msg-thread::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.ai-chat-offcanvas .msg-thread::-webkit-scrollbar-thumb:hover { background: #aaa; }
