:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e4e6eb;
  --text: #121418;
  --muted: #6b7180;
  --accent: #1fbf6f;
  --accent-ink: #0b7a43;
  --accent-soft: #e3f8ec;
  --up: #12a35a;
  --down: #e0413a;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5600;
  --agent: #6d4aff;
  --agent-soft: #efeaff;
  --shadow: 0 1px 2px rgba(16, 20, 28, .06), 0 4px 16px rgba(16, 20, 28, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #16191e;
    --surface-2: #1e2229;
    --border: #2a2f37;
    --text: #eef0f3;
    --muted: #949bab;
    --accent: #2bdc82;
    --accent-ink: #2bdc82;
    --accent-soft: #123222;
    --up: #2bdc82;
    --down: #ff6b63;
    --warn-bg: #3a2f10;
    --warn-ink: #ffd36b;
    --agent: #a28bff;
    --agent-soft: #241d45;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.num { font-variant-numeric: tabular-nums; }

/* demo banner */
.demo-banner {
  position: sticky; top: 0; z-index: 30;
  background: var(--warn-bg); color: var(--warn-ink);
  font-size: 13px; text-align: center; padding: 6px 16px; height: 31px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: calc(100vh - 31px); }
.sidebar {
  position: sticky; top: 31px; height: calc(100vh - 31px);
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 750; font-size: 19px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent);
  display: grid; place-items: center; color: #06120b; font-size: 15px; font-weight: 800;
}
.brand small { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 550;
}
.nav a svg { width: 20px; height: 20px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.sidebar .spacer { flex: 1; }
.sidebar .reset { background: none; border: 1px solid var(--border); border-radius: 10px; padding: 8px; color: var(--muted); font-size: 13px; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 16px 28px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.topbar .search { flex: 1; max-width: 420px; position: relative; }
.topbar .search input {
  width: 100%; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: 9px 14px 9px 38px; outline: none;
}
.topbar .search svg { position: absolute; left: 13px; top: 50%; translate: 0 -50%; width: 17px; color: var(--muted); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; display: none;
}
.search-results.open { display: block; }
.topbar .grow { flex: 1; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-weight: 650; font-size: 13px;
}
.content { padding: 28px; max-width: 1180px; margin: 0 auto; display: grid; gap: 20px; }

/* buttons */
.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 650;
  background: var(--surface-2); color: var(--text); display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--accent); color: #06120b; }
.btn-danger { background: var(--down); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 50%; width: 38px; height: 38px; display: grid; place-items: center; }
.icon-btn svg { width: 18px; }
.icon-btn.on { color: #e8a400; border-color: #e8a400; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.stack { display: grid; gap: 20px; align-content: start; }

.hero-value { font-size: 36px; font-weight: 750; letter-spacing: -.02em; }
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: 13px; font-weight: 600; background: var(--surface-2); }
.pill.up { background: color-mix(in srgb, var(--up) 14%, transparent); }
.pill.down { background: color-mix(in srgb, var(--down) 14%, transparent); }

.tabs { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }

.chart { width: 100%; height: 220px; display: block; }
.chart-sm { width: 84px; height: 30px; display: block; }
.watchlist { container-type: inline-size; }
@container (max-width: 520px) { .wl-spark { display: none; } }

/* lists */
.rows { display: grid; }
.row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px;
  padding: 11px 8px; border-radius: 10px;
}
a.row:hover, button.row:hover { background: var(--surface-2); }
button.row { border: 0; background: none; text-align: left; width: 100%; }
.asset-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.asset-cell > div { min-width: 0; }
.asset-cell .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-cell .sub { color: var(--muted); font-size: 13px; }
.logo {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 750; font-size: 12px; letter-spacing: -.02em;
}
.logo.lg { width: 52px; height: 52px; font-size: 15px; }
.right { text-align: right; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); }
table.list td { padding: 12px 8px; border-bottom: 1px solid var(--border); }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--surface-2); }
table.list .r { text-align: right; }
.table-wrap { overflow-x: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-weight: 650; font-size: 16px; }

