/* Оформление в духе iOS (Apple HIG): системные цвета и слои, списки inset grouped, шрифт растёт вместе с настройкой
   «Размер текста» iOS (-apple-system-body + rem), панели на полупрозрачной подложке, цели нажатия от 44 pt. */

:root {
  color-scheme: light dark;
  --bg: #f2f2f7;               /* systemGroupedBackground */
  --cell: #ffffff;             /* secondarySystemGroupedBackground */
  --cell-pressed: #e5e5ea;
  --bar: rgba(249, 249, 249, .82);
  --label: #000000;
  --label2: rgba(60, 60, 67, .6);
  --label3: rgba(60, 60, 67, .3);
  --sep: rgba(60, 60, 67, .2);
  --fill: rgba(118, 118, 128, .12);
  --seg-on: #ffffff;
  --tint: #0a8f6e;             /* заливка главной кнопки: белый текст ≥ 4,5:1 */
  --tint-text: #0a8f6e;
  --tint-soft: rgba(10, 143, 110, .12);
  --red: #ff3b30;
  --k-workout: #34c759; --k-food: #ff9500; --k-night_attack: #5856d6; --k-vatnost: #af52de; --k-gut: #a2845e; --k-sex: #ff2d55; --k-note: #8e8e93; --k-sleep_bed: #5856d6; --k-sleep_wake: #ff9f0a;
  --k-allergy: #30b0c7; --k-joy: #ffcc00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --cell: #1c1c1e; --cell-pressed: #2c2c2e; --bar: rgba(22, 22, 24, .8);
    --label: #ffffff; --label2: rgba(235, 235, 245, .6); --label3: rgba(235, 235, 245, .3); --sep: rgba(84, 84, 88, .6);
    --fill: rgba(118, 118, 128, .24); --seg-on: #636366;
    --tint: #0f9d7a; --tint-text: #3fd4a8; --tint-soft: rgba(63, 212, 168, .16); --red: #ff453a;
    --k-workout: #30d158; --k-food: #ff9f0a; --k-night_attack: #5e5ce6; --k-vatnost: #bf5af2; --k-gut: #ac8e68; --k-sex: #ff375f; --k-note: #98989d; --k-sleep_bed: #5e5ce6; --k-sleep_wake: #ffb340;
    --k-allergy: #40c8e0; --k-joy: #ffd60a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif; font-size: 17px; line-height: 1.3; }
@supports (font: -apple-system-body) { html { font: -apple-system-body; } }
body { margin: 0; background: var(--bg); color: var(--label); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; margin: 0; }
button { cursor: pointer; border: 0; background: none; padding: 0; text-align: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--tint-text); outline-offset: 2px; border-radius: 6px; }
.ic { width: 1.4rem; height: 1.4rem; flex: none; }
.loading { padding: 64px 16px; color: var(--label2); }

/* ---------- заголовки ---------- */
.large { padding: env(safe-area-inset-top) 16px 0; }
.large-top { height: 44px; display: flex; justify-content: flex-end; align-items: center; margin-right: -12px; }
.large h1 { margin: 0; font-size: 2rem; font-weight: 700; letter-spacing: .01em; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--tint-text); }
.status { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; font-size: .765rem; color: var(--label2); }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--k-workout); }
.status.warn i { background: var(--k-food); }
.status.warn { color: var(--label); }
.status.busy i { background: var(--label3); }

.nav { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  min-height: calc(44px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0;
  background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--sep); }
.nav-back { display: flex; align-items: center; gap: 2px; height: 44px; color: var(--tint-text); justify-self: start; padding-right: 8px; }
.nav-back .ic { width: 1.5rem; height: 1.5rem; }
.nav-title { margin: 0; font-size: 1rem; font-weight: 600; text-align: center; }
.nav-right { justify-self: end; }
.nav-action { height: 44px; padding: 0 8px; color: var(--tint-text); font-weight: 600; }

