/* ══════════════════════════════════════════════════════════════════════════════
   CAUSETTE — widget de messagerie rapide
   ══════════════════════════════════════════════════════════════════════════════ */

.ttm-cst {
	position: fixed;
	bottom: 1.5rem;
	right: 1.5rem;
	z-index: 9990;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 0.75rem;
	pointer-events: none;
}

/* ── Bouton flottant ── */
.ttm-cst__toggle {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--ttm-color-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	font-size: 1.35rem;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	box-shadow: 0 4px 20px rgba(119, 92, 49, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
	transition: transform 0.2s, box-shadow 0.2s;
	pointer-events: all;
	flex-shrink: 0;
}

.ttm-cst__toggle[hidden] { display: none; }

.ttm-cst__toggle:hover {
	transform: scale(1.08);
	box-shadow: 0 6px 28px rgba(119, 92, 49, 0.6), 0 4px 12px rgba(0, 0, 0, 0.35);
}

.ttm-cst__badge {
	position: absolute;
	top: -3px;
	right: -3px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: 10px;
	background: var(--ttm-color-error);
	color: #ffffff;
	font-size: 0.65rem;
	font-weight: 700;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 2px solid var(--color-background, #0b1a22);
	line-height: 1;
	box-sizing: content-box;
	animation: ttm-cst-badge-pulse 2s ease-in-out infinite;
}

.ttm-cst__badge[hidden] {
	display: none;
	animation: none;
}

@keyframes ttm-cst-badge-pulse {
	0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.5); }
	50%       { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
}

/* ── Panel ── */
.ttm-cst__panel {
	width: 340px;
	height: 460px;
	background: var(--ttm-color-surface);
	border: 1px solid var(--ttm-color-border);
	border-radius: 14px;
	box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45), 0 2px 12px rgba(0, 0, 0, 0.2);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	pointer-events: all;
	transform-origin: bottom right;
}

.ttm-cst__panel[hidden] { display: none; }

.ttm-cst__panel:not([hidden]) {
	animation: ttm-cst-panel-in 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes ttm-cst-panel-in {
	from { opacity: 0; transform: scale(0.92) translateY(12px); }
	to   { opacity: 1; transform: scale(1)    translateY(0); }
}

/* ── Views ── */
.ttm-cst__view {
	display: flex;
	flex-direction: column;
	flex: 1;
	overflow: hidden;
}

.ttm-cst__view[hidden] { display: none; }

/* ── Header ── */
.ttm-cst__header {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	padding: 0.65rem 0.85rem;
	border-bottom: 1px solid var(--ttm-color-border);
	background: var(--ttm-color-surface);
	flex-shrink: 0;
	position: relative;
	z-index: 11;
}

.ttm-cst__title {
	font-weight: 700;
	font-size: 0.9rem;
	color: var(--ttm-color-text);
	flex: 1;
	letter-spacing: 0.01em;
}

.ttm-cst__header-actions {
	display: flex;
	align-items: center;
	gap: 0.15rem;
}

.ttm-cst__expand,
.ttm-cst__close-btn,
.ttm-cst__back-btn {
	width: 1.75rem;
	height: 1.75rem;
	border-radius: 50%;
	background: transparent;
	border: none;
	cursor: pointer;
	color: var(--ttm-color-muted);
	font-size: 0.75rem;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s, color 0.15s;
	text-decoration: none;
	flex-shrink: 0;
}

.ttm-cst__expand:hover,
.ttm-cst__close-btn:hover,
.ttm-cst__back-btn:hover {
	background: rgba(255, 255, 255, 0.09);
	color: var(--ttm-color-text);
}

html.light-mode .ttm-cst__expand:hover,
html.light-mode .ttm-cst__close-btn:hover,
html.light-mode .ttm-cst__back-btn:hover {
	background: rgba(0, 0, 0, 0.06);
}

/* ── Inbox list ── */
.ttm-cst__list {
	flex: 1;
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: var(--ttm-scrollbar-thumb) transparent;
}

.ttm-cst__list::-webkit-scrollbar { width: 4px; }
.ttm-cst__list::-webkit-scrollbar-track { background: transparent; }
.ttm-cst__list::-webkit-scrollbar-thumb { background: var(--ttm-scrollbar-thumb); border-radius: 2px; }
.ttm-cst__list::-webkit-scrollbar-thumb:hover { background: rgba(119, 92, 49, 0.6); }

.ttm-cst__loading {
	padding: 1.5rem;
	text-align: center;
	color: var(--ttm-color-muted);
	font-size: 0.875rem;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
}

/* ── Inbox items ── */
.ttm-cst__item {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	width: 100%;
	padding: 0.7rem 0.85rem;
	background: none;
	border: none;
	border-bottom: 1px solid var(--ttm-color-border);
	cursor: pointer;
	text-align: left;
	color: var(--ttm-color-text);
	transition: background 0.12s;
}

.ttm-cst__item:hover {
	background: rgba(255, 255, 255, 0.05);
}

html.light-mode .ttm-cst__item:hover {
	background: rgba(0, 0, 0, 0.04);
}

.ttm-cst__item-menu-btn {
	background: none;
	border: none;
	cursor: pointer;
	color: var(--ttm-color-muted);
	width: 28px;
	height: 28px;
	border-radius: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.1rem;
	letter-spacing: -0.05em;
	flex-shrink: 0;
	line-height: 1;
}

.ttm-cst__item-menu-btn:hover {
	background: rgba(255, 255, 255, 0.1);
	color: var(--ttm-color-text);
}

html.light-mode .ttm-cst__item-menu-btn:hover {
	background: rgba(0, 0, 0, 0.07);
}

.ttm-cst__item-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
}

.ttm-cst__item-info {
	flex: 1;
	min-width: 0;
}

.ttm-cst__item-name {
	font-weight: 500;
	font-size: 0.85rem;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	color: var(--ttm-color-text);
}

.ttm-cst__item-preview {
	font-size: 0.75rem;
	color: var(--ttm-color-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ttm-cst__item-badge {
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	border-radius: 9px;
	background: var(--ttm-color-error);
	color: #ffffff;
	font-size: 0.65rem;
	font-weight: 700;
	line-height: 1;
	border: 2px solid var(--color-background, #0b1a22);
	box-sizing: content-box;
	flex-shrink: 0;
}

/* ── Empty state ── */
.ttm-cst__empty {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	flex: 1;
	padding: 2rem;
	text-align: center;
	color: var(--ttm-color-muted);
	font-size: 0.875rem;
	gap: 0.5rem;
}

/* ── Conversation view ── */
.ttm-cst__partner-avatar {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
}

.ttm-cst__partner-name {
	font-weight: 600;
	font-size: 0.875rem;
	color: var(--ttm-color-text);
	flex: 1;
	min-width: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ttm-cst__partner-link {
	display: flex;
	flex-shrink: 0;
	border-radius: 50%;
	text-decoration: none;
}

.ttm-cst__partner-link:hover .ttm-cst__partner-avatar {
	opacity: 0.8;
}

.ttm-conv-partner-link {
	display: flex;
	flex-shrink: 0;
	border-radius: 50%;
	text-decoration: none;
}

.ttm-conv-partner-link:hover .ttm-conv-partner-avatar {
	opacity: 0.8;
}

/* ── Messages ── */
.ttm-cst__messages {
	flex: 1;
	overflow-y: auto;
	padding: 0.75rem;
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	scrollbar-width: thin;
	scrollbar-color: var(--ttm-scrollbar-thumb) transparent;
}

.ttm-cst__messages::-webkit-scrollbar { width: 4px; }
.ttm-cst__messages::-webkit-scrollbar-track { background: transparent; }
.ttm-cst__messages::-webkit-scrollbar-thumb { background: var(--ttm-scrollbar-thumb); border-radius: 2px; }
.ttm-cst__messages::-webkit-scrollbar-thumb:hover { background: rgba(119, 92, 49, 0.6); }

/* ── Zone de saisie ── */
.ttm-cst__compose {
	padding: 0.6rem 0.65rem;
	border-top: 1px solid var(--ttm-color-border);
	background: var(--ttm-color-surface);
	flex-shrink: 0;
}

.ttm-cst__compose-inner {
	display: flex;
	align-items: flex-end;
	gap: 0.3rem;
	background: var(--ttm-color-bg);
	border: 1px solid var(--ttm-color-border);
	border-radius: 0.875rem;
	padding: 0.3rem 0.35rem 0.3rem 0.4rem;
	transition: border-color 0.2s;
}

.ttm-cst__compose-inner:focus-within {
	border-color: var(--ttm-color-primary);
}

.ttm-cst__input-wrap {
	flex: 1;
	position: relative;
	min-width: 0;
}

.ttm-cst__char-count {
	position: absolute;
	bottom: 4px;
	right: 6px;
	font-size: 0.62rem;
	color: var(--ttm-color-muted);
	pointer-events: none;
	line-height: 1;
	opacity: 0.4;
	user-select: none;
}

.ttm-cst__char-count--warning {
	color: var(--ttm-color-error);
	opacity: 0.85;
}

.ttm-cst__emoji-toggle {
	flex-shrink: 0;
	align-self: center;
	width: 2rem;
	height: 2rem;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.06);
	border: 1px solid var(--ttm-color-border);
	cursor: pointer;
	font-size: 1rem;
	line-height: 1;
	padding: 0;
	transition: background 0.15s, border-color 0.15s;
}

.ttm-cst__emoji-toggle:hover {
	background: rgba(255, 255, 255, 0.14);
	border-color: rgba(255, 255, 255, 0.2);
}

html.light-mode .ttm-cst__emoji-toggle {
	background: rgba(0, 0, 0, 0.05);
}

html.light-mode .ttm-cst__emoji-toggle:hover {
	background: rgba(0, 0, 0, 0.10);
}

.ttm-cst__emoji-close {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.55);
	color: #fff;
	border: 1px solid rgba(255, 255, 255, 0.18);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.75rem;
	transition: background 0.15s;
}

.ttm-cst__emoji-close:hover {
	background: rgba(0, 0, 0, 0.8);
}

.ttm-cst__emoji-close[hidden] { display: none; }

.ttm-cst__input {
	width: 100%;
	box-sizing: border-box;
	resize: none;
	background: transparent;
	border: none;
	border-radius: 0;
	color: var(--ttm-color-text);
	padding: 0.4rem 1.5rem 0.4rem 0.25rem;
	font-size: 0.85rem;
	font-family: inherit;
	line-height: 1.35;
	min-height: 32px;
	max-height: 100px;
	overflow-y: hidden;
}

.ttm-cst__input::placeholder {
	color: var(--ttm-color-muted);
	opacity: 0.7;
}

.ttm-cst__input:focus {
	outline: none;
}

.ttm-cst__send {
	width: 1.875rem;
	height: 1.875rem;
	border-radius: 50%;
	background: var(--ttm-color-primary);
	color: #fff;
	border: none;
	cursor: pointer;
	font-size: 0.75rem;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	align-self: flex-end;
	transition: opacity 0.15s, transform 0.15s;
}

.ttm-cst__send:hover {
	transform: scale(1.08);
}

.ttm-cst__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
}

@media (max-width: 640px) {
	.ttm-cst__panel {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100%;
		border-radius: 0;
		border: none;
		z-index: 9991;
	}

	.ttm-cst__panel:not([hidden]) {
		animation: none;
	}
}
