/* FREAK SHOP Mini App — mobile-first, dark theme, green accents.
   Uses Telegram theme variables when available, dark fallbacks otherwise. */

:root {
  --bg: var(--tg-theme-bg-color, #0d1117);
  --card: var(--tg-theme-secondary-bg-color, #161b22);
  --text: var(--tg-theme-text-color, #e6edf3);
  --muted: var(--tg-theme-hint-color, #8b949e);
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --danger: #f85149;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #14532d, #166534);
  color: #fff;
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: 1px; }
.wallet-chip {
  background: rgba(255,255,255,0.16); color: #fff; border: none;
  padding: 7px 14px; border-radius: 999px; font-weight: 700; font-size: 14px;
}

.banner {
  margin: 12px 14px 0; padding: 12px;
  background: rgba(248, 81, 73, 0.12); border: 1px solid rgba(248, 81, 73, 0.4);
  border-radius: var(--radius); font-size: 13px; text-align: center;
}

main { padding: 14px; max-width: 720px; margin: 0 auto; }

/* ---------- Catalogue ---------- */
.search-row input {
  width: 100%; padding: 13px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-size: 16px; outline: none;
}
.search-row input:focus { border-color: var(--accent); }

.meta-row {
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 12px; margin: 10px 2px;
}

.grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
}
.product-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 8px; cursor: pointer;
  text-align: left; color: var(--text); width: 100%;
}
.product-card:active { border-color: var(--accent); }
.product-card.oos { opacity: 0.55; }
.p-name { font-weight: 700; font-size: 14px; line-height: 1.35; min-height: 38px; }
.p-prices { display: flex; justify-content: space-between; align-items: baseline; }
.price-usd { color: var(--accent); font-weight: 700; font-size: 13px; }
.price-inr { color: #facc15; font-weight: 800; font-size: 16px; }
.badge {
  align-self: flex-start; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
}
.badge.in { background: rgba(34,197,94,0.15); color: var(--accent); }
.badge.out { background: rgba(248,81,73,0.15); color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* ---------- Cards & buttons ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 14px;
}
.btn-primary, .btn-secondary, .btn-ghost {
  width: 100%; padding: 14px; border-radius: 12px; border: none;
  font-size: 16px; font-weight: 700; margin-top: 12px; cursor: pointer;
}
.btn-primary { background: var(--accent-dark); color: #fff; }
.btn-primary:active { background: var(--accent); }
.btn-primary:disabled { opacity: 0.5; }
.btn-secondary { background: rgba(34,197,94,0.14); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-mini {
  background: rgba(34,197,94,0.14); color: var(--accent); border: none;
  padding: 7px 14px; border-radius: 9px; font-weight: 700; cursor: pointer;
  flex-shrink: 0;
}
.link-btn { display: block; text-align: center; text-decoration: none; }

.back-btn {
  background: none; border: none; color: var(--accent);
  font-size: 16px; font-weight: 700; padding: 4px 0 12px; cursor: pointer;
}

input[type="text"], input[type="number"] {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 16px; outline: none; margin-top: 6px;
}
input:focus { border-color: var(--accent); }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-top: 16px; font-weight: 600; }

/* ---------- Product detail ---------- */
.detail-card h2 { font-size: 20px; margin-bottom: 8px; }
.price-row { display: flex; gap: 14px; align-items: baseline; margin: 14px 0 4px; }
.price-row .price-inr { font-size: 24px; }
.price-row .price-usd { font-size: 16px; }
.stock-line { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.stock-line.in { color: var(--accent); }
.stock-line.out { color: var(--danger); }
.qty-row, .total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--border); margin-top: 10px;
}
.qty-ctrl { display: flex; align-items: center; gap: 16px; }
.qty-ctrl button {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 20px; cursor: pointer;
}
#qty-value { font-weight: 800; font-size: 17px; min-width: 24px; text-align: center; }
#pd-total { font-weight: 800; color: #facc15; }

/* ---------- Success ---------- */
.success-card { text-align: center; }
.success-icon { font-size: 46px; margin-bottom: 8px; }
.items-label { text-align: left; font-weight: 700; margin-top: 16px; }
.items-box {
  text-align: left; background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-top: 8px;
  font-family: ui-monospace, Menlo, monospace; font-size: 13px;
  white-space: pre-wrap; word-break: break-all; user-select: all;
}

/* ---------- Force-join gate ---------- */
.join-card { text-align: center; }
.join-icon { font-size: 46px; margin-bottom: 8px; }
.join-card h2 { font-size: 20px; margin-bottom: 8px; }

/* ---------- Wallet ---------- */
.balance-card { text-align: center; background: linear-gradient(135deg, #14532d, #166534); color: #fff; border: none; }
.balance-card .muted { color: #bbf7d0; }
.balance-big { font-size: 34px; font-weight: 800; margin: 6px 0 2px; }
.section-title { font-size: 17px; margin: 18px 0 10px; }

.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab {
  flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--muted); font-weight: 700; font-size: 14px; cursor: pointer;
}
.tab.active { background: var(--accent-dark); color: #fff; border-color: var(--accent-dark); }

#upi-qr-box { margin-top: 16px; text-align: center; }
#upi-qr-img { width: 230px; height: 230px; border-radius: 12px; background: #fff; padding: 8px; }
#upi-qr-box .field-label { text-align: left; }

.copy-row {
  display: flex; align-items: center; gap: 10px; margin-top: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px;
}
.copy-row code { flex: 1; word-break: break-all; font-size: 13px; text-align: left; }

/* ---------- Orders ---------- */
.order-card { padding: 0; overflow: hidden; }
.order-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  gap: 10px; padding: 15px 16px; background: none; border: none;
  color: var(--text); cursor: pointer; text-align: left;
}
.order-name { font-weight: 700; font-size: 14px; }
.order-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.order-price { font-weight: 800; color: #facc15; white-space: nowrap; }
.order-items { padding: 0 16px 16px; }
.order-items .items-box { margin-top: 0; }

/* ---------- Profile ---------- */
.profile-card { text-align: center; }
.avatar {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 10px;
  background: linear-gradient(135deg, #14532d, #22c55e); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800;
}
.profile-balance {
  display: flex; justify-content: space-between; margin-top: 16px;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.links-card { padding: 6px 0; }
.link-row {
  display: flex; justify-content: space-between; padding: 14px 18px;
  color: var(--text); text-decoration: none; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.link-row:last-child { border-bottom: none; }
.link-row span { color: var(--muted); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-item {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 9px 0 8px; font-size: 11px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab-item .tab-icon { font-size: 20px; }
.tab-item.active { color: var(--accent); }

/* ---------- Toast & loading ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 50; max-width: 88vw;
  background: #1f2937; color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { background: #7f1d1d; }
.toast.success { background: #14532d; }

.loading {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.2); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
