:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #888888);
  --link: var(--tg-theme-link-color, #1a6fe8);
  --btn-bg: var(--tg-theme-button-color, #1a6fe8);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --gap: 16px;
  --radius: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --brand-night: #0b1f3a;
  --brand-night-mid: #0d2e5a;
  --brand-alliance: #1a6fe8;
  --brand-cyan: #00c4e8;
  --brand-success: #1ae89a;
  --brand-gold: #f0c040;
  --brand-warning: #f58c1a;
  --brand-error: #e84040;
  --brand-line: rgba(26, 111, 232, 0.35);
  --brand-ring-cyan: rgba(0, 196, 232, 0.22);
  --brand-ring-soft: rgba(26, 111, 232, 0.14);
  --surface: var(--tg-theme-secondary-bg-color, #f7faff);
  --font-display: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --shadow-card: 0 10px 32px rgba(11, 31, 58, 0.09);
  --shadow-hero: 0 22px 56px rgba(11, 31, 58, 0.24);
  --nav-pad: max(10px, env(safe-area-inset-bottom, 0px));
  --touch-min: 48px;
  --tg-header-offset: 56px;
  --metric-card-bg: var(--surface);
  --tab-active-bg: var(--brand-alliance);
  --chip-active-bg: var(--brand-alliance);
  --chip-inactive-border: var(--brand-line);
  --fab-size: 52px;
}

[hidden] { display: none !important; }

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  padding: calc(var(--gap) + env(safe-area-inset-top, 0px) + var(--tg-header-offset)) var(--gap)
    calc(var(--gap) + env(safe-area-inset-bottom, 0px) + var(--fab-size));
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}

.screen-main {
  padding-bottom: calc(var(--nav-pad) + 8px);
}

.loading-screen {
  justify-content: center;
  align-items: center;
  gap: var(--gap);
}

.error-screen {
  justify-content: center;
  align-items: center;
  gap: var(--gap);
  text-align: center;
}

.error-hint {
  color: var(--hint);
  font-size: 0.85rem;
  line-height: 1.45;
  max-width: 26rem;
  text-align: center;
}

.error-icon {
  color: var(--brand-warning);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--secondary-bg);
  border-top-color: var(--btn-bg);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.app-header {
  text-align: center;
  padding: var(--gap) 0 8px;
}

.app-header h1 {
  font-size: 1.45rem;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.subtitle {
  color: var(--hint);
  font-size: 0.9rem;
  margin-top: 4px;
}

.tab-nav {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px var(--gap);
  margin: 0 calc(-1 * var(--gap)) 12px;
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + var(--tg-header-offset));
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--brand-ring-soft);
}

.tab-chip {
  flex: 0 0 auto;
  min-height: var(--touch-min);
  padding: 0 18px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--brand-line);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.12s ease;
}

.tab-chip:active {
  transform: scale(0.98);
}

.tab-chip--active {
  background: var(--tab-active-bg);
  color: var(--btn-text);
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(26, 111, 232, 0.35);
}

.tab-panels {
  flex: 1;
}

.tab-panel {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.tab-panel--active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.hero-card {
  background: linear-gradient(135deg, var(--brand-night-mid) 0%, var(--brand-night) 100%);
  color: #e8f2ff;
  border-radius: var(--radius-lg);
  padding: calc(var(--gap) + 6px);
  text-align: center;
  box-shadow: var(--shadow-hero);
  margin-bottom: var(--gap);
}

.hero-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(232, 242, 255, 0.75);
}

