/**
 * Cycle AI Chat Panel
 *
 * Floating bottom-right chat panel with FAB trigger button.
 * Handles panel container, header, suggestions, chat area,
 * input bar, animations, and responsive behavior.
 *
 * @package    SmartCycleDiscounts
 * @subpackage SmartCycleDiscounts/resources/assets/css/admin
 * @since      2.0.0
 */

/* ==========================================================================
   Shared: panel-scoped visibility toggle
   ========================================================================== */

.wsscd-ai-panel .is-hidden,
.wsscd-ai-fab.is-hidden {
	display: none;
}

/* ==========================================================================
   FAB Button
   ========================================================================== */

.wsscd-ai-fab {
	display: flex;
	align-items: center;
	justify-content: center;
	position: fixed;
	bottom: 24px;
	right: 24px;
	width: 52px;
	height: 52px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--wsscd-color-primary);
	color: #fff;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
	cursor: pointer;
	z-index: var(--wsscd-z-modal);
	transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
	animation: wsscd-fab-entrance 0.3s ease-out 0.3s both;
}

.wsscd-ai-fab:hover {
	background: var(--wsscd-color-primary-dark);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.wsscd-ai-fab:focus-visible {
	outline: 2px solid var(--wsscd-color-primary);
	outline-offset: 2px;
}

.wsscd-ai-fab:active {
	transform: scale(0.93);
}

.wsscd-ai-fab--hidden {
	opacity: 0;
	pointer-events: none;
	transform: scale(0.5);
}

/* ==========================================================================
   Panel container
   ========================================================================== */

.wsscd-ai-panel {
	display: none;
	position: fixed;
	bottom: 16px;
	right: 16px;
	width: 420px;
	max-height: calc(100vh - 80px);
	min-height: 400px;
	flex-direction: column;
	background: #fff;
	border: 1px solid #d0d5dd;
	border-radius: 16px;
	box-shadow:
		0 4px 12px rgba(0, 0, 0, 0.08),
		0 20px 48px rgba(0, 0, 0, 0.16);
	z-index: var(--wsscd-z-modal);
	overflow: hidden;
}

.wsscd-ai-panel--open {
	display: flex;
	height: min(580px, calc(100vh - 80px));
	animation: wsscd-panel-slide-in 0.2s ease-out both;
}

.wsscd-ai-panel--closing {
	animation: wsscd-panel-slide-out 0.15s ease-in both;
}

/* ==========================================================================
   Header
   ========================================================================== */

.wsscd-ai-panel__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 48px;
	padding: 0 16px;
	border-bottom: 1px solid var(--wsscd-color-surface-dark);
	background: #fafbfc;
	flex-shrink: 0;
}

.wsscd-ai-panel__header-left {
	display: flex;
	align-items: center;
	gap: 8px;
	color: var(--wsscd-color-primary);
}

.wsscd-ai-panel__title {
	font-size: 14px;
	font-weight: 600;
	color: var(--wsscd-color-text);
	line-height: 1;
}

.wsscd-ai-panel__header-actions {
	display: flex;
	align-items: center;
	gap: 2px;
}

.wsscd-ai-panel__reset,
.wsscd-ai-panel__disable,
.wsscd-ai-panel__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border: none;
	border-radius: 6px;
	background: transparent;
	color: var(--wsscd-color-text-muted);
	cursor: pointer;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.wsscd-ai-panel__reset:hover,
.wsscd-ai-panel__disable:hover,
.wsscd-ai-panel__close:hover {
	background: #f0f0f0;
	color: var(--wsscd-color-text);
}

.wsscd-ai-panel__disable:hover {
	color: #b32d2e;
}

.wsscd-ai-panel__reset:focus-visible,
.wsscd-ai-panel__disable:focus-visible,
.wsscd-ai-panel__close:focus-visible {
	outline: 2px solid var(--wsscd-color-primary);
	outline-offset: -2px;
}

.wsscd-ai-panel__reset {
	display: none;
}

.wsscd-ai-panel__reset--visible {
	display: flex;
}

/* ==========================================================================
   Welcome (empty state)
   ========================================================================== */

.wsscd-ai-panel__welcome {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 24px 16px 8px;
	text-align: center;
}

.wsscd-ai-panel__welcome-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 52px;
	border-radius: 14px;
	background: linear-gradient( 135deg, #e8f0fe, #d4e4f7 );
	color: var(--wsscd-color-primary);
	margin-bottom: 12px;
}

.wsscd-ai-panel__welcome-text {
	margin: 0;
	font-size: 13px;
	color: var(--wsscd-color-text-muted);
	line-height: 1.5;
	max-width: 280px;
}

