:root {
  --bg:         #0d0d0d;
  --surface:    #181818;
  --border:     #2e2e2e;
  --text:       #f0f0f0;
  --muted:      #888888;
  --green:      #4caf72;
  --red:        #e05c5c;
  --accent:     #f7931a;   /* default; overridden per-chain via JS */
  --radius-sm:  8px;
  --radius:     12px;
  --radius-lg:  16px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Header ── */
.header {
  border-bottom: 1px solid var(--border);
  padding: 1.75rem 1rem;
  text-align: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-kiwi { font-size: 2rem; line-height: 1; }

.brand-name {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.brand-tagline {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 0.3rem;
}

.currency-switch {
  display: inline-flex;
  gap: 0;
  margin-top: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.currency-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.currency-btn + .currency-btn { border-left: 1px solid var(--border); }
.currency-btn:hover { color: var(--accent); }
.currency-btn.active {
  background: var(--accent);
  color: #000;
}

/* ── Main ── */
.main {
  flex: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1rem;
  width: 100%;
}

/* ── Search ── */
.search-box { margin-bottom: 2.5rem; }

.search-row {
  display: flex;
  gap: 0.5rem;
}

.input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  padding: 0.75rem 1rem;
  padding-right: 7rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--muted); }

.detected-chip {
  position: absolute;
  right: 0.6rem;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  background: rgba(255,255,255,0.08);
  color: var(--text);
}

.search-btn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #000;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.75rem 1.4rem;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.search-btn:hover  { opacity: 0.85; }
.search-btn:active { opacity: 0.70; }

/* ── Wallet rows (multi-input) ── */
.wallet-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.wallet-row .search-row { display: flex; gap: 0.5rem; }

.remove-wallet {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.7rem;
  transition: color 0.15s, border-color 0.15s;
}
.remove-wallet:hover { color: var(--red); border-color: var(--red); }
.remove-wallet[hidden] { display: none; }

.wallet-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
  justify-content: space-between;
}

.add-wallet-btn {
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  transition: color 0.15s, border-color 0.15s;
}
.add-wallet-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── Wallet result card (one per looked-up wallet) ── */
.wallet-card {
  background: rgba(255,255,255,0.015);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.wallet-card + .wallet-card { margin-top: 0; }
.wallet-card .balance-card { margin-bottom: 1rem; }
.wallet-card .tx-section { margin-bottom: 0.25rem; }
.wallet-card-error {
  color: var(--red);
  font-size: 0.85rem;
  padding: 0.75rem 0;
}

/* ── EVM network selector ── */
.evm-selector {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.evm-label {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.evm-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.evm-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.evm-tab:hover { border-color: #555; color: var(--text); }
.evm-tab.active {
  border-color: var(--tab-color, var(--accent));
  color: var(--tab-color, var(--accent));
  background: rgba(255,255,255,0.04);
}

.search-hint {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.65rem;
  line-height: 1.6;
}

.search-hint strong { color: var(--text); font-weight: 500; }

/* ── Loading ── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem;
  color: var(--muted);
}

.spinner {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

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

/* ── Error ── */
.error-box {
  background: rgba(224, 92, 92, 0.08);
  border: 1px solid rgba(224, 92, 92, 0.3);
  border-radius: var(--radius);
  color: var(--red);
  padding: 1rem 1.25rem;
}

/* ── Chain header ── */
.chain-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.chain-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  border: 1px solid currentColor;
}

.explorer-addr-link {
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
  transition: color 0.15s;
}

.explorer-addr-link:hover { color: var(--text); }

/* ── Address label ── */
.address-label {
  color: var(--muted);
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.76rem;
  word-break: break-all;
  margin-bottom: 1rem;
}

/* ── Balance card ── */
.balance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.balance-label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.balance-amount {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  word-break: break-all;
}

.balance-usd {
  color: var(--muted);
  font-size: 1.05rem;
  min-height: 1.5rem;
}

/* ── Stats ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value          { font-size: 0.9rem; font-weight: 600; }
.stat-value.green    { color: var(--green); }
.stat-value.red      { color: var(--red);   }

/* ── Transactions ── */
.tx-section { margin-bottom: 2rem; }

.tx-header {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}

.tx-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 0.45rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
  transition: border-color 0.15s;
}

.tx-item:hover { border-color: var(--accent); }

.tx-id {
  color: var(--accent);
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 0.8rem;
  text-decoration: none;
}

.tx-id:hover { text-decoration: underline; }

.tx-meta {
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 0.2rem;
}

.tx-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.4rem;
}

.tx-badge.confirmed   { background: rgba(76,175,114,0.15); color: var(--green); }
.tx-badge.unconfirmed { background: rgba(247,147,26,0.15);  color: #f7931a;      }
.tx-badge.success     { background: rgba(76,175,114,0.15); color: var(--green); }
.tx-badge.failed      { background: rgba(224,92,92,0.15);  color: var(--red);   }

.tx-right { text-align: right; }

.tx-amount            { font-size: 0.92rem; font-weight: 600; }
.tx-amount.positive   { color: var(--green); }
.tx-amount.negative   { color: var(--red);   }
.tx-amount.neutral    { color: var(--text);  }

.tx-usd {
  color: var(--muted);
  font-size: 0.74rem;
  margin-top: 0.15rem;
}

.tx-empty {
  color: var(--muted);
  text-align: center;
  padding: 2.5rem;
}

/* Explorer fallback button */
.explorer-btn {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 1rem 1.5rem;
  text-align: center;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
  margin-top: 0.5rem;
}

.explorer-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Portfolio summary ── */
.portfolio {
  background: rgba(255,255,255,0.015);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.portfolio-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
  gap: 1rem;
}

.portfolio-header {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.export-btns {
  display: flex;
  gap: 0.4rem;
}

.export-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  transition: color 0.15s, border-color 0.15s, opacity 0.15s;
}
.export-btn:hover    { color: var(--accent); border-color: var(--accent); }
.export-btn:active   { opacity: 0.7; }
.export-btn:disabled { cursor: wait; opacity: 0.6; }

.portfolio-total {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
  font-variant-numeric: tabular-nums;
}
.portfolio-total.muted {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 500;
}

.portfolio-body {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.portfolio-chart {
  flex-shrink: 0;
  width: 160px;
  height: 160px;
}

.portfolio-pie {
  width: 100%;
  height: 100%;
  display: block;
}

.portfolio-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.portfolio-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 0.7rem;
  align-items: center;
  font-size: 0.88rem;
}

.portfolio-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.portfolio-name { color: var(--text); font-weight: 500; }
.portfolio-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.portfolio-pct {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 3.5rem;
  text-align: right;
}

/* ── Footer ── */
.footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
  padding: 1.2rem 1rem;
  text-align: center;
  line-height: 2;
}

.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { color: var(--text); }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Mobile ── */
@media (max-width: 520px) {
  .search-row     { flex-direction: column; }
  .stats-row      { grid-template-columns: 1fr 1fr; }
  .stats-row .stat-card:last-child { grid-column: span 2; }
  .balance-amount { font-size: 1.8rem; }
  .evm-selector   { flex-direction: column; align-items: flex-start; }
  .portfolio-body { flex-direction: column; align-items: stretch; }
  .portfolio-chart { width: 140px; height: 140px; align-self: center; }
  .portfolio-total { font-size: 1.6rem; }
}
