/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #000);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  /* Reserve space for fixed tab bar + device bottom safe area */
  padding-bottom: calc(64px + var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
}

main {
  /* Respect Telegram content-safe-area (native UI overlay) and device notch */
  padding-top: max(
    var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)),
    var(--tg-content-safe-area-inset-top, 0px)
  );
  padding-left:  max(var(--tg-safe-area-inset-left,  0px), var(--tg-content-safe-area-inset-left,  0px));
  padding-right: max(var(--tg-safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px));
}

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  background: var(--tg-theme-bottom-bar-bg-color, var(--tg-theme-secondary-bg-color, #f0f0f0));
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  border-top: 1px solid var(--tg-theme-section-separator-color, rgba(128,128,128,0.15));
  padding-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px 6px;
  border: none;
  background: transparent;
  color: var(--tg-theme-hint-color, #888);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab-label { margin-top: 2px; }
.tab.active {
  color: var(--tg-theme-accent-text-color, var(--tg-theme-button-color, #2678b6));
}

/* ── Tab content ── */
.tab-content { display: none; padding: 12px; animation: fadeIn 0.15s ease; }
.tab-content.active { display: block; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Date navigation ── */
.date-nav {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin-bottom: 10px;
}
.date-nav-btn {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #f5f5f5));
  color: var(--tg-theme-text-color, #000);
  font-size: 18px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s;
}
.date-nav-btn:disabled { opacity: 0.25; cursor: default; }
.date-nav-btn:active:not(:disabled) { opacity: 0.6; }
.date-nav-label {
  font-size: 15px; font-weight: 600;
  color: var(--tg-theme-text-color, #000);
  min-width: 120px; text-align: center;
}

/* ── Cards ── */
.card {
  background: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #f5f5f5));
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
}

/* ── AI card ── */
.ai-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-left: 3px solid var(--tg-theme-accent-text-color, var(--tg-theme-button-color, #2678b6));
}
.ai-icon { font-size: 20px; flex-shrink: 0; }
.ai-body { flex: 1; min-width: 0; }
.ai-text {
  line-height: 1.4;
  color: var(--tg-theme-text-color, #000);
  margin: 0;
}

/* ── Typography ── */
.big-number {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--tg-theme-text-color, #000);
}
.big-number.accent { color: var(--tg-theme-accent-text-color, var(--tg-theme-button-color, #2678b6)); }
.label {
  font-size: 11px;
  color: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #888));
  margin-top: 2px;
}
.section-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--tg-theme-section-header-text-color, var(--tg-theme-hint-color, #888));
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Calories row ── */
.calories-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  text-align: center;
}
.calories-divider { text-align: center; }
.calories-remaining-label { font-size: 11px; color: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #888)); }

/* ── Progress bar ── */
.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--tg-theme-section-separator-color, rgba(128,128,128,0.15));
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--tg-theme-button-color, #2678b6);
  transition: width 0.6s ease, background-color 0.3s ease;
  max-width: 100%;
}
.progress-fill.over { background: #e74c3c; }

/* ── Macro rings ── */
.macro-rings { display: flex; justify-content: space-around; }
.macro-ring-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ring { width: 72px; height: 72px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--tg-theme-section-separator-color, rgba(128,128,128,0.15)); stroke-width: 6; }
.ring-fill { fill: none; stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset 0.8s ease-out; }
.ring-fill.protein { stroke: #5b8af5; }
.ring-fill.fat     { stroke: #f5a623; }
.ring-fill.carbs   { stroke: #4cc47c; }
.ring-center {
  position: absolute;
  display: flex;
  align-items: baseline;
  gap: 1px;
}
.macro-ring-item { position: relative; }
.ring-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(0deg);
  pointer-events: none;
}
/* compensate for the -90deg rotation on the svg */
.ring-val { font-size: 11px; font-weight: 700; white-space: nowrap; }
.ring-label { font-size: 11px; color: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #888)); }

/* ── Water ── */
.water-glasses { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.glass-icon { font-size: 22px; cursor: default; }
.glass-icon.empty { opacity: 0.25; }
.water-row { display: flex; justify-content: space-between; align-items: center; }
.water-count-label { font-size: 13px; color: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #888)); }
.btn-small {
  background: var(--tg-theme-button-color, #2678b6);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-small:active { opacity: 0.8; }

/* ── Streak card ── */
.streak-card { display: flex; align-items: center; gap: 10px; }
.streak-fire { font-size: 28px; }

/* ── Meal list ── */
.meal-list { display: flex; flex-direction: column; gap: 8px; }
.meal-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--tg-theme-section-separator-color, rgba(128,128,128,0.1));
}
.meal-item:last-child { border-bottom: none; }
.meal-desc { font-size: 13px; flex: 1; padding-right: 8px; }
.meal-cal { font-size: 13px; font-weight: 600; white-space: nowrap; }
.meal-time { font-size: 11px; color: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #888)); }
.meal-item { cursor: pointer; }
.meal-macros {
  display: flex; gap: 12px; padding-top: 6px;
  font-size: 11px; color: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #888));
  overflow: hidden; max-height: 0; transition: max-height 0.25s ease, padding-top 0.25s ease;
  padding-top: 0;
}
.meal-item.expanded .meal-macros { max-height: 40px; padding-top: 6px; }
.meal-macro-tag { white-space: nowrap; }
.meal-macro-tag b { color: var(--tg-theme-text-color, #000); font-weight: 600; }

/* ── Charts ── */
.chart-container { height: 180px; margin-top: 8px; }
.calories-chart-container { height: 150px; }

/* ── Trends stats ── */
.trends-stats { display: flex; justify-content: space-around; text-align: center; }
.stat-item {}

/* ── Badges ── */
.badges-summary { text-align: center; }
.badge-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 2px;
}
.badge-item {
  background: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #f5f5f5));
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s;
}
.badge-item.locked { opacity: 0.35; filter: grayscale(1); }
.badge-item.unlocked { animation: badgePop 0.4s ease; }
.badge-icon { font-size: 30px; display: block; margin-bottom: 4px; }
.badge-name { font-size: 11px; font-weight: 600; line-height: 1.2; }

@keyframes badgePop {
  0%   { transform: scale(0.8); }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ── Profile ── */
.profile-header { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 20px; }
.profile-avatar { font-size: 48px; }
.profile-name { font-size: 18px; font-weight: 700; }
.tier-badge {
  background: var(--tg-theme-button-color, #2678b6);
  color: var(--tg-theme-button-text-color, #fff);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.profile-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--tg-theme-section-separator-color, rgba(128,128,128,0.1));
}
.profile-row:last-child { border-bottom: none; }
.weight-progress { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.weight-bar-wrap { flex: 1; }
.weight-current-row { font-size: 13px; color: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #888)); text-align: center; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(74px + var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Skeleton shimmer ── */
.skeleton { color: transparent !important; background: linear-gradient(90deg, rgba(128,128,128,0.1) 25%, rgba(128,128,128,0.2) 50%, rgba(128,128,128,0.1) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 4px; }
.skeleton-line { height: 14px; border-radius: 4px; margin: 6px 0; background: linear-gradient(90deg, rgba(128,128,128,0.1) 25%, rgba(128,128,128,0.2) 50%, rgba(128,128,128,0.1) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.skeleton-line:nth-child(2) { width: 70%; }

@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Export button ── */
.btn-export {
  display: block;
  width: 100%;
  background: var(--tg-theme-button-color, #2678b6);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn-export:active { opacity: 0.8; }
.btn-export:disabled { opacity: 0.5; cursor: default; }
.export-note { margin: 6px 0 0; font-size: 12px; color: var(--tg-theme-hint-color, #888); text-align: center; }
