/**
 * UI primitives for Shell V2 — Button, Card, Tile, Banner, EmptyState, Toast.
 *
 * Scoped: classes prefixed with .u- to avoid bleeding into legacy pages.
 * All colors via canonical --t-* tokens only. No hex literals.
 */

/* ── Button ──────────────────────────────────────────────────────────── */

.u-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  font-family: var(--t-font);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  text-align: center;
  border: 1px solid transparent;
  border-radius: var(--t-radius, 12px);
  cursor: pointer;
  transition: transform 0.08s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.u-btn:active {
  transform: scale(0.98);
}

.u-btn--block {
  width: 100%;
}

.u-btn--primary {
  background: var(--t-primary);
  color: #ffffff;
  color: var(--t-card);
}
.u-btn--primary:hover { opacity: 0.95; }

.u-btn--accent {
  background: var(--t-accent);
  color: var(--t-text);
}

.u-btn--ghost {
  background: transparent;
  color: var(--t-text);
  border-color: var(--t-border);
}

/* Yellow brand hero CTA — pill, reserved for the primary action per screen.
   Uses the canonical --t-cta-* tokens so contrast stays correct across
   all three themes (light, dark, violet). */
.u-btn--cta {
  min-height: 56px;
  padding: 16px 28px;
  background: var(--t-cta-bg, var(--t-success));
  color: var(--t-cta-fg, #1a1000);
  border: none;
  border-radius: var(--t-radius-pill);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: var(--t-cta-glow, 0 4px 12px rgba(0, 0, 0, 0.08)), var(--t-cta-inset, none);
  transition: transform 120ms var(--t-ease-premium, ease),
              box-shadow 180ms var(--t-ease-premium, ease);
}
.u-btn--cta:active {
  transform: scale(0.98);
  box-shadow: var(--t-cta-glow-hover, 0 2px 6px rgba(0, 0, 0, 0.12)), var(--t-cta-inset, none);
}

/* ── Card ────────────────────────────────────────────────────────────── */

.u-card {
  background: var(--t-card);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius, 12px);
  padding: 20px;
}

/* Card with tighter internal rhythm — used for form/pill cards. */
.u-card--tight {
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--t-card-shadow, 0 1px 2px rgba(0, 0, 0, 0.04));
  border-width: 1.5px;
  border-radius: var(--t-radius-lg);
}

/* Accent variants — tinted surface + 3px brand edge.
   Purpose: single-accent callout (e.g. Recovery) without leaving the
   .u-card token family. Safe under all themes via color-mix. */
.u-card--accent-success {
  background: color-mix(in srgb, var(--t-success) 6%, var(--t-card));
  border-color: color-mix(in srgb, var(--t-success) 50%, var(--t-border));
  border-left: 3px solid var(--t-success);
}
[data-theme="violet"] .u-card--accent-success {
  background: color-mix(in srgb, var(--t-success) 10%, var(--t-card));
}

.u-card--accent-primary {
  background: color-mix(in srgb, var(--t-primary) 6%, var(--t-card));
  border-color: color-mix(in srgb, var(--t-primary) 45%, var(--t-border));
  border-left: 3px solid var(--t-primary);
}

/* Field-level primitives inside a card. */
.u-card__field {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.u-card__label {
  font-size: 15px;
  font-weight: 700;
  color: var(--t-text);
  letter-spacing: -0.005em;
  line-height: 1.2;
}
.u-card__hint {
  font-size: 13px;
  color: var(--t-text-muted);
  line-height: 1.35;
}

/* ── Tile (square secondary action) ──────────────────────────────────── */

.u-tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  min-height: 116px;
  padding: 16px;
  background: var(--t-card);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius, 12px);
  color: var(--t-text);
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s;
}

.u-tile:active {
  transform: scale(0.98);
}

.u-tile__icon {
  font-size: 26px;
  line-height: 1;
}

.u-tile__label {
  font-size: 15px;
  font-weight: 500;
  color: var(--t-text);
  line-height: 1.25;
}

