/* ==========================================================================
   GAINZ — Component Styles
   Nav, buttons, cards, empty-state, data numerals. Uses tokens.css variables.
   ========================================================================== */

/* ==========================================================================
   BOTTOM NAV
   ========================================================================== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--color-plate);
  border-top: 1px solid var(--color-rack);
  display: flex;
  align-items: stretch;
  z-index: var(--z-nav);
  /* Prevent content scrolling through the nav */
  -webkit-backdrop-filter: blur(0);
}

.bottom-nav__list {
  display: flex;
  flex: 1;
  align-items: stretch;
}

.bottom-nav__item {
  flex: 1;
  display: flex;
}

.bottom-nav__btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: var(--tap-min);
  /* Generous touch area — meets WCAG 2.2 SC 2.5.8 */
  padding: var(--space-2) var(--space-1);
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: color var(--duration-fade) var(--ease-out);
  border-radius: 0;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav__btn[aria-current="page"] {
  color: var(--color-accent);
}

.bottom-nav__icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

/* Primary — belt-amber CTA */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  letter-spacing: 0.02em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--duration-fade) var(--ease-out),
              background-color var(--duration-fade) var(--ease-out);
  border: 2px solid transparent;
  text-align: center;
  white-space: nowrap;
}

.btn--primary {
  background: var(--color-accent);
  color: var(--color-iron);
  border-color: var(--color-accent);
}
.btn--primary:active {
  opacity: 0.85;
}

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-rack);
}
.btn--secondary:active {
  background: var(--color-rack);
}

.btn--ghost {
  background: transparent;
  color: var(--color-accent);
  border-color: var(--color-accent);
}
.btn--ghost:active {
  background: color-mix(in srgb, var(--color-accent) 12%, transparent);
}

.btn--danger {
  background: transparent;
  color: var(--color-danger);
  border-color: var(--color-danger);
}
.btn--danger:active {
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
}

.btn--full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Icon-only button — stepper (+/−) */
.btn--icon {
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  font-size: var(--text-lg);
  font-weight: var(--weight-black);
  background: var(--color-rack);
  color: var(--color-text);
  border-color: transparent;
  line-height: 1;
}
.btn--icon:active {
  background: color-mix(in srgb, var(--color-chalk) 15%, var(--color-rack));
}

/* ==========================================================================
   CARDS
   ========================================================================== */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--color-rack);
}

.card--raised {
  background: var(--color-surface-raised);
}

.card + .card {
  margin-top: var(--space-3);
}

/* ==========================================================================
   DATA NUMERALS
   The hero of the interface — weight and rep counts displayed mid-set.
   ========================================================================== */

.data-numeral {
  font-family: var(--font-display);
  font-weight: var(--weight-black);
  line-height: var(--leading-tight);
  color: var(--color-chalk);
  /* Tabular number rendering for alignment stability */
  font-variant-numeric: tabular-nums;
}

.data-numeral--xl {
  font-size: var(--text-data-xl);  /* 64px — active set weight/reps */
}
.data-numeral--lg {
  font-size: var(--text-data-lg);  /* 40px — secondary numerals */
}
.data-numeral--sm {
  font-size: var(--text-data-sm);  /* 32px — history, inline */
}
.data-numeral--pr {
  font-size: var(--text-data-pr);  /* 96px — PR celebration */
  color: var(--color-iron);        /* dark on the flash-white background */
}

.data-unit {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
  color: var(--color-text-muted);
  text-transform: lowercase;
  letter-spacing: 0.04em;
}

/* ==========================================================================
   EMPTY STATE
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-7) var(--space-5);
  text-align: center;
  min-height: 300px;
}

.empty-state__icon {
  width: 64px;
  height: 64px;
  color: var(--color-text-muted);
  opacity: 0.6;
}

.empty-state__title {
  font-family: var(--font-body);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--color-text);
}

.empty-state__message {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  max-width: 280px;
  line-height: var(--leading-snug);
}

.empty-state__action {
  margin-top: var(--space-2);
}

/* ==========================================================================
   SCREEN HEADER
   ========================================================================== */

.screen-header {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-rack);
}

.screen-header__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--color-text);
}

.screen-header__subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
  font-family: var(--font-mono);
}

/* ==========================================================================
   SCREEN BODY
   ========================================================================== */

.screen-body {
  padding: var(--space-4) var(--space-5);
}

/* ==========================================================================
   PLACEHOLDER / LOADING SKELETONS
   ========================================================================== */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-plate) 25%,
    var(--color-rack) 50%,
    var(--color-plate) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    background: var(--color-plate);
  }
}

/* ==========================================================================
   STATUS BADGES
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge--pr {
  background: color-mix(in srgb, var(--color-belt) 20%, transparent);
  color: var(--color-belt);
  border: 1px solid color-mix(in srgb, var(--color-belt) 40%, transparent);
}

/* ==========================================================================
   PR CELEBRATION OVERLAY
   Built in T7 — reserved z-index and keyframe definitions here.
   ========================================================================== */

