/*
 * Smart Chat - Frontend Styles
 * @package SmartChat
 */

:root {
	--sc-primary:       #2563eb;
	--sc-primary-dark:  #1d4ed8;
	--smartchat-primary-color: #2563eb;
	--smartchat-button-color:  #2563eb;
	--smartchat-accent-color:  #1d4ed8;
	--smartchat-text-color:    #ffffff;
	--sc-bg:            #ffffff;
	--sc-text:          #1f2937;
	--sc-text-muted:    #6b7280;
	--sc-border:        #e5e7eb;
	--sc-bubble-size:   56px;
	--sc-panel-width:   340px;
	--sc-panel-height:  480px;
	--sc-radius:        16px;
	--sc-radius-sm:     8px;
	--sc-shadow:        0 10px 40px rgba(0,0,0,.18);
	--sc-font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Widget wrapper ──────────────────────────────────────── */
.smartchat-widget {
	position: fixed;
	z-index: 99999;
	font-family: var(--sc-font);
	font-size: 14px;
	line-height: 1.5;
}
.smartchat-bottom-right { bottom: 24px; right: 24px; }
.smartchat-bottom-left  { bottom: 24px; left:  24px; }

/* ── Bubble ──────────────────────────────────────────────── */
.smartchat-bubble {
	position: relative;
	width:  var(--sc-bubble-size);
	height: var(--sc-bubble-size);
	border-radius: 50%;
	background: var(--smartchat-button-color, var(--sc-primary));
	color: var(--smartchat-text-color, #fff);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--sc-shadow);
	transition: transform .2s, background .2s;
	outline: none;
}
.smartchat-bubble:hover  { background: var(--smartchat-accent-color, var(--sc-primary-dark)); transform: scale(1.08); }
.smartchat-bubble:focus-visible { outline: 3px solid var(--smartchat-accent-color, var(--sc-primary)); outline-offset: 3px; }

.smartchat-badge {
	position: absolute;
	top: -4px; right: -4px;
	background: #ef4444;
	color: #fff;
	border-radius: 999px;
	font-size: 10px;
	font-weight: 700;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 2px solid #fff;
}

/* ── Bubble visibility ──────────────────────────────────── */
/* Bubble is visible by default (display:flex set on .smartchat-bubble).
   Hide it only when the panel is open — higher specificity wins cleanly. */
.smartchat-widget:not(.smartchat-minimized) .smartchat-bubble { display: none; }

/* ── Panel ───────────────────────────────────────────────── */
.smartchat-panel {
	position: absolute;
	bottom: 0;
	width: var(--sc-panel-width);
	height: var(--sc-panel-height);
	background: var(--sc-bg);
	border-radius: var(--sc-radius);
	box-shadow: var(--sc-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transition: all 0.2s ease;
	opacity: 1;
}
.smartchat-bottom-right .smartchat-panel { right: 0; }
.smartchat-bottom-left  .smartchat-panel { left: 0; }

/* Closed / minimized state */
.smartchat-minimized .smartchat-panel {
	height: 0;
	pointer-events: none;
}

/* ── Header ──────────────────────────────────────────────── */
.smartchat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	background: var(--smartchat-primary-color, var(--sc-primary));
	color: var(--smartchat-text-color, #fff);
	padding: 12px 14px;
	font-weight: 600;
	font-size: 15px;
	flex-shrink: 0;
}
.smartchat-header-actions { display: flex; gap: 6px; }
.smartchat-icon-btn {
	background: transparent;
	border: none;
	color: rgba(255,255,255,.85);
	cursor: pointer;
	padding: 2px;
	border-radius: 4px;
	display: flex;
	align-items: center;
	transition: color .15s, background .15s;
}
.smartchat-icon-btn:hover { color: var(--smartchat-text-color, #fff); background: rgba(255,255,255,.15); }

/* ── Body ────────────────────────────────────────────────── */
.smartchat-body {
	flex: 1;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
}

.sc-screen {
	flex: 1;
	display: flex;
	flex-direction: column;
}

/* ── Welcome / loading ───────────────────────────────────── */
#sc-screen-welcome {
	padding: 28px 20px;
	justify-content: center;
	align-items: center;
	text-align: center;
}

/* ── Form ────────────────────────────────────────────────── */
.sc-form-inner {
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	overflow-y: auto;
}
.sc-label {
	font-weight: 600;
	color: var(--sc-text);
	margin: 0 0 4px;
}
.sc-input,
.sc-textarea {
	width: 100%;
	padding: 9px 12px;
	border: 1px solid var(--sc-border);
	border-radius: var(--sc-radius-sm);
	font-family: inherit;
	font-size: 13px;
	color: var(--sc-text);
	background: #f9fafb;
	box-sizing: border-box;
	transition: border-color .15s, box-shadow .15s;
	resize: none;
}
.sc-input:focus,
.sc-textarea:focus {
	outline: none;
	border-color: var(--smartchat-accent-color, var(--sc-primary));
	box-shadow: 0 0 0 3px rgba(37,99,235,.15);
	background: #fff;
}

/* ── Buttons ─────────────────────────────────────────────── */
.sc-btn {
	padding: 10px 16px;
	border: none;
	border-radius: var(--sc-radius-sm);
	font-family: inherit;
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	transition: background .15s, transform .1s;
}
.sc-btn-primary {
	background: var(--smartchat-button-color, var(--sc-primary));
	color: var(--smartchat-text-color, #fff);
}
.sc-btn-primary:hover   { background: var(--smartchat-accent-color, var(--sc-primary-dark)); }
.sc-btn-primary:active  { transform: scale(.98); }
.sc-btn-primary:disabled { opacity: .6; cursor: default; }

.sc-btn-secondary {
	background: transparent;
	color: var(--smartchat-accent-color, var(--sc-primary));
	border: 1.5px solid var(--smartchat-accent-color, var(--sc-primary));
}
.sc-btn-secondary:hover { background: rgba(37,99,235,.06); }

.sc-btn-ghost {
	background: transparent;
	color: var(--sc-text-muted);
	border: 1px solid var(--sc-border);
	margin-top: 4px;
}
.sc-btn-ghost:hover { background: #f3f4f6; color: var(--sc-text); }

/* End-chat X button — subtle red tint on hover */
.smartchat-end-icon-btn:hover { color: #ef4444 !important; background: rgba(239,68,68,.1) !important; }

/* ── Waiting ─────────────────────────────────────────────── */
.sc-waiting {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	flex: 1;
	color: var(--sc-text-muted);
}
.sc-spinner {
	width: 36px; height: 36px;
	border: 3px solid var(--sc-border);
	border-top-color: var(--smartchat-accent-color, var(--sc-primary));
	border-radius: 50%;
	animation: sc-spin .8s linear infinite;
}
@keyframes sc-spin { to { transform: rotate(360deg); } }

/* ── Messages ────────────────────────────────────────────── */
#sc-screen-chat {
	padding: 12px;
	overflow: hidden;   /* needed so the child can scroll independently */
	min-height: 0;      /* allows flex child to shrink below content size */
}
.sc-messages {
	display: flex;
	flex-direction: column;
	gap: 10px;
	flex: 1;
	min-height: 0;      /* critical: without this, overflow-y has nothing to clip against */
	overflow-y: auto;
}

.sc-msg {
	display: flex;
	flex-direction: column;
	max-width: 82%;
}
.sc-msg-client { align-self: flex-end; align-items: flex-end; }
.sc-msg-agent  { align-self: flex-start; align-items: flex-start; }

.sc-msg-bubble {
	padding: 9px 13px;
	border-radius: 14px;
	font-size: 13px;
	line-height: 1.5;
	word-break: break-word;
	white-space: pre-wrap;
}
.sc-msg-client .sc-msg-bubble {
	background: var(--smartchat-button-color, var(--sc-primary));
	color: var(--smartchat-text-color, #fff);
	border-bottom-right-radius: 4px;
}
.sc-msg-agent .sc-msg-bubble {
	background: #f3f4f6;
	color: var(--sc-text);
	border-bottom-left-radius: 4px;
}

.sc-msg-meta {
	font-size: 10px;
	color: var(--sc-text-muted);
	margin-top: 2px;
	padding: 0 4px;
}

/* ── Typing indicator ───────────────────────────────────── */
.sc-typing-indicator {
	display: flex;
	align-items: center;
	gap: 7px;
	padding: 4px 2px 6px;
	min-height: 24px;
}
.sc-typing-label {
	font-size: 11px;
	color: var(--sc-text-muted);
	font-style: italic;
}
.sc-typing-dots {
	display: inline-flex;
	align-items: center;
	gap: 3px;
}
.sc-typing-dots span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--sc-text-muted);
	animation: sc-dot-bounce 1.2s ease-in-out infinite;
}
.sc-typing-dots span:nth-child(2) { animation-delay: .2s; }
.sc-typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes sc-dot-bounce {
	0%, 80%, 100% { transform: translateY(0);    opacity: .4; }
	40%           { transform: translateY(-5px); opacity: 1;  }
}

/* ── Queue position ─────────────────────────────────────── */
.sc-queue-pos {
	font-size: 13px;
	color: var(--smartchat-accent-color, var(--sc-primary));
	font-weight: 600;
	margin-top: 4px;
	min-height: 1.4em; /* reserve space so layout doesn't jump */
}

/* ── Star rating ─────────────────────────────────────────── */
.sc-rating-box {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	width: 100%;
	padding-bottom: 4px;
}
.sc-rating-label {
	font-size: 13px;
	color: var(--sc-text-muted);
	margin: 0;
}
.sc-stars {
	display: flex;
	gap: 6px;
}
.sc-star {
	background: none;
	border: none;
	cursor: pointer;
	font-size: 28px;
	color: #d1d5db;
	padding: 0;
	line-height: 1;
	transition: color .15s, transform .1s;
}
.sc-star:hover,
.sc-star.sc-star-hover,
.sc-star.sc-star-selected { color: #f59e0b; }
.sc-star:hover            { transform: scale(1.15); }
.sc-rating-box.sc-rated .sc-star { cursor: default; }
.sc-rating-box.sc-rated .sc-star:hover { transform: none; }

/* ── Chat ended ──────────────────────────────────────────── */
.sc-ended {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	flex: 1;
	padding: 20px;
	text-align: center;
	color: var(--sc-text-muted);
}

/* ── Input area ──────────────────────────────────────────── */
.sc-input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--sc-border);
	background: #fff;
	flex-shrink: 0;
}
.sc-msg-textarea {
	flex: 1;
	border: 1px solid var(--sc-border);
	border-radius: var(--sc-radius-sm);
	padding: 8px 10px;
	font-family: inherit;
	font-size: 13px;
	resize: none;
	max-height: 100px;
	overflow-y: auto;
	line-height: 1.4;
	transition: border-color .15s;
}
.sc-msg-textarea:focus {
	outline: none;
	border-color: var(--smartchat-accent-color, var(--sc-primary));
}
.sc-btn-send {
	background: var(--smartchat-button-color, var(--sc-primary));
	color: var(--smartchat-text-color, #fff);
	border: none;
	border-radius: var(--sc-radius-sm);
	padding: 8px 10px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background .15s;
}
.sc-btn-send:hover { background: var(--smartchat-accent-color, var(--sc-primary-dark)); }

.smartchat-powered-by {
	border-top: 1px solid var(--sc-border);
	color: var(--sc-text-muted);
	font-size: 11px;
	line-height: 1.4;
	padding: 6px 10px;
	text-align: center;
}

/* ── Feedback / error ────────────────────────────────────── */
.sc-error    { color: #dc2626; font-size: 12px; margin: 0; }
.sc-feedback { font-size: 12px; margin: 0; }
.sc-feedback.success { color: #16a34a; }
.sc-feedback.error   { color: #dc2626; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 420px) {
	:root { --sc-panel-width: calc(100vw - 32px); }
}
