/* ==========================================================================
   1. 全站通用重設與變數 (Global Resets & Variables)
   ========================================================================== */
:root {
    --primary-color: #28a745;        /* LINE 官方綠色 */
    --primary-hover: #218838;
    --secondary-color: #6c757d;     /* 次要灰色 */
    --secondary-hover: #5a6268;
    --bg-light: #f8f9fa;             /* 畫面的淺灰底色 */
    --text-main: #333333;           /* 主文字顏色 */
    --text-muted: #777777;           /* 輔助文字顏色 */
    --border-color: #e2e8f0;        /* 線條顏色 */
    --card-bg: #ffffff;              /* 卡片底色 */
    --price-color: #dc3545;          /* 金額醒目紅色 */
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans TC', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-tap-highlight-color: transparent; /* 移除手機點擊時的藍色陰影 */
}
/* 🎯 隱藏所有載入失敗（破圖）的圖片 */
img:not([src]), 
img[src=""], 
img:invalid {
    opacity: 0 !important;
}

/* 針對 Chromium 核心（Chrome, Edge）與 LINE 內建瀏覽器的破圖外框與死掉圖標進行封殺 */
img::before {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%; 
    background-color: var(--bg-light); /* 破圖時用淺灰底色代替，或寫 transparent 完全透明 */
    z-index: 2;
}

/* ==========================================================================
   2. 頂部導覽列與容器 (Header & Containers)
   ========================================================================== */
.main-header {
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.header-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-icon {
    color: var(--primary-color);
    font-size: 1.2rem;
}

.brand-name {
    font-weight: 700;
    font-size: 1.1rem;
    color: #1a202c;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #edf2f7;
    padding: 4px 10px;
    border-radius: 20px;
}

.avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

.username {
    font-size: 0.85rem;
    font-weight: 500;
}

/* 內容主容器 */
.main-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 15px 40px 15px;
}

/* ==========================================================================
   3. 首頁儀表板與卡片 (Dashboard & Stats)
   ========================================================================== */
.welcome-section {
    margin-bottom: 25px;
}
.welcome-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #1a202c;
    margin-bottom: 4px;
}
.welcome-desc {
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* 數據卡片網格 */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.stat-card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(0,0,0,0.02);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
}
.icon-users { background: #e8f5e9; color: #2e7d32; }
.icon-pending { background: #fff8e1; color: #f57f17; }
.icon-success { background: #e3f2fd; color: #1565c0; }

.stat-content {
    display: flex;
    flex-direction: column;
}
.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}
.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    margin-top: 2px;
}

/* 複製連結工具 */
.share-box {
    background: #ffffff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
    box-shadow: var(--shadow);
}
.share-title { font-size: 1.1rem; margin-bottom: 8px; }
.share-desc { font-size: 0.88rem; color: var(--text-muted); margin-bottom: 12px; }

.copy-input-group {
    display: flex;
    gap: 8px;
}
.copy-input {
    flex: 1;
    background: #f1f5f9 !important;
    color: #475569;
}
.copy-toast {
    background: #334155;
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    font-size: 0.9rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3);
}

