:root {
  --bg: #232427;
  --card: #2c2d31;
  --card-2: #34353a;
  --text: #f2f3f5;
  --muted: #8b8d94;
  --muted-2: #6a6c73;
  --accent-lime: #c8f549;
  --accent-blue: #4aa8ff;
  --accent-purple: #7c6bff;
  --accent-green: #4fd67a;
  --accent-red: #ff6b6b;
  --accent-orange: #ffab40;
  --gray: #6a6c73;
  --radius: 22px;
  --radius-sm: 16px;
  --nav-h: 76px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { min-height: 100vh; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 20px calc(var(--nav-h) + 24px);
  position: relative;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 20;
}
.topbar-title {
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px;
  cursor: pointer;
  display: flex;
  border-radius: 12px;
  transition: color .15s, background .15s;
}
.icon-btn:active { color: var(--text); background: var(--card); }

/* ---------- Content ---------- */
.content { padding-top: 4px; animation: fade .28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.loader { display: flex; justify-content: center; padding: 80px 0; }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--card-2);
  border-top-color: var(--accent-lime);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Card (balance) ---------- */
.balance-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  margin-top: 6px;
}
.balance-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.card-brand {
  font-size: 26px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: 0.5px;
}
.card-type { color: var(--muted); font-size: 14px; margin-top: 6px; }
.balance-amount {
  text-align: right;
}
.balance-amount .cur { color: var(--muted); font-size: 22px; font-weight: 500; margin-right: 4px; vertical-align: top; }
.balance-amount .val { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; }
.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
}
.card-num { font-size: 18px; font-weight: 600; letter-spacing: 1px; }
.card-meta { display: flex; align-items: baseline; gap: 10px; }
.card-meta .lbl { color: var(--muted-2); font-size: 13px; text-transform: uppercase; }
.card-meta .v { font-size: 16px; font-weight: 600; }

/* ---------- Segment / pills ---------- */
.row-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  border: none;
  cursor: pointer;
}
.pill .dot { width: 9px; height: 9px; border-radius: 50%; }
.pill .chev { color: var(--muted); display: flex; }
.dot-red { background: var(--accent-red); }
.dot-lime { background: var(--accent-lime); }

.segment {
  display: inline-flex;
  background: var(--card);
  border-radius: 999px;
  padding: 4px;
}
.segment button {
  border: none;
  background: none;
  color: var(--muted);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  transition: all .18s;
}
.segment button.active { background: var(--text); color: #1c1d20; }

/* ---------- Charts block ---------- */
.section-month { font-size: 20px; font-weight: 700; margin: 24px 0 4px; }
.charts {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.ring-wrap { flex: 1; display: flex; justify-content: center; position: relative; }
.ring-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 30px;
  font-weight: 700;
  color: var(--accent-blue);
}
.pie-wrap { flex: 1; display: flex; justify-content: center; }

/* ---------- Legend ---------- */
.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 8px;
  margin-top: 22px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
}
.legend-item .ldot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend-item .lname { color: var(--muted); }
.legend-item .lval { color: var(--text); font-weight: 600; margin-left: auto; }
.legend-col { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Income line block ---------- */
.income-block { margin-top: 26px; }
.income-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.income-tag {
  background: var(--accent-lime);
  color: #1c1d20;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
}
.income-month { color: var(--muted); font-size: 15px; }
.line-chart { margin-top: 16px; width: 100%; }
.months {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  color: var(--muted-2);
  font-size: 12px;
}
.months span.active { color: var(--accent-lime); font-weight: 600; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 24px calc(env(safe-area-inset-bottom, 0px));
  z-index: 30;
}
.nav-btn {
  background: none;
  border: none;
  color: var(--muted-2);
  padding: 10px;
  cursor: pointer;
  display: flex;
  transition: color .15s, transform .12s;
}
.nav-btn.active { color: var(--text); }
.nav-btn:active { transform: scale(0.9); }

/* ---------- Tasks list ---------- */
.list-head { margin: 8px 0 16px; }
.list-head h2 { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.list-head p { color: var(--muted); font-size: 14px; margin: 0; }

.task-card {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: transform .12s, background .15s;
}
.task-card:active { transform: scale(0.985); background: var(--card-2); }
.task-card .tc-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.task-card .tc-icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.task-card .tc-title { font-size: 16px; font-weight: 600; flex: 1; }
.task-card .tc-reward {
  background: var(--accent-lime);
  color: #1c1d20;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.task-card .tc-desc {
  color: var(--muted);
  font-size: 14px;
  margin-top: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}
.empty svg { color: var(--muted-2); margin-bottom: 14px; }
.empty p { font-size: 15px; margin: 0; }

/* ---------- Profile ---------- */
.profile-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0 4px;
}
.avatar {
  width: 78px; height: 78px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-lime), var(--accent-green));
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700; color: #1c1d20;
}
.profile-name { font-size: 20px; font-weight: 700; margin-top: 12px; }
.profile-uname { color: var(--muted); font-size: 14px; margin-top: 2px; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 22px;
}
.stat-box {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 18px;
}
.stat-box .sv { font-size: 24px; font-weight: 700; }
.stat-box .sl { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat-box.wide { grid-column: 1 / -1; }

.progress-wrap { margin-top: 18px; }
.progress-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.progress-bar { height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent-lime), var(--accent-green)); border-radius: 999px; transition: width .6s ease; }

