* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Telegram'dan tashqarida (brauzerda) ishlatiladigan zaxira ranglar */
:root {
  --f-bg: #ffffff; --f-bg2: #f0f1f5; --f-text: #12141a; --f-hint: #868c98;
  --f-link: #2481cc; --f-btn: #2481cc; --f-btn-text: #ffffff; --f-danger: #e0484d;
}
@media (prefers-color-scheme: dark) {
  :root {
    --f-bg: #1d2129; --f-bg2: #121419; --f-text: #eef0f4; --f-hint: #8a919e;
    --f-link: #5aa9ff; --f-btn: #3a8cf0; --f-btn-text: #ffffff; --f-danger: #ff6b6b;
  }
}
/* Telegram o‘z mavzusini --tg-theme-* o‘zgaruvchilari orqali beradi */
:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--f-bg2));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--f-bg)));
  --text: var(--tg-theme-text-color, var(--f-text));
  --hint: var(--tg-theme-hint-color, var(--f-hint));
  --link: var(--tg-theme-link-color, var(--f-link));
  --btn: var(--tg-theme-button-color, var(--f-btn));
  --btn-text: var(--tg-theme-button-text-color, var(--f-btn-text));
  --accent: var(--tg-theme-accent-text-color, var(--btn));
  --danger: var(--tg-theme-destructive-text-color, var(--f-danger));
  --ok: #2fb35a;
  --line: rgba(128, 128, 128, .2);
  --soft: rgba(128, 128, 128, .11);
  --r: 16px;
  --tabs-h: 62px;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body { overscroll-behavior-y: none; }
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 12px calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom));
}
body.resting .view { padding-bottom: calc(var(--tabs-h) + 110px + env(safe-area-inset-bottom)); }

/* ---------- typography ---------- */
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.eyebrow { font-size: 12.5px; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.sub { color: var(--hint); font-size: 13.5px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.num-tab { font-variant-numeric: tabular-nums; }
p { margin: 8px 0; }

.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 4px 14px; }
.levels { display: grid; gap: 8px; margin-top: 12px; }
.level { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; border-radius: 14px; padding: 12px 14px; background: var(--soft); }
.level.on { box-shadow: inset 0 0 0 2px var(--btn); }
.level .lv-icon { font-size: 26px; line-height: 1; flex: none; }
.level .lv-text b { display: block; font-size: 16px; }
.level .lv-text small { display: block; color: var(--hint); font-size: 13px; margin-top: 2px; }
.sheet .level { background: var(--card); }
.ai-card { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--btn) 35%, transparent); }
.btn:disabled { opacity: .45; }
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand { width: 48px; height: 48px; border-radius: 13px; display: block; flex: none; }
.section-title { margin: 22px 6px 8px; font-size: 13px; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }

/* ---------- cards ---------- */
.card { background: var(--card); border-radius: var(--r); padding: 14px; margin-bottom: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card.flush { padding: 4px 0; }
.pill { font-size: 12.5px; font-weight: 600; padding: 4px 9px; border-radius: 999px; background: var(--soft); color: var(--hint); white-space: nowrap; }
.pill.accent { background: color-mix(in srgb, var(--btn) 14%, transparent); color: var(--accent); }
.pill.ok { background: rgba(47, 179, 90, .14); color: var(--ok); }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 12px; padding: 11px 14px; background: var(--soft); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--btn); color: var(--btn-text); }
.btn.block { width: 100%; margin-top: 12px; padding: 14px; font-size: 16px; }
.btn.small { padding: 7px 11px; font-size: 13.5px; border-radius: 10px; }
.btn.ghost { background: transparent; color: var(--link); }
.btn.danger { background: transparent; color: var(--danger); }
.btn:active { opacity: .7; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1; }
.icon-btn { border: 0; background: var(--card); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--hint); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 0; background: var(--soft); border-radius: 999px; padding: 7px 12px; font-size: 13.5px; font-weight: 550; white-space: nowrap; }
.chip.on { background: var(--btn); color: var(--btn-text); }

/* ---------- lists ---------- */
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border: 0; background: none; width: 100%; text-align: left; position: relative; }
.row + .row::before { content: ""; position: absolute; left: 14px; right: 0; top: 0; border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 550; }
.row .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--hint); font-size: 18px; }
.badge-day { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--soft); flex: none; }
.badge-day.today { background: var(--btn); color: var(--btn-text); }
.badge-day.rest { color: var(--hint); }

