*, *[hidden] { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0f4f8;
  min-height: 100vh;
}

/* --- Nav --- */
nav {
  background: white;
  border-bottom: 1px solid #e2e8f0;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a202c;
}

.nav-links {
  display: flex;
  gap: 8px;
}

.nav-btn {
  padding: 7px 14px;
  border: none;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: #e2e8f0;
  color: #4a5568;
  transition: background 0.2s, color 0.2s;
}

.nav-btn.active {
  background: #2b6cb0;
  color: white;
}

/* --- Layout --- */
.view {
  padding: 20px 16px 40px;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- Upload Area --- */
.upload-area {
  background: white;
  border: 2px dashed #cbd5e0;
  border-radius: 16px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s;
}

.upload-area:hover { border-color: #4c9f70; }

.upload-placeholder {
  text-align: center;
  color: #a0aec0;
  padding: 32px;
}

.upload-placeholder .icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
}

#preview {
  width: 100%;
  object-fit: cover;
  display: block;
  max-height: 340px;
}

/* --- Buttons --- */
.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

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

.btn-primary  { background: #4c9f70; color: white; }
.btn-secondary { background: #e2e8f0; color: #2d3748; }
.btn-analyze  { background: #2b6cb0; color: white; width: 100%; padding: 14px; font-size: 1.05rem; }
.btn-add      { background: #4c9f70; color: white; width: 100%; margin-top: 12px; }

.add-confirm {
  text-align: center;
  color: #276749;
  font-weight: 600;
  padding: 10px 0 4px;
}

/* --- Result --- */
.result {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.total-calories {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.total-calories .label {
  font-size: 0.85rem;
  color: #718096;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: 1;
}

.calories-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: #2b6cb0;
  line-height: 1;
}

.unit { font-size: 1rem; color: #718096; }

.confidence {
  font-size: 0.8rem;
  color: #a0aec0;
  margin-bottom: 16px;
}

.items-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.items-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #f7fafc;
  border-radius: 10px;
}

.item-name  { font-weight: 600; color: #2d3748; }
.item-amount { font-size: 0.8rem; color: #a0aec0; }
.item-calories { font-weight: 700; color: #2b6cb0; white-space: nowrap; }

.note {
  margin-top: 14px;
  font-size: 0.85rem;
  color: #718096;
  font-style: italic;
}

/* --- Loading / Error --- */
.loading {
  text-align: center;
  padding: 32px;
  color: #718096;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e2e8f0;
  border-top-color: #2b6cb0;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

.error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  color: #c53030;
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 0.9rem;
}

/* --- Today View --- */
.today-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 0 8px;
}

.today-header h2 {
  font-size: 1.3rem;
  color: #1a202c;
}

.today-total {
  font-size: 1.5rem;
  font-weight: 800;
  color: #2b6cb0;
}

.meal-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.meal-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: white;
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  transition: box-shadow 0.2s;
}

.meal-item:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

.meal-thumb {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

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

.meal-title {
  font-weight: 700;
  color: #1a202c;
  margin-bottom: 3px;
}

.meal-components {
  font-size: 0.82rem;
  color: #718096;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-kcal {
  font-weight: 700;
  color: #2b6cb0;
  white-space: nowrap;
}

.delete-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  opacity: 0.5;
  transition: opacity 0.2s, background 0.2s;
  flex-shrink: 0;
}

.delete-btn:hover {
  opacity: 1;
  background: #fff5f5;
}

.empty-hint {
  text-align: center;
  color: #a0aec0;
  padding: 40px 0;
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.modal-box {
  position: relative;
  background: white;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: #e2e8f0;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box img {
  width: 100%;
  border-radius: 12px;
  object-fit: cover;
  max-height: 220px;
  margin-bottom: 16px;
}

.modal-calories {
  font-size: 1.4rem;
  font-weight: 800;
  color: #2b6cb0;
  margin-bottom: 14px;
}
