<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/surface_background">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/surface_background"
        app:navigationIcon="@drawable/ic_round_back_button">

        <TextView
            android:id="@+id/tvToolbarTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cow Selection"
            android:textSize="20sp"
            android:textStyle="bold"
            android:textColor="@color/text_primary"/>

    </androidx.appcompat.widget.Toolbar>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="24dp">

            <TextView
                android:id="@+id/tvAddCowDetails"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Add Cow Details"
                android:textSize="24sp"
                android:textStyle="bold"
                android:textColor="@color/text_primary"
                android:layout_marginBottom="24dp"/>

            <!-- Form Fields -->
            
            <TextView
                android:id="@+id/tvLabelSpecies"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Species"
                android:textColor="@color/text_secondary"
                android:layout_marginBottom="4dp"/>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/tilSpecies"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="16dp"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
                app:boxCornerRadiusTopStart="12dp"
                app:boxCornerRadiusTopEnd="12dp"
                app:boxCornerRadiusBottomStart="12dp"
                app:boxCornerRadiusBottomEnd="12dp"
                app:boxStrokeColor="@color/text_tertiary">

                <AutoCompleteTextView
                    android:id="@+id/spinnerSpecies"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="none"
                    android:textColor="@color/text_primary"/>
            </com.google.android.material.textfield.TextInputLayout>

            <TextView
                android:id="@+id/tvLabelBreed"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Breed"
                android:textColor="@color/text_secondary"
                android:layout_marginBottom="4dp"/>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/tilBreed"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="16dp"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
                app:boxCornerRadiusTopStart="12dp"
                app:boxCornerRadiusTopEnd="12dp"
                app:boxCornerRadiusBottomStart="12dp"
                app:boxCornerRadiusBottomEnd="12dp"
                app:boxStrokeColor="@color/text_tertiary">

                <AutoCompleteTextView
                    android:id="@+id/spinnerBreed"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="none"
                    android:textColor="@color/text_primary"/>
            </com.google.android.material.textfield.TextInputLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:baselineAligned="false"
                android:layout_marginBottom="16dp">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginEnd="8dp"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/tvLabelAge"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Age (Years)"
                        android:textColor="@color/text_secondary"
                        android:layout_marginBottom="4dp"/>

                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/tilAge"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        app:boxCornerRadiusTopStart="12dp"
                        app:boxCornerRadiusTopEnd="12dp"
                        app:boxCornerRadiusBottomStart="12dp"
                        app:boxCornerRadiusBottomEnd="12dp"
                        app:boxStrokeColor="@color/text_tertiary">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/etAge"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:inputType="number"
                            android:textColor="@color/text_primary"/>
                    </com.google.android.material.textfield.TextInputLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginStart="8dp"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/tvLabelMilk"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Milk Yield (L)"
                        android:textColor="@color/text_secondary"
                        android:layout_marginBottom="4dp"/>

                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/tilMilk"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        app:boxCornerRadiusTopStart="12dp"
                        app:boxCornerRadiusTopEnd="12dp"
                        app:boxCornerRadiusBottomStart="12dp"
                        app:boxCornerRadiusBottomEnd="12dp"
                        app:boxStrokeColor="@color/text_tertiary">

                        <com.google.android.material.textfield.TextInputEditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:inputType="numberDecimal"
                            android:textColor="@color/text_primary"/>
                    </com.google.android.material.textfield.TextInputLayout>
                </LinearLayout>
            </LinearLayout>

            <TextView
                android:id="@+id/tvLabelCalving"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Calving Number"
                android:textColor="@color/text_secondary"
                android:layout_marginBottom="4dp"/>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/tilCalving"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="16dp"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                app:boxCornerRadiusTopStart="12dp"
                app:boxCornerRadiusTopEnd="12dp"
                app:boxCornerRadiusBottomStart="12dp"
                app:boxCornerRadiusBottomEnd="12dp"
                app:boxStrokeColor="@color/text_tertiary">

                <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="number"
                    android:textColor="@color/text_primary"/>
            </com.google.android.material.textfield.TextInputLayout>

            <TextView
                android:id="@+id/tvReproductiveStatus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Reproductive Status"
                android:textColor="@color/text_secondary"
                android:layout_marginBottom="8dp"/>

            <RadioGroup
                android:id="@+id/rgReproductiveStatus"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginBottom="16dp">

                <RadioButton
                    android:id="@+id/rbPregnant"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Pregnant"
                    android:layout_marginEnd="16dp"
                    android:textColor="@color/text_primary"/>

                <RadioButton
                    android:id="@+id/rbCalved"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Calved"
                    android:layout_marginEnd="16dp"
                    android:textColor="@color/text_primary"/>

                <RadioButton
                    android:id="@+id/rbNone"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="None"
                    android:textColor="@color/text_primary"/>
            </RadioGroup>
            
            <TextView
                android:id="@+id/tvLabelDescription"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Description"
                android:textColor="@color/text_secondary"
                android:layout_marginBottom="4dp"/>

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/tilDescription"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="24dp"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                app:boxCornerRadiusTopStart="12dp"
                app:boxCornerRadiusTopEnd="12dp"
                app:boxCornerRadiusBottomStart="12dp"
                app:boxCornerRadiusBottomEnd="12dp"
                app:boxStrokeColor="@color/text_tertiary">

                <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textMultiLine"
                    android:minLines="3"
                    android:textColor="@color/text_primary"/>
            </com.google.android.material.textfield.TextInputLayout>

            <!-- Upload Photos -->
            <TextView
                android:id="@+id/tvUploadPhotos"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Upload Photos"
                android:textSize="18sp"
                android:textStyle="bold"
                android:textColor="@color/text_primary"
                android:layout_marginBottom="16dp"/>

            <GridLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnCount="2"
                android:rowCount="4"
                android:alignmentMode="alignMargins"
                android:columnOrderPreserved="false"
                android:layout_marginBottom="24dp">

                <!-- Front View -->
                <androidx.cardview.widget.CardView
                    android:layout_width="0dp"
                    android:layout_height="100dp"
                    android:layout_columnWeight="1"
                    android:layout_margin="8dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="2dp">
                    <LinearLayout
                        android:id="@+id/btnfront"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:gravity="center"
                        android:background="@color/input_background"
                        android:clickable="true"
                        android:focusable="true">
                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_camera"
                            app:tint="@color/icon_tint_primary"/>
                        <TextView
                            android:id="@+id/tvFrontView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Front View"
                            android:textSize="12sp"
                            android:textColor="@color/text_secondary"
                            android:layout_marginTop="4dp"/>
                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <!-- Rear View (Back) -->
                <androidx.cardview.widget.CardView
                    android:layout_width="0dp"
                    android:layout_height="100dp"
                    android:layout_columnWeight="1"
                    android:layout_margin="8dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="2dp">
                    <LinearLayout
                        android:id="@+id/btnback"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:gravity="center"
                        android:background="@color/input_background"
                        android:clickable="true"
                        android:focusable="true">
                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_camera"
                            app:tint="@color/icon_tint_primary"/>
                        <TextView
                            android:id="@+id/tvRearView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Rear View"
                            android:textSize="12sp"
                            android:textColor="@color/text_secondary"
                            android:layout_marginTop="4dp"/>
                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <!-- Left Side -->
                <androidx.cardview.widget.CardView
                    android:layout_width="0dp"
                    android:layout_height="100dp"
                    android:layout_columnWeight="1"
                    android:layout_margin="8dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="2dp">
                    <LinearLayout
                        android:id="@+id/btnleft"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:gravity="center"
                        android:background="@color/input_background"
                        android:clickable="true"
                        android:focusable="true">
                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_camera"
                            app:tint="@color/icon_tint_primary"/>
                        <TextView
                            android:id="@+id/tvLeftSide"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Left Side"
                            android:textSize="12sp"
                            android:textColor="@color/text_secondary"
                            android:layout_marginTop="4dp"/>
                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <!-- Right Side -->
                <androidx.cardview.widget.CardView
                    android:layout_width="0dp"
                    android:layout_height="100dp"
                    android:layout_columnWeight="1"
                    android:layout_margin="8dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="2dp">
                    <LinearLayout
                        android:id="@+id/btnright"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:gravity="center"
                        android:background="@color/input_background"
                        android:clickable="true"
                        android:focusable="true">
                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_camera"
                            app:tint="@color/icon_tint_primary"/>
                        <TextView
                            android:id="@+id/tvRightSide"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Right Side"
                            android:textSize="12sp"
                            android:textColor="@color/text_secondary"
                            android:layout_marginTop="4dp"/>
                    </LinearLayout>
                </androidx.cardview.widget.CardView>
                
                <!-- Left Angle -->
                 <androidx.cardview.widget.CardView
                    android:layout_width="0dp"
                    android:layout_height="100dp"
                    android:layout_columnWeight="1"
                    android:layout_margin="8dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="2dp">
                    <LinearLayout
                        android:id="@+id/btnleftangle"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:gravity="center"
                        android:background="@color/input_background"
                        android:clickable="true"
                        android:focusable="true">
                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_camera"
                            app:tint="@color/icon_tint_primary"/>
                        <TextView
                            android:id="@+id/tvLeftAngle"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Left Angle"
                            android:textSize="12sp"
                            android:textColor="@color/text_secondary"
                            android:layout_marginTop="4dp"/>
                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <!-- Right Angle -->
                 <androidx.cardview.widget.CardView
                    android:layout_width="0dp"
                    android:layout_height="100dp"
                    android:layout_columnWeight="1"
                    android:layout_margin="8dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="2dp">
                    <LinearLayout
                        android:id="@+id/btnrightangle"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:gravity="center"
                        android:background="@color/input_background"
                        android:clickable="true"
                        android:focusable="true">
                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_camera"
                            app:tint="@color/icon_tint_primary"/>
                        <TextView
                            android:id="@+id/tvRightAngle"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Right Angle"
                            android:textSize="12sp"
                            android:textColor="@color/text_secondary"
                            android:layout_marginTop="4dp"/>
                    </LinearLayout>
                </androidx.cardview.widget.CardView>
                
                <!-- Angle View (Top) - Fixed Size, No Span -->
                 <androidx.cardview.widget.CardView
                    android:layout_width="0dp"
                    android:layout_height="100dp"
                    android:layout_columnWeight="1"
                    android:layout_margin="8dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="2dp">
                    <LinearLayout
                        android:id="@+id/btnangle"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:gravity="center"
                        android:background="@color/input_background"
                        android:clickable="true"
                        android:focusable="true">
                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_camera"
                            app:tint="@color/icon_tint_primary"/>
                        <TextView
                            android:id="@+id/tvAngleView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Angle View"
                            android:textSize="12sp"
                            android:textColor="@color/text_secondary"
                            android:layout_marginTop="4dp"/>
                    </LinearLayout>
                </androidx.cardview.widget.CardView>
            </GridLayout>
            
            <!-- Container for showing captured thumbnails -->
            <LinearLayout
                android:id="@+id/currentCowImagesContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginBottom="24dp"/>

            <!-- Bottom Buttons -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                
                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btnNewCow"
                    android:layout_width="0dp"
                    android:layout_height="56dp"
                    android:layout_weight="1"
                    android:text="Save Profile"
                    android:textSize="16sp"
                    android:textStyle="bold"
                    android:textColor="@color/white"
                    app:cornerRadius="12dp"
                    app:backgroundTint="@color/earthy"
                    android:layout_marginEnd="8dp"/>
                    
                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btnCancel"
                    android:layout_width="0dp"
                    android:layout_height="56dp"
                    android:layout_weight="1"
                    android:text="Cancel"
                    android:textSize="16sp"
                    android:textStyle="bold"
                    android:textColor="@color/icon_tint_primary"
                    app:cornerRadius="12dp"
                    app:backgroundTint="@color/input_background"
                    app:strokeColor="@color/icon_tint_primary"
                    app:strokeWidth="1dp"
                    android:layout_marginStart="8dp"/>
            </LinearLayout>

            <!-- Hidden TextView for Cow Name logic compatibility -->
            <TextView
                android:id="@+id/tvCowName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"/>

        </LinearLayout>
    </ScrollView>
</LinearLayout>