/* ==========================================================================
   FitCoach — base, layout and components
   Direction-agnostic: every inline offset uses CSS logical properties, so the
   same stylesheet serves both the Persian RTL UI and a future LTR locale.
   ========================================================================== */

/* --- Reset --------------------------------------------------------------- */

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 700;
  line-height: var(--leading-tight);
  color: var(--text);
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); }

p { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }

a { color: var(--primary); text-decoration: none; transition: color var(--duration-fast) var(--ease); }
a:hover { color: var(--primary-hover); }

img, svg, video { max-width: 100%; height: auto; display: block; }

ul, ol { margin: 0; padding: 0; }
li { list-style: none; }

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

hr { border: none; border-top: 1px solid var(--border); margin: var(--space-6) 0; }

code, kbd, pre { font-family: var(--font-mono); font-size: 0.92em; direction: ltr; }

/* Accessible focus ring on every interactive element. */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Respect the user's motion preference. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip link for keyboard users. */
.skip-link {
  position: absolute;
  inset-inline-start: var(--space-4);
  top: -60px;
  z-index: var(--z-toast);
  background: var(--primary);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius);
  transition: top var(--duration) var(--ease);
}
.skip-link:focus { top: var(--space-4); color: #fff; }

/* --- App shell ----------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.app.is-collapsed { grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr); }

.sidebar {
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: var(--z-sticky);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-height);
}

.sidebar__logo {
  width: 38px; height: 38px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: var(--text-md);
  flex: none;
  overflow: hidden;
}
.sidebar__logo img { width: 100%; height: 100%; object-fit: cover; }

.sidebar__title { font-size: var(--text-md); font-weight: 700; line-height: 1.3; }
.sidebar__subtitle { font-size: var(--text-xs); color: var(--muted); }

.sidebar__nav { padding: var(--space-4) var(--space-3); flex: 1; }

.sidebar__section {
  font-size: var(--text-xs);
  color: var(--muted-2);
  font-weight: 600;
  padding: var(--space-4) var(--space-3) var(--space-2);
  letter-spacing: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: var(--text-base);
  font-weight: 500;
  margin-bottom: 2px;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
  position: relative;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.is-active::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: var(--radius-full);
  background: var(--primary);
}
.nav-item__icon { flex: none; width: 20px; height: 20px; opacity: 0.85; }
.nav-item.is-active .nav-item__icon { opacity: 1; }
.nav-item__badge {
  margin-inline-start: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
}

.app.is-collapsed .sidebar__title,
.app.is-collapsed .sidebar__subtitle,
.app.is-collapsed .nav-item span:not(.nav-item__badge),
.app.is-collapsed .sidebar__section { display: none; }
.app.is-collapsed .nav-item { justify-content: center; }

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

.topbar {
  height: var(--topbar-height);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.topbar__toggle,
.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-2);
  position: relative;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.icon-btn__dot {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 2px solid var(--surface);
}

.page {
  padding: var(--space-6);
  max-width: var(--container);
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  flex: 1;
}

.page__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.page__title { font-size: var(--text-2xl); font-weight: 700; }
.page__subtitle { color: var(--muted); font-size: var(--text-base); margin-top: var(--space-1); }
.page__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--muted);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }
/* The separator flips with the writing direction. */
.breadcrumb__sep { opacity: 0.5; }
[dir='rtl'] .breadcrumb__sep::before { content: '‹'; }
[dir='ltr'] .breadcrumb__sep::before { content: '›'; }

/* --- Search ------------------------------------------------------------- */

.search {
  position: relative;
  flex: 1;
  max-width: 420px;
}
.search__input {
  width: 100%;
  height: 40px;
  padding-inline: 40px var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
.search__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
  background: var(--surface);
}
.search__icon {
  position: absolute;
  inset-inline-start: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search__results {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  display: none;
  padding: var(--space-2);
}
.search__results.is-open { display: block; }
.search__group-title {
  font-size: var(--text-xs);
  color: var(--muted-2);
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
}
.search__result {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--text-base);
}
.search__result:hover, .search__result.is-highlighted { background: var(--surface-hover); }
.search__result small { color: var(--muted); font-size: var(--text-xs); margin-inline-start: auto; }

/* --- Cards --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card--flush { padding: 0; }
.card__body { padding: var(--space-5); }
.card__header {
  padding: var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.card__title { font-size: var(--text-md); font-weight: 600; }
.card__subtitle { font-size: var(--text-sm); color: var(--muted); margin-top: 2px; }
.card__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-end-start-radius: var(--radius-lg);
  border-end-end-radius: var(--radius-lg);
}

.card--interactive {
  transition: transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease),
              border-color var(--duration) var(--ease);
}
.card--interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}

/* --- Stat tiles ---------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
}
.stat__label { font-size: var(--text-sm); color: var(--muted); margin-bottom: var(--space-2); }
.stat__value { font-size: var(--text-3xl); font-weight: 800; line-height: 1.1; letter-spacing: 0; }
.stat__unit { font-size: var(--text-base); font-weight: 500; color: var(--muted); margin-inline-start: 4px; }
.stat__meta { font-size: var(--text-xs); color: var(--muted); margin-top: var(--space-2); }
.stat__delta { font-weight: 600; font-size: var(--text-sm); }
.stat__delta--up { color: var(--success); }
.stat__delta--down { color: var(--danger); }
.stat__delta--neutral { color: var(--muted); }
.stat__icon {
  position: absolute;
  inset-inline-end: var(--space-4);
  top: var(--space-4);
  width: 36px; height: 36px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
}

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-5);
  height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease), transform var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
.btn:hover { background: var(--primary-hover); color: #fff; box-shadow: var(--shadow-primary); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn[disabled], .btn.is-disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }

.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--secondary:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }

.btn--ghost { background: transparent; color: var(--muted); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); box-shadow: none; }

.btn--danger { background: var(--danger); }
.btn--danger:hover { background: #cf3f4b; box-shadow: 0 8px 24px rgba(227, 77, 89, 0.24); }

.btn--success { background: var(--success); }
.btn--success:hover { background: #128757; box-shadow: 0 8px 24px rgba(22, 163, 106, 0.24); }

.btn--soft { background: var(--primary-soft); color: var(--primary); }
.btn--soft:hover { background: var(--primary-border); color: var(--primary); box-shadow: none; }

.btn--sm { height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn--lg { height: 48px; padding: 0 var(--space-6); font-size: var(--text-md); border-radius: var(--radius-md); }
.btn--block { width: 100%; }
.btn--icon { width: 40px; padding: 0; }

/* --- Forms --------------------------------------------------------------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4) var(--space-5);
}
.form-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field--full { grid-column: 1 / -1; }

.field { margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--text-2);
}
.label__optional { font-weight: 400; color: var(--muted-2); font-size: var(--text-xs); }
.label__required { color: var(--danger); margin-inline-start: 2px; }

.input, .select, .textarea {
  width: 100%;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input[readonly], .input[disabled] { background: var(--bg-subtle); color: var(--muted); cursor: not-allowed; }

.textarea { min-height: 96px; resize: vertical; line-height: var(--leading); }

.select {
  appearance: none;
  /* The chevron sits on the trailing edge in either direction. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23777781' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left var(--space-3) center;
  padding-inline-end: var(--space-3);
  padding-inline-start: var(--space-8);
}
[dir='ltr'] .select {
  background-position: right var(--space-3) center;
  padding-inline-start: var(--space-3);
  padding-inline-end: var(--space-8);
}

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea { border-color: var(--danger); }

.field__error { color: var(--danger); font-size: var(--text-xs); margin-top: var(--space-2); }
.field__hint { color: var(--muted); font-size: var(--text-xs); margin-top: var(--space-2); line-height: 1.7; }

.input-group { display: flex; align-items: stretch; }
.input-group .input { border-start-end-radius: 0; border-end-end-radius: 0; }
.input-group__addon {
  display: grid;
  place-items: center;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-inline-start: none;
  border-start-end-radius: var(--radius);
  border-end-end-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--muted);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.checkbox, .radio {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  padding: var(--space-1) 0;
  font-size: var(--text-base);
}
.checkbox input, .radio input {
  width: 18px; height: 18px;
  accent-color: var(--primary);
  margin-top: 3px;
  flex: none;
  cursor: pointer;
}

.choice-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.choice-card:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.choice-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice-card b { display: block; font-size: var(--text-base); font-weight: 600; }
.choice-card span { font-size: var(--text-xs); color: var(--muted); line-height: 1.7; }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  user-select: none;
}
.chip:hover { border-color: var(--border-strong); }
.chip input { display: none; }
.chip:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: none; }
.switch-row b { display: block; font-size: var(--text-base); font-weight: 600; }
.switch-row span { font-size: var(--text-xs); color: var(--muted); }

.switch { position: relative; width: 44px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__track {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--duration) var(--ease);
}
.switch__track::before {
  content: '';
  position: absolute;
  width: 19px; height: 19px;
  inset-inline-start: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--duration) var(--ease);
  box-shadow: var(--shadow-xs);
}
.switch input:checked + .switch__track { background: var(--primary); }
/* Logical translation: the knob travels toward the inline end either way. */
[dir='rtl'] .switch input:checked + .switch__track::before { transform: translateX(-19px); }
[dir='ltr'] .switch input:checked + .switch__track::before { transform: translateX(19px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--ring); }

/* Range slider used by the 1–10 check-in scales. */
.scale { display: flex; align-items: center; gap: var(--space-3); }
.scale input[type='range'] { flex: 1; accent-color: var(--primary); height: 24px; }
.scale__value {
  min-width: 44px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

/* --- Tables -------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
  /* Floor so a many-column data table scrolls inside .table-wrap instead of
     crushing its columns. Tables with two or three columns don't need it. */
  min-width: 560px;
}

.table--fit { min-width: 0; }
.table th {
  text-align: start;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--duration-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-hover); }
