/**
 * Compoundly — Telegram Wallet design system
 *
 * Colours come from Telegram's own theme params so the app inherits the user's actual
 * Telegram theme (light or dark) instead of imposing its own. Every var has a fallback
 * matching Telegram's stock dark palette for when the app runs outside Telegram.
 */

:root {
  color-scheme: light dark;

  --bg: var(--tg-theme-bg-color, #17212b);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #0e1621);
  --section-bg: var(--tg-theme-section-bg-color, #17212b);
  --header-bg: var(--tg-theme-header-bg-color, #17212b);

  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #708499);
  --subtitle: var(--tg-theme-subtitle-text-color, #708499);
  --section-header-text: var(--tg-theme-section-header-text-color, #6ab2f2);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --accent: var(--tg-theme-accent-text-color, #6ab3f3);
  --button: var(--tg-theme-button-color, #5288c1);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --destructive: var(--tg-theme-destructive-text-color, #ec3942);

  --green: #34c759;
  --green-dim: rgba(52, 199, 89, 0.14);
  --amber: #ff9f0a;
  --separator: color-mix(in srgb, var(--hint) 26%, transparent);
  --row-press: color-mix(in srgb, var(--hint) 12%, transparent);

  --radius-card: 12px;
  --radius-sheet: 16px;

  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: var(--font);
  background: var(--bg-secondary);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 17px;
  line-height: 1.29;
}

input, select, button, textarea { font-family: inherit; }

.app-container {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(24px + var(--safe-bottom));
  background: var(--bg-secondary);
}

.hidden { display: none !important; }

/* ============================================================ HEADER */

.tg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--header-bg);
}

.tg-wallet-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  min-width: 0;
}

.tg-wallet-pill:active { opacity: 0.6; }

.tg-wallet-status {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

#walletAddressDisplay {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-chain-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--link);
  font-size: 15px;
  font-weight: 400;
  padding: 6px 2px;
  cursor: pointer;
}

.tg-chain-badge:active { opacity: 0.5; }

/* ============================================================ BALANCE HERO */

.tg-hero {
  background: var(--section-bg);
  padding: 22px 16px 20px;
  text-align: center;
  margin-bottom: 22px;
}

.tg-balance-label {
  font-size: 14px;
  color: var(--hint);
  margin-bottom: 6px;
  letter-spacing: 0.1px;
}

.tg-balance-main {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -1.2px;
  line-height: 1.1;
  font-feature-settings: 'tnum';
}

.tg-balance-sub {
  font-size: 14px;
  color: var(--hint);
  margin-top: 5px;
  font-feature-settings: 'tnum';
}

.tg-balance-pnl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 9px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--green-dim);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  font-feature-settings: 'tnum';
}

/* Circular action row — Telegram Wallet's signature control cluster */
.tg-actions-row {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin-top: 22px;
}

.tg-action-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--link);
}

.tg-action-item:active .tg-action-circle { transform: scale(0.92); }
.tg-action-item:disabled { opacity: 0.4; cursor: default; }

.tg-action-circle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}

.tg-action-label {
  font-size: 13px;
  font-weight: 400;
  color: var(--link);
}

/* ============================================================ SECTIONS & LISTS */

.tg-section-container { margin-bottom: 22px; }

.tg-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px 7px;
}

.tg-section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--section-header-text);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.tg-section-action {
  background: none;
  border: none;
  color: var(--link);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 0;
}

.tg-section-action:active { opacity: 0.5; }

/* Grouped inset list: one rounded card, hairline separators inset past the icon */
.tg-list-group {
  background: var(--section-bg);
  border-radius: var(--radius-card);
  overflow: hidden;
  margin: 0 12px;
}

.tg-list-row,
.tg-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  position: relative;
  cursor: pointer;
  background: var(--section-bg);
}

.tg-list-row:active,
.tg-list-item:active { background: var(--row-press); }

.tg-list-row:not(:last-child)::after,
.tg-list-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 66px;
  right: 0;
  bottom: 0;
  height: 0.5px;
  background: var(--separator);
}

.tg-asset-left,
.tg-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.tg-asset-right,
.tg-item-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.brand-badge-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--button) 18%, transparent);
}

