:root {
    --primary: #1a73e8;
        --primary2: #D27ADB;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --success: #34a853;
    --danger: #ea4335;
    --warning: #fbbc04;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #202124;
    --text-light: #5f6368;
    --border: #dadce0;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-hover: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    padding-bottom: 64px; /* 預留底部 tab-bar 空間 */
}
body.no-tabbar { padding-bottom: 0; }

/* ===== 頁面切換動畫 ===== */
.page {
    display: none;
    width: 100%;
    animation: pageSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.page.active {
    display: block;
}
.page.login-page.active {
    display: flex;
}
@keyframes pageSlideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}
.page.slide-out {
    transform: translateX(-30%);
    opacity: 0;
}

/* ===== 登入頁 ===== */
.login-page {
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    transform: translateY(0);
    transition: var(--transition);
}
.login-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 24px 70px rgba(0,0,0,0.35);
}
.login-card h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 28px;
    color: var(--primary2);
}
.login-card .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 32px;
    font-size: 14px;
}

/* ===== 表單元件 ===== */
.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-light);
}
.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    transition: var(--transition);
    outline: none;
}
.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}
select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235f6368' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ===== 按鈕 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.3);
}
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 13px; }

/* ===== 頂部導航 ===== */
.navbar {
    background: var(--card-bg);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar-brand {
    font-size: 18px;
    font-weight: 600;
    color: var(--primary2);
}
.navbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-light);
}

/* ===== 搜尋列 ===== */
.search-bar {
    padding: 16px 20px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}
.search-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.search-row .form-input {
    flex: 1;
    min-width: 120px;
}

/* ===== 篩選 chip ===== */
.filter-chip {
    margin: 12px 20px 0;
    padding: 8px 14px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    animation: fadeInUp 0.3s ease;
}
.filter-chip button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 14px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}
.filter-chip button:hover { background: var(--primary-dark); }

/* ===== 卡片列表 ===== */
.card-list {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.member-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow);
    transition: var(--transition);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.member-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary);
    transform: scaleY(0);
    transition: var(--transition);
}
.member-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}
.member-card:hover::before {
    transform: scaleY(1);
}
.member-card:active {
    transform: scale(0.98);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.card-name {
    font-size: 17px;
    font-weight: 600;
}
.card-badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}
.card-badge.rep {
    background: #fef3e2;
    color: #e37400;
}
.card-info {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 13px;
    color: var(--text-light);
}
.card-info span::before {
    content: attr(data-icon);
    margin-right: 4px;
}

/* ===== 詳細頁/編輯頁 ===== */
.detail-page {
    padding: 20px;
}
.detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}
.back-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: none;
    cursor: pointer;
    font-size: 18px;
    transition: var(--transition);
}
.back-btn:hover { background: var(--border); }

.detail-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.detail-row {
    display: flex;
    padding: 12px 0;
    border-bottom: 1px solid var(--bg);
}
.detail-row:last-child { border-bottom: none; }
.detail-label {
    width: 100px;
    flex-shrink: 0;
    font-size: 13px;
    color: var(--text-light);
    font-weight: 500;
}
.detail-value {
    font-size: 15px;
}
.detail-value.multiline {
    white-space: pre-line;
    line-height: 1.6;
}

/* ===== 分頁 ===== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 20px;
}
.pagination button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
}
.pagination button:hover { background: var(--primary-light); }
.pagination button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== 底部 Tab 導航 ===== */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    display: flex;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
}
.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    font-size: 11px;
    color: var(--text-light);
    cursor: pointer;
    transition: var(--transition);
    border: none;
    background: none;
}
.tab-item.active {
    color: var(--primary);
}
.tab-item .tab-icon {
    font-size: 20px;
    margin-bottom: 2px;
}

/* ===== 彈出通知 ===== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 9999;
    transition: var(--transition);
    opacity: 0;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== FAB 按鈕 ===== */
.fab {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(26, 115, 232, 0.4);
    transition: var(--transition);
    z-index: 50;
}
.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(26, 115, 232, 0.5);
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}
.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: var(--card-bg);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-overlay.show .modal-content {
    transform: translateY(0);
}
.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

/* ===== 統計卡片 ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 16px 20px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    text-align: center;
}
.stat-number {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}
.stat-label {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

/* ===== 妃妃黨員卡片 (完整資料) ===== */
.fifi-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px 18px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
    border-left: 4px solid var(--primary2, #D27ADB);
}
.fifi-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}
.fifi-card.missing {
    background: #ffe0ec;
    border-left-color: #e91e63;
}
.fifi-card.missing:hover {
    background: #ffd1e1;
}
.fifi-card .fc-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.fifi-card .fc-name {
    font-size: 16px;
    font-weight: 600;
}
.fifi-card .fc-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.fifi-card .fc-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px 12px;
    font-size: 12.5px;
    color: var(--text-light);
    margin-top: 4px;
}
.fifi-card .fc-grid div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fifi-card .fc-grid b { color: var(--text); font-weight: 500; }
.fifi-card .fc-rep {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    font-size: 12px;
}
.fifi-card .fc-rep .pill {
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
}
.fifi-card .fc-rep .pill.empty {
    background: #fde0ea;
    color: #c2185b;
}
@media (max-width: 600px) {
    .fifi-card .fc-grid { grid-template-columns: 1fr; }
}

