/* App frames: client (mobile-first column + bottom tabs) and coach (rail + top bar). Plus chart/ring primitives. */
/* real use (no demo bar): nothing sits above the app, so the sticky rail / top bar offsets start at the very top */
body:not(.demo-mode) { --demobar-h: 0px; }

/* ---------- client frame ---------- */
.c-shell { max-width: var(--client-max); margin: 0 auto; min-height: calc(100dvh - var(--demobar-h)); position: relative; background: var(--color-paper); }
@media (min-width: 40rem) {
  body.client-mode { background: var(--color-paper-3); }
  .c-shell { border-inline: var(--rule); box-shadow: 0 0 0 1px var(--color-rule), 0 24px 60px var(--color-shadow); }
}
.c-main { padding: var(--space-lg) var(--space-lg) calc(var(--tabbar-h) + var(--space-2xl) + env(safe-area-inset-bottom)); outline: none; }
.c-shell--focus .c-main { padding-bottom: calc(var(--space-2xl) + env(safe-area-inset-bottom)); }
.c-tabs {
  position: fixed; z-index: var(--z-nav); bottom: 0; left: 0; right: 0; margin-inline: auto; max-width: var(--client-max);
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-paper-2); border-top: var(--rule);
}
.c-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem; text-decoration: none; color: var(--color-muted); font-size: var(--text-2xs); font-weight: 700; letter-spacing: 0.02em; position: relative; -webkit-tap-highlight-color: transparent; }
.c-tab:hover { color: var(--color-ink); }
.c-tab[aria-current="page"] { color: var(--color-ink); }
.c-tab[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--color-gold); }
.c-tab:focus-visible { outline-offset: -4px; }

/* side rail: desktop only (phone and tablet use the bottom tabs) */
.c-rail { display: none; }
@media (min-width: 40rem) and (max-width: 63.99rem) {
  .c-shell, .c-tabs { max-width: var(--client-max-tablet); }
}
@media (min-width: 64rem) {
  body.client-mode { background: var(--color-paper); }
  .c-shell { max-width: none; display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); border-inline: 0; box-shadow: none; background: var(--color-paper); }
  .c-tabs { display: none; }
  .c-main { width: 100%; max-width: var(--client-desk-max); padding: var(--space-2xl) var(--space-2xl) var(--space-5xl); }
  .c-rail { display: flex; flex-direction: column; gap: var(--space-lg); position: sticky; top: var(--demobar-h); height: calc(100dvh - var(--demobar-h)); padding: var(--space-xl) var(--space-md) var(--space-lg); overflow-y: auto; background: var(--color-paper-2); border-right: var(--rule); }
  .c-rail .k-nav__item { color: var(--color-ink-2); min-height: 2.75rem; }
  .c-rail .k-nav__item:hover { background: var(--color-paper-3); color: var(--color-ink); }
  .c-rail .k-nav__item[aria-current="page"] { background: var(--color-night); color: var(--color-night-text); }
  .c-rail .k-nav__item[aria-current="page"] .ic { color: var(--color-gold); }
  .c-rail .k-nav__item:focus-visible { outline-color: var(--color-focus); }
  /* a focused task (workout in progress) gets no rail: one calm centred column */
  .c-shell--focus { grid-template-columns: minmax(0, 1fr); }
  .c-shell--focus .c-main { max-width: var(--client-focus-max); margin-inline: auto; }
}
.c-rail__brand { display: flex; align-items: baseline; gap: var(--space-xs); padding-inline: var(--space-xs); }
.c-rail__brand .display { font-size: 2rem; letter-spacing: 0.08em; color: var(--color-ink); }
.c-rail__sub { font-size: var(--text-xs); font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: var(--color-muted); }
.c-rail__me { margin-top: auto; display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-sm); border-top: var(--rule); min-width: 0; }

