:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #dbeafe;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #e5e7eb;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* 載入中 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    color: white;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    margin-top: 16px;
    font-size: 16px;
}

/* 容器 */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg-secondary);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
}

.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 24px 20px;
    text-align: center;
    position: relative;
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.week-info {
    font-size: 14px;
    opacity: 0.9;
}

.back-btn {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.back-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(0.95);
}

.user-info h2 {
    font-size: 20px;
    margin-bottom: 4px;
}

.group-path {
    font-size: 12px;
    opacity: 0.85;
}

/* 麵包屑導航 */
.breadcrumb {
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
}

.breadcrumb-item {
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.3s;
    position: relative;
}

.breadcrumb-item:not(:last-child)::after {
    content: '›';
    position: absolute;
    right: -8px;
    color: var(--text-secondary);
    font-size: 16px;
}

.breadcrumb-item:hover {
    background: var(--bg-secondary);
}

.breadcrumb-item.active {
    color: var(--primary);
    font-weight: 600;
    background: var(--primary-light);
}

/* 導航容器 */
.navigation-container {
    padding: 20px;
    background: var(--bg-secondary);
    min-height: calc(100vh - 220px);
}

.group-view {
    display: none;
    animation: slideIn 0.3s ease;
}

.group-view.active {
    display: block;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 組別卡片網格 */
.group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.group-card {
    background: white;
    padding: 24px 16px;
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.group-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    transform: scaleX(0);
    transition: transform 0.3s;
}

.group-card:hover::before {
    transform: scaleX(1);
}

.group-card:active {
    transform: scale(0.95);
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.group-card-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.group-card-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.group-card-count {
    font-size: 12px;
    color: var(--text-secondary);
}

/* 成員列表 */
.member-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.member-item {
    background: white;
    padding: 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    gap: 12px;
}

.member-item:active {
    transform: scale(0.98);
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.member-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    font-weight: 600;
    flex-shrink: 0;
}

.member-info {
    flex: 1;
}

.member-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.member-groups {
    font-size: 13px;
    color: var(--text-secondary);
}


.user-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-item {
    background: white;
    padding: 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
    border: 2px solid transparent;
}

.user-item:active {
    transform: scale(0.98);
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.user-item-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.user-item-group {
    font-size: 13px;
    color: var(--text-secondary);
}

.user-item.recent {
    border-left: 4px solid var(--primary);
}

.no-results {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-size: 14px;
}

/* Tabs */
.tabs {
    display: flex;
    background: white;
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 16px;
    background: none;
    border: none;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    transition: color 0.3s;
    font-family: inherit;
}

.tab.active {
    color: var(--primary);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
    border-radius: 3px 3px 0 0;
}

.tab-content {
    display: none;
    padding: 20px;
    background: var(--bg-secondary);
    min-height: calc(100vh - 280px);
}

.tab-content.active {
    display: block;
}

/* 表單 */
.week-selector {
    background: white;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.week-selector h3 {
    font-size: 16px;
    color: var(--text-primary);
}

.record-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-section {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.form-section h4 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Checkbox 樣式 */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
    padding-left: 36px;
    user-select: none;
    min-height: 24px;
}

.checkbox-item input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.checkmark {
    position: absolute;
    left: 0;
    height: 24px;
    width: 24px;
    background-color: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 6px;
    transition: all 0.3s;
}

.checkbox-item:hover .checkmark {
    border-color: var(--primary);
}

.checkbox-item input:checked~.checkmark {
    background-color: var(--primary);
    border-color: var(--primary);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 7px;
    top: 3px;
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-item input:checked~.checkmark:after {
    display: block;
}

.label-text {
    font-size: 15px;
    color: var(--text-primary);
}

/* Number 輸入 */
.number-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.number-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.number-item .label-text {
    font-size: 15px;
    color: var(--text-primary);
}

.number-item input {
    width: 80px;
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    text-align: center;
    font-family: inherit;
    transition: all 0.3s;
}

.number-item input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* 按鈕 */
.form-actions {
    margin-top: 8px;
}

.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-secondary:active {
    transform: scale(0.98);
    background: var(--primary-light);
}

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* 記錄狀態 */
.record-status {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
}

.record-status.success {
    background: var(--success-light);
    color: var(--success);
}

.record-status.error {
    background: #fee2e2;
    color: var(--danger);
}

/* 歷史查詢 */
.history-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.week-selector-dropdown {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    background: white;
    cursor: pointer;
}

.history-content {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    min-height: 200px;
}

.placeholder-text {
    text-align: center;
    color: var(--text-secondary);
    padding: 60px 20px;
}

.history-record {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.history-item-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.history-item-value.checked {
    color: var(--success);
}

/* 管理員連結 */
.admin-link {
    text-align: center;
    padding: 20px;
    background: var(--bg-secondary);
}

.admin-link a {
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 14px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    max-width: 90%;
    text-align: center;
    backdrop-filter: blur(10px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 響應式調整 */
@media (max-width: 400px) {
    .header h1 {
        font-size: 20px;
    }

    .search-container {
        padding: 16px;
    }

    .tab-content {
        padding: 16px;
    }

    .form-section {
        padding: 16px;
    }
}

/* 深色模式支援（可選） */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #f9fafb;
        --text-secondary: #9ca3af;
        --bg-primary: #1f2937;
        --bg-secondary: #111827;
        --bg-tertiary: #374151;
        --border: #374151;
    }
}

/* ===== 組長功能 ===== */
.leader-bar {
    padding: 12px 16px 4px;
    display: flex;
    justify-content: flex-end;
}

.btn-leader {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 3px 10px rgba(245,87,108,0.35);
    transition: all 0.2s;
}

.btn-leader:active {
    transform: scale(0.96);
}

.leader-week-bar {
    display: flex;
    gap: 12px;
    padding: 16px;
    background: white;
    border-bottom: 1px solid var(--border);
}

.leader-stats-bar {
    padding: 16px;
    background: white;
    border-bottom: 1px solid var(--border);
}

.leader-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.leader-week-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-chip {
    font-size: 13px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
}

.chip-all {
    background: #d1fae5;
    color: #065f46;
}

.chip-part {
    background: #fef3c7;
    color: #92400e;
}

.leader-progress {
    height: 8px;
    background: var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.leader-progress-inner {
    height: 100%;
    background: linear-gradient(90deg, #34d399, #059669);
    border-radius: 8px;
    transition: width 0.5s ease;
}

.leader-member-cards {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-secondary);
    min-height: 200px;
}

.leader-card {
    background: white;
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid transparent;
}

.card-filled {
    border-left-color: var(--success);
}

.card-unfilled {
    border-left-color: #fca5a5;
    opacity: 0.8;
}

.leader-card-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.lc-name {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.fill-chip {
    font-size: 12px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 12px;
}

.chip-filled {
    background: #d1fae5;
    color: #065f46;
}

.chip-unfill {
    background: #fee2e2;
    color: #991b1b;
}

.leader-badges {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.item-chip {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}

.chip-done {
    background: #d1fae5;
    color: #065f46;
}

.chip-miss {
    background: #fee2e2;
    color: #991b1b;
}

.item-rate {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 4px;
}