* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --accent: #6366f1;
  --accent2: #818cf8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --orange: #f97316;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* --- Layout --- */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(72px + var(--safe-bottom));
  min-height: 100dvh;
}

/* --- Bottom Nav --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 100;
}
.nav-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  cursor: pointer;
  transition: color 0.15s;
}
.nav-btn .icon { font-size: 22px; }
.nav-btn.active { color: var(--accent2); }

/* --- Header --- */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.back-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}

/* --- Cards --- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* --- Totals Banner --- */
.totals-banner {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  text-align: center;
}
.totals-banner .label { font-size: 13px; opacity: 0.8; }
.totals-banner .values {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 8px;
}
.totals-banner .val { font-size: 28px; font-weight: 800; }
.totals-banner .unit { font-size: 13px; opacity: 0.7; }

/* --- Progress Bars --- */
.progress-section { margin-bottom: 16px; }
.progress-row {
  margin-bottom: 10px;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}
.progress-label .name { color: var(--text2); }
.progress-label .value { font-weight: 600; }
.progress-bar {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease-out;
}
.progress-fill.cal { background: var(--accent2); }
.progress-fill.pro { background: var(--green); }
.progress-fill.over { background: var(--red); }

/* --- Streak Badge --- */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(234,179,8,0.15);
  color: var(--yellow);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  color: white;
}
.btn-primary { background: var(--accent); }
.btn-primary:active { background: var(--accent2); }
.btn-secondary { background: var(--surface2); }
.btn-secondary:active { background: var(--border); }
.btn-danger { background: var(--red); }
.btn-sm { padding: 8px 14px; font-size: 13px; width: auto; }
.btn-outline {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:active { background: var(--surface2); }
.btn-green { background: var(--green); }

/* --- Grid --- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* --- Day Type Selector --- */
.day-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
}
.day-btn:active, .day-btn.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
}
.day-btn .emoji { font-size: 32px; display: block; margin-bottom: 8px; }
.day-btn .label { font-size: 16px; font-weight: 600; }

/* --- Exercise List --- */
.exercise-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.exercise-item:active { background: var(--surface2); }
.exercise-item.logged { border-color: var(--green); }
.exercise-item.current { border-color: var(--accent); background: rgba(99,102,241,0.1); }
.exercise-name { font-weight: 600; font-size: 15px; }
.exercise-check { color: var(--green); font-size: 18px; }
.exercise-arrow { color: var(--text2); }

/* --- Input --- */
.input-group { margin-bottom: 14px; }
.input-group label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 6px;
  font-weight: 500;
}
input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 100px; font-family: inherit; }

/* --- Search --- */
.search-box { position: relative; margin-bottom: 16px; }
.search-box input { padding-left: 40px; }
.search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text2);
}

/* --- Food Results --- */
.food-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.food-item:active { background: var(--surface2); }
.food-name { font-weight: 600; font-size: 15px; }
.food-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* --- Set Input Row --- */
.set-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}
.set-label { font-weight: 700; font-size: 14px; color: var(--accent2); padding-bottom: 12px; }
.prev-val { font-size: 12px; color: var(--text2); text-align: center; margin-top: 2px; }

/* --- Food Log Entry --- */
.log-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--surface2);
}
.log-entry:last-child { border-bottom: none; }
.log-entry-name { font-weight: 500; font-size: 14px; }
.log-entry-detail { font-size: 12px; color: var(--text2); }
.log-entry-macros { text-align: right; font-size: 13px; font-weight: 600; }
.log-entry-delete {
  background: none;
  border: none;
  color: var(--red);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: 8px;
}
.log-entry-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- Meal Group Header --- */
.meal-group-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 0 4px;
  margin-top: 8px;
}
.meal-group-header:first-child { margin-top: 0; }

/* --- History --- */
.history-day { margin-bottom: 20px; }
.history-date {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--surface2);
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}
.tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--text2);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.tab.active { background: var(--accent); color: white; }

/* --- Empty State --- */
.empty { text-align: center; padding: 40px 20px; color: var(--text2); }
.empty .emoji { font-size: 40px; margin-bottom: 12px; display: block; }

/* --- Quick Add / Favorites --- */
.quick-foods {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}
.quick-food {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  min-width: 80px;
}
.quick-food:active { border-color: var(--accent); background: rgba(99,102,241,0.1); }
.quick-food.fav { border-color: var(--yellow); }
.quick-food .name { font-size: 12px; font-weight: 600; white-space: nowrap; }
.quick-food .cals { font-size: 11px; color: var(--text2); }
.fav-star { color: var(--yellow); font-size: 10px; }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--green);
  color: white;
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  z-index: 200;
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast-undo {
  background: none;
  border: 1px solid rgba(255,255,255,0.5);
  color: white;
  padding: 2px 10px;
  border-radius: 999px;
  margin-left: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

/* --- Toggle --- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.toggle-name { font-weight: 500; }
.toggle-switch {
  width: 48px;
  height: 28px;
  background: var(--surface2);
  border-radius: 14px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}
.toggle-switch.on { background: var(--green); }
.toggle-switch::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}
.toggle-switch.on::after { transform: translateX(20px); }

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 300;
  animation: fadeInOverlay 0.2s;
}
@keyframes fadeInOverlay { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-close {
  float: right;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 22px;
  cursor: pointer;
}

/* --- Chart (simple SVG) --- */
.chart-container {
  width: 100%;
  height: 160px;
  position: relative;
}
.chart-container svg { width: 100%; height: 100%; }
.chart-line { fill: none; stroke: var(--accent2); stroke-width: 2; }
.chart-dot { fill: var(--accent2); }
.chart-label { fill: var(--text2); font-size: 10px; }
.chart-grid { stroke: var(--surface2); stroke-width: 1; }
.chart-area { fill: rgba(99,102,241,0.1); }

/* --- Weight Card --- */
.weight-display {
  font-size: 36px;
  font-weight: 800;
  text-align: center;
  margin: 8px 0;
}
.weight-unit { font-size: 16px; font-weight: 400; color: var(--text2); }
.weight-change { font-size: 14px; text-align: center; }
.weight-change.up { color: var(--red); }
.weight-change.down { color: var(--green); }

/* --- Rest Timer --- */
.timer-display {
  font-size: 48px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--accent2);
}
.timer-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 4px solid var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px auto;
  position: relative;
}
.timer-circle svg {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  transform: rotate(-90deg);
}
.timer-progress { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; }

/* --- Recipe Card --- */
.recipe-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.recipe-card:active { background: var(--surface2); }
.recipe-name { font-weight: 600; font-size: 15px; }
.recipe-meta { font-size: 12px; color: var(--text2); margin-top: 4px; }
.recipe-items-list { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* --- Stat Card --- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-value { font-size: 24px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* --- NL Input --- */
.nl-input {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.nl-input input { flex: 1; }
.nl-input button { width: auto; flex-shrink: 0; }

/* --- Suggestion chip --- */
.suggestion {
  display: inline-block;
  background: var(--surface2);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  margin: 2px;
}
.suggestion:active { background: var(--accent); color: white; }

/* --- Overload suggestion --- */
.overload-tip {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--green);
  margin-bottom: 12px;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeIn 0.2s ease-out; }
