/* ==========================================================================
           1. 全局配置與管理員自定義變數 (CSS Variables)
           後端（如 Flask/Django）可以直接將管理員設定的值渲染到這些變數中，達成全站更換樣式
           ========================================================================== */
        :root {
            /* 管理員設定：Banner 背景色與文字顏色 */
            --app-banner-bg: #1B2B48;       /* 預設深藍色 */
            --app-banner-text: #FDFCF8;     /* 預設米白字 */
            
            /* 管理員設定：系統主題色與點綴色 */
            --app-accent: #E6B325;          /* 預設金色 */
            --app-accent-hover: #D09F1E;
            
            /* 管理員設定：自定義全站底色 */
            --app-bg: #F4F7F9;              /* 預設淺灰藍底色 */
            
            /* 標準語意顏色 */
            --text-main: #1B2B48;
            --text-muted: #64748B;
            --bg-card: #FFFFFF;
            --border-color: #E2E8F0;
            --success: #10B981;
            --danger: #EF4444;
            --disabled-gray: #94A3B8;
        }

        /* 如果管理員上傳了自定義背景圖片，後端可以直接在 body 注入 background-image */
        body {
            font-family: 'Noto Sans TC', 'Poppins', sans-serif;
            background-color: var(--app-bg);
            color: var(--text-main);
            margin: 0;
            padding: 0;
            min-height: 100vh;
            line-height: 1.6;
        }

        * {
            box-sizing: border-box;
        }

        a,
        button,
        input,
        select,
        .card,
        .page-tab,
        .reward-card,
        .student-box,
        .admin-menu-item,
        .child-card {
            transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out, color 0.2s ease-in-out, opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
        }

        /* ==========================================================================
           2. 通用組件：頂部萬用 Banner
           ========================================================================== */
        .app-banner {
            background-color: var(--app-banner-bg);
            color: var(--app-banner-text);
            padding: 15px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            border-bottom: 4px solid var(--app-accent);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .banner-brand {
            display: flex;
            align-items: center;
            gap: 12px;
            font-size: 20px;
            font-weight: 700;
            letter-spacing: 1px;
        }

        .banner-brand i {
            color: var(--app-accent);
            font-size: 24px;
        }

        .banner-menu {
            display: flex;
            gap: 15px;
        }

        /* 模擬多頁面切換的 Tabs（開發時可移除，改為後端 Routing） */
        .page-tab {
            background: rgba(255,255,255,0.1);
            color: var(--app-banner-text);
            border: none;
            padding: 8px 16px;
            border-radius: 20px;
            cursor: pointer;
            font-weight: 500;
            font-size: 14px;
        }

        .page-tab.active {
            background-color: var(--app-accent);
            color: #1B2B48;
            font-weight: 700;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 14px;
        }

        /* ==========================================================================
           3. 通用版面佈局 (Layout Wrapper)
           ========================================================================== */
        .app-container {
            max-width: 1200px;
            margin: 30px auto;
            padding: 0 20px;
        }

        .page-section {
            display: none; /* 預設隱藏，靠 JS 切換展示模擬 */
        }

        .page-section.active-section {
            display: block;
        }

        .section-title {
            font-size: 24px;
            font-weight: 700;
            margin-bottom: 20px;
            padding-left: 10px;
            border-left: 5px solid var(--app-accent);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        /* 卡片通用基礎 */
        .card {
            background: var(--bg-card);
            border-radius: 12px;
            border: 1px solid var(--border-color);
            padding: 24px;
            box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
            margin-bottom: 25px;
        }

        /* 按鈕基礎樣式 */
        .btn {
            padding: 10px 20px;
            border-radius: 8px;
            font-weight: 500;
            cursor: pointer;
            border: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            font-size: 15px;
        }

        .btn-accent { background-color: var(--app-accent); color: #1B2B48; font-weight: 700; }
        .btn-accent:hover { background-color: var(--app-accent-hover); }
        .btn-primary { background-color: var(--app-banner-bg); color: #fff; }
        .btn-secondary { background-color: #E2E8F0; color: var(--text-main); }

        /* ==========================================================================
           一、學生頁面樣式 (Student Dashboard & Redemption)
           ========================================================================== */
        .student-layout {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 25px;
        }

        @media (max-width: 992px) {
            .student-layout { grid-template-columns: 1fr; }
        }

        /* 累計積點大卡片 */
        .points-display-card {
            background: linear-gradient(135deg, var(--app-banner-bg) 0%, #2A3E61 100%);
            color: #fff;
            text-align: center;
            padding: 40px;
            position: relative;
            overflow: hidden;
        }
        
        .points-display-card h3 { margin: 0; font-size: 18px; opacity: 0.8; font-weight: 400; }
        .points-value { font-size: 64px; font-weight: 700; font-family: 'Poppins'; color: var(--app-accent); margin: 10px 0; }

        /* 目標禮物進度條 */
        .target-reward-status {
            background: rgba(255,255,255,0.08);
            padding: 15px;
            border-radius: 8px;
            margin-top: 15px;
            text-align: left;
        }
        .progress-bar-container {
            background: rgba(255,255,255,0.2);
            height: 12px;
            border-radius: 6px;
            margin-top: 8px;
            overflow: hidden;
        }
        .progress-bar-fill {
            background: var(--app-accent);
            height: 100%;
            width: 65%; /* 動態更換 */
        }

        /* 龍虎榜樣式 */
        .leaderboard-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        .leaderboard-item {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            border-bottom: 1px solid var(--border-color);
        }
        .leaderboard-item:last-child { border-bottom: none; }
        .rank-number {
            width: 30px; height: 30px;
            border-radius: 50%;
            display: flex; align-items: center; justify-content: center;
            font-weight: 700; font-family: 'Poppins';
            margin-right: 15px;
            font-size: 14px;
        }
        .rank-1 { background-color: #FFD700; color: #7A6500; }
        .rank-2 { background-color: #C0C0C0; color: #555555; }
        .rank-3 { background-color: #CD7F32; color: #fff; }
        .rank-normal { background-color: #F1F5F9; color: var(--text-muted); }
        
        .rank-name { flex-grow: 1; font-weight: 500; }
        .rank-points { font-family: 'Poppins'; font-weight: 700; color: var(--app-banner-bg); }

        /* 禮物商店網格 */
        .reward-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }

        /* 禮物卡片核心樣式 */
        .reward-card {
            background: #fff;
            border-radius: 12px;
            border: 1px solid var(--border-color);
            overflow: hidden;
            display: flex;
            flex-direction: column;
            box-shadow: 0 2px 4px rgba(0,0,0,0.02);
            position: relative;
        }

        .reward-img-wrapper {
            height: 150px;
            background-color: #F1F5F9;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
        }
        .reward-img-wrapper i { font-size: 48px; color: var(--text-muted); }
        .reward-img-wrapper img { width: 100%; height: 100%; object-fit: cover; }

        .reward-info { padding: 15px; flex-grow: 1; display: flex; flex-direction: column; }
        .reward-title { font-weight: 700; font-size: 16px; margin: 0 0 5px 0; }
        .reward-title-en { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
        .reward-cost { font-family: 'Poppins'; color: var(--danger); font-weight: 700; font-size: 18px; margin-top: auto; }
        .reward-cost span { font-size: 12px; color: var(--text-muted); font-weight: 400; }
        .reward-stock { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }

        /* 核心需求：未能換領以灰色置底顯示 */
        .reward-card.disabled {
            opacity: 0.6;
            filter: grayscale(1);
            background-color: #F8FAFC;
        }
        .reward-card.disabled .btn {
            background-color: var(--disabled-gray);
            color: #fff;
            cursor: not-allowed;
        }

        /* 核心需求：可以設定目標禮物 */
        .reward-card.is-target {
            border: 2px solid var(--app-accent);
            box-shadow: 0 0 12px rgba(230, 179, 37, 0.3);
        }
        .target-badge {
            position: absolute;
            top: 10px; right: 10px;
            background-color: var(--app-accent);
            color: #1B2B48;
            font-size: 11px; font-weight: 700;
            padding: 3px 8px; border-radius: 4px;
            z-index: 2;
        }

        /* ==========================================================================
           二、老師頁面樣式 (Teacher Portal - Mobile First)
           ========================================================================== */
        .teacher-mobile-frame {
            max-width: 430px; /* 模擬手機版型 */
            margin: 0 auto;
            background: #fff;
            border-radius: 30px;
            border: 8px solid #1B2B48;
            box-shadow: 0 20px 40px rgba(0,0,0,0.15);
            overflow: hidden;
            min-height: 750px;
            display: flex;
            flex-direction: column;
        }

        .mobile-body { padding: 15px; flex-grow: 1; overflow-y: auto; background-color: #FAFBFD;}

        /* 表單控制器 */
        .form-group { margin-bottom: 15px; }
        .form-group label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
        .form-control {
            width: 100%; padding: 10px 12px;
            border: 1px solid var(--border-color);
            border-radius: 8px; font-size: 15px;
            background-color: #fff;
        }
        .form-control:focus { outline: none; border-color: var(--app-banner-bg); }

        /* 學生直觀選擇網格 (可單選/複選) */
        .student-select-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            margin-bottom: 20px;
        }
        .student-box {
            background: #fff;
            border: 1px solid var(--border-color);
            border-radius: 10px;
            padding: 12px 5px;
            text-align: center;
            cursor: pointer;
            position: relative;
        }
        .student-box input[type="checkbox"] {
            position: absolute; top: 6px; right: 6px; scale: 1.1;
        }
        .student-avatar {
            width: 40px; height: 40px; background-color: #E2E8F0;
            border-radius: 50%; margin: 0 auto 8px auto;
            display: flex; align-items: center; justify-content: center;
            color: var(--text-muted);
        }
        .student-box .s-name { font-size: 13px; font-weight: 500; display: block; }
        .student-box .s-num { font-size: 11px; color: var(--text-muted); }

        /* 被選中時的樣式高亮 */
        .student-box.selected {
            border-color: var(--app-accent);
            background-color: rgba(230, 179, 37, 0.08);
        }

        /* 點數加減快捷鍵組 */
        .point-stepper {
            display: flex; gap: 10px; align-items: center; justify-content: center; margin: 15px 0;
        }
        .btn-step {
            width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border-color);
            background: #fff; font-size: 18px; font-weight: 700; cursor: pointer;
        }

        /* ==========================================================================
           三、管理員頁面樣式 (Admin Settings Panel)
           ========================================================================== */
        .admin-layout {
            display: grid;
            grid-template-columns: 240px 1fr;
            gap: 30px;
        }
        @media (max-width: 768px) {
            .admin-layout { grid-template-columns: 1fr; }
        }

        /* 管理員側邊選單 */
        .admin-sidebar {
            background: #fff; border-radius: 12px; border: 1px solid var(--border-color); padding: 15px;
            height: fit-content;
        }
        .admin-menu-item {
            display: flex; align-items: center; gap: 10px; padding: 12px 15px;
            border-radius: 8px; text-decoration: none; color: var(--text-main);
            font-weight: 500; margin-bottom: 5px; cursor: pointer;
        }
        .admin-menu-item:hover, .admin-menu-item.active {
            background-color: var(--app-banner-bg); color: #fff;
        }
        .admin-menu-item.active i { color: var(--app-accent); }

        /* 開關切換扭 (Toggle Switch) */
        .switch-row {
            display: flex; justify-content: space-between; align-items: center;
            padding: 12px 0; border-bottom: 1px solid var(--border-color);
        }
        .switch-row:last-child { border-bottom: none; }
        .switch {
            position: relative; display: inline-block; width: 48px; height: 24px;
        }
        .switch input { opacity: 0; width: 0; height: 0; }
        .slider {
            position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
            background-color: #CBD5E1; transition: .3s; border-radius: 24px;
        }
        .slider:before {
            position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px;
            background-color: white; transition: .3s; border-radius: 50%;
        }
        input:checked + .slider { background-color: var(--success); }
        input:checked + .slider:before { transform: translateX(24px); }

        /* 表格通用設定樣式 (特質與獎賞列表) */
        .admin-table {
            width: 100%; border-collapse: collapse; margin-top: 15px; background: #fff;
        }
        .admin-table th {
            background-color: #F8FAFC; padding: 12px 15px; text-align: left;
            font-weight: 700; border-bottom: 2px solid var(--border-color);
            font-size: 14px; color: var(--text-muted);
        }
        .admin-table td {
            padding: 14px 15px; border-bottom: 1px solid var(--border-color); font-size: 14px;
        }
        .drag-handle { cursor: move; color: var(--text-muted); font-size: 16px; }

        /* 彈出視窗 Popup (Modal) */
        .modal-overlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.5); z-index: 1000;
            display: none; align-items: center; justify-content: center;
        }
        .modal-overlay.show { display: flex; }
        .modal-box {
            background: #fff; border-radius: 16px; width: 500px; max-width: 90%;
            box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); overflow: hidden;
            animation: slideDown 0.3s ease-out;
        }
        .modal-header {
            background: var(--app-banner-bg); color: #fff; padding: 15px 20px;
            display: flex; justify-content: space-between; align-items: center;
            border-bottom: 3px solid var(--app-accent);
        }
        .modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
        .modal-footer { padding: 15px 20px; border-top: 1px solid var(--border-color); text-align: right; display: flex; justify-content: flex-end; gap: 10px;}

        @keyframes slideDown {
            from { transform: translateY(-20px); opacity: 0; }
            to { transform: translateY(0); opacity: 1; }
        }

        /* 狀態標籤 */
        .status-badge {
            padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: 500;
        }
        .badge-success { background-color: #D1FAE5; color: #065F46; }
        .badge-danger { background-color: #FEE2E2; color: #991B1B; }

/* ==========================================================================
   多頁面靜態原型補充樣式
   ========================================================================== */
body.split-page .page-section {
    display: block;
}

.banner-menu a.page-tab {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.banner-menu a.page-tab:hover {
    background-color: rgba(255,255,255,0.18);
}

.page-hero {
    background: linear-gradient(135deg, rgba(27,43,72,0.96), rgba(42,62,97,0.92));
    color: var(--app-banner-text);
    border-radius: 18px;
    padding: 36px;
    margin-bottom: 25px;
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 12px 30px rgba(27,43,72,0.16);
}

.page-hero h1 {
    margin: 0 0 10px;
    font-size: 34px;
    line-height: 1.25;
}

.page-hero p {
    margin: 0;
    color: rgba(253,252,248,0.78);
    max-width: 760px;
}

.role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.role-card {
    text-decoration: none;
    color: var(--text-main);
    position: relative;
    overflow: hidden;
}

.role-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 18px 28px rgba(27,43,72,0.12);
}

.role-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: rgba(230,179,37,0.14);
    color: var(--app-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 18px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 25px;
}

.kpi-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 18px;
}

.kpi-label {
    color: var(--text-muted);
    font-size: 13px;
}

.kpi-value {
    font-family: 'Poppins';
    font-size: 28px;
    font-weight: 700;
    color: var(--app-banner-bg);
}

.child-switcher {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.child-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    background: #fff;
    cursor: pointer;
}

.child-card.active {
    border-color: var(--app-accent);
    box-shadow: 0 0 0 3px rgba(230,179,37,0.16);
}

.timeline-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.timeline-list li {
    border-left: 3px solid var(--border-color);
    padding: 0 0 18px 16px;
    margin-left: 6px;
    position: relative;
}

.timeline-list li:before {
    content: '';
    position: absolute;
    left: -8px;
    top: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--app-accent);
}

.admin-table .btn {
    padding: 6px 10px;
    font-size: 12px;
}

@media (max-width: 760px) {
    .app-banner {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
        padding: 16px 18px;
    }

    .banner-menu {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .page-tab {
        white-space: nowrap;
    }

    .page-hero {
        padding: 24px;
    }

    .page-hero h1 {
        font-size: 26px;
    }
}
