/* ==========================================================================
   全域樣式與變數設定
   ========================================================================== */
:root {
    --primary-color: #3b82f6;      /* 科技琉璃藍 */
    --primary-hover: #2563eb;      /* 藍色懸停深色 */
    --bg-gradient: linear-gradient(135deg, #f0f4f8, #e2e8f0); /* 柔和背景漸層 */
    --card-bg: rgba(255, 255, 255, 0.85); /* 半透明卡片背景（毛玻璃效果基礎） */
    --text-main: #1e293b;          /* 主要文字顏色 */
    --text-muted: #64748b;         /* 次要/說明文字 */
    --border-color: #cbd5e1;       /* 邊框顏色 */
    --profit-up: #e11d48;          /* 台灣股市：紅代表上漲與獲利 */
    --profit-down: #16a34a;        /* 台灣股市：綠代表下跌與虧損 */
    --profit-neutral: #475569;     /* 損益為零或中性狀態 */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Microsoft JhengHei", sans-serif;
}

body {
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-main);
    padding: 2rem 1rem;
    display: flex;
    justify-content: center;
}

/* 主容器 */
.container {
    width: 100%;
    max-width: 1200px;
}

/* ==========================================================================
   頁面標題區與會員狀態
   ========================================================================== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    position: relative;
    padding-left: 0.75rem;
}

header h1::before {
    content: "";
    position: absolute;
    left: 0;
    top: 15%;
    height: 70%;
    width: 4px;
    background-color: var(--primary-color);
    border-radius: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.user-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 500;
}

/* ==========================================================================
   按鈕樣式
   ========================================================================== */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.secondary-btn {
    background-color: #e2e8f0;
    color: #475569;
}

.secondary-btn:hover {
    background-color: #cbd5e1;
}

.danger-btn {
    background-color: #fee2e2;
    color: #dc2626;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.danger-btn:hover {
    background-color: #fca5a5;
}

.edit-btn {
    background-color: #dbeafe;
    color: #2563eb;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    margin-right: 0.5rem;
}

.edit-btn:hover {
    background-color: #bfdbfe;
}

/* ==========================================================================
   總覽看板卡片
   ========================================================================== */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.05);
    transition: transform 0.2s ease;
}

.card:hover {
    transform: translateY(-3px);
}

.card h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.card p {
    font-size: 1.6rem;
    font-weight: 700;
}

/* ==========================================================================
   表格區樣式
   ========================================================================== */
.table-container {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.05);
    overflow-x: auto; /* 手機版防溢出滾動 */
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th, td {
    padding: 1rem;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
}

td {
    font-size: 0.95rem;
}

tbody tr:hover {
    background-color: rgba(241, 245, 249, 0.5);
}

.no-data-msg {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 1rem;
}

/* ==========================================================================
   損益顏色表示（台灣股市風格：紅字為賺，綠字為賠）
   ========================================================================== */
.profit-up {
    color: var(--profit-up);
    font-weight: 600;
}

.profit-down {
    color: var(--profit-down);
    font-weight: 600;
}

.profit-neutral {
    color: var(--profit-neutral);
    font-weight: 600;
}

/* ==========================================================================
   對話框 (Modal) 樣式
   ========================================================================== */
.modal {
    display: none; /* 預設隱藏 */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4); /* 暗化背景 */
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
}

/* 當有 show 類別時才顯示（會透過 JavaScript 動態切換） */
.modal.show {
    display: flex;
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    position: relative;
    animation: slideIn 0.3s ease;
}

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

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close-btn:hover {
    color: var(--text-main);
}

.modal h2 {
    margin-bottom: 1.5rem;
    font-size: 1.4rem;
    font-weight: 700;
}

/* 表單欄位排版 */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-group input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 2rem;
}

/* ==========================================================================
   Supabase 登入 / 註冊全螢幕遮罩樣式
   ========================================================================== */
.auth-overlay {
    display: flex; /* 預設為 flex 佈局 */
    position: fixed;
    z-index: 2000; /* 高於其他所有元素 */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.65); /* 暗底 */
    backdrop-filter: blur(10px); /* 背景高強度模糊，隔絕主系統內容 */
    justify-content: center;
    align-items: center;
}

.auth-box {
    background-color: white;
    padding: 2.5rem 2rem;
    border-radius: 16px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: slideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-box h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    color: var(--text-main);
}

.auth-submit-btn {
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
}

.auth-switch-text {
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

.auth-switch-text a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.auth-switch-text a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   RWD 手機版優化
   ========================================================================== */
@media (max-width: 768px) {
    body {
        padding: 1rem 0.5rem;
    }
    
    header h1 {
        font-size: 1.5rem;
    }

    .card p {
        font-size: 1.4rem;
    }

    th, td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
}