.table__num { font-variant-numeric: tabular-nums; }
.table__actions { display: flex; gap: var(--space-1); justify-content: flex-end; }

.table--compact th, .table--compact td { padding: var(--space-2) var(--space-3); }

/* --- Badges and pills ---------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg-subtle);
  color: var(--muted);
}
.badge--primary { background: var(--primary-soft); color: var(--primary); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* --- Avatars ------------------------------------------------------------- */

.avatar {
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: var(--text-sm);
  flex: none;
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 32px; height: 32px; font-size: var(--text-xs); }
.avatar--lg { width: 56px; height: 56px; font-size: var(--text-lg); }
.avatar--xl { width: 88px; height: 88px; font-size: var(--text-2xl); border-radius: var(--radius-lg); }

.user-cell { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.user-cell__name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-cell__meta { font-size: var(--text-xs); color: var(--muted); }

/* --- Alerts -------------------------------------------------------------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid;
  font-size: var(--text-base);
  margin-bottom: var(--space-4);
  line-height: var(--leading);
}
.alert__icon { flex: none; margin-top: 2px; }
.alert--info { background: var(--info-soft); border-color: rgba(45, 128, 210, 0.24); color: #1f5f9e; }
.alert--success { background: var(--success-soft); border-color: rgba(22, 163, 106, 0.24); color: #0f7a4f; }
.alert--warning { background: var(--warning-soft); border-color: rgba(217, 130, 18, 0.24); color: #96590a; }
.alert--danger { background: var(--danger-soft); border-color: rgba(227, 77, 89, 0.24); color: #a32732; }
[data-theme='dark'] .alert--info { color: var(--info); }
[data-theme='dark'] .alert--success { color: var(--success); }
[data-theme='dark'] .alert--warning { color: var(--warning); }
[data-theme='dark'] .alert--danger { color: var(--danger); }

.alert--disclaimer {
  background: var(--bg-subtle);
  border-color: var(--border);
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.9;
}

/* --- Empty state --------------------------------------------------------- */

.empty {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--muted);
}
.empty__icon {
  width: 64px; height: 64px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  display: grid;
  place-items: center;
  color: var(--muted-2);
}
.empty__title { font-size: var(--text-md); font-weight: 600; color: var(--text); margin-bottom: var(--space-2); }
.empty__text { font-size: var(--text-base); max-width: 380px; margin: 0 auto var(--space-5); line-height: var(--leading); }

