/* ============ theme tokens ============
   Light is the default; [data-theme="dark"] (set before first paint by the inline script in index.html)
   swaps every surface/text/line token. Components only use tokens, never raw colors. */
:root {
  --bg: #ffffff;
  --card: #f5f5f7;
  --card-2: #ececf0;
  --surface: #ffffff;      /* stand-alone cards on the page background (CRM, trainee cards, tables) */
  --surface-2: #ffffff;    /* rows nested inside a --card block */
  --sheet: #ffffff;        /* modals, popovers */
  --input-bg: #ffffff;
  --seg-on: #ffffff;
  --glass: rgba(255, 255, 255, 0.86);
  --overlay: rgba(0, 0, 0, 0.28);
  --ink: #1d1d1f;          /* dark pills: active chip, toast, save bar */
  --on-ink: #ffffff;
  --on-ink-soft: rgba(255, 255, 255, 0.14);
  --ring-bg: #ffffff;      /* outline around avatars / medals / status dots */
  --row-hover: #fafafc;
  --track: #e2e2e7;
  --line: #e5e5ea;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #a1a1a6;
  --gray-3: #c7c7cc;
  --accent: #0a84ff;
  --accent-soft: #e8f2ff;
  --focus-ring: rgba(10, 132, 255, 0.15);
  --focus-ring-strong: rgba(10, 132, 255, 0.45);
  --green: #30b158;
  --green-soft: #e9f7ee;
  --green-ink: #1f8a43;
  --green-part: #c9ecd4;
  --orange: #ff9500;
  --orange-soft: #fff4e5;
  --orange-ink: #b86200;
  --red: #ff3b30;
  --red-soft: #ffeceb;
  --red-ink: #d70015;
  --violet: #5e5ce6;
  --violet-mid: #b9b8f5;
  --violet-soft: #f0eefc;
  --violet-ink: #5e4bd8;
  --protein-soft: #ffeef0;
  --protein-ink: #d1344a;
  --carb-soft: #fff4e0;
  --fat-soft: #fff9d9;
  --fat-ink: #8a6e00;
  --kcal: #ff6b3d;
  --water: #0aa5ff;
  --wa: #25d366;
  --gold: #ff9500;
  --silver: #8e8e93;
  --bronze: #e8590c;
  --podium-bg: radial-gradient(120% 90% at 50% 0%, #fff6d6 0%, #fde8f1 45%, #e6efff 100%);
  --pop-shadow: 0 12px 40px rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.05);
  --chart-grid: #ececf0;
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 9px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro', 'Heebo', 'Segoe UI', Arial, sans-serif;
  /* safe areas (notch / home indicator) — non-zero only with viewport-fit=cover on iPhone */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --sheet: #1c1c1e;
  --input-bg: #1c1c1e;
  --seg-on: #636366;
  --glass: rgba(18, 18, 20, 0.8);
  --overlay: rgba(0, 0, 0, 0.6);
  --ink: #f5f5f7;
  --on-ink: #000000;
  --on-ink-soft: rgba(0, 0, 0, 0.08);
  --ring-bg: #1c1c1e;
  --row-hover: #2c2c2e;
  --track: #3a3a3c;
  --line: #38383a;
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #6e6e73;
  --gray-3: #636366;
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.2);
  --focus-ring: rgba(10, 132, 255, 0.35);
  --focus-ring-strong: rgba(64, 156, 255, 0.7);
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.16);
  --green-ink: #30d158;
  --green-part: #1f5a30;
  --orange: #ff9f0a;
  --orange-soft: rgba(255, 159, 10, 0.16);
  --orange-ink: #ffb340;
  --red: #ff453a;
  --red-soft: rgba(255, 69, 58, 0.18);
  --red-ink: #ff6961;
  --violet: #7d7aff;
  --violet-mid: #5856b8;
  --violet-soft: rgba(125, 122, 255, 0.2);
  --violet-ink: #b4b2ff;
  --protein-soft: rgba(255, 55, 95, 0.18);
  --protein-ink: #ff6482;
  --carb-soft: rgba(255, 159, 10, 0.16);
  --fat-soft: rgba(255, 214, 10, 0.15);
  --fat-ink: #ffd60a;
  --kcal: #ff7a4d;
  --water: #40c8ff;
  --gold: #ffb340;
  --silver: #aeaeb2;
  --bronze: #ff8a4c;
  --podium-bg: radial-gradient(120% 90% at 50% 0%, #3a2e10 0%, #2a1622 48%, #101a30 100%);
  --pop-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08);
  --chart-grid: #2c2c2e;
  --shadow: none;
  color-scheme: dark;
}
/* Elevated containers in dark mode: anything that used --card inside them steps one level up,
   so nested tiles stay distinguishable (iOS "grouped" elevation). */
:root[data-theme="dark"] :is(.sheet, .crm-card, .tc, .qs-pop, .tt-wrap, .xc) {
  --card: #2c2c2e;
  --card-2: #3a3a3c;
  --surface-2: #3a3a3c;
  --input-bg: #2c2c2e;
  --track: #48484a;
  --row-hover: #2c2c2e;
  --ring-bg: #2c2c2e;
  --seg-on: #737378;
}
:root[data-theme="dark"] .tt-wrap { --ring-bg: #1c1c1e; }
:root[data-theme="dark"] :is(.block, .session, .t-side, .lb-list, .exc) { --track: #48484a; --ring-bg: #1c1c1e; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 18px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; display: block; object-fit: cover; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 999px; color: var(--text-2); font-weight: 500; font-size: 14px; white-space: nowrap; }
.nav a:hover { color: var(--text); }
.nav a.active { background: var(--card); color: var(--text); }
.logout { background: none; border: 0; color: var(--text-2); font-size: 14px; cursor: pointer; padding: 6px 4px; white-space: nowrap; }
.logout:hover { color: var(--red); }

main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 120px; }

/* ---------- headings ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-size: 30px; line-height: 1.15; letter-spacing: -0.02em; margin: 0; font-weight: 700; }
h2 { font-size: 20px; letter-spacing: -0.01em; margin: 0 0 10px; font-weight: 650; }
h3 { font-size: 16px; margin: 0; font-weight: 600; }
.sub { color: var(--text-2); font-size: 14px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 9px 18px; cursor: pointer;
  font-weight: 600; font-size: 15px; background: var(--accent); color: #fff;
  transition: transform 0.16s var(--ease), opacity 0.16s var(--ease);
  white-space: nowrap; text-decoration: none; -webkit-user-select: none; user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: var(--card); color: var(--text); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 999px; border: 0; background: transparent; color: var(--text-2);
  display: inline-grid; place-items: center; cursor: pointer; font-size: 15px; flex: none;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn.del:hover { background: var(--red-soft); color: var(--red); }
.icon-btn:disabled { opacity: 0.25; cursor: default; background: transparent; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; font-weight: 500; font-size: 14px; }

/* ---------- cards / lists ---------- */
.card { background: var(--card); border-radius: var(--r-lg); padding: 16px; }
.card + .card { margin-top: 12px; }
.stack > * + * { margin-top: 12px; }
.list { background: var(--card); border-radius: var(--r-lg); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px; position: relative;
  color: inherit; cursor: pointer;
}
.row + .row::before { content: ''; position: absolute; top: 0; left: 16px; right: 16px; height: 1px; background: var(--line); }
.row:hover { background: var(--card-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .chev { color: var(--text-3); font-size: 18px; }
.avatar {
  --hue: 211;
  width: 40px; height: 40px; border-radius: 999px; background: hsl(var(--hue) 85% 94%); color: hsl(var(--hue) 55% 38%);
  display: grid; place-items: center; font-weight: 700; flex: none; position: relative; font-size: 15px; letter-spacing: -0.02em;
}
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--card-2); color: var(--text-2); white-space: nowrap; }
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.orange { background: var(--orange-soft); color: var(--orange-ink); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { text-align: center; color: var(--text-2); padding: 40px 16px; }
.empty .big { font-size: 34px; margin-bottom: 6px; }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--input-bg); border-radius: var(--r-sm);
  padding: 9px 11px; font-size: 15px; outline: none;
  min-height: 40px;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.5; }
.input.tiny { width: 68px; padding: 6px 8px; min-height: 34px; text-align: center; font-size: 14px; }
.input.ltr { direction: ltr; text-align: left; }
.fields { display: flex; flex-wrap: wrap; gap: 12px; }
.fields > .field { flex: 1 1 200px; }
.fields > .field.narrow { flex: 1 1 120px; }
.form-error { color: var(--red); font-size: 14px; min-height: 20px; margin-top: 8px; }

.search { position: relative; }
.search .input { padding-inline-start: 34px; background: var(--card); border-color: transparent; }
.search .input:focus { background: var(--input-bg); }
.search::before { content: '⌕'; position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-52%); color: var(--text-3); font-size: 17px; pointer-events: none; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 220px; }

/* chips (filters) */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 0; border-radius: 999px; padding: 6px 12px; background: var(--card); color: var(--text-2); cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap; transition: transform 0.16s var(--ease); }
.chip:active { transform: scale(0.97); }
.chip.on { background: var(--ink); color: var(--on-ink); }

/* segmented control */
.segmented { display: inline-flex; background: var(--card); border-radius: 11px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }
.segmented a, .segmented button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font-size: 14px; font-weight: 500;
  color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.segmented .on { background: var(--seg-on); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 360px; text-align: center; }
.login .brand-mark { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 16px; }
.login h1 { margin-bottom: 4px; }
.login form { margin-top: 26px; text-align: start; }
.login .field + .field { margin-top: 12px; }
.login .btn { margin-top: 18px; }

/* ---------- trainee header ---------- */
.t-head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.t-head .avatar { width: 54px; height: 54px; font-size: 20px; }
.t-head .grow { flex: 1; min-width: 180px; }
.code-badge { font-variant-numeric: tabular-nums; letter-spacing: 0.12em; font-weight: 700; direction: ltr; unicode-bidi: isolate; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-size: 15px; margin-bottom: 10px; }
.tabs-bar { margin-bottom: 18px; }

