/* ===== 食记 (Food Snap) — 样式 ===== */

:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-light: #d1fae5;
  --blue: #3b82f6;
  --blue-light: #dbeafe;
  --amber: #f59e0b;
  --amber-light: #fef3c7;
  --purple: #8b5cf6;
  --purple-light: #ede9fe;
  --red: #ef4444;
  --red-light: #fee2e2;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xl: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--gray-800);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }

/* ===== Layout ===== */
.app-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.page-content::-webkit-scrollbar { width: 0; }

/* ===== Bottom Tab Bar ===== */
.tab-bar {
  display: flex;
  background: white;
  border-top: 1px solid var(--gray-200);
  padding: 6px 0 calc(6px + var(--safe-bottom));
  flex-shrink: 0;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  font-size: 11px;
  color: var(--gray-400);
  transition: color 0.2s;
}

.tab-item.active { color: var(--primary); }
.tab-item .tab-icon { font-size: 22px; line-height: 1; }

/* ===== Cards ===== */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.card-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
}

/* ===== Calorie Ring ===== */
.calorie-ring-wrap {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto;
}

.calorie-ring-wrap svg { transform: rotate(-90deg); }
.calorie-ring-bg { fill: none; stroke: var(--gray-200); stroke-width: 8; }
.calorie-ring-fill { fill: none; stroke: var(--primary); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 0.6s ease; }
.calorie-ring-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.calorie-number {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.calorie-label {
  font-size: 12px;
  color: var(--gray-500);
}

/* ===== Macro Cards ===== */
.macro-row {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.macro-item {
  flex: 1;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}

.macro-item .macro-value {
  font-size: 18px;
  font-weight: 600;
}

.macro-item .macro-unit {
  font-size: 11px;
  color: var(--gray-500);
}

.macro-item .macro-label {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 2px;
}

.macro-protein .macro-value { color: var(--blue); }
.macro-fat .macro-value { color: var(--amber); }
.macro-carbs .macro-value { color: var(--primary); }

/* ===== Button ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-primary:active { transform: scale(0.97); background: var(--primary-dark); }

.btn-large {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  border-radius: var(--radius-xl);
}

.btn-outline {
  border: 1.5px solid var(--gray-200);
  background: white;
  color: var(--gray-600);
}

.btn-outline:active { background: var(--gray-50); }

/* ===== FAB (Floating Action Button) ===== */
.fab {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 64px;
  border-radius: 32px;
  background: var(--primary);
  color: white;
  font-size: 28px;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  z-index: 10;
}

.fab:active { transform: translateX(-50%) scale(0.92); }

/* ===== Camera ===== */
.camera-view {
  position: fixed;
  inset: 0;
  background: black;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.camera-video {
  flex: 1;
  object-fit: cover;
  width: 100%;
}

.camera-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
}

.camera-btn {
  width: 72px; height: 72px;
  border-radius: 36px;
  border: 4px solid white;
  background: rgba(255,255,255,0.3);
  transition: transform 0.15s;
}

.camera-btn:active { transform: scale(0.92); }

.camera-close {
  position: absolute;
  top: 16px; left: 16px;
  width: 40px; height: 40px;
  border-radius: 20px;
  background: rgba(0,0,0,0.4);
  color: white;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-gallery-btn {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: rgba(255,255,255,0.2);
  color: white;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Upload area (when camera not available) ===== */
.upload-area {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-xl);
  padding: 40px 20px;
  text-align: center;
  background: white;
  transition: border-color 0.2s;
}

.upload-area:active { border-color: var(--primary); }
.upload-area .upload-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== Image Preview ===== */
.image-preview {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

/* ===== Result ===== */
.result-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.result-thumb {
  width: 80px; height: 80px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

.result-dish-name {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 2px;
}

.result-dish-edit {
  font-size: 13px;
  color: var(--primary);
  cursor: pointer;
}

.result-confidence {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.calorie-big {
  font-size: 48px;
  font-weight: 700;
  color: var(--amber);
  text-align: center;
}

.calorie-big-label {
  text-align: center;
  font-size: 13px;
  color: var(--gray-500);
  margin-bottom: 12px;
}

/* ===== Ingredient list ===== */
.ingredient-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}

.ingredient-item:last-child { border-bottom: none; }
.ingredient-name { flex: 1; font-size: 14px; }
.ingredient-weight { font-size: 13px; color: var(--gray-500); margin-right: 12px; }
.ingredient-cal { font-size: 14px; font-weight: 600; color: var(--gray-700); }

/* ===== Portion adjust ===== */
.portion-row {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.portion-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  border: 1.5px solid var(--gray-200);
  background: white;
  transition: all 0.15s;
}

.portion-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

.portion-custom {
  flex: 0 0 auto;
  padding: 10px 16px;
  border: 1.5px dashed var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--gray-500);
}

/* ===== History ===== */
.history-day {
  margin-bottom: 12px;
}

.history-date {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-date-total {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-800);
}

.history-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
  gap: 10px;
}

.history-item:last-child { border-bottom: none; }

.history-item-icon { font-size: 20px; width: 28px; text-align: center; }
.history-item-info { flex: 1; }
.history-item-name { font-size: 14px; font-weight: 500; }
.history-item-time { font-size: 12px; color: var(--gray-400); }
.history-item-cal { font-size: 15px; font-weight: 600; color: var(--amber); }
.history-item-del { font-size: 16px; color: var(--gray-400); padding: 4px; }

/* ===== Tabs ===== */
.tab-row {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.tab-chip {
  padding: 6px 16px;
  border-radius: 16px;
  font-size: 13px;
  background: var(--gray-100);
  color: var(--gray-500);
  transition: all 0.2s;
}

.tab-chip.active {
  background: var(--primary);
  color: white;
}

/* ===== Form elements ===== */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--gray-600); margin-bottom: 4px; display: block; }
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: white;
  transition: border-color 0.2s;
}

.form-input:focus { outline: none; border-color: var(--primary); }
.form-select { appearance: none; background: white; }

.goal-picker {
  display: flex;
  gap: 8px;
}

.goal-option {
  flex: 1;
  padding: 14px 8px;
  border-radius: var(--radius);
  border: 1.5px solid var(--gray-200);
  text-align: center;
  transition: all 0.15s;
  font-size: 14px;
}

.goal-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

.goal-option .goal-icon { font-size: 24px; display: block; margin-bottom: 4px; }

/* ===== Loading ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: var(--gray-500); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-800);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show { opacity: 1; }

/* ===== Food search ===== */
.food-search-results {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  margin-top: 4px;
}

.food-search-item {
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
}

.food-search-item:active { background: var(--gray-50); }
.food-search-item:last-child { border-bottom: none; }
.food-search-item .fsi-cal { font-size: 12px; color: var(--gray-500); }

/* ===== Meal type picker ===== */
.meal-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.meal-picker .meal-btn {
  padding: 6px 14px;
  border-radius: 14px;
  font-size: 13px;
  background: var(--gray-100);
  transition: all 0.15s;
}

.meal-picker .meal-btn.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
}

