:root {
  color-scheme: dark;
  --bg: #0b1224;
  --panel: #0f172a;
  --border: #1f2937;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --green: #22c55e;
  --red: #ef4444;
  --accent: #2563eb;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#app-root {
  height: var(--tg-vh, 100vh);
  display: flex;
  flex-direction: column;
}

.page {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.page-with-nav {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.app-header {
  flex: 0 0 auto;
  padding-top: calc(8px + var(--tg-safe-top, 0px));
  padding-top: calc(8px + var(--tg-safe-top, 0px) + env(safe-area-inset-top, 0px));
  padding-bottom: 8px;
}

.app-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.35);
  z-index: 2;
}

.topbar .title {
  font-size: 15px;
  letter-spacing: 0.02em;
}

.topbar .subtitle {
  font-size: 12px;
  color: var(--muted);
}

.price-block {
  text-align: right;
}

.topbar .price {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.content {
  flex: 1 1 auto;
  padding: 12px;
  min-height: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.chart-card {
  padding: 0;
  overflow: hidden;
}

.chart-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.tf-dropdown {
  position: relative;
}

.dropdown {
  position: absolute;
  top: 36px;
  left: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: none;
  min-width: 120px;
  z-index: 5;
}

.dropdown div {
  padding: 8px 10px;
  cursor: pointer;
}

.dropdown div:hover {
  background: #1a2235;
}

.dropdown.open {
  display: block;
}

.btn {
  background: #1b2742;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}

.ohlc {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 400px;
  min-height: 320px;
}

#auto-mode-toggle {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 3;
  padding: 3px 6px;
  font-size: 11px;
}

#auto-mode-toggle.auto-active {
  background: var(--accent);
  color: #fff;
}

main#chart-container {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: calc(var(--tg-vh, 100vh) - 56px);
}

#chart {
  position: absolute;
  inset: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(var(--tg-vh, 100vh) - 260px);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table-wrap th,
.table-wrap td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.table-wrap th {
  color: var(--muted);
  font-weight: 600;
}

.table-wrap tbody tr:hover {
  background: #10172a;
}

.label {
  font-size: 12px;
  color: var(--muted);
}

#timeframe-container {
  position: relative;
}

.tf-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
}

.tf-menu {
  position: absolute;
  top: 36px;
  left: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  padding: 6px 0;
  z-index: 5;
}

.tf-menu.hidden {
  display: none;
}