/* ---------- plan editors ---------- */
.block { background: var(--card); border-radius: var(--r-lg); padding: 6px 0 10px; }
.block + .block { margin-top: 14px; }
.block-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 12px; }
.block-head .name-input {
  flex: 1; min-width: 0; border: 0; background: transparent; font-size: 18px; font-weight: 650; padding: 6px 6px;
  border-radius: 8px; outline: none; letter-spacing: -0.01em;
}
.block-head .name-input:focus { background: var(--input-bg); box-shadow: 0 0 0 3px var(--focus-ring); }
.order-num { width: 26px; height: 26px; border-radius: 999px; background: var(--ink); color: var(--on-ink); font-size: 13px; font-weight: 700; display: grid; place-items: center; flex: none; }
.block-foot { padding: 6px 16px 2px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.ex-row { background: var(--surface-2); border-radius: var(--r-md); margin: 8px 12px 0; padding: 12px; }
.ex-row-top { display: flex; align-items: flex-start; gap: 8px; }
.ex-row-top .grow { flex: 1; min-width: 0; }
.ex-name { font-weight: 600; }
.ex-meta { color: var(--text-2); font-size: 13px; }
.ex-params { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; align-items: flex-end; }
.param { display: flex; flex-direction: column; gap: 4px; }
.param > span { font-size: 12px; color: var(--text-2); font-weight: 500; }
.param .pair { display: flex; align-items: center; gap: 4px; }
.param .pair .faint { font-size: 13px; }
.ex-note { margin-top: 10px; }
.ex-note .input { min-height: 36px; padding: 7px 10px; font-size: 14px; background: var(--card); border-color: transparent; }
.ex-note .input:focus { background: var(--input-bg); }
.row-actions { display: flex; gap: 2px; flex: none; }

/* meal items */
.item-row { background: var(--surface-2); border-radius: var(--r-md); margin: 8px 12px 0; padding: 12px; }
.item-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.food-btn {
  flex: 1 1 180px; min-width: 0; text-align: start; border: 1px solid var(--line); background: var(--input-bg); border-radius: var(--r-sm);
  padding: 8px 11px; cursor: pointer; min-height: 40px; display: flex; flex-direction: column; justify-content: center;
}
.food-btn:hover { border-color: var(--accent); }
.food-btn .fn { font-weight: 600; font-size: 15px; }
.food-btn .fm { font-size: 12px; color: var(--text-2); }
.amount { display: flex; gap: 4px; align-items: center; }
.amount select.input { width: auto; min-height: 34px; padding: 6px 8px; font-size: 14px; }
.group-sel { width: auto !important; min-height: 34px !important; padding: 6px 8px !important; font-size: 14px !important; }
.macro-line { font-size: 12.5px; color: var(--text-2); margin-top: 8px; display: flex; gap: 10px; flex-wrap: wrap; }
.macro-line b { color: var(--text); font-weight: 600; }
.alts { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.alts-title { font-size: 12px; color: var(--text-2); font-weight: 600; margin-bottom: 6px; }
.alt { display: flex; align-items: center; gap: 8px; padding: 6px 0; flex-wrap: wrap; }
.alt .alt-name { flex: 1 1 140px; min-width: 0; font-size: 14px; }
.alt .alt-kcal { font-size: 12px; color: var(--text-2); min-width: 64px; }
.swap-glyph { color: var(--accent); font-weight: 700; }

.meal-total { font-size: 13px; color: var(--text-2); }
.meal-total b { color: var(--text); }

.day-bar {
  position: sticky; top: 57px; z-index: 10; background: var(--glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  padding: 10px 0 12px; margin-bottom: 8px; border-bottom: 1px solid var(--line);
}
.macros { display: flex; gap: 14px; flex-wrap: wrap; }
.macro { flex: 1 1 110px; min-width: 0; }
.macro .m-top { display: flex; justify-content: space-between; font-size: 13px; gap: 6px; }
.macro .m-top .lbl { color: var(--text-2); font-weight: 500; }
.macro .m-top .val { font-weight: 600; }
.bar { height: 6px; border-radius: 999px; background: var(--card-2); overflow: hidden; margin-top: 5px; }
/* Fill is scaled, not resized: transform animates on the compositor. RTL, so it grows from the right. */
.bar > i { display: block; width: 100%; height: 100%; border-radius: 999px; background: var(--accent); transform-origin: right center; transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1); }
.bar.ok > i { background: var(--green); }
.bar.over > i { background: var(--orange); }

/* save bar */
.savebar {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, calc(100% + 40px)); visibility: hidden;
  background: var(--ink); color: var(--on-ink); border-radius: 999px; padding: 8px 8px 8px 8px;
  display: flex; align-items: center; gap: 12px; z-index: 30; transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1), visibility 0s linear 0.3s;
  max-width: calc(100% - 32px);
}
.savebar.show { transform: translate(-50%, 0); visibility: visible; transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1), visibility 0s; }
.savebar .msg { padding-inline-start: 10px; font-size: 14px; white-space: nowrap; }
.savebar .btn.plain { background: var(--on-ink-soft); color: var(--on-ink); }

/* ---------- progress ---------- */
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stat { flex: 1 1 140px; background: var(--card); border-radius: var(--r-lg); padding: 14px 16px; }
.stat .k { font-size: 13px; color: var(--text-2); }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat .v small { font-size: 14px; color: var(--text-2); font-weight: 500; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--font); font-size: 12px; fill: var(--text-2); }
.section { margin-top: 26px; }
.session { background: var(--card); border-radius: var(--r-lg); padding: 14px 16px; }
.session + .session { margin-top: 10px; }
.session-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; cursor: pointer; }
.session-body { margin-top: 10px; display: none; }
.session.open .session-body { display: block; }
.set-line { display: flex; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; align-items: baseline; flex-wrap: wrap; }
.set-line .n { flex: 1 1 160px; min-width: 0; }
.set-chips { display: flex; gap: 5px; flex-wrap: wrap; direction: ltr; }
.set-chip { background: var(--surface-2); border-radius: 7px; padding: 2px 7px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.day-row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; position: relative; flex-wrap: wrap; }
.day-row + .day-row::before { content: ''; position: absolute; top: 0; left: 16px; right: 16px; height: 1px; background: var(--line); }
.day-row .d { width: 92px; font-weight: 600; font-size: 14px; }
.day-row .bars { flex: 1 1 200px; }
.ai-card { background: var(--orange-soft); border-radius: var(--r-lg); padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; }
.ai-card + .ai-card { margin-top: 10px; }
.ai-card img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; flex: none; background: #fff; }
.ai-card .grow { flex: 1; min-width: 0; }
.ai-tag { color: var(--orange-ink); font-size: 12px; font-weight: 700; }

/* ---------- modal / sheet ---------- */
.overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade 0.2s var(--ease);
}
.sheet {
  background: var(--sheet); border-radius: 20px; width: 100%; max-width: 520px; max-height: min(86vh, 760px);
  display: flex; flex-direction: column; overflow: hidden;
  animation: pop 0.26s var(--ease);
}
.sheet.wide { max-width: 640px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 10px; }
.sheet-head h3 { font-size: 17px; }
.sheet-body { padding: 16px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.sheet-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-start; flex-wrap: wrap; }
.pick-list { margin-top: 10px; }
.pick { display: flex; gap: 10px; align-items: center; padding: 11px 6px; border-radius: 10px; cursor: pointer; }
.pick:hover { background: var(--card); }
.pick + .pick { border-top: 1px solid var(--line); }
.pick .grow { flex: 1; min-width: 0; }
.pick .plus { color: var(--accent); font-size: 20px; font-weight: 400; }
.code-big { font-size: 40px; font-weight: 800; letter-spacing: 0.2em; text-align: center; padding: 18px 0 6px; font-variant-numeric: tabular-nums; direction: ltr; }

.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--on-ink); padding: 9px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
  animation: drop 0.26s var(--ease); max-width: calc(100% - 32px);
}
.toast.err { background: var(--red); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(8px); } }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -8px); } }

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

/* ---------- phone ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar-inner { padding: 8px 16px; flex-wrap: wrap; gap: 6px 12px; }
  .brand { order: 1; flex: 1; }
  .logout { order: 2; }
  .nav { order: 3; flex-basis: 100%; display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 6px 0 4px; }
  .nav a { grid-column: span 2; display: grid; place-items: center; min-height: 46px; padding: 8px 6px; border-radius: 14px;
    background: var(--card); color: var(--text); font-size: 15px; font-weight: 600; text-align: center; white-space: normal; line-height: 1.15;
    transition: transform 0.16s var(--ease); }
  .nav a:last-child:nth-child(3n+1) { grid-column: span 6; }
  .nav a:nth-last-child(2):nth-child(3n+1), .nav a:last-child:nth-child(3n+2) { grid-column: span 3; }
  .nav a:active { transform: scale(0.97); }
  .nav a.active { background: var(--accent); color: #fff; }
  main { padding: 18px 16px 120px; }
  h1 { font-size: 26px; }
  .block-head { padding: 6px 8px; }
  .ex-row, .item-row { margin: 8px 8px 0; padding: 11px; }
  .input.tiny { width: 60px; }
  .overlay { align-items: flex-end; padding: 0; }
  .sheet { border-radius: 20px 20px 0 0; max-height: 92vh; max-height: 92dvh; max-width: none; animation: slideup 0.32s var(--ease); }
  .sheet-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .sheet-foot .btn { flex: 1; }
  .day-row .d { width: auto; flex-basis: 100%; }
  .block-head { flex-wrap: wrap; }
  .block-head .name-input { flex: 1 1 calc(100% - 40px); }
  .block-head .input.tiny[type=time] { margin-inline-start: 34px; }
  .block-head .row-actions { margin-inline-start: auto; }
  .macro { flex: 1 1 40%; }
  .alt .alt-name { flex: 1 1 calc(100% - 30px); }
  .alt .alt-kcal { flex: 1; }
  .savebar { bottom: max(14px, env(safe-area-inset-bottom)); }
}
@keyframes slideup { from { transform: translateY(40%); opacity: 0.4; } }

/* ---------- food database: search, sources, smart swaps ---------- */
.f-thumb { width: 36px; height: 36px; border-radius: 9px; object-fit: contain; background: var(--card-2); border: 1px solid var(--line); flex: none; }
.f-thumb.ph { display: grid; place-items: center; font-size: 15px; font-weight: 700; color: var(--text-2); background: var(--card-2); border-color: transparent; }
.f-thumb.ph.protein { background: var(--protein-soft); color: var(--protein-ink); }
.f-thumb.ph.carb { background: var(--carb-soft); color: var(--orange-ink); }
.f-thumb.ph.fat { background: var(--fat-soft); color: var(--fat-ink); }
.f-thumb.ph.veg { background: var(--green-soft); color: var(--green-ink); }
.src { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; flex: none; background: var(--card-2); color: var(--text-2); }
.src.coach { background: var(--accent-soft); color: var(--accent); }
.src.tzameret { background: var(--green-soft); color: var(--green-ink); }
.src.off { background: var(--orange-soft); color: var(--orange-ink); }
.pick.added { opacity: 0.55; cursor: default; }
.pick.added .plus { color: var(--green); }