/* layout helpers for client views: one column on the phone, two on a desktop */
.c-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-lg); align-items: start; }
.c-split > * { min-width: 0; }
.c-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-md); }
.c-narrow { max-width: var(--client-focus-max); }
@media (min-width: 48rem) {
  .c-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 64rem) {
  .c-split { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: var(--space-xl); }
  .c-split__aside { position: sticky; top: calc(var(--demobar-h) + var(--space-xl)); }
}

/* client page header (used by client views) */
.c-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-sm); margin-bottom: var(--space-lg); min-width: 0; }
.c-head__title { font-size: var(--text-2xl); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.c-head__sub { font-size: var(--text-sm); color: var(--color-muted); font-weight: 600; }
.c-back { display: inline-flex; align-items: center; gap: var(--space-2xs); margin: calc(var(--space-xs) * -1) 0 var(--space-sm) calc(var(--space-xs) * -1); padding: var(--space-xs); border-radius: var(--radius-sm); text-decoration: none; color: var(--color-muted); font-weight: 700; font-size: var(--text-sm); }
.c-back:hover { color: var(--color-ink); background: var(--color-paper-3); }

/* ---------- coach frame ---------- */
.k-shell { display: grid; grid-template-columns: minmax(0, 1fr); min-height: calc(100dvh - var(--demobar-h)); }
.k-rail { display: none; }
.k-main { min-width: 0; display: flex; flex-direction: column; }
.k-top { position: sticky; top: var(--demobar-h); z-index: var(--z-sticky); display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-xs) var(--space-md); background: var(--color-paper); border-bottom: var(--rule); min-height: 3.75rem; }
.k-top__brand { font-size: 1.6rem; letter-spacing: 0.08em; color: var(--color-ink); margin-right: auto; position: relative; }
/* sync state: a dot on the brand on phones / tablets (no room taken from the coach filter), before the search on desktop */
.k-top__brand .syncpill { position: absolute; top: 0.1rem; right: -0.5rem; padding: 0; }
.k-top__brand .syncpill span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.k-top__sync { display: none; }
.k-top__search { flex: 1 1 18rem; max-width: 26rem; display: none; position: relative; }
.k-top__filter { flex: 0 1 auto; min-width: 0; }
.k-top__filter .input { min-width: 11rem; max-width: 100%; }
@media (max-width: 22.5rem) { .k-top__filter .input { min-width: 9.5rem; } }   /* 320 px admin bar: the coach filter ran 7 px off screen */
.k-search__results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--color-paper-2); border: var(--rule); border-radius: var(--radius-md); box-shadow: 0 16px 40px var(--color-shadow-2); overflow: hidden; z-index: var(--z-nav); }
.k-view { padding: var(--space-xl) var(--space-md) var(--space-4xl); outline: none; min-width: 0; }
@media (min-width: 40rem) {
  .k-top__search { display: flex; }
  .k-view { padding-inline: var(--space-xl); }
}
@media (min-width: 64rem) {
  .k-shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .k-rail { display: flex; flex-direction: column; gap: var(--space-lg); position: sticky; top: var(--demobar-h); height: calc(100dvh - var(--demobar-h)); padding: var(--space-xl) var(--space-md) var(--space-lg); overflow-y: auto; border-right: 1px solid var(--color-night-rule); }
  .k-top__menu, .k-top__brand { display: none; }
  .k-top__sync { display: inline-flex; }
  .k-top { padding-inline: var(--space-2xl); }
  .k-top__search { margin-right: auto; }
  .k-view { padding: var(--space-2xl) var(--space-2xl) var(--space-5xl); max-width: 92rem; }
}
.k-rail__brand { display: flex; align-items: baseline; gap: var(--space-xs); padding-inline: var(--space-xs); }
.k-rail__brand .display { font-size: 2rem; letter-spacing: 0.08em; color: var(--color-gold); }
.k-rail__sub { font-size: var(--text-xs); font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: var(--color-night-muted); }
.k-nav { display: flex; flex-direction: column; gap: 2px; }
.k-nav__group { margin: var(--space-md) var(--space-sm) var(--space-2xs); font-size: var(--text-2xs); font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-night-muted); }
.k-nav__item { display: flex; align-items: center; gap: var(--space-sm); min-height: 2.6rem; padding: 0 var(--space-sm); border-radius: var(--radius-sm); text-decoration: none; color: var(--color-night-muted); font-weight: 700; font-size: var(--text-sm); white-space: nowrap; transition: background-color var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out); }
.k-nav__item:hover { background: var(--color-night-2); color: var(--color-night-text); }
.k-nav__item[aria-current="page"] { background: var(--color-night-3); color: var(--color-night-text); }
.k-nav__item[aria-current="page"] .ic { color: var(--color-gold); }
.k-nav__item:focus-visible { outline-color: var(--color-focus-night); }
.k-nav__badge { min-width: 1.4rem; height: 1.4rem; padding: 0 0.35rem; border-radius: var(--radius-pill); background: var(--color-gold); color: var(--color-night); font-size: var(--text-2xs); font-weight: 800; display: grid; place-items: center; }
.k-rail__me { margin-top: auto; display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-sm); border-top: 1px solid var(--color-night-rule); }
.k-rail__me .row__meta { color: var(--color-night-muted); }
/* nav inside the mobile sheet (paper background) */
.k-sheetnav .k-nav__item { color: var(--color-ink-2); min-height: 3rem; }
.k-sheetnav .k-nav__item:hover { background: var(--color-paper-3); color: var(--color-ink); }
.k-sheetnav .k-nav__item[aria-current="page"] { background: var(--color-night); color: var(--color-night-text); }
.k-sheetnav .k-nav__group { color: var(--color-muted); }

