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

:root {
  --bg:       #000000;
  --bg2:      #111111;
  --bg3:      #1c1c1e;
  --bg4:      #2c2c2e;
  --text:     #ffffff;
  --text2:    rgba(235,235,245,0.6);
  --text3:    rgba(235,235,245,0.3);
  --green:    #30d158;
  --red:      #ff453a;
  --blue:     #0a84ff;
  --sep:      #38383a;
  --radius:   16px;
  --nav-h:    83px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, 'SF Pro Display', 'Segoe UI', sans-serif; overflow: hidden; }

#app { height: 100vh; overflow: hidden; padding-bottom: var(--nav-h); }

/* ─── Pages ─────────────────────────────────────────────────────────── */
.page { display: none; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page.active { display: block; }

/* ─── Bottom nav ─────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--sep);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; background: none; border: none; color: var(--text3); cursor: pointer;
  transition: color .2s; padding-top: 8px;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item span { font-size: 10px; }
.nav-item.active { color: var(--blue); }

/* ─── Nav header (sub-pages) ─────────────────────────────────────────── */
.nav-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.nav-title { font-size: 17px; font-weight: 600; }
.back-btn { background: none; border: none; color: var(--blue); cursor: pointer; padding: 4px; display: flex; }
.back-btn svg { width: 20px; height: 20px; }

/* ─── HOME ───────────────────────────────────────────────────────────── */
.home-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
}
.home-user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg4); display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600; color: var(--text2);
}
.user-name { font-size: 17px; font-weight: 600; }
.header-actions { display: flex; gap: 8px; }
.icon-btn { background: none; border: none; color: var(--text2); cursor: pointer; padding: 6px; display: flex; border-radius: 8px; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--bg3); }

.balance-section { padding: 24px 20px 20px; }
.balance-label { font-size: 14px; color: var(--text2); margin-bottom: 6px; }
.balance-amount { font-size: 48px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.balance-sub { font-size: 14px; color: var(--text2); margin-top: 6px; }

.quick-actions { display: flex; gap: 12px; padding: 0 16px 20px; }
.action-btn {
  flex: 1; height: 46px; border-radius: 14px; border: none;
  background: var(--bg3); color: var(--text); font-size: 15px; font-weight: 500;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.action-btn svg { width: 18px; height: 18px; }
.action-btn.primary { background: var(--bg4); }
.action-btn:active { opacity: 0.7; }

.section-header { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 10px; }
.section-title { font-size: 17px; font-weight: 600; }
.section-link { font-size: 15px; color: var(--blue); cursor: pointer; }

.stats-footer {
  text-align: center; color: var(--text3); font-size: 13px;
  padding: 16px 16px 8px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;
}
.dot { color: var(--text3); }

/* ─── Transactions ───────────────────────────────────────────────────── */
.tx-list { padding: 0 16px; }
.tx-list-full { padding-bottom: 20px; }
.tx-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--sep);
}
.tx-item:last-child { border-bottom: none; }

.tx-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--bg3); display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.tx-body { flex: 1; min-width: 0; }
.tx-desc { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.tx-amount { font-size: 15px; font-weight: 600; flex-shrink: 0; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--text); }
.tx-amount.trade { color: var(--blue); }

.empty { text-align: center; color: var(--text3); font-size: 15px; padding: 32px 16px; }
.loading { text-align: center; color: var(--text3); font-size: 15px; padding: 24px; }

/* ─── Filter row ─────────────────────────────────────────────────────── */
.filter-row { display: flex; gap: 8px; padding: 8px 16px 12px; }
.filter-row select {
  flex: 1; background: var(--bg3); border: none; color: var(--text);
  border-radius: 10px; padding: 8px 12px; font-size: 14px; appearance: none;
}

