/* ============================================================
   Company AI Chatbot — Widget Styles
   ============================================================ */

:root {
	--cac-primary:        #1d4ed8;
	--cac-primary-light:  #3b82f6;
	--cac-primary-dark:   #1e3a8a;
	--cac-bg:             #ffffff;
	--cac-surface:        #f8fafc;
	--cac-border:         #e2e8f0;
	--cac-text:           #0f172a;
	--cac-text-muted:     #64748b;
	--cac-user-bg:        var(--cac-primary);
	--cac-user-text:      #ffffff;
	--cac-bot-bg:         #f1f5f9;
	--cac-bot-text:       #0f172a;
	--cac-shadow:         0 20px 60px rgba(0, 0, 0, 0.18);
	--cac-radius:         16px;
	--cac-trigger-size:   58px;
	--cac-widget-width:   380px;
	--cac-widget-height:  530px;
	--cac-bottom:         24px;
	--cac-side:           24px;
	--cac-font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

/* ── Root wrapper ──────────────────────────────────────────── */
#cac-widget-root {
	position:   fixed;
	bottom:     var(--cac-bottom);
	right:      var(--cac-side);
	z-index:    999999;
	font-family: var(--cac-font);
}

#cac-widget-root[data-position="bottom-left"] {
	right: auto;
	left:  var(--cac-side);
}

/* ── Trigger button ─────────────────────────────────────────── */
#cac-trigger {
	position:        relative;
	width:           var(--cac-trigger-size);
	height:          var(--cac-trigger-size);
	border-radius:   50%;
	background:      var(--cac-primary);
	border:          none;
	cursor:          pointer;
	display:         flex;
	align-items:     center;
	justify-content: center;
	color:           #fff;
	box-shadow:      0 4px 24px rgba(29, 78, 216, 0.45);
	transition:      transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
	outline:         none;
}

#cac-trigger:hover {
	transform:  scale(1.08);
	box-shadow: 0 8px 30px rgba(29, 78, 216, 0.55);
	background: var(--cac-primary-light);
}

#cac-trigger:focus-visible {
	outline:        3px solid var(--cac-primary-light);
	outline-offset: 3px;
}

#cac-trigger svg {
	transition: opacity 0.2s ease, transform 0.2s ease;
}

#cac-unread-dot {
	position:      absolute;
	top:           4px;
	right:         4px;
	width:         12px;
	height:        12px;
	background:    #ef4444;
	border-radius: 50%;
	border:        2px solid #fff;
	animation:     cac-pulse 2s infinite;
}

@keyframes cac-pulse {
	0%, 100% { transform: scale(1); opacity: 1; }
	50%       { transform: scale(1.3); opacity: 0.7; }
}

/* ── Widget panel ───────────────────────────────────────────── */
#cac-widget {
	position:      absolute;
	bottom:        calc(var(--cac-trigger-size) + 12px);
	right:         0;
	width:         var(--cac-widget-width);
	height:        var(--cac-widget-height);
	background:    var(--cac-bg);
	border-radius: var(--cac-radius);
	box-shadow:    var(--cac-shadow);
	display:       flex;
	flex-direction: column;
	overflow:      hidden;
	transform-origin: bottom right;

	/* Hidden state */
	opacity:    0;
	transform:  scale(0.92) translateY(12px);
	pointer-events: none;
	transition: opacity 0.25s ease, transform 0.25s ease;
}

#cac-widget-root[data-position="bottom-left"] #cac-widget {
	right: auto;
	left:  0;
	transform-origin: bottom left;
}

#cac-widget.cac-open {
	opacity:        1;
	transform:      scale(1) translateY(0);
	pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────────── */
.cac-header {
	display:     flex;
	align-items: center;
	gap:         12px;
	padding:     16px 18px;
	background:  linear-gradient(135deg, var(--cac-primary-dark), var(--cac-primary));
	color:       #ffffff;
	flex-shrink: 0;
}

.cac-header-avatar {
	width:           40px;
	height:          40px;
	border-radius:   50%;
	background:      rgba(255,255,255,0.2);
	display:         flex;
	align-items:     center;
	justify-content: center;
	font-size:       18px;
	font-weight:     700;
	flex-shrink:     0;
	border:          2px solid rgba(255,255,255,0.35);
}

