:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #14181f;
  --hint: #6b7280;
  --border: rgba(20, 24, 31, 0.08);
  --mint: #1fce9c;
  --mint-2: #0ea5a0;
  --sunset-1: #ff7a45;
  --sunset-2: #ff3d68;
  --success: #16a866;
  --success-bg: #e3f8ee;
  --info: #2f7bf6;
  --info-bg: #e8f0fe;
  --warning: #d98a12;
  --warning-bg: #fdf1dd;
  --danger: #e0433d;
  --shadow: 0 1px 2px rgba(20,24,31,0.04), 0 4px 16px rgba(20,24,31,0.06);
  --tg-viewport-height: 100vh;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden; -webkit-font-smoothing: antialiased;
}

.icon { width: 20px; height: 20px; flex: 0 0 auto; display: inline-block; vertical-align: middle; }

#app { display: flex; flex-direction: column; height: var(--tg-viewport-height); overflow: hidden; }

/* ---------- Content ---------- */
main#views {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: max(16px, env(safe-area-inset-top, 0px)) 16px 24px;
  max-width: 480px; width: 100%; margin: 0 auto;
}
.view.hidden { display: none; }
.view:not(.hidden) { animation: viewIn 0.18s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.page-title { font-size: 25px; font-weight: 800; letter-spacing: -0.4px; margin: 2px 0 2px; }
.page-sub { font-size: 13px; color: var(--hint); font-weight: 500; margin: 0 0 18px; }

.section-title {
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--hint); margin: 22px 2px 10px;
}
.section-title-row { display: flex; align-items: center; justify-content: space-between; margin: 22px 2px 10px; }
.section-title-row .section-title { margin: 0; }
.txn-count { font-size: 12.5px; color: var(--hint); font-weight: 600; }

.footnote {
  display: flex; align-items: flex-start; gap: 7px;
  font-size: 12.5px; color: var(--hint); margin: 12px 2px 16px; line-height: 1.45;
}
.footnote-icon { width: 15px; height: 15px; flex: 0 0 auto; margin-top: 1px; color: var(--mint-2); }
.footnote b { color: var(--text); }

/* ---------- Grouped list ---------- */
.list-group { display: flex; flex-direction: column; gap: 10px; }

.field, .list-row, .stat-row, .tx-row2, .campaign-row, .detail-row {
  display: flex; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 14px 15px; position: relative; box-shadow: var(--shadow);
}

.field { flex-direction: column; align-items: stretch; gap: 7px; }
.field-label { font-size: 12px; color: var(--hint); font-weight: 700; }
.field-label-row { display: flex; align-items: center; justify-content: space-between; }
.field-hint { font-size: 11.5px; color: var(--hint); font-weight: 600; }

/* ---------- Grouped field card (iOS-settings style — one card, dividers between
   rows, instead of every field floating as its own separate shadowed box) ---------- */
.field-group {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); overflow: hidden;
}
.field-group .field {
  background: none; border: none; border-radius: 0; box-shadow: none;
  padding: 14px 15px; border-bottom: 1px solid var(--border);
}
.field-group .field.last { border-bottom: none; }
.field-group .row { display: flex; border-bottom: 1px solid var(--border); }
.field-group .row .field { flex: 1; border-bottom: none; }
.field-group .row .field:first-child { border-right: 1px solid var(--border); }

input, textarea, select {
  font: inherit; font-size: 15px; color: var(--text);
  background: transparent; border: none; padding: 0; outline: none; width: 100%;
}
select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>"); background-repeat: no-repeat; background-position: right 2px center; background-size: 18px; padding-right: 22px; }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--hint); opacity: 0.7; }

/* ---------- Budget presets ---------- */
.budget-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 4px; }
.preset-btn {
  font: inherit; font-weight: 700; font-size: 13px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 11px;
  padding: 10px 4px; cursor: pointer; transition: all 0.12s ease;
}
.preset-btn.active { background: var(--success-bg); color: var(--success); border-color: var(--success); }

/* ---------- Estimate callout ---------- */
.estimate-callout {
  display: flex; align-items: flex-start; gap: 9px;
  background: var(--warning-bg); color: #8a5a10; border-radius: 14px;
  padding: 13px 14px; font-size: 13px; line-height: 1.4; margin: 4px 0 6px;
}
.estimate-callout .icon { color: var(--warning); flex: 0 0 auto; margin-top: 1px; }
.estimate-callout b { font-weight: 800; }

