* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: #f5f7fa;
  color: #1f2937;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.date-display {
  font-size: 13px;
  opacity: 0.95;
}

.tab-bar {
  display: flex;
  background: white;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 56px;
  z-index: 99;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab {
  flex: 1;
  min-width: 70px;
  border: none;
  background: transparent;
  padding: 12px 8px;
  font-size: 13px;
  color: #6b7280;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab.active {
  color: #10b981;
  border-bottom-color: #10b981;
  font-weight: 600;
}

.content {
  flex: 1;
  padding: 16px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

h3 {
  margin: 20px 0 10px;
  font-size: 15px;
  color: #374151;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hint {
  font-size: 12px;
  color: #9ca3af;
  font-weight: normal;
}

.cal-summary {
  font-size: 14px;
  color: #10b981;
  font-weight: 600;
}

.meal-selector {
  display: flex;
  gap: 8px;
  background: white;
  padding: 8px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.meal-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 4px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: #6b7280;
  transition: all 0.2s;
}

.meal-btn.active {
  background: #10b981;
  color: white;
  font-weight: 600;
}

.food-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}

.food-card {
  background: white;
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid #f0f0f0;
  position: relative;
}

.food-card:active {
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

.food-card .name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
  color: #1f2937;
}

.food-card .cal {
  font-size: 12px;
  color: #10b981;
}

.food-card .freq-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #fef3c7;
  color: #92400e;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 6px;
}

.search-add input,
.custom-add input,
.custom-add select,
.settings-group input,
.settings-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  background: white;
  color: #1f2937;
  -webkit-appearance: none;
}

.search-add input:focus,
.custom-add input:focus,
.custom-add select:focus,
.settings-group input:focus,
.settings-group select:focus {
  outline: none;
  border-color: #10b981;
}

.search-results {
  margin-top: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.search-results .food-item {
  padding: 10px 12px;
  background: white;
  border-radius: 8px;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.search-results .food-item:active {
  background: #f0fdf4;
}

.search-results .food-item .info {
  display: flex;
  flex-direction: column;
}

.search-results .food-item .name {
  font-weight: 500;
}

.search-results .food-item .meta {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}

.search-results .food-item .cal {
  color: #10b981;
  font-weight: 600;
}

.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.form-row label {
  min-width: 60px;
  font-size: 14px;
  color: #6b7280;
}

.form-row input,
.form-row select {
  flex: 1;
}

.primary-btn {
  background: #10b981;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.primary-btn:active {
  background: #059669;
}

.primary-btn.full-width {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
}

.secondary-btn {
  background: white;
  color: #10b981;
  border: 1px solid #10b981;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  margin-bottom: 8px;
}

.danger-btn {
  background: white;
  color: #ef4444;
  border: 1px solid #ef4444;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}

.today-records {
  margin-top: 24px;
}

.record-group {
  background: white;
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}

.record-group-header {
  padding: 10px 14px;
  background: #f9fafb;
  font-weight: 600;
  font-size: 13px;
  color: #374151;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  justify-content: space-between;
}

.record-item {
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f3f4f6;
}

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

.record-item .info {
  flex: 1;
}

.record-item .name {
  font-weight: 500;
}

.record-item .meta {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}

.record-item .right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.record-item .cal {
  color: #10b981;
  font-weight: 600;
  font-size: 14px;
}

.record-item .delete {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
}

.empty-state {
  text-align: center;
  color: #9ca3af;
  padding: 40px 20px;
  font-size: 14px;
}

.period-selector {
  display: flex;
  gap: 8px;
  background: white;
  padding: 6px;
  border-radius: 10px;
  margin-bottom: 16px;
}

.period-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  color: #6b7280;
}

.period-btn.active {
  background: #10b981;
  color: white;
  font-weight: 600;
}

.history-day {
  background: white;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}

.history-day .day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 600;
}

.history-day .day-cal {
  color: #10b981;
}

.history-day .day-meals {
  font-size: 13px;
  color: #6b7280;
}

.nutrient-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0;
  background: #f3f4f6;
}