/* ==========================================================================
   Suggestions
   ========================================================================== */

.wsscd-ai-panel__suggestions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	padding: 8px 16px 12px;
}

.wsscd-ai-panel__suggestions:empty {
	display: none;
}

.wsscd-ai-panel__suggestion-card {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 10px 12px;
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	cursor: pointer;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.wsscd-ai-panel__suggestion-card:hover {
	border-color: #c5d9ed;
	background: #f0f6fc;
	box-shadow: 0 2px 8px var(--wsscd-color-primary-alpha-8);
}

.wsscd-ai-panel__suggestion-card:focus-visible {
	outline: 2px solid var(--wsscd-color-primary);
	outline-offset: 1px;
}

.wsscd-ai-panel__suggestion-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	background: #daeaf5;
	border-radius: 6px;
	font-size: 14px;
	line-height: 1;
	flex-shrink: 0;
}

.wsscd-ai-panel__suggestion-title {
	font-size: 12px;
	font-weight: 600;
	color: var(--wsscd-color-text);
	line-height: 1.3;
	margin: 0;
}

.wsscd-ai-panel__suggestion-desc {
	font-size: 11px;
	color: #50575e;
	line-height: 1.4;
	margin: 0;
}

/* --- Used Suggestion Cards --- */

.wsscd-ai-panel__suggestion-card--used {
	opacity: 0.5;
	position: relative;
}

.wsscd-ai-panel__suggestion-card--used::after {
	content: '\2713';
	position: absolute;
	top: 6px;
	right: 8px;
	font-size: 11px;
	color: var(--wsscd-text-secondary, #646970);
}

/* ==========================================================================
   Chat area
   ========================================================================== */

.wsscd-ai-panel__chat {
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 12px 16px;
	flex: 1 1 auto;
	overflow-y: auto;
}

.wsscd-ai-panel__chat:empty {
	padding: 0;
}

/* Scrollbar styling */
.wsscd-ai-panel__chat::-webkit-scrollbar {
	width: 4px;
}

.wsscd-ai-panel__chat::-webkit-scrollbar-track {
	background: transparent;
}

.wsscd-ai-panel__chat::-webkit-scrollbar-thumb {
	background: rgba(0, 0, 0, 0.12);
	border-radius: 2px;
}

.wsscd-ai-panel__chat::-webkit-scrollbar-thumb:hover {
	background: rgba(0, 0, 0, 0.2);
}

/* --- Typing indicator (bouncing dots) --- */

/* --- Thinking indicator --- */

.wsscd-ai-panel__thinking {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 2px 0;
}

.wsscd-ai-panel__thinking-dots {
	display: flex;
	align-items: center;
	gap: 4px;
}

.wsscd-ai-panel__thinking-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--wsscd-color-border);
	animation: wsscd-ai-thinking-pulse 1.2s ease-in-out infinite both;
}

.wsscd-ai-panel__thinking-dot:nth-child( 2 ) {
	animation-delay: 0.15s;
}

.wsscd-ai-panel__thinking-dot:nth-child( 3 ) {
	animation-delay: 0.3s;
}

@keyframes wsscd-ai-thinking-pulse {
	0%, 60%, 100% {
		background: var(--wsscd-color-border);
		transform: scale( 1 );
	}
	30% {
		background: var(--wsscd-color-primary);
		transform: scale( 1.3 );
	}
}

.wsscd-ai-panel__thinking-label {
	font-size: 12px;
	color: var(--wsscd-color-gray-400);
	font-style: italic;
}

/* --- Timestamp --- */

.wsscd-ai-panel__timestamp {
	font-size: 10px;
	color: var(--wsscd-color-gray-400);
	margin-top: 2px;
	padding-left: 42px;
}

/* ==========================================================================
   Input bar
   ========================================================================== */

.wsscd-ai-panel__input-bar {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 16px 16px;
	border-top: 1px solid #e2e4e7;
	background: #fafbfc;
	flex-shrink: 0;
}

.wsscd-ai-panel__input-bar.is-disabled {
	opacity: 0.5;
	pointer-events: none;
}

.wsscd-ai-panel__input-wrap {
	flex: 1 1 auto;
	position: relative;
}

/* Character counter — positioned inside input wrap */
.wsscd-ai-panel__input-wrap .wsscd-cycle-ai-modal__char-count {
	position: absolute;
	right: 14px;
	bottom: -16px;
	font-size: 10px;
	padding: 0;
}

.wsscd-ai-panel__input {
	display: block;
	width: 100%;
	min-height: 40px;
	max-height: 100px;
	padding: 10px 16px;
	font-size: 13px;
	font-family: inherit;
	color: var(--wsscd-color-text);
	background: #fff;
	border: 1px solid #d0d5dd;
	border-radius: 20px;
	resize: none;
	outline: none;
	line-height: 1.4;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
	box-sizing: border-box;
}

