/* Wallet mini app — design system.
   The user's Telegram theme owns the surfaces; one brand accent (TON blue) owns the money.
   The balance card is the single loud element: everything around it stays quiet.
   No vibration anywhere: motion and depth carry the feedback instead. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #0f0f0f);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --card: var(--tg-theme-secondary-bg-color, #f3f3f5);

  --accent: #0098ea;
  --accent-2: #0060b0;
  --on-accent: #ffffff;

  /* Hex, and it must stay hex: sparkline() builds its fill by concatenating an alpha
     pair onto this value (col + "22"). oklch()/rgb() would break it in silence. */
  --up: #1fb85f;
  --down: #e5484d;
  --warn: #f0b429;

  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --glass: color-mix(in srgb, var(--card) 78%, transparent);

  --r-xl: 24px;
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;

  --sh-card: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px -12px rgba(0, 0, 0, .18);
  --sh-glow: 0 18px 44px -14px color-mix(in srgb, var(--accent) 60%, transparent);
  --nav-h: 62px;
}

/* Forced themes. Without data-theme the app follows the Telegram client (the vars above);
   these override the surfaces only, never the accent. */
:root[data-theme="light"] {
  --bg: #ffffff;
  --text: #0f0f0f;
  --hint: #8a8a8e;
  --card: #f2f3f5;
}
:root[data-theme="dark"] {
  --bg: #17212b;
  --text: #f5f5f5;
  --hint: #7d8b99;
  --card: #232e3c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* A class with display:flex/grid beats the [hidden] attribute, and the element stays on
   screen while the code believes it is gone. Every hidden thing here means it. */
[hidden] { display: none !important; }
html { height: 100%; }
/* min-height, not height: with the global border-box, a fixed 100% height puts the
   padding-bottom *inside* a box exactly one screen tall, so it reserves nothing. Anything
   that overflows the screen then slides under the fixed nav — the last row of the history
   and the "Вся история" button were unreachable. min-height lets the box grow and the
   padding do its job. */
body {
  margin: 0; min-height: 100%;
  font: 16px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + 10px + env(safe-area-inset-bottom));
}

.view { display: none; padding: 12px 16px 8px; }
.view.active { display: block; animation: rise .2s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes spin { to { transform: rotate(360deg); } }
/* Rows arrive one after another instead of all at once — the eye follows the list down
   instead of being handed a wall of text. Capped at 8 steps in JS: past that the last rows
   are just waiting, and waiting is not motion design. */
@keyframes row-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.row-list .row {
  animation: row-in .34s cubic-bezier(.2, .7, .3, 1) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}
@media (prefers-reduced-motion: reduce) {
  .view.active, .sheet, .skel::after, .spinning, .row-list .row { animation: none; }
  .btn:active, .tile:active { transform: none; }
  .ptr { transition: none; }
}

h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--hint); margin: 0 0 10px; font-weight: 700;
}

/* icons ------------------------------------------------------------------- */
.ic {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.ic.sm { width: 18px; height: 18px; }
.ic.lg { width: 26px; height: 26px; }
.spinning { animation: spin .9s linear infinite; }

/* surfaces ---------------------------------------------------------------- */
.card {
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-card);
}
.pad { padding: 14px; }
.muted { color: var(--hint); }
.err { color: var(--down); }
.status {
  padding: 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-md); font-weight: 600;
}
.hintline { color: var(--hint); font-size: 12px; margin-top: 8px; line-height: 1.4; }
.hintline.err { color: var(--down); font-weight: 600; }

.empty { text-align: center; color: var(--hint); padding: 30px 12px; }
.empty .ic { width: 32px; height: 32px; margin-bottom: 8px; opacity: .7; }
.empty .t { font-weight: 600; color: var(--text); }
.empty .s { font-size: 13px; margin-top: 4px; }

/* skeletons: a moving highlight, not a blinking box ------------------------ */
.skel { position: relative; overflow: hidden; background: var(--card); border-radius: var(--r-md); }
.skel::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent,
    color-mix(in srgb, var(--text) 7%, transparent), transparent);
  animation: shimmer 1.4s infinite;
}
.skel-bal { height: 168px; border-radius: var(--r-xl); }
.skel-row { height: 66px; margin-bottom: 10px; }
.skel-coin { height: 154px; margin-bottom: 12px; }

