/* =====================================================================
   TELEGRAM MINI APP — GIFT MARKETPLACE
   Dark theme matching Telegram's design language
   ===================================================================== */

/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors */
  --bg-primary:    #0e0e0e;
  --bg-secondary:  #1a1a1a;
  --bg-card:       #1c1c1c;
  --bg-card-alt:   #222222;
  --bg-input:      #2a2a2a;
  --bg-chip:       #252525;
  --bg-filter:     #2e2e2e;

  --text-primary:  #ffffff;
  --text-secondary:#8a8a8a;
  --text-muted:    #5a5a5a;

  --accent-blue:   #4D9EFF;
  --accent-gold:   #D4A843;
  --accent-green:  #3D8F5F;
  --accent-gem:    #5B9BFF;

  --border:        rgba(255,255,255,0.07);
  --border-hover:  rgba(255,255,255,0.12);

  /* Spacing */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Sizes */
  --nav-height: 72px;
  --top-bar-height: 48px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── App Shell ────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

/* ── Top Balance Bar ──────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  background: var(--bg-primary);
  z-index: 10;
  flex-shrink: 0;
}

.balance-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.stars-chip {
  background: linear-gradient(135deg, #2a2010 0%, #3a2a10 100%);
  border: 1px solid rgba(212,168,67,0.25);
  color: var(--accent-gold);
}

.gram-chip {
  background: linear-gradient(135deg, #101828 0%, #162035 100%);
  border: 1px solid rgba(77,158,255,0.25);
  color: var(--accent-blue);
}

.balance-icon { font-size: 14px; }

.gem-icon {
  display: flex;
  align-items: center;
}

/* ── Page Container ───────────────────────────────────────────────── */
.page-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-height) + 16px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  -webkit-overflow-scrolling: touch;
}

.page.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

/* ── Hero Banner ──────────────────────────────────────────────────── */
.hero-banner {
  margin: 8px 16px 0;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #1565C0 0%, #0D47A1 40%, #1976D2 70%, #42A5F5 100%);
  padding: 20px 24px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.hero-banner::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 70% 50%, rgba(100,180,255,0.3) 0%, transparent 60%);
}

.hero-banner::after {
  content: '';
  position: absolute;
  bottom: -20px;
  right: -10px;
  width: 140px;
  height: 140px;
  background: radial-gradient(circle, rgba(100,160,255,0.15) 0%, transparent 70%);
}

.hero-content { position: relative; z-index: 1; }

.hero-title {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.hero-stars {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: -16px;
}

.hero-star {
  filter: drop-shadow(0 4px 16px rgba(255,255,255,0.3));
  animation: float 3s ease-in-out infinite;
}

.hero-star--lg {
  width: 72px;
  height: 72px;
  margin-right: -12px;
  animation-delay: 0s;
}

.hero-star--md {
  width: 56px;
  height: 56px;
  animation-delay: 0.8s;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-6px) rotate(2deg); }
}

/* ── Tab Navigation ───────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 16px 16px 0;
  flex-shrink: 0;
}

.tab-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 4px;
  letter-spacing: -0.01em;
  transition: color 0.18s ease;
  position: relative;
}

.tab-btn.active {
  color: var(--text-primary);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
}

.tab-btn.gold { color: var(--accent-gold); }
.tab-btn.gold.active { color: var(--accent-gold); }
.tab-btn.gold.active::after { background: var(--accent-gold); }

.tab-btn + .tab-btn { margin-left: 16px; }

/* ── Search Row ───────────────────────────────────────────────────── */
.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 0;
}

.search-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 0 14px;
  height: 40px;
  transition: border-color 0.15s;
}

.search-input-wrap:focus-within {
  border-color: var(--border-hover);
}

.search-icon { flex-shrink: 0; }

.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
}

.search-input::placeholder { color: var(--text-muted); }

.filter-btn-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:active { background: var(--bg-filter); }

/* ── Filters Row ──────────────────────────────────────────────────── */
.filters-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 0;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.filters-row::-webkit-scrollbar { display: none; }

.filter-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-filter);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s;
}

.filter-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--accent-blue);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.icon-btn-sm {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-filter);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.filter-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

.filter-clear-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.filter-clear-btn svg path { stroke: #fff; }

.filter-dropdown {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-filter);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.filter-dropdown:hover { border-color: var(--border-hover); }

.filter-count-inline {
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
}

.filter-dropdown--arrow {
  border-radius: 20px 8px 8px 20px;
}

/* ── Items Grid ───────────────────────────────────────────────────── */
.items-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 16px 0;
}