/* ── Banner / Alert / Empty / Error / Loading ────────────────────────── */

.u-banner {
  padding: 12px 16px;
  background: var(--t-surface);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-sm, 8px);
  color: var(--t-text);
  font-size: 14px;
}

.u-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 32px 16px;
  color: var(--t-text-muted);
}

.u-empty__icon {
  font-size: 40px;
  line-height: 1;
}

.u-empty__title {
  font-size: 17px;
  font-weight: 600;
  color: var(--t-text);
  margin: 0;
}

.u-empty__hint {
  font-size: 14px;
  color: var(--t-text-muted);
  margin: 0;
}

/* ── List row ────────────────────────────────────────────────────────── */

.u-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--t-border);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius, 12px);
  overflow: hidden;
}

.u-list-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  min-height: 56px;
  background: var(--t-card);
  color: var(--t-text);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.u-list-row:active {
  background: var(--t-surface);
}

.u-list-row__icon {
  flex: 0 0 auto;
  width: 28px;
  font-size: 20px;
  text-align: center;
  line-height: 1;
}

.u-list-row__body {
  flex: 1 1 auto;
  min-width: 0;
}

.u-list-row__title {
  font-size: 15px;
  font-weight: 500;
  color: var(--t-text);
  line-height: 1.3;
}

.u-list-row__hint {
  font-size: 13px;
  color: var(--t-text-muted);
  margin-top: 2px;
  line-height: 1.3;
}

.u-list-row__badge {
  flex: 0 0 auto;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--t-primary);
  color: var(--t-card);
  border-radius: var(--t-radius-pill);
  line-height: 1.4;
}

.u-list-row__chevron {
  flex: 0 0 auto;
  color: var(--t-text-subtle);
  font-size: 18px;
  line-height: 1;
}

.u-section-header {
  padding: 16px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--t-text-muted);
}

/* Tight variant — used inside .u-card--tight sections where the card
   already provides breathing room. */
.u-section-header--tight {
  padding: 0 4px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

/* ── Pills (single-select chip group) ────────────────────────────────── */

.u-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.u-pill {
  flex: 1 1 0;
  min-width: 64px;
  min-height: 60px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  border: 1.5px solid var(--t-border);
  border-radius: 14px;
  background: var(--t-surface, var(--t-bg));
  color: var(--t-text);
  font-family: var(--t-font);
  cursor: pointer;
  transition: transform 120ms var(--t-ease-premium, ease),
              border-color 180ms var(--t-ease-premium, ease),
              background 180ms var(--t-ease-premium, ease),
              box-shadow 180ms var(--t-ease-premium, ease);
  -webkit-tap-highlight-color: transparent;
}
.u-pill:active { transform: scale(0.97); }
@media (hover: hover) {
  .u-pill:hover { border-color: var(--t-primary); }
}

.u-pill-icon { font-size: 1.3rem; line-height: 1; }
.u-pill-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--t-text);
  text-align: center;
  line-height: 1.15;
}

.u-pill--active {
  border-color: var(--t-primary);
  background: color-mix(in srgb, var(--t-primary) 10%, var(--t-surface, var(--t-bg)));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--t-primary) 18%, transparent);
  /* Make the currentColor dots (check-in scale) always render dark/readable
   * regardless of theme — otherwise in violet, they inherit light text color
   * on a yellow-tinted surface and disappear. */
  color: var(--t-cta-fg);
}
[data-theme="violet"] .u-pill--active {
  border-color: var(--t-success);
  background: color-mix(in srgb, var(--t-success) 10%, var(--t-surface));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--t-success) 20%, transparent);
  color: var(--t-cta-fg);
}

/* Inside an accent-success card the pills echo the yellow family. */
.u-card--accent-success .u-pill--active {
  border-color: var(--t-success);
  background: color-mix(in srgb, var(--t-success) 14%, var(--t-surface, var(--t-bg)));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--t-success) 22%, transparent);
}

/* ── Toast (mount point in overlays_root) ────────────────────────────── */

