/* ==========================================================
   Cluster Minit · Dedi chat
   Stile "totem" adattato ai design token del sito Cluster.
   ========================================================== */

.cm-dedi {
	--cm-dedi-black: var(--cm-black, #000);
	--cm-dedi-white: var(--cm-white, #fff);
	--cm-dedi-yellow: var(--cm-yellow, #eaff57);
	--cm-dedi-lime: var(--cm-lime, #e6ff64);
	--cm-dedi-radius: var(--cm-radius-card, 20px);
	max-width: 800px;
	margin: 0 auto;
	background: var(--cm-dedi-yellow);
	border: 1px solid var(--cm-dedi-black);
	border-radius: var(--cm-dedi-radius);
	overflow: hidden;
}

/* ---------- messages ---------- */

.cm-dedi__messages {
	height: 420px;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 20px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.cm-dedi__message {
	max-width: 85%;
	padding: 12px 15px;
	font-size: 15px;
	line-height: 1.55;
	overflow-wrap: anywhere;
	animation: cm-dedi-in 0.28s ease both;
}

.cm-dedi__message--ai {
	align-self: flex-start;
	background: var(--cm-dedi-white);
	border: 1px solid var(--cm-dedi-black);
	border-radius: 18px 18px 18px 4px;
}

.cm-dedi__message--user {
	align-self: flex-end;
	background: var(--cm-dedi-black);
	color: var(--cm-dedi-white);
	border-radius: 18px 18px 4px 18px;
}

.cm-dedi__message--error {
	border-color: #d63638;
	color: #d63638;
}

@keyframes cm-dedi-in {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ---------- markdown inside AI bubbles ---------- */

.cm-dedi__message p { margin: 0 0 8px; }
.cm-dedi__message p:last-child { margin-bottom: 0; }
.cm-dedi__message strong { font-weight: 700; }
.cm-dedi__message em { font-style: italic; }
.cm-dedi__message ul,
.cm-dedi__message ol { margin: 6px 0; padding-left: 20px; }
.cm-dedi__message li { margin-bottom: 4px; }
.cm-dedi__message h4 { margin: 10px 0 6px; font-size: 15px; font-weight: 700; }
.cm-dedi__message h4:first-child { margin-top: 0; }
.cm-dedi__message a { color: inherit; text-decoration: underline; }
.cm-dedi__message code {
	background: var(--cm-dedi-lime);
	border: 1px solid rgba(0, 0, 0, 0.15);
	padding: 1px 5px;
	border-radius: 6px;
	font-size: 0.9em;
}

.cm-dedi__ref {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 15px;
	height: 15px;
	padding: 0 3px;
	margin: 0 1px;
	vertical-align: super;
	font-size: 9px;
	font-weight: 700;
	line-height: 1;
	font-style: normal;
	background: var(--cm-dedi-black);
	color: var(--cm-dedi-yellow);
	border-radius: 99px;
}

/* ---------- thinking (ragionamento) ---------- */

.cm-dedi__thinking {
	margin: 0 0 10px;
	border: 1px dashed rgba(0, 0, 0, 0.25);
	border-radius: 12px;
	overflow: hidden;
}

.cm-dedi__thinking summary {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 7px 11px;
	font-size: 12px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.4px;
	color: rgba(0, 0, 0, 0.55);
	cursor: pointer;
	list-style: none;
	user-select: none;
}

.cm-dedi__thinking summary::-webkit-details-marker { display: none; }

.cm-dedi__thinking-chevron {
	margin-left: auto;
	width: 10px;
	height: 10px;
	border-right: 1.5px solid currentColor;
	border-bottom: 1.5px solid currentColor;
	transform: rotate(45deg) translate(-1px, -1px);
	transition: transform 0.2s;
}

.cm-dedi__thinking[open] .cm-dedi__thinking-chevron {
	transform: rotate(225deg) translate(-1px, -1px);
}

.cm-dedi__thinking-body {
	padding: 10px 11px;
	border-top: 1px dashed rgba(0, 0, 0, 0.2);
	font-size: 12px;
	line-height: 1.6;
	color: rgba(0, 0, 0, 0.6);
	white-space: pre-wrap;
	max-height: 180px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* ---------- typing indicator ---------- */

.cm-dedi__message--typing {
	padding: 14px 16px;
}

.cm-dedi__dots {
	display: inline-flex;
	align-items: center;
	gap: 5px;
}

.cm-dedi__dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--cm-dedi-black);
	animation: cm-dedi-typing 1.2s ease-in-out infinite;
}

.cm-dedi__dot:nth-child(2) { animation-delay: 0.2s; }
.cm-dedi__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes cm-dedi-typing {
	0%, 60%, 100% { opacity: 0.25; transform: scale(1); }
	30%           { opacity: 1;    transform: scale(1.25); }
}

/* ---------- input row ---------- */

.cm-dedi__form {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	border-top: 1px solid var(--cm-dedi-black);
	background: var(--cm-dedi-yellow);
}

.cm-dedi__avatar {
	flex-shrink: 0;
	display: inline-flex;
	width: 44px;
	height: 36px;
	color: var(--cm-dedi-black);
}

.cm-dedi__avatar svg {
	width: 100%;
	height: 100%;
}

.cm-dedi__input {
	flex: 1;
	min-width: 0;
	background: var(--cm-dedi-white);
	border: 1px solid var(--cm-dedi-black);
	border-radius: 99px;
	padding: 12px 16px;
	color: var(--cm-dedi-black);
	font-size: 15px;
	font-family: inherit;
	outline: none;
}

.cm-dedi__input:focus {
	box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15);
}

.cm-dedi__input::placeholder { color: rgba(0, 0, 0, 0.45); }

.cm-dedi__send {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	background: var(--cm-dedi-black);
	color: var(--cm-dedi-white);
	border: 1px solid var(--cm-dedi-black);
	border-radius: 99px;
	padding: 12px 22px;
	font-family: inherit;
	font-size: 14px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.4px;
	cursor: pointer;
	transition: background 0.2s, color 0.2s, opacity 0.2s;
}

.cm-dedi__send:hover:not(:disabled) {
	background: var(--cm-dedi-white);
	color: var(--cm-dedi-black);
}

.cm-dedi__input:disabled,
.cm-dedi__send:disabled {
	opacity: 0.55;
	cursor: progress;
}

/* ---------- Dedi avatar animations ---------- */

.cm-dedi--idle .cm-dedi__avatar #cm-dedi-eye-left,
.cm-dedi--idle .cm-dedi__avatar #cm-dedi-eye-right {
	animation: cm-dedi-blink-idle 6s infinite;
}

.cm-dedi--thinking .cm-dedi__avatar #cm-dedi-eye-left,
.cm-dedi--thinking .cm-dedi__avatar #cm-dedi-eye-right {
	animation: cm-dedi-blink 2s infinite, cm-dedi-look 2s infinite;
}

.cm-dedi--speaking .cm-dedi__avatar #cm-dedi-eye-left,
.cm-dedi--speaking .cm-dedi__avatar #cm-dedi-eye-right {
	animation: cm-dedi-blink 2s infinite;
}

.cm-dedi--speaking .cm-dedi__avatar #cm-dedi-mouth {
	animation: cm-dedi-speak 0.5s infinite;
}

