@use '../../tokens/variables';

/* Patterns - Content - Chat Message */
////
/// @group Patterns-Chat_Message
/// Patterns - Content - Chat Message

///
.chat {
	// ─── Component CSS API ─────────────────────────────────────────────
	--osui-chat-message-background: #{variables.$token-bg-neutral-subtle-default};
	--osui-chat-message-border-radius: var(--border-radius-lg, #{variables.$token-shape-soft-lg});
	--osui-chat-message-sent-background: var(--color-primary);
	--osui-chat-message-sent-color: var(--color-text-light);
	--osui-chat-message-status-color: #{variables.$token-text-subtlest};
	// Figma says 18px, which sits exactly between the 16px and 20px steps; 16px keeps
	// the 11px status text at a caption-like 1.45 ratio rather than 1.82.
	--osui-chat-message-status-line-height: #{variables.$token-font-line-height-400};
	// ───────────────────────────────────────────────────────────────────

	display: flex;

	&.right {
		flex-direction: row-reverse;

		.chat {
			&-photo {
				margin-inline-start: variables.$token-space-400;
				margin-inline-end: variables.$token-scale-0;
			}

			&-message {
				background-color: var(--osui-chat-message-sent-background);
				color: var(--osui-chat-message-sent-color);
			}
		}
	}

	&-photo {
		margin-inline-end: variables.$token-space-400;

		// Service Studio Preview
		// Empty placeholders (unclassed div children) collapse and clip the editor's hint;
		// give them room until content is added. The negative margin equals the photo gap, so the
		// placeholder fills avatar plus gap and the message does not move when an avatar is dropped in.
		& > div:empty {
			-servicestudio-margin-right: calc(-1 * #{variables.$token-scale-400});
			-servicestudio-min-height: variables.$token-scale-1600;
			-servicestudio-min-width: variables.$token-scale-1200;
		}

		// The photo gap sits on the left when the message is displayed on the right.
		.right & > div:empty {
			-servicestudio-margin-left: calc(-1 * #{variables.$token-scale-400});
			-servicestudio-margin-right: 0;
		}

		img {
			border-radius: var(--border-radius-rounded);
			height: variables.$token-scale-800;
			object-fit: cover;
			width: variables.$token-scale-800;
		}
	}

	&-message {
		background-color: var(--osui-chat-message-background);
		border-radius: var(--osui-chat-message-border-radius);
		display: flex;
		flex-direction: column;
		max-width: 600px;
		padding: variables.$token-space-300;
		position: relative;
		overflow-wrap: anywhere;

		// Service Studio Preview — see .chat-photo above
		& > div:empty {
			-servicestudio-min-width: variables.$token-scale-4000;
		}

		&-status {
			color: var(--osui-chat-message-status-color);
			display: block;
			font-size: variables.$token-font-size-275;
			line-height: var(--osui-chat-message-status-line-height);
			margin-block-start: variables.$token-space-100;
			width: 100%;

			&.hidden {
				display: none;
			}
		}
	}
}
