/* fitsel app — shared component styles. Uses only tokens.css custom properties. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--color-bg); color: var(--color-text);
  font-family: var(--font-body); font-weight: var(--weight-light); font-size: var(--text-base);
  line-height: var(--leading-normal); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
h1, h2, h3, p, ol, ul, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--color-primary-ink); }
a:hover { color: var(--color-text); }
::selection { background: var(--color-highlight); color: var(--color-on-highlight); }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--color-text-muted); }

/* ---------- Type ---------- */
.page-title { font-size: var(--text-3xl); font-weight: var(--weight-thin); letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
.panel-title { font-size: var(--text-2xl); font-weight: var(--weight-thin); line-height: var(--leading-tight); }
.eyebrow { font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--color-text-muted); font-weight: var(--weight-regular); }
.caption { font-size: var(--text-xs); color: var(--color-text-muted); }
.big-number { font-size: var(--text-4xl); font-weight: var(--weight-thin); letter-spacing: -0.03em; line-height: 1; }
.unit { font-size: var(--text-2xs); color: var(--color-text-muted); margin-left: 2px; }

/* ---------- AppShell ---------- */
.app { min-height: 100vh; display: grid; grid-template-columns: 1fr; grid-template-rows: auto 1fr; padding-bottom: var(--size-tabbar); }
.app-header { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-2) 0 var(--space-4); }
.brand { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-lg); font-weight: var(--weight-regular); color: var(--color-text); text-decoration: none; }
.brand img { width: 20px; height: 20px; }
.app-header .btn--icon { margin-left: auto; }
.main { min-width: 0; }
.page { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.page__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

/* SideNav (tablet rail / desktop sidebar) */
.sidenav { display: none; }
.sidenav__list { display: flex; flex-direction: column; gap: var(--space-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--space-2-5); min-height: var(--size-control); padding: 0 var(--space-3);
  border-radius: 10px; color: var(--color-text); text-decoration: none; font-size: var(--text-base); font-weight: var(--weight-regular);
  transition: background var(--duration-fast);
}
.nav-item:hover { background: var(--color-highlight); color: var(--color-on-highlight); }
.nav-item[aria-current="page"] { background: var(--color-primary); color: var(--color-on-primary); }
.nav-item svg { flex: none; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; margin-left: auto; background: var(--color-primary-ink); }
.status-dot[data-status="sample"] { background: var(--color-text-faint); }
.status-dot[data-status="disconnected"] { background: var(--color-highlight); }

/* TabBar (phone) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-tabbar); height: var(--size-tabbar);
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-1); padding: 6px var(--space-2) var(--space-2);
  background: var(--color-bg); border-top: 1px solid var(--color-border);
}
.tabbar .nav-item { flex-direction: column; justify-content: center; gap: 2px; padding: 0; font-size: var(--text-xs); min-height: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: flex-start; gap: var(--space-2);
  min-height: var(--size-control); padding: 0 var(--space-4); border-radius: var(--radius-lg);
  border: 1px solid transparent; background: transparent; cursor: pointer; white-space: nowrap;
  font-size: var(--text-md); font-weight: var(--weight-regular); text-decoration: none; color: var(--color-text);
  transition: background var(--duration-fast), border-color var(--duration-fast);
}
.btn--primary { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-border); }
.btn--primary:hover, .btn--primary.is-hover { background: var(--color-highlight); color: var(--color-on-highlight); }
.btn--primary:active { background: var(--color-text); color: var(--color-bg); }
.btn--secondary { background: var(--color-surface); border-color: var(--color-border); }
.btn--secondary:hover, .btn--secondary.is-hover { background: var(--color-highlight); color: var(--color-on-highlight); }
.btn--ghost { color: var(--color-primary-ink); padding: 0 var(--space-2); }
.btn--ghost:hover, .btn--ghost.is-hover { background: var(--color-highlight); color: var(--color-on-highlight); }
.btn--icon { justify-content: center; width: var(--size-tap); min-height: var(--size-tap); padding: 0; }
.btn--icon:hover { background: var(--color-highlight); color: var(--color-on-highlight); }
.btn--lg { min-height: 48px; font-size: var(--text-base); padding: 0 18px; }
.btn--block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
.is-focus { outline: 2px solid var(--color-focus); outline-offset: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.badge-count { min-width: 20px; height: 20px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--color-primary); color: var(--color-on-primary); font-size: var(--text-2xs); }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-1-5); min-width: 0; }
.field > label, .field__label { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-muted); }
.input {
  width: 100%; min-height: var(--size-tap); padding: 0 var(--space-3); border-radius: var(--radius-lg);
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); font-weight: var(--weight-light);
}
.input::placeholder { color: var(--color-text-faint); }
.input:hover { border-color: var(--color-text-muted); }
.input:focus-visible, .input.is-focus { outline: none; border-color: var(--color-focus); box-shadow: 0 0 0 1px var(--color-focus); }
.input[aria-invalid="true"] { border-color: var(--color-text); background: var(--color-error-bg); color: var(--color-error-text); }
.input:disabled { opacity: .45; cursor: not-allowed; }
.input--mono { font-family: var(--font-mono); font-size: var(--text-sm); }
textarea.input { min-height: 100px; padding: var(--space-3); resize: vertical; line-height: var(--leading-normal); }
select.input { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.field__error { font-size: var(--text-sm); color: var(--color-text); }
.input-row { display: flex; gap: var(--space-1-5); align-items: stretch; }
.search { position: relative; flex: 1; min-width: 0; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--color-text-muted); pointer-events: none; }
.search .input { padding-left: 40px; }

/* SegmentedControl */
.seg { display: inline-flex; gap: 3px; padding: 3px; background: var(--color-surface-sunken); border-radius: var(--radius-lg); max-width: 100%; overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
.seg__opt { flex: none; min-height: 36px; padding: 0 var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent; cursor: pointer; font-size: var(--text-md); font-weight: var(--weight-regular); color: var(--color-text); white-space: nowrap; }
.seg__opt:hover { background: var(--color-highlight); color: var(--color-on-highlight); }
.seg__opt[aria-pressed="true"], .seg__opt[aria-selected="true"], .seg__opt[aria-current="page"] { background: var(--color-primary); color: var(--color-on-primary); }
a.seg__opt { display: inline-flex; align-items: center; text-decoration: none; }
.seg--full { display: flex; }
.seg--full .seg__opt { flex: 1; }

/* FilterChip */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-1-5); }
.chip { min-height: var(--size-control-sm); padding: 0 var(--space-2-5); display: inline-flex; align-items: center; gap: var(--space-1-5); border-radius: 10px; border: 1px solid var(--color-border); background: transparent; cursor: pointer; font-size: var(--text-sm); font-weight: var(--weight-regular); color: var(--color-text); }
.chip:hover { border-color: var(--color-border-strong); }
.chip[aria-pressed="true"] { background: var(--color-primary); color: var(--color-on-primary); border-color: var(--color-border); }
.chip--removable { background: var(--color-surface-sunken); border-color: transparent; font-family: var(--font-mono); font-size: var(--text-xs); min-height: 26px; }

