:root {
  --accent: #4f7cff;
  --accent-2: #7c5cff;
  --bg: #eef0f7;
  --glass: rgba(255,255,255,.55);
  --glass-strong: rgba(255,255,255,.72);
  --glass-border: rgba(255,255,255,.6);
  --surface-2: rgba(255,255,255,.4);
  --text: #14161c;
  --text-dim: #5b6072;
  --border: rgba(255,255,255,.5);
  --success: #1fa971;
  --danger: #e5484d;
  --warning: #c9862a;
  --radius: 20px;
  --radius-sm: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --blur: 22px;
  --shadow: 0 8px 32px rgba(31,41,80,.10), inset 0 1px 0 rgba(255,255,255,.6);
}

:root[data-theme="dark"] {
  --bg: #0a0b10;
  --glass: rgba(32,34,46,.55);
  --glass-strong: rgba(38,40,54,.68);
  --glass-border: rgba(255,255,255,.10);
  --surface-2: rgba(255,255,255,.06);
  --text: #f2f3f7;
  --text-dim: #9298a8;
  --border: rgba(255,255,255,.08);
  --shadow: 0 8px 32px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0b10;
    --glass: rgba(32,34,46,.55);
    --glass-strong: rgba(38,40,54,.68);
    --glass-border: rgba(255,255,255,.10);
    --surface-2: rgba(255,255,255,.06);
    --text: #f2f3f7;
    --text-dim: #9298a8;
    --border: rgba(255,255,255,.08);
    --shadow: 0 8px 32px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.06);
  }
}

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

html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Tahoma, "Segoe UI", Vazirmatn, sans-serif;
  overscroll-behavior-y: none;
}

body { direction: rtl; position: relative; }

/* Animated mesh-gradient blobs behind everything, so the glass panels
   have vivid color to blur/refract - this is what makes "liquid glass"
   read as glass instead of just semi-transparent grey. */
body::before {
  content: ""; position: fixed; inset: -20%; z-index: -1;
  background:
    radial-gradient(38% 32% at 12% 8%, rgba(124,92,255,.55), transparent 70%),
    radial-gradient(42% 36% at 92% 18%, rgba(79,124,255,.50), transparent 70%),
    radial-gradient(46% 40% at 20% 92%, rgba(255,120,180,.32), transparent 70%),
    radial-gradient(40% 34% at 88% 90%, rgba(56,220,190,.30), transparent 70%);
  filter: blur(60px) saturate(160%);
  animation: drift 22s ease-in-out infinite alternate;
}
:root[data-theme="dark"] body::before {
  background:
    radial-gradient(38% 32% at 12% 8%, rgba(124,92,255,.38), transparent 70%),
    radial-gradient(42% 36% at 92% 18%, rgba(79,124,255,.34), transparent 70%),
    radial-gradient(46% 40% at 20% 92%, rgba(255,90,160,.22), transparent 70%),
    radial-gradient(40% 34% at 88% 90%, rgba(40,200,170,.20), transparent 70%);
}
@keyframes drift {
  0%   { transform: translate3d(0,0,0) rotate(0deg); }
  50%  { transform: translate3d(-2%,2%,0) rotate(6deg); }
  100% { transform: translate3d(2%,-2%,0) rotate(-4deg); }
}
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } }

#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; position: sticky; top: 0; z-index: 5;
  background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
  border-bottom: 1px solid var(--glass-border);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; }
.balance-chip {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(90,90,230,.35), inset 0 1px 0 rgba(255,255,255,.4);
}

main#view {
  flex: 1; padding: 4px 16px calc(90px + var(--safe-bottom));
  max-width: 560px; margin: 0 auto; width: 100%;
}

.card {
  background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 12px 16px; }
.card-title { font-size: 14px; font-weight: 700; margin: 0 0 10px; color: var(--text); }
.card-sub { font-size: 12.5px; color: var(--text-dim); margin: 2px 0 0; }

