<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0f172a">

    <!-- Splash screen (shown briefly on launch) -->
    <LinearLayout
        android:id="@+id/splashContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center"
        android:visibility="visible">

        <ImageView
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:src="@drawable/ic_launcher_foreground"
            android:layout_marginBottom="24dp"
            android:contentDescription="EverShelf" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="EverShelf"
            android:textColor="#f1f5f9"
            android:textSize="32sp"
            android:textStyle="bold"
            android:layout_marginBottom="8dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Smart Pantry Manager"
            android:textColor="#64748b"
            android:textSize="16sp"
            android:layout_marginBottom="48dp" />

        <ProgressBar
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:indeterminateTint="#7c3aed" />
    </LinearLayout>

    <!-- Setup wizard container -->
    <ScrollView
        android:id="@+id/wizardContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center_horizontal"
            android:paddingStart="32dp"
            android:paddingEnd="32dp"
            android:paddingTop="48dp"
            android:paddingBottom="48dp">

            <!-- Step indicator -->
            <LinearLayout
                android:id="@+id/stepIndicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginBottom="40dp"
                android:gravity="center" />

            <!-- Step 1: Welcome -->
            <LinearLayout
                android:id="@+id/step1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center_horizontal"
                android:visibility="visible">

                <ImageView
                    android:layout_width="96dp"
                    android:layout_height="96dp"
                    android:src="@drawable/ic_launcher_foreground"
                    android:layout_marginBottom="16dp"
                    android:contentDescription="EverShelf" />

                <TextView
                    android:id="@+id/wizardTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Welcome to\nEverShelf Kiosk"
                    android:textColor="#f1f5f9"
                    android:textSize="28sp"
                    android:textStyle="bold"
                    android:gravity="center"
                    android:lineSpacingExtra="4dp"
                    android:layout_marginBottom="16dp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Turn this tablet into a dedicated kitchen panel for your smart pantry. Always-on display with built-in smart scale support."
                    android:textColor="#94a3b8"
                    android:textSize="16sp"
                    android:gravity="center"
                    android:lineSpacingExtra="6dp"
                    android:layout_marginBottom="48dp" />

                <!-- Feature highlights -->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_marginBottom="48dp">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="📺  Full-screen kiosk mode"
                        android:textColor="#cbd5e1"
                        android:textSize="15sp"
                        android:paddingTop="8dp"
                        android:paddingBottom="8dp" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="⚖️  Bluetooth scale via Gateway app"
                        android:textColor="#cbd5e1"
                        android:textSize="15sp"
                        android:paddingTop="8dp"
                        android:paddingBottom="8dp" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="🔋  Always-on, screen never sleeps"
                        android:textColor="#cbd5e1"
                        android:textSize="15sp"
                        android:paddingTop="8dp"
                        android:paddingBottom="8dp" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="📷  Barcode scanning from WebView"
                        android:textColor="#cbd5e1"
                        android:textSize="15sp"
                        android:paddingTop="8dp"
                        android:paddingBottom="8dp" />
                </LinearLayout>

                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btnGetStarted"
                    android:layout_width="match_parent"
                    android:layout_height="56dp"
                    android:text="Get Started"
                    android:textSize="17sp"
                    android:textAllCaps="false"
                    android:backgroundTint="#7c3aed" />
            </LinearLayout>

            <!-- Step 2: Server URL -->
            <LinearLayout
                android:id="@+id/step2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center_horizontal"
                android:visibility="gone">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="🌐"
                    android:textSize="48sp"
                    android:layout_marginBottom="16dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Connect to EverShelf"
                    android:textColor="#f1f5f9"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:layout_marginBottom="8dp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Enter the URL of your EverShelf server. This is the same address you use in your browser."
                    android:textColor="#94a3b8"
                    android:textSize="15sp"
                    android:gravity="center"
                    android:lineSpacingExtra="4dp"
                    android:layout_marginBottom="32dp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Server URL"
                    android:textColor="#cbd5e1"
                    android:textSize="13sp"
                    android:textStyle="bold"
                    android:layout_marginBottom="8dp" />

                <EditText
                    android:id="@+id/wizardUrl"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="https://192.168.1.100/dispensa/"
                    android:inputType="textUri"
                    android:textColor="#f1f5f9"
                    android:textColorHint="#475569"
                    android:background="@drawable/input_background"
                    android:padding="16dp"
                    android:textSize="16sp"
                    android:singleLine="true"
                    android:layout_marginBottom="12dp" />

                <TextView
                    android:id="@+id/urlStatus"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text=""
                    android:textSize="13sp"
                    android:visibility="gone"
                    android:layout_marginBottom="12dp" />

                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btnTestUrl"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:text="🔗  Test Connection"
                    android:textSize="15sp"
                    android:textAllCaps="false"
                    style="@style/Widget.MaterialComponents.Button.OutlinedButton"
                    android:strokeColor="#334155"
                    android:textColor="#94a3b8"
                    android:layout_marginBottom="24dp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="💡 Tip: Copy the exact URL from your browser address bar — including the path (e.g. /dispensa/)."
                    android:textColor="#64748b"
                    android:textSize="13sp"
                    android:lineSpacingExtra="2dp"
                    android:background="@drawable/tip_background"
                    android:padding="14dp"
                    android:layout_marginBottom="32dp" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="center">

                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/btnStep2Back"
                        android:layout_width="0dp"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:text="Back"
                        android:textSize="15sp"
                        android:textAllCaps="false"
                        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
                        android:strokeColor="#334155"
                        android:textColor="#94a3b8"
                        android:layout_marginEnd="12dp" />

                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/btnStep2Next"
                        android:layout_width="0dp"
                        android:layout_height="48dp"
                        android:layout_weight="2"
                        android:text="Next →"
                        android:textSize="15sp"
                        android:textAllCaps="false"
                        android:backgroundTint="#7c3aed" />
                </LinearLayout>
            </LinearLayout>

            <!-- Step 3: Scale Setup -->
            <LinearLayout
                android:id="@+id/step3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center_horizontal"
                android:visibility="gone">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="⚖️"
                    android:textSize="48sp"
                    android:layout_marginBottom="16dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Smart Scale (Optional)"
                    android:textColor="#f1f5f9"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    android:layout_marginBottom="8dp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="To use a Bluetooth kitchen scale, you need the EverShelf Scale Gateway app installed separately."
                    android:textColor="#94a3b8"
                    android:textSize="15sp"
                    android:gravity="center"
                    android:lineSpacingExtra="4dp"
                    android:layout_marginBottom="24dp" />

                <!-- Scale status card -->
                <LinearLayout
                    android:id="@+id/scaleStatusCard"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:background="@drawable/card_background"
                    android:padding="20dp"
                    android:layout_marginBottom="16dp">

                    <TextView
                        android:id="@+id/scaleStatusIcon"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="🔍"
                        android:textSize="32sp"
                        android:layout_gravity="center"
                        android:layout_marginBottom="8dp" />

                    <TextView
                        android:id="@+id/scaleStatusText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Checking..."
                        android:textColor="#cbd5e1"
                        android:textSize="16sp"
                        android:gravity="center"
                        android:layout_marginBottom="4dp" />

                    <TextView
                        android:id="@+id/scaleStatusDetail"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text=""
                        android:textColor="#64748b"
                        android:textSize="13sp"
                        android:gravity="center" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:gravity="center"
                    android:layout_marginTop="16dp">

                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/btnStep3Back"
                        android:layout_width="0dp"
                        android:layout_height="48dp"
                        android:layout_weight="1"
                        android:text="Back"
                        android:textSize="15sp"
                        android:textAllCaps="false"
                        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
                        android:strokeColor="#334155"
                        android:textColor="#94a3b8"
                        android:layout_marginEnd="12dp" />

                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/btnFinish"
                        android:layout_width="0dp"
                        android:layout_height="56dp"
                        android:layout_weight="2"
                        android:text="🚀  Launch EverShelf"
                        android:textSize="16sp"
                        android:textAllCaps="false"
                        android:backgroundTint="#059669" />
                </LinearLayout>

                <com.google.android.material.button.MaterialButton
                    android:id="@+id/btnSkipScale"
                    android:layout_width="wrap_content"
                    android:layout_height="36dp"
                    android:text="Skip — I don't have a scale"
                    android:textSize="13sp"
                    android:textAllCaps="false"
                    style="@style/Widget.MaterialComponents.Button.TextButton"
                    android:textColor="#64748b"
                    android:layout_marginTop="12dp" />
            </LinearLayout>

        </LinearLayout>
    </ScrollView>

    <!-- WebView (shown after setup) -->
    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" />

    <!-- Settings gear (shown after setup, over WebView) -->
    <ImageButton
        android:id="@+id/btnSettings"
        android:layout_width="44dp"
        android:layout_height="44dp"
        android:layout_gravity="bottom|start"
        android:layout_marginBottom="70dp"
        android:layout_marginStart="8dp"
        android:background="@android:color/transparent"
        android:src="@android:drawable/ic_menu_manage"
        android:alpha="0.12"
        android:contentDescription="Settings"
        android:scaleType="centerInside"
        android:visibility="gone" />

</FrameLayout>