.u-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--app-tabs-h, 64px) + env(safe-area-inset-bottom, 0) + 24px);
  transform: translateX(-50%);
  z-index: 100;
  padding: 12px 18px;
  background: var(--t-text);
  color: var(--t-card);
  border-radius: var(--t-radius, 12px);
  font-size: 14px;
  max-width: calc(100% - 32px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.u-toast--show {
  opacity: 1;
  pointer-events: auto;
}

/* ══════════════════════════════════════════════════════════════════════════
   Internal content primitives — v2.105.0 unification pass.
   Promoted from Programs (.prg-*), Profile (.pf-*), and the various per-screen
   one-off namespaces. Target: Programs-grade density + hierarchy, expressed
   once here so every screen inherits for free.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Section header — count pill (promoted from .prg-section__count) ─── */

.u-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.u-section-header__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 7px;
  margin-left: auto;
  background: color-mix(in srgb, var(--t-primary) 10%, transparent);
  color: var(--t-primary);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

/* ── Card head — inline title + optional count inside a card ────────── */

.u-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.u-card__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--t-text);
  letter-spacing: -0.005em;
  line-height: 1.25;
}
.u-card__head .u-section-header__count { margin-left: auto; }

/* ── Icon chip — the single canonical tinted icon surface ─────────────
   Replaces ad-hoc 40×40 / 44×44 / 56×56 icon boxes across every screen.
   Size variants only — color variants pick up --t-chip-* family tokens. */

.u-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--t-chip-primary-bg, color-mix(in srgb, var(--t-primary) 10%, transparent));
  color: var(--t-chip-primary-fg, var(--t-primary));
  box-shadow: var(--t-chip-inset, none);
  font-size: 20px;
  line-height: 1;
}
.u-chip svg { display: block; }

.u-chip--sm { width: 32px; height: 32px; border-radius: 9px; font-size: 16px; }
.u-chip--lg { width: 56px; height: 56px; border-radius: var(--t-radius-row); font-size: 24px; }

.u-chip--primary {
  background: var(--t-chip-primary-bg);
  color: var(--t-chip-primary-fg);
  box-shadow: var(--t-chip-inset, none), 0 0 0 1px var(--t-chip-primary-ring, transparent);
}
.u-chip--rose {
  background: var(--t-chip-rose-bg);
  color: var(--t-chip-rose-fg);
  box-shadow: var(--t-chip-inset, none), 0 0 0 1px var(--t-chip-rose-ring, transparent);
}
.u-chip--accent {
  background: var(--t-chip-accent-bg);
  color: var(--t-chip-accent-fg);
  box-shadow: var(--t-chip-inset, none), 0 0 0 1px var(--t-chip-accent-ring, transparent);
}
.u-chip--success {
  background: color-mix(in srgb, var(--t-success) 16%, transparent);
  color: color-mix(in srgb, var(--t-success) 70%, var(--t-text));
}
.u-chip--danger {
  background: color-mix(in srgb, var(--t-danger) 12%, transparent);
  color: var(--t-danger);
}
.u-chip--muted {
  background: var(--t-surface);
  color: var(--t-text-muted);
  box-shadow: inset 0 0 0 1px var(--t-border);
}

/* ── Stat block — compact value+label (achievements, history rhythm) ── */

.u-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.u-stat__value {
  font-family: var(--t-font-display, var(--t-font));
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--t-text);
  letter-spacing: -0.01em;
}
.u-stat__label {
  font-size: 12px;
  color: var(--t-text-muted);
  line-height: 1.3;
}
.u-stat--inline { flex-direction: row; align-items: baseline; gap: 6px; }
.u-stat--inline .u-stat__value { font-size: 16px; }

.u-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 14px 18px;
}

/* ── Mini badge — inline after a title (promoted from .cb-mini-badge) ── */

