/*
  Оформление.

  Опора — сам зал: графитовые аппараты Technogym с жёлтыми деталями.
  Отсюда пара «графит + жёлтый»: жёлтый работает только как заливка под
  тёмным текстом, поэтому контраст остаётся высоким и на солнце.

  Шрифты системные намеренно: приложение обязано открываться без сети
  (ТЗ 25), а веб-шрифт с CDN это требование ломает.
*/

:root {
  --ink: #101418;
  --ink-2: #566068;
  --line: #D9DCDA;
  --line-2: #ECEEEC;
  --bg: #F1F2F0;
  --surface: #FFFFFF;
  --accent: #F2C200;
  --accent-ink: #101418;
  --ok: #1C6B45;
  --ok-bg: #E4F2EA;
  --warn: #A8321C;
  --warn-bg: #FBE9E5;
  --info-bg: #EDF1F5;
  --radius: 12px;
  --tap: 44px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #EEF1F3; --ink-2: #9AA5AD; --line: #333B42; --line-2: #232A30;
    --bg: #0E1216; --surface: #171D22; --accent: #F2C200; --accent-ink: #101418;
    --ok: #6BD3A0; --ok-bg: #143325; --warn: #FF9E8A; --warn-bg: #3A1D17; --info-bg: #1D242A;
  }
}
:root[data-theme="dark"] {
  --ink: #EEF1F3; --ink-2: #9AA5AD; --line: #333B42; --line-2: #232A30;
  --bg: #0E1216; --surface: #171D22;
  --ok: #6BD3A0; --ok-bg: #143325; --warn: #FF9E8A; --warn-bg: #3A1D17; --info-bg: #1D242A;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.45;
  overscroll-behavior-y: none; -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0 0 10px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hide { display: none !important; }

/* ——— каркас ——— */
.app { max-width: 640px; margin: 0 auto; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}
.topbar h1 { font-size: 22px; }
.topbar .sub { color: #A8B4BC; font-size: 13px; margin-top: 4px; }
.topbar__row { display: flex; align-items: center; gap: 10px; }
.topbar__row h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  min-width: var(--tap); min-height: var(--tap); display: inline-grid; place-items: center;
  border-radius: 10px; font-size: 18px;
}
.topbar .iconbtn { color: #fff; }
.topbar .iconbtn:hover { background: rgba(255,255,255,.14); }

.screen { padding: 16px 16px 120px; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs.hide { display: none; }
.tab {
  min-height: var(--tap); padding: 8px 2px 10px; font-size: 11px; color: var(--ink-2);
  display: grid; gap: 2px; justify-items: center; text-align: center;
}
.tab b { font-size: 17px; line-height: 1; font-weight: 600; }
.tab[aria-current="page"] { color: var(--ink); box-shadow: inset 0 3px 0 var(--accent); }

/* ——— блоки ——— */
.card {
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card--flat { border-color: var(--line); }
.card h2 { font-size: 17px; margin-bottom: 4px; }
.sec { margin: 22px 0 10px; font-size: 13px; color: var(--ink-2); }
.sec:first-child { margin-top: 0; }
.row { display: flex; gap: 10px; align-items: center; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.btn {
  min-height: var(--tap); padding: 11px 16px; border-radius: 10px;
  background: var(--ink); color: var(--surface); font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn--block { display: flex; width: 100%; }
.btn--accent { background: var(--accent); color: var(--accent-ink); }
.btn--ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn--ghost-dark { background: transparent; color: #fff; border: 1.5px solid rgba(255,255,255,.4); min-height: 40px; padding: 8px 12px; }
.btn--light { background: #fff; color: var(--ink); min-height: 40px; padding: 8px 14px; }
.btn--danger { background: transparent; color: var(--warn); border: 1.5px solid var(--warn); }
.btn--sm { min-height: 38px; padding: 8px 12px; font-size: 14px; }

.tag {
  display: inline-block; font-size: 12px; padding: 3px 8px; border-radius: 999px;
  background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.tag--main { background: var(--ink); color: var(--surface); }
.tag--ok { background: var(--ok-bg); color: var(--ok); }
.tag--warn { background: var(--warn-bg); color: var(--warn); }
.tag--accent { background: var(--accent); color: var(--accent-ink); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

.note {
  border-left: 3px solid var(--line); padding: 8px 0 8px 10px; margin: 10px 0;
  font-size: 13px; color: var(--ink-2);
}
.note--warn { border-color: var(--warn); color: var(--warn); background: var(--warn-bg); padding: 10px; border-radius: 0 8px 8px 0; }
.note--info { border-color: var(--ink-2); background: var(--info-bg); padding: 10px; border-radius: 0 8px 8px 0; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
}
textarea.input { min-height: 88px; resize: vertical; }
.input:focus { outline: 3px solid var(--accent); outline-offset: -1px; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 38px; padding: 8px 14px; border-radius: 999px; font-size: 14px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }

.list { display: grid; gap: 10px; }
.item {
  display: block; width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--radius); padding: 14px;
}
.item__title { font-weight: 600; }
.item__meta { font-size: 13px; color: var(--ink-2); margin-top: 3px; }

/* ——— рабочий экран ——— */
.progress { height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

.ex { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.ex--done { border-color: var(--ok); }
.ex--skipped { opacity: .6; }
.ex__head { padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }
.ex__name { font-weight: 600; flex: 1; min-width: 0; }
.ex__meta { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.ex__body { padding: 0 14px 12px; }

/* Одна строка = один подход. Прошлый результат стоит рядом с полями,
   а не под всей карточкой (ТЗ 11.3, A25). */
.sets { width: 100%; border-collapse: collapse; }
.sets th {
  font-size: 11px; font-weight: 600; color: var(--ink-2); text-align: left;
  padding: 4px 4px; border-bottom: 1px solid var(--line-2);
}
.sets td { padding: 5px 4px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.sets tr:last-child td { border-bottom: 0; }
.sets .c-n { width: 26px; color: var(--ink-2); font-size: 13px; }
.sets .c-prev { width: 82px; font-size: 12px; color: var(--ink-2); }
.sets .c-do { width: 56px; text-align: right; }
.setinput {
  width: 100%; min-width: 0; min-height: 42px; padding: 6px 8px; border-radius: 8px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font-variant-numeric: tabular-nums; text-align: center;
}
.setinput--sugg { border-style: dashed; color: var(--ink-2); }
.setinput:focus { outline: 3px solid var(--accent); outline-offset: -1px; }
.doBtn {
  min-width: 52px; min-height: 42px; border-radius: 10px; border: 1.5px solid var(--line);
  font-size: 13px; font-weight: 600; color: var(--ink-2); background: var(--surface);
}
.doBtn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.legend { font-size: 12px; color: var(--ink-2); display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.legend b { font-weight: 600; color: var(--ink); }

/* ——— справочник тренажёров: строго одна колонка (ТЗ 26.4, A09) ——— */
.machines { display: grid; grid-template-columns: 1fr; gap: 12px; }
.machine { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; }
.machine img { display: block; width: 100%; height: auto; aspect-ratio: 25 / 18; object-fit: cover; background: #fff; }
.machine__body { padding: 12px 14px 14px; }
.machine__code { font-weight: 700; letter-spacing: .02em; }
.machine__en { color: var(--ink-2); font-size: 13px; }

/* ——— график ——— */
.chart { width: 100%; height: 160px; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--ink); stroke-width: 2; }
.chart .dot { fill: var(--accent); stroke: var(--ink); stroke-width: 1.5; }

/* ——— календарь ——— */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal__d {
  aspect-ratio: 1; border-radius: 8px; background: var(--line-2); display: grid; place-items: center;
  font-size: 12px; color: var(--ink-2);
}
.cal__d--saved { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.cal__d--partial { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.cal__d--many { box-shadow: inset 0 0 0 2px var(--ink); }

/* ——— шторка ——— */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet__scrim { position: absolute; inset: 0; background: rgba(16,20,24,.5); }
.sheet__panel {
  position: relative; width: 100%; max-width: 640px; max-height: 88dvh; overflow: auto;
  background: var(--bg); border-radius: 16px 16px 0 0; padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
}
.sheet__head {
  position: sticky; top: 0; background: var(--bg); display: flex; align-items: center; gap: 10px;
  padding: 14px 12px 10px 16px; border-bottom: 1px solid var(--line);
}
.sheet__title { font-size: 17px; flex: 1; }
.sheet__body { padding: 14px 16px 16px; }

/* ——— таймер отдыха ——— */
.rest {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--ink); color: #fff;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.rest[hidden] { display: none; }
.rest__time { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 74px; }
.rest__label { flex: 1; font-size: 13px; color: #A8B4BC; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 60;
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px;
  max-width: 90%; text-align: center;
}
.toast[hidden] { display: none; }

.empty {
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px 16px;
  text-align: center; color: var(--ink-2); background: var(--surface);
}

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; }

table.plain { width: 100%; border-collapse: collapse; font-size: 14px; }
table.plain th { text-align: left; font-size: 12px; color: var(--ink-2); padding: 6px 6px; border-bottom: 1px solid var(--line); }
table.plain td { padding: 7px 6px; border-bottom: 1px solid var(--line-2); }

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

/* ——— баннер обновления версии ——— */
.update {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: var(--ink); color: #fff; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); font-size: 14px;
}
.update[hidden] { display: none; }