.tg-asset-title {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-asset-sub,
.tg-item-sub {
  font-size: 13px;
  color: var(--hint);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-row-chevron {
  color: var(--hint);
  opacity: 0.5;
  font-size: 17px;
  flex-shrink: 0;
}

.brand-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  border-radius: 50%;
  flex-shrink: 0;
}

/* APY figure — the number that matters most on this screen */
.apy-pill {
  font-size: 16px;
  font-weight: 600;
  color: var(--green);
  font-feature-settings: 'tnum';
  white-space: nowrap;
}

.tvl-note {
  font-size: 12px;
  color: var(--hint);
  margin-top: 2px;
  text-align: right;
  font-feature-settings: 'tnum';
}

.risk-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--hint);
  background: color-mix(in srgb, var(--hint) 16%, transparent);
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: middle;
}

.tg-empty-row {
  padding: 16px;
  text-align: center;
  color: var(--hint);
  font-size: 14px;
  background: var(--section-bg);
}

/* Filter chips */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 12px 10px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar { display: none; }

.cat-chip, .tx-cat-chip {
  background: var(--section-bg);
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 18px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.cat-chip.active, .tx-cat-chip.active {
  background: var(--button);
  color: var(--button-text);
}

/* Refresh control */
.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--link);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 0;
}

.refresh-btn:active { opacity: 0.5; }
.refresh-btn:disabled { opacity: 0.45; cursor: default; }

.refresh-btn svg { transition: transform 0.4s ease; }
.refresh-btn.spinning svg { animation: spin 0.9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================ ONBOARDING */

#onboardingView {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 88vh;
  padding: 24px 16px calc(24px + var(--safe-bottom));
  gap: 26px;
}

.onboarding-hero-graphic {
  width: 78px;
  height: 78px;
  border-radius: 22px;
  background: var(--button);
  color: var(--button-text);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

.onboarding-title {
  font-size: 27px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.6px;
  line-height: 1.2;
}

.onboarding-desc {
  font-size: 15px;
  color: var(--hint);
  text-align: center;
  margin-top: 9px;
  line-height: 1.4;
}

.onboarding-features {
  background: var(--section-bg);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.onboarding-feat-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
  position: relative;
}

.onboarding-feat-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 66px;
  right: 0;
  bottom: 0;
  height: 0.5px;
  background: var(--separator);
}

.onboarding-feat-title { font-size: 16px; font-weight: 500; }
.onboarding-feat-sub { font-size: 13px; color: var(--hint); margin-top: 2px; line-height: 1.35; }

/* ============================================================ BUTTONS & INPUTS */

.tg-main-btn {
  width: 100%;
  background: var(--button);
  color: var(--button-text);
  border: none;
  border-radius: 10px;
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.12s ease;
}

.tg-main-btn:active { opacity: 0.75; }
.tg-main-btn:disabled { opacity: 0.5; cursor: default; }

.tg-secondary-btn {
  width: 100%;
  background: transparent;
  color: var(--link);
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

.tg-secondary-btn:active { opacity: 0.55; }

.tg-input {
  width: 100%;
  background: var(--bg-secondary);
  border: none;
  border-radius: 10px;
  padding: 13px 14px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.tg-input:focus { box-shadow: 0 0 0 1.5px var(--button); }

select.tg-input {
  background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%);
  background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.input-label {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 6px;
  display: block;
}

.max-btn {
  background: color-mix(in srgb, var(--button) 20%, transparent);
  border: none;
  color: var(--link);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.max-btn:active { opacity: 0.6; }

/* ============================================================ MODALS (bottom sheets) */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal-sheet {
  width: 100%;
  max-width: 520px;
  background: var(--section-bg);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 10px 16px calc(20px + var(--safe-bottom));
  max-height: 92vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.open .modal-sheet { transform: translateY(0); }

.modal-sheet::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  border-radius: 3px;
  background: var(--hint);
  opacity: 0.35;
  margin: 0 auto 14px;
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-title {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.modal-close-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: color-mix(in srgb, var(--hint) 18%, transparent);
  color: var(--hint);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.modal-close-btn:active { opacity: 0.6; }

.modal-note {
  font-size: 14px;
  color: var(--hint);
  line-height: 1.4;
  margin-bottom: 12px;
}

/* Detail rows inside sheets */
.proof-card {
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 4px 12px;
  margin-bottom: 12px;
}

.proof-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  position: relative;
}

.proof-row:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0.5px;
  background: var(--separator);
}

.proof-label { font-size: 14px; color: var(--hint); }

/* Numbers must never wrap mid-value ("$0.1 1"); only .mono values (tx hashes) may break */
.proof-val {
  font-size: 14px;
  font-weight: 600;
  text-align: right;
  font-feature-settings: 'tnum';
  white-space: nowrap;
  flex-shrink: 0;
}

.proof-val.mono { white-space: normal; word-break: break-all; }
.proof-label { min-width: 0; }

.tg-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 12px;
  margin: 12px 0;
}

/* Safe / Max Yield switch */
.mode-switch {
  display: flex;
  gap: 4px;
  margin: 0 16px 8px;
  padding: 3px;
  background: var(--bg-secondary);
  border-radius: 11px;
}

.mode-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--hint);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.mode-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 600;
}