/* --- Tabs ---------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: var(--space-3) var(--space-4);
  color: var(--muted);
  font-size: var(--text-base);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
  cursor: pointer;
  background: none;
  border-inline: none;
  border-top: none;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* --- Modal --------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.modal.is-open { display: flex; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 23, 27, 0.45);
  backdrop-filter: blur(3px);
  animation: fade-in var(--duration) var(--ease);
}
.modal__dialog {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modal-in var(--duration-slow) var(--ease);
}
.modal__dialog--lg { max-width: 860px; }
.modal__dialog--xl { max-width: 1100px; }
.modal__header {
  padding: var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.modal__body { padding: var(--space-5); overflow-y: auto; flex: 1; }
.modal__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* --- Drawer (mobile navigation, exercise picker) ------------------------- */

.drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  display: none;
}
.drawer.is-open { display: block; }
.drawer__backdrop { position: absolute; inset: 0; background: rgba(23, 23, 27, 0.42); }
.drawer__panel {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: min(320px, 86vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  animation: drawer-in var(--duration-slow) var(--ease);
}
@keyframes drawer-in {
  from { transform: translateX(var(--drawer-from, -100%)); }
  to { transform: none; }
}
[dir='rtl'] .drawer__panel { --drawer-from: 100%; }

/* --- Toast --------------------------------------------------------------- */

.toasts {
  position: fixed;
  bottom: var(--space-5);
  inset-inline-end: var(--space-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3) var(--space-4);
  min-width: 260px;
  max-width: 380px;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-size: var(--text-base);
  animation: toast-in var(--duration-slow) var(--ease);
  pointer-events: auto;
  border-inline-start: 3px solid var(--primary);
}
.toast--success { border-inline-start-color: var(--success); }
.toast--error { border-inline-start-color: var(--danger); }
.toast--warning { border-inline-start-color: var(--warning); }
.toast.is-leaving { animation: toast-out var(--duration) var(--ease) forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* --- Dropdown ------------------------------------------------------------ */

.dropdown { position: relative; }
.dropdown__menu {
  position: absolute;
  top: calc(100% + 6px);
  /* Anchored to the inline end so it never spills off-screen in RTL. */
  inset-inline-end: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  z-index: var(--z-dropdown);
  display: none;
  animation: fade-in var(--duration-fast) var(--ease);
}
.dropdown__menu.is-open { display: block; }
.dropdown__menu--wide { min-width: 320px; }
.dropdown__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: var(--text-base);
  width: 100%;
  text-align: start;
  background: none;
  border: none;
  cursor: pointer;
}
.dropdown__item:hover { background: var(--surface-hover); color: var(--text); }
.dropdown__item--danger { color: var(--danger); }
.dropdown__item--danger:hover { background: var(--danger-soft); color: var(--danger); }
.dropdown__divider { height: 1px; background: var(--border); margin: var(--space-2) 0; }
.dropdown__header {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  margin: calc(var(--space-2) * -1) calc(var(--space-2) * -1) var(--space-2);
  font-weight: 600;
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* --- Progress ------------------------------------------------------------ */

.progress {
  height: 8px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease);
}
.progress--success .progress__bar { background: var(--success); }
.progress--warning .progress__bar { background: var(--warning); }
.progress--danger .progress__bar { background: var(--danger); }

/* --- Form-check videos ---------------------------------------------------- */

.fv { display: flex; flex-direction: column; gap: var(--space-3); }
.fv__player {
  width: 100%;
  max-height: 70vh;
  border-radius: var(--radius-lg);
  background: #000;
  display: block;
}
.fv__missing {
  padding: var(--space-6);
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
}
.fv__meta { min-width: 0; }
.fv__reply {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px dashed var(--border);
}

/* Installed as an app: keep the bars clear of the notch and the home indicator. */
@media (display-mode: standalone) {
  .topbar { padding-top: max(var(--space-3), env(safe-area-inset-top, 0px)); }
  .page { padding-bottom: max(var(--space-8), calc(env(safe-area-inset-bottom, 0px) + var(--space-6))); }
  .sidebar { padding-top: max(var(--space-4), env(safe-area-inset-top, 0px)); }
}

/* Weekly sets per muscle */
.mvol { display: flex; flex-direction: column; gap: var(--space-2); }
.mvol__row {
  display: grid;
  grid-template-columns: minmax(0, 7.5rem) minmax(0, 1fr) 2.5rem;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}
.mvol__track {
  position: relative;
  height: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.mvol__band { position: absolute; top: 0; bottom: 0; background: var(--success-soft); }
.mvol__bar {
  position: absolute;
  top: 0;
  bottom: 0;
  inset-inline-start: 0;
  border-radius: var(--radius-full);
  background: var(--success);
}
.mvol__bar--low { background: var(--info); }
.mvol__bar--high { background: var(--warning); }
.mvol__value { text-align: end; font-weight: 600; }
.mvol__legend { margin: var(--space-4) 0 0; font-size: var(--text-xs); color: var(--muted); line-height: 1.9; }

.ring {
  --ring-size: 88px;
  --ring-thickness: 8px;
  width: var(--ring-size);
  height: var(--ring-size);
  position: relative;
  flex: none;
}
.ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring__track { fill: none; stroke: var(--bg-subtle); }
.ring__value { fill: none; stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset var(--duration-slow) var(--ease); }
.ring__label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: var(--text-md);
}

/* --- Charts (server-rendered SVG) ---------------------------------------- */

/* An inline SVG with a viewBox carries an intrinsic width, which becomes its
   min-content contribution and can force a grid or flex track wider than the
   screen. min-width:0 lets it shrink to whatever it is given. */
.chart { width: 100%; min-width: 0; height: auto; display: block; overflow: visible; }
.chart text { font-family: var(--font); }
.chart circle { transition: r var(--duration-fast) var(--ease); }
.chart circle:hover { r: 6; }

.chart-empty {
  display: grid;
  place-items: center;
  color: var(--muted-2);
  font-size: var(--text-sm);
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.sparkline { width: 100%; height: 32px; display: block; opacity: 0.9; }

/* --- Check list (system health) ------------------------------------------ */

.checklist { list-style: none; margin: 0; padding: 0; }

.checklist__item {
  padding: var(--space-3) var(--space-5);
  border-block-start: 1px solid var(--border);
}
.checklist__item:first-child { border-block-start: 0; }

.checklist__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.checklist__label { font-size: var(--text-sm); }

.checklist__value {
  margin-block-start: 2px;
  font-size: var(--text-xs);
  color: var(--muted);
  /* Version strings and paths have no spaces to break on. */
  overflow-wrap: anywhere;
}

.chart-legend { display: flex; gap: var(--space-4); flex-wrap: wrap; font-size: var(--text-xs); color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: var(--space-2); }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* --- Pagination ---------------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-5);
  flex-wrap: wrap;
}
.pagination__info { font-size: var(--text-sm); color: var(--muted); }
.pagination__pages { display: flex; gap: var(--space-1); }
.pagination__page {
  min-width: 36px; height: 36px;
  padding: 0 var(--space-2);
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.pagination__page:hover { background: var(--surface-hover); color: var(--text); }
.pagination__page.is-active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pagination__page.is-disabled { opacity: 0.4; pointer-events: none; }

/* --- Filters bar --------------------------------------------------------- */

.filters {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.filters .field { margin-bottom: 0; flex: 1; min-width: 150px; }
.filters__actions { display: flex; gap: var(--space-2); }

/* --- Workout day (shared by coach, portal, share page and print) --------- */

.wday {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  overflow: hidden;
}
.wday--rest { background: var(--surface-2); border-style: dashed; }

.wday__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.wday--rest .wday__header { border-bottom: none; }
.wday__title { font-size: var(--text-md); font-weight: 700; }
.wday__weekday { font-size: var(--text-xs); color: var(--muted); }
.wday__meta { font-size: var(--text-sm); color: var(--muted); white-space: nowrap; }
.wday__rest { padding: var(--space-6); text-align: center; color: var(--muted); margin: 0; }
.wday__notes {
  margin: 0;
  padding: var(--space-4) var(--space-5);
  border-top: 1px dashed var(--border);
  font-size: var(--text-sm);
  color: var(--muted);
  white-space: pre-line;
}

.wday__groups { padding: var(--space-2); }

.wgroup { border-radius: var(--radius-md); }
.wgroup--superset, .wgroup--giant, .wgroup--circuit, .wgroup--dropset {
  border: 1px solid var(--primary-border);
  background: var(--primary-soft);
  padding: var(--space-2);
  margin: var(--space-2);
}
.wgroup--giant { border-color: rgba(217, 130, 18, 0.3); background: var(--warning-soft); }
.wgroup--circuit { border-color: rgba(22, 163, 106, 0.3); background: var(--success-soft); }
.wgroup--dropset { border-color: rgba(227, 77, 89, 0.3); background: var(--danger-soft); }

.wgroup__label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--primary);
  padding: var(--space-1) var(--space-3) var(--space-2);
}
.wgroup--giant .wgroup__label { color: var(--warning); }
.wgroup--circuit .wgroup__label { color: var(--success); }
.wgroup--dropset .wgroup__label { color: var(--danger); }

