:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-dim: #9aa3b2;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --warn: #fbbf24;
  --danger: #f87171;
  --protein: #60a5fa;
  --fat: #fbbf24;
  --carbs: #c084fc;
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любой заданный нами display
   (иначе .login{display:grid} и подобные правила оставляют элемент на экране). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--text-dim); font-size: .9rem; margin: .25rem 0 .75rem; }

/* ---------- Кнопки и поля ---------- */

.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .6rem 1.1rem;
  cursor: pointer;
  transition: filter .15s, background .15s;
  /* Класс вешается и на <a> (вход через Яндекс ID) — гасим стили ссылки */
  display: inline-block;
  text-align: center;
  text-decoration: none;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--accent-dim); color: #07130c; font-weight: 600; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--sm { padding: .35rem .7rem; font-size: .85rem; }
.btn--danger { background: transparent; color: var(--danger); border-color: transparent; padding: .25rem .5rem; }

.input {
  font: inherit;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  width: 100%;
}
.input:focus { outline: 2px solid var(--accent-dim); outline-offset: -1px; }
.input--date { width: auto; }

.field { display: flex; flex-direction: column; gap: .3rem; flex: 1 1 140px; }
.field > span { font-size: .82rem; color: var(--text-dim); }
.field--grow { flex: 2 1 200px; }
.field-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }

.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem;
  margin: 1rem 0;
}
.fieldset legend { padding: 0 .4rem; font-size: .85rem; color: var(--text-dim); }

.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- Экран входа ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.2rem 1.8rem;
  max-width: 420px;
  text-align: center;
}
.login__logo { font-size: 3rem; }
.login__tagline { color: var(--text-dim); margin: .75rem 0 1.5rem; }
.login__actions { display: grid; gap: .6rem; }
.login__error { color: var(--danger); font-size: .9rem; }

/* ---------- Каркас ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__brand { font-weight: 700; }
.topbar__user { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; }

.tabs {
  display: flex;
  gap: .25rem;
  padding: .5rem 1rem 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 57px;
  z-index: 9;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  font: inherit;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: .5rem .8rem .7rem;
  cursor: pointer;
  white-space: nowrap;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

.content { max-width: 940px; margin: 0 auto; padding: 1.2rem 1rem 4rem; }
.panel { display: none; }
.panel.is-active { display: block; }
.panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
}
.card__head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }

.badge {
  font-size: .75rem;
  padding: .2rem .55rem;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.badge--draft { background: rgba(251,191,36,.15); color: var(--warn); }
.badge--partial { background: rgba(251,191,36,.15); color: var(--warn); }
.badge--complete { background: rgba(74,222,128,.15); color: var(--accent); }

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.segmented__btn {
  font: inherit;
  font-size: .85rem;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: .35rem .85rem;
  border-radius: 7px;
  cursor: pointer;
}
.segmented__btn.is-active { background: var(--surface); color: var(--text); }

/* ---------- Кольца прогресса ---------- */

.rings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .75rem;
  margin-bottom: 1.2rem;
}
.ring {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem;
}
.ring__label { font-size: .8rem; color: var(--text-dim); }
.ring__value { font-size: 1.35rem; font-weight: 700; margin: .2rem 0; }
.ring__value small { font-size: .85rem; font-weight: 400; color: var(--text-dim); }
.ring__bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.ring__fill { height: 100%; border-radius: 99px; transition: width .4s; }
.ring__note { font-size: .78rem; color: var(--text-dim); margin-top: .35rem; }

/* ---------- Приёмы пищи ---------- */

.meals { display: grid; gap: .75rem; }
.meal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem;
  display: flex;
  gap: .9rem;
}
.meal__photo {
  width: 78px; height: 78px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}
.meal__body { flex: 1; min-width: 0; }
.meal__top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.meal__time { font-size: .82rem; color: var(--text-dim); }
.meal__items { margin: .4rem 0; font-size: .9rem; color: var(--text-dim); }
.meal__totals { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .85rem; }
.macro-k { color: var(--accent); font-weight: 600; }
.macro-p { color: var(--protein); }
.macro-f { color: var(--fat); }
.macro-c { color: var(--carbs); }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 2.5rem 1rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Загрузка фото ---------- */

.uploader {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  transition: border-color .15s, background .15s;
  margin-bottom: 1rem;
}
.uploader.is-dragover { border-color: var(--accent); background: rgba(74,222,128,.06); }
.uploader__icon { font-size: 2.4rem; }
.uploader__title { margin: .5rem 0 .2rem; font-weight: 600; }
.uploader__hint { color: var(--text-dim); font-size: .85rem; margin: 0 0 1rem; }

.status-box {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.draft__body { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .8rem; }
.draft__photo {
  width: 160px; height: 160px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}
.draft__main { flex: 1 1 340px; min-width: 0; }

.warnings {
  background: rgba(251,191,36,.1);
  border: 1px solid rgba(251,191,36,.35);
  border-radius: var(--radius-sm);
  padding: .7rem .85rem;
  margin-bottom: .8rem;
  font-size: .87rem;
}
.warnings ul { margin: 0; padding-left: 1.1rem; }
.warnings li + li { margin-top: .3rem; }

/* ---------- Таблицы ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 520px; }
.table th, .table td { padding: .45rem .4rem; text-align: right; border-bottom: 1px solid var(--border); }
.table th { color: var(--text-dim); font-weight: 500; font-size: .8rem; }
.table .th-name { text-align: left; }
.table tfoot td { font-weight: 600; border-bottom: none; }
.table .input { padding: .35rem .45rem; text-align: right; min-width: 64px; }
.table .input--name { text-align: left; min-width: 140px; }

/* ---------- График ---------- */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 160px;
  padding: .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow-x: auto;
}
.chart__col { flex: 1 0 22px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 4px; }
.chart__bar { background: var(--accent-dim); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.chart__bar.is-over { background: var(--warn); }
.chart__label { font-size: .65rem; color: var(--text-dim); text-align: center; white-space: nowrap; }

/* ---------- План питания ---------- */

.plan-form { display: grid; gap: .25rem; }

.plan-day { margin-bottom: 1rem; }
.plan-day__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .5rem;
}
.plan-slot { margin-bottom: .6rem; }
.plan-slot__title { font-size: .82rem; color: var(--text-dim); margin-bottom: .2rem; }
.plan-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .6rem;
  padding: .45rem .6rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin-bottom: .3rem;
  font-size: .88rem;
}
.plan-item__name { flex: 1; min-width: 0; }
.plan-item__name a { color: inherit; text-decoration: none; }
.plan-item__name a:hover { text-decoration: underline; }
.plan-item__meta { color: var(--text-dim); font-size: .82rem; white-space: nowrap; }

.cart-box {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: .9rem;
  margin-top: .8rem;
}

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .7rem 1.1rem;
  z-index: 100;
  max-width: min(92vw, 520px);
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.toast--error { border-color: var(--danger); color: var(--danger); }
.toast--ok { border-color: var(--accent-dim); }

@media (max-width: 560px) {
  .draft__photo { width: 100%; height: 200px; }
  .meal__photo { width: 60px; height: 60px; }
}
