<?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="match_parent"
    android:background="?android:attr/colorBackground">

    <!-- Header Section -->
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/headerSection"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/password_unlock_gradient"
        android:paddingBottom="24dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <!-- Logo -->
        <ImageView
            android:id="@+id/logoImageView"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@mipmap/ic_launcher"
            android:contentDescription="@string/aliasvault_icon"
            android:elevation="4dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="80dp" />

        <!-- Title -->
        <TextView
            android:id="@+id/titleTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/password_unlock_title"
            android:textSize="28sp"
            android:textStyle="bold"
            android:textColor="?android:attr/textColorPrimary"
            app:layout_constraintTop_toBottomOf="@id/logoImageView"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="16dp"
            tools:text="Unlock Vault" />

        <!-- Subtitle -->
        <TextView
            android:id="@+id/subtitleTextView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/password_unlock_subtitle"
            android:textSize="16sp"
            android:textColor="?android:attr/textColorSecondary"
            android:gravity="center"
            app:layout_constraintTop_toBottomOf="@id/titleTextView"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="8dp"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp"
            android:paddingBottom="16dp"
            tools:text="Enter your master password" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    <!-- Main Content Section -->
    <ScrollView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:fillViewport="true"
        android:clipToPadding="false"
        app:layout_constraintTop_toBottomOf="@id/headerSection"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="20dp"
            android:paddingBottom="32dp">

            <!-- Password Input -->
            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/passwordInputLayout"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:hint="@string/password_unlock_password_hint"
                app:boxStrokeColor="@color/password_field_stroke_color"
                app:boxStrokeWidth="2dp"
                app:hintTextColor="?android:attr/textColorSecondary"
                app:startIconDrawable="@drawable/ic_lock"
                app:startIconTint="?android:attr/textColorSecondary"
                app:endIconMode="password_toggle"
                app:endIconTint="@color/primary"
                app:boxCornerRadiusTopStart="12dp"
                app:boxCornerRadiusTopEnd="12dp"
                app:boxCornerRadiusBottomStart="12dp"
                app:boxCornerRadiusBottomEnd="12dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginStart="32dp"
                android:layout_marginEnd="32dp">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/passwordEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:imeOptions="actionDone"
                    android:inputType="textPassword"
                    android:textColor="?android:attr/textColorPrimary"
                    android:textSize="16sp"
                    android:padding="16dp" />

            </com.google.android.material.textfield.TextInputLayout>

            <!-- Error Message with icon -->
            <LinearLayout
                android:id="@+id/errorContainer"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center"
                android:visibility="gone"
                app:layout_constraintTop_toBottomOf="@id/passwordInputLayout"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginTop="12dp"
                android:layout_marginStart="32dp"
                android:layout_marginEnd="32dp"
                tools:visibility="visible">

                <ImageView
                    android:layout_width="16dp"
                    android:layout_height="16dp"
                    android:src="@drawable/ic_error"
                    android:contentDescription="Error icon"
                    android:tint="@android:color/holo_red_dark"
                    android:layout_marginEnd="8dp" />

                <TextView
                    android:id="@+id/errorTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textColor="@android:color/holo_red_dark"
                    tools:text="Incorrect password" />
            </LinearLayout>

            <!-- Unlock Button -->
            <com.google.android.material.button.MaterialButton
                android:id="@+id/unlockButton"
                android:layout_width="0dp"
                android:layout_height="54dp"
                android:text="@string/password_unlock_button"
                android:textColor="@android:color/white"
                android:textSize="17sp"
                android:textStyle="bold"
                android:backgroundTint="@color/primary"
                app:icon="@drawable/ic_arrow_forward"
                app:iconGravity="end"
                app:iconTint="@android:color/white"
                app:cornerRadius="12dp"
                app:elevation="4dp"
                app:layout_constraintTop_toBottomOf="@id/errorContainer"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginTop="32dp"
                android:layout_marginStart="32dp"
                android:layout_marginEnd="32dp" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>

    <!-- Back Button -->
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="4dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <ImageButton
            android:id="@+id/backButton"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:src="@drawable/ic_arrow_back"
            android:contentDescription="@string/common_back"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:tint="?android:attr/textColorPrimary"
            android:padding="12dp"
            android:elevation="8dp" />
    </FrameLayout>

    <!-- Loading Overlay -->
    <FrameLayout
        android:id="@+id/loadingOverlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#80000000"
        android:clickable="true"
        android:focusable="true"
        android:visibility="gone"
        tools:visibility="visible">

        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_gravity="center"
            android:indeterminateTint="@color/primary" />

    </FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