/* ---------- Buttons ---------- */
.primary-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; font: inherit; font-weight: 700; font-size: 16px;
  color: #fff; background: linear-gradient(135deg, var(--mint), var(--mint-2));
  border: none; border-radius: 14px; padding: 15px; cursor: pointer;
  box-shadow: 0 8px 20px rgba(31, 206, 156, 0.32);
  transition: transform 0.1s ease, opacity 0.1s ease;
}
.primary-btn .icon { width: 17px; height: 17px; }
.primary-btn:active { transform: scale(0.98); opacity: 0.92; }
.primary-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; }

.list-row {
  width: 100%; border: 1px solid var(--border);
  font: inherit; text-align: left; cursor: pointer; gap: 4px; color: var(--text);
  transition: transform 0.1s ease;
}
.list-row .row-title { flex: 1; font-size: 15px; font-weight: 600; }
.list-row .row-value { font-size: 15px; color: var(--hint); font-variant-numeric: tabular-nums; font-weight: 700; }
.list-row .row-chevron { width: 16px; height: 16px; color: var(--hint); opacity: 0.6; margin-left: 2px; flex: 0 0 auto; }
.list-row:active { transform: scale(0.98); }
.list-row.action .row-title { color: var(--mint-2); }
.list-row.destructive .row-title { color: var(--danger); }
.list-row:disabled { opacity: 0.4; cursor: default; }
.list-row:disabled:active { transform: none; }

.back-row {
  display: flex; align-items: center; gap: 2px; background: none; border: none;
  color: var(--mint-2); font: inherit; font-weight: 700; font-size: 15px; padding: 4px 2px 12px; cursor: pointer;
}
.back-row .icon { width: 19px; height: 19px; }

/* ---------- Chip buttons ---------- */
.chip-btn {
  display: flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 700; font-size: 13.5px;
  border: none; border-radius: 999px; padding: 11px 18px; cursor: pointer;
}
.chip-btn .icon { width: 15px; height: 15px; }
.chip-dark { color: #fff; background: rgba(0,0,0,0.82); }
.chip-ghost { color: var(--text); background: rgba(255,255,255,0.55); border: 1px solid rgba(0,0,0,0.08); }
.chip-btn:active { opacity: 0.8; }

/* ---------- Icon badges (tx rows) ---------- */
.icon-badge {
  width: 36px; height: 36px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto; margin-right: 12px;
}
.icon-badge .icon { width: 17px; height: 17px; }
.icon-badge.in { background: var(--success-bg); color: var(--success); }
.icon-badge.out { background: #eef0f3; color: var(--text); }
.icon-badge.refund { background: var(--warning-bg); color: var(--warning); }

/* ---------- Campaign row ---------- */
.campaign-row {
  width: 100%; border: 1px solid var(--border); text-align: left; cursor: pointer;
  font: inherit; color: var(--text); gap: 13px; align-items: flex-start;
  transition: transform 0.1s ease;
}
.campaign-row:active { transform: scale(0.98); }
.campaign-thumb {
  width: 52px; height: 52px; border-radius: 12px; object-fit: cover; flex: 0 0 auto;
  background: var(--bg); border: 1px solid var(--border);
}
.campaign-thumb-fallback {
  width: 52px; height: 52px; border-radius: 12px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--mint), var(--mint-2));
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.campaign-thumb-fallback .icon { width: 22px; height: 22px; }
.campaign-row .row-body { flex: 1; min-width: 0; }
.campaign-row .row-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.campaign-row .row-name { font-size: 15px; font-weight: 700; }
.campaign-row .badges-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.campaign-row .meta-row { display: flex; align-items: center; justify-content: space-between; margin-top: 9px; font-size: 12.5px; }
.campaign-row .meta-row .spend { color: var(--hint); font-weight: 600; }
.campaign-row .meta-row .views { color: var(--hint); font-weight: 600; }
.campaign-row .row-chevron { align-self: flex-start; margin-top: 2px; }

.pill-status {
  font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 7px; text-transform: capitalize;
}
.pill-status.active { color: var(--success); background: var(--success-bg); }
.pill-status.paused { color: var(--warning); background: var(--warning-bg); }
.pill-status.pending_funds, .pill-status.pending_review { color: var(--info); background: var(--info-bg); }
.pill-status.rejected { color: var(--danger); background: #fbe6e5; }
.pill-status.completed { color: var(--mint-2); background: #e3f8f6; }

.pill-category {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; color: var(--hint);
  border: 1px solid var(--border); padding: 3px 9px 3px 7px; border-radius: 7px;
}
.pill-category .icon { width: 11px; height: 11px; }

.progress-track { height: 6px; border-radius: 999px; background: var(--bg); overflow: hidden; margin-top: 9px; }
.progress-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--mint), var(--mint-2)); }

