/* ============================================
   FitTrack - 极简风格样式表
   ============================================ */

/* --- CSS 变量 --- */
:root {
  --primary: #10B981;
  --primary-dark: #059669;
  --primary-light: #D1FAE5;
  --bg: #F9FAFB;
  --card-bg: #FFFFFF;
  --text: #111827;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --border: #E5E7EB;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --info: #3B82F6;
  --info-light: #DBEAFE;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --header-h: 56px;
  --nav-h: 64px;
  --max-w: 480px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* --- Reset --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
* { -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }
svg { display: block; }

/* --- 滚动条隐藏 --- */
::-webkit-scrollbar { width: 0; height: 0; }

/* --- App 容器 --- */
#app {
  max-width: var(--max-w);
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  background: var(--bg);
}

/* --- 顶部导航栏 --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.header-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  transition: background 0.2s;
}
.icon-btn:active { background: var(--border); }

/* --- 主内容区 --- */
#main-content {
  padding: 16px;
  padding-bottom: calc(var(--nav-h) + 24px);
  min-height: calc(100vh - var(--header-h));
}

/* --- 底部导航栏 --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-w);
  height: var(--nav-h);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  padding: 8px 4px;
  color: var(--text-tertiary);
  font-size: 0.6875rem;
  transition: color 0.2s;
}
.nav-item.active { color: var(--primary); }
.nav-item span { font-weight: 500; }
.nav-center { position: relative; }
.nav-center-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -20px;
  box-shadow: 0 4px 12px rgba(16,185,129,0.4);
  transition: transform 0.2s;
}
.nav-center-btn:active { transform: scale(0.92); }

/* --- 通用组件 --- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  margin-top: 8px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-outline {
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:active { border-color: var(--primary); color: var(--primary); }
.btn-text { color: var(--primary); padding: 8px 12px; }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.8125rem; }

/* --- 进度条 --- */
.progress-ring {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto;
}
.progress-ring svg { transform: rotate(-90deg); }
.progress-ring-bg { stroke: var(--border); }
.progress-ring-fg { stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.progress-ring-text {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.progress-ring-value { font-size: 1.75rem; font-weight: 800; color: var(--text); }
.progress-ring-label { font-size: 0.6875rem; color: var(--text-tertiary); }

.macro-bar { margin-bottom: 10px; }
.macro-bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  margin-bottom: 4px;
}
.macro-bar-name { font-weight: 600; }
.macro-bar-value { color: var(--text-secondary); }
.macro-bar-track {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.macro-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}
.fill-carbs { background: #F59E0B; }
.fill-protein { background: #3B82F6; }
.fill-fat { background: #EF4444; }
.fill-cal { background: var(--primary); }

/* --- 仪表盘 --- */
.greeting { font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; }
.greeting-sub { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 16px; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 1.5rem; font-weight: 800; }
.stat-label { font-size: 0.75rem; color: var(--text-secondary); }
.stat-unit { font-size: 0.75rem; color: var(--text-tertiary); font-weight: 400; }

/* --- 健身模块 --- */
.plan-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.15s;
}
.plan-card:active { transform: scale(0.98); }
.plan-card-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 8px; }
.plan-name { font-weight: 700; font-size: 1rem; }
.plan-meta { font-size: 0.75rem; color: var(--text-secondary); }
.plan-exercises { font-size: 0.8125rem; color: var(--text-secondary); }
.exercise-tag {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  margin: 2px;
}

.workout-session { margin-bottom: 16px; }
.exercise-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.exercise-name { font-weight: 700; font-size: 0.9375rem; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.set-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: none; }
set-num { font-size: 0.75rem; color: var(--text-tertiary); width: 32px; }
.set-input {
  flex: 1;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.8125rem;
  max-width: 70px;
}
.set-checkbox {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.set-checkbox.checked { background: var(--primary); border-color: var(--primary); }
.set-checkbox.checked::after { content: "✓"; color: white; font-size: 0.75rem; font-weight: bold; }

/* --- 饮食模块 --- */
.meal-section { margin-bottom: 16px; }
.meal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.meal-title { font-weight: 700; font-size: 0.9375rem; }
.meal-cal { font-size: 0.8125rem; color: var(--text-secondary); }
.meal-add-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 600;
}
.food-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  box-shadow: var(--shadow);
}
.food-item-info { flex: 1; }
.food-item-name { font-weight: 600; font-size: 0.875rem; }
.food-item-meta { font-size: 0.75rem; color: var(--text-secondary); }
.food-item-cal { text-align: right; }
.food-item-cal-value { font-weight: 700; font-size: 0.9375rem; }
.food-item-cal-unit { font-size: 0.6875rem; color: var(--text-tertiary); }
.food-item-delete {
  margin-left: 8px;
  color: var(--text-tertiary);
  padding: 4px;
}

/* --- 拍照模块 --- */
.photo-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  margin-bottom: 16px;
  transition: all 0.2s;
  cursor: pointer;
}
.photo-upload-area:active { border-color: var(--primary); background: var(--primary-light); }
.photo-upload-icon { color: var(--text-tertiary); margin-bottom: 12px; }
.photo-upload-text { font-size: 0.9375rem; color: var(--text-secondary); font-weight: 500; }
.photo-upload-hint { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 4px; }

