<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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="match_parent"
    android:fillViewport="true"
    android:overScrollMode="never"
    android:scrollbars="none"
    android:background="#F5F5F5">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        tools:context=".PinActivity">

        <!-- Red Status Bar (Override purple) -->
        <View
            android:id="@+id/red_status_bar"
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:background="#E31937"
            app:layout_constraintTop_toTopOf="parent"/>

        <!-- Red Background Header (Extended height untuk back navigation) -->
        <View
            android:id="@+id/red_header_background"
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:background="#E31937"
            app:layout_constraintTop_toBottomOf="@id/red_status_bar"/>

        <!-- Header with Back Navigation -->
        <LinearLayout
            android:id="@+id/back_navigation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:layout_marginStart="16dp"
            android:layout_marginBottom="5dp"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:padding="8dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/red_status_bar">

            <!-- Back Arrow -->
            <ImageView
                android:id="@+id/backArrow"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:src="@drawable/ic_arrow_back"
                android:contentDescription="Back" />

            <!-- Title Text -->
            <TextView
                android:id="@+id/toolbarTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:text="Kembali"
                android:textColor="@android:color/white"
                android:textSize="12sp"
                android:fontFamily="@font/inter"/>

        </LinearLayout>

        <!-- PIN Card -->
        <androidx.cardview.widget.CardView
            android:id="@+id/pin_card"
            android:layout_width="match_parent"
            android:layout_height="191dp"
            android:layout_margin="16dp"
            android:layout_marginTop="5dp"
            app:cardBackgroundColor="#3498DB"
            app:cardCornerRadius="12dp"
            app:cardElevation="8dp"
            app:layout_constraintTop_toBottomOf="@id/back_navigation">

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

                <!-- Title Text -->
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="SILAKAN MASUKAN PIN"
                    android:textColor="@android:color/white"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    android:fontFamily="@font/inter"
                    android:layout_marginBottom="24dp"
                    android:gravity="center"
                    android:textAlignment="center"/>

                <!-- PIN Input Display -->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_marginBottom="8dp"
                    android:gravity="center">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@android:color/white"
                        android:textSize="20sp"
                        android:textStyle="bold"
                        android:fontFamily="@font/inter"
                        android:layout_marginEnd="8dp"
                        android:layout_gravity="center_vertical" />                    

                    <EditText
                        android:id="@+id/editTextPin"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:background="@android:color/transparent"
                        android:textColor="@android:color/white"
                        android:textColorHint="#80FFFFFF"
                        android:textSize="20sp"
                        android:textStyle="bold"
                        android:fontFamily="@font/inter"
                        android:hint=""
                        android:inputType="none"
                        android:focusable="false"
                        android:clickable="false"
                        android:cursorVisible="false"
                        android:text=""
                        android:gravity="center"
                        android:textAlignment="center"
                        android:paddingBottom="4dp" />
                    
                </LinearLayout>

                <!-- White Underline -->
                <View
                    android:layout_width="match_parent"
                    android:layout_height="2dp"
                    android:background="@android:color/white"
                    android:layout_marginBottom="16dp" />

            </LinearLayout>
        </androidx.cardview.widget.CardView>

        <!-- Numpad Grid -->
        <GridLayout
            android:id="@+id/numpad_grid"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:columnCount="3"
            android:rowCount="4"
            android:layout_margin="16dp"
            android:layout_marginTop="32dp"
            app:layout_constraintTop_toBottomOf="@id/pin_card">

            <!-- Row 1: 1, 2, 3 -->
            <TextView
                android:id="@+id/btn1"
                style="@style/NumpadButton"
                android:text="1"/>

            <TextView
                android:id="@+id/btn2"
                style="@style/NumpadButton"
                android:text="2"/>

            <TextView
                android:id="@+id/btn3"
                style="@style/NumpadButton"
                android:text="3"/>

            <!-- Row 2: 4, 5, 6 -->
            <TextView
                android:id="@+id/btn4"
                style="@style/NumpadButton"
                android:text="4"/>

            <TextView
                android:id="@+id/btn5"
                style="@style/NumpadButton"
                android:text="5"/>

            <TextView
                android:id="@+id/btn6"
                style="@style/NumpadButton"
                android:text="6"/>

            <!-- Row 3: 7, 8, 9 -->
            <TextView
                android:id="@+id/btn7"
                style="@style/NumpadButton"
                android:text="7"/>

            <TextView
                android:id="@+id/btn8"
                style="@style/NumpadButton"
                android:text="8"/>

            <TextView
                android:id="@+id/btn9"
                style="@style/NumpadButton"
                android:text="9"/>

            <!-- Row 4: 000, 0, Delete -->
            <TextView
                android:id="@+id/btn000"
                style="@style/NumpadButton"
                android:text="000"/>

            <TextView
                android:id="@+id/btn0"
                style="@style/NumpadButton"
                android:text="0"/>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_columnWeight="1"
                android:layout_margin="8dp"
                android:gravity="center">

                <ImageView
                    android:id="@+id/btnDelete"
                    android:layout_width="48dp"
                    android:layout_height="48dp"
                    android:src="@drawable/ic_backspace"
                    android:background="?android:attr/selectableItemBackgroundBorderless"
                    android:padding="12dp"
                    app:tint="#666666"/>
            </LinearLayout>
        </GridLayout>

        <!-- Confirmation Button -->
        <Button
            android:id="@+id/confirmButton"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_margin="16dp"
            android:layout_marginTop="32dp"
            android:text="Konfirmasi"
            android:textColor="#999999"
            android:textSize="16sp"
            android:textStyle="bold"
            android:background="@drawable/button_inactive_background"
            android:enabled="false"
            android:alpha="0.6"
            app:layout_constraintTop_toBottomOf="@id/numpad_grid"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintVertical_bias="0"/>

        <!-- Success Screen (Full Screen Overlay) - IMPROVED VERSION -->
        <LinearLayout
            android:id="@+id/success_screen"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:gravity="center"
            android:background="#E31937"
            android:visibility="gone"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <!-- Success Icon -->
            <ImageView
                android:id="@+id/success_icon"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:src="@drawable/ic_success_payment"
                android:layout_marginBottom="32dp"
                android:scaleType="centerInside"/>

            <!-- Success Message -->
            <TextView
                android:id="@+id/success_message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Pembayaran Berhasil"
                android:textColor="@android:color/white"
                android:textSize="24sp"
                android:textStyle="bold"
                android:fontFamily="@font/inter"
                android:gravity="center"
                android:letterSpacing="0.02"/>

        </LinearLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>