.cac-header-info {
	flex: 1;
}

.cac-header-name {
	font-size:   15px;
	font-weight: 600;
	line-height: 1.2;
}

.cac-header-status {
	font-size:   12px;
	color:       rgba(255,255,255,0.8);
	display:     flex;
	align-items: center;
	gap:         5px;
	margin-top:  2px;
}

.cac-status-dot {
	width:         8px;
	height:        8px;
	border-radius: 50%;
	background:    #4ade80;
	box-shadow:    0 0 6px #4ade80;
	animation:     cac-pulse 2.5s infinite;
}

.cac-minimize {
	background:  transparent;
	border:      none;
	cursor:      pointer;
	color:       rgba(255,255,255,0.8);
	padding:     4px;
	border-radius: 6px;
	display:     flex;
	align-items: center;
	transition:  color 0.15s, background 0.15s;
}

.cac-minimize:hover {
	color:       #fff;
	background:  rgba(255,255,255,0.15);
}

/* ── Messages area ──────────────────────────────────────────── */
.cac-messages {
	flex:       1;
	overflow-y: auto;
	padding:    16px 14px;
	display:    flex;
	flex-direction: column;
	gap:        4px;
	scroll-behavior: smooth;
}

.cac-messages::-webkit-scrollbar {
	width: 4px;
}

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

.cac-messages::-webkit-scrollbar-thumb {
	background:    #cbd5e1;
	border-radius: 99px;
}

/* ── Message groups ─────────────────────────────────────────── */
.cac-msg-group {
	display:       flex;
	flex-direction: column;
	gap:           3px;
	margin-bottom: 10px;
}

.cac-msg-group.cac-user {
	align-items: flex-end;
}

.cac-msg-group.cac-bot {
	align-items: flex-start;
}

/* ── Message row (avatar + bubble) ─────────────────────────── */
.cac-msg-row {
	display:     flex;
	align-items: flex-end;
	gap:         8px;
	max-width:   88%;
}

.cac-user .cac-msg-row {
	flex-direction: row-reverse;
}

.cac-msg-avatar {
	width:           28px;
	height:          28px;
	border-radius:   50%;
	background:      var(--cac-primary);
	color:           #fff;
	font-size:       12px;
	font-weight:     700;
	display:         flex;
	align-items:     center;
	justify-content: center;
	flex-shrink:     0;
}

/* ── Bubbles ─────────────────────────────────────────────────── */
.cac-bubble {
	padding:       10px 14px;
	border-radius: 18px;
	font-size:     14px;
	line-height:   1.55;
	word-wrap:     break-word;
	animation:     cac-fade-up 0.2s ease forwards;
	white-space:   pre-wrap;
}

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

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

.cac-bot .cac-bubble {
	background:         var(--cac-bot-bg);
	color:              var(--cac-bot-text);
	border-bottom-left-radius: 4px;
}

/* ── Timestamp ──────────────────────────────────────────────── */
.cac-timestamp {
	font-size:   11px;
	color:       var(--cac-text-muted);
	padding:     0 8px;
	margin-top:  1px;
}

.cac-user .cac-timestamp {
	text-align: right;
}

/* ── Typing indicator ───────────────────────────────────────── */
.cac-typing-wrap {
	display:     flex;
	align-items: center;
	gap:         8px;
	padding:     0 14px 10px;
}

.cac-typing-avatar {
	width:           28px;
	height:          28px;
	border-radius:   50%;
	background:      var(--cac-primary);
	color:           #fff;
	font-size:       12px;
	font-weight:     700;
	display:         flex;
	align-items:     center;
	justify-content: center;
	flex-shrink:     0;
}

.cac-typing-indicator {
	background:    var(--cac-bot-bg);
	border-radius: 18px;
	border-bottom-left-radius: 4px;
	padding:       12px 16px;
	display:       flex;
	gap:           5px;
	align-items:   center;
}