/* ===== Settings page ===== */
.settings-section {
  margin-bottom: 20px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
}

.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: 14px; }
.settings-row-value { font-size: 14px; color: var(--gray-500); }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .empty-text { font-size: 14px; }

/* ===== Macros result bar ===== */
.macro-bar-row {
  display: flex;
  gap: 0;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}

.macro-bar-protein { background: var(--blue); }
.macro-bar-fat { background: var(--amber); }
.macro-bar-carbs { background: var(--primary); }

/* ===== Macros detail ===== */
.macro-detail {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.macro-detail-item {
  flex: 1;
  text-align: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.macro-detail-item .md-value { font-size: 16px; font-weight: 600; display: block; }
.macro-detail-item .md-label { color: var(--gray-400); margin-top: 2px; display: block; }
.macro-detail-item.md-protein { background: var(--blue-light); }
.macro-detail-item.md-fat { background: var(--amber-light); }
.macro-detail-item.md-carbs { background: var(--primary-light); }

/* ===== Text input for dish name modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: white;
  border-radius: var(--radius-xl);
  padding: 20px;
  width: 100%;
  max-width: 360px;
}

.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.modal-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 16px;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ===== Scrollable chip row ===== */
.chip-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.chip-scroll::-webkit-scrollbar { height: 0; }

/* ===== Textarea for text description ===== */
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 15px;
  resize: none;
  min-height: 44px;
  font-family: inherit;
  background: white;
}

.form-textarea:focus { outline: none; border-color: var(--primary); }

/* ===== Nutrients target ===== */
.target-info {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.target-card {
  text-align: center;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--gray-50);
}

.target-card .tc-value { font-size: 16px; font-weight: 600; }
.target-card .tc-label { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

/* ===== Slider ===== */
input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--gray-200);
  border-radius: 2px;
  outline: none;
  margin: 8px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ===== Responsive ===== */
@media (min-width: 480px) {
  .app-container { border-left: 1px solid var(--gray-200); border-right: 1px solid var(--gray-200); }
}