/* ---------- Campaign detail hero ---------- */
.detail-card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 20px; margin-bottom: 8px; box-shadow: var(--shadow); }
.detail-card .detail-name { font-size: 18px; font-weight: 800; margin-bottom: 12px; }
.detail-card .progress-track { margin: 0 0 9px; }
.detail-card .progress-caption { font-size: 12.5px; color: var(--hint); font-weight: 500; }

.detail-row .row-title { color: var(--hint); font-size: 14px; font-weight: 500; }
.detail-row .row-value { color: var(--text); font-weight: 700; }

/* ---------- Ad preview card ---------- */
.ad-preview-card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 16px; margin-bottom: 6px; box-shadow: var(--shadow); }
.ad-preview-image { width: 100%; max-height: 180px; object-fit: cover; border-radius: 13px; margin-bottom: 12px; display: block; }
.ad-preview-text { font-size: 14.5px; line-height: 1.5; color: var(--text); margin: 0 0 14px; white-space: pre-wrap; }
.ad-preview-btn {
  display: block; width: 100%; font: inherit; font-weight: 700; font-size: 14.5px;
  color: #fff; background: linear-gradient(135deg, var(--mint), var(--mint-2));
  border: none; border-radius: 12px; padding: 12px; cursor: pointer;
}
.ad-preview-btn:active { transform: scale(0.98); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center; color: var(--hint); font-size: 13.5px; padding: 40px 20px;
  background: linear-gradient(180deg, var(--success-bg), var(--card) 65%);
  border: 1px solid var(--border); border-radius: 16px;
}
.empty-icon {
  width: 30px; height: 30px; margin-bottom: 12px; color: var(--mint-2);
  background: #fff; border-radius: 50%; padding: 9px; box-shadow: var(--shadow);
}

/* ---------- Tips card (contextual guidance in empty states) ---------- */
.tips-card {
  display: flex; align-items: flex-start; gap: 11px;
  background: var(--info-bg); border-radius: 16px; padding: 15px 16px; margin-top: 14px;
}
.tips-card .icon { width: 18px; height: 18px; color: var(--info); flex: 0 0 auto; margin-top: 1px; }
.tips-title { font-size: 13.5px; font-weight: 800; color: var(--text); margin-bottom: 3px; }
.tips-text { font-size: 12.5px; color: var(--hint); line-height: 1.45; }

/* ---------- Wallet hero (mint gradient) ---------- */
.balance-card {
  border-radius: 22px; padding: 24px; margin-bottom: 6px; position: relative; overflow: hidden;
}
.hero-mint {
  background: linear-gradient(135deg, var(--mint) 0%, var(--mint-2) 100%);
  color: #0a2e26;
}
.balance-label { font-size: 12.5px; font-weight: 700; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.4px; }
.balance-value { display: flex; align-items: center; gap: 6px; font-size: 38px; font-weight: 800; letter-spacing: -0.8px; margin: 6px 0 16px; font-variant-numeric: tabular-nums; }
.rupee-icon { width: 24px; height: 24px; }
.balance-actions { display: flex; gap: 10px; }

.list-row.topup-row .icon-badge { background: var(--warning-bg); color: var(--warning); }
.best-tag { font-size: 10.5px; font-weight: 800; color: var(--mint-2); margin-left: 6px; }