.pr-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-pr);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  pointer-events: auto;
  background: var(--color-iron);
}

.pr-overlay--flash {
  background: var(--color-pr);
}

.pr-overlay__label {
  font-family: var(--font-display);
  font-weight: var(--weight-black);
  font-size: 2rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--color-belt);
}

.pr-overlay__value {
  font-family: var(--font-display);
  font-weight: var(--weight-black);
  font-size: var(--text-data-pr);
  line-height: var(--leading-tight);
  color: var(--color-chalk);
}

.pr-overlay__delta {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}

@keyframes pr-slam {
  from {
    opacity: 0;
    transform: translateY(60px) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.pr-overlay__value--animate {
  animation: pr-slam var(--duration-slam) var(--ease-snap) forwards;
}

@media (prefers-reduced-motion: reduce) {
  .pr-overlay__value--animate {
    animation: none;
  }
}

/* Burn phase: value now sits on dark background — switch to chalk */
.pr-overlay__value--burn {
  color: var(--color-chalk);
  transition: color 200ms var(--ease-out);
}

/* ==========================================================================
   LIBRARY SCREEN (T5 / F2)
   ========================================================================== */

/* Exercise list */
.ex-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.ex-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.ex-row__main {
  flex: 1;
  min-width: 0;
}

.ex-row__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-1);
}

.ex-row__name {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-chalk);
}

.ex-row__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.ex-row__actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Tags */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: color-mix(in srgb, var(--color-chalk) 10%, transparent);
  color: var(--color-chalk-dim);
  letter-spacing: 0.03em;
}

.tag--type {
  background: color-mix(in srgb, var(--color-belt) 15%, transparent);
  color: var(--color-belt);
}

.tag--eq {
  background: color-mix(in srgb, var(--color-chalk) 8%, transparent);
  color: var(--color-chalk-dim);
  border: 1px solid var(--color-rack);
}

.tag--more {
  color: var(--color-chalk-dim);
}

/* Bodyweight badge */
.badge--bw {
  background: color-mix(in srgb, var(--color-chalk) 12%, transparent);
  color: var(--color-chalk-dim);
  border: 1px solid var(--color-rack);
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Smart suggestion chip — visually same muted tone as badge--bw but semantically distinct */
.badge--hint {
  background: color-mix(in srgb, var(--color-chalk) 12%, transparent);
  color: var(--color-chalk-dim);
  border: 1px solid var(--color-rack);
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Exercise form */
.lib-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.lib-form__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--color-chalk);
  margin-bottom: var(--space-1);
}

.lib-form__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.lib-form__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-chalk-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.lib-form__input--error {
  border-color: var(--color-danger) !important;
  outline-color: var(--color-danger);
}

.lib-form__error {
  font-size: var(--text-sm);
  color: var(--color-danger);
  margin-top: calc(-1 * var(--space-1));
}

.lib-form__actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-2);
}

/* Chip selector (type / muscle group toggles) */
.lib-form__chips {
  display: flex;
  gap: var(--space-2);
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.lib-form__chips--wrap {
  flex-wrap: wrap;
  overflow-x: visible;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  background: var(--color-surface);
  color: var(--color-chalk-dim);
  border: 1.5px solid var(--color-rack);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--duration-fade) var(--ease-out),
              color var(--duration-fade) var(--ease-out);
}

.chip--active {
  background: color-mix(in srgb, var(--color-belt) 18%, var(--color-surface));
  color: var(--color-belt);
  border-color: var(--color-belt);
}

.chip--sm {
  font-size: var(--text-xs);
  min-height: var(--tap-min);
  padding: var(--space-1) var(--space-2);
}

/* Equipment list */
.eq-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.eq-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.eq-item__info {
  flex: 1;
  min-width: 0;
}

.eq-item__name {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-chalk);
  display: block;
}

.eq-item__cat {
  font-size: var(--text-sm);
  display: block;
  margin-top: 2px;
}

/* Equipment toggle button */
.eq-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  min-width: 100px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  border: 1.5px solid;
  cursor: pointer;
  transition: background var(--duration-fade) var(--ease-out);
  flex-shrink: 0;
}

.eq-toggle--on {
  background: color-mix(in srgb, var(--color-belt) 15%, transparent);
  color: var(--color-belt);
  border-color: var(--color-belt);
}

.eq-toggle--off {
  background: color-mix(in srgb, var(--color-chalk) 6%, transparent);
  color: var(--color-chalk-dim);
  border-color: var(--color-rack);
}

/* ==========================================================================
   WORKOUT SCREEN (T6 / F1)
   ========================================================================== */

/* Start session screen */
.start-field {
  margin-bottom: var(--space-5);
}