/* profile header ---------------------------------------------------------- */
.phead {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; padding: 2px 2px 12px; color: var(--text);
  cursor: pointer; text-align: left; font: inherit;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none;
  background: var(--card); display: grid; place-items: center;
  font-size: 14px; font-weight: 800; color: var(--hint);
}
.avatar.big { width: 62px; height: 62px; font-size: 24px; }
.avatar.md { width: 40px; height: 40px; font-size: 16px; }
.phead .pname {
  flex: 1; min-width: 0; font-weight: 600; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.phead .ic { color: var(--hint); }

/* the balance card — the one loud thing on the screen ---------------------- */
.balance {
  position: relative; overflow: hidden;
  border-radius: var(--r-xl); padding: 20px 18px 18px;
  background: linear-gradient(155deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  box-shadow: var(--sh-glow), inset 0 1px 0 rgba(255, 255, 255, .22);
}
.balance::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 12% -10%, rgba(255, 255, 255, .28), transparent 62%);
}
.balance > * { position: relative; }
.bal-top { display: flex; align-items: center; justify-content: space-between; }
.bal-top .blabel { font-size: 13px; font-weight: 600; opacity: .88; }
.eye {
  border: 0; background: rgba(255, 255, 255, .16); color: var(--on-accent);
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  cursor: pointer; padding: 0;
}
.amount { margin-top: 8px; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 7px; }
.amount .amt { font-size: 42px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; }
.amount .cur { font-size: 16px; font-weight: 700; opacity: .85; }
.bal-sub {
  margin-top: 8px; display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-variant-numeric: tabular-nums;
}
/* Plain red on the blue card is unreadable, so the sign rides in a dimmed pill: the tint
   still says up or down, the pill keeps it legible. */
.bal-sub .delta {
  font-weight: 700; font-size: 13px; padding: 3px 9px; border-radius: 999px;
  background: rgba(0, 0, 0, .28);
}
.bal-sub .delta.neg { color: #ff6b60; }
.bal-sub .delta.pos { color: #4ade8b; }
.bal-sub .delta.flat { color: rgba(255, 255, 255, .8); font-weight: 600; }
.bal-held {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .18);
  display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
}

/* Centred card. The eye leaves the flex flow — inside it, it would drag the label off
   centre by half its own width — but it stays pinned to the label's own row, not to the
   corner of the card, so the two read as one line. */
.balance.center .bal-top { position: relative; justify-content: center; }
.balance.center .amount,
.balance.center .bal-sub,
.balance.center .bal-held { justify-content: center; }
.balance.center .eye { position: absolute; right: 0; top: 50%; transform: translateY(-50%); }
.net-badge {
  position: absolute; top: 14px; right: 14px; z-index: 1;
  font-size: 11px; font-weight: 800; letter-spacing: .04em;
  padding: 4px 9px; border-radius: 999px;
  background: var(--warn); color: #1a1a1a;
}

/* buttons ----------------------------------------------------------------- */
.tiles { display: flex; gap: 8px; margin: 14px 0 12px; }
.tile {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--glass); color: var(--text); font: inherit; font-size: 12px;
  font-weight: 600; cursor: pointer; box-shadow: var(--sh-card);
  transition: transform .08s ease;
}
.tile:active { transform: scale(.97); }
.tile .ic { color: var(--accent); }
.tile:disabled { opacity: .45; cursor: default; }
.tile:disabled .ic { color: var(--hint); }

