:root {
  --navy: #0f1a3c;
  --navy-2: #18265a;
  --navy-text: #aab3d6;
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e6e8f0;
  --text: #141a33;
  --muted: #6b7290;
  --accent: #6d4aff;
  --accent-soft: #efebff;
  --grad-1: #4c1d95;
  --grad-2: #7c3aed;
  --grad-3: #a855f7;
  --pos: #0f9d6b;
  --pos-soft: #e6f6ef;
  --neg: #e0445a;
  --neg-soft: #fdecee;
  --warn: #b7791f;
  --warn-soft: #fdf4e3;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 26, 51, .04), 0 4px 16px rgba(20, 26, 51, .05);
  --sidebar-w: 248px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
code { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: .92em; }
[hidden] { display: none !important; }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--navy);
  color: var(--navy-text);
  padding: 20px 14px;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 20px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-mark {
  position: relative; width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--grad-2), var(--grad-3));
  display: grid; place-items: center;
}
.brand-mark span { width: 14px; height: 14px; border: 3px solid #fff; border-radius: 50%; }
.brand-mark::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 5px; height: 5px; border-radius: 50%; background: #fff;
}
.sidebar .sidebar-close { display: none; color: #fff; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-label {
  margin: 16px 12px 6px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: #6c76a3;
}
.nav-label:first-child { margin-top: 0; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  font-weight: 500; transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--navy-2); color: #fff; box-shadow: inset 3px 0 0 var(--grad-3); }
.nav-link.active .icon { color: #c4b5fd; }

.network-card {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .05); font-size: 12px;
}
.network-card strong { display: block; color: #fff; font-size: 13px; }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: #34d399; box-shadow: 0 0 0 3px rgba(52, 211, 153, .2);
}

.overlay {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(15, 26, 60, .45); backdrop-filter: blur(2px);
}

.main {
  flex: 1; min-width: 0;
  margin-left: var(--sidebar-w);
  padding: 24px 32px 32px;
  display: flex; flex-direction: column; gap: 20px;
}

.topbar { display: flex; align-items: center; gap: 16px; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.topbar-title p { color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.menu-btn { display: none; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 13px;
}

.view { display: flex; flex-direction: column; gap: 20px; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.grid { display: grid; gap: 20px; }
.grid-top { grid-template-columns: minmax(300px, 380px) 1fr; }
.grid-mid { grid-template-columns: 1fr minmax(280px, 360px); }
.grid-form { grid-template-columns: minmax(0, 560px) minmax(240px, 360px); align-items: start; }

.footer { color: var(--muted); font-size: 12px; text-align: center; padding-top: 8px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.card-head h2 { font-size: 16px; font-weight: 600; }
.card-head-actions { display: flex; align-items: center; gap: 12px; }
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }

.balance-card {
  position: relative; overflow: hidden;
  color: #fff; border: 0;
  background: linear-gradient(135deg, var(--grad-1) 0%, var(--grad-2) 55%, var(--grad-3) 100%);
  box-shadow: 0 12px 32px rgba(109, 40, 217, .28);
  display: flex; flex-direction: column; gap: 6px;
}
.balance-card::before, .balance-card::after {
  content: ""; position: absolute; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .16); pointer-events: none;
}
.balance-card::before { width: 260px; height: 260px; right: -90px; top: -110px; }
.balance-card::after { width: 160px; height: 160px; right: -20px; top: -40px; background: rgba(255, 255, 255, .05); }
.balance-head { display: flex; align-items: center; justify-content: space-between; opacity: .85; font-weight: 500; }
.balance-amount { font-size: 36px; font-weight: 700; letter-spacing: -.03em; line-height: 1.15; margin-top: 4px; word-break: break-all; }
.balance-change { font-size: 13px; font-weight: 500; }
.balance-change .delta { padding: 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, .18); margin-right: 6px; }
.balance-party {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 14px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .12); font-size: 12px;
}
.balance-party span { opacity: .8; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: auto; padding-top: 14px; }
.quick-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px; border-radius: 12px;
  background: rgba(255, 255, 255, .14); font-weight: 600; font-size: 13px;
  transition: background .15s, transform .15s;
}
.quick-btn:hover { background: rgba(255, 255, 255, .24); transform: translateY(-1px); }