.plan { list-style: none; margin: 12px 0 0; padding: 0; }
.plan li { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.plan li:first-child { border-top: 0; }
.plan .n { width: 20px; color: var(--hint); font-size: 13px; text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.plan .nm { flex: 1; }
.plan .sr { color: var(--hint); font-size: 13.5px; font-variant-numeric: tabular-nums; }

/* ---------- gym age / KPIs ---------- */
.hero { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero-num { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.hero-num small { font-size: 15px; font-weight: 600; color: var(--hint); margin: 0 6px 0 2px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.kpi { background: var(--card); border-radius: var(--r); padding: 12px 14px; }
.kpi .label { font-size: 13px; color: var(--hint); }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 2px; letter-spacing: -.01em; }
.kpi .delta { font-size: 12.5px; color: var(--hint); }

/* ---------- week strip ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 12px; }
.wd { text-align: center; font-size: 12px; color: var(--hint); }
.wd .dot { margin: 5px auto 0; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: var(--soft); color: var(--hint); }
.wd.done .dot { background: var(--ok); color: #fff; }
.wd.today .dot { box-shadow: 0 0 0 2px var(--btn); }
.wd.rest .dot { background: transparent; border: 1px dashed var(--line); }

/* ---------- daily metrics ---------- */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.metric { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--hint); }
.metric input { width: 100%; }

input.in, select.in, textarea.in {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 10px; outline: none; width: 100%;
  color: var(--text); -webkit-appearance: none; appearance: none; min-width: 0;
}
input.in:focus, textarea.in:focus, select.in:focus { border-color: var(--btn); }
textarea.in { min-height: 80px; resize: vertical; font-size: 13px; }
.field { display: block; margin-top: 12px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin: 0 0 5px 2px; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-weight: 550; }
.check input { width: 20px; height: 20px; accent-color: var(--btn); }

/* ---------- session ---------- */
.sess { position: sticky; top: 0; z-index: 5; margin: -14px -12px 10px; padding: 12px 16px 12px; background: var(--bg); }
.sess-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.timer { font-size: 34px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.timer-of { font-size: 14px; color: var(--hint); font-weight: 600; white-space: nowrap; flex: none; }
.bars { display: grid; gap: 6px; margin-top: 10px; }
.bar-lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--hint); margin-bottom: 3px; }
.track { height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--btn) 16%, transparent); overflow: hidden; }
.track > i { display: block; height: 100%; border-radius: 99px; background: var(--btn); }
.track.ok { background: rgba(47, 179, 90, .16); }
.track.ok > i { background: var(--ok); }

.ex { background: var(--card); border-radius: var(--r); margin-bottom: 8px; overflow: hidden; }
.ex.current { box-shadow: inset 0 0 0 2px var(--btn); }
.ex-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; border: 0; background: none; text-align: left; }
.ex-head .n { width: 28px; height: 28px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.ex-head .n.ok { background: var(--ok); color: #fff; }
.ex-head .t { flex: 1; min-width: 0; }
.ex-head .t b { display: block; font-weight: 600; }
.ex-head .t small { color: var(--hint); font-size: 13px; }
.ex-head .cnt { font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; }
.ex-body { padding: 0 14px 14px; }
.ex-cue { font-size: 13.5px; color: var(--hint); margin: 0 0 10px; }
.last { font-size: 13px; background: var(--soft); padding: 8px 10px; border-radius: 10px; margin-bottom: 10px; }
.last b { font-weight: 600; }
.hint-up { font-size: 13px; color: var(--ok); font-weight: 600; margin: -4px 0 10px; }

.sets { display: grid; grid-template-columns: 28px 1fr 1fr 48px; gap: 8px; align-items: center; }
.sets.t { grid-template-columns: 28px 1fr 48px; }
.sets .h { font-size: 12px; color: var(--hint); text-align: center; }
.sets .i { text-align: center; font-weight: 700; color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; }
.sets input { text-align: center; font-size: 17px; font-weight: 600; padding: 10px 6px; font-variant-numeric: tabular-nums; }
.sets .done-row input { color: var(--hint); }
.tick { width: 48px; height: 44px; border-radius: 12px; border: 0; background: var(--soft); display: grid; place-items: center; }
.tick svg { width: 22px; height: 22px; fill: none; stroke: var(--hint); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tick.on { background: var(--ok); }
.tick.on svg { stroke: #fff; }
.ex-tools { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.ex-tools .btn { flex: 1 1 auto; white-space: nowrap; padding: 8px 10px; }
.ex-tools .btn.sq { flex: 0 0 42px; }
.yt-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.yt-row .btn { white-space: nowrap; padding: 9px 6px; }

/* ---------- rest bar ---------- */
.restbar {
  position: fixed; left: 10px; right: 10px; z-index: 20; max-width: 620px; margin: 0 auto;
  bottom: calc(var(--tabs-h) + 10px + env(safe-area-inset-bottom));
  background: var(--card); border-radius: 18px; overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .22), 0 0 0 1px var(--line);
}
.rest-fill { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--btn) 16%, transparent); transition: width .5s linear; }
.restbar.done .rest-fill { background: rgba(47, 179, 90, .25); width: 100% !important; }
.rest-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; }
.rest-label { font-size: 12.5px; color: var(--hint); font-weight: 600; }
.rest-time { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.rest-btns { display: flex; gap: 6px; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--hint); font-size: 11.5px; font-weight: 600; }
.tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--btn); }