.photo-preview { width: 100%; border-radius: var(--radius); margin-bottom: 12px; max-height: 300px; object-fit: cover; }
.analysis-result { margin-bottom: 16px; }
.ai-food-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ai-food-info { flex: 1; }
.ai-food-name { font-weight: 600; font-size: 0.9375rem; }
.ai-food-nutrition { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }
.ai-food-cal { font-weight: 700; color: var(--primary); font-size: 1rem; }

/* --- 设置模块 --- */
.settings-group { margin-bottom: 20px; }
.settings-group-title { font-size: 0.8125rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; padding-left: 4px; }
.settings-item {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.settings-item:last-child { border-bottom: none; border-radius: var(--radius); }
.settings-item-label { font-size: 0.9375rem; }
.settings-item-value { font-size: 0.875rem; color: var(--text-secondary); }
.settings-input {
  width: 80px;
  text-align: right;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.875rem;
}
.settings-input-full {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.875rem;
  margin-top: 8px;
}

/* --- 模态弹窗 --- */
#modal-container { position: fixed; inset: 0; z-index: 200; display: none; }
#modal-container.show { display: block; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  animation: fadeIn 0.2s;
}
.modal-panel {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-w);
  background: var(--card-bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-title { font-size: 1.125rem; font-weight: 700; }
.modal-close { font-size: 1.5rem; color: var(--text-tertiary); padding: 4px 8px; line-height: 1; }

/* --- 搜索 --- */
.search-bar {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  margin-bottom: 12px;
}
.search-bar:focus { outline: none; border-color: var(--primary); }
.category-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.category-tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8125rem;
  white-space: nowrap;
  background: var(--border);
  color: var(--text-secondary);
  transition: all 0.2s;
}
.category-tab.active { background: var(--primary); color: white; }
.food-search-result {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.food-search-result:active { background: var(--bg); }
.food-search-name { font-weight: 600; font-size: 0.875rem; }
.food-search-meta { font-size: 0.75rem; color: var(--text-secondary); }

/* --- Toast --- */
#toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s, toastOut 0.3s 2.5s forwards;
  max-width: 300px;
  text-align: center;
}
.toast.success { background: var(--primary); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

/* --- 日期选择器 --- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s;
}
.overlay.hidden { display: none; }
.date-picker-panel {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 90%;
  max-width: 360px;
}
.date-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.date-picker-header span { font-weight: 700; font-size: 1rem; }
.date-picker-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 12px;
}
.date-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.2s;
}
.date-day.other-month { color: var(--text-tertiary); opacity: 0.4; }
.date-day.today { font-weight: 700; color: var(--primary); }
.date-day.selected { background: var(--primary); color: white; font-weight: 700; }
.date-day.has-data::after {
  content: "";
  position: absolute;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--primary);
}
.date-day { position: relative; }
.date-picker-actions { display: flex; justify-content: space-between; }

/* --- 空状态 --- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
}
.empty-state-icon { margin-bottom: 12px; }
.empty-state-text { font-size: 0.9375rem; }
.empty-state-hint { font-size: 0.8125rem; margin-top: 4px; }

/* --- 标签页 --- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  background: var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: all 0.2s;
}
.tab.active { background: var(--card-bg); color: var(--text); box-shadow: var(--shadow); }

/* --- 动画 --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}
.loading-text { text-align: center; color: var(--text-secondary); font-size: 0.875rem; }

/* --- 工具类 --- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.text-secondary { color: var(--text-secondary); }
.font-bold { font-weight: 700; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
