/* ─── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --bg:      var(--tg-theme-bg-color,            #111113);
  --bg2:     var(--tg-theme-secondary-bg-color,  #1C1C1F);
  --text:    var(--tg-theme-text-color,           #F2F2F7);
  --hint:    var(--tg-theme-hint-color,           rgba(235,235,245,.6));
  --accent:  var(--tg-theme-button-color,         #2AABEE);
  --acc-txt: var(--tg-theme-button-text-color,    #FFFFFF);

  --cal:  #FF6B6B;
  --prot: #4DD0C4;
  --fat:  #FFD166;
  --carb: #6BCB77;

  --r:    18px;
  --r-sm: 12px;
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app { min-height: 100vh; }

/* ─── Screens ───────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ─── Header ────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 8px;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.3px;
}

.header-date {
  font-size: 13px;
  color: var(--hint);
  margin-top: 1px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  line-height: 1;
}

/* ─── Content ───────────────────────────────────────────────────────────── */
.content {
  padding: 4px 16px 96px;
}

/* ─── Calorie ring ──────────────────────────────────────────────────────── */
.calorie-section {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0 18px;
}

.calorie-ring-wrap {
  position: relative;
  width: 148px;
  height: 148px;
  flex-shrink: 0;
}

.ring-bg {
  fill: none;
  stroke: rgba(255,255,255,.08);
  stroke-width: 13;
}

.ring-progress {
  fill: none;
  stroke: var(--cal);
  stroke-width: 13;
  stroke-linecap: round;
  /* circumference of r=62: 2π×62 ≈ 389.6 */
  stroke-dasharray: 0 389.6;
  transform-origin: 50% 50%;
  transform: rotate(-90deg);
  transition: stroke-dasharray 1.1s cubic-bezier(.4,0,.2,1),
              stroke .4s ease;
}

.calorie-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.cal-number {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.5px;
  line-height: 1;
}

.cal-unit {
  font-size: 11px;
  color: var(--hint);
  margin-top: 3px;
}

.cal-goal {
  font-size: 10px;
  color: var(--hint);
  margin-top: 4px;
}

.remaining-block {
  flex: 1;
}

.rem-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--cal);
  line-height: 1;
  letter-spacing: -.5px;
}

.rem-label {
  font-size: 13px;
  color: var(--hint);
  margin-top: 4px;
}

.rem-pct {
  font-size: 12px;
  color: var(--hint);
  margin-top: 6px;
}

/* ─── Macro bars ────────────────────────────────────────────────────────── */
.macro-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 22px;
}

.macro-item {
  background: var(--bg2);
  border-radius: var(--r-sm);
  padding: 11px 14px;
}

.macro-top {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 9px;
}

.macro-emoji { font-size: 15px; }

.macro-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
}