.start-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-chalk-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

.start-day-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border: 1.5px solid var(--color-rack);
  cursor: pointer;
  transition: border-color var(--duration-fade) var(--ease-out),
              background var(--duration-fade) var(--ease-out);
}

.start-day-btn--active {
  border-color: var(--color-belt);
  background: color-mix(in srgb, var(--color-belt) 10%, var(--color-surface));
}

.start-day-btn__label {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-chalk);
}

/* Exercise card */
.ex-card {
  margin-bottom: var(--space-3);
  overflow: hidden;
  transition: border-color var(--duration-fade) var(--ease-out);
}

.ex-card--expanded {
  border-color: color-mix(in srgb, var(--color-belt) 40%, var(--color-rack));
}

.ex-card__header {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
}

.ex-card__title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.ex-card__name {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  color: var(--color-chalk);
}

.ex-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-1);
}

.ex-card__chevron {
  font-size: var(--text-xs);
  color: var(--color-chalk-dim);
}

/* Logged sets list */
.ex-card__sets {
  border-top: 1px solid var(--color-rack);
  padding: 0 var(--space-4);
}

/* Individual logged set */
.set-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-rack) 50%, transparent);
}

.set-card:last-child {
  border-bottom: none;
}

.set-card__number {
  font-size: var(--text-xs);
  min-width: 40px;
}

.set-card__values {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* Input panel */
.ex-card__panel {
  border-top: 1px solid var(--color-rack);
  padding: var(--space-4);
  background: color-mix(in srgb, var(--color-rack) 30%, var(--color-surface));
}

.ex-card__inputs {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Steppers */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}

.stepper__display {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
  text-align: center;
}

/* Exercise picker overlay */
.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 32, 0.85);
  z-index: var(--z-overlay);
  display: flex;
  align-items: flex-end;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.picker-panel {
  background: var(--color-plate);
  border-top: 1px solid var(--color-rack);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) 0;
}

.picker-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-2) 0 var(--space-7);
}

.picker-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-bottom: 1px solid color-mix(in srgb, var(--color-rack) 50%, transparent);
  background: none;
  color: inherit;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: background var(--duration-fade) var(--ease-out);
}

.picker-item:active {
  background: var(--color-rack);
}

.picker-item__name {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--color-chalk);
}

/* ==========================================================================
   ERROR BANNER (D2 — lightweight in-app error capture)
   Top-anchored so it never covers the bottom nav. Sits above overlays but
   below the PR celebration (--z-overlay).
   ========================================================================== */

.error-banner {
  position: fixed;
  top: var(--safe-top);
  left: 0;
  right: 0;
  z-index: var(--z-overlay);
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--color-danger) 18%, var(--color-rack));
  border-bottom: 2px solid var(--color-danger);
  /* Subtle drop so it reads as a layer above content */
  box-shadow: 0 4px 12px rgba(15, 22, 32, 0.5);
}

.error-banner__row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  max-width: 640px;
  margin: 0 auto;
}

.error-banner__icon {
  flex-shrink: 0;
  font-size: var(--text-lg);
  line-height: 1.2;
  color: var(--color-chalk);
}

.error-banner__body {
  flex: 1;
  min-width: 0;
}

.error-banner__title {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  color: var(--color-chalk);
}

.error-banner__sub {
  font-size: var(--text-sm);
  color: var(--color-chalk);
  opacity: 0.85;
  margin-top: 2px;
  line-height: var(--leading-snug);
}

.error-banner__detail {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-chalk);
  margin-top: var(--space-2);
  padding: var(--space-2);
  background: color-mix(in srgb, var(--color-iron) 55%, transparent);
  border-radius: var(--radius-sm);
  /* Long stacks/messages: wrap + scroll rather than blow out the layout */
  max-height: 8rem;
  overflow: auto;
  word-break: break-word;
  white-space: pre-wrap;
}

.error-banner__toggle {
  margin-top: var(--space-2);
  min-height: var(--tap-min);
  padding: var(--space-1) 0;
  background: none;
  border: none;
  color: var(--color-chalk);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-decoration: underline;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.error-banner__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  padding: var(--space-2);
  background: none;
  border: none;
  color: var(--color-chalk);
  font-size: var(--text-lg);
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-md);
  -webkit-tap-highlight-color: transparent;
}

.error-banner__close:active {
  background: color-mix(in srgb, var(--color-chalk) 15%, transparent);
}

/* ==========================================================================
   UTILITY
   ========================================================================== */

.text-accent  { color: var(--color-accent); }
.text-muted   { color: var(--color-text-muted); }
.text-chalk   { color: var(--color-chalk); }
.font-mono    { font-family: var(--font-mono); }
.font-display { font-family: var(--font-display); font-weight: var(--weight-black); }

.mt-auto { margin-top: auto; }
.w-full  { width: 100%; }