.btn {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
  transition: transform .12s, opacity .15s;
}
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--accent-lime); color: #1c1d20; }
.btn-secondary { background: var(--card); color: var(--text); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Referral ---------- */
.ref-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  margin-top: 8px;
}
.ref-big { font-size: 44px; font-weight: 800; color: var(--accent-lime); }
.ref-sub { color: var(--muted); font-size: 15px; margin-top: 4px; }
.ref-link {
  background: var(--card-2);
  border-radius: 12px;
  padding: 14px;
  font-size: 13px;
  color: var(--text);
  margin-top: 20px;
  word-break: break-all;
  font-family: ui-monospace, monospace;
}
.info-note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin-top: 18px;
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 16px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 20px);
  transform: translate(-50%, 20px);
  background: var(--card-2);
  color: var(--text);
  padding: 13px 20px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  z-index: 100;
  max-width: 90%;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Bottom sheet ---------- */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
  z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-overlay.show { opacity: 1; pointer-events: auto; }
.sheet {
  width: 100%; max-width: 480px;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.sheet-overlay.show .sheet { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; background: var(--card-2); border-radius: 999px; margin: 0 auto 18px; }
.sheet h3 { margin: 0 0 6px; font-size: 20px; font-weight: 700; }
.sheet .sheet-sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; line-height: 1.45; }
.sheet textarea, .sheet input {
  width: 100%;
  background: var(--card-2);
  border: none;
  border-radius: 12px;
  padding: 14px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
}
.sheet textarea:focus, .sheet input:focus { box-shadow: 0 0 0 2px var(--accent-lime); }
.sheet-reward {
  display: inline-flex;
  background: var(--accent-lime);
  color: #1c1d20;
  font-weight: 700;
  font-size: 15px;
  padding: 8px 14px;
  border-radius: 999px;
  margin-bottom: 16px;
}

/* ===== Админ-панель ===== */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.astat {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px 6px;
  text-align: center;
}
.astat .av { font-size: 20px; font-weight: 700; color: var(--text); }
.astat .al { font-size: 11px; color: var(--muted); margin-top: 2px; }

.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.admin-tabs button {
  flex: 1;
  white-space: nowrap;
  background: var(--card);
  color: var(--muted);
  border: none;
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.admin-tabs button.active {
  background: var(--accent-lime);
  color: #1c1d20;
}

.admin-item {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 12px;
}
.ai-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ai-title { font-size: 15px; font-weight: 600; color: var(--text); flex: 1; }
.ai-reward {
  background: var(--accent-lime);
  color: #1c1d20;
  font-weight: 700;
  font-size: 13px;
  border-radius: 999px;
  padding: 4px 10px;
}
.ai-desc { font-size: 13px; color: var(--muted); margin-top: 8px; word-break: break-word; }
.ai-meta { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.ai-badge {
  background: var(--card-2);
  color: var(--text);
  font-size: 12px;
  border-radius: 999px;
  padding: 3px 10px;
}
.a-btn {
  background: var(--card-2);
  color: var(--text);
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.a-btn.a-ok { background: var(--accent-green); color: #1c1d20; }
.a-btn.a-danger { background: var(--accent-red); color: #fff; }

.sheet select {
  width: 100%;
  background: var(--card-2);
  color: var(--text);
  border: none;
  border-radius: 14px;
  padding: 14px;
  font-size: 15px;
  margin-top: 10px;
  -webkit-appearance: none;
  appearance: none;
}
.nav-btn.nav-admin.active { color: var(--accent-lime); }