.tag { display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px var(--space-2); border-radius: var(--radius-lg); font-family: var(--font-mono); font-size: var(--text-2xs); white-space: nowrap; background: var(--color-surface-sunken); color: var(--color-text-secondary); }
.tag--primary { background: var(--color-primary); color: var(--color-on-primary); }
.tag--outline { background: transparent; border: 1px solid var(--color-border); }
.code { font-family: var(--font-mono); font-size: var(--text-sm); background: var(--color-surface-sunken); padding: 1px 6px; border-radius: var(--radius-sm); }
.sport-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.sport-dot--run { background: var(--color-sport-run); }
.sport-dot--ride { background: var(--color-sport-ride); }
.sport-dot--swim { background: var(--color-sport-swim); }
.sport-dot--strength { background: var(--color-sport-strength); }
.series-1 { --series: var(--color-series-1); }
.series-2 { --series: var(--color-series-2); }
.series-3 { --series: var(--color-series-3); }
.series-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--series); flex: none; }

/* ---------- Card ---------- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-4); min-width: 0; }
.card--flush { padding: 0; overflow: hidden; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); flex-wrap: wrap; }

/* ---------- WeekSummary ---------- */
.week { background: var(--color-primary); color: #1c2118; border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-4) 0; overflow: hidden; }
.week .eyebrow { color: #4a5244; }
.week .btn--ghost { color: #1c2118; }
.week__head { display: flex; justify-content: space-between; align-items: baseline; }
.week__total { display: flex; align-items: baseline; gap: var(--space-2-5); flex-wrap: wrap; margin: 2px 0 var(--space-2-5); }
.week__delta { font-size: var(--text-sm); color: #4a5244; }
.week__sports { display: grid; grid-template-columns: repeat(4, 1fr); margin: var(--space-3) calc(-1 * var(--space-4)) 0; padding: var(--space-2) 0 var(--space-3) var(--space-4); background: #ffffff; border-top: 1px solid #c4ccb8; color: #1c2118; }
.week__sport { display: flex; flex-direction: column; gap: 2px; padding-right: var(--space-2); }
.week__sport-label { display: flex; align-items: center; gap: var(--space-1-5); font-family: var(--font-mono); font-size: var(--text-2xs); color: #687061; }
.week__sport-main { font-size: var(--text-lg); font-weight: var(--weight-regular); }
.week__sport-sub { font-size: var(--text-2xs); color: #687061; }
.week .bar-chart__bar[data-sport="run"] { background: #3f6b00; }
.week .bar-chart__bar[data-sport="ride"] { background: #1c2118; }
.week .bar-chart__bar[data-sport="swim"] { background: #687061; }
.week .bar-chart__bar[data-sport="strength"] { background: #ffffff; }
.week .bar-chart__axis { border-color: #687061; }
.week .bar-chart__labels { color: #4a5244; }

/* ---------- Charts ---------- */
.chart { position: relative; }
.chart__plot { position: relative; touch-action: pan-y; cursor: crosshair; }
.chart__plot svg { display: block; width: 100%; overflow: visible; }
.chart__grid { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--color-chart-grid); }
.chart__ytick { position: absolute; left: 0; transform: translateY(-50%); font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-muted); background: var(--color-surface); padding-right: 4px; }
.chart__xticks { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-muted); margin-top: var(--space-1); }
.chart__area { position: absolute; top: 0; bottom: 0; left: 36px; right: 0; }
.chart__grid { left: 36px; }
.chart__plot--stream { height: 150px; }
.chart__plot--overlay { height: 170px; }
.chart__plot--trend { height: 110px; }
.chart__plot--route { height: 120px; }
.chart__plot--trend .chart__area, .chart__plot--route .chart__area { left: 0; }
.bar-chart--week .bar-chart__bars { height: 64px; }
.bar-chart--report .bar-chart__bars { height: 150px; }
.chart__cursor { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed var(--color-text); pointer-events: none; }
.chart__marker { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--color-primary); border: 1.5px solid var(--color-text); pointer-events: none; }
.chart__marker--ring { width: 20px; height: 20px; margin: -10px 0 0 -10px; background: transparent; }
.chart__note { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: var(--space-1-5); }
.line { fill: none; stroke: var(--color-chart-line); stroke-width: 1.75; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.line--avg { stroke: var(--color-text); stroke-dasharray: 6 4; stroke-width: 1; }
.line--series { stroke: var(--series); }
.area { fill: var(--color-chart-area); }

.bar-chart__bars { position: relative; display: grid; align-items: end; border-bottom: 1px solid var(--color-chart-axis); }
.bar-chart__col { position: relative; height: 100%; display: flex; flex-direction: column-reverse; align-items: center; gap: 1px; border-radius: var(--radius-xs); }
.bar-chart__col.is-active { background: color-mix(in srgb, currentColor 8%, transparent); }
.bar-chart__bar { width: 68%; border-radius: 2px; }
.bar-chart__bar[data-sport="run"] { background: var(--color-sport-run); }
.bar-chart__bar[data-sport="ride"] { background: var(--color-sport-ride); }
.bar-chart__bar[data-sport="swim"] { background: var(--color-sport-swim); }
.bar-chart__bar[data-sport="strength"] { background: var(--color-sport-strength); }
.bar-chart__labels { display: grid; font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-muted); margin-top: var(--space-1); text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-4); font-size: var(--text-sm); }
.legend li { display: flex; align-items: center; gap: var(--space-1-5); }

/* ChartTooltip */
.tooltip { position: absolute; z-index: var(--z-tooltip); width: var(--size-tooltip); padding: var(--space-2) var(--space-2-5); border-radius: 10px; background: var(--color-tooltip-bg); color: var(--color-tooltip-text); box-shadow: var(--shadow-tooltip); display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.tooltip__title { font-family: var(--font-mono); font-size: var(--text-2xs); opacity: .75; }
.tooltip__row { display: flex; align-items: center; gap: var(--space-1-5); font-size: var(--text-sm); white-space: nowrap; }
.tooltip__row span:nth-child(2) { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tooltip__swatch { width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px var(--color-tooltip-text); }
.tooltip__link { pointer-events: auto; margin-top: var(--space-1); color: var(--color-tooltip-link); font-size: var(--text-sm); background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }

/* ---------- MapView ---------- */
.map { position: relative; overflow: hidden; background: var(--color-surface-sunken); }
.map svg { display: block; width: 100%; height: 100%; }
.map__grid { stroke: var(--color-bg); stroke-width: 1; vector-effect: non-scaling-stroke; }
.map__casing { fill: none; stroke: var(--color-route-casing); stroke-width: 6; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.map__route { fill: none; stroke: var(--color-route); stroke-width: 3; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.map__start { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--color-text); border: 2px solid var(--color-bg); }
.map__credit { position: absolute; right: 0; bottom: 0; font-size: 9px; padding: 1px 4px; background: var(--color-bg); color: var(--color-text-muted); }

/* ---------- ActivityCard ---------- */
.feed { display: flex; flex-direction: column; gap: var(--space-3); }
.activity-card { display: block; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; color: inherit; text-decoration: none; cursor: pointer; }
.activity-card:hover, .activity-card.is-hover { border-color: var(--color-border-strong); }
.activity-card[aria-current="true"] { border-color: var(--color-border-strong); background: var(--color-surface-sunken); }
.activity-card__body { padding: var(--space-4) var(--space-4) var(--space-3); display: flex; flex-direction: column; gap: var(--space-2-5); }
.activity-card__title-row { display: flex; gap: var(--space-2-5); align-items: flex-start; }
.activity-card__title-row .sport-dot { margin-top: 8px; }
.activity-card__title { font-size: var(--text-lg); font-weight: var(--weight-regular); line-height: 1.3; }
.activity-card__meta { font-size: var(--text-xs); color: var(--color-text-muted); }
.activity-card__stats { display: flex; gap: var(--space-5); }
.stat__label { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-muted); }
.stat__value { font-size: var(--text-xl); font-weight: var(--weight-light); line-height: 1.2; }
.activity-card__visual { height: 150px; background: var(--color-surface-sunken); position: relative; }
.activity-card__visual--short { height: 72px; }
.activity-card--compact { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: var(--space-3); padding: var(--space-2); }
.activity-card--compact .activity-card__visual { height: 72px; border-radius: 8px; overflow: hidden; }
.activity-card--compact .activity-card__body { padding: 0; gap: var(--space-1); justify-content: center; }
.activity-card--compact .activity-card__title { font-size: var(--text-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-card--compact .activity-card__stats { gap: var(--space-3); font-size: var(--text-md); }
.activity-card--compact .sport-dot { width: 8px; height: 8px; margin-top: 7px; }
.visual-label { position: absolute; z-index: 1; left: 8px; top: 6px; font-family: var(--font-mono); font-size: 10px; color: var(--color-text-muted); }
.pace-bars { position: absolute; inset: 24px 0 0; display: flex; align-items: flex-end; gap: 2px; padding: 0 2px; }
.pace-bars span { flex: 1; background: var(--color-text-faint); border-radius: 1px 1px 0 0; }
/* The card's elevation profile and HR sparkline take the pace bars' chart area,
   below the label, so the line never runs over it (phone and wide cards). */
.elevation-profile, .hr-sparkline { position: absolute; inset: 24px 0 0; }

/* Skeleton (loading) */
.skeleton { background: var(--color-surface-sunken); border-radius: var(--radius-sm); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .skeleton, .btn[aria-busy="true"]::before { animation: none; } }

/* ActiveFilterBar */
.active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1-5); }
.active-filters__count { font-size: var(--text-sm); margin-right: var(--space-1); }

/* FilterPanel */
.filter-panel { display: flex; flex-direction: column; gap: var(--space-4); }
.filter-panel fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.filter-panel legend { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-muted); padding: 0; margin-bottom: var(--space-2); }
.filter-panel__head { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Detail ---------- */
.detail { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.detail__head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); flex-wrap: wrap; }
.detail__tags { display: flex; gap: var(--space-1-5); margin-bottom: var(--space-1-5); }
.detail__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.detail__map { height: 230px; border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.stat-grid > div { padding: var(--space-2-5) var(--space-3); box-shadow: inset -1px -1px 0 var(--color-border-subtle); }
.detail__lower { display: grid; gap: var(--space-4); }
.kv { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border-subtle); font-size: var(--text-md); }
.kv:last-child { border-bottom: 0; }
.kv dd { font-weight: var(--weight-regular); }

/* Table */
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th { text-align: left; font-family: var(--font-mono); font-weight: var(--weight-regular); font-size: var(--text-2xs); color: var(--color-text-muted); padding: var(--space-2) var(--space-2) var(--space-2) 0; border-bottom: 1px solid var(--color-border); }
.table td { padding: var(--space-2) var(--space-2) var(--space-2) 0; border-bottom: 1px solid var(--color-border-subtle); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.delta--better { color: var(--color-primary-ink); }
.delta--worse { color: var(--color-text-muted); }

/* ---------- Reports ---------- */
.period-nav { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.period-nav__label { font-size: var(--text-xl); font-weight: var(--weight-light); color: var(--color-text-secondary); }
.totals { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
.total__value { font-size: 28px; font-weight: var(--weight-thin); letter-spacing: var(--tracking-tight); line-height: 1.15; }
.total__delta { font-size: var(--text-xs); color: var(--color-text-muted); }
.total__delta--up { color: var(--color-primary-ink); }
.reports__lower { display: grid; gap: var(--space-3); }

/* ---------- Compare ---------- */
.compare { display: grid; gap: var(--space-3); align-content: start; }
.compare__aside { display: flex; flex-direction: column; gap: var(--space-2); }
.selected-activity { display: flex; align-items: center; gap: var(--space-2-5); padding: var(--space-2) var(--space-1) var(--space-2) var(--space-3); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.selected-activity__text { flex: 1; min-width: 0; }
.selected-activity__title { font-size: var(--text-base); font-weight: var(--weight-regular); }
.picker-list { display: flex; flex-direction: column; }
.picker-row { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: var(--space-2-5); align-items: center; padding: var(--space-2) var(--space-4); cursor: pointer; min-height: var(--size-tap); }
.picker-row:hover { background: var(--color-surface-sunken); }
.picker-row input { appearance: none; width: 16px; height: 16px; margin: 0; border-radius: var(--radius-xs); border: 1px solid var(--color-border); background: transparent; cursor: pointer; }
.picker-row input:checked { background: var(--color-primary); border-color: var(--color-text); }
.picker-row input:disabled { opacity: .45; }
.picker-row__title { display: block; font-size: var(--text-md); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-row__meta { font-size: var(--text-xs); color: var(--color-text-muted); }
.readouts { display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
.readout__at { display: flex; align-items: center; gap: var(--space-1-5); font-size: var(--text-xs); color: var(--color-text-muted); }
.readout__value { font-size: var(--text-2xl); font-weight: var(--weight-thin); }
.compare-table { display: grid; font-size: var(--text-md); }
.compare-table > * { padding: var(--space-2-5) var(--space-2) var(--space-2-5) 0; border-bottom: 1px solid var(--color-border-subtle); }
.compare-table > .th { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-muted); border-bottom-color: var(--color-border); }
.split-row { display: grid; grid-template-columns: 36px 1fr 64px; gap: var(--space-3); align-items: center; padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border-subtle); }
.split-row:last-child { border-bottom: 0; }
.split-bar { display: flex; align-items: center; gap: var(--space-2); }
.split-bar span:first-child { height: 10px; border-radius: 5px; background: var(--series); }
.split-bar span:last-child { font-family: var(--font-mono); font-size: var(--text-xs); }
.route-row { display: grid; grid-template-columns: 18px 1fr auto auto; gap: var(--space-2-5); align-items: center; padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border-subtle); font-size: var(--text-sm); min-height: var(--size-tap); }
.scatter { position: relative; height: 270px; border-left: 1px solid var(--color-chart-axis); border-bottom: 1px solid var(--color-chart-axis); margin-left: 40px; }
.scatter__dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; border: 2px solid transparent; }
.scatter__dot[data-selected="true"] { border-color: var(--color-text); width: 14px; height: 14px; margin: -7px 0 0 -7px; }
.scatter__ytick { position: absolute; left: -40px; width: 34px; text-align: right; transform: translateY(-50%); font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-muted); }
.scatter__xtick { position: absolute; bottom: -20px; transform: translateX(-50%); font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--color-text-muted); }
.axis-selects { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); align-items: end; }

/* ---------- Metrics ---------- */
.thresholds { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.metric-item { display: grid; grid-template-columns: 1fr auto; gap: var(--space-1) var(--space-3); padding: var(--space-3); border-radius: var(--radius-lg); color: inherit; text-decoration: none; }
.metric-item:hover { background: var(--color-surface-sunken); }
.metric-item[aria-current="true"] { background: var(--color-surface-sunken); }
.metric-item__name { font-size: var(--text-lg); font-weight: var(--weight-regular); }
.metric-item__value { text-align: right; font-size: var(--text-lg); }
.metric-item__expr { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-secondary); word-break: break-word; }
.metric-item__tags { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.editor { display: flex; flex-direction: column; gap: var(--space-4); }
.editor__bar { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.editor__cols { display: grid; gap: var(--space-4); align-items: start; }
.builder-step { display: grid; grid-template-columns: 64px minmax(0, 1fr) var(--size-control); gap: var(--space-1-5); align-items: center; margin-bottom: var(--space-1-5); }
.builder-step .input { min-height: var(--size-control); }
.formula-result { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-text-secondary); word-break: break-word; margin-top: var(--space-2-5); }
.insert-tokens { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.insert-tokens .chip { min-height: 28px; font-family: var(--font-mono); font-size: var(--text-2xs); border-radius: 8px; }
.editor__row { display: flex; gap: var(--space-4); flex-wrap: wrap; }

/* ---------- Settings ---------- */
.settings { max-width: var(--size-content-max); }
.status-badge { display: inline-flex; align-items: center; height: 26px; padding: 0 var(--space-2-5); border-radius: 13px; font-size: var(--text-xs); color: #1c2118; background: var(--color-status-connected); }
.status-badge[data-status="sample"] { background: var(--color-status-sample); color: var(--color-text); }
.status-badge[data-status="disconnected"] { background: var(--color-status-disconnected); }
.token-display { flex: 1; min-width: 0; min-height: var(--size-tap); display: flex; align-items: center; padding: 0 var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-bg); font-family: var(--font-mono); font-size: var(--text-sm); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.notice { padding: var(--space-3) 14px; border-radius: var(--radius-lg); display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-md); }
.notice__code { font-family: var(--font-mono); font-size: var(--text-xs); }
.notice--error { background: var(--color-error-bg); color: var(--color-error-text); }
.notice--success { background: var(--color-success-bg); }
.notice--success .notice__code { color: var(--color-success-text); }

/* ConnectBanner */
.banner { position: fixed; left: var(--space-3); right: var(--space-3); bottom: calc(var(--size-tabbar) + var(--space-3)); z-index: var(--z-banner); display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2-5) var(--space-2-5) var(--space-2-5) var(--space-4); border-radius: 14px; background: var(--color-text); color: var(--color-bg); box-shadow: var(--shadow-banner); font-size: var(--text-md); }
.banner p { flex: 1; }

.banner--inline { position: static; }

/* EmptyState */
.empty { padding: var(--space-8) var(--space-4); display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-3); color: var(--color-text-secondary); }
.empty__title { font-size: var(--text-xl); font-weight: var(--weight-light); color: var(--color-text); }

/* ---------- Dialogs ---------- */
dialog { color: inherit; }
.dialog { border: 0; padding: 0; background: transparent; max-width: none; max-height: none; }
.gallery { padding: var(--space-6) var(--space-4); display: flex; flex-direction: column; gap: var(--space-8); max-width: 1100px; }
.gallery section { display: flex; flex-direction: column; gap: var(--space-3); }
.gallery__row { display: flex; flex-wrap: wrap; gap: var(--space-4); align-items: flex-start; }
.gallery__cell { display: flex; flex-direction: column; gap: var(--space-1-5); min-width: 0; max-width: 100%; }
.gallery__cell > *, .gallery__row > .stack { max-width: 100%; }
.gallery__cell > .caption { font-family: var(--font-mono); }
.dialog::backdrop { background: var(--color-backdrop); }
.dialog--static { position: fixed; inset: 0; z-index: var(--z-dialog); width: 100%; height: 100%; margin: 0; padding: 0; border: 0; display: flex; background: var(--color-backdrop); }
/* Bottom sheet (phone) */
.sheet { margin-top: auto; width: 100%; max-height: 88vh; overflow-y: auto; background: var(--color-bg); border-radius: var(--radius-2xl) var(--radius-2xl) 0 0; padding: var(--space-5) var(--space-4) var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.sheet__grip { width: 36px; height: 4px; border-radius: 2px; background: var(--color-border); align-self: center; margin-top: calc(-1 * var(--space-2)); }

/* OnboardingDialog */
.onboarding { margin: auto var(--space-2) var(--space-2); width: 100%; align-self: flex-end; max-height: calc(100vh - 56px); overflow-y: auto; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-xl); box-shadow: var(--shadow-dialog); }
.onboarding__hero { background: var(--color-primary); color: #1c2118; padding: var(--space-5) var(--space-6) 22px; display: flex; flex-direction: column; gap: 14px; }
.onboarding__top { display: flex; align-items: center; gap: var(--space-2-5); }
.onboarding__top .brand img { width: 26px; height: 26px; border-radius: 7px; outline: 1px solid #c4ccb8; }
.onboarding__step { margin-left: auto; font-family: var(--font-mono); font-size: var(--text-xs); }
.onboarding__top .btn--icon { color: #1c2118; }
.onboarding__title { font-size: 30px; font-weight: var(--weight-thin); letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
.onboarding__title mark { background: var(--color-highlight); color: inherit; padding: 0 .12em; border-radius: 8px; }
.onboarding__body { padding: var(--space-5) var(--space-6) var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.onboarding__body p { font-size: 16px; line-height: 1.6; color: var(--color-text-secondary); }
.onboarding__actions { display: flex; flex-direction: column; gap: var(--space-2); }
.steps { border-top: 1px solid var(--color-border); }
.steps li { display: grid; grid-template-columns: 40px 1fr; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border-subtle); }
.steps__num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--color-primary); color: #1c2118; font-family: var(--font-mono); font-size: var(--text-xs); }
.steps__num--warn { background: var(--color-highlight); }
.steps__title { display: block; font-weight: var(--weight-regular); }
.steps__hint { font-size: var(--text-sm); color: var(--color-text-muted); }
.stepper { display: flex; gap: var(--space-1-5); }
.stepper span { width: 24px; height: 4px; border-radius: 2px; background: var(--color-border); }
.stepper span[data-done="true"] { background: var(--color-text); }

/* ---------- Helpers ---------- */
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.only-wide { display: none; }

/* ================= Tablet ≥ 768 ================= */
@media (min-width: 768px) {
  .app { grid-template-columns: var(--size-rail) minmax(0, 1fr); grid-template-rows: 1fr; padding-bottom: 0; }
  .app-header, .tabbar { display: none; }
  .sidenav { display: flex; flex-direction: column; gap: var(--space-5); position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--color-border); padding: var(--space-5) 0 var(--space-4); align-items: center; }
  .sidenav .brand span, .sidenav .sidenav__filters { display: none; }
  .sidenav .brand img { width: 32px; height: 32px; }
  .sidenav .nav-item { flex-direction: column; justify-content: center; gap: var(--space-1); width: 68px; height: 60px; padding: 0; font-size: var(--text-2xs); border-radius: var(--radius-lg); }
  .sidenav .status-dot { display: none; }
  .sidenav__foot { margin-top: auto; }
  .only-wide { display: revert; }
  .only-phone { display: none !important; }
  .page { padding: 22px var(--space-6) var(--space-6); gap: var(--space-4); }
  .split { display: grid; grid-template-columns: var(--size-list-md) minmax(0, 1fr); min-height: 100vh; }
  .split > .split__list { border-right: 1px solid var(--color-border); padding-left: var(--space-3); padding-right: var(--space-3); }
  .split > * { display: flex; flex-direction: column; min-width: 0; }
  .chart__plot--stream { height: 220px; }
  .chart__plot--overlay { height: 300px; }
  .chart__plot--route { height: 130px; }
  .bar-chart--report .bar-chart__bars { height: 220px; }
  .feed { gap: var(--space-2); }
  .totals { grid-template-columns: repeat(4, 1fr); }
  .reports__lower { grid-template-columns: 1fr 1fr; align-items: start; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .detail { padding: 22px var(--space-6) var(--space-6); }
  .detail__map { height: 300px; }
  .detail__lower { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; }
  .compare { grid-template-columns: var(--size-compare-list) minmax(0, 1fr); gap: 0; min-height: 100vh; }
  .compare__aside { border-right: 1px solid var(--color-border); }
  .scatter { height: 440px; }
  .editor__cols { grid-template-columns: 1fr 1fr; }
  .editor__cols > .card { position: sticky; top: var(--space-4); }
  .metrics { align-content: stretch; }
  .metrics { display: grid; grid-template-columns: var(--size-metric-list) minmax(0, 1fr); min-height: 100vh; }
  .metrics > :first-child { border-right: 1px solid var(--color-border); }
  .banner { left: calc(var(--size-rail) + var(--space-6)); right: auto; width: 460px; bottom: var(--space-5); }
  .sheet { margin: 0 0 0 auto; width: var(--size-drawer); max-height: none; height: 100%; border-radius: 0; border-left: 1px solid var(--color-border); }
  .sheet__grip { display: none; }
  .onboarding { margin: auto; width: var(--size-dialog); align-self: center; }
}

/* Phone: list/detail split shows one side */
@media (max-width: 767px) {
  .split[data-focus="list"] > .split__detail { display: none; }
  .split[data-focus="detail"] > .split__list { display: none; }
  .metrics[data-focus="list"] > :last-child { display: none; }
  .metrics[data-focus="editor"] > :first-child { display: none; }
  .compare__picker { display: none; }
}

/* ================= Desktop ≥ 1200 ================= */
@media (min-width: 1200px) {
  .app { grid-template-columns: var(--size-sidenav) minmax(0, 1fr); }
  .sidenav { align-items: stretch; padding: 22px 0 var(--space-3); }
  .sidenav .brand { padding: 0 var(--space-5); font-size: var(--text-xl); }
  .sidenav .brand span { display: inline; }
  .sidenav .brand img { width: 24px; height: 24px; }
  .sidenav__list { padding: 0 var(--space-3); }
  .sidenav .nav-item { flex-direction: row; justify-content: flex-start; width: auto; height: var(--size-control); padding: 0 var(--space-3); font-size: var(--text-base); border-radius: 10px; }
  .sidenav .status-dot { display: block; }
  .sidenav .sidenav__filters { display: flex; border-top: 1px solid var(--color-border); padding: var(--space-4) var(--space-5) 0; }
  .sidenav__foot { padding: var(--space-3) var(--space-3) 0; border-top: 1px solid var(--color-border); }
  .split { grid-template-columns: var(--size-list) minmax(0, 1fr); }
  .filter-trigger { display: none !important; }
  .filter-sheet { display: none !important; }
  .banner { left: calc(var(--size-sidenav) + var(--space-6)); }
}

/* ================================================================
   Web app overrides (fitsel-web).
   The pages in web/ are the shipped product; the screens in
   docs/design/screens/ are the design's reference. This block is
   scoped to the web app's own ids (#shell, #filter-sheet,
   #connect-banner, #active-filters) so it changes only the shipped
   pages and leaves the design's screens the design's. The design's
   rules above are not deleted.
   ================================================================= */

/* The web app renders its shell into #shell (id, not the design's .app
   class), so the grid that the design applies to .app has to be re-applied
   here. Two tabs (Activities, Settings): Reports, Compare and Metrics are
   out of v1, so the tab bar has two items, not four. */
#shell { min-height: 100vh; display: grid; grid-template-columns: 1fr; grid-template-rows: auto 1fr; padding-bottom: var(--size-tabbar); }
#shell .tabbar { grid-template-columns: repeat(2, 1fr); }

/* The filter sheet is a bottom sheet on phone: hidden until the page opens
   it (shell.js adds .open). */
#filter-sheet { display: none; }
#filter-sheet.open { display: flex; }

/* The connect banner hides itself with the hidden attribute, but .banner
   above forces display:flex, which beats the UA [hidden]{display:none}. This
   rule beats the flex so settings.js can hide it (hidden while Connected). */
#connect-banner[hidden] { display: none !important; }

/* The active-filter bar hides itself with the hidden attribute. */
#active-filters[hidden] { display: none; }

/* The web app's onboarding dialog (story #188) opens an .input token field
   (step 3). The design's .input:focus-visible { outline: none } (line 100)
   would hide its focus ring (AC18). Give the dialog's inputs a visible 2px
   focus ring; the design's own screens keep their none-outline as the design's. */
.dialog .input:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

/* The web app's shell at tablet: the rail shows, the tab bar goes away. */
@media (min-width: 768px) {
  #shell { grid-template-columns: var(--size-rail) minmax(0, 1fr); grid-template-rows: 1fr; padding-bottom: 0; }
}

/* The web app's shell at desktop: the side nav shows. */
@media (min-width: 1200px) {
  #shell { grid-template-columns: var(--size-sidenav) minmax(0, 1fr); }
}

/* BUG-26: the app's #feed is a div wrapping the WeekSummary and the cards, so
   the design's .feed card gap (8px) doesn't apply to it. Give it the list's
   .page gap so the WeekSummary→first-card spacing matches the design: 16px at
   768+, 12px at the base .page gap. */
#feed { display: flex; flex-direction: column; gap: var(--space-3); }
@media (min-width: 768px) {
  #feed { gap: var(--space-4); }
}

/* BUG-36: the status line and the filter bar sit in the list column under the
   search, in the .page flow (design activity-filter), so they take their own
   row and never overlap the title, the search or each other. The status line
   hides itself while the filter bar shows. */
#status[hidden] { display: none; }
/* The FilterButton badge is display:inline-flex, which beats [hidden]: without
   this the phone Filter button shows a "0" badge the design does not have. */
.badge-count[hidden] { display: none; }

/* BUG-31 AC6: the Record stream card's control stays on the eyebrow's row on every width: the SegmentedControl scrolls sideways instead of dropping to its own line. */
.card[data-component="StreamChart"] .card__head { flex-wrap: nowrap; }
