<?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="?attr/itemBackground"
    android:fitsSystemWindows="true">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/custom_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true"
        android:padding="8dp">

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

            <!-- Custom Script Section -->
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_marginBottom="8dp"
                app:cardCornerRadius="8dp"
                app:cardElevation="2dp"
                app:cardBackgroundColor="?attr/itemBackground"
                app:cardUseCompatPadding="true"
                app:strokeColor="?android:attr/textColorSecondary"
                app:strokeWidth="1dp">

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

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:gravity="center_vertical"
                        android:layout_marginBottom="8dp">

                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_edit"
                            app:tint="?attr/colorPrimary" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/custom_startup_script"
                            android:textAppearance="?android:attr/textAppearanceLarge"
                            android:textStyle="bold"
                            android:textColor="?attr/colorPrimary"
                            android:layout_marginStart="8dp" />
                    </LinearLayout>

                    <TextView
                        android:id="@+id/customscript_link"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/custom_script_info"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="?android:attr/textColorSecondary"
                        android:layout_marginBottom="12dp" />

                    <com.google.android.material.textfield.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:hint="@string/enter_custom_script_hint"
                        app:boxBackgroundMode="outline"
                        app:boxCornerRadiusTopStart="4dp"
                        app:boxCornerRadiusTopEnd="4dp"
                        app:boxCornerRadiusBottomStart="4dp"
                        app:boxCornerRadiusBottomEnd="4dp">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/customscript"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="top|start"
                            android:inputType="textMultiLine|textNoSuggestions"
                            android:scrollbars="vertical"
                            android:fontFamily="monospace"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:minLines="8">
                            <requestFocus />
                        </com.google.android.material.textfield.TextInputEditText>
                    </com.google.android.material.textfield.TextInputLayout>

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

            <!-- Custom Shutdown Script Section -->
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_marginBottom="8dp"
                app:cardCornerRadius="8dp"
                app:cardElevation="2dp"
                app:cardBackgroundColor="?attr/itemBackground"
                app:cardUseCompatPadding="true"
                app:strokeColor="?android:attr/textColorSecondary"
                app:strokeWidth="1dp">

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

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:gravity="center_vertical"
                        android:layout_marginBottom="8dp">

                        <ImageView
                            android:layout_width="24dp"
                            android:layout_height="24dp"
                            android:src="@android:drawable/ic_menu_close_clear_cancel"
                            app:tint="?android:attr/textColorSecondary" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/custom_shutdown_script"
                            android:textAppearance="?android:attr/textAppearanceLarge"
                            android:textStyle="bold"
                            android:textColor="?android:attr/textColorSecondary"
                            android:layout_marginStart="8dp" />
                    </LinearLayout>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/custom_script2_info"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="?android:attr/textColorSecondary"
                        android:layout_marginBottom="12dp" />

                    <com.google.android.material.textfield.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:hint="@string/enter_shutdown_script_hint"
                        app:boxBackgroundMode="outline"
                        app:boxCornerRadiusTopStart="4dp"
                        app:boxCornerRadiusTopEnd="4dp"
                        app:boxCornerRadiusBottomStart="4dp"
                        app:boxCornerRadiusBottomEnd="4dp">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/customscript2"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:gravity="top|start"
                            android:inputType="textMultiLine|textNoSuggestions"
                            android:scrollbars="vertical"
                            android:fontFamily="monospace"
                            android:textAppearance="?android:attr/textAppearanceSmall"
                            android:minLines="8" />
                    </com.google.android.material.textfield.TextInputLayout>

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

        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

    <!-- Action Buttons -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="end"
        android:padding="12dp"
        android:background="?attr/itemBackground"
        android:elevation="4dp">

        <Button
            android:id="@+id/customscript_cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:text="@android:string/cancel"
            android:background="?android:attr/selectableItemBackground"
            android:textColor="?android:attr/textColorSecondary"
            style="?android:attr/buttonBarButtonStyle" />

        <Button
            android:id="@+id/customscript_ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@android:string/ok"
            android:backgroundTint="?attr/colorPrimary"
            android:textColor="@android:color/white"
            style="?android:attr/buttonBarButtonStyle" />

    </LinearLayout>

</LinearLayout>