/* ── Item Card — Type A (owned/selling) ───────────────────────────── */
.item-card {
  border-radius: var(--radius-md);
  background: var(--bg-card);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.item-card:active {
  transform: scale(0.97);
}

.item-card--owned {
  display: flex;
  flex-direction: column;
}

.item-card--listed {
  display: flex;
  flex-direction: column;
}

/* Card image wrapper */
.card-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg-card-alt);
  overflow: hidden;
}

.card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Placeholder when no image */
.card-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-card-alt));
}

.card-info-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-secondary);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

/* Card badges (wallet / clover icons) */
.card-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
  z-index: 2;
}

.card-badge-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

/* Card body */
.card-body {
  padding: 10px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Owned card: price centered */
.card-body--owned {
  align-items: center;
  text-align: center;
}

.card-price-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-gem-icon {
  display: flex;
  align-items: center;
}

.card-best-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: -2px;
}

/* Sell now button */
.btn-sell {
  width: 100%;
  padding: 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-filter);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  letter-spacing: 0.01em;
}

.btn-sell:hover { background: var(--bg-chip); border-color: var(--border-hover); }

/* Offers row */
.card-offers-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.offers-count {
  color: var(--text-primary);
  font-weight: 700;
}

/* Listed card */
.card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.card-item-id {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

/* Price + cart row */
.card-price-action {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-buy {
  flex: 1;
  padding: 8px 10px;
  border-radius: 20px;
  background: var(--accent-blue);
  border: none;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  justify-content: center;
  transition: opacity 0.15s, transform 0.12s;
  white-space: nowrap;
}

.btn-buy:active { opacity: 0.8; transform: scale(0.97); }

.btn-buy-gem {
  display: flex;
  align-items: center;
}

.btn-cart-sm {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg-filter);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.btn-cart-sm:active { background: var(--bg-chip); }

/* Skeleton loading */
.skeleton-card {
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  aspect-ratio: 0.7;
  position: relative;
  overflow: hidden;
}

.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.04) 50%, transparent 100%);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ── Load More ────────────────────────────────────────────────────── */
.load-more-wrap {
  padding: 16px;
  text-align: center;
}

.load-more-btn {
  padding: 12px 32px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.load-more-btn:hover { background: var(--bg-filter); color: var(--text-primary); }

/* ── Bottom Navigation ────────────────────────────────────────────── */
.bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: var(--nav-height);
  padding-bottom: var(--safe-bottom);
  background: rgba(14,14,14,0.95);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 500;
  transition: color 0.15s ease;
  min-width: 52px;
}

.nav-item.active { color: var(--accent-blue); }

.nav-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
}

.nav-store-dot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

/* Active store button: circle highlight */
.nav-item[data-page="store"].active .nav-store-dot::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-blue);
  z-index: -1;
  opacity: 0.15;
}

.nav-item[data-page="store"].active {
  color: var(--accent-blue);
}

/* Avatar nav item */
.nav-avatar {
  padding: 4px;
}

.avatar-wrap {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-filter);
  border: 2px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.avatar-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* ── Coming Soon / Empty ─────────────────────────────────────────── */
.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  gap: 12px;
  color: var(--text-muted);
}

.coming-soon-icon { font-size: 48px; }

.coming-soon h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-secondary);
}

.coming-soon p { font-size: 14px; }

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty-icon { font-size: 48px; }
.empty-state p { font-size: 14px; color: var(--text-secondary); }

.btn-primary {
  padding: 10px 24px;
  border-radius: 20px;
  background: var(--accent-blue);
  border: none;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.gifts-header {
  padding: 16px 16px 0;
}

.gifts-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ── Item Detail Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s ease;
}

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

.modal-sheet {
  width: 100%;
  max-height: 88vh;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  overflow-y: auto;
  padding-bottom: calc(24px + var(--safe-bottom));
  animation: slideUp 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

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

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border-hover);
  border-radius: 2px;
  margin: 12px auto 0;
}

.modal-img-wrap {
  padding: 16px 24px;
  display: flex;
  justify-content: center;
}

.modal-img-wrap img {
  width: 70%;
  max-width: 220px;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.modal-info { padding: 0 20px; }

.modal-badges {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.modal-name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.modal-id {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.modal-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-price {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.modal-offers {
  font-size: 13px;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.btn-cart {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--accent-blue);
  border: none;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s;
}

.btn-offer {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-filter);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-filter);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ── Scrollbar ────────────────────────────────────────────────────── */
.page::-webkit-scrollbar { width: 2px; }
.page::-webkit-scrollbar-track { background: transparent; }
.page::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Gem SVG inline ───────────────────────────────────────────────── */
.gem-sm {
  display: inline-block;
  vertical-align: middle;
  margin-left: 2px;
}