.u-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 8px;
  margin-left: 6px;
  vertical-align: 2px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: color-mix(in srgb, var(--t-primary) 10%, transparent);
  color: var(--t-primary);
  line-height: 1.4;
}
.u-badge--primary { background: var(--t-primary); color: var(--t-card); }
.u-badge--success { background: var(--t-cta-bg); color: var(--t-cta-fg); }
.u-badge--danger  { background: var(--t-danger); color: var(--t-card); }
.u-badge--muted   { background: var(--t-surface); color: var(--t-text-muted); box-shadow: inset 0 0 0 1px var(--t-border); }
.u-badge--ghost   { background: color-mix(in srgb, var(--t-primary) 6%, transparent); color: var(--t-text-muted); }

/* ── Extended list row — meta line + accent variants + kebab slot ───── */

.u-list-row {
  border: 1px solid var(--t-row-border);
  border-radius: 12px;
  background: var(--t-card);
  transition: border-color 150ms, box-shadow 150ms;
  min-height: 0;
  padding: 10px 12px;
  gap: 12px;
}
.u-list-row:hover {
  border-color: var(--t-row-border-hover);
  box-shadow: var(--t-row-shadow);
}

.u-list-row__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.u-list-row__title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.005em;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.u-list-row__meta {
  font-size: 12px;
  color: var(--t-text-muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}

.u-list-row__kebab {
  flex-shrink: 0;
  width: 40px;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--t-text-muted);
  cursor: pointer;
  border-left: 1px solid color-mix(in srgb, var(--t-row-border) 60%, transparent);
  margin: -10px -12px -10px 0;
  border-top-right-radius: 12px;
  border-bottom-right-radius: 12px;
  transition: background 120ms, color 120ms;
}
.u-list-row__kebab:hover,
.u-list-row__kebab[aria-expanded="true"] {
  background: color-mix(in srgb, var(--t-primary) 6%, transparent);
  color: var(--t-primary);
}

/* Grid container — compact row rhythm (Programs: 6px, default in ui.css) */
.u-list--compact { gap: 6px; background: transparent; border: 0; border-radius: 0; overflow: visible; }
.u-list--compact .u-list-row { border-radius: 12px; }

/* Accent variants (subtle tint, same row anatomy) */
.u-list-row--accent-primary {
  border-color: var(--t-primary);
  background: color-mix(in srgb, var(--t-primary) 4%, var(--t-card));
  box-shadow: 0 1px 12px color-mix(in srgb, var(--t-primary) 10%, transparent);
}
.u-list-row--accent-primary .u-chip {
  background: color-mix(in srgb, var(--t-primary) 14%, transparent);
}
.u-list-row--accent-success {
  border: 1.5px solid var(--t-cta-bg);
  background: color-mix(in srgb, var(--t-cta-bg) 5%, var(--t-card));
}
.u-list-row--accent-success .u-chip {
  background: color-mix(in srgb, var(--t-cta-bg) 16%, transparent);
  color: color-mix(in srgb, var(--t-cta-bg) 70%, var(--t-text));
}
.u-list-row--accent-muted {
  border-color: color-mix(in srgb, var(--t-primary) 30%, var(--t-row-border));
  background: color-mix(in srgb, var(--t-primary) 3%, var(--t-card));
}
.u-list-row--accent-muted .u-chip {
  background: color-mix(in srgb, var(--t-primary) 12%, transparent);
}

/* ── Empty state — card surface + dual CTA (promoted from .prg-empty) ── */

.u-empty--card {
  background: var(--t-card);
  border: 1px solid var(--t-row-border);
  border-radius: var(--t-radius, 14px);
  box-shadow: var(--t-row-shadow, none);
  padding: 36px 24px;
  margin-bottom: 16px;
}
.u-empty__text {
  color: var(--t-text-muted);
  font-size: 14px;
  line-height: 1.55;
  max-width: 280px;
  margin: 0 auto;
}
.u-empty__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}
.u-empty__cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition: box-shadow 150ms, background 150ms;
}
.u-empty__cta--primary {
  background: var(--t-cta-bg);
  color: var(--t-cta-fg);
  box-shadow: var(--t-cta-glow, none), var(--t-cta-inset, none);
}
.u-empty__cta--primary:hover { box-shadow: var(--t-cta-glow-hover, none), var(--t-cta-inset, none); }
.u-empty__cta--ghost {
  background: color-mix(in srgb, var(--t-primary) 8%, transparent);
  color: var(--t-primary);
}
.u-empty__cta--ghost:hover { background: color-mix(in srgb, var(--t-primary) 14%, transparent); }

