/**
 * Smart FAQ Chat Widget — Front-end стилове. (v2)
 *
 * z-index бележка: 2147483000 е нарочно много високо, за да стои над
 * sticky елементите на Astra и мобилния sticky "Добави в количка" бар
 * на WooCommerce, без да е абсолютният таван (2147483647).
 */

.sfcw-widget {
	--sfcw-color: #2e7d32;
	--sfcw-secondary: #1b5e20;
	--sfcw-spacing: 20px;
	position: fixed;
	z-index: 2147483000;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	line-height: 1.4;
}

/* Позициониране по ъгли */
.sfcw-widget.sfcw-corner-bottom-right { right: var(--sfcw-spacing); bottom: var(--sfcw-spacing); }
.sfcw-widget.sfcw-corner-bottom-left  { left: var(--sfcw-spacing);  bottom: var(--sfcw-spacing); }
.sfcw-widget.sfcw-corner-top-right    { right: var(--sfcw-spacing); top: var(--sfcw-spacing); }
.sfcw-widget.sfcw-corner-top-left     { left: var(--sfcw-spacing);  top: var(--sfcw-spacing); }

/* Плаващо бутонче */
.sfcw-toggle-btn {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--sfcw-color);
	border: none;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	transition: transform 0.15s ease, background 0.15s ease;
}
.sfcw-toggle-btn:hover { transform: scale(1.06); background: var(--sfcw-secondary); }
.sfcw-toggle-btn:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
	box-shadow: 0 0 0 5px var(--sfcw-color);
}
.sfcw-toggle-btn .sfcw-icon { width: 28px; height: 28px; }
.sfcw-toggle-btn .sfcw-icon-default { filter: brightness(0) invert(1); }
.sfcw-toggle-btn .sfcw-icon-custom { border-radius: 50%; object-fit: cover; }

.sfcw-size-small .sfcw-toggle-btn  { width: 44px; height: 44px; }
.sfcw-size-small .sfcw-icon        { width: 22px; height: 22px; }
.sfcw-size-large .sfcw-toggle-btn  { width: 68px; height: 68px; }
.sfcw-size-large .sfcw-icon        { width: 34px; height: 34px; }

.sfcw-widget[data-mode="draggable"] .sfcw-toggle-btn { cursor: grab; }
.sfcw-widget[data-mode="draggable"] .sfcw-toggle-btn:active { cursor: grabbing; }

/* Панел */
.sfcw-panel {
	position: absolute;
	bottom: 68px;
	right: 0;
	width: 360px;
	max-width: calc(100vw - 24px);
	max-height: min(700px, calc(100vh - 100px - 68px - var(--sfcw-spacing)));
	background: #fff;
	border-radius: 14px;
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}
.sfcw-corner-bottom-left .sfcw-panel,
.sfcw-corner-top-left .sfcw-panel { right: auto; left: 0; }
.sfcw-corner-top-right .sfcw-panel,
.sfcw-corner-top-left .sfcw-panel { bottom: auto; top: 68px; }
.sfcw-panel[hidden] { display: none; }

/* Header — гъвкава височина, пренася на нов ред, не се реже */
.sfcw-header {
	background: var(--sfcw-color);
	color: #fff;
	padding: 12px 14px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	flex-shrink: 0;
}
.sfcw-header-title {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: 600;
	font-size: 14.5px;
	line-height: 1.35;
}
.sfcw-header-icon {
	width: 20px;
	height: 20px;
	flex-shrink: 0;
	margin-top: 1px;
}
.sfcw-header-text { word-break: break-word; font-size: 13px; }
.sfcw-close-btn {
	background: none;
	border: none;
	color: #fff;
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
	padding: 2px 4px;
	border-radius: 4px;
	flex-shrink: 0;
}
.sfcw-close-btn:hover, .sfcw-close-btn:focus-visible {
	background: rgba(255, 255, 255, 0.18);
	outline: 2px solid #fff;
}

.sfcw-body { padding: 14px; overflow-y: auto; flex-shrink: 0; max-height: 350px; }

.sfcw-greeting { margin: 0 0 12px; font-size: 14px; color: #333; }

.sfcw-categories, .sfcw-tags-list {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

#sfcw-view-tags:not([hidden]) {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 8px;
}

.sfcw-category-group:not([hidden]) {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.sfcw-category-btn,
.sfcw-tag-btn {
	border-radius: 999px;
	padding: 7px 14px;
	background: #eef6ef;
	border: 1px solid var(--sfcw-color);
	color: var(--sfcw-color);
	font-weight: 600;
	font-size: 13px;
	cursor: pointer;
}
.sfcw-category-btn:hover, .sfcw-tag-btn:hover { background: var(--sfcw-secondary); border-color: var(--sfcw-secondary); color: #fff; }

.sfcw-question-btn {
	display: block;
	width: 100%;
	text-align: left;
	background: #f3f4f6;
	border: 1px solid #e2e4e8;
	border-radius: 8px;
	padding: 9px 12px;
	font-size: 13.5px;
	cursor: pointer;
	color: #222;
	margin-bottom: 6px;
	transition: background 0.12s ease;
}
.sfcw-question-btn:hover { background: var(--sfcw-secondary); color: #fff; border-color: var(--sfcw-secondary); }

#sfcw-view-questions .sfcw-back-btn { margin-bottom: 5px; }
#sfcw-view-questions .sfcw-question-btn { padding: 7px 10px; font-size: 12px; }
#sfcw-view-search .sfcw-back-btn { margin-bottom: 5px; }

.sfcw-category-btn:focus-visible,
.sfcw-tag-btn:focus-visible,
.sfcw-question-btn:focus-visible,
.sfcw-back-btn:focus-visible,
#sfcw-home-btn:focus-visible,
.sfcw-fallback-home-btn:focus-visible,
.sfcw-contact-btn:focus-visible,
.sfcw-footer-link:focus-visible,
#sfcw-search-submit:focus-visible,
#sfcw-search-input:focus-visible {
	outline: 2px solid var(--sfcw-color);
	outline-offset: 2px;
}

.sfcw-back-btn {
	background: none;
	border: none;
	color: var(--sfcw-color);
	font-weight: 600;
	font-size: 13px;
	cursor: pointer;
	padding: 4px 6px;
	display: block;
}

.sfcw-answer-title { font-weight: 600; font-size: 14px; margin: 0 0 6px; }
.sfcw-answer-text { font-size: 13.5px; color: #333; margin: 0 0 14px; }

.sfcw-answer-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
	border-top: 1px solid #eee;
	padding-top: 10px;
}
.sfcw-answer-actions .sfcw-back-btn {
	padding: 4px 6px 6px;
}
#sfcw-home-btn, .sfcw-fallback-home-btn {
	background: #f3f4f6;
	border: none;
	border-radius: 6px;
	padding: 6px 10px;
	font-size: 13px;
	cursor: pointer;
	color: #222;
}
.sfcw-contact-btn {
	background: var(--sfcw-color);
	color: #fff !important;
	border-radius: 6px;
	padding: 6px 12px;
	font-size: 13px;
	text-decoration: none;
	margin-left: auto;
}
.sfcw-contact-btn:hover { background: var(--sfcw-secondary); }

.sfcw-search-fallback { font-size: 13.5px; color: #555; margin: 0 0 12px; }
.sfcw-search-fallback-actions { display: flex; gap: 8px; align-items: center; }
.sfcw-search-results .sfcw-question-btn[hidden] { display: none; }

/* Хронология на чата (Viber/WhatsApp стил "балончета") — само за
   преглед, некликаема статистика на изминалия път на потребителя. */
.sfcw-chat-history {
	max-height: 250px;
	min-height: 50px;
	overflow-y: auto;
	flex-shrink: 1;
	padding: 10px 14px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	border-bottom: 1px solid #eee;
	background: #f7f7f8;
}
.sfcw-chat-history[hidden] { display: none; }

.sfcw-history-item {
	max-width: 80%;
	padding: 6px 10px;
	border-radius: 12px;
	font-size: 12px;
	line-height: 1.35;
	word-break: break-word;
}

.sfcw-history-nav,
.sfcw-history-question,
.sfcw-history-answer,
.sfcw-history-fallback {
	align-self: flex-start;
	background: #e9eaec;
	color: #333;
	border-bottom-left-radius: 4px;
}

.sfcw-history-search {
	align-self: flex-end;
	background: var(--sfcw-color);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.sfcw-history-group {
	display: flex;
	flex-direction: column;
	gap: 3px;
	align-items: flex-start;
}
.sfcw-history-group .sfcw-history-question { font-weight: 600; }

/* Постоянна лента за свободен текст — над footer-а, на всяко ниво */
.sfcw-search-bar {
	display: flex;
	gap: 8px;
	align-items: flex-end;
	padding: 10px 14px;
	border-top: 1px solid #eee;
	flex-shrink: 0;
	background: #fff;
}
#sfcw-search-input {
	flex-grow: 1;
	resize: none;
	max-height: 84px; /* ~5 реда */
	min-height: 34px;
	border: 1px solid #ddd;
	border-radius: 8px;
	padding: 7px 10px;
	font-size: 13px;
	font-family: inherit;
	overflow-y: auto;
}
#sfcw-search-submit {
	background: var(--sfcw-color);
	color: #fff;
	border: none;
	border-radius: 8px;
	width: 36px;
	height: 34px;
	flex-shrink: 0;
	cursor: pointer;
	font-size: 15px;
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
	padding: 0;
}
#sfcw-search-submit:hover { background: var(--sfcw-secondary); }

.sfcw-footer {
	border-top: 1px solid #eee;
	padding: 10px;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 10px;
	flex-shrink: 0;
	background: #fafafa;
}
.sfcw-footer-link { font-size: 12px; color: var(--sfcw-color); text-decoration: none; font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.sfcw-footer-icon { width: 12px; height: 12px; color: #111; flex-shrink: 0; }
.sfcw-footer-link:hover { color: var(--sfcw-secondary); text-decoration: underline; }

/* Mobile — position: fixed спрямо viewport-а, независимо от избрания
   ъгъл в админа, за да няма конфликт между absolute позициониране
   (наследено от ъгъла) и calc(100vw) изчисления. */
@media (max-width: 480px) {
	.sfcw-panel {
		position: fixed !important;
		left: 24px !important;
		right: 24px !important;
		width: auto !important;
		max-width: none !important;
	}
	.sfcw-corner-bottom-right .sfcw-panel,
	.sfcw-corner-bottom-left .sfcw-panel {
		bottom: 84px !important;
		top: auto !important;
	}
	.sfcw-corner-top-right .sfcw-panel,
	.sfcw-corner-top-left .sfcw-panel {
		top: 84px !important;
		bottom: auto !important;
	}
	.sfcw-header-title { font-size: 13px; }
	.sfcw-footer-link { font-size: 11px; }
	#sfcw-search-input { font-size: 16px; } /* избягва zoom-in на iOS при focus */
}
