<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg">

    <!-- Login Screen -->
    <LinearLayout
        android:id="@+id/loginScreen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center"
        android:padding="32dp"
        android:visibility="gone">

        <com.google.android.material.card.MaterialCardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardBackgroundColor="@color/panel"
            app:cardCornerRadius="14dp"
            app:cardElevation="0dp"
            app:strokeColor="@color/border"
            app:strokeWidth="1dp">

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="睡眠紀錄"
                    android:textSize="22sp"
                    android:textStyle="bold"
                    android:textColor="@color/text"
                    android:layout_marginBottom="18dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="帳號"
                    android:textSize="14sp"
                    android:textColor="@color/muted"
                    android:layout_marginBottom="4dp" />

                <EditText
                    android:id="@+id/inputUsername"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/bg"
                    android:textColor="@color/text"
                    android:padding="10dp"
                    android:inputType="text"
                    android:singleLine="true"
                    android:layout_marginBottom="12dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="密碼"
                    android:textSize="14sp"
                    android:textColor="@color/muted"
                    android:layout_marginBottom="4dp" />

                <EditText
                    android:id="@+id/inputPassword"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/bg"
                    android:textColor="@color/text"
                    android:padding="10dp"
                    android:inputType="textPassword"
                    android:singleLine="true"
                    android:layout_marginBottom="20dp" />

                <Button
                    android:id="@+id/btnLogin"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="登入"
                    android:textSize="16sp"
                    android:textColor="#FFFFFF"
                    android:backgroundTint="@color/accent" />

                <TextView
                    android:id="@+id/loginError"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#FFE74C3C"
                    android:textSize="14sp"
                    android:layout_marginTop="12dp"
                    android:visibility="gone" />
            </LinearLayout>
        </com.google.android.material.card.MaterialCardView>
    </LinearLayout>

    <!-- Main App Screen -->
    <ScrollView
        android:id="@+id/mainScreen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingStart="16dp"
            android:paddingEnd="16dp"
            android:paddingTop="24dp"
            android:paddingBottom="24dp">

            <!-- Top bar: logout -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="end"
                android:layout_marginBottom="12dp">

                <Button
                    android:id="@+id/btnLogout"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_width="wrap_content"
                    android:layout_height="36dp"
                    android:text="登出"
                    android:textSize="13sp"
                    android:textColor="@color/muted" />
            </LinearLayout>

            <!-- Status Card -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:gravity="center"
                android:background="@color/panel"
                android:padding="20dp"
                android:layout_marginBottom="20dp">

                <TextView
                    android:id="@+id/statusIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="40sp" />

                <TextView
                    android:id="@+id/statusLabel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="20sp"
                    android:textStyle="bold"
                    android:textColor="@color/text"
                    android:layout_marginTop="8dp"
                    android:text="載入中…" />

                <TextView
                    android:id="@+id/statusTime"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textColor="@color/muted"
                    android:layout_marginTop="8dp"
                    android:visibility="gone" />
            </LinearLayout>

            <!-- Action Buttons -->
            <FrameLayout
                android:id="@+id/btnBed"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="12dp"
                android:background="@color/btn_bed"
                android:clipChildren="true"
                android:visibility="gone">
                <View
                    android:id="@+id/fillBed"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:background="@color/fill_overlay" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="80dp"
                    android:gravity="center"
                    android:text="躺　床"
                    android:textSize="28sp"
                    android:textColor="#FFFFFF" />
            </FrameLayout>

            <FrameLayout
                android:id="@+id/btnSleep"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="12dp"
                android:background="@color/btn_sleep"
                android:clipChildren="true"
                android:visibility="gone">
                <View
                    android:id="@+id/fillSleep"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:background="@color/fill_overlay" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="80dp"
                    android:gravity="center"
                    android:text="睡　眠"
                    android:textSize="28sp"
                    android:textColor="#FFFFFF" />
            </FrameLayout>

            <FrameLayout
                android:id="@+id/btnLazy"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="12dp"
                android:background="@color/btn_lazy"
                android:clipChildren="true"
                android:visibility="gone">
                <View
                    android:id="@+id/fillLazy"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:background="@color/fill_overlay" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="80dp"
                    android:gravity="center"
                    android:text="賴　床"
                    android:textSize="28sp"
                    android:textColor="#FFFFFF" />
            </FrameLayout>

            <FrameLayout
                android:id="@+id/btnWake"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="12dp"
                android:background="@color/btn_wake"
                android:clipChildren="true"
                android:visibility="gone">
                <View
                    android:id="@+id/fillWake"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:background="@color/fill_overlay" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="80dp"
                    android:gravity="center"
                    android:text="清　醒"
                    android:textSize="28sp"
                    android:textColor="#FFFFFF" />
            </FrameLayout>

            <!-- Hint -->
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="長按 1.5 秒以打卡"
                android:textColor="@color/muted"
                android:textSize="13sp"
                android:layout_marginBottom="24dp" />

            <!-- History Section -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@color/panel"
                android:padding="16dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="最近紀錄"
                    android:textColor="@color/muted"
                    android:textSize="14sp"
                    android:layout_marginBottom="8dp" />

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

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