.page-pad { padding: var(--space-xl) 0; }

/* ---------- charts ---------- */
.chart__grid { stroke: var(--color-rule); stroke-width: 1; }
.chart__line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart__line--ink { stroke: var(--color-ink); }
.chart__line--gold { stroke: var(--color-gold-deep); }
.chart__line--good { stroke: var(--color-good); }
.chart__line--muted { stroke: var(--color-rule-strong); }
.chart__dot { stroke: var(--color-paper-2); stroke-width: 2.5; }
.chart__dot--ink { fill: var(--color-ink); }
.chart__dot--gold { fill: var(--color-gold-deep); }
.chart__dot--good { fill: var(--color-good); }
.chart__last { font-weight: 800 !important; fill: var(--color-ink) !important; font-size: 12px !important; }
/* charts draw in a 640-unit viewBox: on a phone the card is about half that wide, so the labels get twice the
   size in chart units to stay readable (about 10-12 px on screen) */
@media (max-width: 39.99rem) { .chart text { font-size: 20px; } .chart .chart__last { font-size: 21px !important; } }
.spark { display: block; }
.night .chart__line--ink { stroke: var(--color-night-text); }
.night .chart__grid { stroke: var(--color-night-rule); }

.ring { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring svg { position: absolute; inset: 0; }
.ring__track { stroke: var(--color-paper-4); }
.ring__track--night { stroke: var(--color-night-3); }
.ring__val { transition: stroke-dashoffset var(--dur-long) var(--ease-out); }
.ring__val--gold { stroke: var(--color-gold); }
.ring__val--ink { stroke: var(--color-ink); }
.ring__val--good { stroke: var(--color-good); }
.ring__label { position: relative; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.ring__num { font-family: var(--font-display); font-size: 1.7rem; font-variant-numeric: tabular-nums; }
.ring__sub { font-size: var(--text-2xs); font-weight: 700; color: var(--color-muted); margin-top: 0.15rem; letter-spacing: 0.04em; text-transform: uppercase; }
.night .ring__sub { color: var(--color-night-muted); }

.wbars { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2xs); align-items: end; height: 4.5rem; }
.wbars__col { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; height: 100%; justify-content: flex-end; font-size: var(--text-2xs); font-weight: 700; color: var(--color-muted); }
.wbars__bar { width: 100%; max-width: 1.75rem; height: calc(var(--p) * 100% - 1.2rem + 4px); min-height: 4px; border-radius: 4px; background: var(--color-ink); }

/* ---------- backend: start-up splash, sign-in, sync state, busy veil (19.11.2026) ---------- */
.splash {
  min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: var(--space-md);
  background: var(--color-paper); color: var(--color-ink);
}
.splash .display { font-size: var(--text-4xl); letter-spacing: 0.04em; }
.splash__bar, .busyveil__bar {
  display: block; width: 7rem; height: 3px; border-radius: var(--radius-pill); background: var(--color-rule);
  position: relative; overflow: hidden;
}
.splash__bar::after, .busyveil__bar::after {
  content: ''; position: absolute; inset: 0; width: 40%; border-radius: inherit; background: var(--color-gold);
  animation: koutsi-bar 1.1s var(--ease-in-out) infinite;
}
@keyframes koutsi-bar { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* busy veil: a thin progress line on top, clicks wait; the page underneath keeps its look (no flash) */
.busyveil { position: fixed; inset: 0; z-index: var(--z-toast); cursor: progress; background: transparent; }
.busyveil[hidden] { display: none; }
.busyveil .busyveil__bar { position: fixed; top: 0; left: 0; width: 100%; height: 3px; border-radius: 0; background: transparent; }

/* sign-in */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-lg) var(--space-md); background: var(--color-paper-2); }
.auth__card { width: min(100%, 26rem); padding: var(--space-xl) var(--space-lg); display: grid; gap: var(--space-md); }
.auth__brand { display: flex; align-items: baseline; gap: var(--space-xs); margin: 0; }
.auth__brand .display { font-size: var(--text-3xl); }
.auth__brand span:last-child { font-size: var(--text-sm); color: var(--color-muted); font-weight: 600; }
.auth__err { margin: 0; color: var(--color-terra-ink); }
.auth__err[hidden] { display: none; }
.auth__steps { margin: 0; padding-inline-start: 1.25rem; display: grid; gap: var(--space-2xs); font-size: var(--text-sm); }
.auth__qr { justify-self: center; width: 11rem; height: 11rem; padding: var(--space-xs); border-radius: var(--radius-md); background: var(--color-night-text); }   /* scannable on the dark theme too */
.auth__keybox { display: grid; gap: var(--space-3xs); justify-items: center; text-align: center; }
.auth__key { font-family: ui-monospace, monospace; font-size: var(--text-sm); letter-spacing: 0.04em; overflow-wrap: anywhere; user-select: all; }
.auth__code { letter-spacing: 0.3em; font-size: var(--text-lg); text-align: center; }

