:root {
  --bg: #F6F3EE;
  --card: #FFFFFF;
  --ink: #2B2A28;
  --ink-2: #5E5A55;
  --muted: #A29D96;
  --line: #EEE9E2;
  --soft: #F1EDE7;

  --peach: #F7D3C1;  --peach-d: #E08E6B;
  --sage: #D3E8D9;   --sage-d: #5FA27A;
  --lav: #DED7F6;    --lav-d: #7E70D0;
  --butter: #F8EAB9; --butter-d: #C9A33A;
  --sky: #D2E5F4;    --sky-d: #5A92C2;
  --rose: #F6D6DC;   --rose-d: #C9566B;

  --r-lg: 26px;
  --r-md: 18px;
  --r-sm: 12px;
  --shadow: 0 1px 2px rgba(60, 45, 30, .04), 0 8px 24px rgba(60, 45, 30, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Вход ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 24px; box-shadow: var(--shadow); }
.login h1 { margin: 18px 0 2px; font-size: 30px; letter-spacing: -.02em; }
.login form { margin-top: 28px; display: grid; gap: 12px; }
.error { color: var(--rose-d); min-height: 20px; margin: 0; font-size: 14px; }

/* ---------- Каркас ---------- */
#app { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(110px + var(--safe-b)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 4px 14px; }
.topbar h1 { margin: 0; font-size: 30px; font-weight: 750; letter-spacing: -.025em; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--card); box-shadow: var(--shadow); }
.icon-btn svg { fill: var(--ink-2); }

.card { background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 26px 4px 10px; }
.section-title h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; }

