/**
 * NEXUSAR App Shell — tokens del holding
 * @see ../../css/tokens.css
 */
@import url("/css/tokens.css");

:root {
  --shell-header-h: 56px;
  --shell-tab-h: 64px;
  --shell-max: 720px;
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: var(--color-warning);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  background: var(--color-bg-main);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(var(--shell-tab-h) + env(safe-area-inset-bottom, 0px));
}

a { color: inherit; }

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  min-height: var(--shell-header-h);
  padding: 0.5rem 1rem;
  padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
  background: rgba(8, 9, 10, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-border);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0.03em;
  font-size: 0.9375rem;
}

.app-brand span {
  background: var(--gradient-nexus);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-header__nav-desktop {
  display: none;
  align-items: center;
  gap: 0.25rem;
}

/* ── Main ── */
.app-main {
  flex: 1;
  width: min(100% - 2rem, var(--shell-max));
  margin: 0 auto;
  padding: var(--space-lg) 0 var(--space-xl);
}

.app-view[hidden] { display: none !important; }

.app-view {
  animation: app-fade 0.28s var(--ease-out);
}

@keyframes app-fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app-view { animation: none; }
}

/* ── Typography / premium blocks ── */
.app-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 1.875rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.app-body {
  margin: 0 0 var(--space-lg);
  color: var(--color-text-secondary);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.app-section-title {
  margin: 0 0 var(--space-md);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-meta {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.app-empty {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  padding: var(--space-md) 0;
}

/* ── Buttons ── */
.app-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-pill);
  border: none;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), opacity 0.15s, background 0.15s;
  width: 100%;
}

.app-btn:active { transform: scale(0.98); }
.app-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.app-btn--primary {
  background: #fff;
  color: #000;
}

.app-btn--secondary {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-strong);
}

.app-btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid transparent;
  min-height: 40px;
  padding: 0.4rem 0.75rem;
  width: auto;
}

.app-btn--finance {
  background: var(--gradient-finance);
  color: #fff;
}

.app-btn--health {
  background: var(--gradient-health);
  color: #fff;
}

.app-btn-row {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

@media (min-width: 768px) {
  .app-btn { width: auto; }
  .app-btn-row {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

/* ── Cards ── */
.app-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: var(--space-md);
}

.app-card--link {
  display: block;
  text-decoration: none;
  transition: border-color 0.2s, transform 0.2s;
}

.app-card--link:hover {
  border-color: var(--color-border-strong);
  transform: translateY(-1px);
}

.app-card--finance {
  border-color: rgba(0, 229, 255, 0.22);
  background:
    radial-gradient(ellipse 70% 80% at 100% 0%, rgba(0, 229, 255, 0.08), transparent 55%),
    var(--color-bg-card);
}

.app-card--health {
  border-color: rgba(165, 94, 234, 0.22);
  background:
    radial-gradient(ellipse 70% 80% at 0% 0%, rgba(165, 94, 234, 0.08), transparent 55%),
    var(--color-bg-card);
}

.app-card__eyebrow {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-brand-cyan);
}

.app-card--health .app-card__eyebrow {
  color: var(--color-brand-purple);
}

.app-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.app-card p {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
}

/* ── Stats ── */
.app-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: var(--space-lg);
}

.app-stat {
  text-align: center;
  padding: 0.85rem 0.5rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--color-border);
}

.app-stat__value {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--color-brand-cyan);
  font-variant-numeric: tabular-nums;
}

.app-stat__label {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

/* ── Profile header ── */
.app-profile-header {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: var(--space-lg);
}

.app-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--gradient-nexus-diagonal);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.5rem;
  flex-shrink: 0;
}

/* ── Quick grid ── */
.app-quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: var(--space-lg);
}

/* ── Leaderboard / lists ── */
.app-list-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
  color: inherit;
}

.app-list-row:last-child { border-bottom: none; }

.app-list-row .rank {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
}

.app-list-row .rank.rank-1 { color: var(--gold); }
.app-list-row .rank.rank-2 { color: var(--silver); }
.app-list-row .rank.rank-3 { color: var(--bronze); }

.app-list-row .name {
  font-weight: 600;
  text-decoration: none;
}

.app-list-row .time {
  font-weight: 700;
  color: var(--color-brand-cyan);
  font-variant-numeric: tabular-nums;
}

/* ── Badges ── */
.app-badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.75rem;
}

.app-badge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.75rem 0.5rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
}

.app-badge-card.badge-gold { border-color: rgba(251, 191, 36, 0.35); }
.app-badge-card.badge-silver { border-color: rgba(203, 213, 225, 0.35); }
.app-badge-card.badge-bronze { border-color: rgba(255, 159, 67, 0.35); }
.app-badge-card.badge-special { border-color: rgba(165, 94, 234, 0.4); }

.app-badge-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--color-surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.app-badge-title {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.3;
}

.app-badge-tier {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

/* ── Activity ── */
.app-activity-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
}

.app-activity-row:last-child { border-bottom: none; }

.app-activity-kind {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-brand-purple);
  font-weight: 700;
}

/* ── Forms ── */
.app-form {
  display: grid;
  gap: 0.75rem;
}

.app-form input {
  min-height: 44px;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg-main);
  color: var(--color-text);
  font: inherit;
}

.app-form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.app-form-inline input {
  flex: 1;
  min-width: 160px;
  min-height: 44px;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg-main);
  color: var(--color-text);
  font: inherit;
}

.app-error {
  color: var(--color-danger);
  font-size: 0.875rem;
  margin: 0.5rem 0 0;
}

.app-success {
  color: var(--color-success);
  font-size: 0.875rem;
  margin: 0.5rem 0 0;
}

.auth-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 12px;
  background: rgba(0, 229, 255, 0.04);
  border: 1px dashed rgba(0, 229, 255, 0.2);
}

.qr-image {
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.auth-user {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Tab bar ── */
.app-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: var(--shell-tab-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(8, 9, 10, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--color-border);
}

.app-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 44px;
  padding: 0.4rem 0.25rem;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}

.app-tab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-tab.is-active {
  color: var(--color-brand-cyan);
}

.app-tab--finance.is-active,
.app-tab--finance:hover {
  color: var(--color-brand-cyan);
}

.app-tab--health.is-active {
  color: var(--color-brand-purple);
}

/* ── Desktop ── */
@media (min-width: 900px) {
  body { padding-bottom: 0; }

  .app-tabbar { display: none; }

  .app-header__nav-desktop { display: flex; }

  .app-main {
    width: min(100% - 3rem, 960px);
    padding-top: var(--space-xl);
  }

  .auth-grid {
    grid-template-columns: 1fr 1fr;
  }

  .app-quick-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