/* 佈告欄公告 */
.announcement-section {
    background: #ffffff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.section-title { font-size: 1.1rem; margin-bottom: 15px; border-left: 4px solid var(--primary-color); padding-left: 10px; }
.announcement-item { padding: 15px 0; border-bottom: 1px solid var(--border-color); }
.announcement-item:last-child { border-bottom: none; }
.announcement-date { font-size: 0.8rem; color: var(--text-muted); }
.announcement-item-title { font-size: 1rem; margin: 4px 0; color: #1a202c; }
.announcement-body { font-size: 0.9rem; color: #4a5568; }

/* ==========================================================================
   4. 表單排版樣式 (Forms)
   ========================================================================== */
.merchant-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.form-section {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.section-desc { font-size: 0.85rem; color: #94a3b8; margin-top: -10px; margin-bottom: 15px; }
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 15px;
}
.form-group-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}
@media (max-width: 576px) {
    .form-group-row { grid-template-columns: 1fr; gap: 0; }
}
.form-label { font-size: 0.9rem; font-weight: 500; color: #344054; }
.required { color: var(--price-color); }
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}
.form-control:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.12); }

/* ==========================================================================
   5. 響應式表格 (RWD Tables) - 針對手機版重組排版
   ========================================================================== */
.table-responsive {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 25px;
}
.rwd-table {
    width: 100%;
    border-collapse: collapse;
}
.rwd-table th, .rwd-table td {
    padding: 14px 16px;
    text-align: left;
    font-size: 0.92rem;
}
.rwd-table th { background-color: #f1f5f9; color: #475569; font-weight: 500; border-bottom: 2px solid var(--border-color); }
.rwd-table tr { border-bottom: 1px solid var(--border-color); }
.rwd-table tr:last-child { border-bottom: none; }

/* 手機版表格：將 Table 轉為 Card */
@media (max-width: 600px) {
    .rwd-table thead { display: none; } /* 隱藏原本的表頭 */
    .rwd-table tr {
        display: block;
        padding: 10px;
        background: #fff;
        margin-bottom: 10px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
    }
    .rwd-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 8px 10px;
        border-bottom: 1px dashed #f1f5f9;
    }
    .rwd-table td:last-child { border-bottom: none; }
    .rwd-table td::before {
        content: attr(data-th);
        float: left;
        font-weight: 700;
        color: var(--text-muted);
    }
}


/* ==========================================================================
   6. 推廣樹狀名單卡片 (Partner Tree UI & Accordion)
   ========================================================================== */
.partner-tree-container { 
    background: #fff; 
    padding: 20px; 
    border-radius: 12px; 
    box-shadow: var(--shadow); 
}

.partner-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

/* 當卡片具備手風琴功能時的觸發器樣式 */
.accordion-trigger {
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

/* 手機版點擊或滑鼠懸停時的細緻反饋 */
.accordion-trigger:hover,
.accordion-trigger:active {
    background-color: #f1f5f9;
}

.partner-info { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
}

.avatar-wrapper { 
    position: relative; 
}

.partner-avatar { 
    width: 44px; 
    height: 44px; 
    border-radius: 50%; 
    object-fit: cover; 
    border: 2px solid #fff; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.05); 
}

.layer-badge { 
    position: absolute; 
    top: -5px; 
    left: -5px; 
    font-size: 0.65rem; 
    padding: 2px 5px; 
    border-radius: 10px; 
    color: #fff; 
    font-weight: 700; 
    z-index: 3;
}

.layer-1 { background-color: #3b82f6; }
.layer-2 { background-color: #ec4899; }

.partner-name { font-size: 1rem; color: #1a202c; }
.partner-date { font-size: 0.78rem; color: var(--text-muted); }

/* 右側狀態與箭頭區塊 */
.partner-status-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 🎯 手風琴摺疊箭頭預設樣式 */
.accordion-icon {
    color: #a0aec0;
    font-size: 0.88rem;
    width: 20px;
    text-align: center;
    /* 配合 JS 動態，讓箭頭轉向時有平滑的 0.3 秒緩動特效 */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s ease;
}

/* 🎯 核心手風琴內層容器：利用 max-height 做高度動畫的基礎 */
.sub-layer-accordion-content {
    max-height: 0;
    overflow: hidden;
    /* 當 JS 改變 max-height 時，觸發流暢的展開/收合過渡 */
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 🟢 當外層節點被注入 .open 類別時的樣式變化 */
.first-layer-node.open .accordion-icon {
    transform: rotate(180deg); /* 箭頭順暢翻轉 180 度 */
    color: var(--text-main);   /* 箭頭顏色加深提示 */
}

/* 第二層容器縮排與連線 */
.sub-layer-container { 
    margin-left: 25px; 
    margin-top: 10px; 
    padding-left: 15px; 
    border-left: 2px dashed #cbd5e1; 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
}

.sub-card { 
    background: #ffffff; 
    border-style: dotted; 
}

.node-divider { 
    margin: 20px 0; 
    border: 0; 
    border-top: 1px solid #f1f5f9; 
}


/* ==========================================================================
   7. 常用元件 (Buttons, Badges & Utilities)
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
}
.btn-primary { background-color: var(--primary-color); color: #fff; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-secondary { background-color: var(--secondary-color); color: #fff; }
.btn-secondary:hover { background-color: var(--secondary-hover); }
.btn-block { width: 100%; display: flex; }

/* 狀態標籤 */
.badge, .status-badge { padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.badge-success, .status-success { background-color: #e6f4ea; color: #137333; }
.badge-warning, .status-default { background-color: #fef7e0; color: #b06000; }
.badge-danger { background-color: #fce8e6; color: #c5221f; }

.text-center { text-align: center; }
.text-price { color: var(--price-color); font-weight: 700; }
.text-success { color: #137333; font-weight: 700; }
.text-important { color: #1e3a8a; font-weight: 700; }

.empty-state { text-align: center; padding: 40px 20px; background: #fff; border-radius: 12px; box-shadow: var(--shadow); color: var(--text-muted); }
.empty-icon { font-size: 2.5rem; margin-bottom: 15px; color: #cbd5e1; }

/* ==========================================================================
   8. 手機專用固定式底部選單 (Sticky Bottom Navigation)
   ========================================================================== */
.bottom-nav-spacer { height: 75px; } /* 為頁尾留空間，防止內容被遮住 */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #ffffff;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); /* 相容 iPhone 底部黑條 */
    z-index: 999;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}
.nav-item-form { flex: 1; display: flex; justify-content: center; }
.nav-link {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: #64748b;
    font-size: 0.75rem;
    cursor: pointer;
    width: 100%;
    padding: 4px 0;
    transition: color 0.2s;
}
.nav-link i { font-size: 1.25rem; }
.nav-link.active { color: var(--primary-color); font-weight: 700; }

/* ==========================================================================
   9. 頁尾樣式 (Footer)
   ========================================================================== */
.main-footer { text-align: center; padding: 20px 0; margin-top: 20px; border-top: 1px solid var(--border-color); }
.copyright { font-size: 0.8rem; color: var(--text-muted); }
.system-version { font-size: 0.7rem; color: #cbd5e1; margin-top: 2px; }

/* ===== App Engine + Firestore v3 additions ===== */
a.nav-link { text-decoration: none; }
.liff-loading-page {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  min-height:100vh; margin:0; background:#f5f5f5; font-family:'Noto Sans TC',sans-serif;
}
.liff-loader {
  width:42px; height:42px; border-radius:50%; border:4px solid #e5e7eb;
  border-top-color:#06c755; animation:liff-spin 1s linear infinite;
}
.liff-status { margin-top:18px; color:#5f6368; font-size:15px; text-align:center; padding:0 24px; }
.liff-status.is-error { color:#b3261e; }
@keyframes liff-spin { to { transform:rotate(360deg); } }
.notice { padding:12px 14px; border-radius:10px; margin:0 0 16px; font-weight:500; }
.notice-success { background:#e8f5e9; color:#1b5e20; }
.notice-error { background:#ffebee; color:#b71c1c; }
.status-inline-danger { color:#c62828; font-weight:700; margin-left:6px; }
.bonus-value { font-weight:700; color:#2e7d32; margin-right:6px; }
.system-state-card { max-width:680px; margin:40px auto; }
.system-state-card h2 { margin:12px 0 10px; }
.system-state-card code { background:#f2f3f5; border-radius:5px; padding:2px 5px; }
.error-code { font-size:48px; font-weight:700; color:#9aa0a6; }
.bottom-nav > a.nav-link { flex: 1; }
