/* Дневник еды — Mini App. Тёплая «бумажная» палитра; в Telegram базовые
   поверхности наследуются из темы клиента, фирменные акценты свои. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f4f1ea);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #241f17);
  --hint: var(--tg-theme-hint-color, #837b69);
  --line: color-mix(in srgb, var(--text) 8%, transparent);
  --field: color-mix(in srgb, var(--text) 5%, var(--card));
  --accent: #6b8f5b;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, var(--card));
  --protein: #6c8ebf;
  --fat: #d9a441;
  --carb: #c08262;
  --danger: #b65c43;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(30, 24, 12, .04), 0 6px 20px rgba(30, 24, 12, .05);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; } /* иначе display:flex у блока перебивает hidden */

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 560px; margin: 0 auto; padding: 6px 14px calc(30px + env(safe-area-inset-bottom)); }

/* --- шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0 12px; margin: 0 -14px; padding-left: 14px; padding-right: 14px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.nav-btn {
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--card); color: var(--text); font-size: 21px; line-height: 1;
  box-shadow: var(--shadow); cursor: pointer; padding-bottom: 3px;
}
.nav-btn:active { transform: scale(.92); }
.nav-btn.off { opacity: .35; }
.date-title {
  border: none; background: none; color: var(--text);
  font-size: 20px; font-weight: 700; letter-spacing: -.2px;
  cursor: pointer; padding: 8px 14px; font-family: inherit;
}
.date-title::after {
  content: ""; display: inline-block; margin-left: 7px; margin-bottom: 2px;
  width: 7px; height: 7px; border-right: 2px solid var(--hint);
  border-bottom: 2px solid var(--hint); transform: rotate(45deg) translateY(-2px);
}

/* --- сводка дня --- */
.summary {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  padding: 26px 20px 16px; text-align: center; margin-bottom: 16px;
}
.summary-kcal {
  font-size: 48px; font-weight: 800; letter-spacing: -1.5px; line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.summary-kcal .unit { font-size: 16px; font-weight: 500; color: var(--hint); letter-spacing: 0; margin-left: 2px; }
.summary-sub { color: var(--hint); font-size: 14px; margin-top: 4px; min-height: 18px; font-variant-numeric: tabular-nums; }
.goal-wrap { margin-top: 16px; }
.goal-bar { height: 6px; border-radius: 3px; background: var(--field); overflow: hidden; }
.goal-fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width .4s ease; }
.goal-text { font-size: 13px; color: var(--hint); margin-top: 6px; }
.macros {
  display: flex; margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--line);
}
.macro { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.macro + .macro { border-left: 1px solid var(--line); }
.macro-val { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.macro-name { font-size: 12px; color: var(--hint); }
.macro-name::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 5px; background: var(--dot, var(--hint)); vertical-align: 1px;
}
.macro.p { --dot: var(--protein); }
.macro.f { --dot: var(--fat); }
.macro.c { --dot: var(--carb); }

/* --- записи --- */
.entries { display: flex; flex-direction: column; gap: 10px; }
.entry {
  display: flex; align-items: center; gap: 13px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 11px 14px 11px 11px; cursor: pointer; border: none; text-align: left; width: 100%;
  color: var(--text); font: inherit;
  animation: rise .3s ease both;
}
.entry:nth-child(2) { animation-delay: .04s; }
.entry:nth-child(3) { animation-delay: .08s; }
.entry:nth-child(4) { animation-delay: .12s; }
.entry:nth-child(n+5) { animation-delay: .16s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.entry:active { transform: scale(.985); }
.entry-photo {
  width: 56px; height: 56px; border-radius: 15px; background: var(--accent-soft);
  object-fit: cover; flex-shrink: 0; display: flex; align-items: center;
  justify-content: center; font-size: 24px; overflow: hidden;
}
.entry-photo img { width: 100%; height: 100%; object-fit: cover; }
.entry-main { flex: 1; min-width: 0; }
.entry-title { font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-time { font-size: 13px; color: var(--hint); margin-top: 2px; }
.badge-rough {
  display: inline-block; font-size: 11px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
  padding: 1px 8px 2px; border-radius: 999px; margin-left: 6px; vertical-align: 1px;
}
.entry-kcal { text-align: right; font-weight: 700; font-size: 16.5px; font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: 4px; }
.entry-kcal .approx { color: var(--hint); font-weight: 500; }
.entry-kcal small { display: block; font-size: 11px; color: var(--hint); font-weight: 500; }
.entry.deleted { opacity: .45; }
.entry.deleted .entry-title { text-decoration: line-through; }

.empty { text-align: center; color: var(--hint); padding: 20vh 20px 40px; }
.empty-icon {
  width: 92px; height: 92px; border-radius: 50%; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; margin: 0 auto 16px;
}
.empty-title { font-size: 17px; font-weight: 650; color: var(--text); }
.empty-sub { font-size: 14px; margin-top: 5px; max-width: 260px; margin-left: auto; margin-right: auto; }

/* --- календарь --- */
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 14px; }
.cal-title { font-size: 18px; font-weight: 700; text-transform: capitalize; letter-spacing: -.2px; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center;
  font-size: 12px; color: var(--hint); margin-bottom: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell {
  aspect-ratio: 1 / 1.15; border-radius: 14px; background: var(--field);
  border: none; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font: inherit; padding: 2px;
}
.cal-cell:active { transform: scale(.92); }
.cal-cell.blank { background: none; cursor: default; }
/* дни с записями — карточки, пустые — плоские: заполненное заметнее пустого */
.cal-cell.has { background: var(--card); box-shadow: var(--shadow); }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day { font-size: 14px; font-weight: 600; opacity: .55; }
.cal-cell.has .cal-day, .cal-cell.today .cal-day { opacity: 1; }
.cal-kcal { font-size: 10.5px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.cal-cell.future { opacity: .25; }
.cal-legend { text-align: center; font-size: 12px; color: var(--hint); margin-top: 12px; }

/* --- нижний лист (редактор) --- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(22, 17, 10, .48); z-index: 30;
  opacity: 0; transition: opacity .22s ease;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 560px; margin: 0 auto;
  background: var(--card); border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .26s cubic-bezier(.32, .72, .35, 1);
  max-height: 88vh; overflow-y: auto;
}
.sheet.show { transform: translateY(0); }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--hint);
  opacity: .35; margin: 4px auto 16px; }
.sheet-photo { border-radius: 18px; overflow: hidden; margin-bottom: 16px; }
.sheet-photo img { width: 100%; height: 190px; object-fit: cover; display: block; }
.sheet-title {
  width: 100%; border: none; background: var(--field); border-radius: 13px;
  font-size: 17px; font-weight: 650; color: var(--text); padding: 12px 14px;
  font-family: inherit;
}
.sheet-title:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sheet-kcal { text-align: center; font-size: 30px; font-weight: 800; margin: 16px 0 4px;
  letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.sheet-kcal .range { display: block; font-size: 13px; color: var(--hint); font-weight: 500;
  margin-top: 2px; }

.portion-label { font-size: 13px; color: var(--hint); margin: 16px 0 8px; }
.chips { display: flex; gap: 8px; }
.chips button {
  flex: 1; padding: 12px 0; border-radius: 13px; border: none;
  background: var(--field); color: var(--text); font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: background .15s;
}
.chips button.active { background: var(--accent); color: #fff; }

.components { margin-top: 18px; }
.comp-head { font-size: 13px; color: var(--hint); margin-bottom: 2px; }
.comp-row { display: flex; justify-content: space-between; gap: 12px;
  font-size: 14px; padding: 9px 2px; }
.comp-row + .comp-row { border-top: 1px solid var(--line); }
.comp-row .name { color: var(--text); }
.comp-row .info { color: var(--hint); font-variant-numeric: tabular-nums; white-space: nowrap; }

.sheet-meta { display: flex; gap: 10px; margin-top: 16px; }
.sheet-meta input {
  flex: 1; border: none; background: var(--field); border-radius: 13px;
  padding: 12px; font-size: 15px; color: var(--text); font-family: inherit;
  min-width: 0;
}

.danger-btn, .restore-btn {
  width: 100%; margin-top: 20px; padding: 14px 0; border: none; border-radius: 14px;
  font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.danger-btn { background: color-mix(in srgb, var(--danger) 10%, var(--card)); color: var(--danger); }
.restore-btn { background: var(--accent); color: #fff; }

.toast {
  position: fixed; bottom: calc(22px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); background: var(--text); color: var(--card);
  padding: 11px 20px; border-radius: 999px; font-size: 14px; font-weight: 500;
  z-index: 40; opacity: 0; transition: opacity .25s; white-space: nowrap;
}
.toast.show { opacity: .94; }