.mode-note {
  margin: 0 18px 10px;
  font-size: 12.5px;
  color: var(--hint);
  line-height: 1.4;
}

/* Inline risk note on a pool row — concrete, never a vague label */
.row-risk {
  font-size: 12px;
  color: var(--amber);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Rebalance prompt — only rendered when the move is provably profitable */
.rebalance-card {
  margin: 0 16px 18px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--bg-elevated);
  border: 1px solid color-mix(in srgb, var(--green) 35%, transparent);
}

.rebalance-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.rebalance-title { font-size: 16px; font-weight: 600; }

.rebalance-delta {
  font-size: 15px;
  font-weight: 700;
  color: var(--green);
  font-feature-settings: 'tnum';
}

.rebalance-body { font-size: 14px; color: var(--hint); line-height: 1.45; }
.rebalance-body b { color: var(--text); font-weight: 600; }

/* Pool detail sheet */
.detail-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--section-header-text);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 4px 2px 7px;
}

/* The summed net rate closes the breakdown — heavier, with a rule above it */
.proof-row.is-total {
  border-top: 0.5px solid var(--separator);
  margin-top: 2px;
  padding-top: 11px;
}

.proof-row.is-total .proof-label { color: var(--text); font-weight: 600; font-size: 15px; }
.proof-row.is-total .proof-val { font-size: 17px; color: var(--green); }

.alloc-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--button);
  opacity: 0.55;
  margin-top: 5px;
}

.pool-warning {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  background: color-mix(in srgb, var(--amber) 14%, transparent);
  border-radius: 10px;
  padding: 11px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}

.detail-loading {
  padding: 14px;
  text-align: center;
  color: var(--hint);
  font-size: 14px;
}

/* Numbered walkthrough in the guide sheet */
.guide-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 4px 0 18px;
}

.guide-steps li {
  display: flex;
  align-items: flex-start;
  gap: 13px;
}

.guide-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.guide-step-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 3px;
}

.guide-step-sub {
  font-size: 14px;
  color: var(--hint);
  line-height: 1.4;
}

/* ============================================================ TOAST */

.tg-toast {
  position: fixed;
  bottom: calc(26px + var(--safe-bottom));
  left: 50%;
  /* translateY alone is relative to the toast's own height, which was too short to clear
     the 26px offset — it left a bright sliver parked at the bottom of every screen.
     Visibility/opacity make "hidden" unambiguous regardless of the toast's size. */
  transform: translateX(-50%) translateY(160%);
  opacity: 0;
  visibility: hidden;
  background: color-mix(in srgb, var(--text) 88%, transparent);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 88vw;
  z-index: 2000;
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.2s ease, visibility 0.28s;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}

.tg-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}

/* ============================================================ RECEIPT */

.receipt-amount {
  font-size: 34px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.8px;
  font-feature-settings: 'tnum';
  margin: 6px 0 4px;
}

.receipt-check {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--green-dim);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin: 0 auto 12px;
}

.mono { font-family: var(--font-mono); font-size: 13px; word-break: break-all; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