.macro-val {
  font-size: 12px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

.macro-track {
  background: rgba(255,255,255,.07);
  border-radius: 5px;
  height: 7px;
  overflow: hidden;
}

.macro-fill {
  height: 100%;
  border-radius: 5px;
  width: 0%;
  transition: width .9s cubic-bezier(.4,0,.2,1);
}

.prot-fill { background: var(--prot); }
.fat-fill  { background: var(--fat); }
.carb-fill { background: var(--carb); }

/* ─── Section label ─────────────────────────────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--hint);
  margin-bottom: 10px;
}

/* ─── Food list ─────────────────────────────────────────────────────────── */
.food-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.food-card {
  background: var(--bg2);
  border-radius: var(--r-sm);
  padding: 13px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: slideUp .28s ease-out both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-body { flex: 1; min-width: 0; }

.card-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.card-meta {
  font-size: 12px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.card-kcal {
  font-size: 16px;
  font-weight: 700;
  color: var(--cal);
}

.card-time {
  font-size: 11px;
  color: var(--hint);
}

.card-del {
  background: none;
  border: none;
  color: rgba(255,255,255,.18);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  transition: color .2s;
}

.card-del:hover, .card-del:active { color: var(--cal); }

/* ─── Empty state ───────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--hint);
}

.empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty-text { font-size: 15px; line-height: 1.7; }

/* ─── FAB ───────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 22px;
  right: 18px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--acc-txt);
  border: none;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
  transition: transform .18s, box-shadow .18s;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
}

.fab:active {
  transform: scale(.9);
  box-shadow: 0 3px 12px rgba(0,0,0,.35);
}

/* ─── Overlay ───────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}

.overlay.show { opacity: 1; pointer-events: auto; }

/* ─── Bottom sheet ──────────────────────────────────────────────────────── */
.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-radius: 24px 24px 0 0;
  z-index: 200;
  padding: 0 18px 28px;
  transform: translateY(100%);
  transition: transform .34s cubic-bezier(.32,1.28,.6,1);
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 38px;
  height: 4px;
  background: rgba(255,255,255,.18);
  border-radius: 2px;
  margin: 10px auto 18px;
}

.sheet-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.sheet-subtitle {
  font-size: 14px;
  color: var(--hint);
  margin-bottom: 14px;
}

/* Sheet steps */
.sheet-step { display: none; }
.sheet-step.active { display: block; }

/* ─── Textarea ──────────────────────────────────────────────────────────── */
.food-textarea {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1.5px solid rgba(255,255,255,.1);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 12px;
  resize: none;
  outline: none;
  transition: border-color .2s;
  margin-bottom: 12px;
  line-height: 1.5;
}

.food-textarea:focus { border-color: var(--accent); }
.food-textarea::placeholder { color: var(--hint); }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: var(--acc-txt);
  border: none;
  border-radius: var(--r-sm);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .2s, transform .12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:active  { transform: scale(.97); opacity: .9; }
.btn-primary:disabled { opacity: .45; cursor: default; }

.btn-ghost {
  flex: 1;
  padding: 14px;
  background: rgba(255,255,255,.08);
  color: var(--text);
  border: none;
  border-radius: var(--r-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .2s;
}

.btn-ghost:active { opacity: .7; }

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn-save { flex: 2; }

/* ─── Dish card ─────────────────────────────────────────────────────────── */
.dish-card {
  background: rgba(255,255,255,.05);
  border-radius: var(--r-sm);
  padding: 14px;
  margin: 14px 0;
}

.dish-total-row {
  margin-bottom: 10px;
}

.dish-label {
  font-size: 12px;
  color: var(--hint);
  margin-bottom: 3px;
}

.dish-total-kcal {
  font-size: 26px;
  font-weight: 800;
  color: var(--cal);
}

.dish-macro-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 8px;
}

.dish-macro {
  background: rgba(255,255,255,.06);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
}

.dish-macro-label { font-size: 10px; color: var(--hint); margin-bottom: 2px; }
.dish-macro-val   { font-size: 15px; font-weight: 700; }

/* ─── Portion slider ────────────────────────────────────────────────────── */
.portion-box { margin-bottom: 4px; }

.portion-label {
  font-size: 14px;
  color: var(--hint);
  margin-bottom: 10px;
}

.portion-label strong {
  color: var(--text);
  font-size: 20px;
}

.portion-slider {
  width: 100%;
  height: 5px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,.12);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  margin-bottom: 14px;
}

.portion-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
  cursor: pointer;
  transition: transform .15s;
}

.portion-slider:active::-webkit-slider-thumb { transform: scale(1.2); }

/* Portion КБЖУ grid */
.pkbzhu-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.pkbzhu-cell {
  background: rgba(255,255,255,.06);
  border-radius: 10px;
  padding: 9px 4px;
  text-align: center;
}

.pkbzhu-lbl { font-size: 10px; color: var(--hint); margin-bottom: 3px; }
.pkbzhu-num { font-size: 15px; font-weight: 700; }
.pkbzhu-cal  { color: var(--cal); }
.pkbzhu-prot { color: var(--prot); }
.pkbzhu-fat  { color: var(--fat); }
.pkbzhu-carb { color: var(--carb); }

/* ─── Success step ──────────────────────────────────────────────────────── */
.success-block {
  text-align: center;
  padding: 32px 20px 16px;
  animation: popIn .5s cubic-bezier(.34,1.56,.64,1);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(.7); }
  to   { opacity: 1; transform: scale(1); }
}

.success-icon  { font-size: 56px; margin-bottom: 12px; }
.success-title { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.success-sub   { font-size: 14px; color: var(--hint); line-height: 1.6; }

/* ─── Loading spinner ───────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