.alloc-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; gap: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* forms */
.field { display: grid; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 550; }
.input, select.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 10px 12px; outline: none;
}
.input:focus { border-color: var(--accent); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.form-row > .field { flex: 1; min-width: 140px; }
form:tool-form-active { outline: 2px solid var(--agent); outline-offset: 6px; border-radius: 12px; }
form.agent-active { outline: 2px solid var(--agent); outline-offset: 6px; border-radius: 12px; }

.empty { color: var(--muted); padding: 20px 8px; text-align: center; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(8, 10, 14, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 420px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); display: grid; gap: 16px; }
.modal .side-toggle { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.modal .side-toggle button { border: 0; background: none; border-radius: 999px; padding: 8px; font-weight: 650; color: var(--muted); }
.modal .side-toggle button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.amount-input { font-size: 34px; font-weight: 750; border: 0; background: none; width: 100%; text-align: center; outline: none; }
.quote { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; font-size: 14px; }
.quote div { display: flex; justify-content: space-between; }
.agent-note { background: var(--agent-soft); color: var(--agent); border-radius: 10px; padding: 9px 12px; font-size: 13px; font-weight: 550; }

/* toasts */
.toasts { position: fixed; left: 50%; translate: -50% 0; bottom: 24px; z-index: 60; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.agent { background: var(--agent); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* WebMCP inspector */
.mcp-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 40; border: 0; border-radius: 999px;
  background: var(--agent); color: #fff; padding: 11px 16px; font-weight: 700; box-shadow: 0 6px 20px rgba(109, 74, 255, .35);
  display: flex; align-items: center; gap: 8px;
}
.mcp-fab .count { background: rgba(255, 255, 255, .25); border-radius: 999px; padding: 0 7px; font-size: 12px; }
.mcp-fab.pulse { animation: pulse .6s ease-out; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.mcp-panel {
  position: fixed; top: 31px; right: 0; bottom: 0; width: min(460px, 100vw); z-index: 45;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: -10px 0 40px rgba(0, 0, 0, .12);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform .2s ease;
}
.mcp-panel.open { transform: none; }
.mcp-panel header { padding: 16px 18px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.mcp-panel header .top { display: flex; justify-content: space-between; align-items: center; }
.mcp-status { font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.mcp-status span { border-radius: 6px; padding: 2px 8px; background: var(--surface-2); font-weight: 600; }
.mcp-status .ok { background: var(--accent-soft); color: var(--accent-ink); }
.mcp-status .shim { background: var(--warn-bg); color: var(--warn-ink); }
.mcp-body { overflow-y: auto; flex: 1; padding: 12px 18px 24px; display: grid; gap: 14px; align-content: start; }
.mcp-tool { border: 1px solid var(--border); border-radius: 12px; }
.mcp-tool summary { list-style: none; cursor: pointer; padding: 10px 12px; display: grid; gap: 3px; }
.mcp-tool summary::-webkit-details-marker { display: none; }
.mcp-tool summary code { font-weight: 700; font-size: 13px; }
.mcp-tool summary .d { font-size: 12.5px; color: var(--muted); }
.mcp-tool .tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; border-radius: 5px; padding: 1px 6px; background: var(--surface-2); color: var(--muted); }
.tag.ro { background: var(--accent-soft); color: var(--accent-ink); }
.tag.cons { background: color-mix(in srgb, var(--down) 15%, transparent); color: var(--down); }
.tag.decl { background: var(--agent-soft); color: var(--agent); }
.tag.dyn { background: var(--warn-bg); color: var(--warn-ink); }
.mcp-tool .inner { padding: 0 12px 12px; display: grid; gap: 8px; }
.mcp-tool textarea { width: 100%; min-height: 70px; font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: var(--surface-2); resize: vertical; }
pre.json { margin: 0; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; overflow-x: auto; max-height: 260px; white-space: pre-wrap; word-break: break-word; }
.mcp-log { display: grid; gap: 6px; }
.mcp-log .entry { font-size: 12.5px; border-left: 3px solid var(--agent); padding: 4px 10px; background: var(--surface-2); border-radius: 0 8px 8px 0; }
.mcp-log .entry.err { border-color: var(--down); }
.mcp-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.mcp-help { font-size: 13px; color: var(--muted); display: grid; gap: 6px; }
.mcp-help code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* responsive */
@media (max-width: 980px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 35;
    flex-direction: row; padding: 6px; border-right: 0; border-top: 1px solid var(--border);
  }
  .sidebar .brand, .sidebar .spacer, .sidebar .reset { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 4px; }
  .nav a.hide-sm { display: none; }
  .topbar { padding: 12px 16px; }
  .topbar .btn-label { display: none; }
  .content { padding: 16px 16px 96px; }
  .hero-value { font-size: 30px; }
  .mcp-fab { bottom: 80px; right: 16px; }
  .toasts { bottom: 140px; }
  .hide-sm { display: none; }
}