/* ---------- Controls ---------- */
.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: inline-grid; place-items: center;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); border-color: #d5d9e6; }
.icon-btn-light { width: 32px; height: 32px; border-color: rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .12); color: #fff; }
.icon-btn-light:hover { background: rgba(255, 255, 255, .22); border-color: rgba(255, 255, 255, .35); }
.sidebar .icon-btn { background: transparent; border-color: rgba(255, 255, 255, .15); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; transition: background .15s, box-shadow .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(109, 74, 255, .3); }
.btn-primary:hover { background: #5b3cf0; }
.btn-ghost { background: var(--surface); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--neg-soft); color: var(--neg); border-color: #f8c9d0; }
.btn-danger:hover { background: #fbdde1; }
.btn .icon { width: 16px; height: 16px; }

.link { color: var(--accent); font-weight: 600; font-size: 13px; background: none; border: 0; padding: 0; cursor: pointer; }
.link:hover { text-decoration: underline; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(20, 26, 51, .1); }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.chip-warn { background: var(--warn-soft); color: var(--warn); }

.search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; height: 38px; min-width: 240px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent); background: var(--surface); }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; color: var(--text); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Chart ---------- */
.chart-summary { margin-top: 2px; color: var(--muted); font-size: 13px; }
.chart-summary strong { color: var(--text); font-size: 20px; font-weight: 700; letter-spacing: -.02em; margin-right: 6px; }
.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: 240px; touch-action: pan-y; }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .hover-line { stroke: #c9c2f5; stroke-width: 1; }
.chart .hover-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 3; }
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%);
  padding: 6px 10px; border-radius: 8px; pointer-events: none;
  background: var(--navy); color: #fff; font-size: 12px; white-space: nowrap;
  box-shadow: 0 6px 16px rgba(15, 26, 60, .25);
}
.chart-tip span { display: block; color: var(--navy-text); font-size: 11px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 0 12px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table .num { text-align: right; }
.table .sub { display: block; color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px 0 !important; }

.asset-cell { display: flex; align-items: center; gap: 12px; }
.asset-icon {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 700; letter-spacing: -.02em;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25);
}
.asset-cell strong { display: block; font-weight: 600; }

.delta-badge {
  display: inline-block; padding: 3px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 600;
}
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.delta-badge.pos { background: var(--pos-soft); }
.delta-badge.neg { background: var(--neg-soft); }