/* ---------- Сегодня ---------- */
.today { padding: 20px 20px 8px; }
.today-date { font-size: 14px; color: var(--muted); font-weight: 500; }
.totals { display: flex; gap: 10px; margin: 12px 0 14px; }
.total {
  flex: 1; border-radius: var(--r-md); padding: 14px 14px 12px;
}
.total.kcal { background: var(--peach); }
.total.prot { background: var(--sage); }
.total .v { font-size: 30px; font-weight: 750; letter-spacing: -.02em; line-height: 1.05; }
.total .u { font-size: 14px; font-weight: 600; opacity: .55; margin-left: 3px; }
.total .l { font-size: 13px; font-weight: 600; opacity: .6; margin-top: 4px; }
.macro-mini { display: flex; gap: 14px; font-size: 13px; color: var(--muted); padding: 0 2px 10px; }
.macro-mini b { color: var(--ink-2); font-weight: 600; }

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  display: flex; align-items: center; gap: 12px; padding: 13px 2px;
  border-top: 1px solid var(--line); cursor: pointer;
}
.entry:active { opacity: .6; }
.entry .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--lav); flex: none; }
.entry .name { flex: 1; min-width: 0; }
.entry .name div { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .name small { color: var(--muted); font-size: 13px; }
.entry .k { font-weight: 650; white-space: nowrap; }
.entry .k small { color: var(--muted); font-weight: 500; font-size: 13px; }
.empty { padding: 18px 2px 20px; color: var(--muted); font-size: 15px; border-top: 1px solid var(--line); }

/* ---------- Сегмент ---------- */
.seg { display: inline-flex; background: var(--soft); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { padding: 7px 13px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- История ---------- */
.hist { padding: 4px 16px; }
.hrow { border-top: 1px solid var(--line); }
.hrow:first-child { border-top: 0; }
.hhead { display: flex; align-items: center; gap: 10px; padding: 14px 2px; cursor: pointer; width: 100%; text-align: left; }
.hhead .t { flex: 1; min-width: 0; }
.hhead .t div { font-weight: 600; }
.hhead .t small { color: var(--muted); font-size: 13px; }
.hhead .vals { text-align: right; white-space: nowrap; }
.hhead .vals b { font-weight: 650; }
.hhead .vals small { display: block; color: var(--muted); font-size: 13px; }
.chev { width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 2; transition: transform .2s; flex: none; }
.hrow.open > .hhead .chev { transform: rotate(90deg); }
.hbody { padding: 0 0 10px 0; }
.hbody .entry { padding-left: 4px; }
.hbody .hist-inner { background: var(--soft); border-radius: var(--r-md); padding: 0 12px; margin-bottom: 4px; }
.hbody .hist-inner .hrow { border-color: #E6E0D8; }
.tag-empty { color: var(--muted); font-size: 13px; font-weight: 500; background: var(--soft); padding: 3px 9px; border-radius: 999px; }
.add-day { display: flex; align-items: center; gap: 8px; color: var(--lav-d); font-weight: 600; font-size: 15px; padding: 12px 4px; }
.more { display: block; width: 100%; padding: 14px; text-align: center; color: var(--lav-d); font-weight: 600; border-top: 1px solid var(--line); }

/* ---------- Таббар ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b));
  width: min(360px, calc(100% - 32px));
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(255,255,255,.86); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-radius: 999px; box-shadow: 0 10px 30px rgba(60,45,30,.12); padding: 8px 10px; z-index: 10;
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 92px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--ink); }
.fab {
  width: 58px; height: 58px; border-radius: 50%; margin-top: -26px;
  background: linear-gradient(145deg, #B9AEF0, #8F82DD);
  box-shadow: 0 10px 24px rgba(126,112,208,.42), inset 0 1px 0 rgba(255,255,255,.35);
  display: grid; place-items: center; transition: transform .15s;
}
.fab:active { transform: scale(.93); }
.fab svg { width: 28px; height: 28px; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; fill: none; }

/* ---------- Кнопки и поля ---------- */
.btn { height: 54px; border-radius: var(--r-md); font-weight: 650; font-size: 17px; width: 100%; transition: transform .12s, opacity .12s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(145deg, #B3A7EE, #8F82DD); color: #fff; box-shadow: 0 8px 20px rgba(126,112,208,.3); }
.btn.primary:disabled { opacity: .5; }
.btn.ghost { background: var(--soft); color: var(--ink); }
.btn.danger { background: var(--rose); color: var(--rose-d); }
input[type=password], .field input, .search {
  width: 100%; height: 52px; border-radius: var(--r-sm); border: 1.5px solid transparent;
  background: var(--soft); padding: 0 14px; font-size: 17px; outline: none; transition: border-color .15s, background .15s;
}
input:focus { border-color: var(--lav); background: #fff; }
.login input[type=password] { background: #fff; box-shadow: var(--shadow); }

/* ---------- Шторка ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(40,30,20,.28); z-index: 20; opacity: 0; transition: opacity .25s; }
.backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 560px; margin: 0 auto;
  background: var(--bg); border-radius: 28px 28px 0 0; max-height: 92dvh; overflow-y: auto;
  padding: 10px 18px calc(20px + var(--safe-b));
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 -10px 40px rgba(40,30,20,.12);
}
.sheet.show { transform: translateY(0); }
.grip { width: 40px; height: 5px; border-radius: 3px; background: #DDD6CC; margin: 0 auto 8px; }
.sheet-head { display: grid; grid-template-columns: 80px 1fr 80px; align-items: center; margin-bottom: 14px; }
.sheet-head h3 { text-align: center; }
.sheet-head h3 { margin: 0; font-size: 18px; font-weight: 700; }
.sheet-head button { color: var(--lav-d); font-weight: 600; min-width: 64px; text-align: left; }
.sheet-head span { min-width: 64px; }

.form { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; position: relative; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); padding-left: 4px; }
.row { display: flex; gap: 10px; align-items: end; }
.row .field { flex: 1; }
.grid4 { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 8px; }
.grid4 .field input { padding: 0 10px; text-align: center; }
.f-kcal input { background: var(--peach) !important; font-weight: 650; }
.f-p input { background: var(--sage) !important; }
.f-f input { background: var(--butter) !important; }
.f-c input { background: var(--sky) !important; }
.grid4 .field input:focus { border-color: rgba(0,0,0,.08); }
.date-chip {
  display: inline-flex; align-items: center; gap: 8px; background: var(--card); box-shadow: var(--shadow);
  border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 15px; position: relative; justify-self: start;
}
.date-chip input { position: absolute; inset: 0; opacity: 0; width: 100%; }
.date-chip svg { width: 18px; height: 18px; stroke: var(--lav-d); fill: none; stroke-width: 2; }
.mode-seg { height: 52px; align-items: stretch; }
.mode-seg button { padding: 0 12px; font-size: 13px; }
.preview { font-size: 14px; color: var(--ink-2); background: var(--card); border-radius: var(--r-sm); padding: 12px 14px; }
.preview b { color: var(--ink); }

.suggest { display: grid; gap: 6px; }
.suggest-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 2px 4px; }
.sugg {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  background: var(--card); border-radius: var(--r-sm); padding: 12px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.sugg:active { background: var(--lav); }
.sugg span { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sugg small { color: var(--muted); white-space: nowrap; font-size: 13px; }
.picked { display: flex; align-items: center; justify-content: space-between; background: var(--lav); border-radius: var(--r-sm); padding: 10px 14px; font-size: 14px; font-weight: 600; color: #4E43A0; }
.picked button { color: #4E43A0; font-weight: 700; font-size: 18px; line-height: 1; }

.switch-row { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: var(--r-sm); padding: 12px 14px; font-weight: 560; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 999px; background: #E3DDD5; position: relative; transition: background .2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.15); transition: transform .2s; }
.switch:checked { background: var(--sage-d); }
.switch:checked::after { transform: translateX(20px); }

.list-card { background: var(--card); border-radius: var(--r-md); overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 15px 16px; border-top: 1px solid var(--line); width: 100%; text-align: left; font-weight: 560; }
.list-item:first-child { border-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item small { color: var(--muted); font-weight: 500; display: block; font-size: 13px; }
.list-item.red { color: var(--rose-d); }

/* ---------- Статистика ---------- */
.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.stat { border-radius: var(--r-md); padding: 14px; }
.stat .l { font-size: 13px; font-weight: 600; opacity: .6; }
.stat .v { font-size: 26px; font-weight: 750; letter-spacing: -.02em; margin-top: 2px; }
.stat .v small { font-size: 14px; opacity: .55; font-weight: 600; margin-left: 2px; }
.stat.kcal { background: var(--peach); }
.stat.prot { background: var(--sage); }
.stat.fill { background: var(--card); grid-column: span 2; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
.stat.fill .v { font-size: 20px; }
.chart-card { padding: 16px 16px 10px; margin-top: 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.chart-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.chart-head .tip { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-size: 10px; fill: var(--muted); font-family: inherit; }
.chart .bar { cursor: pointer; transition: opacity .15s; }
.chart .bar.dim { opacity: .35; }
.range { display: flex; justify-content: center; margin: 4px 0 6px; }

/* ---------- Тост ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 560;
  z-index: 30; box-shadow: 0 8px 24px rgba(0,0,0,.18); white-space: nowrap;
}