.wex {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--surface);
}
.wgroup .wex + .wex { margin-top: var(--space-1); }
.wday__groups > .wgroup:not([class*='wgroup--']) .wex { border-bottom: 1px dashed var(--border); border-radius: 0; }

.wex__label {
  flex: none;
  min-width: 30px;
  height: 26px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--text-xs);
  font-weight: 800;
  display: grid;
  place-items: center;
}

.wex__body { flex: 1; min-width: 0; }
.wex__name { font-weight: 600; font-size: var(--text-base); }
.wex__name small { display: block; font-weight: 400; font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }
.wex__tags { display: flex; gap: var(--space-1); flex-wrap: wrap; margin-top: var(--space-2); }
.wex__note {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
  color: var(--muted);
  line-height: 1.9;
  border-inline-start: 2px solid var(--border-strong);
  padding-inline-start: var(--space-2);
}

.wex__numbers { text-align: end; flex: none; }
.wex__sets { display: block; font-weight: 700; font-size: var(--text-md); font-variant-numeric: tabular-nums; }
.wex__weight { display: block; font-size: var(--text-sm); color: var(--primary); font-weight: 600; }
.wex__rest { display: block; font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }

@media (max-width: 560px) {
  .wex { flex-wrap: wrap; }
  .wex__numbers { text-align: start; width: 100%; padding-inline-start: 42px; }
  .wex__sets { display: inline; }
  .wex__weight, .wex__rest { display: inline; margin-inline-start: var(--space-3); }
}

