:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #6b7280;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --border: #e5e7eb;
  --kcal: #f97316;
  --protein: #3b82f6;
  --fat: #eab308;
  --carbs: #a855f7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card-bg: #1a1d23;
    --text: #f2f2f2;
    --text-secondary: #9ca3af;
    --border: #2a2d34;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 2rem;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 1rem 0 1rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0.75rem 0 0.5rem 0;
}

.lang-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 0.25rem;
}

.tab-btn {
  flex: 1;
  padding: 0.6rem 0.5rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0.75rem 0 0.3rem 0;
}
label:first-child { margin-top: 0; }

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.goal-progress-row {
  margin-bottom: 0.75rem;
}

.goal-progress-row .goal-row-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.goal-progress-row .goal-row-top .goal-label {
  color: var(--text-secondary);
}

.goal-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
}

.goal-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.2s ease;
}

.goal-bar-fill.kcal { background: var(--kcal); }
.goal-bar-fill.protein { background: var(--protein); }
.goal-bar-fill.fat { background: var(--fat); }
.goal-bar-fill.carbs { background: var(--carbs); }

.primary-btn, .secondary-btn {
  width: 100%;
  padding: 0.75rem;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.85rem;
  cursor: pointer;
}

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

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

.secondary-btn.small {
  width: auto;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.result-card h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
}

.kbju-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
}

.kbju-item {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.25rem;
  border-radius: 10px;
  background: var(--bg);
}

.kbju-item .val {
  font-size: 1.1rem;
  font-weight: 700;
}

.kbju-item .lbl {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.kbju-item.kcal .val { color: var(--kcal); }
.kbju-item.protein .val { color: var(--protein); }
.kbju-item.fat .val { color: var(--fat); }
.kbju-item.carbs .val { color: var(--carbs); }

.ingredient-row {
  display: grid;
  grid-template-columns: 1fr 80px 32px;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.ingredient-row input[list] { width: 100%; }

.remove-row-btn {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0;
}

.list {
  margin-top: 0.5rem;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }

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

.list-item .meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.list-item-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  color: var(--primary);
  cursor: pointer;
  white-space: nowrap;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--card-bg);
  width: 100%;
  max-height: 80vh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1rem 0 1rem;
  flex-shrink: 0;
}

.modal-body {
  padding: 1rem;
  overflow-y: auto;
}

.modal-header h3 { margin: 0; }

.icon-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}

.empty-msg {
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 0.5rem 0;
}