/* client offline note (real use): only while the device is offline */
.c-offline {
  position: sticky; top: 0; z-index: var(--z-nav);
  margin: 0; padding: var(--space-xs) var(--space-md);
  background: var(--color-terra-soft); color: var(--color-terra-ink);
  font-size: var(--text-xs); font-weight: 600; text-align: center; text-wrap: balance;
}
.c-offline[hidden] { display: none; }
.c-offline svg { display: inline-block; vertical-align: -0.2em; margin-right: var(--space-2xs); }

/* sync state pill */
.syncpill {
  display: inline-flex; align-items: center; gap: var(--space-2xs); white-space: nowrap; flex: none;
  font-size: var(--text-xs); font-weight: 600; color: var(--color-muted); padding: 0 var(--space-xs);
}
.syncpill i { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--color-good); flex: none; }
.syncpill--saving i { background: var(--color-gold); }
.syncpill--offline i { background: var(--color-terra); }
.syncpill--offline { color: var(--color-terra-ink); }
.demobar .syncpill { color: var(--color-night-muted); }
.demobar .syncpill--offline { color: var(--color-gold-soft); }
@media (max-width: 40rem) { .syncpill span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); } }

.k-rail__out { margin-left: auto; color: var(--color-night-muted); }
.k-rail__out:hover { color: var(--color-night-text); }