/* ─── Analytics ──────────────────────────────────────────────────────── */
.period-tabs {
  display: flex; gap: 8px; padding: 8px 16px 16px; overflow-x: auto;
}
.period-btn {
  padding: 7px 18px; border-radius: 20px; border: none; font-size: 14px;
  background: var(--bg3); color: var(--text2); cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.period-btn.active { background: var(--blue); color: #fff; }

.summary-cards { display: flex; gap: 10px; padding: 0 16px; margin-bottom: 10px; }
.sum-card {
  flex: 1; background: var(--bg3); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.net-card {
  background: var(--bg3); border-radius: var(--radius);
  padding: 16px; margin: 0 16px 16px;
}
.sum-label { font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.sum-value { font-size: 22px; font-weight: 700; }
.income-card .sum-value { color: var(--green); }
.expense-card .sum-value { color: var(--red); }

.chart-wrap { padding: 0 16px 16px; height: 200px; }

.category-list { padding: 0 16px; }
.category-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--sep);
}
.cat-emoji { font-size: 20px; width: 28px; flex-shrink: 0; }
.cat-name { font-size: 14px; flex: 1; }
.cat-bar-wrap { width: 80px; height: 4px; background: var(--bg4); border-radius: 2px; overflow: hidden; flex-shrink: 0; }
.cat-bar { height: 100%; background: var(--blue); border-radius: 2px; }
.cat-amount { font-size: 14px; font-weight: 500; min-width: 60px; text-align: right; flex-shrink: 0; }

.accounts-list { padding: 0 16px 20px; }
.account-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--bg3); border-radius: 12px; margin-bottom: 8px;
}
.acct-icon { font-size: 22px; margin-right: 12px; flex-shrink: 0; }
.acct-body { flex: 1; }
.acct-name { font-size: 15px; font-weight: 500; }
.acct-type { font-size: 12px; color: var(--text2); margin-top: 2px; }
.acct-balance { font-size: 16px; font-weight: 600; }

/* ─── Positions ──────────────────────────────────────────────────────── */
.positions-list { padding: 0 16px; }
.position-item {
  background: var(--bg3); border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  border-left: 3px solid var(--bg4);
}
.position-item.long { border-left-color: var(--green); }
.position-item.short { border-left-color: var(--red); }
.pos-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.pos-symbol { font-size: 16px; font-weight: 700; }
.pos-exchange { font-size: 12px; color: var(--text2); margin-top: 2px; }
.pos-pnl { font-size: 18px; font-weight: 700; }
.pos-pnl.positive { color: var(--green); }
.pos-pnl.negative { color: var(--red); }
.pos-details { display: flex; gap: 16px; flex-wrap: wrap; }
.pos-details > div { font-size: 12px; color: var(--text2); }
.pos-details > div span { color: var(--text); font-weight: 500; margin-left: 3px; }

/* ─── Wallets ────────────────────────────────────────────────────────── */
.wallets-list { padding: 0 16px 20px; }
.wallet-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--bg3); border-radius: 12px; margin-bottom: 8px;
}
.wallet-info { flex: 1; min-width: 0; }
.w-label { font-size: 15px; font-weight: 500; }
.w-chain { font-size: 12px; color: var(--blue); margin-top: 2px; }
.w-addr { font-size: 12px; color: var(--text3); margin-top: 2px; font-family: monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wallet-del { color: var(--red); font-size: 22px; padding: 4px 8px; cursor: pointer; flex-shrink: 0; }

/* ─── Settings ───────────────────────────────────────────────────────── */
.settings-section { padding: 16px 16px 0; }
.settings-group-title { font-size: 13px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }

.cred-service { background: var(--bg3); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.cred-service-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--sep);
}
.cred-service-name { font-size: 16px; font-weight: 600; }
.cred-dot { width: 8px; height: 8px; border-radius: 50%; }
.cred-dot.ok { background: var(--green); }
.cred-dot.missing { background: var(--red); }
.cred-field { display: flex; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--sep); gap: 10px; }
.cred-field:last-child { border-bottom: none; }
.cred-field-name { flex: 1; font-size: 14px; color: var(--text2); }
.cred-field-status { font-size: 12px; }
.cred-field-status.set { color: var(--green); }
.cred-field-status.unset { color: var(--red); }
.cred-set-btn {
  padding: 5px 14px; border-radius: 8px; border: none;
  background: var(--bg4); color: var(--blue); font-size: 13px; cursor: pointer;
}