/* ---------- раскладка ---------- */
main { max-width: 680px; margin: 0 auto; padding: 8px 16px 32px; }
main.with-tabbar { padding-bottom: calc(49px + env(safe-area-inset-bottom) + 24px); }
main.with-toolbar { padding-bottom: calc(232px + env(safe-area-inset-bottom)); }
main.with-toolbar .group, main.with-toolbar .row { scroll-margin-bottom: calc(248px + env(safe-area-inset-bottom)); }
main.with-cta { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.lead, .screen-sub { margin: 4px 4px 16px; color: var(--label2); font-size: .765rem; }
.center { text-align: center; }
.sub { color: var(--label2); }
.empty { margin: 0; padding: 12px 16px; color: var(--label2); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- списки inset grouped ---------- */
.group { margin: 0 0 24px; }
.group-h { margin: 0 0 6px; padding: 0 16px; font-size: .765rem; font-weight: 400; color: var(--label2); text-transform: uppercase; letter-spacing: .02em; }
.group-h.out { margin-top: 8px; padding: 0 4px; }
.group-f { margin: 6px 0 0; padding: 0 16px; font-size: .765rem; color: var(--label2); }
.rows { background: var(--cell); border-radius: 12px; overflow: hidden; }
.group.plain .rows { background: none; border-radius: 0; overflow: visible; }
.group.is-active .rows { box-shadow: 0 0 0 2px var(--tint-text); }

.row { position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 11px 16px;
  color: var(--label); background: none; }
.row + .row::before, .rows > .row-input + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.row:has(.sq) + .row::before { left: 58px; }
button.row:active, label.row:active { background: var(--cell-pressed); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { flex: 1; min-width: 0; }
.row-main .row-title { flex: none; }
.row-sub { font-size: .765rem; color: var(--label2); }
.row-value { color: var(--label2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row .chev { width: .9rem; height: .9rem; color: var(--label3); }
.row .chev.tint { width: 1.3rem; height: 1.3rem; color: var(--tint-text); }
.row.tint { color: var(--tint-text); }
.row .lead { color: var(--tint-text); }
.row .lead.muted { color: var(--label2); }
.row.danger { color: var(--red); justify-content: center; }
.row.danger .row-title { flex: none; }
.row.field { cursor: text; }

.sq { width: 30px; height: 30px; flex: none; border-radius: 7px; display: grid; place-items: center; color: #fff; }
.sq .ic { width: 20px; height: 20px; }
.k-workout.sq { background: var(--k-workout); } .k-food.sq { background: var(--k-food); }
.k-night_attack.sq { background: var(--k-night_attack); } .k-vatnost.sq { background: var(--k-vatnost); }
.k-gut.sq { background: var(--k-gut); } .k-sex.sq { background: var(--k-sex); } .k-note.sq { background: var(--k-note); }
.k-sleep_bed.sq { background: var(--k-sleep_bed); } .k-sleep_wake.sq { background: var(--k-sleep_wake); }
.k-allergy.sq { background: var(--k-allergy); } .k-joy.sq { background: var(--k-joy); }

.row-input { display: block; width: 100%; padding: 11px 16px; border: 0; background: none; color: var(--label); }
.row-input::placeholder { color: var(--label3); }
.row.field .row-input { padding: 0; flex: 1; min-width: 0; }
.row-input.end { text-align: right; }
.row-input.area { min-height: 96px; resize: none; }
.row.when { cursor: pointer; }
.row .tintv { color: var(--tint-text); }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; cursor: pointer; }

.pill { flex: none; padding: 3px 8px; border-radius: 999px; font-size: .765rem; background: var(--fill); color: var(--label2); }
.pill.tint { background: var(--tint-soft); color: var(--tint-text); font-weight: 600; }

/* ---------- кнопки ---------- */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; padding: 0 20px;
  border-radius: 14px; font-weight: 600; transition: opacity .15s, transform .15s; }
.btn.filled { background: var(--tint); color: #fff; }
.btn.filled:active { opacity: .8; transform: scale(.985); }
.btn.large { min-height: 54px; margin: 0 0 24px; }
.btn .ic { width: 1.3rem; height: 1.3rem; }

/* ---------- вкладка «Самочувствие» ---------- */
.sleep { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; margin: 0 0 16px; border-radius: 16px; background: var(--cell); }
.sleep .hero-text { flex: 1; }
.sleep .btn { width: auto; min-height: 44px; padding: 0 16px; border-radius: 999px; }
.btn.tinted { background: var(--tint-soft); color: var(--tint-text); }
.btn.tinted:active { opacity: .7; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 24px; }
.tile { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 128px; padding: 16px;
  border-radius: 16px; background: var(--cell); transition: transform .12s, background .12s; }
.tile .sq { width: 40px; height: 40px; border-radius: 10px; margin-bottom: 12px; }
.tile .sq .ic { width: 24px; height: 24px; }
.tile b { font-weight: 600; }
.tile span:last-child { font-size: .765rem; color: var(--label2); }
.tile:active { transform: scale(.97); background: var(--cell-pressed); }

/* ---------- вкладка «Тренировки» ---------- */
.hero { display: flex; flex-direction: column; gap: 16px; padding: 16px; margin: 0 0 24px; border-radius: 16px; background: var(--cell); }
.hero-top { display: flex; align-items: center; gap: 12px; }
.hero .sq { width: 40px; height: 40px; border-radius: 10px; }
.hero .sq .ic { width: 24px; height: 24px; }
.hero-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hero-text span { font-size: .765rem; color: var(--label2); }


/* ---------- экран тренировки ---------- */
.ex-head { align-items: flex-start; }
.set .num { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--fill); color: var(--label2); font-size: .765rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.set b { font-weight: 600; font-variant-numeric: tabular-nums; }
.set .note { flex: 0 1 auto; max-width: 40%; text-align: right; }
.set .ok { width: 1.2rem; height: 1.2rem; color: var(--tint-text); }
.row.small { min-height: 44px; font-size: .765rem; color: var(--label2); }
.row.small .lead { width: 1.1rem; height: 1.1rem; }
@keyframes pop { 0% { background: var(--tint-soft); } 100% { background: transparent; } }
.row.pop { animation: pop 1.2s ease-out; }

.toolbar, .cta { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep); }
.toolbar > *, .cta > * { max-width: 648px; margin-left: auto; margin-right: auto; }
.cta .btn.large, .toolbar .btn.large { margin-bottom: 0; }
.toolbar-h { margin: 0 0 10px; font-size: .765rem; color: var(--label2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-h b { color: var(--label); font-weight: 600; }
.steppers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.stepper { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 4px 6px; padding: 8px 8px 8px 12px;
  border-radius: 14px; background: var(--fill); }
.stepper .value { width: 100%; min-width: 0; border: 0; background: none; padding: 0; font-size: 2rem; font-weight: 700;
  font-variant-numeric: tabular-nums; color: var(--label); }
.stepper .unit { font-size: .765rem; color: var(--label2); padding-right: 4px; }
.stepper .seg { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; border-radius: 10px; overflow: hidden;
  background: var(--sep); }
.stepper .seg button { min-height: 44px; background: var(--cell); font-weight: 600; font-variant-numeric: tabular-nums; text-align: center; }
.stepper .seg button:active { background: var(--cell-pressed); }

/* ---------- формы быстрых записей ---------- */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 2px; border-radius: 10px; background: var(--fill); }
.segmented button { min-height: 40px; text-align: center; border-radius: 8px; font-size: .765rem; font-weight: 600; color: var(--label); transition: background .15s; }
.segmented button.on { background: var(--seg-on); box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 3px 1px rgba(0, 0, 0, .04); }

.photo { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 200px; margin: 0 0 24px; padding: 24px; border-radius: 16px; background: var(--cell); text-align: center; cursor: pointer; }
.photo .sq { width: 52px; height: 52px; border-radius: 14px; margin-bottom: 6px; }
.photo .sq .ic { width: 30px; height: 30px; }
.photo b { font-weight: 600; }
.photo span { font-size: .765rem; color: var(--label2); }
.photo input[type="file"] { display: none; }
.photo.has { padding: 0; overflow: hidden; min-height: 0; }
.photo.has img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--fill); }
.photo .retake { position: absolute; right: 12px; bottom: 12px; padding: 8px 14px; border-radius: 999px; color: #fff !important;
  background: rgba(0, 0, 0, .45); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); font-weight: 600; }

/* ---------- вкладка «Еда» ---------- */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 0 0 24px; border-radius: 12px; overflow: hidden; }
.ph { position: relative; aspect-ratio: 1; background: var(--fill); overflow: hidden; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .noph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--label3); }
.ph-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px; font-size: .765rem; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, .55)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ph-cap b { font-weight: 600; }