.nutrient-bar .protein { background: #f59e0b; }
.nutrient-bar .carbs { background: #3b82f6; }
.nutrient-bar .fat { background: #ec4899; }

.nutrient-legend {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
}
.nutrient-legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

.health-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.health-card h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #374151;
}

.score-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px auto;
  background: conic-gradient(#10b981 var(--p, 0%), #e5e7eb 0%);
  position: relative;
}

.score-circle::before {
  content: '';
  position: absolute;
  inset: 8px;
  background: white;
  border-radius: 50%;
}

.score-circle .score {
  position: relative;
  font-size: 28px;
  font-weight: 700;
  color: #10b981;
}

.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  margin: 2px 4px 2px 0;
}
.tag.good { background: #d1fae5; color: #065f46; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.bad { background: #fee2e2; color: #991b1b; }

.recommend-item {
  background: white;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}

.recommend-item .reason {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 8px;
}

.recommend-item .dishes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.recommend-item .dish-chip {
  background: #f0fdf4;
  color: #065f46;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid #bbf7d0;
}

.recommend-item .dish-chip:active {
  background: #bbf7d0;
}

.search-app-buttons {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.search-app-buttons button {
  flex: 1;
  padding: 8px;
  border: 1px solid #e5e7eb;
  background: white;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  color: #374151;
}

.settings-group {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.profile-result {
  margin-top: 12px;
  padding: 12px;
  background: #f0fdf4;
  border-radius: 8px;
  font-size: 13px;
  color: #065f46;
  display: none;
}

.profile-result.show {
  display: block;
}

.about-text {
  font-size: 13px;
  color: #6b7280;
  line-height: 1.6;
  margin: 0;
}

.hint-text {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.5;
  background: #f9fafb;
  padding: 8px 10px;
  border-radius: 6px;
  margin: 4px 0 12px;
}

.search-input-row {
  display: flex;
  gap: 6px;
}
.search-input-row input { flex: 1; }

.online-btn {
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s;
}
.online-btn:active {
  background: #f0fdf4;
  border-color: #10b981;
}
.online-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

.online-results {
  margin-top: 10px;
}

.online-results .source-label {
  font-size: 11px;
  color: #9ca3af;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.online-results .source-label .badge {
  background: #ddd6fe;
  color: #5b21b6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
}
.online-results .source-label .badge.ai { background: #fef3c7; color: #92400e; }
.online-results .source-label .badge.off { background: #d1fae5; color: #065f46; }

.online-loading {
  text-align: center;
  padding: 16px;
  color: #6b7280;
  font-size: 13px;
}
.online-error {
  padding: 10px;
  background: #fef2f2;
  color: #991b1b;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 8px;
}

.error-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.error-actions button {
  flex: 1;
  margin: 0;
}

/* 拍照识别 */
.photo-add { margin-top: 8px; }
.photo-buttons {
  display: flex;
  gap: 8px;
}
.photo-btn {
  flex: 1;
  padding: 16px;
  background: linear-gradient(135deg, #ddd6fe, #c7d2fe);
  border: 1px solid #a5b4fc;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: #4338ca;
  cursor: pointer;
  transition: transform 0.15s;
}
.photo-btn:active {
  transform: scale(0.97);
}
.photo-preview {
  margin-top: 12px;
  position: relative;
}
.photo-preview img {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 12px;
  background: #f3f4f6;
  display: block;
}
.photo-preview .remove-photo {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-recognizing {
  text-align: center;
  padding: 16px;
  color: #4338ca;
  font-size: 14px;
  background: #eef2ff;
  border-radius: 8px;
  margin-top: 8px;
}
.vision-summary {
  background: #fef3c7;
  color: #92400e;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 12px;
  margin-bottom: 8px;
}
.vision-item {
  background: white;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  border: 1px solid #e5e7eb;
}
.vision-item .vi-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.vision-item .vi-name {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  font-weight: 500;
}
.vision-item .vi-cal {
  width: 80px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  text-align: right;
  color: #10b981;
  font-weight: 600;
}
.vision-item .vi-meta {
  display: flex;
  gap: 6px;
  font-size: 12px;
  color: #6b7280;
}
.vision-item .vi-meta input {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
}
.vision-item .vi-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.vision-item .vi-confidence {
  font-size: 11px;
  color: #6b7280;
  flex: 1;
  display: flex;
  align-items: center;
}
.vision-add-btn {
  background: #10b981;
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.vision-skip-btn {
  background: white;
  color: #6b7280;
  border: 1px solid #d1d5db;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.vision-actions-bar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.vision-actions-bar button {
  flex: 1;
}

.key-input-wrap {
  flex: 1;
  display: flex;
  gap: 6px;
}
.key-input-wrap input { flex: 1; }
.key-toggle-btn {
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 0 12px;
  cursor: pointer;
  font-size: 16px;
}
.key-toggle-btn:active {
  background: #f0fdf4;
}

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1f2937;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 768px) {
  .app-header { padding: 20px 32px; }
  .content { padding: 24px; }
  .tab { font-size: 14px; }
}
