:root {
  --primary: #2e7d32;
  --primary-dark: #1b5e20;
  --accent: #ff6f3c;
  --bg: #f4f7f4;
  --card: #ffffff;
  --text: #1c231c;
  --muted: #6b7a6c;
  --danger: #d9483a;
  --border: #e3e9e3;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

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

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
}

.brand { text-align: center; margin-bottom: 24px; }
.brand-logo {
  width: 64px; height: 64px;
  margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px;
}
.brand h1 { margin: 0; font-size: 26px; }
.muted { color: var(--muted); margin: 4px 0 0; }
.small { font-size: 12px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card h2 { margin-top: 0; }

.card-click { cursor: pointer; }
.card-row { display: flex; align-items: center; justify-content: space-between; }
.chevron { color: var(--muted); font-size: 22px; }

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

input, select {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  color: var(--text);
  background: #fff;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eef2ee; color: var(--text); }
.btn-danger { background: #fdeceb; color: var(--danger); }
.btn-block { width: 100%; margin-top: 8px; }

.switch-auth { text-align: center; font-size: 13px; color: var(--muted); margin-top: 10px; }
.link-btn {
  background: none; border: none; color: var(--primary);
  font-weight: 600; cursor: pointer; padding: 0; font-size: 13px;
}

.error {
  background: #fdeceb;
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ---------- App shell ---------- */
.topbar {
  padding: 16px 20px;
  font-weight: 700;
  font-size: 18px;
  color: var(--primary-dark);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

#main-content {
  flex: 1;
  padding: 16px;
  padding-bottom: 90px;
}

.view { display: none; }
.view.active { display: block; }

.page-title { margin: 4px 0 16px; font-size: 20px; }
.page-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
}

.nav-item {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
}

.nav-item.active { color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 20px; }

/* ---------- Calendar strip ---------- */
.calendar-strip {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 14px;
}
.cal-day {
  flex: 1;
  text-align: center;
  padding: 8px 2px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.cal-day .cal-dow { display: block; font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.cal-day .cal-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
}
.cal-day.today .cal-num { border: 2px solid var(--primary); }
.cal-day.past .cal-num { background: var(--primary); color: #fff; }

/* ---------- Ring card ---------- */
.ring-card { display: flex; justify-content: center; }
.ring-wrap { position: relative; width: 140px; height: 140px; }
.ring-svg { width: 140px; height: 140px; transform: rotate(-90deg); }
.ring-bg, .ring-fg {
  fill: none;
  stroke-width: 10;
}
.ring-bg { stroke: var(--border); }
.ring-fg { stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset 0.4s ease; }
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-value { font-size: 24px; font-weight: 700; color: var(--text); }
.ring-label { font-size: 11px; color: var(--muted); }

/* ---------- Macro row ---------- */
.macro-row { display: flex; gap: 10px; margin-bottom: 14px; }
.macro-card {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 6px;
  text-align: center;
}
.macro-card .macro-icon { font-size: 18px; display: block; }
.macro-card .macro-name { font-size: 10px; color: var(--muted); display: block; margin-top: 2px; }
.macro-card .macro-value { font-size: 13px; font-weight: 700; display: block; margin-top: 2px; }
.macro-card.exceeded .macro-value { color: var(--danger); }
.macro-card.exceeded { background: #fdeceb; }

.section-title { font-size: 15px; margin: 18px 0 10px; }

/* ---------- Health score & macro grid (calorie counter result) ---------- */
.health-score { margin: 14px 0; }
.health-score-row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.health-score-bar { height: 8px; border-radius: 6px; background: var(--border); overflow: hidden; }
.health-score-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--primary)); border-radius: 6px; }

.macro-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.macro-box {
  background: #f4f7f4;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.macro-box-icon { font-size: 16px; }
.macro-box-label { font-size: 11px; color: var(--muted); }
.macro-box-value { font-size: 15px; font-weight: 700; }

/* ---------- BMI ---------- */
.current-weight { font-size: 20px; font-weight: 700; margin: 4px 0; }
.bmi-value { font-size: 26px; font-weight: 700; color: var(--primary-dark); margin: 4px 0 0; }
.bmi-bar {
  position: relative;
  height: 8px;
  border-radius: 6px;
  margin: 14px 0 4px;
  background: linear-gradient(90deg, #4fa3ff 0%, #43b581 30%, #f5c542 55%, #ff8a3d 75%, #e0483e 100%);
}
.bmi-marker {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 16px;
  background: var(--text);
  border-radius: 2px;
  transform: translateX(-50%);
}
.bmi-scale-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* ---------- Diet ---------- */
.diet-section { margin-bottom: 14px; }
.diet-section h3 { margin: 0 0 8px; font-size: 15px; }
.diet-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.diet-item:last-child { border-bottom: none; }
.diet-item .cal { color: var(--muted); font-size: 13px; }
.diet-empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

.recipe-suggest-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 12px 0 6px; }

.recipe-list { display: flex; flex-direction: column; gap: 8px; }
.recipe-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f4f7f4;
  border-radius: 12px;
  padding: 8px 10px;
}
.recipe-emoji { font-size: 22px; }
.recipe-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.recipe-name { font-size: 13px; font-weight: 600; }
.recipe-macros { margin-top: 2px; }
.btn-recipe-add {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-recipe-add:active { background: var(--primary-dark); }

.actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.actions-row .btn { flex: 1; min-width: 140px; }

/* ---------- Calorie counter ---------- */
.centered { text-align: center; }
.photo-placeholder, .photo-preview {
  width: 160px; height: 160px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: #eef2ee;
  display: flex; align-items: center; justify-content: center;
  font-size: 52px;
  overflow: hidden;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.ai-result { margin-top: 18px; text-align: left; }
.estimate-label { color: var(--muted); font-size: 13px; margin-bottom: 2px; }
.estimate-value { font-size: 26px; font-weight: 700; color: var(--primary-dark); margin-top: 0; }

/* ---------- History ---------- */
.empty-icon { font-size: 40px; margin-bottom: 4px; }
.history-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.history-item .hi-top { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; }
.history-item .hi-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- Profile ---------- */
.avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 10px;
}
.stats-row { display: flex; justify-content: space-around; margin: 14px 0; }
.stat { text-align: center; }
.stat-value { display: block; font-size: 18px; font-weight: 700; color: var(--primary-dark); }
.stat-label { font-size: 12px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 480px;
  border-radius: 18px 18px 0 0;
  padding: 22px;
  max-height: 88vh;
  overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c231c;
  color: #fff;
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13px;
  z-index: 100;
}
