/* === Design Tokens === */
:root {
  --color-primary: #4a9c5e;
  --color-primary-light: #e8f5e9;
  --color-bg: #f5f5f5;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-secondary: #666666;
  --color-border: #e0e0e0;
  --color-error: #dc2626;
  --color-success: #16a34a;
  --radius: 12px;
  --radius-sm: 8px;
  --spacing: 12px;
  --nav-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #121212;
    --color-surface: #1e1e1e;
    --color-text: #e0e0e0;
    --color-text-secondary: #999999;
    --color-border: #333333;
    --color-primary-light: #1a3a1f;
  }
}

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

html {
  font-family: var(--font);
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  overscroll-behavior: none;
}

a { color: var(--color-primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* === Bottom Nav === */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 16px;
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 10px;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-item.active { color: var(--color-primary); }
.nav-icon { font-size: 20px; line-height: 1; }
.nav-label { font-weight: 500; }

/* === Content === */
#content {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--spacing);
}

/* === Cards === */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* === Nutrient Bars === */
.nutrient-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.nutrient-row:last-child { margin-bottom: 0; }

.nutrient-label {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 70px;
  font-size: 12px;
  font-weight: 500;
}

.nutrient-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nutrient-bar-track {
  flex: 1;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}

.nutrient-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.nutrient-bar-fill.over {
  animation: pulse 1s ease infinite alternate;
}

@keyframes pulse {
  to { opacity: 0.7; }
}

.nutrient-value {
  min-width: 80px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.nutrient-unit {
  font-weight: 400;
  color: var(--color-text-secondary);
  font-size: 10px;
}

/* === Meal Cards === */
.meal-card-main {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

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

.meal-thumb-placeholder {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.meal-info { flex: 1; min-width: 0; }

.meal-desc {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.meal-time {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.meal-macros {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.macro {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--color-bg);
}

.macro.cal { color: #f59e0b; }
.macro.pro { color: #3b82f6; }
.macro.fat { color: #ef4444; }
.macro.carb { color: #eab308; }

/* === Meal Detail (expanded) === */
.meal-detail {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--color-border);
}

.meal-detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 4px 0;
}

.meal-detail-row .detail-label {
  color: var(--color-text-secondary);
}

.meal-detail-row .detail-value {
  font-weight: 600;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: transparent;
  color: var(--color-error);
  border: 1px solid var(--color-error);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  min-height: 32px;
}

.btn-block { width: 100%; }

.btn-group {
  display: flex;
  gap: 8px;
}

.btn-group .btn { flex: 1; }

/* === Date Header === */
.date-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: var(--spacing);
  padding: 4px 0;
}

.date-header .date-label {
  font-size: 17px;
  font-weight: 700;
  min-width: 140px;
  text-align: center;
}

.date-header .btn-nav {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* === Capture View === */
.capture-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  padding: 20px 0;
}

.capture-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 4px solid var(--color-primary-light);
  color: white;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
}

.capture-btn:active { transform: scale(0.9); }

.photo-preview {
  width: 100%;
  max-height: 280px;
  border-radius: var(--radius);
  object-fit: contain;
  background: var(--color-bg);
}

.capture-inputs {
  display: none;
}

/* === Analysis Results === */
.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}

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

.result-label { font-size: 14px; font-weight: 500; }

.result-input {
  width: 72px;
  text-align: right;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.result-unit {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-left: 4px;
}

.confidence-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.confidence-high { background: #dcfce7; color: #16a34a; }
.confidence-medium { background: #fef3c7; color: #d97706; }
.confidence-low { background: #fee2e2; color: #dc2626; }

@media (prefers-color-scheme: dark) {
  .confidence-high { background: #14532d; }
  .confidence-medium { background: #451a03; }
  .confidence-low { background: #450a0a; }
}

/* === Trends === */
.chip {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}

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

.chart-container {
  position: relative;
  height: 220px;
  margin-bottom: var(--spacing);
}

.trend-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.stat-card {
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 10px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* === Settings === */
.setting-group {
  margin-bottom: 0;
}

.setting-group h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.setting-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-top: 10px;
}

.setting-label:first-of-type {
  margin-top: 0;
}

.setting-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-size: 14px;
  margin-top: 4px;
}

.setting-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(74, 156, 94, 0.2);
}

select.setting-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.goal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.goal-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.goal-item label {
  font-size: 12px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.goal-item input {
  padding: 7px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}

.setting-hint {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
  line-height: 1.4;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--color-text-secondary);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.5;
}

/* === Toast === */
.toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  transition: transform 0.3s ease;
  max-width: 90vw;
  text-align: center;
}

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

.toast-info { background: var(--color-primary); color: white; }
.toast-error { background: var(--color-error); color: white; }
.toast-success { background: var(--color-success); color: white; }

/* === Loading === */
.loading-spinner {
  display: flex;
  justify-content: center;
  padding: 32px;
}

.loading-spinner::after {
  content: '';
  width: 28px;
  height: 28px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === FAB === */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  right: 16px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  border: none;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(74, 156, 94, 0.4);
  cursor: pointer;
  z-index: 50;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s;
}

.fab:active { transform: scale(0.9); }

/* === Manual Entry === */
.manual-input-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  width: 100%;
}

.manual-input-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-size: 14px;
  min-width: 0;
}

/* === Misc === */
.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
  font-weight: 600;
}

.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 12px; }
.mb-1 { margin-bottom: 6px; }
.mb-2 { margin-bottom: 12px; }

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

.chip-scroll::-webkit-scrollbar { display: none; }

/* === Notes === */
.notes-text {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-style: italic;
  line-height: 1.4;
}

/* === Items list in results === */
.food-items-list {
  list-style: none;
  margin-bottom: 10px;
}

.food-items-list li {
  padding: 5px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
}

.food-items-list li:last-child { border-bottom: none; }

.portion-text {
  color: var(--color-text-secondary);
  font-size: 12px;
}

/* === Page title === */
.page-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
}