.tf-menu button {
  display: block;
  width: 100%;
  padding: 6px 12px;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.tf-menu button:hover {
  background: #1a2235;
}

.tf-chevron {
  font-size: 10px;
}

.subnet-chevron {
  font-size: 12px;
  opacity: 0.7;
  color: var(--text);
}

.overlay.hidden {
  display: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.overlay-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  width: min(420px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.overlay-results {
  overflow-y: auto;
  max-height: 60vh;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.overlay-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.overlay-row:last-child {
  border-bottom: none;
}

.overlay-row:hover {
  background: #10172a;
}

.subnet-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  margin-bottom: 10px;
}

.subnet-name {
  font-size: 1.2rem;
  font-weight: 600;
}

.subnet-code {
  font-size: 0.9rem;
  opacity: 0.7;
}

.subnet-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
}

.rows-filter {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0px;
  margin-bottom: 4px;
}

.rows-filter span {
  font-size: 0.85rem;
  color: var(--muted);
}

.rows-filter button {
  border-radius: 999px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text);
}

.rows-filter button.active {
  background: rgba(255, 255, 255, 0.08);
}

.rows-filter-container {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.pagination button {
  border-radius: 999px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  cursor: pointer;
  color: var(--text);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

.pagination span {
  font-size: 0.9rem;
  color: var(--muted);
}

.badge {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  display: none;
}

.badge.error {
  color: var(--red);
  border-color: var(--red);
}

.footer {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  bottom: 0;
  width: 100%;
}

.footer-btn {
  flex: 1;
  text-align: center;
  padding: 12px;
  color: var(--text);
  text-decoration: none;
  border-right: 1px solid var(--border);
  font-weight: 600;
}

.footer-btn:last-child {
  border-right: none;
}

.footer-btn.active {
  background: #1b2742;
  color: var(--accent);
}

.input {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f172a;
  color: var(--text);
  outline: none;
}

.label {
  display: block;
  margin-bottom: 6px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-row {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  cursor: pointer;
}

.list-row:hover {
  border-color: var(--accent);
}

.list-title {
  font-weight: 700;
}

.list-sub {
  color: var(--muted);
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.pos {
  color: var(--green);
}

.neg {
  color: var(--red);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  background: rgba(15, 23, 42, 0.96);
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  gap: 8px;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  letter-spacing: 0.01em;
}

.nav-icon-circle {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.nav-icon-circle svg {
  width: 22px;
  height: 22px;
}

.nav-item.active .nav-icon-circle {
  background: #fff;
  color: #0b1224;
  transform: translateY(-2px);
}

.nav-label {
  font-weight: 600;
}

.nav-item.active .nav-label {
  color: #fff;
}

.wallet-card .wallet-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.wallet-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wallet-address {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.wallet-balance {
  text-align: right;
}

.balance-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
}

.balance-sub {
  margin-top: 2px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.pnl-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pnl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.pnl-periods {
  display: flex;
  gap: 6px;
}

.pnl-periods button {
  border-radius: 999px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: #111a2c;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.pnl-periods button.active {
  background: #fff;
  color: #0b1224;
}

.pnl-value {
  font-size: 28px;
  font-weight: 800;
}

.pnl-sub {
  margin-top: -4px;
}

.trade-action-label {
  font-weight: 600;
  font-size: 1rem;
}

.trade-action-label--stake {
  color: var(--green);
}

.trade-action-label--unstake {
  color: var(--red);
}

.trade-subnet {
  text-align: right;
}

.trade-subnet-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.trade-subnet-id {
  font-size: 0.75rem;
  color: var(--muted);
}

.trades-card .card-header {
  align-items: center;
}

.trade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(var(--tg-vh, 100vh) - 340px);
  overflow-y: auto;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.trade-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.trade-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.trade-side {
  font-weight: 700;
  letter-spacing: 0.03em;
}

.trade-side.buy {
  color: var(--green);
}

.wallet-view-btn {
  border-radius: 999px;
  border: 1px solid #3b82f6;
  padding: 4px 12px;
  color: #3b82f6;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.wallet-view-btn:hover {
  background: rgba(59, 130, 246, 0.1);
}

.wallet-delete-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(239, 68, 68, 0.6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #ef4444;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.wallet-delete-btn:hover {
  background: rgba(239, 68, 68, 0.12);
}

.wallet-back-link {
  color: #3b82f6;
  font-weight: 600;
  text-decoration: none;
}

.wallet-back-link:hover {
  text-decoration: underline;
}

.trade-side.sell {
  color: var(--red);
}

.trade-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.trade-pnl {
  font-weight: 700;
}

.trade-hash {
  display: flex;
  align-items: center;
  gap: 6px;
}

.external-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--muted);
}

.external-link svg {
  width: 16px;
  height: 16px;
}

.empty-state {
  text-align: center;
  padding: 12px 0;
}

.tab-card {
  margin-bottom: 8px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.tabs button {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f172a;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.tabs button.active {
  background: #fff;
  color: #0b1224;
}

.positions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.position-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #0f172a;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
}

.position-name {
  font-weight: 700;
}

.position-sub {
  margin-top: 2px;
}

.position-metrics {
  text-align: right;
  min-width: 120px;
}

.position-middle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 120px;
}

.position-pnl {
  font-weight: 800;
}

.position-pct {
  font-size: 12px;
}

.wallet-add-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

@media (min-width: 540px) {
  .wallet-add-row {
    grid-template-columns: 2fr 1fr auto;
    align-items: center;
  }
}

.wallet-add-row.compact {
  grid-template-columns: 1fr;
  align-items: center;
  gap: 8px;
}

@media (min-width: 540px) {
  .wallet-add-row.compact {
    grid-template-columns: 2fr 1fr auto;
  }
}

.wallet-actions {
  display: flex;
  gap: 8px;
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
}

.file-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.bulk-container {
  margin-top: 10px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #0f172a;
}

.bulk-preview {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bulk-preview-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
}

.bulk-address {
  font-weight: 700;
}

.tracked-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tracked-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tracked-address {
  font-weight: 700;
}

.tracked-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.icon-btn.danger {
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--red);
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
  }

.tx-action-green { color: #32d74b; }
.tx-action-red { color: #ff453a; }
.tx-action-swap { color: #ffd60a; }
.tx-action-neutral { color: var(--muted); }

.activity-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #0f172a;
}

.activity-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.activity-wallet {
  font-weight: 700;
}

.activity-body {
  margin-top: 4px;
}

.fade-in {
  animation: fadeIn 0.25s ease;
}

.fade-out {
  animation: fadeOut 0.25s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; height: 0; margin: 0; padding: 0; }
}

.tx-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(var(--tg-vh, 100vh) - 200px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.tx-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tx-top, .tx-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tx-type {
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