/* ===== 處所計票 ===== */
.byloc-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    margin-bottom: 16px;
}
.byloc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary-light);
    margin-bottom: 12px;
}
.byloc-loc {
    font-size: 17px;
    font-weight: 600;
    color: var(--primary);
}
.byloc-total {
    font-size: 13px;
    color: var(--text-light);
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 12px;
}
.byloc-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.byloc-col h4 {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--bg);
}
.byloc-col h4 small { color: var(--text-light); font-size: 11px; font-weight: normal; }
.byloc-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}
.byloc-row:hover { background: var(--primary-light); }
.byloc-no {
    min-width: 28px;
    color: var(--primary);
    font-weight: 600;
}
.byloc-name { flex: 1; }
.byloc-votes {
    font-weight: 600;
    color: var(--text);
    min-width: 32px;
    text-align: right;
}
@media (max-width: 600px) {
    .byloc-cols { grid-template-columns: 1fr; }
}

/* ===== 計票總覽 ===== */
.tally-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.tally-header h2 { font-size: 20px; margin: 0; }
.tally-header small { color: var(--text-light); font-size: 12px; margin-right: auto; }
.tally-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    margin-bottom: 16px;
}
.tally-section h3 {
    font-size: 16px;
    color: var(--primary);
    margin-bottom: 12px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.tally-section h3 small { font-size: 12px; color: var(--text-light); font-weight: normal; }
.tally-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 6px;
}
.tally-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--bg);
    font-size: 13px;
    transition: var(--transition);
    cursor: pointer;
}
.tally-item:hover { background: var(--primary-light); }
.tally-item.zero {
    background: transparent;
    color: var(--text-light);
}
.tally-item.zero:hover { background: var(--bg); }
.tally-item .t-no {
    min-width: 28px;
    font-weight: 600;
    color: var(--primary);
}
.tally-item.zero .t-no { color: var(--text-light); }
.tally-item .t-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tally-item .t-count {
    font-weight: 600;
    min-width: 36px;
    text-align: right;
}
.tally-item.zero .t-count { font-weight: normal; }
.tally-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--bg);
}
.tally-summary div {
    text-align: center;
}
.tally-summary .label { font-size: 11px; color: var(--text-light); }
.tally-summary .val { font-size: 18px; font-weight: 600; color: var(--primary); }

/* ===== 票數統計 ===== */
.vote-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
.vote-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: var(--primary);
}
.vote-section h3 small { font-size: 12px; color: var(--text-light); font-weight: normal; }
.vote-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--bg);
    cursor: pointer;
    transition: var(--transition);
}
.vote-row:hover { background: var(--primary-light); margin: 0 -12px; padding: 10px 12px; border-radius: 6px; border-bottom-color: transparent; }
.vote-row:last-child { border-bottom: none; }
.vote-no {
    min-width: 120px;
    font-weight: 600;
    color: var(--primary);
    font-size: 15px;
}
.vote-name {
    color: var(--text);
    font-weight: 500;
    font-size: 14px;
    margin-left: 4px;
}
.vote-bar-wrap {
    flex: 1;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}
.vote-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #4a90e2);
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.vote-count {
    min-width: 90px;
    text-align: right;
    font-size: 13px;
    color: var(--text-light);
}

/* ===== Loading ===== */
.loading {
    display: flex;
    justify-content: center;
    padding: 40px;
}
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 空狀態 ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }

/* ===== 響應式 ===== */
@media (min-width: 768px) {
    .card-list { max-width: 600px; margin: 0 auto; }
    .search-bar { max-width: 600px; margin: 0 auto; padding: 16px 0; }
    .stats-row { max-width: 600px; margin: 0 auto; grid-template-columns: repeat(4, 1fr); }
    .modal-content { border-radius: 16px; margin-bottom: 20px; }
}

/* ===== 動畫 ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-in {
    animation: fadeInUp 0.4s ease forwards;
}
.member-card { animation: fadeInUp 0.4s ease forwards; }
.member-card:nth-child(1) { animation-delay: 0s; }
.member-card:nth-child(2) { animation-delay: 0.05s; }
.member-card:nth-child(3) { animation-delay: 0.1s; }
.member-card:nth-child(4) { animation-delay: 0.15s; }
.member-card:nth-child(5) { animation-delay: 0.2s; }