.alloc-bar { display: inline-flex; align-items: center; gap: 8px; }
.alloc-bar i { display: block; width: 64px; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.alloc-bar b { display: block; height: 100%; border-radius: inherit; }

/* ---------- Allocation ---------- */
.allocation { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.donut { width: 180px; height: 180px; }
.donut .center-label { fill: var(--muted); font-size: 11px; font-weight: 500; }
.donut .center-value { fill: var(--text); font-size: 16px; font-weight: 700; }
.legend { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 10px; }
.legend li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .name { flex: 1; }
.legend .pct { font-weight: 600; }

/* ---------- Activity ---------- */
.activity { list-style: none; margin: 0; padding: 0; }
.activity-item { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: 0; padding-bottom: 0; }
.activity-item:first-child { padding-top: 0; }
.tx-icon {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
}
.tx-icon .icon { width: 17px; height: 17px; }
.tx-send { background: var(--neg-soft); color: var(--neg); }
.tx-receive { background: var(--pos-soft); color: var(--pos); }
.tx-swap { background: var(--accent-soft); color: var(--accent); }
.tx-main { flex: 1; min-width: 0; }
.tx-main strong { display: block; font-weight: 600; }
.tx-main span, .tx-amount span { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amount { text-align: right; }
.tx-amount strong { display: block; font-weight: 600; white-space: nowrap; }
.tx-type { display: flex; align-items: center; gap: 10px; font-weight: 600; text-transform: capitalize; }
.tx-type .tx-icon { width: 32px; height: 32px; border-radius: 10px; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; }
.field-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; }
.field input, .field select {
  width: 100%; height: 46px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); outline: 0;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.field input:focus, .field select:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input[aria-invalid="true"] { border-color: var(--neg); }
.hint { color: var(--muted); font-size: 12px; }
.form-error { color: var(--neg); font-size: 13px; font-weight: 500; min-height: 1em; }
.form-error:empty { display: none; }

.swap-box { display: flex; flex-direction: column; gap: 4px; position: relative; }
.swap-row { display: flex; gap: 8px; }
.swap-row input, .swap-out { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; }
.swap-row select { width: 130px; flex: none; }
.swap-out {
  display: flex; align-items: center; height: 46px; padding: 0 14px;
  border: 1px dashed var(--border); border-radius: 10px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis;
}
.swap-flip { align-self: center; margin: 4px 0 -4px; border-radius: 50%; }
.swap-rate { font-size: 13px; color: var(--muted); padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }

.note-card { background: var(--surface-2); box-shadow: none; }
.note-card p { color: var(--muted); }
.note-card ul { margin: 12px 0 0; padding-left: 18px; color: var(--muted); display: grid; gap: 4px; }
.price-list { list-style: none; padding: 0 !important; }
.price-list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.price-list li:last-child { border-bottom: 0; }
.price-list b { color: var(--text); font-weight: 600; }

.receive-card { display: flex; flex-direction: column; gap: 12px; }
.qr {
  width: 168px; height: 168px; align-self: center; padding: 12px;
  border: 1px solid var(--border); border-radius: 14px; background: #fff;
  display: grid; grid-template-columns: repeat(21, 1fr); gap: 0;
}
.qr i { background: var(--navy); }
.qr i.off { background: transparent; }
.receive-label { font-size: 13px; font-weight: 600; margin-top: 4px; }
.address-box {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.address-box code { flex: 1; min-width: 0; word-break: break-all; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.info-list { margin: 0; display: grid; }
.info-list div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.info-list div:last-child { border-bottom: 0; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; font-weight: 500; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.danger-card p { color: var(--muted); margin-bottom: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 12px;
  background: var(--navy); color: #fff; font-weight: 500;
  box-shadow: 0 12px 28px rgba(15, 26, 60, .3);
  animation: toast-in .2s ease;
}
.toast.error { background: var(--neg); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .grid-top, .grid-mid { grid-template-columns: 1fr; }
  .allocation { flex-direction: row; justify-content: center; gap: 32px; }
  .legend { max-width: 320px; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .sidebar.open { transform: none; }
  .sidebar .sidebar-close { display: inline-grid; }
  .menu-btn { display: inline-grid; }
  .main { margin-left: 0; padding: 16px 16px 24px; gap: 16px; }
  .view, .grid { gap: 16px; }
  .grid-form { grid-template-columns: 1fr; }
  .pill-network { display: none; }
  body.menu-open { overflow: hidden; }
}

@media (max-width: 600px) {
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .topbar-title h1 { font-size: 19px; }
  .topbar-title p { display: none; }
  .balance-amount { font-size: 30px; }
  .allocation { flex-direction: column; }
  .search { min-width: 0; width: 100%; }
  .hide-sm { display: none; }
  .chart { height: 200px; }
  .card-head .segmented { width: 100%; }
  .card-head .segmented button { flex: 1; }
  .activity-item { flex-wrap: wrap; }
  .activity-item .chip { display: none; }
  .swap-row select { width: 108px; }
}

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