/* --- Meal card (read-only, shared across contexts) ----------------------- */

.mealview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  overflow: hidden;
}
.mealview--done { border-color: rgba(22, 163, 106, 0.35); background: var(--success-soft); }

.mealview__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.mealview--done .mealview__header { background: transparent; }

.mealview__title { display: flex; align-items: center; gap: var(--space-3); }
.mealview__title h3 { font-size: var(--text-md); font-weight: 700; }
.mealview__time { font-size: var(--text-xs); color: var(--muted); }

.mealview__check {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
  transition: all var(--duration-fast) var(--ease);
}
.mealview__check[aria-pressed='true'] {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.mealview__macros { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.mealview__items { padding: var(--space-2) var(--space-3); }
.mealview__item {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px dashed var(--border);
}
.mealview__item:last-child { border-bottom: none; }
.mealview__amount { font-weight: 700; min-width: 92px; flex: none; font-size: var(--text-sm); }
.mealview__food { flex: 1; min-width: 0; }
.mealview__kcal { font-size: var(--text-xs); color: var(--muted); flex: none; }

.mealview__alts {
  margin: 0 var(--space-3) var(--space-3);
  padding: var(--space-3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.mealview__alts-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--muted);
  display: block;
  margin-bottom: var(--space-2);
}
.mealview__alts li { font-size: var(--text-sm); padding: var(--space-1) 0; }
.mealview__alts li small { color: var(--muted); font-size: var(--text-xs); margin-inline-start: var(--space-2); }

.mealview__empty { padding: var(--space-5); text-align: center; color: var(--muted); margin: 0; }
.mealview__note {
  margin: 0;
  padding: var(--space-3) var(--space-5);
  border-top: 1px dashed var(--border);
  font-size: var(--text-sm);
  color: var(--muted);
}

@media (max-width: 560px) {
  .mealview__item { flex-wrap: wrap; }
  .mealview__amount { min-width: 0; }
  .mealview__kcal { width: 100%; }
}

/* --- Utilities ----------------------------------------------------------- */

/* A bare `1fr` track has an automatic minimum of min-content, so one wide child
   — a chart SVG, a long table — drags the whole track past the viewport and the
   page scrolls sideways. `minmax(0, …)` lets the track be narrower than its
   content, and `min(Npx, 100%)` stops a fixed floor from exceeding a narrow
   screen. Grid items need min-width:0 for the same reason. */
.grid { display: grid; gap: var(--space-4); }
.grid > * { min-width: 0; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 0; }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-muted { color: var(--muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-center { text-align: center; }
.text-end { text-align: end; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.nums { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Directional icons (chevrons, arrows) mirror with the writing direction. */
[dir='rtl'] .icon-flip { transform: scaleX(-1); }

.hidden { display: none !important; }
.divider { height: 1px; background: var(--border); margin: var(--space-5) 0; }
.dir-ltr { direction: ltr; text-align: start; }

/* --- Sales funnel -------------------------------------------------------- */

.funnel { display: flex; flex-direction: column; gap: var(--space-3); }

.funnel__row {
  display: grid;
  grid-template-columns: minmax(110px, 160px) 1fr auto;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}

.funnel__bar {
  background: var(--bg-subtle);
  border-radius: var(--radius);
  height: 22px;
  overflow: hidden;
}

.funnel__bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: var(--radius);
}

.funnel__value { font-weight: 700; min-width: 3ch; text-align: end; }

@media (max-width: 560px) {
  .funnel__row { grid-template-columns: 1fr auto; }
  .funnel__bar { grid-column: 1 / -1; order: 2; }
}

/* --- Two-factor set-up --------------------------------------------------- */

/* The setup key is read character by character off the screen, so it is spaced
   and monospaced rather than pretty. */
.secret-key {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: var(--text-lg);
  letter-spacing: 0.08em;
  background: var(--bg-subtle);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  user-select: all;
  word-break: break-all;
}

/* QR for the authenticator app. White stays white in dark mode: a scanner
   needs the real contrast, not the theme's. */
.qr-box {
  display: inline-block;
  background: #fff;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.qr-box svg { display: block; width: 180px; height: 180px; }

.recovery-codes {
  list-style: none;
  margin: var(--space-4) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-2);
}

.recovery-codes li {
  font-family: ui-monospace, Consolas, monospace;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  text-align: center;
  font-size: var(--text-sm);
  user-select: all;
}

.steps { padding-inline-start: 20px; line-height: 2.1; font-size: var(--text-sm); }
.steps li { margin-bottom: var(--space-2); }

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 1100px) {
  .grid--sidebar { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(300px, 86vw);
    transform: translateX(var(--sidebar-hidden, -100%));
    transition: transform var(--duration-slow) var(--ease),
                visibility var(--duration-slow) var(--ease);
    z-index: var(--z-drawer);

    /* Parked off-canvas. Without this the drawer still counts as painted
       content past the edge of the page and the whole document scrolls
       sideways — in RTL it is parked to the right, where it is most visible. */
    visibility: hidden;
  }
  [dir='rtl'] .sidebar { --sidebar-hidden: 100%; }
  .app.is-nav-open .sidebar { transform: none; visibility: visible; }
  .app.is-nav-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(23, 23, 27, 0.42);
    z-index: calc(var(--z-drawer) - 1);
  }
  .page { padding: var(--space-4); }
  .form-grid--2, .form-grid--3 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .page__header { flex-direction: column; align-items: stretch; }
  .page__actions .btn { flex: 1; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: var(--space-3); }
  .stat { padding: var(--space-4); }
  .stat__value { font-size: var(--text-2xl); }
  .modal__dialog { max-height: 94vh; }
  .toasts { inset-inline: var(--space-4); bottom: var(--space-4); }
  .toast { min-width: 0; max-width: none; }
  .topbar { padding-inline: var(--space-3); gap: var(--space-2); }
}

/* Smallest phones: five controls plus a name do not fit across 320px. The
   avatar still identifies the account, so the name is what gives way. */
@media (max-width: 420px) {
  .topbar__username { display: none; }
}

/* --- Print --------------------------------------------------------------- */

@media print {
  .sidebar, .topbar, .page__actions, .btn, .no-print, .bottom-nav { display: none !important; }
  .app { grid-template-columns: 1fr; }
  body { background: #fff; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ddd; }
}
