:root {
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2f9e63;
  --accent-dark: #227a4c;
  --danger: #d94f4f;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1e2126;
    --text: #eceef0;
    --muted: #9aa1ab;
    --border: #2c3036;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.app-header h1 {
  font-size: 1.4rem;
  margin: 0;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.nav-link {
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.nav-link:hover {
  text-decoration: underline;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-nav button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.date-nav input[type="date"] {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.summary-card {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
}

.summary-item {
  display: flex;
  flex-direction: column;
  position: relative;
}

.summary-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.summary-item.highlight .summary-value {
  color: var(--accent);
}

.edit-goal {
  position: absolute;
  right: 0;
  top: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  text-transform: none;
}

section {
  margin-bottom: 28px;
}

.meal-group {
  margin-bottom: 14px;
}

.meal-group-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
}

.entry-row .entry-name {
  font-weight: 500;
}

.entry-row .entry-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.entry-row .entry-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.entry-row .remove-btn {
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px 0;
}

.entry-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.entry-form input,
.entry-form select {
  flex: 1 1 100px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.95rem;
  min-width: 0;
}

.food-search {
  position: relative;
  flex: 1 1 100px;
}

.food-search input {
  width: 100%;
}

.suggestions-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: 280px;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  display: none;
}

.suggestions-dropdown.open {
  display: block;
}

.suggestion-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.9rem;
}

.suggestion-item:hover,
.suggestion-item.active {
  background: var(--bg);
}

.suggestion-item .suggestion-kcal {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.entry-form button {
  flex: 1 1 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.entry-form button:hover {
  background: var(--accent-dark);
}

.field-hint {
  flex: 1 1 100%;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: -2px;
}

#analyzePhoto {
  flex: 1 1 auto;
}

.entry-form .secondary-btn {
  flex: 0 0 auto;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-weight: normal;
}

.entry-form .secondary-btn:hover {
  background: var(--bg);
}

#photoResults {
  margin-top: 10px;
}

#photoResults select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  margin-bottom: 8px;
}

.photo-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
}

.photo-item-row .photo-item-name {
  flex: 1 1 auto;
  min-width: 0;
}

.photo-item-row .photo-item-grams,
.photo-item-row .photo-item-kcal {
  width: 64px;
}

.photo-item-row input {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

#photoResults > button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
