:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --card: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #708499);
  --accent: var(--tg-theme-button-color, #5288c1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e74c3c;
  --success: #2ecc71;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro", system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  min-height: 100vh;
}

/* ====== TOPBAR ====== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 16px;
}
.brand-logo { font-size: 20px; }
.counters {
  font-size: 13px; color: var(--hint);
  display: flex; align-items: baseline; gap: 4px;
}
.counters span#mau {
  color: var(--accent); font-weight: 700; font-size: 15px;
}
.counter-label { color: var(--hint); }

/* ====== TABS ====== */
.tabs {
  display: flex; gap: 6px;
  padding: 10px 12px;
  background: var(--bg);
  position: sticky; top: 57px; z-index: 9;
}
.tab {
  flex: 1;
  padding: 10px 8px;
  background: var(--card);
  color: var(--hint);
  border: none; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* ====== MAIN ====== */
main { padding: 12px 16px 80px; }
.loader { text-align: center; padding: 40px; color: var(--hint); }
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--hint);
}
.empty .icon { font-size: 48px; display: block; margin-bottom: 12px; }

/* ====== CARD ====== */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.product {
  display: flex; flex-direction: column; gap: 12px;
}
.product-head {
  display: flex; align-items: flex-start; gap: 12px;
}
.product-emoji {
  font-size: 28px; line-height: 1;
  flex-shrink: 0;
}
.product-info { flex: 1; min-width: 0; }
.product-info h3 {
  font-size: 15px; font-weight: 600;
  margin-bottom: 4px;
}
.product-desc {
  font-size: 13px; color: var(--hint);
  line-height: 1.4;
}
.product-bottom {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
}
.product-price {
  font-size: 18px; font-weight: 700;
  color: var(--accent);
}
.product-stock {
  font-size: 12px; color: var(--hint);
  margin-top: 2px;
}

/* ====== BUTTONS ====== */
.btn {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}
.btn:active { opacity: .75; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
}

/* ====== PROFILE ====== */
.profile-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.profile-row:last-child { border-bottom: none; }
.profile-row .label { color: var(--hint); font-size: 14px; }
.profile-row .value { font-weight: 600; }

.profile-header {
  display: flex;
  align-items: center;
  gap: 14px;
}
.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6ba6e8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  flex-shrink: 0;
}
.profile-name { font-size: 17px; font-weight: 600; }
.profile-username { font-size: 13px; color: var(--hint); margin-top: 2px; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* Статистика */
.stats-grid {
  display: flex;
  justify-content: space-around;
  gap: 8px;
}
.stat-item { flex: 1; text-align: center; }
.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}
.stat-label {
  font-size: 11px;
  color: var(--hint);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Реферальный код */
.ref-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(82, 136, 193, 0.1);
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 10px;
}
.ref-code code {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  user-select: all;
}
.btn-copy-icon {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
}
.btn-copy-icon:active { background: rgba(255,255,255,.1); }

.btn-share {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-share:active { opacity: .75; }

/* Промокоды */
.promo-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.promo-row:last-child { border-bottom: none; }
.promo-code {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 14px;
  color: var(--success);
  font-weight: 600;
  user-select: all;
}
.promo-info { font-size: 12px; color: var(--hint); margin-top: 2px; }

/* ====== PURCHASE ====== */
.purchase {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.purchase-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.purchase-title { font-weight: 600; font-size: 14px; }
.purchase-price { color: var(--accent); font-weight: 700; white-space: nowrap; }
.purchase-meta {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--hint);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-waiting { background: rgba(241,196,15,.15); color: #f1c40f; }
.badge-paid { background: rgba(52,152,219,.15); color: #3498db; }
.badge-completed { background: rgba(46,204,113,.15); color: var(--success); }
.badge-cancelled { background: rgba(231,76,60,.15); color: var(--danger); }

/* ====== АККАУНТ ====== */
.purchase-account {
  margin-top: 12px;
  padding: 12px;
  background: rgba(82, 136, 193, 0.08);
  border-radius: 10px;
}
.purchase-account .account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.purchase-account .account-row:last-of-type { border-bottom: none; }
.purchase-account code {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  user-select: all;
}
.btn-copy-small {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  font-size: 13px;
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
}
.btn-pay {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  font-size: 14px;
}

/* ====== TOAST ====== */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(0,0,0,.85);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 90vw;
  text-align: center;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ====== ЭКРАН ОЖИДАНИЯ ОПЛАТЫ ====== */
.waiting-screen, .success-screen {
  text-align: center;
  padding: 40px 20px;
}
.waiting-screen h2, .success-screen h2 {
  font-size: 20px;
  margin: 20px 0 12px;
}
.hint {
  color: var(--hint);
  font-size: 13px;
  margin: 6px 0;
}
.product-name {
  font-weight: 600;
  font-size: 15px;
  margin: 12px 0;
}
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(82, 136, 193, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.success-icon { font-size: 64px; margin-bottom: 16px; }
.success-account {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin: 20px 0;
  text-align: left;
}
.success-account .account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.success-account .account-row:last-child { border-bottom: none; }
.success-account .account-row .label {
  color: var(--hint);
  font-size: 13px;
}
.success-account .account-row code {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  user-select: all;
}
.btn-copy {
  width: 100%;
  margin-top: 12px;
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
}

/* ====== МОДАЛЬНОЕ ОКНО ====== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px 28px;
  width: 100%;
  max-width: 500px;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--hint);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.modal-product {
  background: rgba(82, 136, 193, 0.08);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.modal-product-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.modal-product-desc {
  font-size: 12px;
  color: var(--hint);
  line-height: 1.4;
}

.modal-price-block {
  text-align: center;
  padding: 12px 0 16px;
}

.modal-price-label {
  font-size: 12px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.modal-price {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
}

.modal-price-old {
  font-size: 14px;
  color: var(--hint);
  text-decoration: line-through;
  margin-top: 4px;
}

.modal-promo {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.modal-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: "SF Mono", Menlo, monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-apply {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  padding: 12px 16px;
  font-size: 13px;
}

.modal-promo-status {
  font-size: 12px;
  min-height: 16px;
  text-align: center;
  margin-bottom: 12px;
}

.modal-promo-status.success {
  color: var(--success);
}

.modal-promo-status.error {
  color: var(--danger);
}

.btn-buy-confirm {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  margin-top: 8px;
}

/* ====== НАЧАЛЬНЫЙ ЛОАДЕР ====== */
.initial-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 20px;
}

.big-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(82, 136, 193, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loader-text {
  color: var(--hint);
  font-size: 14px;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ====== ПЛАВНОЕ ПОЯВЛЕНИЕ КАРТОЧЕК ====== */
.fade-in {
  animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ====== КРАСИВАЯ ШАПКА ====== */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Кнопка "открыть бота" (в шапке, если нужно) */
.btn-bot {
  background: transparent;
  border: none;
  color: var(--hint);
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.btn-bot:active { background: rgba(255,255,255,.08); }

/* ====== УЛУЧШЕНИЕ КАРТОЧЕК ====== */
.card, .purchase, .product {
  transition: transform 0.15s ease;
}

.card:active, .purchase:active {
  transform: scale(0.99);
}

/* Кнопки — плавнее */
.btn, .btn-share, .btn-copy-small, .btn-pay {
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active, .btn-share:active, .btn-copy-small:active, .btn-pay:active {
  transform: scale(0.97);
}

/* Скролл-бар потемнее (для мобильных) */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