.btn {
  width: 100%; border: 0; border-radius: var(--r-md); padding: 15px;
  font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  transition: transform .08s ease;
}
.btn:active { transform: scale(.98); }
.btn.sec { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.slim { width: auto; padding: 10px 14px; font-size: 14px; }
.link-btn {
  border: 0; background: none; color: var(--down); font: inherit; font-size: 13px;
  font-weight: 700; cursor: pointer; flex: none; padding: 6px;
}

/* segmented control ------------------------------------------------------- */
.seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
}
.seg button {
  flex: 1; border: 0; background: none; color: var(--hint); font: inherit;
  font-size: 13px; font-weight: 700; padding: 9px 6px; border-radius: 999px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.seg button[aria-selected="true"] { background: var(--accent); color: var(--on-accent); }

/* TON Connect row --------------------------------------------------------- */
.wconn {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--glass); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--sh-card);
}
.wconn .wic {
  width: 38px; height: 38px; border-radius: 50%; background: var(--bg);
  display: grid; place-items: center; color: var(--accent); flex: none;
}
.wconn .wmid { flex: 1; min-width: 0; }
.wconn .wlabel { font-size: 12px; color: var(--hint); }
.wconn .wsub { font-size: 13px; }
.wconn .waddr { font-weight: 700; font-size: 14px; font-family: ui-monospace, "SF Mono", monospace; }

/* rows: transactions, friends, cheques ------------------------------------ */
.row-list { display: flex; flex-direction: column; gap: 8px; }
.day { margin: 16px 0 8px; font-size: 12px; font-weight: 700; color: var(--hint); }
.day:first-child { margin-top: 4px; }