.tx-row2 { justify-content: space-between; }
.tx-row2 .row-body { min-width: 0; }
.tx-note { font-size: 14px; font-weight: 700; }
.tx-date { font-size: 11.5px; color: var(--hint); margin-top: 2px; font-weight: 500; }
.tx-amount { font-weight: 800; font-size: 14.5px; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.tx-amount.pos { color: var(--success); }
.tx-amount.neg { color: var(--text); }

/* ---------- Statistics ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 15px; box-shadow: var(--shadow); }
.stat-card-top { display: flex; align-items: flex-start; justify-content: space-between; }
.stat-card .icon-badge { margin: 0; width: 32px; height: 32px; border-radius: 10px; background: var(--success-bg); color: var(--success); }
.stat-card .stat-label { font-size: 11.5px; color: var(--hint); font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; margin-top: 10px; }
.stat-card .stat-value { font-size: 21px; font-weight: 800; margin-top: 2px; letter-spacing: -0.3px; font-variant-numeric: tabular-nums; }

.trend-chip { font-size: 11.5px; font-weight: 800; padding: 3px 7px; border-radius: 7px; white-space: nowrap; }
.trend-chip.up { color: var(--success); background: var(--success-bg); }
.trend-chip.down { color: var(--danger); background: #fbe6e5; }
.trend-chip.flat { color: var(--hint); background: var(--bg); }

.hero-card {
  border-radius: 20px; padding: 22px; margin-bottom: 10px; position: relative; overflow: hidden; color: #fff;
}
.hero-sunset { background: linear-gradient(135deg, var(--sunset-1) 0%, var(--sunset-2) 100%); }
.hero-label { font-size: 12.5px; font-weight: 700; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.4px; }
.hero-value { font-size: 34px; font-weight: 800; letter-spacing: -0.6px; margin: 4px 0 6px; }
.hero-sub { font-size: 13px; font-weight: 600; opacity: 0.92; }
.hero-icon { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; opacity: 0.35; }

.week-row { cursor: default; justify-content: space-between; }
.week-row:active { transform: none; }
.week-row .row-title { font-size: 13px; color: var(--hint); font-weight: 600; flex: none; }
.week-row .row-value { color: var(--text); font-size: 17px; font-weight: 800; margin-left: 8px; }
.week-row .row-body { display: flex; align-items: baseline; flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff;
  padding: 11px 18px; border-radius: 12px; font-size: 13px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50; max-width: 90%; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Skeleton ---------- */
.skeleton { position: relative; overflow: hidden; height: 60px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(20,24,31,0.06), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- Tab bar ---------- */
.tabbar {
  flex: 0 0 auto; display: flex; background: var(--card);
  border-top: 1px solid var(--border); padding: 8px 8px env(safe-area-inset-bottom, 0px);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px; margin: 0 3px; border-radius: 12px;
  background: none; border: none; color: var(--hint); cursor: pointer;
}
.tab span { font-size: 10px; font-weight: 700; }
.tab.active { color: var(--mint-2); }
.tab-fab .icon {
  width: 26px; height: 26px; padding: 5px; border-radius: 50%;
  background: linear-gradient(135deg, var(--mint), var(--mint-2)); color: #fff;
  margin-bottom: 1px;
}
.tab-fab.active .icon { box-shadow: 0 4px 12px rgba(31,206,156,0.4); }
.tab-fab.active span { color: var(--mint-2); }

.hidden { display: none !important; }

/* ---------- TON top-up sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20,24,31,0.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 480px; background: var(--bg);
  border-radius: 20px 20px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh; overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 36px; height: 4px; border-radius: 999px; background: var(--border); margin: 6px auto 14px; }
.sheet-title { font-size: 18px; font-weight: 800; margin: 0 0 4px; }
.sheet-sub { font-size: 13px; color: var(--hint); margin: 0 0 14px; }
.sheet-input {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--card); font-size: 15px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.sheet-close {
  display: block; width: 100%; text-align: center; background: none; border: none;
  color: var(--hint); font-weight: 700; font-size: 14px; padding: 12px 2px 2px; cursor: pointer;
}
.ton-connect-btn-root { display: flex; justify-content: center; margin: 18px 0 8px; min-height: 48px; }
.ton-wallet-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--success-bg); color: var(--success); border-radius: 12px;
  padding: 10px 14px; font-size: 13px; font-weight: 700; margin-bottom: 14px;
}
.ton-wallet-chip button {
  background: none; border: none; color: var(--danger); font-weight: 700; font-size: 12px; cursor: pointer;
}
.currency-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.currency-tab {
  padding: 10px 6px; border-radius: 12px; border: 1px solid var(--border); background: var(--card);
  font-weight: 700; font-size: 13px; color: var(--text); cursor: pointer;
}
.currency-tab.active { background: var(--success-bg); color: var(--success); border-color: var(--success); }

/* ---------- UPI top-up sheet ---------- */
.upi-qr-wrap {
  display: flex; justify-content: center; background: #fff; border-radius: 16px;
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.upi-qr-wrap img { width: 100%; max-width: 220px; height: auto; display: block; }
.upi-amount-big { text-align: center; font-size: 22px; font-weight: 800; margin-bottom: 14px; }
.copy-row {
  display: flex; align-items: center; gap: 10px; padding: 14px 15px; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.copy-row .copy-label { font-size: 12px; font-weight: 700; color: var(--hint); flex: 0 0 auto; }
.copy-row .copy-value { flex: 1; font-size: 14px; font-weight: 700; word-break: break-all; }
.copy-row .icon { width: 15px; height: 15px; color: var(--mint-2); flex: 0 0 auto; }

.ton-status {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 13px; color: var(--hint); font-weight: 600; margin-top: 14px; padding: 10px;
}
.ton-spinner {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border);
  border-top-color: var(--mint-2); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ton-success-icon { font-size: 44px; text-align: center; margin-bottom: 6px; }
#tonStepDone .sheet-title, #tonStepDone .sheet-sub { text-align: center; }