.hero {
  background: linear-gradient(135deg, rgba(124,92,255,.9), rgba(79,124,255,.85));
  backdrop-filter: blur(var(--blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
  color: #fff; border-radius: 24px; padding: 22px 18px; margin-bottom: 16px;
  position: relative; overflow: hidden;
  border: 1px solid rgba(255,255,255,.35);
  box-shadow: 0 14px 40px rgba(90,80,220,.35), inset 0 1px 0 rgba(255,255,255,.5);
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 80% at 0% 0%, rgba(255,255,255,.35), transparent 55%);
}
.hero .label { font-size: 12.5px; opacity: .9; position: relative; }
.hero .amount { font-size: 30px; font-weight: 800; margin-top: 4px; letter-spacing: -0.5px; position: relative; }
.hero .row { display: flex; gap: 10px; margin-top: 14px; position: relative; }

.btn {
  border: none; border-radius: var(--radius-sm); padding: 12px 16px; font-size: 14.5px;
  font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; transition: transform .08s ease, opacity .15s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 6px 18px rgba(90,90,230,.35), inset 0 1px 0 rgba(255,255,255,.4);
}
.btn-accent {
  background: rgba(255,255,255,.9); color: var(--accent-2);
  backdrop-filter: blur(10px); box-shadow: 0 4px 14px rgba(0,0,0,.12), inset 0 1px 0 #fff;
}
.btn-ghost {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.btn-danger { background: linear-gradient(135deg, #ff6b6b, var(--danger)); color: #fff; box-shadow: 0 6px 16px rgba(229,72,77,.35); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 12.5px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--glass-border);
  font-size: 13px; cursor: pointer; color: var(--text); font-weight: 600;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff;
  box-shadow: 0 4px 14px rgba(90,90,230,.35), inset 0 1px 0 rgba(255,255,255,.4);
}

input[type=text], input[type=number], textarea {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--glass-border);
  background: var(--surface-2); color: var(--text); font-size: 14.5px; font-family: inherit;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
input[type=text]:focus, input[type=number]:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,124,255,.18);
}
textarea { resize: vertical; min-height: 90px; }
label.field-label { font-size: 12.5px; color: var(--text-dim); margin: 0 0 6px; display: block; font-weight: 600; }
.field { margin-bottom: 14px; }

.svc-card {
  border-radius: var(--radius); background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(160%); -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
  border: 1px solid var(--glass-border); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.svc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.svc-name { font-weight: 700; font-size: 14.5px; }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 700; backdrop-filter: blur(8px); }
.badge-trial { background: rgba(124,92,255,.18); color: #6a5cff; }
.badge-active { background: rgba(31,169,113,.18); color: var(--success); }
:root[data-theme="dark"] .badge-trial { background: rgba(124,92,255,.25); color: #b3a6ff; }
:root[data-theme="dark"] .badge-active { background: rgba(31,169,113,.22); color: #4ade95; }

.progress { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.svc-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-dim); margin-bottom: 10px; }
.svc-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tx-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.tx-row:last-child { border-bottom: none; }
.tx-amount.pos { color: var(--success); font-weight: 700; }
.tx-amount.neg { color: var(--danger); font-weight: 700; }
.tx-note { color: var(--text-dim); font-size: 11.5px; margin-top: 2px; }

.empty-state { text-align: center; padding: 40px 10px; color: var(--text-dim); font-size: 13.5px; }
.empty-state .emoji { font-size: 34px; margin-bottom: 10px; display: block; }

nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  background: var(--glass-strong);
  backdrop-filter: blur(var(--blur)) saturate(180%); -webkit-backdrop-filter: blur(var(--blur)) saturate(180%);
  border-top: 1px solid var(--glass-border);
  display: flex; padding: 6px 6px calc(6px + var(--safe-bottom));
  max-width: 560px; margin: 0 auto;
  box-shadow: 0 -8px 32px rgba(31,41,80,.10);
}
nav.tabbar .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0; border-radius: 12px; cursor: pointer; color: var(--text-dim);
  font-size: 11px; font-weight: 600; border: none; background: none;
  transition: color .15s ease, transform .1s ease;
}
nav.tabbar .tab.active { color: var(--accent); transform: translateY(-2px); }
nav.tabbar .tab .ic { font-size: 20px; line-height: 1; }

.sheet-bg {
  position: fixed; inset: 0; background: rgba(10,10,20,.35);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  z-index: 40; display: none; align-items: flex-end; justify-content: center;
}
.sheet-bg.open { display: flex; }
.sheet {
  background: var(--glass-strong);
  backdrop-filter: blur(30px) saturate(180%); -webkit-backdrop-filter: blur(30px) saturate(180%);
  width: 100%; max-width: 560px; border-radius: 26px 26px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bottom)); max-height: 86vh; overflow-y: auto;
  animation: sheetup .22s cubic-bezier(.2,.9,.3,1);
  border: 1px solid var(--glass-border); border-bottom: none;
  box-shadow: 0 -12px 48px rgba(31,41,80,.18);
}
@keyframes sheetup { from { transform: translateY(40px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }
.sheet-handle { width: 36px; height: 4px; background: var(--text-dim); opacity: .35; border-radius: 4px; margin: 0 auto 14px; }
.sheet h2 { font-size: 16px; margin: 0 0 14px; }

.toast {
  position: fixed; bottom: calc(96px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--glass-strong); color: var(--text);
  backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  padding: 10px 18px; border-radius: 14px; font-size: 13px;
  z-index: 60; display: none; max-width: 90%; text-align: center; box-shadow: var(--shadow);
}

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, rgba(255,255,255,.35) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: 10px; }
@keyframes sk { 0% { background-position: 100% 50% } 100% { background-position: 0 50% } }
.sk-row { height: 16px; margin-bottom: 8px; }

.copy-row {
  display: flex; gap: 8px; align-items: center; background: var(--surface-2);
  border: 1px solid var(--glass-border); border-radius: var(--radius-sm); padding: 10px 12px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.copy-row .val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; direction: ltr; text-align: left; color: var(--text-dim); }

.section-title { font-size: 13px; font-weight: 700; color: var(--text-dim); margin: 18px 4px 10px; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.status-open { background: var(--warning); }
.status-answered { background: var(--success); }
.status-closed { background: var(--text-dim); }

.gate-screen { padding: 40px 20px; text-align: center; }
.gate-screen .emoji { font-size: 44px; }
.gate-list { margin: 20px 0; display: flex; flex-direction: column; gap: 10px; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }
