<?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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?android:attr/windowBackground">

    <!-- Custom Header/Toolbar -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="#1A1A1A"
        android:padding="8dp">

        <ImageView
            android:id="@+id/header_icon"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_centerVertical="true"
            android:src="@mipmap/ic_launcher" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@id/header_icon"
            android:layout_centerVertical="true"
            android:layout_marginStart="12dp"
            android:text="@string/app_name"
            android:textColor="#FFFFFF"
            android:textSize="18sp"
            android:textStyle="bold" />

        <!-- Triple Toggle Theme ImageButton -->
        <ImageButton
            android:id="@+id/theme_toggle"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:background="?android:attr/selectableItemBackgroundBorderless"
            android:src="@drawable/ic_theme_system"
            android:contentDescription="Toggle Theme"
            android:padding="8dp"
            android:scaleType="fitCenter" />
    </RelativeLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

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

            <!-- HR above Watchdog -->
            <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#444444" android:layout_marginBottom="16dp"/>

            <!-- Watchdog Control Section -->
            <Button
                android:id="@+id/watchdog_control"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:text="Enable Master Watchdog"
                android:textSize="20sp"
                android:textStyle="bold"
                android:textColor="#FFFFFF"
                android:background="@drawable/rounded_button"
                android:backgroundTint="#1976D2"
                android:layout_marginBottom="8dp"
                android:textAllCaps="false"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Protects Termux from Doze mode and keeps Wi-Fi active."
                android:textSize="13sp"
                android:gravity="center"
                android:textColor="?android:attr/textColorSecondary"
                android:layout_marginBottom="16dp"/>

            <!-- HR below Watchdog -->
            <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#444444" android:layout_marginBottom="20dp"/>

            <!-- VPN Control Section -->
            <Button
                android:id="@+id/control"
                android:layout_width="match_parent"
                android:layout_height="90dp"
                android:text="@string/control_enable"
                android:textSize="20sp"
                android:textStyle="bold"
                android:textColor="#FFFFFF"
                android:background="@drawable/rounded_button"
                android:backgroundTint="#2E7D32"
                android:textAllCaps="false"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/vpn_description"
                android:textSize="13sp"
                android:gravity="center"
                android:textColor="?android:attr/textColorSecondary"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="12dp"/>

            <Button
                android:id="@+id/apps"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/apps"
                android:layout_marginTop="4dp"
                android:background="@drawable/rounded_button"
                android:backgroundTint="#444444"
                android:textColor="#FFFFFF"
                android:textAllCaps="false"/>

            <!-- Config Section (Below VPN Button) -->
            <TextView
                android:id="@+id/config_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="▶ Configuration"
                android:textStyle="bold"
                android:padding="12dp"
                android:background="?attr/sectionHeaderBackground"
                android:textColor="#FFFFFF"
                android:clickable="true"
                android:focusable="true"
                android:layout_marginTop="20dp" />

            <LinearLayout
                android:id="@+id/config_layout"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:padding="12dp"
                android:background="?attr/sectionBackground">

                <!-- Primary Fields -->
                <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/socks_addr" android:textColor="?android:attr/textColorSecondary" android:textSize="12sp"/>
                <EditText android:id="@+id/socks_addr" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textColor="?android:attr/textColorPrimary"/>

                <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/socks_port" android:textColor="?android:attr/textColorSecondary" android:textSize="12sp"/>
                <EditText android:id="@+id/socks_port" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:inputType="number" android:textColor="?android:attr/textColorPrimary"/>

                <!-- Advanced Sub-section -->
                <TextView
                    android:id="@+id/adv_config_label"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="▶ Advanced Settings"
                    android:textColor="?android:attr/textColorSecondary"
                    android:padding="8dp"
                    android:textSize="13sp"
                    android:clickable="true"
                    android:focusable="true"/>

                <LinearLayout
                    android:id="@+id/advanced_config"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:visibility="gone">

                    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/socks_udp_addr" android:textColor="?android:attr/textColorSecondary" android:textSize="11sp"/>
                    <EditText android:id="@+id/socks_udp_addr" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textColor="?android:attr/textColorPrimary"/>

                    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/socks_user" android:textColor="?android:attr/textColorSecondary" android:textSize="11sp"/>
                    <EditText android:id="@+id/socks_user" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textColor="?android:attr/textColorPrimary"/>

                    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/socks_pass" android:textColor="?android:attr/textColorSecondary" android:textSize="11sp"/>
                    <EditText android:id="@+id/socks_pass" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:inputType="textPassword" android:textColor="?android:attr/textColorPrimary"/>

                    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/dns_ipv4" android:textColor="?android:attr/textColorSecondary" android:textSize="11sp"/>
                    <EditText android:id="@+id/dns_ipv4" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textColor="?android:attr/textColorPrimary"/>

                    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/dns_ipv6" android:textColor="?android:attr/textColorSecondary" android:textSize="11sp"/>
                    <EditText android:id="@+id/dns_ipv6" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textColor="?android:attr/textColorPrimary"/>

                    <CheckBox android:id="@+id/udp_in_tcp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/udp_in_tcp" android:textColor="?android:attr/textColorSecondary"/>
                    <CheckBox android:id="@+id/ipv4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/ipv4" android:textColor="?android:attr/textColorSecondary"/>
                    <CheckBox android:id="@+id/ipv6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/ipv6" android:textColor="?android:attr/textColorSecondary"/>
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp">
                    <CheckBox android:id="@+id/remote_dns" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/remote_dns" android:textColor="?android:attr/textColorSecondary"/>
                    <CheckBox android:id="@+id/global" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/global" android:textColor="?android:attr/textColorSecondary"/>
                </LinearLayout>

                <Button android:id="@+id/save" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/save" android:layout_marginTop="8dp" android:background="@drawable/rounded_button" android:backgroundTint="#555555" android:textColor="#FFFFFF" android:textAllCaps="false"/>
            </LinearLayout>

            <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#444444" android:layout_marginVertical="20dp"/>

            <!-- Log Section (Collapsible) -->
            <TextView
                android:id="@+id/log_label"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="▶ Connection Log"
                android:textStyle="bold"
                android:padding="10dp"
                android:background="?attr/sectionHeaderBackground"
                android:textColor="#FFFFFF"
                android:clickable="true"
                android:focusable="true"/>

            <TextView
                android:id="@+id/connection_log"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:background="#000000"
                android:textColor="#00FF00"
                android:fontFamily="monospace"
                android:padding="8dp"
                android:visibility="gone"
                android:scrollbars="vertical"
                android:text="System ready...\n"
                android:textSize="11sp"/>

            <!-- Log Actions Bar -->
            <LinearLayout
                android:id="@+id/log_actions"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:layout_marginTop="4dp">

                <Button
                    android:id="@+id/btn_clear_log"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Reset Log"
                    android:textSize="12sp"
                    android:backgroundTint="#D32F2F"
                    android:textColor="#FFFFFF"
                    android:textAllCaps="false"
                    android:layout_marginEnd="4dp"/>

                <Button
                    android:id="@+id/btn_copy_log"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Copy All"
                    android:textSize="12sp"
                    android:backgroundTint="#388E3C"
                    android:textColor="#FFFFFF"
                    android:textAllCaps="false"
                    android:layout_marginStart="4dp"/>
            </LinearLayout>

            <!-- Version Footer -->
            <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#444444" android:layout_marginTop="32dp" android:layout_marginBottom="8dp"/>
            <TextView
                android:id="@+id/version_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="v0.1.17alpha"
                android:textColor="#888888"
                android:textSize="10sp"
                android:paddingBottom="16dp"/>

        </LinearLayout>
    </ScrollView>
</LinearLayout>