.cac-typing-indicator span {
	width:         7px;
	height:        7px;
	background:    #94a3b8;
	border-radius: 50%;
	animation:     cac-typing-dot 1.2s infinite ease-in-out;
}

.cac-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.cac-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cac-typing-dot {
	0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
	30%            { transform: translateY(-5px); opacity: 1;   }
}

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

#cac-input {
	flex:         1;
	border:       1.5px solid var(--cac-border);
	border-radius: 24px;
	padding:      10px 16px;
	font-size:    14px;
	font-family:  var(--cac-font);
	color:        var(--cac-text);
	background:   var(--cac-surface);
	outline:      none;
	transition:   border-color 0.2s;
}

#cac-input:focus {
	border-color: var(--cac-primary);
	background:   #fff;
}

#cac-input::placeholder {
	color: #94a3b8;
}

#cac-send {
	width:           40px;
	height:          40px;
	border-radius:   50%;
	background:      var(--cac-primary);
	border:          none;
	cursor:          pointer;
	color:           #fff;
	display:         flex;
	align-items:     center;
	justify-content: center;
	flex-shrink:     0;
	transition:      background 0.2s, transform 0.15s;
}

#cac-send:hover:not(:disabled) {
	background:  var(--cac-primary-light);
	transform:   scale(1.06);
}

#cac-send:disabled {
	background: #cbd5e1;
	cursor:     not-allowed;
}

/* ── Powered by ─────────────────────────────────────────────── */
.cac-powered-by {
	text-align:  center;
	font-size:   11px;
	color:       #94a3b8;
	padding:     5px 0 8px;
	flex-shrink: 0;
}

.cac-powered-by strong {
	color: var(--cac-text-muted);
}

/* ── Error state ─────────────────────────────────────────────── */
.cac-error-msg {
	background:    #fef2f2;
	color:         #b91c1c;
	border-radius: 10px;
	padding:       8px 12px;
	font-size:     13px;
	text-align:    center;
	margin:        4px 0;
}

/* ── Mobile full-screen ─────────────────────────────────────── */
@media (max-width: 480px) {
	#cac-widget {
		position:       fixed;
		top:            0;
		left:           0;
		right:          0;
		bottom:         0;
		width:          100%;
		height:         100%;
		border-radius:  0;
		transform-origin: bottom center;
	}

	#cac-trigger {
		position: fixed;
		bottom:   20px;
		right:    20px;
	}

	#cac-widget-root[data-position="bottom-left"] #cac-trigger {
		right: auto;
		left:  20px;
	}
}

/* ── Lead form inside chat ──────────────────────────────────── */
.cac-lead-form {
	background:    #f8faff;
	border:        1.5px solid #dbeafe;
	border-radius: 12px;
	padding:       14px;
	margin-top:    4px;
	animation:     cac-fade-up 0.25s ease;
}

.cac-lead-form p {
	margin:      0 0 10px;
	font-size:   13px;
	color:       #475569;
	font-weight: 500;
}

.cac-lead-form input,
.cac-lead-form select {
	width:         100%;
	padding:       9px 12px;
	margin-bottom: 8px;
	border:        1.5px solid #e2e8f0;
	border-radius: 8px;
	font-size:     13px;
	font-family:   var(--cac-font);
	color:         var(--cac-text);
	background:    #fff;
	box-sizing:    border-box;
	transition:    border-color 0.2s;
}

.cac-lead-form input:focus,
.cac-lead-form select:focus {
	border-color: var(--cac-primary);
	outline:      none;
}

.cac-lead-form button {
	width:         100%;
	padding:       10px;
	background:    var(--cac-primary);
	color:         #fff;
	border:        none;
	border-radius: 8px;
	font-size:     14px;
	font-weight:   600;
	cursor:        pointer;
	transition:    background 0.2s;
}

.cac-lead-form button:hover {
	background: var(--cac-primary-light);
}

.cac-lead-form .cac-lead-skip {
	width:      100%;
	background: transparent;
	color:      var(--cac-text-muted);
	font-size:  12px;
	font-weight: 400;
	margin-top: 4px;
	cursor:     pointer;
	border:     none;
}

.cac-lead-form .cac-lead-skip:hover {
	color: var(--cac-text);
}