/* ---------- нижние вкладки ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px env(safe-area-inset-bottom); min-height: calc(49px + env(safe-area-inset-bottom));
  background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 44px; color: var(--label2);
  font-size: 10px; font-weight: 500; }
.tabbar a .ic { width: 26px; height: 26px; }
.tabbar a.on { color: var(--tint-text); }

/* ---------- шторка ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; background: rgba(0, 0, 0, 0); transition: background .22s; }
.sheet-wrap.in { background: rgba(0, 0, 0, .4); }
.sheet { position: relative; width: 100%; max-height: 88vh; overflow: auto; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--bg); border-radius: 14px 14px 0 0; transform: translateY(100%); transition: transform .22s ease-out; }
.sheet-wrap.in .sheet { transform: none; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label3); margin: 0 auto 8px; }
.sheet-cancel { position: absolute; top: 12px; left: 16px; height: 32px; color: var(--tint-text); }
.sheet h2 { margin: 8px 64px 20px; font-size: 1rem; font-weight: 600; text-align: center; }
.done { width: 72px; height: 72px; margin: 24px auto 16px; border-radius: 50%; display: grid; place-items: center; background: var(--tint); color: #fff; }
.done .ic { width: 40px; height: 40px; }
.sheet .sub { margin: -8px 0 24px; }

/* ---------- всплывающее «Записано» ---------- */
.toast { position: fixed; left: 50%; bottom: calc(49px + env(safe-area-inset-bottom) + 16px); z-index: 30; display: flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px; background: rgba(28, 28, 30, .92); color: #fff; font-size: .765rem; font-weight: 600; white-space: nowrap;
  transform: translateX(-50%); animation: toast-in .25s ease-out; transition: opacity .35s, transform .35s; }
.toast .ic { width: 18px; height: 18px; color: #3fd4a8; }
.toast.out { opacity: 0; transform: translate(-50%, 8px); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.error { color: var(--red); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