.cm-dedi--error .cm-dedi__avatar #cm-dedi-eye-left,
.cm-dedi--error .cm-dedi__avatar #cm-dedi-eye-right {
	animation: none;
}

@keyframes cm-dedi-blink-idle {
	0%, 91%, 100% { height: 22.0675px; }
	94%           { height: 2px; }
	97%           { height: 22.0675px; }
}

@keyframes cm-dedi-blink {
	0%   { height: 22.0675px; transform: translate(0, 0); }
	10%  { height: 2px;       transform: translate(0, 0); }
	14%  { height: 22.0675px; transform: translate(0, 0); }
	25%  { height: 22.0675px; transform: translate(-1px, 0); }
	50%  { height: 22.0675px; transform: translate(1px, 0); }
	75%  { height: 22.0675px; transform: translate(-1px, 0); }
	100% { height: 22.0675px; transform: translate(0, 0); }
}

@keyframes cm-dedi-look {
	0%, 100% { transform: translate(0, -20px); }
	25%      { transform: translate(-10px, -25px); }
	50%      { transform: translate(0, -30px); }
	75%      { transform: translate(10px, -25px); }
}

@keyframes cm-dedi-speak {
	0%, 100% { height: 5px;  transform: translateY(0) rotate(0deg); }
	25%      { height: 13px; transform: translateY(-2px) rotate(-2deg); }
	50%      { height: 5px;  transform: translateY(2px) rotate(2deg); }
	75%      { height: 12px; transform: translateY(-1px) rotate(-1deg); }
}

/* ---------- responsive ---------- */

@media (max-width: 600px) {
	.cm-dedi__messages { height: 60vh; padding: 14px; }
	.cm-dedi__message { max-width: 92%; }
	.cm-dedi__avatar { display: none; }
	.cm-dedi__send { padding: 12px 16px; }
}
