/* ========================================
   BodyTrack - 主要樣式
   日式和風 (Zen) 設計
======================================== */

/* ========================================
   基礎重置與全域樣式
======================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    opacity: 0.8;
}

img {
    max-width: 100%;
    height: auto;
}

/* ========================================
   導航列
======================================== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--navbar-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 1000;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.logo-icon {
    font-size: 1.5rem;
}

.logo-text {
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}

.nav-menu {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: var(--transition);
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-primary);
    color: #fff;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: var(--transition);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    transform: rotate(20deg);
}

/* ========================================
   主要內容區
======================================== */
.main-content {
    padding: 80px 1.5rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
    letter-spacing: 0.05em;
}

/* ========================================
   卡片
======================================== */
.card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-light);
}

.card h2 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.card h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* ========================================
   按鈕
======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius-sm);
    border: none;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-hover);
}

.btn-danger {
    background: var(--accent-danger);
    color: #fff;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-full {
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.range-btn.active {
    background: var(--accent-primary);
    color: #fff;
}

/* ========================================
   表單
======================================== */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.form-group .optional {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.form-group .hint {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

input,
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-sm);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(144, 183, 125, 0.2);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* ========================================
   認證頁面
======================================== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 2.5rem;
    box-shadow: var(--card-shadow);
    position: relative;
    z-index: 1;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header .logo {
    font-size: 2rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.auth-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.error-message {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid var(--accent-danger);
    color: var(--accent-danger);
    padding: 0.75rem;
    border-radius: var(--border-radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.hidden {
    display: none !important;
}

.zen-pattern {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 0L60 30L30 60L0 30L30 0z' fill='%23888' fill-opacity='0.4'/%3E%3C/svg%3E");
    pointer-events: none;
}

/* ========================================
   日期選擇
======================================== */
.date-picker-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.date-input {
    width: auto;
    text-align: center;
    font-size: 1.1rem;
    padding: 0.5rem 1rem;
}

/* ========================================
   摘要區
======================================== */
.summary-section {
    margin-bottom: 1.5rem;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.summary-card {
    padding: 1.25rem;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.card-icon {
    font-size: 1.25rem;
}

.card-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.card-body {
    margin-bottom: 1rem;
}

.big-number {
    font-size: 2.5rem;
    font-weight: 300;
    line-height: 1;
}

.unit {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-left: 0.25rem;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
}

.bmi-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.trend {
    font-weight: 500;
}

/* ========================================
   卡路里顯示
======================================== */
.calorie-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.calorie-in,
.calorie-out,
.calorie-net {
    text-align: center;
}

.calorie-display .label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.calorie-display .value {
    font-size: 1.25rem;
    font-weight: 500;
}

.calorie-in .value {
    color: var(--accent-success);
}

.calorie-out .value {
    color: var(--accent-danger);
}

.calorie-sep {
    color: var(--text-muted);
}

/* ========================================
   目標進度
======================================== */
.goal-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.goal-current,
.goal-target {
    font-size: 1.5rem;
    font-weight: 300;
}

.goal-arrow {
    color: var(--text-muted);
}

.goal-remaining {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ========================================
   進度條
======================================== */
.progress-bar {
    height: 6px;
    background: var(--progress-bg);
    border-radius: 3px;
    overflow: hidden;
    flex-grow: 1;
    margin-right: 0.75rem;
}

.progress-fill {
    height: 100%;
    background: var(--progress-fill);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.progress-fill.goal-progress {
    background: var(--progress-goal);
}

.progress-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ========================================
   圖表區
======================================== */
.chart-section {
    padding: 1.5rem;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.chart-controls {
    display: flex;
    gap: 0.5rem;
}

.chart-container {
    position: relative;
    height: 300px;
}

/* ========================================
   快速輸入
======================================== */
.quick-input-section {
    margin-bottom: 1rem;
}

.quick-input-grid {
    display: grid;
    gap: 1rem;
}

.quick-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}

.quick-form input,
.quick-form select {
    width: auto;
    min-width: 100px;
    flex: 1;
}

.input-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 1;
}

.input-group input {
    min-width: 80px;
}

/* ========================================
   快速操作
======================================== */
.quick-actions-section {
    margin-top: 1.5rem;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.action-card h3 {
    margin-bottom: 1rem;
}

/* ========================================
   表格
======================================== */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.data-table th {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.data-table tr:hover {
    background: var(--bg-hover);
}

/* ========================================
   摘要列
======================================== */
.summary-row {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
}

.summary-item {
    text-align: center;
}

.summary-item .label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.summary-item .value {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--accent-primary);
}

.summary-item .unit {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ========================================
   餐別列表
======================================== */
.meal-section {
    margin-bottom: 1.5rem;
}

.meal-section h3 {
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
}

.food-list {
    list-style: none;
}

.food-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-light);
}

.food-list li:last-child {
    border-bottom: none;
}

.food-name {
    flex: 1;
}

.food-cal {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-right: 1rem;
}

/* ========================================
   運動列表
======================================== */
.exercise-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.exercise-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-sm);
}

.exercise-icon {
    font-size: 1.25rem;
}

.exercise-type {
    flex: 1;
    font-weight: 500;
}

.exercise-duration,
.exercise-cal {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.empty-message {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

/* ========================================
   設定頁面
======================================== */
.theme-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.theme-option {
    cursor: pointer;
}

.theme-option input {
    display: none;
}

.theme-preview {
    display: block;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 2px solid transparent;
    text-align: center;
    transition: var(--transition);
}

.theme-option input:checked+.theme-preview {
    border-color: var(--accent-primary);
}

.theme-preview-dark {
    background: #1a1a1a;
    color: #f5f5f0;
}

.theme-preview-light {
    background: #faf8f5;
    color: #2d2d2d;
}

.divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 1.5rem 0;
}

.import-result {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-sm);
}

/* ========================================
   Toast 通知
======================================== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    z-index: 2000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ========================================
   響應式設計
======================================== */
@media (max-width: 768px) {
    .navbar {
        padding: 0 1rem;
    }

    .nav-menu {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--navbar-bg);
        border-top: 1px solid var(--border-light);
        padding: 0.5rem;
        justify-content: space-around;
    }

    .nav-link {
        flex-direction: column;
        font-size: 0.7rem;
        padding: 0.5rem;
    }

    .main-content {
        padding-bottom: 80px;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .quick-form {
        flex-direction: column;
    }

    .quick-form input,
    .quick-form select,
    .quick-form button {
        width: 100%;
    }

    .input-group {
        flex-direction: column;
    }

    .actions-grid {
        grid-template-columns: 1fr;
    }

    .chart-container {
        height: 250px;
    }

    .calorie-display {
        flex-wrap: wrap;
    }

    .theme-options {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   雲端備份
======================================== */
.google-connect-section p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-badge.connected {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-success);
}

.backup-list {
    max-height: 300px;
    overflow-y: auto;
}

.backup-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

.backup-item:last-child {
    border-bottom: none;
}

.backup-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.backup-name {
    font-size: 0.9rem;
    font-weight: 500;
}

.backup-time {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.backup-actions {
    display: flex;
    gap: 0.5rem;
}

.backup-list .empty,
.backup-list .loading,
.backup-list .error {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
}