/* ── Hero — state banner above a card/list (training index, start, body) ── */

.u-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--t-card);
  border: 1px solid var(--t-row-border);
  border-radius: var(--t-radius, 14px);
  box-shadow: var(--t-row-shadow, none);
}
.u-hero__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.u-hero__title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--t-text);
  letter-spacing: -0.01em;
}
.u-hero__meta {
  font-size: 13px;
  color: var(--t-text-muted);
  line-height: 1.4;
}
.u-hero__cta {
  flex-shrink: 0;
}

.u-hero--primary {
  border-color: var(--t-primary);
  background: color-mix(in srgb, var(--t-primary) 5%, var(--t-card));
  box-shadow: 0 1px 16px color-mix(in srgb, var(--t-primary) 12%, transparent);
}
.u-hero--success {
  border: 1.5px solid var(--t-cta-bg);
  background: color-mix(in srgb, var(--t-cta-bg) 6%, var(--t-card));
}
.u-hero--muted {
  background: var(--t-surface);
  border-color: var(--t-border);
}

/* ── Accordion — <details> primitive for FAQ-style blocks ──────────── */

.u-accordion {
  background: var(--t-card);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius, 12px);
  padding: 14px 16px;
  margin-bottom: 8px;
  transition: border-color 150ms;
}
.u-accordion[open] { border-color: var(--t-primary); }
.u-accordion > summary {
  font-size: 15px;
  font-weight: 600;
  color: var(--t-text);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1.35;
}
.u-accordion > summary::-webkit-details-marker { display: none; }
.u-accordion > summary::after {
  content: '';
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--t-text-muted);
  border-bottom: 2px solid var(--t-text-muted);
  transform: rotate(45deg);
  transition: transform 180ms;
}
.u-accordion[open] > summary::after { transform: rotate(-135deg); }
.u-accordion__body {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--t-border);
  color: var(--t-text-muted);
  font-size: 14px;
  line-height: 1.55;
}

/* ── Grouped list — iOS-style grouped card (promoted from .pf-group) ── */

.u-grouped-list {
  background: var(--t-card);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius, 14px);
  overflow: hidden;
  margin-bottom: 16px;
}
.u-grouped-list__title {
  padding: 16px 16px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--t-text-muted);
}
.u-grouped-list__row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  min-height: 56px;
  color: var(--t-text);
  text-decoration: none;
  border-top: 1px solid var(--t-border);
  transition: background 120ms;
  -webkit-tap-highlight-color: transparent;
}
.u-grouped-list__row:first-of-type { border-top: 0; }
.u-grouped-list__row:active { background: var(--t-surface); }
.u-grouped-list__row .u-list-row__body { flex: 1 1 auto; min-width: 0; }

/* ── Danger button variant ──────────────────────────────────────────── */

.u-btn--danger {
  background: var(--t-danger);
  color: var(--t-card);
}
.u-btn--danger:hover { opacity: 0.92; }

/* ── Dark / violet tweaks ───────────────────────────────────────────── */

[data-theme="dark"] .u-list-row--accent-success {
  border-color: color-mix(in srgb, var(--t-cta-bg) 75%, var(--t-text));
  background: color-mix(in srgb, var(--t-cta-bg) 6%, var(--t-card));
}
[data-theme="violet"] .u-list-row--accent-success {
  border-color: var(--t-cta-bg);
  background: color-mix(in srgb, var(--t-cta-bg) 8%, var(--t-card));
}
[data-theme="violet"] .u-list-row--accent-success .u-list-row__title {
  color: var(--t-cta-bg);
}