/* ---------- sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); animation: fade .18s ease; }
.sheet {
  position: relative; background: var(--bg); border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto;
  padding: 8px 14px calc(24px + env(safe-area-inset-bottom)); animation: up .22s cubic-bezier(.2, .8, .2, 1);
  width: 100%; max-width: 640px; margin: 0 auto; overscroll-behavior: contain;
}
.sheet::before { content: ""; display: block; width: 38px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 2px 12px; position: sticky; top: -8px; background: var(--bg); padding: 6px 0; z-index: 2; }
.sheet-head h2 { flex: 1; min-width: 0; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.thumb { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; padding: 0; border-radius: 10px; overflow: hidden; background: #000 center / cover no-repeat; }
.thumb .play { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; background: rgba(0, 0, 0, .62); }
.thumb .play::after { content: ""; position: absolute; left: 13px; top: 10px; border-left: 11px solid #fff; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.thumb.big .play { width: 58px; height: 58px; margin: -29px 0 0 -29px; }
.thumb.big .play::after { left: 23px; top: 18px; border-left-width: 17px; border-top-width: 11px; border-bottom-width: 11px; }
.thumb:active { opacity: .8; }
.vid-card { display: grid; grid-template-columns: 124px 1fr; gap: 12px; align-items: start; padding: 12px; }
.vid-card.playing, .vid-card.no-vid { grid-template-columns: 1fr; }
.vid-card .video-box { margin-top: 0; }
.vid-title { display: flex; gap: 6px; align-items: baseline; }
.vid-title .n { color: var(--hint); font-weight: 700; font-size: 13px; }
.thumb-sm { width: 64px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--soft); flex: none; display: block; }
.plan li[data-act] { cursor: pointer; }
.play-mini { color: var(--accent); font-size: 11px; margin-left: 2px; }
.video-box { position: relative; padding-top: 56.25%; border-radius: 12px; overflow: hidden; background: #000; margin-top: 10px; }
.video-box iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.edit-item { background: var(--card); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; }
.edit-top { display: flex; align-items: center; gap: 8px; }
.edit-top b { flex: 1; min-width: 0; font-weight: 600; }
.edit-top .n { color: var(--hint); font-weight: 700; width: 20px; font-size: 13px; }
.mini { border: 0; background: var(--soft); width: 32px; height: 32px; border-radius: 9px; font-size: 15px; display: grid; place-items: center; }
.mini.x { color: var(--danger); }
.edit-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.edit-fields label { font-size: 12px; color: var(--hint); display: flex; flex-direction: column; gap: 3px; }
.edit-fields input { text-align: center; }

/* ---------- charts ---------- */
.chart { position: relative; margin-top: 8px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--hint); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--btn); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--btn); opacity: .1; }
.chart .dot { fill: var(--btn); stroke: var(--card); stroke-width: 2; }
.chart .end-lbl { fill: var(--text); font-size: 12px; font-weight: 650; }
.chart .xhair { stroke: var(--hint); stroke-width: 1; }
.tip {
  position: absolute; top: 0; pointer-events: none; background: var(--text); color: var(--card);
  font-size: 12px; padding: 5px 8px; border-radius: 8px; white-space: nowrap; transform: translateX(-50%); font-weight: 600;
}
.tip span { opacity: .7; font-weight: 500; }

.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, auto); grid-auto-columns: 1fr; gap: 3px; margin-top: 10px; }
.heat i { aspect-ratio: 1; border-radius: 3px; background: var(--soft); display: block; }
.heat i.l1 { background: color-mix(in srgb, var(--btn) 35%, transparent); }
.heat i.l2 { background: color-mix(in srgb, var(--btn) 65%, transparent); }
.heat i.l3 { background: var(--btn); }
.heat i.fut { background: transparent; }
.heat i.sel { outline: 2px solid var(--text); outline-offset: 1px; }
.heat-legend { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--hint); margin-top: 8px; justify-content: flex-end; }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; background: var(--soft); }
.heat-legend i.l1 { background: color-mix(in srgb, var(--btn) 35%, transparent); }
.heat-legend i.l2 { background: color-mix(in srgb, var(--btn) 65%, transparent); }
.heat-legend i.l3 { background: var(--btn); }
.heat-read { font-size: 13px; color: var(--hint); margin-top: 6px; min-height: 18px; }

.log-ex { padding: 9px 0; border-top: 1px solid var(--line); }
.log-ex:first-child { border-top: 0; }
.log-ex .sets-txt { font-size: 13.5px; color: var(--hint); font-variant-numeric: tabular-nums; }
.pr { color: var(--ok); font-weight: 700; font-size: 12px; margin-left: 4px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabs-h) + 20px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--card); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25); max-width: 90vw; text-align: center;
}
.empty { text-align: center; color: var(--hint); padding: 24px 10px; font-size: 14px; }
