/*
 * components.css — TrackBounty primitive component library (redesign A1)
 *
 * Spec: .claude/reports/arch/redesign_a1_spec_2026-04-30T2144Z.md §2
 *
 * Every primitive consumes ONLY tokens from tokens.css. Reusable across
 * /marketplace (A1), editor profile + embed (A2), sound page + landing +
 * for-label + collections + display face (A3).
 *
 * Each primitive ships with: states (default/hover/focus/active/disabled),
 * ARIA + keyboard nav, motion behavior, and mobile behavior.
 */

/* === Base reset (scoped — does NOT replace base.html's existing reset) === */

.tb-r * { box-sizing: border-box; }

/* ============================================================================
 * Button (§2.2) — variants: --primary / --secondary / --ghost / --danger
 *                 sizes:    --sm / --md / --lg
 *                 modifiers: with-icon / icon-only
 * ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 36px;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: 1;
  letter-spacing: 0.1px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background var(--motion-fast) var(--ease-out-expo),
              border-color var(--motion-fast) var(--ease-out-expo),
              color var(--motion-fast) var(--ease-out-expo),
              transform var(--motion-fast) var(--ease-out-expo);
}
.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn--sm { height: 28px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn--md { height: 36px; padding: 0 var(--space-4); }
.btn--lg { height: 44px; padding: 0 var(--space-5); font-size: var(--text-md); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--primary:hover:not(:disabled) {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
}

.btn--secondary {
  background: var(--surface-2);
  border-color: var(--border-default);
  color: var(--text-primary);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text-primary);
}

.btn--danger {
  background: var(--state-error-bg);
  border-color: var(--state-error);
  color: var(--state-error);
}
.btn--danger:hover:not(:disabled) {
  background: var(--state-error);
  color: #fff;
}

.btn--icon-only {
  width: 36px;
  padding: 0;
}
.btn--icon-only.btn--sm { width: 28px; }
.btn--icon-only.btn--lg { width: 44px; }

/* ============================================================================
 * Tier badge (§2.3) — most-rendered primitive
 * ========================================================================== */

.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-width: 22px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-black);
  font-feature-settings: "tnum" 1;     /* tabular numerals */
  letter-spacing: 0.4px;
  white-space: nowrap;
}

/* v1.1 — glow tokens are full box-shadow expressions; consume directly */
.tier-badge--splus { background: var(--tier-splus-bg); color: var(--tier-splus-text); box-shadow: var(--tier-splus-glow); }
.tier-badge--s     { background: var(--tier-s-bg);     color: var(--tier-s-text);     box-shadow: var(--tier-s-glow); }
.tier-badge--a     { background: var(--tier-a-bg);     color: var(--tier-a-text);     box-shadow: var(--tier-a-glow); }
.tier-badge--b     { background: var(--tier-b-bg);     color: var(--tier-b-text);     box-shadow: var(--tier-b-glow); }
.tier-badge--c     { background: var(--tier-c-bg);     color: var(--tier-c-text);     box-shadow: var(--tier-c-glow); }

/* D-tier intentional ghost (v1.1) — surface tint + dashed border + dim text + no glow.
   Reads as "intentional bottom rung," NOT as "broken/missing-data card." */
.tier-badge--d {
  background: var(--tier-d-bg);
  color: var(--tier-d-text);
  border: 1px dashed var(--tier-d-border);
  box-shadow: none;
}

/* Gamification slot — DORMANT in A1. Renders only when data-level > 0.
   A1 ships with no data-level attribute on any badge. Future ship sets
   data-level="N" → visual lights up automatically. */
.tier-badge[data-level]:not([data-level="0"])::after {
  content: attr(data-level);
  font-feature-settings: "subs" 1;     /* OpenType subscript */
  font-family: var(--font-mono);
  margin-left: 1px;
}

/* ============================================================================
 * Pill (§2.6) — multi-select chip, removable
 * ========================================================================== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-3);
  height: 28px;
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion-fast) var(--ease-out-expo),
              color var(--motion-fast) var(--ease-out-expo),
              border-color var(--motion-fast) var(--ease-out-expo);
}
.chip:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text-primary);
}
.chip:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.chip[data-active="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-bright);
}
.chip--success {
  background: var(--state-success-bg);
  border-color: var(--state-success);
  color: var(--state-success);
}

.chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: var(--space-1);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.10);
  color: inherit;
  font-size: 12px;
  line-height: 1;
}
.chip-x:hover { background: rgba(255, 255, 255, 0.18); }

/* ============================================================================
 * Card (§2.2) — base + --editor / --scanner / --showcase
 * ========================================================================== */

.card {
  display: block;
  padding: var(--density-card-padding);
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-decoration: none;
}
.card--editor { /* density-aware via tokens; no override needed */ }
.card--scanner {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.card--showcase {
  position: relative;
  overflow: hidden;
}

/* ============================================================================
 * Input (§2.2) — text / search / with-icon. Error state.
 * ========================================================================== */

.input-wrap {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  height: 36px;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  transition: border-color var(--motion-fast) var(--ease-out-expo);
}
.input-wrap:focus-within { border-color: var(--border-focus); }
.input-wrap[data-error="true"] { border-color: var(--state-error); }

.input {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1;
}
.input::placeholder { color: var(--text-muted); }

.input-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

/* ============================================================================
 * Select (§2.2) — dropdown with custom indicator
 * ========================================================================== */

.select {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 var(--space-8) 0 var(--space-3);
  background: var(--surface-1) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path fill='%239b9eaf' d='M6 8 0 0h12z'/></svg>")
              right var(--space-3) center / 10px 6px no-repeat;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  cursor: pointer;
}
.select:focus-visible { border-color: var(--border-focus); outline: none; }

/* ============================================================================
 * Density toggle (§2.5) — segmented control of 3 buttons. Hidden <768px.
 * ========================================================================== */

.density-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.density-toggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-base);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out-expo),
              color var(--motion-fast) var(--ease-out-expo);
}
.density-toggle button:hover { color: var(--text-primary); }
.density-toggle button[aria-checked="true"] {
  background: var(--accent-dim);
  color: var(--accent-bright);
}
.density-toggle button:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .density-toggle { display: none; }
}

