/* ===== FitnessLifeBot MiniApp ===== */
:root {
  --bg: #0a0a0e;
  --surface: #15151c;
  --surface-2: #1f1f29;
  --surface-3: #2a2a36;
  --border: rgba(255,255,255,.06);
  --text: #f0f0f5;
  --text-2: #9a9aab;
  --text-3: #5a5a6c;
  --primary: #7c3aed;
  --primary-2: #06b6d4;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --accent: #ec4899;
  --gradient: linear-gradient(135deg, #7c3aed, #06b6d4);
  --gradient-2: linear-gradient(135deg, #ec4899, #7c3aed);
  --gradient-success: linear-gradient(135deg, #22c55e, #4ade80);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,.4);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}

button, input { font-family: inherit; color: inherit; }
input { -webkit-appearance: none; appearance: none; }

/* ===== Splash ===== */
.splash {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.splash.fade-out { animation: fadeOut .4s ease forwards; }
@keyframes fadeOut { to { opacity: 0; visibility: hidden; } }
.splash-logo { text-align: center; }
.splash-title {
  font-size: 22px; font-weight: 700; margin-top: 16px;
  background: var(--gradient);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.splash-loader {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--primary);
  margin: 24px auto 0; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== App layout ===== */
.app {
  display: flex; flex-direction: column;
  height: 100vh; max-width: 480px; margin: 0 auto;
  background: var(--bg);
  position: relative;
}
.status-safe-top { height: env(safe-area-inset-top, 12px); }

.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px 8px;
}
.header-title {
  font-size: 22px; font-weight: 700; letter-spacing: -.5px;
}
.header-title span { background: var(--gradient); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.header-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-streak {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface-2); padding: 5px 10px;
  border-radius: 99px; font-size: 13px; font-weight: 600;
}
.streak-flame { font-size: 14px; }
.header-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--gradient);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 16px;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px rgba(124,58,237,.3);
}

/* ===== Pages ===== */
.app-main {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 8px 16px 100px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.app-main::-webkit-scrollbar { display: none; }

.page { display: none; animation: pageIn .35s ease; }
.page.active { display: block; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.card-counter {
  font-size: 11px; color: var(--text-3); font-weight: 500;
  text-transform: none; letter-spacing: 0;
}

/* ===== Hero card ===== */
.hero-card { background: linear-gradient(135deg, #1a1a24, #15151c); position: relative; overflow: hidden; }
.hero-card::before {
  content: ''; position: absolute; top: -50%; right: -20%; width: 200px; height: 200px;
  background: radial-gradient(circle, rgba(124,58,237,.18), transparent 60%);
  pointer-events: none;
}
.hero-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.hero-block { flex: 1; }
.hero-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; }
.hero-value { font-size: 36px; font-weight: 700; line-height: 1.1; margin-top: 4px; }
.hero-target { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.hero-target span { color: var(--text); }
.hero-ring { position: relative; width: 80px; height: 80px; }
.hero-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.hero-ring-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

.macro-pills {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.macro-pill {
  flex: 1; display: flex; align-items: center; gap: 4px; justify-content: center;
  background: var(--surface-2); padding: 8px; border-radius: var(--radius-sm); font-size: 12px;
}
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot.protein { background: #f59e0b; }
.dot.fat { background: #ec4899; }
.dot.carbs { background: #06b6d4; }
.dot.burn { background: #22c55e; }

.balance-row {
  display: flex; align-items: center;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px;
}
.balance-item { flex: 1; text-align: center; }
.balance-divider { width: 1px; height: 30px; background: var(--surface-3); }
.balance-label { font-size: 11px; color: var(--text-3); }
.balance-val { font-size: 18px; font-weight: 700; margin-top: 2px; }
.balance-val.burn { color: var(--success); }

/* ===== Quick tiles ===== */
.quick-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; margin-bottom: 12px;
}
.quick-tile {
  background: var(--surface); border-radius: var(--radius-sm);
  padding: 12px 4px; text-align: center; cursor: pointer;
  border: 1px solid var(--border);
  transition: transform .15s, border-color .15s;
}
.quick-tile:active { transform: scale(.96); border-color: var(--primary); }
.quick-icon {
  width: 40px; height: 40px; border-radius: 12px; margin: 0 auto 6px;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.quick-label { font-size: 11px; color: var(--text-2); font-weight: 500; }

/* ===== History list ===== */
.history-list { display: flex; flex-direction: column; gap: 4px; }
.history-empty { color: var(--text-3); text-align: center; padding: 24px; font-size: 13px; }
.history-item {
  display: flex; align-items: center; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-icon-mini {
  width: 36px; height: 36px; border-radius: 10px; margin-right: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  background: var(--surface-2);
}
.history-info { flex: 1; min-width: 0; }
.history-name { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.history-val { font-size: 14px; font-weight: 700; }
.history-val.orange { color: var(--warning); }
.history-val.green { color: var(--success); }

/* ===== Week bars ===== */
.week-bars {
  display: flex; gap: 6px; height: 80px; align-items: flex-end;
  margin: 12px 0;
}
.week-bar {
  flex: 1; display: flex; flex-direction: column;
  background: var(--surface-2); border-radius: 6px; padding: 4px 2px;
  position: relative; min-height: 30px;
  justify-content: flex-end;
}
.week-bar-fill {
  background: var(--gradient); border-radius: 4px; height: 50%;
  margin-bottom: 2px; transition: height .6s ease;
}
.week-bar-fill.burn { background: var(--gradient-success); height: 30%; }
.week-bar-label { font-size: 9px; color: var(--text-3); text-align: center; }
.week-legend { display: flex; gap: 12px; justify-content: center; font-size: 11px; color: var(--text-3); }
.legend-item { display: flex; align-items: center; gap: 4px; }

/* ===== Calendar ===== */
.calendar-card { padding: 16px 12px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding: 0 4px; }
.cal-nav-btn {
  background: var(--surface-2); border: none; color: var(--text);
  width: 36px; height: 36px; border-radius: 50%; font-size: 18px;
  cursor: pointer; transition: background .2s;
  display: flex; align-items: center; justify-content: center;
}
.cal-nav-btn:active { background: var(--primary); transform: scale(.95); }
.cal-month { font-size: 18px; font-weight: 700; }
.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  font-size: 10px; color: var(--text-3); text-align: center; margin-bottom: 8px;
  text-transform: uppercase; font-weight: 600;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day {
  aspect-ratio: 1; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500; color: var(--text-2);
  cursor: pointer; transition: all .15s; position: relative;
}
.cal-day.other { color: var(--text-3); opacity: .3; }
.cal-day.today {
  background: var(--gradient); color: #fff; font-weight: 700;
  box-shadow: 0 4px 12px rgba(124,58,237,.4);
}
.cal-day.has-workout {
  background: var(--surface-2); color: var(--success);
  font-weight: 600;
}
.cal-day.has-workout::after {
  content: ''; position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--success);
}
.cal-day.has-workout.today { background: var(--gradient); }
.cal-day.has-workout.today::after { background: #fff; }
.cal-day:active { transform: scale(.92); }

.cal-summary {
  display: flex; align-items: center; justify-content: center;
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.cal-summary-item { text-align: center; padding: 0 16px; }
.cal-summary-divider { width: 1px; height: 30px; background: var(--border); }
.cal-summary-num { font-size: 20px; font-weight: 700; display: block; }
.cal-summary-label { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ===== Muscle selector ===== */
.muscle-selector {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.muscle-tile {
  background: var(--surface-2); border-radius: 12px;
  padding: 12px 4px; text-align: center; cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
}
.muscle-tile:active { transform: scale(.96); }
.muscle-tile.active {
  background: linear-gradient(135deg, rgba(124,58,237,.2), rgba(6,182,212,.2));
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(124,58,237,.25);
}
.muscle-emoji { font-size: 24px; }
.muscle-label { font-size: 11px; margin-top: 4px; color: var(--text-2); }
.muscle-tile.active .muscle-label { color: var(--text); font-weight: 600; }

/* ===== Exercise pills ===== */
.exercise-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.exercise-pill {
  background: var(--surface-2); padding: 6px 12px; border-radius: 99px;
  font-size: 12px; cursor: pointer; border: 1px solid transparent;
  transition: all .15s;
}
.exercise-pill:active { transform: scale(.96); }
.exercise-pill.active {
  background: var(--gradient); color: #fff; font-weight: 600;
}

/* ===== Set input ===== */
.set-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.set-chip {
  background: var(--surface-2); padding: 6px 12px; border-radius: 99px;
  font-size: 13px; font-weight: 500;
}
.set-chip.done { background: rgba(34,197,94,.15); color: var(--success); }
.set-input-wrap {
  display: flex; gap: 8px; align-items: center;
  background: var(--surface-2); border-radius: 12px; padding: 8px;
  margin-bottom: 12px;
}
.set-input-wrap input {
  flex: 1; background: var(--surface); border: none; padding: 10px;
  border-radius: 8px; font-size: 16px; text-align: center; min-width: 0;
}
.set-input-wrap input:focus { outline: 2px solid var(--primary); }
.set-x { color: var(--text-3); font-weight: 700; }

/* ===== Buttons ===== */
.btn {
  border: none; padding: 12px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all .15s; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px;
  color: #fff;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--gradient); box-shadow: 0 4px 12px rgba(124,58,237,.3); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-success { background: var(--gradient-success); box-shadow: 0 4px 12px rgba(34,197,94,.3); }
.btn-block { display: flex; width: 100%; margin-top: 8px; }
.btn-block + .btn-block { margin-top: 8px; }

.set-input-wrap .btn { flex: 0 0 50px; padding: 10px; }

/* ===== Programs ===== */
.program-list { display: flex; flex-direction: column; gap: 8px; }
.program-item {
  background: var(--surface-2); padding: 12px; border-radius: 12px;
  cursor: pointer; transition: all .15s;
}
.program-item:active { transform: scale(.98); }
.program-name { font-weight: 600; font-size: 14px; }
.program-desc { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ===== Food page ===== */
.photo-zone {
  background: var(--surface-2); border: 2px dashed var(--surface-3);
  border-radius: var(--radius); padding: 24px;
  text-align: center; cursor: pointer;
  transition: all .15s;
}
.photo-zone:active { transform: scale(.98); border-color: var(--primary); background: rgba(124,58,237,.05); }
.photo-zone-icon { font-size: 40px; margin-bottom: 8px; }
.photo-zone-text { font-size: 14px; color: var(--text-2); }
.or-divider {
  text-align: center; margin: 16px 0; position: relative; color: var(--text-3); font-size: 12px;
}
.or-divider::before, .or-divider::after {
  content: ''; position: absolute; top: 50%; width: 35%; height: 1px;
  background: var(--border);
}
.or-divider::before { left: 0; }
.or-divider::after { right: 0; }
.search-row {
  display: flex; gap: 8px;
}
.search-row input {
  flex: 1; background: var(--surface-2); border: none; padding: 14px;
  border-radius: 12px; font-size: 14px;
}
.search-row input:focus { outline: 2px solid var(--primary); }

.quick-foods {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px;
}
.quick-food-chip {
  background: var(--surface-2); padding: 6px 12px; border-radius: 99px;
  font-size: 12px; cursor: pointer;
}
.quick-food-chip:active { background: var(--primary); color: #fff; }

.meals-list { display: flex; flex-direction: column; }
.meal-item {
  display: flex; align-items: center; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.meal-item:last-child { border-bottom: none; }
.meal-icon { width: 40px; height: 40px; border-radius: 12px; background: rgba(245,158,11,.12); display: flex; align-items: center; justify-content: center; font-size: 20px; margin-right: 12px; }
.meal-info { flex: 1; }
.meal-name { font-size: 14px; font-weight: 500; }
.meal-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.meal-cals { font-weight: 700; font-size: 14px; color: var(--warning); }

/* ===== Stats page ===== */
.stats-hero {
  text-align: center; padding: 24px 16px;
  background: linear-gradient(135deg, #1a1a24, #15151c);
}
.stats-hero-emoji { font-size: 48px; margin-bottom: 8px; }
.stats-hero-title { font-size: 22px; font-weight: 700; }
.stats-hero-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; }

.progress-bar {
  height: 6px; background: var(--surface-2); border-radius: 99px;
  overflow: hidden; margin: 12px 0;
}
.progress-bar.large { height: 10px; }
.progress-fill {
  height: 100%; background: var(--gradient);
  border-radius: 99px; transition: width .8s ease;
}

.stats-hero-xp { font-size: 11px; color: var(--text-3); }
.stats-hero-xp span { color: var(--text); font-weight: 600; }

.month-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; text-align: center;
}
.month-stat-num { font-size: 22px; font-weight: 700; }
.month-stat-num.green { color: var(--success); }
.month-stat-num.purple { color: var(--primary); }
.month-stat-num.orange { color: var(--warning); }
.month-stat-label { font-size: 11px; color: var(--text-3); margin-top: 2px; }

.goals-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.goal-item { background: var(--surface-2); padding: 12px; border-radius: 12px; }
.goal-header { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.goal-pct { color: var(--primary); font-weight: 600; }

/* ===== Achievements ===== */
.ach-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ach-item {
  aspect-ratio: 1; border-radius: 12px;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  font-size: 24px; position: relative;
  filter: grayscale(1) opacity(.4);
  transition: all .15s;
}
.ach-item.earned { filter: none; background: linear-gradient(135deg, rgba(245,158,11,.2), rgba(239,68,68,.2)); }

/* ===== Bottom nav ===== */
.bottom-nav {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around;
  background: rgba(15,15,22,.85); backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + var(--safe-bottom));
  z-index: 50;
}
.nav-item {
  flex: 1; text-align: center; padding: 6px;
  color: var(--text-3); cursor: pointer;
  position: relative; transition: all .15s;
}
.nav-item.active { color: var(--primary); }
.nav-item.active::before {
  content: ''; position: absolute; top: -1px; left: 50%;
  transform: translateX(-50%);
  width: 24px; height: 2px; border-radius: 99px;
  background: var(--gradient);
}
.nav-icon { display: flex; justify-content: center; margin-bottom: 2px; }
.nav-icon svg { width: 22px; height: 22px; }
.nav-label { font-size: 10px; font-weight: 500; }

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 200; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } }
.modal-sheet {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(20px + var(--safe-bottom));
  max-height: 80vh; overflow-y: auto;
  animation: slideUp .3s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 -8px 32px rgba(0,0,0,.4);
}
@keyframes slideUp { from { transform: translateY(100%); } }
.modal-handle { width: 36px; height: 4px; background: var(--surface-3); border-radius: 99px; margin: 0 auto 16px; }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-body { font-size: 14px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); padding: 10px 20px; border-radius: 99px;
  font-size: 13px; font-weight: 500; z-index: 300;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-8px); }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

/* ===== Loader ===== */
.loader { display: flex; align-items: center; justify-content: center; padding: 32px; }
.loader-spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
