<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="@color/bg_light">

    <!-- 1. SETUP CONTAINER (Shown on first run) -->
    <LinearLayout
        android:id="@+id/layoutSetup"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="24dp"
        android:visibility="gone"
        tools:visibility="visible">

        <com.google.android.material.card.MaterialCardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="16dp"
            app:cardElevation="6dp"
            app:cardBackgroundColor="@color/card_bg"
            app:strokeWidth="0dp">

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

                <!-- App Logo -->
                <ImageView
                    android:id="@+id/imgAppLogo"
                    android:layout_width="120dp"
                    android:layout_height="120dp"
                    android:layout_marginBottom="16dp"
                    android:contentDescription="@string/app_name"
                    android:src="@drawable/app_logo" />

                <!-- Header Icon / Title -->
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/setup_title"
                    android:textColor="@color/text_primary"
                    android:textSize="22sp"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:text="@string/setup_subtitle"
                    android:textColor="@color/text_secondary"
                    android:textSize="14sp" />

                <!-- Input Field -->
                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/textInputLayoutId"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    app:boxCornerRadiusBottomEnd="10dp"
                    app:boxCornerRadiusBottomStart="10dp"
                    app:boxCornerRadiusTopEnd="10dp"
                    app:boxCornerRadiusTopStart="10dp"
                    app:boxStrokeColor="@color/primary"
                    app:hintTextColor="@color/primary"
                    android:hint="@string/id_hint">

                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/etRouteId"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="textCapCharacters|textNoSuggestions"
                        android:maxLines="1"
                        android:textColor="@color/text_primary"
                        android:textSize="16sp" />
                </com.google.android.material.textfield.TextInputLayout>

                <!-- Save & Continue Button -->
                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btnSaveAndContinue"
                    android:layout_width="match_parent"
                    android:layout_height="54dp"
                    android:layout_marginTop="24dp"
                    android:text="@string/btn_save_continue"
                    android:textColor="@color/white"
                    android:textSize="16sp"
                    android:textStyle="bold"
                    app:cornerRadius="10dp"
                    app:backgroundTint="@color/primary" />

            </LinearLayout>
        </com.google.android.material.card.MaterialCardView>

    </LinearLayout>

    <!-- 2. WEBVIEW CONTAINER (Shown after setup) -->
    <RelativeLayout
        android:id="@+id/layoutWebView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        tools:visibility="gone">

        <!-- Top Progress Bar -->
        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:layout_alignParentTop="true"
            android:progressTint="@color/primary"
            android:indeterminate="false"
            android:visibility="gone" />

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipeRefreshLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/progressBar">

            <WebView
                android:id="@+id/webView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

        <!-- Error Layout -->
        <LinearLayout
            android:id="@+id/layoutError"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/bg_light"
            android:gravity="center"
            android:orientation="vertical"
            android:padding="24dp"
            android:visibility="gone">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/no_internet_title"
                android:textColor="@color/text_primary"
                android:textSize="20sp"
                android:textStyle="bold" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:text="@string/no_internet_msg"
                android:textColor="@color/text_secondary"
                android:textSize="14sp"
                android:gravity="center" />

            <com.google.android.material.button.MaterialButton
                android:id="@+id/btnRetry"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="@string/retry"
                app:cornerRadius="8dp"
                app:backgroundTint="@color/primary" />
        </LinearLayout>

        <!-- Floating Reset / Change ID Button (Discreet in corner) -->
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fabSettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:layout_margin="16dp"
            android:contentDescription="@string/change_id"
            app:fabSize="mini"
            app:backgroundTint="@color/white"
            app:tint="@color/primary"
            app:srcCompat="@drawable/ic_settings"
            app:elevation="4dp" />

    </RelativeLayout>

</FrameLayout>
