:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.08);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px rgba(11, 11, 11, 0.04);

  --s1: #2a78d6;  /* синий */
  --s2: #eb6834;  /* оранжевый */
  --s3: #1baf7a;  /* бирюзовый */
  --s7: #6250d6;  /* фиолетовый */
  --accent-wash: #cde2fb;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;
  --bad-ink: #b42a2a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: none;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s7: #9085e9;
    --accent-wash: #184f95;
    --good-ink: #0ca30c;
    --bad-ink: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: none;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s7: #9085e9;
  --accent-wash: #184f95;
  --good-ink: #0ca30c;
  --bad-ink: #e66767;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 1280px; margin-left: auto; margin-right: auto; padding-left: 24px; padding-right: 24px; }
@media (max-width: 640px) { #app { padding-left: 16px; padding-right: 16px; } }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
button:focus-visible { outline: 2px solid var(--s1); outline-offset: 2px; }

.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* --- шапка и фильтры -------------------------------------------------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 28px;
  padding-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand-mark circle { fill: var(--s1); }
.brand-mark path { fill: none; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.brand h1 { font-size: 22px; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; font-size: 13px; }

.theme, .filters {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
}
.theme button, .filters button {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap;
}
.theme button:hover, .filters button:hover { background: var(--border); }
.theme button[aria-pressed="true"], .filters button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.filters { display: flex; width: fit-content; max-width: 100%; overflow-x: auto; margin-bottom: 20px; }

main { padding-bottom: 64px; transition: opacity 0.15s; }
main.loading { opacity: 0.55; }

.section-title {
  font-size: 18px;
  margin: 36px 0 14px;
  letter-spacing: -0.01em;
}
.day-title { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.day-nav { display: inline-flex; align-items: center; gap: 4px; font-size: 15px; font-weight: 500; color: var(--ink-2); }
.day-nav button {
  width: 30px; height: 30px; border-radius: 50%;
  font-size: 20px; line-height: 1; color: var(--ink-2);
  background: var(--surface-2);
}
.day-nav button:hover { background: var(--border); }
.day-nav button:disabled { opacity: 0.35; cursor: default; }
#day-label { min-width: 150px; text-align: center; }
.hint { margin: -6px 0 14px; font-size: 13px; }

/* --- карточки --------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  min-width: 0;
}

.overview {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 2fr;
  gap: 16px;
}
@media (max-width: 900px) { .overview { grid-template-columns: 1fr; } }

.hero { display: flex; flex-direction: column; gap: 14px; }
.hero .label { font-size: 13px; color: var(--ink-2); }
.hero-value { display: flex; align-items: baseline; gap: 10px; }
.hero-value strong { font-size: 64px; line-height: 1; font-weight: 650; letter-spacing: -0.03em; }
.hero-value span { color: var(--muted); font-size: 18px; }
.meter { height: 8px; border-radius: 999px; background: var(--accent-wash); overflow: hidden; }
.meter > div { height: 100%; border-radius: 999px; }
.hero dl { margin: 4px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.hero dt { font-size: 12px; color: var(--muted); }
.hero dd { margin: 2px 0 0; font-weight: 600; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.status i {
  display: inline-grid; place-items: center;
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  font-style: normal; font-size: 11px; font-weight: 700; color: #fff;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
}
@media (max-width: 640px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 14px; }
  .tile .value { font-size: 24px; }
}
.tile { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.tile .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.tile .delta { font-size: 12px; color: var(--muted); }
.tile .delta b { font-weight: 600; }
.tile .delta .up-good, .tile .delta .down-good { color: var(--good-ink); }
.tile .delta .up-bad, .tile .delta .down-bad { color: var(--bad-ink); }
.spark { width: 100%; height: 34px; margin-top: 6px; display: block; overflow: visible; }

/* --- графики ---------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.wide { grid-column: 1 / -1; }

.chart-card header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin-bottom: 6px;
}
.chart-card h3 { font-size: 15px; }
.chart-card .sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.chart-card .toggle {
  font-size: 12px; color: var(--ink-2);
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2); flex: none;
}
.chart-card .toggle:hover { background: var(--border); }
.chart { width: 100%; height: 260px; }
.chart.short { height: 170px; }
.chart.tall { height: 300px; }
.empty {
  display: grid; place-items: center;
  height: 160px; color: var(--muted); font-size: 14px; text-align: center;
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 2px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .ln { width: 14px; height: 2px; border-radius: 2px; }

/* --- таблицы ---------------------------------------------------------- */

.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  position: sticky; top: 0;
  background: var(--surface);
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: 0; }
table.activities tbody tr { cursor: pointer; }
table.activities tbody tr:hover td { background: var(--surface-2); }
table.activities tbody tr[aria-selected="true"] td { background: var(--surface-2); }
table.activities tbody tr[aria-selected="true"] td:first-child { box-shadow: inset 3px 0 0 var(--s1); }
.type { display: inline-flex; align-items: center; gap: 8px; }
.type i { width: 8px; height: 8px; border-radius: 50%; background: var(--s1); }

.activity { margin-top: 16px; }
.activity-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 20px; margin-bottom: 14px; }
.activity-head h3 { font-size: 18px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; }
.facts div { display: flex; flex-direction: column; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-size: 18px; font-weight: 600; }

.zones { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.zone { display: grid; grid-template-columns: 104px 1fr 76px; align-items: center; gap: 10px; font-size: 13px; }
.zone .bar { height: 14px; background: var(--surface-2); border-radius: 0 4px 4px 0; }
.zone .bar div { height: 100%; border-radius: 0 4px 4px 0; background: var(--s1); }
.zone .t { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.zone .z { color: var(--ink-2); white-space: nowrap; }
.zone .z b { color: var(--ink); }

.error { padding: 40px 0; color: var(--bad-ink); }

/* --- оболочка: вход, меню, настройки ------------------------------------ */

[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--s1); }

.top-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-pick select, .field input {
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.user-pick select { padding: 6px 30px 6px 12px; font-size: 13px; font-weight: 600; border-radius: 999px; background-color: var(--surface-2); border-color: transparent; }

.menu { position: relative; }
.menu-button {
  padding: 6px 14px; border-radius: 999px; background: var(--surface-2);
  font-size: 13px; font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu-button::after { content: " ▾"; color: var(--muted); }
.menu-button:hover { background: var(--border); }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 200px; padding: 6px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
}
.menu-list a, .menu-list button {
  text-align: left; padding: 8px 12px; border-radius: 8px;
  color: var(--ink); text-decoration: none; font-size: 14px;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-2); }
.menu-list #logout { color: var(--bad-ink); border-top: 1px solid var(--grid); border-radius: 0 0 8px 8px; margin-top: 4px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(400px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 22px; }
.login-card form, .stack { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); }
.field input { padding: 10px 12px; font-size: 15px; }
.field input:focus { outline: 2px solid var(--s1); outline-offset: 0; border-color: transparent; }

button.primary, a.button {
  display: inline-flex; justify-content: center; align-items: center;
  padding: 10px 18px; border-radius: 10px;
  background: var(--s1); color: #fff; font-weight: 600; text-decoration: none;
}
button.primary:hover, a.button:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.6; cursor: progress; }
button.link { color: var(--ink-2); font-size: 13px; align-self: center; text-decoration: underline; }
.small-button {
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.small-button:hover { background: var(--border); }
.small-button.danger { background: var(--critical); color: #fff; }

.lead { margin: 0; color: var(--ink-2); font-size: 14px; }
.small { font-size: 12.5px; }
.form-error { margin: 0; color: var(--bad-ink); font-size: 13.5px; }

.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.qr { width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 4px; }
.qr svg { width: 100%; height: 100%; display: block; }
.qr-wrap details { font-size: 13px; color: var(--ink-2); text-align: center; }
code.secret {
  display: inline-block; margin-top: 6px; padding: 6px 10px; border-radius: 8px;
  background: var(--surface-2); font: 600 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em; word-break: break-all; color: var(--ink);
}
code.secret.big { font-size: 18px; }

.notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--s1);
  font-size: 14px;
}
.notice.error { border-left-color: var(--critical); }
.notice p { margin: 6px 0; }
.notice a.button { padding: 6px 14px; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  max-width: min(520px, calc(100% - 32px)); padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--page); font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast.error { background: var(--critical); color: #fff; }

.settings { display: flex; flex-direction: column; gap: 16px; padding-bottom: 64px; }
.settings-card { display: flex; flex-direction: column; gap: 16px; }
.settings-card > header h2 { font-size: 20px; }
.settings-card > header p { margin: 4px 0 0; font-size: 14px; }
.settings-card h3 { font-size: 15px; margin-top: 4px; }
.settings-card .stack { max-width: 420px; }
.back { font-size: 14px; text-decoration: none; color: var(--ink-2); width: fit-content; }
.back:hover { color: var(--ink); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.inline-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.inline-form .field { flex: 1 1 180px; }
.inline-form .form-error { flex-basis: 100%; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; padding-bottom: 10px; }
td.actions > div { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* --- разбор тренировки ------------------------------------------------- */

.review { margin-top: 16px; }
.review > header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 4px; }
.review h3 { font-size: 16px; }
.empty-review p { margin: 6px 0 0; font-size: 14px; }
.review-body { max-width: 78ch; font-size: 15px; line-height: 1.6; color: var(--ink); }
.review-body h1, .review-body h2 { font-size: 17px; margin: 22px 0 8px; }
.review-body h3 { font-size: 15px; margin: 18px 0 6px; }
.review-body > :first-child { margin-top: 8px; }
.review-body p { margin: 8px 0; }
.review-body ul, .review-body ol { margin: 8px 0; padding-left: 22px; }
.review-body li { margin: 4px 0; }
.review-body li::marker { color: var(--muted); }
.review-body strong { font-weight: 650; }
.review-body code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.review-body blockquote { margin: 10px 0; padding: 4px 14px; border-left: 3px solid var(--s1); color: var(--ink-2); }
.review-body table { border-collapse: collapse; font-size: 14px; margin: 10px 0; display: block; overflow-x: auto; }
.review-body th, .review-body td { padding: 6px 10px; border-bottom: 1px solid var(--grid); text-align: left; }
.review-body th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.review-body hr { border: 0; border-top: 1px solid var(--grid); margin: 18px 0; }
.review-body pre { white-space: pre-wrap; font: inherit; }
.badge {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; color: var(--s1); background: var(--accent-wash);
}
:root[data-theme="dark"] .badge { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge { color: #fff; } }