.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--sh-card); color: var(--text); font: inherit; text-align: left;
}
button.row { cursor: pointer; transition: transform .08s ease; }
button.row:active { transform: scale(.99); }
.row .ico {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
}
.row .ico.in { background: color-mix(in srgb, var(--up) 15%, transparent); color: var(--up); }
.row .ico.out { background: color-mix(in srgb, var(--down) 15%, transparent); color: var(--down); }
.row .ico.hold { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.row .mid { flex: 1; min-width: 0; }
.row .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .t2 {
  color: var(--hint); font-size: 12px; margin-top: 3px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
/* The comment is a quiet aside, not a card: one clipped line, tap to unfold. */
.row .note { margin-top: 4px; display: flex; align-items: baseline; gap: 6px; }
.row .note .txt {
  flex: 1; min-width: 0; font-size: 13px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row .note .more {
  flex: none; font-size: 12px; font-weight: 600; color: var(--accent); cursor: pointer;
}
/* Unfolded, the text gets the full width and the toggle drops below it — side by side it
   would squeeze the comment into a narrow column. */
.row .note.open { flex-direction: column; align-items: flex-start; gap: 2px; }
.row .note.open .txt { white-space: normal; overflow-wrap: anywhere; }
.row .amt2 { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.up { color: var(--up); }
.down { color: var(--down); }
/* An amount that was charged and then given back. Not red — nothing was lost. */
.row .amt2.void { color: var(--hint); text-decoration: line-through; font-weight: 700; }

.st { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.st.done, .st.claimed { background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up); }
.st.failed { background: color-mix(in srgb, var(--down) 18%, transparent); color: var(--down); }
.st.pending, .st.sent, .st.unattributed, .st.cancelled, .st.active {
  background: color-mix(in srgb, var(--hint) 22%, transparent); color: var(--hint);
}

/* send tab ---------------------------------------------------------------- */
.field {
  width: 100%; padding: 14px; border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 17px;
}
.field.amount-in {
  font-size: 30px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums;
  padding: 18px 14px;
}
.amount-box { position: relative; }
.amount-box .max {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 6px 11px; font: inherit; font-size: 12px;
  font-weight: 700; cursor: pointer;
}
.under {
  display: flex; justify-content: space-between; align-items: center;
  margin: 8px 2px 14px; font-size: 12px; color: var(--hint);
}
.picked {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 12px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--r-md);
}
.picked .mid { flex: 1; min-width: 0; }
.picked .name { font-weight: 700; }
.picked .uname { color: var(--hint); font-size: 13px; }

/* The row itself is not the button: the delete control lives inside it, so tapping the
   person and tapping the cross must be two different targets. */
.friend-pick {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  border: 0; background: none; padding: 0; color: inherit; font: inherit;
  text-align: left; cursor: pointer;
}
.friend-add {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px; margin-top: 10px;
  border: 1px dashed color-mix(in srgb, var(--text) 22%, transparent);
  border-radius: var(--r-md); background: none; color: var(--accent);
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}

.mono { font-family: ui-monospace, "SF Mono", monospace; font-size: 13px; word-break: break-all; }
.linkbox {
  display: flex; align-items: center; gap: 8px; padding: 12px;
  background: var(--card); border-radius: var(--r-md); margin: 12px 0;
}
.linkbox .mono { flex: 1; min-width: 0; }
.icon-btn {
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  cursor: pointer; flex: none; padding: 0;
}

/* rates ------------------------------------------------------------------- */
.rates-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.rates-head h2 { margin: 0; }
.updated { color: var(--hint); font-size: 12px; margin-bottom: 10px; }
.coin {
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-card); padding: 14px; margin-bottom: 12px;
}
.coin-top { display: flex; align-items: center; gap: 10px; }
.coin-ic { width: 34px; height: 34px; border-radius: 50%; background: var(--bg); flex: none; }
.coin-name { flex: 1; min-width: 0; }
.coin-name .sym { font-weight: 800; font-size: 16px; }
.coin-name .full { color: var(--hint); font-size: 13px; }
.coin-right { text-align: right; }
.coin-price { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.coin-24h { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.spark { width: 100%; height: 52px; display: block; margin: 12px 0 8px; }
.changes { display: flex; gap: 8px; }
.chg { flex: 1; background: var(--bg); border-radius: var(--r-sm); padding: 7px; text-align: center; }
.chg .lbl { color: var(--hint); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.chg .val { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* sheets ------------------------------------------------------------------ */
.sheet-bg {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.sheet-bg.open { display: flex; animation: rise .16s ease; }
.sheet {
  width: 100%; max-width: 360px; background: var(--bg); border-radius: var(--r-xl);
  padding: 18px; box-shadow: 0 24px 70px rgba(0, 0, 0, .35);
  animation: pop .2s cubic-bezier(.2, .8, .2, 1);
  max-height: 86vh; overflow-y: auto;
}
.sheet .btn { margin-top: 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { margin: 0; font-size: 19px; font-weight: 800; }
.sheet-close {
  border: 0; background: var(--card); color: var(--hint); width: 30px; height: 30px;
  border-radius: 50%; display: grid; place-items: center; cursor: pointer; flex: none; padding: 0;
}
.dest-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px;
}
.dest-box .dl { font-size: 12px; color: var(--hint); }
.dest-box .dv { font-weight: 700; font-family: ui-monospace, "SF Mono", monospace; font-size: 14px; }

/* the confirm card: who exactly is getting the money ----------------------- */
.confirm {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 4px; padding: 16px; margin-bottom: 14px;
  background: var(--card); border-radius: var(--r-lg);
}
.confirm .avatar { margin-bottom: 6px; }
.confirm .name { font-size: 17px; font-weight: 700; }
.confirm .uname { color: var(--accent); font-size: 14px; }
.confirm .id { color: var(--hint); font-size: 12px; font-variant-numeric: tabular-nums; }
.confirm .sum { margin-top: 10px; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }

.row2 { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; }
.row2 + .row2 { border-top: 1px solid var(--line); }
.row2 .k { color: var(--hint); }
.row2 .v { font-weight: 600; text-align: right; word-break: break-word; }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 13px;
  font-weight: 700; background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up);
}
.footer { margin-top: 18px; text-align: center; color: var(--hint); font-size: 14px; font-style: italic; }

/* pull to refresh --------------------------------------------------------- */
/* Parked above the top edge and pulled into view by the finger; JS owns --pull. */
.ptr {
  position: fixed; top: 0; left: 50%; z-index: 15;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--card); color: var(--accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .16);
  transform: translate(-50%, calc(var(--pull, 0px) - 44px)) rotate(var(--spin, 0deg));
  opacity: var(--pull-op, 0);
}
.ptr.smooth { transition: transform .25s ease, opacity .25s ease; }
.ptr.loading .ic { animation: spin .8s linear infinite; }

/* bottom nav -------------------------------------------------------------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); z-index: 20;
  display: flex; background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav button {
  flex: 1; border: 0; background: none; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--hint); font-size: 11px; font-weight: 600;
}
.nav button[aria-selected="true"] { color: var(--accent); }