.swap-search { margin-top: 8px; }
.swap-input { display: flex; gap: 8px; align-items: center; }
.swap-input .search { flex: 1; min-width: 0; }
.swap-input .input { min-height: 38px; font-size: 14px; }
.chip.small-chip { padding: 5px 10px; font-size: 12px; flex: none; }
.swap-results { margin-top: 6px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sheet); max-height: 330px; overflow-y: auto; padding: 2px 6px; overscroll-behavior: contain; }
.swap-results .pick { padding: 8px 4px; }
.swap-results .pick .plus { font-size: 18px; }

.alts-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.alts-head .alts-title { margin-bottom: 4px; }
.link-btn.small { font-size: 13px; padding: 0; flex: none; }
.alt { display: block; padding: 6px 0; }
.alt + .alt { border-top: 1px dashed var(--line); }
.alt-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alt .alt-name { flex: 1 1 160px; min-width: 0; font-size: 14px; }
.alt-macros { margin-top: 4px; padding-inline-start: 22px; }
.delta { font-weight: 600; padding: 0 7px; border-radius: 999px; }
.delta.ok { background: var(--green-soft); color: var(--green-ink); }
.delta.warn { background: var(--orange-soft); color: var(--orange-ink); }
.delta.bad { background: var(--red-soft); color: var(--red-ink); }
.list-chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.list-chip { background: var(--card); color: var(--text); padding: 5px 11px; font-size: 13px; }
.list-chip.match { background: var(--accent-soft); color: var(--accent); }
.list-chip:hover { filter: brightness(0.97); }

/* exchange lists page */
.list-block .block-head .name-input { flex: 1; }
.list-body { padding: 4px 14px 6px; }
.food-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.food-chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; background: var(--surface-2); border-radius: 999px; padding: 4px 6px 4px 4px; padding-inline-start: 12px; font-size: 13.5px; }
.food-chip .x { border: 0; background: none; color: var(--text-3); cursor: pointer; width: 22px; height: 22px; border-radius: 999px; flex: none; font-size: 12px; }
.food-chip .x:hover { background: var(--red-soft); color: var(--red); }

.food-info-head { display: flex; gap: 12px; align-items: center; }
.food-info-head .f-thumb { width: 64px; height: 64px; border-radius: 14px; font-size: 26px; }
.stat-row.compact { margin-bottom: 0; }
.stat-row.compact .stat { flex: 1 1 100px; padding: 10px 12px; }
.stat-row.compact .stat .v { font-size: 20px; }

.site-foot { max-width: 1080px; margin: 0 auto; padding: 18px 20px 110px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-2); line-height: 1.6; }
.site-foot a { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
main { padding-bottom: 32px; }

@media (max-width: 640px) {
  .alt .alt-name { flex: 1 1 calc(100% - 30px); }
  .alt-macros { padding-inline-start: 0; }
  .swap-results { max-height: 300px; }
  .src { font-size: 10px; padding: 1px 6px; }
  .site-foot { padding: 16px 16px 110px; }
}

/* ---------- exercise library (grouped by muscle) ---------- */
.chip .cnt { margin-inline-start: 6px; font-size: 11.5px; font-weight: 600; opacity: 0.6; font-variant-numeric: tabular-nums; }
.chip:disabled { opacity: 0.4; cursor: default; }
.chip { flex: none; }
.ex-filter {
  position: sticky; top: 57px; z-index: 10; margin: 0 -20px 6px; padding: 10px 20px 10px;
  background: var(--glass); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.ex-filter .chips { margin-top: 10px; flex-wrap: wrap; }
.ex-group { padding-top: 18px; scroll-margin-top: 160px; }
.ex-group-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ex-group-head h2 { margin: 0; }
.exc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.exc { background: var(--card); border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.exc-media { aspect-ratio: 16 / 9; background: var(--card); position: relative; overflow: hidden; }
.exc-media video, .exc-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.exc-play { all: unset; cursor: pointer; display: block; width: 100%; height: 100%; position: relative; }
.exc-play:focus-visible { outline: 3px solid var(--focus-ring-strong); outline-offset: -3px; }
.play-glyph {
  position: absolute; inset: 0; margin: auto; width: 46px; height: 46px; border-radius: 999px;
  background: rgba(29, 29, 31, 0.72); color: #fff; display: grid; place-items: center; font-size: 15px; padding-inline-start: 3px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); transition: transform 0.2s var(--ease);
}
.exc-play:hover .play-glyph { transform: scale(1.06); }
.exc-body { padding: 12px 14px 14px; flex: 1; }
.exc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.exc-name { font-size: 15.5px; line-height: 1.3; min-width: 0; overflow-wrap: anywhere; }
.exc-cues { margin: 10px 0 0; padding-inline-start: 18px; font-size: 13px; color: var(--text-2); line-height: 1.5; }
.exc-cues li + li { margin-top: 3px; }
.exc-cues li::marker { color: var(--text-3); font-variant-numeric: tabular-nums; }

.ex-thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--card-2); flex: none; }
.ex-thumb.sm { width: 40px; height: 40px; }
.ex-thumb.ph { display: grid; place-items: center; font-weight: 700; font-size: 15px; color: var(--text-2); }
.ex-pick-top { position: sticky; top: -16px; z-index: 2; background: var(--sheet); margin: -16px -18px 0; padding: 16px 18px 10px; border-bottom: 1px solid var(--line); }
.ex-pick-top .chips { margin-top: 10px; }
.ex-pick-group + .ex-pick-group { margin-top: 8px; }
.ex-pick-head { position: sticky; top: var(--pick-top, 96px); z-index: 1; background: var(--sheet); font-size: 13px; font-weight: 700; color: var(--text); padding: 10px 6px 6px; }

.exc-flag { margin-top: 8px; }
@media (max-width: 640px) {
  .ex-filter .chips { flex-wrap: nowrap; }
  .ex-filter { top: 92px; margin: 0 -16px 6px; padding: 10px 16px; }
  .exc-grid { grid-template-columns: 1fr; }
}

/* =====================================================================
   v2 — CRM dashboard, trainee switcher, leaderboard, exercise library
   Motion: transform/opacity only, ease-out var(--ease), no bounce.
   ===================================================================== */
main.wide, .topbar-inner.wide, .site-foot.wide { max-width: 1320px; }
.brand { color: var(--text); }
.coach-chip {
  display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap;
  background: none; border: 0; padding: 3px 3px 3px 10px; border-radius: 999px; cursor: pointer; transition: background-color 0.15s ease;
}
.coach-chip:hover { background: var(--card-2); }
.coach-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.coach-chip .avatar.xs { width: 30px; height: 30px; font-size: 12px; }
.avatar.has-photo { background: var(--card-2); color: transparent; }
.avatar > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06); }
.avatar.xl { width: 112px; height: 112px; font-size: 38px; }
/* coach profile sheet */
.profile { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 4px 0 2px; }
.pf-photo .avatar.xl { box-shadow: 0 0 0 4px var(--ring-bg, var(--card)), 0 8px 24px rgba(0, 0, 0, 0.14); }
.pf-name { margin-top: 14px; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.pf-email { margin-top: 2px; font-size: 13px; color: var(--text-2); }
.pf-section { align-self: stretch; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); text-align: start; }
.pf-label { font-weight: 600; font-size: 15px; }
.pf-hint { margin: 4px 0 14px; font-size: 13px; color: var(--text-2); line-height: 1.5; }
.pf-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pf-status { margin-top: 10px; font-size: 13px; color: var(--text-2); min-height: 1em; }
.pf-status:empty { display: none; }
.avatar.xs { width: 26px; height: 26px; font-size: 11px; }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 58px; height: 58px; font-size: 21px; }
.avatar .dot { position: absolute; bottom: -1px; inset-inline-end: -1px; width: 11px; height: 11px; border-radius: 999px; border: 2px solid var(--ring-bg); background: var(--text-3); }
.avatar.lg .dot { width: 15px; height: 15px; border-width: 3px; }
.avatar .dot.green { background: var(--green); }
.avatar .dot.orange { background: var(--orange); }
.avatar .dot.red { background: var(--red); }
.avatar .dot.paused { background: var(--gray-3); }
.pill.red { background: var(--red-soft); color: var(--red-ink); }
.tag { display: inline-flex; align-items: center; gap: 1px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--violet-soft); color: var(--violet-ink); white-space: nowrap; }
.eyebrow { font-size: 13px; color: var(--text-2); font-weight: 500; margin-bottom: 2px; }
.plain-link { color: inherit; }
.as-btn { border: 0; background: var(--card); border-radius: 7px; padding: 1px 7px; cursor: pointer; font: inherit; font-weight: 700; color: var(--text); transition: transform 0.16s var(--ease); }
.as-btn:active { transform: scale(0.97); }

