:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #71767f;
  --line: #e6e8ec;
  --accent: #111318;
  --ok: #1a7f37;
  --err: #b42318;
  --protein: #175cd3;
  --fat: #b54708;
  --carbs: #6941c6;
  --fiber: #067647;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.wrap { max-width: 900px; margin: 0 auto; padding: 28px 16px 72px; }

header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 18px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.date { color: var(--muted); font-size: 14px; }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.flash.success { background: #e6f4ea; color: var(--ok); }
.flash.error { background: #feeceb; color: var(--err); }

/* --- Итоги за день --- */
.summary {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.summary .kcal { display: flex; align-items: center; gap: 10px; }
.summary .kcal b { font-size: 36px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.summary .kcal span { color: var(--muted); font-size: 12px; line-height: 1.3; }
.macros { display: flex; gap: 20px; flex-wrap: wrap; margin-left: auto; }
.macros div { text-align: center; min-width: 58px; }
.macros b { display: block; font-size: 17px; font-weight: 700; }
.macros span { color: var(--muted); font-size: 12px; }
.macros .p b { color: var(--protein); }
.macros .f b { color: var(--fat); }
.macros .c b { color: var(--carbs); }
.macros .fb b { color: var(--fiber); }

/* --- Загрузка фото --- */
.upload {
  background: var(--card);
  border: 1.5px dashed #c8cdd4;
  border-radius: 16px;
  padding: 18px;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 26px;
}
.upload input[type="file"] { flex: 1 1 220px; font-size: 14px; }
.upload button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.upload button:hover { opacity: 0.9; }
.hint { width: 100%; margin: 0; color: var(--muted); font-size: 12.5px; }

/* --- Карточки блюд --- */
/* align-items: start — карточки не растягиваются по высоте строки,
   поэтому раскрытие details в одной карточке не «уезжает» у соседних */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; align-items: start; }

/* Раскрытая карточка занимает всю строку — таблице нужно место;
   на мобиле сетка и так одноколоночная, ничего не меняется */
.card:has(details[open]) { grid-column: 1 / -1; }
.card:has(details[open]) .photo { max-width: 380px; }

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 210px;
}
.card .del { position: absolute; top: 8px; right: 8px; }
.card .del button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 7px;
  border-radius: 8px;
  cursor: pointer;
}
.card .del button:hover { background: #feeceb; color: var(--err); }

.card .photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}

.card h2 { margin: 0; font-size: 16px; letter-spacing: -0.01em; padding-right: 28px; }
.card .kcal { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; }
.card .kcal small { font-size: 13px; color: var(--muted); font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 9px; }
.chips .p  { background: #eff4ff; color: var(--protein); }
.chips .f  { background: #fef0e6; color: var(--fat); }
.chips .c  { background: #f2ecfb; color: var(--carbs); }
.chips .fb { background: #e7f4ee; color: var(--fiber); }

details { margin-top: auto; border-top: 1px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; font-size: 13px; color: var(--muted); }
summary:hover { color: var(--text); }
.desc { font-size: 13.5px; line-height: 1.45; margin: 6px 0 8px; }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; white-space: nowrap; }
td.num, th.num { text-align: right; }
.note { color: var(--muted); font-style: italic; font-size: 11px; }
.verdict { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 8px 0 0; }

time { font-size: 11.5px; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 48px 0; font-size: 15px; }

/* --- Карточка в обработке / ошибка --- */
.hidden { display: none !important; }

.card-pending { border-style: dashed; }

/* --- Спойлер «Исправить через ИИ» --- */
.corr-details { border-top: 0; padding-top: 0; }
.corr-details summary { color: var(--protein); font-size: 12.5px; }
.corr-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.corr-form textarea {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
  min-height: 44px;
}
.corr-form textarea:focus { outline: 2px solid #bed3f7; border-color: var(--protein); }
.corr-form button {
  align-self: flex-start;
  background: var(--protein);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.corr-form button:hover { opacity: 0.9; }
.corr-form button:disabled { opacity: 0.5; cursor: default; }
.corr-error { font-size: 12px; color: var(--err); margin: 8px 0 0; }
.pending-name { color: var(--muted); font-style: italic; }
.card-error {
  font-size: 12.5px;
  color: var(--err);
  background: #feeceb;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0;
  word-break: break-word;
}

/* Скелетон-плашки вместо цифр */
.sk {
  height: 20px;
  border-radius: 999px;
  flex: 1 1 40px;
  background: linear-gradient(100deg, #e9ebee 40%, #f6f7f9 50%, #e9ebee 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.sk-wide { flex: 1.6 1 60px; }
@keyframes shimmer {
  to { background-position: -200% 0; }
}

/* --- Прогресс загрузки файла --- */
.upload-progress {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  width: min(420px, calc(100vw - 32px));
}
.up-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 12px 14px;
}
.up-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.up-title span { color: var(--muted); font-variant-numeric: tabular-nums; }
.up-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.up-fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.15s ease;
}

/* Анимация мини-plumbob: парение + «вращение» */
@keyframes pb-bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -12px; }
}
@keyframes pb-spin {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.18); }
}

/* Мини-plumbob для pending-карточки */.mini-plumbob {
  --pb-w: 20px;
  --pb-h: 30px;
  position: relative;
  width: var(--pb-w);
  height: var(--pb-h);
  margin: 4px 0;
  filter: drop-shadow(0 0 6px rgba(53, 217, 75, 0.5));
  animation: pb-bob 2.2s ease-in-out infinite, pb-spin 1.9s linear infinite;
}
.mini-plumbob::before,
.mini-plumbob::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  background: linear-gradient(180deg, #4ef05f, #23c93a);
}
.mini-plumbob::before { top: 0; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.mini-plumbob::after { bottom: 0; clip-path: polygon(0 0, 100% 0, 50% 100%); }

/* --- Верхние вкладки --- */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a {
  padding: 9px 16px 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border-radius: 10px 10px 0 0;
  border: 1px solid transparent;
  border-bottom: 0;
  position: relative;
  top: 1px;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); background: var(--card); border-color: var(--line); }

/* --- Календарь --- */
.wrap-wide { max-width: 1150px; }

.cal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.cal-switch { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); padding: 4px; border-radius: 11px; }
.cal-switch a { padding: 6px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-decoration: none; }
.cal-switch a.active { background: var(--accent); color: #fff; }
.cal-pager { display: flex; align-items: center; gap: 12px; }
.cal-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; min-width: 180px; text-align: center; }
.cal-pager .arrow {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 9px;
  font-size: 18px; color: var(--text); text-decoration: none; line-height: 1;
}
.cal-pager .arrow:hover { border-color: #c8cdd4; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 0; }
.day-cell {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 11px;
  min-height: 92px;
  padding: 8px 9px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.day-cell:hover { border-color: #c8cdd4; background: #fbfbfc; }
.day-cell.other { opacity: 0.38; }
.day-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.day-cell.empty { background: transparent; border-style: dashed; }
.dnum { font-size: 13px; font-weight: 700; }
.day-cell .dkcal { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; display: flex; align-items: center; gap: 6px; }
.dmini { font-size: 11px; color: var(--muted); }

.flag { font-style: normal; font-size: 11px; }
.flag.over { color: var(--err); }
.flag.under { color: #b58900; }
.flag.ok { color: var(--ok); }

/* Цвета попадания в нормы (зелёный/красный/жёлтый), '' — чёрный по умолчанию */
.m-ok { color: var(--ok) !important; }
.m-over { color: var(--err) !important; }
.m-under { color: #b58900 !important; }

/* --- Год: 12 мини-месяцев --- */
.year-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); gap: 14px; }
.mini-month { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 12px 10px; }
.mini-month h3 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.mini-month h3 a { text-decoration: none; color: var(--text); }
.mini-month h3 a:hover { text-decoration: underline; }
.mini-sub { font-size: 10.5px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mini-dow { font-size: 9.5px; color: var(--muted); text-align: center; padding: 2px 0; }
.mini-day { font-size: 11px; text-align: center; padding: 4px 0; border-radius: 5px; text-decoration: none; color: var(--text); }
.mini-day.otherm { padding: 4px 0; }
.mini-day.over { background: #feeceb; color: var(--err); font-weight: 700; }
.mini-day.under { background: #fdf3d7; color: #b58900; }
.mini-day.ok { background: #e6f4ea; }
.mini-day:hover { outline: 1px solid #c8cdd4; }

/* --- «Это интересно» --- */
.facts { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; margin-top: 18px; }
.facts h2 { font-size: 16px; margin: 0 0 12px; letter-spacing: -0.01em; }
.facts ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.facts li { display: flex; justify-content: space-between; gap: 14px; font-size: 13.5px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.facts li:last-child { border-bottom: 0; padding-bottom: 0; }
.facts li span { color: var(--muted); }
.facts li b { text-align: right; font-weight: 600; }

.facts h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.stars { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; margin-top: 16px; }
.stars-random { margin-top: 18px; }
.stars-random .grid { margin-top: 8px; }
.day-link {
  margin-top: auto;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--protein);
  text-decoration: none;
}
.day-link:hover { text-decoration: underline; }

.crumbs { margin: 0 0 14px; font-size: 13.5px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }

/* --- Форма настроек --- */
.form-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.form-card label { font-size: 13px; font-weight: 600; display: flex; flex-direction: column; gap: 6px; }
.form-card input, .form-card textarea {
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
}
.form-card input:focus, .form-card textarea:focus { outline: 2px solid #bed3f7; border-color: var(--protein); }
.form-card textarea { resize: vertical; min-height: 84px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row label { flex: 1 1 110px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.group-title { font-size: 13px; font-weight: 600; }
.form-group .form-row label { font-weight: 400; color: var(--muted); flex: 0 1 150px; }
.btn {
  align-self: flex-start;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { opacity: 0.9; }

@media (max-width: 640px) {
  .day-cell { min-height: 66px; padding: 6px; }
  .dmini { display: none; }
  .cal-title { min-width: 0; }
  .facts li { flex-direction: column; gap: 2px; }
  .facts li b { text-align: left; }
}

/* --- Выход (шапка) --- */
.logout { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.logout .username { color: var(--muted); font-size: 13px; }
.logout button {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.logout button:hover { color: var(--err); border-color: #f1b9b3; }

/* --- Страница входа --- */
.login-wrap { max-width: 380px; margin: 14vh auto 0; padding: 0 16px; }
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 4px; color: var(--muted); font-size: 13.5px; }
.login-card label { font-size: 13px; font-weight: 600; display: flex; flex-direction: column; gap: 6px; }
.login-card input {
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}
.login-card input:focus { outline: 2px solid #bed3f7; border-color: var(--protein); }
.login-card .btn { width: 100%; }