.hero-value {
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 1.1;
  margin: 6px 0;
  background: linear-gradient(90deg, #fff 0%, var(--brand-cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-hint {
  font-size: 0.82rem;
  color: rgba(232, 242, 255, 0.65);
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: calc(var(--gap) + 6px);
}

.metric-card {
  background: var(--metric-card-bg);
  border-radius: var(--radius-md);
  padding: 14px;
  border: 1px solid var(--brand-ring-soft);
  box-shadow: var(--shadow-card);
}

.metric-icon {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.metric-icon--bingx {
  background: linear-gradient(90deg, var(--brand-alliance), var(--brand-cyan));
}
.metric-icon--kyc,
.metric-icon--trade {
  background: linear-gradient(135deg, var(--brand-success), #12b882);
}
.metric-icon--m1,
.metric-icon--m2 {
  background: linear-gradient(90deg, var(--brand-alliance), #4a9fff);
}
.metric-icon--premium {
  background: linear-gradient(135deg, var(--brand-alliance), var(--brand-gold));
}
.metric-icon--vip {
  background: linear-gradient(135deg, var(--brand-gold), var(--brand-warning));
}

.metric-value {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
}

.metric-label {
  font-size: 0.72rem;
  color: var(--hint);
  margin-top: 4px;
  line-height: 1.3;
}

.funnel-block {
  margin-top: 8px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.section-hint {
  font-size: 0.78rem;
  color: var(--hint);
  margin-bottom: 12px;
}

.funnel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.funnel-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.funnel-label {
  font-size: 0.72rem;
  color: var(--hint);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.funnel-track {
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--secondary-bg);
  overflow: hidden;
  border: 1px solid var(--brand-ring-soft);
}

.funnel-fill {
  height: 100%;
  border-radius: inherit;
  min-width: 0;
  transition: width 0.35s ease;
}

.funnel-fill--registro { background: linear-gradient(90deg, #5a7ab0, var(--brand-alliance)); }
.funnel-fill--kyc { background: linear-gradient(90deg, var(--brand-success), #12c98a); }
.funnel-fill--trade { background: linear-gradient(90deg, #0ecf8f, var(--brand-success)); }
.funnel-fill--m1 { background: linear-gradient(90deg, var(--brand-alliance), var(--brand-cyan)); }
.funnel-fill--m2 { background: linear-gradient(90deg, #3d8fff, var(--brand-alliance)); }
.funnel-fill--premium { background: linear-gradient(135deg, var(--brand-alliance), var(--brand-gold)); }
.funnel-fill--vip { background: linear-gradient(135deg, var(--brand-gold), var(--brand-warning)); }

.filter-row-wrap {
  margin: 0 calc(-1 * var(--gap)) 12px;
}

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px var(--gap) 8px;
  scroll-padding-inline: var(--gap);
}

.filter-chip {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--chip-inactive-border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.filter-chip--active {
  background: var(--chip-active-bg);
  color: var(--btn-text);
  border-color: transparent;
}

.equipo-total-line {
  font-size: 0.85rem;
  color: var(--hint);
  margin-bottom: 10px;
}

.lista-referidos {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.referido-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px;
  border: 1px solid var(--brand-ring-soft);
  box-shadow: 0 4px 16px rgba(11, 31, 58, 0.06);
}

.referido-nombre {
  font-weight: 600;
  font-size: 0.95rem;
  font-family: var(--font-display);
}

.referido-user {
  font-size: 0.8rem;
  color: var(--hint);
  margin-top: 2px;
}

.referido-fecha {
  font-size: 0.75rem;
  color: var(--hint);
  margin-top: 6px;
  font-family: var(--font-mono);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: var(--font-body);
}

.badge--kyc,
.badge--trade {
  background: rgba(26, 232, 154, 0.18);
  color: #0a6b4a;
}
.badge--m1,
.badge--m2 {
  background: rgba(26, 111, 232, 0.12);
  color: var(--brand-alliance);
}
.badge--m2prog {
  background: rgba(0, 196, 232, 0.15);
  color: #006080;
}
.badge--premium {
  background: linear-gradient(135deg, rgba(26, 111, 232, 0.2), rgba(240, 192, 64, 0.35));
  color: var(--brand-night);
}
.badge--vip {
  background: rgba(240, 192, 64, 0.28);
  color: #5c4a10;
}

.empty-msg {
  text-align: center;
  color: var(--hint);
  padding: 24px 12px;
  font-size: 0.9rem;
}

.gran-toggle {
  display: flex;
  gap: 10px;
  margin-bottom: var(--gap);
}

.gran-btn {
  flex: 1;
  min-height: var(--touch-min);
  border-radius: var(--radius-md);
  border: 2px solid var(--brand-line);
  background: var(--surface);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.gran-btn--active {
  border-color: var(--brand-alliance);
  box-shadow: 0 4px 14px rgba(26, 111, 232, 0.2);
  background: color-mix(in srgb, var(--brand-alliance) 12%, var(--surface));
}

.historial-periodos {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.period-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px;
  border: 1px solid var(--brand-ring-soft);
}

.period-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.period-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.period-stat-label {
  font-size: 0.7rem;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.period-stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
}

.mini-funnel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.mini-funnel-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-funnel-row span:first-child {
  width: 72px;
  flex-shrink: 0;
  font-size: 0.65rem;
  color: var(--hint);
  text-transform: uppercase;
}

.mini-funnel-track {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--secondary-bg);
  overflow: hidden;
}

.mini-funnel-fill {
  height: 100%;
  border-radius: inherit;
  transition: width 0.3s ease;
}

.mini-funnel-empty {
  color: var(--hint);
  font-size: 0.8rem;
  margin-top: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  padding: 0 22px;
  border-radius: var(--radius-md);
  border: none;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(90deg, var(--brand-alliance), var(--brand-cyan));
  color: var(--btn-text);
  box-shadow: 0 6px 20px rgba(26, 111, 232, 0.35);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--brand-line);
  box-shadow: 0 2px 12px rgba(11, 31, 58, 0.06);
}

.btn-block {
  width: 100%;
  margin-top: 12px;
}

.fab-export {
  position: fixed;
  right: calc(var(--gap) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--gap) + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  min-height: var(--fab-size);
  padding: 0 18px;
  border-radius: var(--radius-pill);
  border: none;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--btn-text);
  background: linear-gradient(135deg, var(--brand-alliance), var(--brand-gold));
  box-shadow: 0 10px 28px rgba(11, 31, 58, 0.28);
}

.fab-export:active {
  transform: scale(0.98);
}
