/* بدون این، display: grid در .splash و .sheet ویژگی hidden را خنثی می‌کند
   و اسپینر و پس‌زمینه‌ی تیره‌ی برگه هیچ‌وقت کنار نمی‌روند. */
[hidden] { display: none !important; }

/* رنگ‌ها از تم تلگرام می‌آیند تا مینی‌اپ با پوسته‌ی کاربر (روشن/تاریک) یکی شود. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #0f1115);
  --muted: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f7bf6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f7bf6);
  --border: color-mix(in srgb, var(--muted) 22%, transparent);
  --radius: 14px;
  --ok: #2ea56b;
  --warn: #d99a0b;
  --bad: #d8453c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", "IRANSans", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}

body { padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }

/* ── بارگذاری ── */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ── سربرگ ── */
.head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 0 12px;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: var(--surface) center/cover no-repeat;
  display: grid; place-items: center; font-weight: 700; color: var(--muted);
}
.name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shop { color: var(--muted); font-size: 12px; }
.balance { text-align: left; flex: none; }
.balance-label { display: block; color: var(--muted); font-size: 11px; }
.balance strong { font-size: 15px; }

/* ── تب‌ها ── */
.tabs {
  display: flex; gap: 6px; padding: 4px; margin-bottom: 14px;
  background: var(--surface); border-radius: var(--radius);
  position: sticky; top: 0; z-index: 5;
}
.tab {
  flex: 1; padding: 9px 4px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.tab.is-active { background: var(--bg); color: var(--text); }

.panel { display: none; }
.panel.is-active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .panel.is-active { animation: none; } }

/* ── کارت‌ها ── */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title { font-weight: 700; }
.badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted);
}
.badge.ok   { background: color-mix(in srgb, var(--ok) 16%, transparent);   color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.bad  { background: color-mix(in srgb, var(--bad) 15%, transparent);  color: var(--bad); }

.meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 13px; margin-top: 8px; }
.meta b { color: var(--text); font-weight: 600; }

/* نوار مصرف */
.bar { height: 7px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 20%, transparent); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--ok); transition: width .3s ease; }
.bar.warn > i { background: var(--warn); }
.bar.bad  > i { background: var(--bad); }

/* ── دکمه‌ها ── */
.row { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1; padding: 10px 12px; border: 0; border-radius: 11px;
  background: color-mix(in srgb, var(--muted) 15%, transparent); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { opacity: .7; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.wide { width: 100%; }

.price { font-weight: 700; color: var(--accent); white-space: nowrap; }
.desc { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* ── حالت خالی ── */
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty-icon { font-size: 40px; display: block; margin-bottom: 10px; }

.notice { background: var(--surface); border-radius: var(--radius); padding: 14px; color: var(--muted); font-size: 13px; }
.notice b { color: var(--text); }

/* ── شیت پایین ── */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; align-items: end; z-index: 20; }
.sheet-card {
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 22px 16px calc(22px + env(safe-area-inset-bottom));
  position: relative; max-height: 86vh; overflow-y: auto;
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) { .sheet-card { animation: none; } }
.sheet-close {
  position: absolute; inset-inline-start: 14px; top: 14px;
  width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: var(--surface); color: var(--muted); font-size: 14px; cursor: pointer;
}
.sheet-title { font-weight: 700; text-align: center; margin-bottom: 14px; }
.qr { display: block; width: 210px; max-width: 70vw; aspect-ratio: 1; margin: 0 auto 14px; border-radius: 12px; background: #fff; padding: 8px; }
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; direction: ltr; text-align: left;
  background: var(--surface); border-radius: 10px; padding: 10px; margin-bottom: 8px;
  word-break: break-all; max-height: 130px; overflow-y: auto;
}
