:root {
  color-scheme: dark;
  --bg: #0e1110;
  --bg-elev: #121613;
  --surface: #181e1a;
  --surface-2: #1f2722;
  --line: #2a332d;
  --line-strong: #3b473e;
  --text: #eef3ec;
  --muted: #9aa89e;
  --muted-2: #748177;
  --accent: #c6f45c;
  --accent-ink: #12160f;
  --accent-soft: rgba(198, 244, 92, 0.12);
  --danger: #ff7070;
  --danger-soft: rgba(255, 107, 107, 0.12);
  --warn: #ffb347;
  --ok: #7bd88f;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.42);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -200px, #17201a 0%, var(--bg) 55%) no-repeat, var(--bg);
  color: var(--text);
  font: 400 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(78px + var(--safe-bottom));
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

a {
  color: var(--accent);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Шапка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, calc((100vw - 760px) / 2 + 16px));
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  background: rgba(14, 17, 16, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 16px rgba(198, 244, 92, 0.18);
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand-text small {
  font-size: 11px;
  color: var(--muted);
}

.net-state {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
}

.net-state.is-warn {
  color: var(--warn);
  border-color: rgba(255, 179, 71, 0.4);
  background: rgba(255, 179, 71, 0.08);
}

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

.view {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.loading {
  padding: 48px 0;
  text-align: center;
  color: var(--muted);
}

.noscript {
  margin: 0;
  padding: 14px 16px;
  background: #3a2a13;
  color: #ffdfae;
  font-size: 14px;
  text-align: center;
}

.page-title {
  font-size: 22px;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}

.page-sub {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card {
  margin-top: 12px;
}

.card-title {
  font-size: 17px;
  font-weight: 650;
  margin: 0 0 6px;
}

.card-text {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

.muted {
  color: var(--muted);
}

.error-box {
  border-color: rgba(255, 112, 112, 0.4);
  background: linear-gradient(180deg, rgba(255, 112, 112, 0.09), rgba(255, 112, 112, 0.02));
}

.error-box .card-title {
  color: var(--danger);
}

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

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.06s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:hover {
  border-color: var(--muted-2);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.btn-primary:hover {
  background: #d3ff70;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(255, 112, 112, 0.35);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 8px 10px;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

.btn-small {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 13px;
  border-radius: 9px;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

.icon-btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.link-btn {
  appearance: none;
  border: none;
  background: none;
  padding: 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.link-btn:hover {
  text-decoration: underline;
}

.link-btn.is-muted {
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 16px;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
  min-height: 72px;
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

input[type="checkbox"] {
  width: 26px;
  height: 26px;
  min-height: 0;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

label {
  display: block;
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}

/* ---------- Выбор даты ---------- */

.datebar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 14px;
}

.date-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.date-weekday {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.date-field input[type="date"] {
  width: 100%;
  min-height: 30px;
  padding: 0;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.date-field input[type="date"]:focus {
  box-shadow: none;
}

.date-field input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.75);
  opacity: 0.7;
  cursor: pointer;
}

/* ---------- Карточка тренировки ---------- */

.session-card {
  margin-bottom: 18px;
}

.session-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.session-head h1 {
  font-size: 25px;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 0 0 4px;
}

.session-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.session-meta .dot::before {
  content: "·";
  margin-right: 6px;
}

.session-progress {
  margin-top: 12px;
}

.progress-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

progress {
  appearance: none;
  display: block;
  width: 100%;
  height: 8px;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
}

progress::-webkit-progress-bar {
  background: var(--surface-2);
  border-radius: 999px;
}

progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
}

.progress-value {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.session-notes {
  margin-top: 12px;
  padding: 8px 12px;
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- Секции ---------- */

.section {
  margin-top: 22px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-count {
  font-size: 11px;
  color: var(--muted-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

/* ---------- Упражнение ---------- */

.exercise {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
  margin-bottom: 10px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.exercise.is-done {
  border-color: rgba(198, 244, 92, 0.38);
  background: linear-gradient(180deg, rgba(198, 244, 92, 0.07), rgba(198, 244, 92, 0.015));
}

.exercise.is-error {
  border-color: rgba(255, 112, 112, 0.45);
}

.exercise-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.ex-check {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -4px 0 0 -6px;
}

.ex-main {
  flex: 1;
  min-width: 0;
}

.ex-title {
  margin: 0;
  font-size: 16px;
  font-weight: 620;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.exercise.is-done .ex-title {
  color: var(--muted);
}

.ex-target {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted-2);
}

.ex-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field span {
  font-size: 11px;
  color: var(--muted);
  padding-left: 2px;
}

.field input {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 16px;
}

.field input[type="number"] {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.picker-targets .field input {
  text-align: center;
}

.ex-note {
  margin-top: 8px;
}

.ex-note textarea {
  min-height: 58px;
  font-size: 16px;
}

.ex-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted-2);
}

.ex-status.is-saved {
  color: var(--ok);
}

.ex-status.is-error {
  color: var(--danger);
}

.ex-status .link-btn {
  padding: 0;
  font-size: 12px;
}

.ex-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.ex-foot .link-btn {
  min-height: 36px;
  padding: 6px 2px;
}

.ex-note-toggle {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 2px;
}

.ex-note-toggle.has-note::after {
  content: "•";
  color: var(--accent);
  margin-left: 4px;
}

.ex-remove {
  font-size: 12px;
  color: var(--muted-2);
  opacity: 0.85;
}

.ex-remove:hover {
  color: var(--danger);
}

.add-exercise {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

.add-exercise:hover {
  color: var(--text);
  border-color: var(--muted-2);
  background: rgba(255, 255, 255, 0.02);
}

/* ---------- Пустое состояние ---------- */

.empty-state {
  text-align: center;
  padding: 26px 6px 20px;
}

.empty-state h2 {
  font-size: 19px;
  margin: 0 0 6px;
}

.empty-state p {
  color: var(--muted);
  font-size: 14px;
  margin: 0 auto;
  max-width: 42ch;
}

.template-list {
  display: grid;
  gap: 8px;
  margin-top: 20px;
  text-align: left;
}

.template-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 11px 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}

.template-choice:hover {
  border-color: var(--accent);
}

.template-choice small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-top: 2px;
}

.badge {
  flex: none;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(198, 244, 92, 0.3);
  border-radius: 999px;
  padding: 3px 8px;
}

.empty-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 10px;
  color: var(--muted-2);
  font-size: 12px;
}

.empty-divider::before,
.empty-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ---------- История ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.stat-value {
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-value small {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.stat-label {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.month-title {
  margin: 22px 0 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.session-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease;
}

.session-row:hover {
  border-color: var(--line-strong);
}

.session-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-right: 10px;
  border-right: 1px solid var(--line);
}

.session-date strong {
  font-size: 20px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.session-date span {
  margin-top: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.session-info {
  min-width: 0;
}

.session-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 620;
  font-size: 15px;
}

.session-title .chev {
  color: var(--muted-2);
  font-size: 18px;
}

.session-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 2px 0 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.session-info progress {
  height: 4px;
}

.export-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.empty-hint {
  padding: 30px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Прогресс ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar select {
  flex: 1;
  min-width: 200px;
}

.chart-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.chart-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev);
}

.segmented button {
  flex: 1;
  min-height: 32px;
  padding: 5px 9px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface-2);
  color: var(--text);
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart .grid-line {
  stroke: var(--line);
  stroke-width: 1;
}

.chart .axis-text {
  fill: var(--muted-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart .series {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart .area {
  fill: rgba(198, 244, 92, 0.08);
  stroke: none;
}

.chart .dot {
  fill: var(--accent);
  stroke: var(--bg);
  stroke-width: 2;
}

.chart .dot-hit {
  fill: transparent;
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 200px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 14px;
}

.history-table th {
  padding: 7px 6px;
  text-align: left;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}

.history-table td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.history-table td:first-child {
  white-space: nowrap;
}

.history-table tr:last-child td {
  border-bottom: none;
}

/* ---------- План ---------- */

.intro {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(198, 244, 92, 0.04);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.intro strong {
  color: var(--text);
}

.template {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.template[open] {
  border-color: var(--line-strong);
}

.template summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 12px 15px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.template summary::-webkit-details-marker {
  display: none;
}

.template summary:hover {
  background: rgba(255, 255, 255, 0.015);
}

.template-summary-main {
  flex: 1;
  min-width: 0;
}

.template-name {
  font-weight: 650;
  font-size: 16px;
}

.template-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.template-chev {
  flex: none;
  color: var(--muted-2);
  transition: transform 0.15s ease;
}

.template[open] .template-chev {
  transform: rotate(90deg);
}

.template-body {
  padding: 14px 15px 16px;
  border-top: 1px solid var(--line);
}

.template-settings {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 8px;
  margin-bottom: 14px;
}

.template-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.template-item:last-of-type {
  border-bottom: none;
}

.ti-name {
  font-size: 14px;
  font-weight: 550;
  overflow-wrap: anywhere;
}

.ti-group {
  margin-left: 6px;
  font-size: 10px;
  font-weight: 500;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ti-fields {
  display: flex;
  gap: 6px;
  margin-top: 7px;
}

.ti-field {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.ti-field input {
  width: 62px;
  min-height: 34px;
  padding: 4px 6px;
  font-size: 16px;
  text-align: center;
}

.ti-field input.ti-reps {
  width: 78px;
}

.ti-actions {
  display: flex;
  gap: 2px;
}

.ti-actions .icon-btn {
  width: 34px;
  height: 34px;
  min-height: 0;
  font-size: 15px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.ti-actions .icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.ti-actions .icon-btn[data-action="tpl-remove"]:hover {
  color: var(--danger);
}

.add-form {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.add-form-row {
  display: grid;
  grid-template-columns: 76px 96px minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.add-form-row .btn {
  min-height: 42px;
}

.auto-hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted-2);
}

.plan-footer {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

/* ---------- Диалоги ---------- */

dialog.dialog {
  width: min(560px, calc(100vw - 20px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog.dialog::backdrop {
  background: rgba(4, 7, 5, 0.72);
  backdrop-filter: blur(3px);
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.dialog-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.dialog-head .icon-btn {
  width: 36px;
  height: 36px;
  font-size: 17px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.dialog-body {
  max-height: calc(100dvh - 130px);
  overflow-y: auto;
  padding: 16px;
  overscroll-behavior: contain;
}

.dialog-text {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.dialog-actions .btn {
  flex: 1 1 auto;
}

.dialog-actions .btn-danger {
  margin-right: auto;
}

.form-stack {
  display: grid;
  gap: 12px;
}

.picker-search {
  margin-bottom: 12px;
}

.picker-group-title {
  margin: 14px 0 6px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 14px;
}

.picker-item:hover {
  background: var(--surface-2);
  border-color: var(--line);
}

.picker-item span {
  font-size: 11px;
  color: var(--muted);
}

.picker-empty {
  padding: 18px 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.picker-targets {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

details.create-exercise {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

details.create-exercise summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  list-style: none;
}

details.create-exercise summary::-webkit-details-marker {
  display: none;
}

details.create-exercise .form-stack {
  margin-top: 12px;
}

/* ---------- Навигация ---------- */

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  max-width: 760px;
  transform: translateX(-50%);
  padding: 6px 6px calc(4px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(20, 25, 22, 0.94);
  backdrop-filter: blur(14px);
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  padding: 5px 2px;
  border-radius: 10px;
  color: var(--muted-2);
  text-decoration: none;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tab svg {
  width: 22px;
  height: 22px;
}

.tab:hover {
  color: var(--muted);
}

.tab.is-active {
  color: var(--accent);
  background: rgba(198, 244, 92, 0.06);
}

.tab.is-active::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  width: 26px;
  height: 2px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: var(--accent);
}

/* ---------- Уведомления ---------- */

.offline-bar {
  position: fixed;
  left: 50%;
  bottom: calc(64px + var(--safe-bottom));
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(760px, 100%);
  padding: 9px 14px;
  transform: translateX(-50%);
  background: #3a2a13;
  border-top: 1px solid rgba(255, 179, 71, 0.4);
  color: #ffdfae;
  font-size: 13px;
}

.offline-bar span {
  flex: 1;
  min-width: 0;
}

.offline-bar .btn {
  flex: none;
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
  border-color: rgba(255, 179, 71, 0.45);
  background: rgba(255, 179, 71, 0.12);
  color: #ffdfae;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 60;
  transition: bottom 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(520px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}

body.has-offline .toasts {
  bottom: calc(128px + var(--safe-bottom));
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.4;
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}

.toast > span {
  flex: 1;
  min-width: 0;
}

.toast-error {
  border-color: rgba(255, 112, 112, 0.45);
  background: #2c1c1c;
  color: #ffdcdc;
}

.toast-success {
  border-color: rgba(123, 216, 143, 0.4);
  background: #17251b;
  color: #d8f7e0;
}

.toast-close {
  flex: none;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  opacity: 0.6;
  font-size: 14px;
}

.toast-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.07);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Адаптив ---------- */

@media (max-width: 420px) {
  .view {
    padding: 12px 12px 36px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .brand-text small {
    display: none;
  }

  .session-head h1 {
    font-size: 22px;
  }

  .stat-value {
    font-size: 20px;
  }

  .chart-head {
    flex-direction: column;
    align-items: stretch;
  }

  .template-settings {
    grid-template-columns: 1fr;
  }

  .add-form-row {
    grid-template-columns: 1fr 1fr;
  }

  .add-form-row .btn {
    grid-column: 1 / -1;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions .btn {
    width: 100%;
  }
}

@media (min-width: 761px) {
  .tabbar {
    border: 1px solid var(--line);
    border-bottom: none;
    border-radius: 14px 14px 0 0;
  }

  .offline-bar {
    border: 1px solid rgba(255, 179, 71, 0.4);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
  }

  .ex-fields {
    max-width: 420px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