.import-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--bg3); border-radius: 12px; margin-bottom: 8px;
}
.import-name { font-size: 15px; font-weight: 500; }
.import-hint { font-size: 12px; color: var(--text2); margin-top: 2px; }
.upload-btn {
  padding: 7px 16px; border-radius: 10px; background: var(--bg4);
  color: var(--blue); font-size: 14px; cursor: pointer;
}

/* ─── Sheets (bottom drawers) ────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 200; }
.sheet.hidden { display: none; }
.sheet-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.sheet-box {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--bg2); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
  max-height: 90vh; overflow-y: auto;
}
.sheet-handle { width: 36px; height: 4px; background: var(--bg4); border-radius: 2px; margin: 0 auto 16px; }
.sheet-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; }

.type-switcher { display: flex; background: var(--bg3); border-radius: 12px; padding: 3px; margin-bottom: 20px; }
.type-btn {
  flex: 1; padding: 8px; border: none; border-radius: 10px; font-size: 15px;
  background: none; color: var(--text2); cursor: pointer; font-weight: 500;
}
.type-btn.active { background: var(--bg4); color: var(--text); }

.amount-input-wrap {
  display: flex; align-items: center; background: var(--bg3); border-radius: 14px;
  padding: 12px 16px; margin-bottom: 12px;
}
.currency-prefix { font-size: 28px; font-weight: 300; color: var(--text2); margin-right: 6px; }
.amount-input-wrap input {
  flex: 1; background: none; border: none; color: var(--text); font-size: 28px;
  font-weight: 600; outline: none; width: 100%;
}

.text-input {
  display: block; width: 100%; background: var(--bg3); border: none; color: var(--text);
  border-radius: 14px; padding: 14px 16px; font-size: 16px; margin-bottom: 12px; outline: none;
}
.text-input::placeholder { color: var(--text3); }
.select-input {
  display: block; width: 100%; background: var(--bg3); border: none; color: var(--text);
  border-radius: 14px; padding: 14px 16px; font-size: 16px; margin-bottom: 12px; outline: none; appearance: none;
}

.category-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.cat-chip {
  padding: 8px 14px; border-radius: 20px; border: none;
  background: var(--bg3); color: var(--text2); font-size: 14px; cursor: pointer;
}
.cat-chip.active { background: var(--blue); color: #fff; }

.sheet-actions { display: flex; gap: 10px; padding-top: 4px; }
.btn-cancel {
  flex: 1; padding: 14px; border-radius: 14px; border: none;
  background: var(--bg3); color: var(--text2); font-size: 16px; cursor: pointer;
}
.btn-save {
  flex: 2; padding: 14px; border-radius: 14px; border: none;
  background: var(--blue); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}

.modal-hint { font-size: 12px; color: var(--text3); margin-bottom: 16px; text-align: center; }

/* ─── More menu ──────────────────────────────────────────────────────── */
.more-menu { display: flex; flex-direction: column; gap: 4px; padding-bottom: 8px; }
.more-item {
  display: flex; align-items: center; gap: 14px; padding: 16px 4px;
  background: none; border: none; border-bottom: 1px solid var(--sep);
  color: var(--text); font-size: 16px; cursor: pointer; text-align: left; width: 100%;
}
.more-item:last-child { border-bottom: none; }
.more-item svg { width: 22px; height: 22px; color: var(--blue); flex-shrink: 0; }

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg4); color: var(--text); padding: 10px 20px; border-radius: 20px;
  font-size: 14px; opacity: 0; transition: all .3s; pointer-events: none; white-space: nowrap; z-index: 300;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Sync spin ──────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.syncing svg { animation: spin 1s linear infinite; }

/* ─── Scrollbar ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { display: none; }