/* WhatsApp buttons */
.btn.wa { background: var(--wa); color: #fff; }
.btn.wa .wa-ic { display: inline-grid; }
.btn.wa.icon-only { width: 34px; height: 34px; padding: 0; flex: none; }
.btn.wa.big { padding: 12px 20px; font-size: 16px; }

/* ---------- login / sign-up ---------- */
.auth-switch { margin-top: 22px; width: 100%; display: flex; }
.auth-switch a { flex: 1; text-align: center; }
.login form { margin-top: 18px; }
.login .field .hint { display: block; font-size: 12px; color: var(--text-3); margin-top: 5px; }
.login .field .hint.ok { color: var(--green); }
.auth-alt { text-align: center; margin: 14px 0 0; }
label.field > span em { font-style: normal; }

/* ---------- dashboard ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { text-align: start; border: 0; font: inherit; color: inherit; background: var(--card); border-radius: var(--r-lg); padding: 14px 16px; min-width: 0; transition: transform 0.16s var(--ease); }
button.kpi { cursor: pointer; }
button.kpi:active { transform: scale(0.97); }
.kpi .k { font-size: 13px; color: var(--text-2); font-weight: 500; }
.kpi .v { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin: 2px 0; }
.kpi .v small { font-size: 15px; color: var(--text-2); font-weight: 500; }
.kpi .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi.warn { background: var(--orange-soft); }
.kpi.warn .v { color: var(--orange-ink); }
.kpi.good .v { color: var(--green); }
.dash-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.dash-toolbar .search { flex: 1 1 260px; }
.dash-toolbar .sort { display: flex; align-items: center; gap: 6px; }
.dash-toolbar .sort select { width: auto; min-height: 38px; padding: 6px 10px; }
.view-toggle button { padding: 6px 12px; }
.dash-chips { margin-bottom: 8px; flex-wrap: wrap; }
.chip.warn:not(.on) { background: var(--orange-soft); color: var(--orange-ink); }
.chip.tag-chip:not(.on) { background: var(--violet-soft); color: var(--violet-ink); }
.chip-sep { width: 1px; background: var(--line); margin: 4px 2px; flex: none; }
.dash-count { margin: 4px 0 12px; }

.tc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.tc {
  display: flex; flex-direction: column; gap: 12px; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px;
  box-shadow: var(--shadow); transition: transform 0.2s var(--ease), opacity 0.2s var(--ease); min-width: 0; animation: rise 0.36s var(--ease) both;
}
.tc:hover { transform: translateY(-2px); }
.tc:active { transform: scale(0.97); }
.tc.paused { opacity: 0.72; }
.tc-top { display: flex; gap: 12px; align-items: center; }
.tc-top .grow { flex: 1; min-width: 0; }
.tc-name { font-weight: 650; font-size: 16.5px; letter-spacing: -0.01em; }
.tc-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: -4px; }
.tc-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tm { background: var(--card); border-radius: 12px; padding: 9px 11px; min-width: 0; }
.tm .k { font-size: 12px; color: var(--text-2); font-weight: 500; }
.tm .v { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; }
.tm .v small { font-size: 12px; color: var(--text-2); font-weight: 500; }
.tc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tc-l7 { display: flex; align-items: center; gap: 8px; }
.tc-flags { display: flex; gap: 5px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.mbar { display: block; height: 5px; border-radius: 999px; background: var(--card-2); overflow: hidden; margin-top: 6px; }
.tm .mbar { background: var(--track); }
.mbar > i { display: block; height: 100%; width: 100%; border-radius: 999px; background: var(--accent); transform-origin: right center; transition: transform 0.5s var(--ease); }
.mbar.ok > i { background: var(--green); }
.mbar.over > i { background: var(--orange); }
.mbar.steps > i { background: var(--violet); }
.wdots { display: flex; gap: 4px; margin-top: 7px; }
.wdots i { width: 100%; max-width: 22px; height: 5px; border-radius: 999px; background: var(--track); }
.wdots i.on { background: var(--text); }
.l7 { display: inline-flex; gap: 3px; }
.l7-d { width: 14px; height: 14px; border-radius: 4px; background: var(--card-2); display: grid; place-items: center; }
.l7-d.part { background: var(--green-part); }
.l7-d.ok { background: var(--green); }
.l7-d i { width: 4px; height: 4px; border-radius: 999px; background: var(--text); }
.l7-d.ok i { background: #fff; }
.delta-w { font-weight: 600; }
.delta-w.down { color: var(--green); }
.delta-w.up { color: var(--orange-ink); }

.tt-wrap { border: 1px solid var(--line); border-radius: 16px; overflow: auto; background: var(--surface); }
.tt { width: 100%; border-collapse: collapse; font-size: 14px; }
.tt th { text-align: start; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 10px 12px; background: var(--card); white-space: nowrap; position: sticky; top: 0; }
.tt td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.tt .n { text-align: end; }
.tt .c { text-align: center; }
.tt tbody tr { cursor: pointer; }
.tt tbody tr:hover td { background: var(--row-hover); }
.tt-name { display: flex; align-items: center; gap: 10px; min-width: 180px; max-width: 260px; }
.tt-name .grow { min-width: 0; }
.tt-kcal { min-width: 90px; }
.tt-flags { display: flex; gap: 4px; flex-wrap: wrap; white-space: normal; min-width: 150px; }

/* ---------- trainee layout + switcher ---------- */
.t-layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); gap: 28px; align-items: start; }
.t-side { position: sticky; top: 73px; background: var(--card); border-radius: 18px; padding: 12px 8px 8px; max-height: calc(100vh - 90px); max-height: calc(100dvh - 90px); display: flex; flex-direction: column; }
.t-side-head { padding: 0 6px 8px; }
.t-side-title { font-weight: 700; font-size: 15px; margin: 2px 4px 8px; }
.t-side-head .input { background: var(--input-bg); min-height: 36px; font-size: 14px; }
.t-side-list { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 2px; }
.t-side-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; color: inherit; transition: transform 0.16s var(--ease); }
.t-side-item:hover { background: var(--card-2); }
.t-side-item:active { transform: scale(0.97); }
.t-side-item.on { background: var(--surface-2); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.t-side-item .grow { min-width: 0; display: flex; flex-direction: column; }
.t-side-item .nm { font-weight: 600; font-size: 14px; }
.t-side-item .sb { font-size: 12px; color: var(--text-2); }
.t-main { min-width: 0; }
.t-switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.t-switch .back { margin: 0; }
.t-switch-nav { display: flex; align-items: center; gap: 4px; }
.t-switch-nav .pos { min-width: 36px; text-align: center; }
.nav-arrow { width: 34px; height: 34px; font-size: 20px; background: var(--card); color: var(--text); text-decoration: none; transition: transform 0.16s var(--ease); }
.nav-arrow:active { transform: scale(0.97); }
.qs { position: relative; margin-inline-start: 6px; }
.qs-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; font: inherit; transition: transform 0.16s var(--ease); }
.qs-btn:active { transform: scale(0.97); }
.qs-caret { font-size: 13px; color: var(--text-2); line-height: 1; transform: translateY(-2px); transition: transform 0.2s var(--ease); }
.qs.open .qs-caret { transform: translateY(1px) rotate(180deg); }
.qs-pop {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0; z-index: 40; width: min(340px, calc(100vw - 32px));
  background: var(--sheet); border-radius: 16px; box-shadow: var(--pop-shadow); padding: 10px;
  transform-origin: top left; animation: popIn 0.2s var(--ease);
}
.qs-pop[hidden] { display: none; }
.qs-list { max-height: 340px; overflow-y: auto; margin-top: 8px; overscroll-behavior: contain; }
.qs-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; color: inherit; }
.qs-item:hover, .qs-item:focus-visible { background: var(--card); outline: none; }
.qs-item.on { background: var(--accent-soft); }
.qs-item .grow { min-width: 0; font-weight: 500; }
.qs-flag { max-width: 120px; }
@keyframes popIn { from { opacity: 0; transform: scale(0.96) translateY(-4px); } }
.t-strip { display: none; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 14px; padding: 2px 16px 4px; scroll-padding-inline: 16px; }
.t-strip::-webkit-scrollbar { display: none; }
.t-strip-item { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 62px; flex: none; color: var(--text-2); font-size: 12px; padding: 6px 2px; border-radius: 12px; transition: transform 0.16s var(--ease); }
.t-strip-item .ellipsis { max-width: 100%; }
.t-strip-item:active { transform: scale(0.97); }
.t-strip-item.on { background: var(--card); color: var(--text); font-weight: 600; }
.t-head { margin-bottom: 16px; align-items: center; }
.t-head-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.t-head-title h1 { margin-inline-end: 4px; }
.t-head .sub { margin-top: 4px; }
.t-head-actions { display: flex; gap: 8px; align-items: center; }
.t-head-actions .btn.wa { padding: 6px 12px; font-size: 13px; }
.t-head .avatar.lg { width: 58px; height: 58px; }
.settings-links { display: flex; gap: 18px; flex-wrap: wrap; }

/* ---------- CRM tab ---------- */
.crm-flags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.crm-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.crm-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.crm-card + .crm-card { margin-top: 0; }
.crm-card { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 16px 18px; }
.crm-card h2 { font-size: 17px; margin: 0; }
.crm-card-head { margin-bottom: 12px; }
.crm-card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ring-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ring-stat { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.ring-stat .k { font-size: 12px; color: var(--text-2); font-weight: 500; }
.ring-stat .v { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.ring-stat .v small { font-weight: 500; color: var(--text-2); font-size: 12px; }
.ring { flex: none; }
.ring circle { fill: none; stroke-width: 5; }
.ring .track { stroke: var(--track); }
.ring .val { stroke-linecap: round; stroke: var(--accent); }
.ring.kcal .val { stroke: var(--kcal); }
.ring.protein .val { stroke: var(--protein-ink); }
.ring.steps .val { stroke: var(--violet); }
.ring.water .val { stroke: var(--water); }
.crm-note { margin-top: 10px; font-size: 13px; border-radius: 10px; padding: 8px 12px; background: var(--card); color: var(--text-2); }
.crm-note.orange { background: var(--orange-soft); color: var(--orange-ink); }
.week-top { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.week-top .wdots { flex: 1; margin: 0; }
.week-top .wdots i { height: 7px; max-width: none; }
.big-num { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
.week-sessions { display: flex; gap: 6px; flex-wrap: wrap; }
.adh { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.adh-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.adh-cols { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.adh-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.adh-bar { width: 100%; max-width: 34px; height: 64px; border-radius: 8px; background: var(--card); overflow: hidden; display: flex; align-items: flex-end; }
.adh-bar i { display: block; width: 100%; height: 100%; background: var(--violet-mid); border-radius: 8px; transform-origin: bottom; transition: transform 0.6s var(--ease); }
.adh-cell { width: 100%; max-width: 34px; height: 16px; border-radius: 5px; background: var(--card-2); display: grid; place-items: center; }
.adh-cell.part { background: var(--green-part); }
.adh-cell.ok { background: var(--green); }
.adh-cell i { width: 6px; height: 6px; border-radius: 999px; background: var(--text); }
.adh-cell.ok i { background: #fff; }
.adh-day { font-size: 12px; color: var(--text-2); }
.adh-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.adh-legend span { display: inline-flex; align-items: center; gap: 5px; }
.lgd { width: 10px; height: 10px; border-radius: 3px; display: inline-block; background: var(--card-2); }
.lgd.steps { background: var(--violet-mid); }
.lgd.ok { background: var(--green); }
.lgd.part { background: var(--green-part); }
.lgd.wo { background: var(--text); border-radius: 999px; width: 7px; height: 7px; }
.timeline { margin-top: 12px; }
.tl-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; position: relative; }
.tl-item + .tl-item { border-top: 1px solid var(--line); }
.tl-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--accent); margin-top: 6px; flex: none; box-shadow: 0 0 0 4px var(--accent-soft); }
.tl-item .grow { flex: 1; min-width: 0; }
.tl-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tl-text { margin-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
.ci-form { display: flex; flex-direction: column; gap: 8px; }
.ci-form textarea { min-height: 64px; }
.ci-row { display: flex; gap: 8px; align-items: center; }
.ci-row input[type=date] { flex: 1 1 150px; min-width: 0; }
.ci-row input[type=number] { flex: 0 1 100px; min-width: 0; }
.contact { display: flex; flex-direction: column; }
.contact-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; font-size: 14px; align-items: center; min-width: 0; }
.contact-row + .contact-row { border-top: 1px solid var(--line); }
.contact-row .k { color: var(--text-2); flex: none; }
.contact-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.contact-actions .btn.wa { padding: 7px 14px; font-size: 14px; }
.crm-field { display: block; }
.crm-field + .crm-field { margin-top: 14px; }
.crm-field .k { font-size: 13px; color: var(--text-2); font-weight: 500; margin-bottom: 6px; }
.status-seg { display: flex; }
.status-seg button { flex: 1; }
.tag-edit { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag.removable { padding-inline-end: 3px; }
.tag .x { border: 0; background: none; color: inherit; opacity: 0.6; cursor: pointer; width: 20px; height: 20px; border-radius: 999px; font-size: 10px; }
.tag .x:hover { opacity: 1; background: var(--violet-soft); }
.tag-input { width: 110px !important; min-height: 30px !important; padding: 4px 10px !important; font-size: 13px !important; border-radius: 999px !important; }
.notes { min-height: 130px; }
.saved-ind { color: var(--green); font-weight: 600; opacity: 0; transition: opacity 0.3s var(--ease); }
.saved-ind.show { opacity: 1; }
.qa-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.qa { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--card); color: inherit; transition: transform 0.16s var(--ease); }
.qa:active { transform: scale(0.97); }
.qa .grow { display: flex; flex-direction: column; min-width: 0; }
.qa b { font-weight: 600; }
.qa .chev { color: var(--text-3); font-size: 18px; }

/* ---------- leaderboard ---------- */
.podium-wrap {
  border-radius: 24px; padding: 26px 16px 0; margin-bottom: 18px; overflow: hidden;
  background: var(--podium-bg);
}
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 12px; max-width: 620px; margin: 0 auto; direction: ltr; }
.pod { display: flex; flex-direction: column; align-items: center; color: inherit; min-width: 0; direction: rtl; }
.pod-person { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 10px; min-width: 0; max-width: 100%; animation: rise 0.5s var(--ease) both; animation-delay: calc(var(--d) + 160ms); }
.pod-avatar { position: relative; }
.pod-avatar .avatar.lg { width: 64px; height: 64px; font-size: 22px; box-shadow: 0 0 0 4px var(--ring-bg), 0 6px 20px rgba(0, 0, 0, 0.12); }
.pod.p1 .pod-avatar .avatar.lg { width: 82px; height: 82px; font-size: 28px; }
.medal { position: absolute; top: -8px; inset-inline-start: -6px; width: 28px; height: 28px; border-radius: 999px; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; box-shadow: 0 0 0 3px var(--ring-bg); }
.p1 .medal { background: linear-gradient(135deg, #ffd60a, #ff9f0a); }
.p2 .medal { background: linear-gradient(135deg, #d1d5db, #8e8e93); }
.p3 .medal { background: linear-gradient(135deg, #f7b57a, #c2410c); }
.pod-name { font-weight: 650; font-size: 15px; max-width: 100%; margin-top: 4px; }
.pod-steps { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }
.p1 .pod-steps { font-size: 24px; }
.pod-steps small { font-size: 12px; font-weight: 500; color: var(--text-2); }
.pod-block {
  width: 100%; border-radius: 16px 16px 0 0; display: grid; place-items: start center; padding-top: 12px; color: rgba(255, 255, 255, 0.92);
  font-size: 34px; font-weight: 800; transform-origin: bottom; animation: grow 0.6s var(--ease) both; animation-delay: var(--d);
}
.p1 .pod-block { height: 150px; background: linear-gradient(180deg, #ffcc00, #ff9500); }
.p2 .pod-block { height: 108px; background: linear-gradient(180deg, #c7c7cc, #8e8e93); }
.p3 .pod-block { height: 82px; background: linear-gradient(180deg, #ffb27a, #e8590c); }
.empty-pod { visibility: hidden; }
@keyframes grow { from { transform: scaleY(0.2); opacity: 0; } }
.lb-list { background: var(--card); border-radius: 18px; padding: 6px; }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; color: inherit; transition: transform 0.16s var(--ease); }
.lb-row + .lb-row { margin-top: 2px; }
.lb-row:hover { background: var(--card-2); }
.lb-row:active { transform: scale(0.97); }
.lb-row .grow { flex: 1; min-width: 0; }
.lb-rank { width: 28px; text-align: center; font-weight: 800; color: var(--text-2); font-variant-numeric: tabular-nums; flex: none; }
.lb-row.r1 .lb-rank { color: var(--gold); }
.lb-row.r2 .lb-rank { color: var(--silver); }
.lb-row.r3 .lb-rank { color: var(--bronze); }
.lb-top { display: flex; justify-content: space-between; gap: 10px; }
.lb-steps { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-bar { height: 7px; background: var(--track); }
.lb-bar > i { background: linear-gradient(270deg, #5e5ce6, #bf5af2); }
.lb-row.r1 .lb-bar > i { background: linear-gradient(270deg, #ffcc00, #ff9500); }
.lb-row.r2 .lb-bar > i { background: linear-gradient(270deg, #c7c7cc, #8e8e93); }
.lb-row.r3 .lb-bar > i { background: linear-gradient(270deg, #ffb27a, #e8590c); }

/* ---------- exercise library v2 ---------- */
.xl-search { display: flex; gap: 8px; align-items: center; }
.xl-search .search { flex: 1; min-width: 0; }
.xl-info { margin: 10px 0 2px; }
.xl-group { padding-top: 22px; }
.xl-group-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.xl-group-head h2 { margin: 0; }
.xl-group-head .link-btn { margin-inline-start: auto; }
.xl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 12px; padding-top: 12px; }
.xl-group .xl-grid { padding-top: 0; }
.xl-sentinel { height: 1px; }
.xc {
  all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden; min-width: 0; transition: transform 0.2s var(--ease); content-visibility: auto; contain-intrinsic-size: 200px 220px;
}
.xc:hover { transform: translateY(-2px); }
.xc:active { transform: scale(0.97); }
.xc:focus-visible { outline: 3px solid var(--focus-ring-strong); outline-offset: 2px; }
.xc-media { --mh: 211; position: relative; aspect-ratio: 4 / 3; background: hsl(var(--mh) 60% 96%); display: block; overflow: hidden; }
.xc-media img { width: 100%; height: 100%; object-fit: cover; display: block; background: #fff; }
.xc-ph { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: hsl(var(--mh) 45% 45%); }
.xc-ph b { font-size: 26px; font-weight: 800; width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: hsl(var(--mh) 70% 90%); }
.xc-ph small { font-size: 11px; font-weight: 600; opacity: 0.8; }
.xc-play { position: absolute; bottom: 8px; inset-inline-start: 8px; width: 28px; height: 28px; border-radius: 999px; background: rgba(29, 29, 31, 0.7); color: #fff; display: grid; place-items: center; font-size: 10px; padding-inline-start: 2px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.xc-body { display: flex; flex-direction: column; gap: 2px; padding: 9px 11px 11px; min-width: 0; }
.xc-name { font-weight: 600; font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.xc-sub { font-size: 12px; color: var(--text-2); }
.xd { display: flex; flex-direction: column; gap: 14px; }
.sheet.wide:has(.xd) { max-width: 780px; }
.xd-media { margin: -16px -18px 0; overflow: hidden; }
.xd-video { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; cursor: pointer; }
.xd-ph { --mh: 211; position: relative; aspect-ratio: 16 / 9; display: grid; place-items: center; background: hsl(var(--mh) 60% 96%); color: hsl(var(--mh) 40% 35%); overflow: hidden; }
.xd-ph img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0.35; }
.xd-ph-text { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 16px; }
.xd-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.ltr-pill { font-weight: 500; }
.xd-cues { margin: 4px 0 0; padding-inline-start: 22px; line-height: 1.6; }
.xd-cues li + li { margin-top: 6px; }
.xd-cues li::marker { color: var(--accent); font-weight: 700; }

/* ---------- invite (login code) ---------- */
.invite { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.invite-ok { display: inline-flex; gap: 8px; align-items: center; background: var(--green-soft); color: var(--green-ink); font-weight: 600; border-radius: 999px; padding: 5px 14px; margin-bottom: 8px; }
.code-big { border: 0; background: var(--card); border-radius: 18px; padding: 14px 22px 12px; cursor: pointer; color: var(--text); transition: transform 0.16s var(--ease); margin: 4px 0; font-family: inherit; }
.code-big:active { transform: scale(0.97); }
.invite-preview { width: 100%; text-align: start; background: var(--green-soft); border-radius: 14px; padding: 12px 14px; margin-top: 10px; }
.invite-preview pre { margin: 0; font: inherit; font-size: 13.5px; white-space: pre-wrap; line-height: 1.55; color: var(--text); }
.invite-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .t-layout { grid-template-columns: minmax(0, 1fr); }
  .t-side { display: none; }
  .t-strip { display: flex; }
  .crm-grid { grid-template-columns: minmax(0, 1fr); }
  .crm-col.side { order: -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
}
@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-row > :last-child:nth-child(odd) { grid-column: span 2; }
  .view-toggle { display: none; }
}
@media (max-width: 640px) {
  .coach-chip { order: 2; padding: 2px; }
  .coach-chip .coach-name { display: none; }
  .kpi { padding: 12px 14px; }
  .kpi .v { font-size: 24px; }
  .tc-grid { grid-template-columns: minmax(0, 1fr); }
  .dash-toolbar .search { flex-basis: 100%; }
  .dash-chips { flex-wrap: nowrap; margin: 0 -16px 8px; padding: 0 16px 2px; }
  .t-switch .back { font-size: 14px; }
  .qs-btn .small { display: none; }
  .qs-btn { padding: 6px 10px; }
  .qs-pop { position: fixed; top: 140px; inset-inline: 16px; width: auto; }
  .t-head { gap: 12px; }
  .t-head .grow { min-width: 0; flex-basis: calc(100% - 72px); }
  .t-head-actions { width: 100%; }
  .t-head-actions > * { flex: 1; }
  .ring-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .ring-stat { padding: 8px; gap: 8px; }
  .ring-stat .v { font-size: 15px; }
  .ring { width: 36px; height: 36px; }
  .crm-card { padding: 14px; }
  .adh-cols { gap: 5px; }
  .adh-bar { height: 52px; }
  .podium-wrap { padding: 20px 8px 0; border-radius: 20px; }
  .podium { gap: 6px; }
  .pod-avatar .avatar.lg { width: 52px; height: 52px; font-size: 18px; }
  .pod.p1 .pod-avatar .avatar.lg { width: 64px; height: 64px; font-size: 22px; }
  .pod-name { font-size: 13px; }
  .pod-steps { font-size: 16px; }
  .p1 .pod-steps { font-size: 19px; }
  .p1 .pod-block { height: 120px; }
  .p2 .pod-block { height: 88px; }
  .p3 .pod-block { height: 66px; }
  .xl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .xl-group-head .link-btn { font-size: 13px; }
  .xd-media { margin: -16px -18px 0; }
  .ex-filter { top: 92px; }
}
/* .btn.block (full-width button) must win over the plan editor's .block card */
.btn.block { background: var(--accent); color: #fff; border-radius: 999px; padding: 12px; width: 100%; }
.btn.block:disabled { opacity: 0.4; }

/* =====================================================================
   v3 — dark theme details, theme toggle, installed-app (PWA) safe areas
   ===================================================================== */
html { background: var(--bg); }
.theme-toggle { width: 34px; height: 34px; color: var(--text-2); }
.theme-toggle svg { display: block; }
.login-wrap { position: relative; }
.login-theme { position: absolute; top: calc(14px + var(--sat)); inset-inline-end: calc(14px + var(--sal)); }

/* Theme cross-fade: colors only, ≤200ms, only on an explicit switch, never with reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  html.theme-switching, html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
    transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, fill 0.18s ease, stroke 0.18s ease, box-shadow 0.18s ease !important;
  }
}

/* dark-only details that tokens can't express */
:root[data-theme="dark"] .avatar { background: hsl(var(--hue) 38% 24%); color: hsl(var(--hue) 85% 82%); }
:root[data-theme="dark"] :is(.xc-media, .xd-ph) { background: hsl(var(--mh) 22% 15%); }
:root[data-theme="dark"] .xc-ph { color: hsl(var(--mh) 65% 74%); }
:root[data-theme="dark"] .xc-ph b { background: hsl(var(--mh) 30% 24%); }
:root[data-theme="dark"] .xd-ph { color: hsl(var(--mh) 65% 78%); }
:root[data-theme="dark"] .list-chip:hover { filter: brightness(1.18); }
:root[data-theme="dark"] .segmented .on { box-shadow: none; }
:root[data-theme="dark"] .t-side-item.on { box-shadow: none; }
:root[data-theme="dark"] .pod-avatar .avatar.lg { box-shadow: 0 0 0 4px #1c1c1e, 0 6px 20px rgba(0, 0, 0, 0.5); }
:root[data-theme="dark"] .medal { box-shadow: 0 0 0 3px #1c1c1e; }
:root[data-theme="dark"] .p2 .pod-block { background: linear-gradient(180deg, #8e8e93, #5a5a5f); }
:root[data-theme="dark"] .lb-row.r2 .lb-bar > i { background: linear-gradient(270deg, #aeaeb2, #6e6e73); }
:root[data-theme="dark"] .btn.wa { background: #1fb457; }
:root[data-theme="dark"] .input::placeholder { color: var(--text-3); }
:root[data-theme="dark"] input[type="date"].input::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type="time"].input::-webkit-calendar-picker-indicator { filter: invert(0.8); }
/* exercise media are filmed on white: keep their white frame, just soften it a touch at night */
:root[data-theme="dark"] :is(.exc-media, .xd-media, .xc-media img, .ai-card img) { filter: brightness(0.94); }

/* ---------- safe areas (iPhone notch / Dynamic Island / home indicator in standalone mode) ---------- */
.topbar { padding-top: var(--sat); }
.topbar-inner { padding-left: max(20px, var(--sal)); padding-right: max(20px, var(--sar)); }
main { padding-left: max(20px, var(--sal)); padding-right: max(20px, var(--sar)); }
.site-foot { padding-bottom: calc(110px + var(--sab)); }
.day-bar, .ex-filter { top: var(--topbar-h, calc(57px + var(--sat))); }
.t-side { top: calc(var(--topbar-h, calc(57px + var(--sat))) + 16px); }
.toast { top: calc(70px + var(--sat)); }
.login-wrap { padding: calc(24px + var(--sat)) max(16px, var(--sar)) calc(24px + var(--sab)) max(16px, var(--sal)); }
.savebar { bottom: calc(20px + var(--sab)); }
@media (max-width: 640px) {
  .topbar-inner { padding-left: max(16px, var(--sal)); padding-right: max(16px, var(--sar)); }
  .theme-toggle { order: 2; }
  main { padding-left: max(16px, var(--sal)); padding-right: max(16px, var(--sar)); }
  .savebar { bottom: max(14px, var(--sab)); }
  .sheet { max-height: min(92dvh, calc(100dvh - 12px - var(--sat))); }
  .sheet-foot { padding-left: max(18px, var(--sal)); padding-right: max(18px, var(--sar)); }
}
/* Installed app: no rubber-band reveal of a mismatched color behind the page, no text-selection on chrome. */
@media (display-mode: standalone) {
  html, body { overscroll-behavior-y: none; }
  .topbar, .nav, .btn, .chip { -webkit-user-select: none; user-select: none; }
  .site-foot { padding-bottom: calc(40px + var(--sab)); }
}
:root[data-theme="dark"] .avatar.has-photo { background: var(--card-2); color: transparent; }

/* ---------- no zooming: the panel behaves like a native app ---------- */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
input, select, textarea { font-size: max(16px, 1em); }

/* ---------- v3: obvious replace / delete / add in the plan editors ---------- */
.row-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line);
}
.rt-move, .rt-main { display: flex; gap: 6px; align-items: center; }
.rt-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; min-width: 44px;
  padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; transition: transform 0.16s var(--ease), opacity 0.16s var(--ease);
}
.rt-btn:active { transform: scale(0.97); }
.rt-btn:disabled { opacity: 0.3; cursor: default; transform: none; }
.rt-btn.icon { padding: 0; width: 44px; }
.rt-btn.replace { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.rt-btn.delete { color: var(--red); background: var(--red-soft); border-color: transparent; }
.rt-btn.small { min-height: 36px; min-width: 36px; padding: 0 10px; font-size: 13px; border-radius: 10px; }
.rt-ic { display: inline-grid; place-items: center; line-height: 0; }
.add-row-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 14px; border: 1.5px dashed var(--accent); background: var(--accent-soft); color: var(--accent);
  font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; transition: transform 0.16s var(--ease);
}
.add-row-btn:active { transform: scale(0.97); }
.block-foot { padding: 12px 12px 4px; }
.ex-row-top .ex-thumb { width: 48px; height: 48px; border-radius: 12px; }
.ex-row-top { align-items: center; gap: 12px; }
.alt-add-label { display: flex; align-items: center; gap: 6px; margin-top: 12px; font-size: 13px; font-weight: 700; color: var(--accent); }
.alt-top .rt-btn.small { margin-inline-start: auto; }
.toast.undo { display: flex; align-items: center; gap: 14px; padding: 6px 6px 6px 6px; padding-inline-start: 16px; }
.toast-undo {
  border: 0; border-radius: 999px; background: var(--on-ink-soft); color: var(--on-ink); font: inherit; font-weight: 700;
  min-height: 36px; padding: 0 14px; cursor: pointer; transition: transform 0.16s var(--ease);
}
.toast-undo:active { transform: scale(0.97); }
@media (max-width: 640px) {
  .block-foot .add-row-btn { width: 100%; }
  .rt-btn:not(.icon):not(.small) { padding: 0 12px; }
}

/* ---------- v3: trainee card — sections, sub-cards, dividers ---------- */
.crm-grid { gap: 18px; }
.crm-col { gap: 18px; }
.crm-card { padding: 0; border-radius: 18px; overflow: hidden; }
.crm-card-head { margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--card); }
.crm-card-head h2 { font-size: 16.5px; letter-spacing: -0.01em; }
.crm-card-title { align-items: center; min-height: 32px; }
.crm-card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 14px; }
.crm-card-body > .ring-grid, .crm-card-body > .week-top { margin: 0; }
.sub { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.sub-title { font-size: 13px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; letter-spacing: 0.01em; }
.crm-card-body > .sub-title { margin: 4px 0 -6px; }
.adh.sub { margin-top: 0; border-top: 0; padding-top: 12px; }
.head-actions { display: flex; align-items: center; gap: 10px; }
.empty-note { color: var(--text-2); font-size: 14px; background: var(--card); border-radius: 14px; padding: 16px; text-align: center; }
.contact-row { padding: 11px 0; }
.timeline .tl-item { padding: 12px 0; }
.qa-list { gap: 8px; }
.crm-card-body .crm-field + .crm-field { margin-top: 0; padding-top: 14px; border-top: 1px solid var(--line); }
.more-btn { align-self: center; }

/* progress photos */
.pp-list { display: flex; flex-direction: column; gap: 12px; }
.pp-date { padding: 12px; }
.pp-date-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.pp-date-head .grow { flex: 1; min-width: 140px; }
.pp-date-title { font-weight: 700; font-size: 15.5px; }
.pp-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 560px) { .pp-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pp-slot { margin: 0; min-width: 0; }
.pp-img { all: unset; box-sizing: border-box; display: block; width: 100%; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: var(--card-2); cursor: zoom-in; transition: transform 0.18s var(--ease); }
.pp-img:active { transform: scale(0.97); }
.pp-img:focus-visible { outline: 3px solid var(--focus-ring-strong); outline-offset: 2px; }
.pp-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pp-img.ph { display: grid; place-items: center; cursor: default; border: 1.5px dashed var(--line); background: transparent; color: var(--text-3); font-size: 13px; }
.pp-slot figcaption { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 6px; font-size: 13px; font-weight: 600; }
.pp-dl { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); flex: none; transition: transform 0.16s var(--ease); }
.pp-dl:active { transform: scale(0.97); }

/* full-screen photo viewer */
.pv { position: fixed; inset: 0; z-index: 70; background: #000; color: #fff; display: flex; flex-direction: column; animation: fade 0.2s var(--ease); }
.pv-top { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--sat, 0px)) 12px 10px; }
.pv-title { flex: 1; min-width: 0; text-align: center; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-count { opacity: 0.6; font-variant-numeric: tabular-nums; }
.pv-actions { display: flex; gap: 8px; }
.pv-btn { min-width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(255, 255, 255, 0.12); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; cursor: pointer; padding: 0 12px; text-decoration: none; transition: transform 0.16s var(--ease); }
.pv-btn:active { transform: scale(0.97); }
.pv-btn[hidden] { display: none; }
.pv-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px 12px calc(16px + var(--sab, 0px)); touch-action: pan-y; user-select: none; }
.pv-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 12px; animation: fade 0.22s var(--ease); }
.pv-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border-radius: 14px; border: 0; background: rgba(255, 255, 255, 0.14); color: #fff; font-size: 30px; cursor: pointer; transition: transform 0.16s var(--ease); }
.pv-nav:active { transform: translateY(-50%) scale(0.97); }
.pv-nav.prev { right: 12px; }
.pv-nav.next { left: 12px; }
.pv-nav[hidden] { display: none; }
.pv-compare { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 12px; }
.pv-controls { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pv.compare .segmented { background: rgba(255, 255, 255, 0.12); }
.pv.compare .segmented button { color: rgba(255, 255, 255, 0.75); }
.pv.compare .segmented .on { background: #fff; color: #1d1d1f; }
.pv-dates { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pv-sel { width: auto; background: rgba(255, 255, 255, 0.12); color: #fff; border-color: transparent; }
.pv-sel option { color: #1d1d1f; }
.pv-vs { opacity: 0.7; font-size: 14px; }
.pv-pair { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pv-side { margin: 0; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.pv-side img { flex: 1; min-height: 0; width: 100%; object-fit: contain; border-radius: 12px; }
.pv-side figcaption { text-align: center; font-size: 14px; }
.pv-missing { flex: 1; display: grid; place-items: center; border: 1.5px dashed rgba(255, 255, 255, 0.3); border-radius: 12px; opacity: 0.7; font-size: 14px; }

/* body measurements */
.ms-body { display: flex; flex-direction: column; gap: 14px; }
.ms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ms-tile { background: var(--card); border-radius: 14px; padding: 11px 12px; min-width: 0; }
.ms-tile-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ms-tile .k { font-size: 13px; color: var(--text-2); font-weight: 600; }
.ms-val { font-size: 21px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.ms-val small { font-size: 12px; color: var(--text-2); font-weight: 500; }
.ms-spark svg { width: 100%; height: 30px; display: block; margin: 4px 0; }
.ms-delta { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.ms-delta.good { background: var(--green-soft); color: var(--green-ink); }
.ms-delta.bad { background: var(--red-soft); color: var(--red); }
.ms-delta.flat { background: var(--card-2); color: var(--text-2); }
.ms-table td { vertical-align: top; }
.ms-table td.n .ms-delta { margin-top: 3px; }
.ms-note { white-space: normal; min-width: 120px; color: var(--text-2); font-size: 13px; }
.ms-add summary { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; color: var(--accent); min-height: 44px; list-style: none; }
.ms-add summary::-webkit-details-marker { display: none; }
.ms-form { margin-top: 8px; display: flex; flex-direction: column; gap: 12px; }
.ms-form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.ms-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); font-weight: 600; }
.ms-field.date { grid-column: 1 / -1; max-width: 220px; }
.ms-form-foot { display: flex; gap: 10px; flex-wrap: wrap; }
.ms-form-foot .input { flex: 1 1 200px; }
@media (max-width: 640px) {
  .crm-card-head { padding: 12px 14px; }
  .crm-card-body { padding: 14px; }
  .pp-grid { gap: 8px; }
  .pp-date-head .rt-btn { width: 100%; }
  .ms-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pv-pair { grid-template-columns: 1fr 1fr; gap: 6px; }
  .pv-btn.wide { padding: 0 10px; }
}

/* ---------- collapsible plan-editor rows (meal items + exercises) ---------- */
.cl-row { padding: 0 !important; overflow: hidden; }
.cl-head {
  all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px;
  cursor: pointer; border-radius: inherit; -webkit-tap-highlight-color: transparent;
}
.cl-head:focus-visible { outline: 3px solid var(--focus-ring-strong); outline-offset: -3px; }
.cl-head:active .cl-text { opacity: 0.7; }
.cl-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; transition: opacity 0.12s var(--ease); }
.cl-name { font-weight: 650; font-size: 15px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12.5px; color: var(--text-2); }
.cl-meta .cl-amt { color: var(--text); font-weight: 600; }
.cl-badge { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; flex: none; }
.cl-badge.none { background: transparent; color: var(--text-3); font-weight: 500; padding: 3px 0; }
.cl-chev { flex: none; width: 32px; height: 32px; border-radius: 999px; display: grid; place-items: center; color: var(--text-2); background: var(--card); transition: transform 0.24s var(--ease); }
.cl-row.open .cl-chev { transform: rotate(180deg); }
.cl-panel { display: grid; grid-template-rows: 0fr; opacity: 0; visibility: hidden; transition: grid-template-rows 0.24s var(--ease), opacity 0.2s var(--ease), visibility 0s linear 0.24s; }
.cl-row.open .cl-panel { grid-template-rows: 1fr; opacity: 1; visibility: visible; transition-delay: 0s; }
.cl-inner { overflow: hidden; min-height: 0; }
.cl-body { padding: 0 14px 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.cl-sub { margin-bottom: 10px; }
.cl-body > .ex-params { margin-top: 0; }
.ex-row.cl-row .ex-thumb { width: 44px; height: 44px; border-radius: 11px; }
.ex-row + .ex-row, .item-row + .item-row { margin-top: 8px; }
@media (prefers-reduced-motion: reduce) {
  .cl-panel, .cl-chev, .cl-text { transition: none !important; }
}

/* ---------- smooth navigation: view swap, progress bar, skeletons ---------- */
main.view { min-height: calc(100vh - 140px); min-height: calc(100dvh - 140px); } /* footer never jumps up while a view loads */
main.view.enter { animation: viewIn 140ms var(--ease) both; }
@keyframes viewIn { from { opacity: 0.35; } }
.nav-progress {
  position: fixed; top: 0; inset-inline: 0; height: 3px; z-index: 80; pointer-events: none;
  background: var(--accent); transform-origin: right center; transform: scaleX(0); opacity: 0;
  transition: transform 0.9s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.2s var(--ease);
}
.nav-progress.on { transform: scaleX(0.75); opacity: 1; }
.sk-wrap { display: flex; flex-direction: column; gap: 14px; padding-top: 4px; }
.sk { background: var(--card); border-radius: 14px; animation: skPulse 1.2s ease-in-out infinite alternate; }
.sk-line { height: 18px; border-radius: 8px; }
.sk-line.w30 { width: 30%; } .sk-line.w40 { width: 40%; } .sk-line.w60 { width: 60%; }
.sk-head { height: 64px; } .sk-tabs { height: 44px; width: min(520px, 100%); }
.sk-card { height: 220px; border-radius: 18px; }
.sk-kpis { height: 96px; }
.sk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.sk-tile { height: 200px; border-radius: 18px; }
@keyframes skPulse { from { opacity: 1; } to { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { main.view.enter, .sk { animation: none; } .nav-progress { transition: none; } }

/* coach switch: trainee may rearrange the plan */
.arrange-switch { display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 14px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line); cursor: pointer; }
.arrange-switch .arr-text { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.arrange-switch .arr-text small { color: var(--text-2); font-size: 13px; line-height: 1.4; }
.arrange-switch .arr-ctl { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.arrange-switch .arr-state { font-size: 13px; font-weight: 600; color: var(--text-2); }
.switch { position: relative; width: 52px; height: 32px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--track); transition: background-color 200ms ease; pointer-events: none; }
.switch i::after { content: ''; position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform 200ms cubic-bezier(0.23, 1, 0.32, 1); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(-20px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

.label-checks .lc-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.label-checks .lc-mark { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.label-checks .ok .lc-mark { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.label-checks .bad .lc-mark { background: rgba(255, 59, 48, .14); color: #ff3b30; }
.label-checks .lc-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.label-checks .lc-text small { color: var(--text-2); font-size: 13px; line-height: 1.4; }

/* push bell */
.bell-toggle { width: 34px; height: 34px; color: var(--text-2); position: relative; }
.bell-toggle svg { display: block; }
.bell-toggle.on { color: var(--accent); }
.bell-toggle.on::after { content: ''; position: absolute; top: 6px; left: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
@media (max-width: 720px) { .bell-toggle { order: 2; } }

/* one day of eating (opened from a notification) */
.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.day-nav b { font-size: 16px; text-align: center; }
.day-card { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.day-ring { --p: 0; width: 112px; height: 112px; border-radius: 50%; display: grid; place-content: center; text-align: center; flex-shrink: 0;
  background: radial-gradient(closest-side, var(--card) 79%, transparent 80% 100%), conic-gradient(var(--accent) calc(var(--p) * 1%), var(--track) 0); }
.day-card.closed .day-ring { background: radial-gradient(closest-side, var(--card) 79%, transparent 80% 100%), conic-gradient(var(--green) calc(var(--p) * 1%), var(--track) 0); }
.day-ring b { font-size: 22px; }
.day-ring small { color: var(--text-2); font-size: 12px; }
.day-info { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 6px; }
.day-status { font-size: 18px; font-weight: 700; }
.day-card.closed .day-status { color: var(--green); }
.day-info .btn.wa { align-self: flex-start; margin-top: 6px; }
.day-item { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.day-item .lc-mark { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.day-item.ok .lc-mark { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.day-item.miss .lc-mark { background: rgba(255, 59, 48, .12); color: #ff3b30; }
.day-item.miss .grow { color: var(--text-2); }
.day-item .tag { margin-inline-start: 6px; }

/* ---- team (studio) ---- */
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.team-card { display: flex; flex-direction: column; gap: 14px; }
.team-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.team-name { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.team-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.team-stat { background: var(--surface); border: 0; border-radius: 12px; padding: 10px 8px; text-align: center; font: inherit; color: inherit; }
button.team-stat { cursor: pointer; transition: transform 160ms ease-out; }
button.team-stat:active { transform: scale(0.97); }
.team-stat .v { font-size: 22px; font-weight: 700; line-height: 1.1; }
.team-stat.warn .v { color: var(--orange-ink); }
.team-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-text { color: var(--red) !important; }
.tc-coach { color: var(--accent); font-weight: 600; }

/* ---- import from screenshots ---- */
.imp-drop { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px; border: 1.5px dashed var(--gray-3); border-radius: 14px; cursor: pointer; text-align: center; }
.imp-drop .big { font-size: 28px; }
.imp-file { position: absolute; width: 1px; height: 1px; opacity: 0; }
.imp-thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.imp-thumb { position: relative; width: 64px; height: 120px; border-radius: 8px; overflow: hidden; background: var(--card); }
.imp-thumb img { width: 100%; height: 100%; object-fit: cover; }
.imp-x { position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--overlay); color: #fff; font-size: 11px; cursor: pointer; }
.imp-busy { display: flex; align-items: center; gap: 10px; color: var(--text-2); }
.imp-review .card { padding: 12px; }
.imp-meal { display: flex; flex-direction: column; gap: 8px; }
.imp-meal-name { font-weight: 700; }
.imp-w-name { font-weight: 700; }
.imp-item { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.imp-item > .tag { align-self: flex-start; }
.imp-row { display: flex; flex-direction: column; gap: 4px; padding: 6px 8px; border-radius: 10px; }
.imp-row.new { background: var(--orange-soft); }
.imp-row.alt { margin-inline-start: 14px; }
.imp-pick { display: flex; gap: 6px; flex-wrap: wrap; align-items: end; }
.imp-pick > .imp-food, .imp-pick > input[list] { flex: 1 1 260px; min-width: 0; }
.imp-amt, .imp-unit { flex: none; }
.imp-amt { width: 90px; }
.imp-unit { width: 96px; }
.imp-n { display: flex; flex-direction: column; gap: 2px; width: 84px; }
.imp-alts summary { cursor: pointer; color: var(--accent); }
.imp-check { display: flex; align-items: center; gap: 8px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--track); border-top-color: var(--accent); animation: imp-spin 0.7s linear infinite; }
@keyframes imp-spin { to { transform: rotate(360deg); } }

/* ---- leads ---- */
.lead-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 14px; }
.lead-card { display: flex; flex-direction: column; gap: 10px; text-align: right; font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); transition: transform 160ms ease-out, box-shadow 200ms ease; }
.lead-card:active { transform: scale(0.98); }
.lead-card.is-new { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.lead-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.lead-name { font-weight: 700; font-size: 17px; }
.lead-goals { display: flex; flex-wrap: wrap; gap: 6px; }
.lead-sheet { display: flex; flex-direction: column; gap: 16px; }
.lead-hero { display: flex; align-items: center; gap: 14px; }
.lead-hero-name { font-size: 22px; font-weight: 700; }
.lead-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.lead-actions .btn { justify-content: center; }
.lead-status { display: grid; grid-template-columns: repeat(4, 1fr); }
.lead-rows { margin: 0; display: grid; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.lead-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 12px 14px; background: var(--surface); }
.lead-row + .lead-row { border-top: 1px solid var(--line); }
.lead-row dt { color: var(--text-2); font-size: 14px; }
.lead-row dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 560px) { .lead-row { grid-template-columns: 1fr; gap: 2px; } .lead-actions { grid-template-columns: 1fr 1fr; } .lead-actions .btn.wa { grid-column: span 2; } .lead-status { grid-template-columns: repeat(2, 1fr); } }

/* ---- in-app PDF export ---- */
.print-ov { position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column; background: var(--card); }
.print-bar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: var(--sheet); box-shadow: 0 1px 0 var(--line); }
.print-title { text-align: center; font-weight: 700; }
.print-hint { text-align: center; padding: 10px 16px 0; }
.print-scroll { flex: 1; overflow: auto; padding: 14px 14px calc(24px + env(safe-area-inset-bottom)); }
.print-sheet { max-width: 720px; margin: 0 auto; background: #fff; color: #141414; border-radius: 14px; padding: 28px 24px; box-shadow: 0 10px 30px -18px rgba(0,0,0,.4); font: 15px/1.6 -apple-system, "Heebo", Arial, sans-serif; }
.print-sheet h1 { font-size: 26px; margin: 0 0 4px; }
.print-sub { color: #666; margin-bottom: 18px; }
.print-sheet table { width: 100%; border-collapse: collapse; }
.print-sheet th { width: 30%; text-align: right; vertical-align: top; color: #555; font-weight: 600; padding: 10px 0 10px 12px; border-bottom: 1px solid #e6e6e6; }
.print-sheet td { padding: 10px 0; border-bottom: 1px solid #e6e6e6; white-space: pre-wrap; overflow-wrap: anywhere; }
.print-foot { margin-top: 20px; color: #999; font-size: 12px; }
@media print {
  @page { size: A4; margin: 16mm; }
  html.printing body > *:not(.print-ov) { display: none !important; }
  html.printing .print-ov { position: static; background: #fff; }
  html.printing .print-bar, html.printing .print-hint { display: none !important; }
  html.printing .print-scroll { overflow: visible; padding: 0; }
  html.printing .print-sheet { box-shadow: none; padding: 0; max-width: none; border-radius: 0; }
}

/* ---- check-in routine (weigh-ins + weekly photos) ---- */
.trk-today { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.pill.green { background: color-mix(in srgb, #1f9d55 14%, transparent); color: #1f9d55; }
.ok-txt { color: #1f9d55; }
.trk-weeks { margin-top: 14px; overflow-x: auto; }
.trk-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.trk-table th { color: var(--text-2); font-weight: 600; text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.trk-table td { padding: 8px; border-bottom: 1px solid var(--line); }
.trk-table .n { text-align: left; font-variant-numeric: tabular-nums; }
.trk-table .c { text-align: center; }
.trk-settings { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.trk-settings summary { cursor: pointer; color: var(--text-2); padding: 4px 0; }
.trk-settings[open] summary { margin-bottom: 8px; }
.trk-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.trk-row .input { width: auto; min-width: 150px; }

.chart-legend { display: flex; gap: 16px; justify-content: center; margin-top: 6px; color: var(--text-2); font-size: 12px; }
.chart-legend i { display: inline-block; vertical-align: middle; margin-inline-end: 6px; }
.chart-legend .lg-avg { width: 18px; height: 3px; border-radius: 2px; background: var(--accent); }
.chart-legend .lg-day { width: 18px; border-top: 1.5px dashed var(--text-3, #9aa0a6); }

.head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.bc-list { display: grid; gap: 8px; margin-top: 4px; }
.bc-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }

/* ---- backgrounds ---- */
body.has-bg { background-image: var(--app-bg-image); background-size: cover; background-position: center; background-attachment: fixed; }
body.has-bg::before { content: ""; position: fixed; inset: 0; z-index: -1; background: color-mix(in srgb, var(--bg, #f2f2f7) 68%, transparent); pointer-events: none; }
.bg-modes { display: grid; gap: 8px; margin: 6px 0 10px; }
.bg-mode { display: grid; gap: 2px; text-align: right; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; cursor: pointer; }
.bg-mode.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.bg-preview { height: 140px; border-radius: 14px; background-size: cover; background-position: center; margin: 4px 0 10px; }
.code-chip { margin-top: 6px; display: inline-flex; gap: 4px; align-items: center; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; }

/* ---- bubble ---- */
.tc-acts { display: flex; gap: 6px; align-items: center; }
.bubble-btn { font-size: 18px; background: var(--card); border: 1px solid var(--line); }
.bubble-btn.on { border-color: var(--accent); }
.tc-bubble { margin-top: 8px; padding: 6px 10px; border-radius: 12px; background: var(--accent-soft); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble-card { display: grid; gap: 10px; }
.bubble-ideas { display: flex; flex-wrap: wrap; gap: 6px; }
.bubble-acts { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.bubble-acts > :first-child { margin-inline-end: auto; }

/* ---- the head coach (Ben, top of the pyramid): his panel is yellow ---- */
html[data-role="owner"] { --accent: #f5b301; --accent-soft: #fff4cc; --on-accent: #1a1a1a; }
@media (prefers-color-scheme: dark) { html[data-role="owner"]:not([data-theme="light"]) { --accent: #ffc928; --accent-soft: rgba(255, 201, 40, 0.18); } }
html[data-role="owner"][data-theme="dark"] { --accent: #ffc928; --accent-soft: rgba(255, 201, 40, 0.18); }
html[data-role="owner"] .btn:not(.wa):not(.plain):not(.secondary):not(.danger),
html[data-role="owner"] .btn.block,
html[data-role="owner"] .nav a.active { color: #1a1a1a; }
html[data-role="owner"] .btn.secondary,
html[data-role="owner"] .pill.blue,
html[data-role="owner"] .src.coach,
html[data-role="owner"] .list-chip.match { color: #8a6400; }
html[data-role="owner"] .brand-mark { content: url("/coach/icons/icon-192-owner.png"); }

/* ---------- phone: bottom tab bar (same as the trainee app) ---------- */
.tabbar { display: none; }
@media (max-width: 640px) {
  .topbar .nav, .topbar .bell-toggle, .topbar .theme-toggle, .topbar .logout { display: none !important; }
  .tabbar { position: fixed; z-index: 35; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 6px; border-radius: 30px; background: color-mix(in srgb, var(--card) 88%, transparent);
    backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6); box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.35), 0 0 0 0.5px var(--line); }
  body.typing .tabbar { display: none; }
  .tabbar a { border-radius: 24px; padding: 7px 2px 6px; display: grid; justify-items: center; gap: 3px;
    font-size: 10.5px; font-weight: 600; color: var(--text-2); text-decoration: none; -webkit-tap-highlight-color: transparent; transition: transform 0.12s var(--ease); }
  .tabbar .ic { width: 25px; height: 25px; display: block; }
  .tabbar .ic svg { width: 100%; height: 100%; display: block; }
  .tabbar a:active { transform: scale(0.94); }
  .tabbar a.active { background: var(--card-2); color: var(--accent); }
  .savebar { bottom: calc(86px + env(safe-area-inset-bottom)); }
  main { padding-bottom: calc(110px + env(safe-area-inset-bottom)) !important; }
  .site-foot { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
}
@media (min-width: 641px) { .tabbar { display: none !important; } }

/* ---------- "עוד" page ---------- */
.more-profile { width: 100%; display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 22px; border: 0; border-radius: 20px; background: var(--card); color: var(--text); text-align: start; cursor: pointer; font: inherit; transition: transform 0.12s var(--ease); }
.more-profile:active, .more-row:not(.static):active { transform: scale(0.985); }
.more-profile b, .more-row b { display: block; font-size: 17px; font-weight: 700; }
.more-profile small, .more-row small { display: block; color: var(--text-2); font-size: 13px; margin-top: 2px; line-height: 1.35; }
.more-group { margin-bottom: 22px; }
.more-group h2 { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0 6px 8px; }
.more-card { background: var(--card); border-radius: 18px; overflow: hidden; }
.more-row { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 14px; border: 0; background: none; color: var(--text); text-align: start; cursor: pointer; font: inherit; }
.more-row + .more-row { border-top: 0.5px solid var(--line); }
.more-row.static { cursor: default; }
.more-ic { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.more-ic svg { width: 21px; height: 21px; }
.more-chev { width: 16px; height: 16px; flex: none; color: var(--text-3, var(--text-2)); opacity: 0.6; }
.more-chev svg { width: 100%; height: 100%; }
.more-badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: #ff3b30; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.more-row.danger, .more-row.danger .more-ic { color: #ff3b30; }
.more-row.danger .more-ic { background: color-mix(in srgb, #ff3b30 12%, transparent); }
.more-toggle { flex: none; }
.topbar .more-toggle { display: none; }
