/* === 全局变量 === */
:root {
  --bg-primary: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-card2: #16213e;
  --accent: #e94560;
  --accent2: #0f3460;
  --green: #4caf50;
  --yellow: #ffc107;
  --blue: #2196f3;
  --orange: #ff9800;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --border: #2a2a3e;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --nav-height: 64px;
  --header-height: 60px;
}

/* === 重置 === */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 15px;
}

button { border: none; cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; }

/* === App 容器 === */
#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* === Header === */
.app-header {
  height: var(--header-height);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.app-header h1 { font-size: 17px; font-weight: 600; color: var(--text-primary); }
.date-display { font-size: 12px; color: var(--text-secondary); }
.icon-btn { background: none; color: var(--text-primary); font-size: 20px; padding: 4px; border-radius: 8px; }

/* === 主内容区 === */
#mainContent {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + 16px);
  -webkit-overflow-scrolling: touch;
}

/* === 底部导航 === */
.bottom-nav {
 height: var(--nav-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  color: var(--text-secondary);
  padding: 6px 0;
  transition: color 0.2s;
}
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 500; }

/* === 卡片 === */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card-title {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 500;
  text-transform: uppercase;
letter-spacing: 0.5px;
}

/* === Dashboard 页 === */
.calorie-ring-container {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 4px 0;
}
.ring-wrap { position: relative; flex-shrink: 0; }
.ring-svg { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--border); stroke-width: 10; }
.ring-progress { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.8s ease; }
.ring-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.ring-cal { font-size: 22px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.ring-label { font-size: 10px; color: var(--text-secondary); margin-top: 2px; }

.calorie-stats { flex: 1; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-name { font-size: 13px; color: var(--text-secondary); }
.stat-val { font-size: 14px; font-weight: 600; }

/* 营养素进度条 */
.nutrient-bars { display: flex; flex-direction: column; gap: 10px; }
.nutrient-item {}
.nutrient-header { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 13px; }
.nutrient-name { color: var(--text-primary); font-weight: 500; }
.nutrient-val { color: var(--text-secondary); }
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.6s ease; }

/* 训练状态卡片 */
.workout-mode-btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.mode-btn {
  flex: 1;
  min-width: 80px;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  border: 1px solid var(--border);
  transition: all 0.2s;
}
.mode-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* 提醒时间显示 */
.reminder-time {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  padding: 8px 0;
}
.reminder-desc { text-align: center; color: var(--text-secondary); font-size: 13px; }

/* 今日饮食列表摘要 */
.food-summary-list { display: flex; flex-direction: column; gap: 8px; }
.food-summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
}
.food-item-name { font-size: 14px; font-weight: 500; }
.food-item-cal { font-size: 13px; color: var(--accent); font-weight: 600; }

/* === 饮食页 === */
.add-food-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.food-log-list { display: flex; flex-direction: column; gap: 8px; }
.food-log-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.food-log-main { flex: 1; }
.food-log-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.food-log-time { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.food-log-nutrients { display: flex; gap: 8px; flex-wrap: wrap; }
.nutrient-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 500;
}
.tag-protein { background: rgba(33,150,243,0.2); color: #64b5f6; }
.tag-carb { background: rgba(255,193,7,0.2); color: #ffd54f; }
.tag-fat { background: rgba(255,152,0,0.2); color: #ffb74d; }
.food-log-cal { font-size: 16px; font-weight: 700; color: var(--accent); margin-left: 10px; }
.del-btn { background: none; color: var(--text-secondary); font-size: 18px; padding: 2px 6px; margin-left: 4px; }

/* === 添加食物模态框 === */
.modal-inner { padding: 0 4px; }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.photo-upload-area {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg-primary);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 12px;
  overflow: hidden;
  position: relative;
}
.photo-upload-area img { width: 100%; height: 100%; object-fit: cover; position: absolute; }
.photo-placeholder { font-size: 40px; }
.photo-text { color: var(--text-secondary); font-size: 14px; }
#photoInput { display: none; }

.ai-analyzing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  color: var(--text-secondary);
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.form-group { margin-bottom: 12px; }
.form-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; display: block; }
.form-input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 15px;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.nutrient-inputs { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.nutrient-input-item label { font-size: 12px; color: var(--text-secondary); display: block; margin-bottom: 4px; }
.submit-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

/* === 训练页 === */
.workout-today-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.workout-status-badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 600;
}
.badge-normal { background: rgba(76,175,80,0.2); color: var(--green); }
.badge-delayed { background: rgba(255,193,7,0.2); color: var(--yellow); }
.badge-cancelled { background: rgba(233,69,96,0.2); color: var(--accent); }

.exercise-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.exercise-icon { font-size: 24px; }
.exercise-info { flex: 1; }
.exercise-name { font-size: 15px; font-weight: 600; }
.exercise-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.exercise-cal { font-size: 14px; color: var(--orange); font-weight: 600; }

.log-workout-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent2);
  color: white;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* === 历史页 === */
.history-day {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}
.history-day-header { display: flex; justify-content: space-between; margin-bottom: 10px; }
.history-date { font-size: 14px; font-weight: 600; }
.history-cal { font-size: 13px; color: var(--text-secondary); }
.history-macros { display: flex; gap: 10px; }
.macro-chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 20px;
}

/* === 设置页 === */
.settings-section { margin-bottom: 20px; }
.settings-section-title { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  border: 1px solid var(--border);
}
.settings-label { font-size: 15px; }
.settings-input {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  text-align: right;
  width: 80px;
}
.settings-input:focus { outline: none; }
.save-settings-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  margin-top: 8px;
}

/* === 模态框 === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
}
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 16px 32px;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30,30,50,0.95);
  color: white;
padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 200;
  white-space: nowrap;
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.toast.hidden { display: none; }

/* === 空状态 === */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 15px; }

/* === 滚动条 === */
::-webkit-scrollbar { width: 0; }

/* === 通知权限提示 === */
.notify-banner {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.notify-banner-text { font-size: 13px; flex: 1; }
.notify-banner-btn {
  background: white;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 20px;
  white-space: nowrap;
}

/* === Gemini key 设置提示 === */
.api-key-hint {
  background: rgba(255,193,7,0.1);
  border: 1px solid rgba(255,193,7,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--yellow);
  margin-bottom: 12px;
  line-height: 1.6;
}