/* ============================================================================
 * Avatar (§2.2) — with status ring, tier ring (data-tier), fallback initial
 * ========================================================================== */

.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-weight: var(--weight-bold);
  font-size: var(--text-md);
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar--lg { width: 64px; height: 64px; }
.avatar--sm { width: 32px; height: 32px; font-size: var(--text-sm); }

/* Tier ring per DNA — colored ring matching --tier-{X}-glow */
.avatar[data-tier="S+"] { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px #ff7a30; }
.avatar[data-tier="S"]  { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px #fbbf24; }
.avatar[data-tier="A"]  { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px #a855f7; }
.avatar[data-tier="B"]  { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px #3b82f6; }
.avatar[data-tier="C"]  { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px #64748b; }

/* ============================================================================
 * Bottom sheet (§2.4) — used in 2 places: mobile filter overlay + niche-pill picker
 * ========================================================================== */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: var(--z-sheet);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-base) var(--ease-out-expo);
}
.sheet-backdrop[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface-3);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  box-shadow: var(--shadow-4);
  z-index: calc(var(--z-sheet) + 1);
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--motion-base) var(--ease-out-expo);
}
.sheet[data-open="true"] { transform: translateY(0); }

.sheet-handle {
  display: block;
  width: 40px;
  height: 4px;
  margin: var(--space-3) auto;
  background: var(--border-strong);
  border-radius: var(--radius-pill);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}
.sheet-body { padding: var(--space-5); }

body[data-sheet-open="true"] {
  overflow: hidden;
}

/* ============================================================================
 * Empty state (§2.2) — icon + title + body + optional CTA, Discord-warm copy
 * ========================================================================== */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-5);
  text-align: center;
  color: var(--text-secondary);
  gap: var(--space-3);
}
.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}
.empty-title {
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin: 0;
}
.empty-body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-secondary);
  max-width: 42ch;
  line-height: var(--leading-normal);
  margin: 0;
}

/* ============================================================================
 * Loading skeleton (§2.2) — matches actual card layout, shimmer at --motion-slow
 * ========================================================================== */

.skeleton {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--border-default) 50%,
    transparent 100%
  );
  animation: shimmer var(--motion-slow) linear infinite;
}
@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

.skeleton-card {
  padding: var(--density-card-padding);
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.skeleton-avatar { width: 44px; height: 44px; border-radius: var(--radius-pill); }
.skeleton-bar { height: 12px; border-radius: var(--radius-xs); }
.skeleton-bar--name { width: 70%; }
.skeleton-bar--handle { width: 50%; }

/* ============================================================================
 * Error state (§2.2) — same shape as empty but with red accent border
 * ========================================================================== */

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-8) var(--space-5);
  background: var(--state-error-bg);
  border: 1px solid var(--state-error);
  border-radius: var(--radius-md);
  text-align: center;
  gap: var(--space-3);
  color: var(--text-primary);
}
.error-state .empty-icon {
  background: var(--state-error-bg);
  color: var(--state-error);
}

/* ============================================================================
 * Tooltip (§2.2) — popover with arrow
 * ========================================================================== */

.tooltip {
  position: absolute;
  z-index: var(--z-popover);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  box-shadow: var(--shadow-3);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-fast) var(--ease-out-expo);
}
.tooltip[data-visible="true"] {
  opacity: 1;
  pointer-events: auto;
}
.tooltip::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 8px;
  height: 8px;
  background: var(--surface-4);
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
}

/* ============================================================================
 * Active filters bar — composition primitive used by /marketplace
 * ========================================================================== */

.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) 0;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}
.active-filters[data-empty="true"] { display: none; }
.active-filters-helper {
  flex: 1 1 100%;
  margin-top: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-sm);
}
.active-filters-clear {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--accent-bright);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  padding: 0;
}
.active-filters-clear:hover { color: var(--accent); }

/* ============================================================================
 * Sticky CTA bar — generic mobile-bottom CTA primitive (Redesign A2 extract).
 * Used on profile (claim/contact) and any future surface with a single
 * primary action below 768px viewport. Visibility: data-visible="true".
 * Surface css ALWAYS supplies .btn--primary children for the action buttons.
 * ========================================================================== */

.sticky-cta-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-sticky);
  display: none;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--surface-3);
  border-top: 1px solid var(--border-default);
  transform: translateY(100%);
  transition: transform var(--motion-base) var(--ease-out-expo);
}

@media (max-width: 768px) {
  .sticky-cta-bar { display: flex; }
  .sticky-cta-bar[data-visible="true"] { transform: translateY(0); }
  /* Suppress while a sheet is open to avoid double-modal stacking */
  body[data-sheet-open="true"] .sticky-cta-bar { transform: translateY(100%); }
}

.sticky-cta-bar > .btn { flex: 1 1 0; }
