<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="8dp">

    <!-- Reply Indicator (for both sent and received messages) -->
    <LinearLayout
        android:id="@+id/replyIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="4dp"
        android:layout_marginEnd="8dp"
        android:background="@color/reply_background"
        android:orientation="vertical"
        android:padding="8dp"
        android:visibility="gone"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:visibility="visible">

        <TextView
            android:id="@+id/replySenderText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/text_secondary"
            android:textSize="12sp"
            android:textStyle="bold"
            tools:text="John Smith" />

        <TextView
            android:id="@+id/replyMessageText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="2"
            android:textColor="@color/text_secondary"
            android:textSize="12sp"
            tools:text="Original message text..." />

    </LinearLayout>

    <!-- Sent Message Bubble -->
    <androidx.cardview.widget.CardView
        android:id="@+id/sentMessageCard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="64dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="4dp"
        android:visibility="gone"
        app:cardBackgroundColor="@color/message_sent"
        app:cardCornerRadius="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/replyIndicator"
        tools:visibility="visible">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/sentReplyIndicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="4dp"
                android:layout_marginBottom="2dp"
                android:background="@color/reply_background"
                android:orientation="vertical"
                android:padding="4dp"
                android:visibility="gone"
                tools:visibility="visible">

                <TextView
                    android:id="@+id/sentReplySenderText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/text_secondary"
                    android:textSize="12sp"
                    android:textStyle="bold"
                    tools:text="John Smith" />

                <TextView
                    android:id="@+id/sentReplyMessageText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:maxLines="2"
                    android:textColor="@color/text_secondary"
                    android:textSize="12sp"
                    tools:text="Original message text..." />

            </LinearLayout>

            <!-- File Attachment for Sent Messages -->
            <LinearLayout
                android:id="@+id/sentFileLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="12dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="12dp"
                android:layout_marginBottom="4dp"
                android:gravity="center_horizontal"
                android:orientation="vertical"
                android:visibility="gone"
                tools:visibility="visible">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="4dp"
                    android:clickable="true"
                    android:focusable="true"
                    android:text="📎"
                    android:textSize="24sp" />

                <TextView
                    android:id="@+id/sentFileNameText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:focusable="true"
                    android:textColor="@color/message_sent_text"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    tools:text="document.pdf" />

            </LinearLayout>

            <!-- Image Preview for Sent Messages -->
            <ImageView
                android:id="@+id/sentImagePreview"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_marginStart="12dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="12dp"
                android:layout_marginBottom="4dp"
                android:adjustViewBounds="true"
                android:clickable="true"
                android:focusable="true"
                android:scaleType="centerCrop"
                android:visibility="gone"
                tools:src="@drawable/ic_launcher_foreground"
                tools:visibility="visible" />

            <TextView
                android:id="@+id/sentMessageText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxWidth="280dp"
                android:padding="12dp"
                android:textAlignment="textEnd"
                android:textColor="@color/message_sent_text"
                android:textSize="16sp"
                tools:text="This is a sent message" />

            <!-- Reactions for Sent Messages -->
            <LinearLayout
                android:id="@+id/sentReactionsContainer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="4dp"
                android:orientation="horizontal"
                android:visibility="gone"
                tools:visibility="visible">

                <!-- Reactions will be added dynamically -->

            </LinearLayout>

        </LinearLayout>

    </androidx.cardview.widget.CardView>

    <!-- Received Message Bubble -->
    <androidx.cardview.widget.CardView
        android:id="@+id/receivedMessageCard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="64dp"
        android:layout_marginBottom="4dp"
        android:visibility="gone"
        app:cardBackgroundColor="@color/message_received"
        app:cardCornerRadius="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/replyIndicator"
        tools:visibility="visible">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/receivedReplyIndicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="4dp"
                android:layout_marginBottom="2dp"
                android:background="@color/reply_background"
                android:orientation="vertical"
                android:padding="4dp"
                android:visibility="gone"
                tools:visibility="visible">

                <TextView
                    android:id="@+id/receivedReplySenderText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/text_secondary"
                    android:textSize="12sp"
                    android:textStyle="bold"
                    tools:text="John Smith" />

                <TextView
                    android:id="@+id/receivedReplyMessageText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:maxLines="2"
                    android:textColor="@color/text_secondary"
                    android:textSize="12sp"
                    tools:text="Original message text..." />

            </LinearLayout>

            <!-- File Attachment for Received Messages -->
            <LinearLayout
                android:id="@+id/receivedFileLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="12dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="12dp"
                android:layout_marginBottom="4dp"
                android:gravity="center_horizontal"
                android:orientation="vertical"
                android:visibility="gone"
                tools:visibility="visible">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="4dp"
                    android:clickable="true"
                    android:focusable="true"
                    android:text="📎"
                    android:textSize="24sp" />

                <TextView
                    android:id="@+id/receivedFileNameText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:focusable="true"
                    android:textColor="@color/message_received_text"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    tools:text="document.pdf" />

            </LinearLayout>

            <!-- Image Preview for Received Messages -->
            <ImageView
                android:id="@+id/receivedImagePreview"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_marginStart="12dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="12dp"
                android:layout_marginBottom="4dp"
                android:adjustViewBounds="true"
                android:clickable="true"
                android:focusable="true"
                android:scaleType="centerCrop"
                android:visibility="gone"
                tools:src="@drawable/ic_launcher_foreground"
                tools:visibility="visible" />

            <TextView
                android:id="@+id/receivedMessageText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxWidth="280dp"
                android:padding="12dp"
                android:textColor="@color/message_received_text"
                android:textSize="16sp"
                tools:text="This is a received message" />

            <!-- Reactions for Received Messages -->
            <LinearLayout
                android:id="@+id/receivedReactionsContainer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="4dp"
                android:orientation="horizontal"
                android:visibility="gone"
                tools:visibility="visible">

                <!-- Reactions will be added dynamically -->

            </LinearLayout>

        </LinearLayout>

    </androidx.cardview.widget.CardView>

    <!-- Sender Name (for received messages) -->
    <TextView
        android:id="@+id/senderNameText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="4dp"
        android:textColor="@color/text_secondary"
        android:textSize="10sp"
        android:visibility="gone"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/receivedMessageCard"
        tools:text="John Doe"
        tools:visibility="visible" />

    <!-- Timestamp -->
    <TextView
        android:id="@+id/timestampText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:maxLines="1"
        android:textAlignment="textEnd"
        android:textColor="@color/text_hint"
        android:textSize="10sp"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/sentMessageCard"
        tools:text="Я (17.01.2026 12:30) ✓"
        tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>
