:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --surface: var(--tg-theme-secondary-bg-color, #181b22);
  --text: var(--tg-theme-text-color, #f2f3f5);
  --hint: var(--tg-theme-hint-color, #8b90a0);
  --accent: var(--tg-theme-button-color, #4c8bf5);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #ff5a52;
  --ok: #34c759;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  --border: color-mix(in srgb, var(--text) 9%, transparent);
}

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

html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: 40px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 14px 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.header-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin: 0; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); animation: pulse 2.4s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- overview stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
  animation: itemIn .45s both;
}
.stat b { display: block; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.stat span { font-size: 10.5px; color: var(--hint); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- scrollable tab bar ---------- */
.tabbar {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: none; background: transparent;
  color: var(--hint); font-size: 14px; font-weight: 700;
  padding: 8px 14px; border-radius: 9px; white-space: nowrap;
  transition: color .25s ease, background .25s ease;
}
.tab.active {
  color: var(--accent-text);
  background: var(--accent);
  box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 45%, transparent);
}

/* ---------- main / views ---------- */
main { padding: 12px 16px; }
.view-enter { animation: viewEnter .34s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes viewEnter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes itemIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.view-title { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; margin: 2px 2px 4px; }
.view-sub { color: var(--hint); font-size: 13px; margin: 0 2px 8px; }
.section-title { font-size: 11.5px; text-transform: uppercase; color: var(--hint);
  letter-spacing: .07em; margin: 18px 4px 8px; font-weight: 700; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 9px;
  animation: itemIn .4s both;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(.975); background: color-mix(in srgb, var(--surface) 80%, var(--text) 6%); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--hint); font-size: 12.5px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--hint); font-size: 20px; opacity: .6; }

/* ---------- tags / pills ---------- */
.tag { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.tag.auto { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.tag.saved { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }

/* ---------- buttons ---------- */
.btn { border: none; border-radius: 11px; padding: 9px 14px; font-size: 13px; font-weight: 700;
  background: var(--accent); color: var(--accent-text); transition: transform .14s ease, opacity .2s ease; }
.btn:active { transform: scale(.93); opacity: .9; }
.btn.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.btn.block { width: 100%; padding: 13px; font-size: 15px; margin-top: 4px; }

/* ---------- inputs ---------- */
.input { width: 100%; padding: 12px 14px; border-radius: 12px; font-size: 15px; margin-bottom: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); transition: border-color .2s ease; }
.input:focus { outline: none; border-color: var(--accent); }
.input.flat { margin-bottom: 0; }

/* ---------- button rows / variants ---------- */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.btn-row .btn { flex: 1; min-width: 64px; }
.btn.ghost { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.btn.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.btn.sm { padding: 7px 11px; font-size: 12px; }

/* ---------- toggle pill ---------- */
.toggle { display: inline-flex; align-items: center; gap: 8px; border: none; cursor: pointer;
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 700;
  background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--hint);
  transition: background .2s ease, color .2s ease; }
.toggle.on { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.toggle .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; opacity: .9; }

/* ---------- key-value rows ---------- */
.kv { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: none; }
.kv span { color: var(--hint); }
.kv b { font-weight: 650; }

pre.bill { white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px; font-size: 13px; line-height: 1.55; margin: 0 0 10px; }

/* ---------- empty + skeleton ---------- */
.empty { text-align: center; color: var(--hint); padding: 40px 16px; animation: viewEnter .4s both; }
.empty .emoji { font-size: 34px; display: block; margin-bottom: 8px; opacity: .8; }

.skeleton { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  height: 58px; margin-bottom: 9px; position: relative; overflow: hidden; }
.skeleton::after { content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 8%, transparent), transparent);
  transform: translateX(-100%); animation: shimmer 1.3s infinite; }
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ---------- toast ---------- */
.toast { position: fixed; left: 16px; right: 16px; bottom: 18px; z-index: 50;
  background: var(--danger); color: #fff; padding: 13px 16px; border-radius: 13px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(20px); pointer-events: none;
  transition: opacity .28s ease, transform .28s cubic-bezier(.2,.9,.3,1.2); }
.toast.show { opacity: 1; transform: none; }
.toast.ok { background: var(--ok); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- ledger amounts ---------- */
.pos { color: #27d07a; } .neg { color: #ff6b6b; }

/* custom coin glyph — replaces the 🪙 emoji everywhere */
.coin { display: inline-block; width: 1em; height: 1em; vertical-align: -0.14em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='11' fill='%23e0992a'/%3E%3Ccircle cx='12' cy='12' r='9' fill='%23ffcf5c'/%3E%3Ccircle cx='12' cy='12' r='6.5' fill='none' stroke='%23e0992a' stroke-width='1.4'/%3E%3Cpath d='M12 7l1.2 2.6 2.8.3-2.1 1.9.6 2.8L12 13.9 9.5 15.5l.6-2.8-2.1-1.9 2.8-.3z' fill='%23e0992a'/%3E%3C/svg%3E") center/contain no-repeat; }

/* universal access gate (admin panel) */
html.gating body > :not(.gate) { visibility: hidden; }
.gate { position: fixed; inset: 0; z-index: 9999; background: #0b0d12;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; color: #f4f6fa; font-family: -apple-system, system-ui, sans-serif; }
.gate-orb { position: relative; width: 96px; height: 96px; }
.gate-orb span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid transparent;
  border-top-color: #ff7a18; animation: gate-spin 1.4s linear infinite; }
.gate-orb span:nth-child(2) { inset: 12px; border-top-color: #ffb020; animation-duration: 2s; animation-direction: reverse; }
.gate-orb span:nth-child(3) { inset: 26px; border-top-color: #27d07a; animation-duration: 2.6s; }
.gate-title { font-weight: 900; font-size: 20px; }
.gate-sub { color: #8b93a7; }
.gate-note { margin-top: 8px; font-size: 12px; color: #27d07a; font-weight: 800; }
@keyframes gate-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .gate-orb span { animation: none; } }