.wsscd-ai-panel__input:focus {
	border-color: var(--wsscd-color-primary);
	box-shadow: 0 0 0 2px var(--wsscd-color-primary-alpha-15);
}

.wsscd-ai-panel__input::placeholder {
	color: var(--wsscd-color-gray-400);
}

/* ==========================================================================
   Send button
   ========================================================================== */

.wsscd-ai-panel__send-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--wsscd-color-primary);
	color: #fff;
	cursor: pointer;
	flex-shrink: 0;
	transition: background-color 0.15s ease, transform 0.1s ease;
}

.wsscd-ai-panel__send-btn svg {
	display: block;
}

.wsscd-ai-panel__send-btn:hover {
	background: var(--wsscd-color-primary-dark);
}

.wsscd-ai-panel__send-btn:active {
	transform: scale(0.93);
}

.wsscd-ai-panel__send-btn:focus-visible {
	outline: 2px solid var(--wsscd-color-primary);
	outline-offset: 2px;
}

.wsscd-ai-panel__send-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* ==========================================================================
   Error display
   ========================================================================== */

.wsscd-ai-panel__error {
	display: none;
	padding: 0 16px 10px;
	margin: 0;
	font-size: 12px;
	color: var(--wsscd-color-danger);
	line-height: 1.4;
}

.wsscd-ai-panel__error.is-visible {
	display: block;
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes wsscd-panel-slide-in {
	from {
		opacity: 0;
		transform: translateY(20px) scale(0.95);
	}

	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

@keyframes wsscd-panel-slide-out {
	from {
		opacity: 1;
		transform: translateY(0) scale(1);
	}

	to {
		opacity: 0;
		transform: translateY(20px) scale(0.95);
	}
}

@keyframes wsscd-fab-entrance {
	from {
		opacity: 0;
		transform: scale(0.5);
	}

	to {
		opacity: 1;
		transform: scale(1);
	}
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media screen and (max-width: 600px) {
	.wsscd-ai-panel__suggestions {
		grid-template-columns: 1fr;
	}
}

@media screen and (max-width: 480px) {
	.wsscd-ai-panel {
		width: 100%;
		height: 100%;
		max-height: 100%;
		bottom: 0;
		right: 0;
		border-radius: 0;
	}

	.wsscd-ai-panel__header {
		border-radius: 0;
	}

	.wsscd-ai-panel__error {
		padding-left: 16px;
		padding-right: 16px;
	}
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
	.wsscd-ai-fab {
		animation: none;
	}

	.wsscd-ai-panel--open {
		animation: none;
	}

	.wsscd-ai-panel--closing {
		animation: none;
	}

	.wsscd-ai-fab,
	.wsscd-ai-panel__close,
	.wsscd-ai-panel__disable,
	.wsscd-ai-panel__reset,
	.wsscd-ai-panel__send-btn,
	.wsscd-ai-panel__input,
	.wsscd-ai-panel__suggestion-card {
		transition: none;
	}

	.wsscd-ai-panel__thinking-dot {
		animation: none;
	}
}

/* ==========================================================================
   Consent Modal (first-use opt-in per WordPress.org Guideline 7)
   ========================================================================== */

.wsscd-ai-consent-modal {
	display: none;
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 100010;
}

.wsscd-ai-consent-modal[aria-hidden="false"] {
	display: block;
}

.wsscd-ai-consent-modal__backdrop {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	background: rgba(17, 24, 39, 0.55);
}

.wsscd-ai-consent-modal__dialog {
	position: relative;
	max-width: 460px;
	margin: 12vh auto 0;
	background: #fff;
	border-radius: 12px;
	box-shadow: 0 24px 48px rgba(17, 24, 39, 0.28);
	padding: 28px 32px 24px;
	text-align: center;
}

.wsscd-ai-consent-modal__icon {
	width: 56px;
	height: 56px;
	margin: 0 auto 14px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: linear-gradient(135deg, #e0e7ff 0%, #dbeafe 100%);
	color: var(--wsscd-color-primary);
	border-radius: 50%;
}

.wsscd-ai-consent-modal__title {
	margin: 0 0 10px;
	font-size: 20px;
	font-weight: 600;
	color: #1e1e1e;
	line-height: 1.3;
}

.wsscd-ai-consent-modal__body {
	font-size: 14px;
	line-height: 1.55;
	color: #3c434a;
	text-align: left;
}

.wsscd-ai-consent-modal__body p {
	margin: 0 0 12px;
}

.wsscd-ai-consent-modal__reassure {
	color: var(--wsscd-color-text-muted);
	font-size: 13px;
	font-style: italic;
}

.wsscd-ai-consent-modal__links {
	margin-top: 8px;
	font-size: 12px;
	text-align: center;
}

.wsscd-ai-consent-modal__links a {
	color: var(--wsscd-color-primary);
	text-decoration: none;
}

.wsscd-ai-consent-modal__links a:hover {
	text-decoration: underline;
}

.wsscd-ai-consent-modal__sep {
	color: var(--wsscd-color-text-disabled);
	margin: 0 6px;
}

.wsscd-ai-consent-modal__actions {
	display: flex;
	justify-content: center;
	gap: 10px;
	margin-top: 22px;
}

.wsscd-ai-consent-modal__actions .button {
	min-width: 120px;
}

/* Consent modal: free-tier disclosure line (added 2.0.0). */
.wsscd-ai-consent-modal__tier {
	margin-top: 12px;
	padding: 10px 12px;
	background: var(--wsscd-color-surface);
	border-left: 3px solid var(--wsscd-color-primary);
	border-radius: 4px;
	font-size: 12px;
	line-height: 1.5;
	color: #50575e;
}

/* Panel header: quota badge + upgrade link (added 2.0.0). */
.wsscd-ai-panel__quota {
	display: inline-flex;
	align-items: center;
	padding: 2px 8px;
	border-radius: 999px;
	background: #e9ecef;
	color: var(--wsscd-color-text);
	font-size: 11px;
	font-weight: 600;
	line-height: 1.6;
	white-space: nowrap;
}

.wsscd-ai-panel__quota--warning {
	background: #fff3cd;
	color: #7a5700;
}

.wsscd-ai-panel__quota--danger {
	background: #f8d7da;
	color: #7a1f1f;
}

.wsscd-ai-panel__upgrade {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 10px;
	margin-right: 4px;
	border-radius: 999px;
	background: linear-gradient( 135deg, var(--wsscd-color-primary) 0%, var(--wsscd-color-primary-dark) 100% );
	color: #fff;
	font-size: 11px;
	font-weight: 600;
	text-decoration: none;
	line-height: 1.4;
	transition: filter 0.15s ease, transform 0.15s ease;
}

.wsscd-ai-panel__upgrade:hover,
.wsscd-ai-panel__upgrade:focus {
	color: #fff;
	filter: brightness( 1.08 );
	transform: translateY( -1px );
}

.wsscd-ai-panel__upgrade svg {
	flex-shrink: 0;
}


/* Quota-exceeded chat bubble (added 2.0.0). */
.wsscd-ai-panel__quota-exceeded {
	margin: 8px 0;
	padding: 14px 16px;
	background: linear-gradient( 135deg, #fff8e1 0%, #fff3cd 100% );
	border: 1px solid #ffd54f;
	border-radius: 10px;
	color: #5d4037;
	font-size: 13px;
	line-height: 1.55;
}

.wsscd-ai-panel__quota-exceeded-title {
	display: block;
	margin-bottom: 6px;
	font-size: 14px;
	font-weight: 600;
	color: #3e2723;
}

.wsscd-ai-panel__quota-exceeded-reset {
	display: block;
	margin-top: 4px;
	font-size: 12px;
	color: #8d6e63;
}

.wsscd-ai-panel__quota-exceeded-cta {
	display: inline-block;
	margin-top: 10px;
	padding: 6px 14px;
	background: var(--wsscd-color-primary);
	color: #fff;
	border-radius: 6px;
	text-decoration: none;
	font-size: 12px;
	font-weight: 600;
	transition: background-color 0.15s ease;
}

.wsscd-ai-panel__quota-exceeded-cta:hover,
.wsscd-ai-panel__quota-exceeded-cta:focus {
	background: var(--wsscd-color-primary-dark);
	color: #fff;
}

/* Empty-state example prompt chips (added 2.0.0). */
.wsscd-ai-panel__example-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 12px 16px 4px;
}

.wsscd-ai-panel__example-chip {
	padding: 8px 12px;
	background: #f0f6fc;
	border: 1px solid #c3dbef;
	border-radius: 16px;
	color: #1d4d82;
	font-size: 12px;
	font-family: inherit;
	line-height: 1.4;
	cursor: pointer;
	text-align: left;
	transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.wsscd-ai-panel__example-chip:hover,
.wsscd-ai-panel__example-chip:focus {
	background: #e0eaf6;
	border-color: var(--wsscd-color-primary);
	outline: none;
}

.wsscd-ai-panel__example-chip:active {
	transform: translateY( 1px );
}
