:root {
  --bg: #0c0f14;
  --surface: #141a22;
  --surface2: #1c2430;
  --border: #2a3544;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3dd6c3;
  --accent-dim: #2a9d8f;
  --amber: #f4a261;
  --rose: #e76f7a;
  --green: #52b788;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: "DM Sans", system-ui, sans-serif;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(61, 214, 195, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(244, 162, 97, 0.06), transparent);
}

.app { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.brand { display: flex; gap: 1rem; align-items: center; }
.logo {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: var(--bg);
  font-size: 1.5rem; font-weight: 700;
  border-radius: 12px;
}
.brand h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.tagline { color: var(--muted); font-size: 0.85rem; }

.header-meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--accent);
}

.header-link {
  padding: 0.5rem 0.85rem;
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}

.stepper {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.step {
  flex: 1;
  min-width: 120px;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.step:hover { border-color: var(--accent-dim); color: var(--text); }
.step.active {
  background: var(--surface2);
  border-color: var(--accent);
  color: var(--accent);
}
.step.done { color: var(--green); border-color: rgba(82, 183, 136, 0.4); }

.panel { display: none; animation: fade 0.25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel h2 { font-size: 1.25rem; margin-bottom: 0.35rem; }
.lead { color: var(--muted); margin-bottom: 1.25rem; font-size: 0.95rem; }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 1.25rem;
}
.upload-zone.dragover { border-color: var(--accent); background: var(--surface2); }
.upload-icon { font-size: 2rem; color: var(--accent); margin-bottom: 0.5rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.5rem; }

.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; text-decoration: underline; font: inherit;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.profile-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.profile-card:hover { border-color: var(--muted); }
.profile-card.selected { border-color: var(--accent); background: var(--surface2); }
.profile-card h4 { font-size: 0.95rem; margin-bottom: 0.35rem; }
.profile-card p { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.5rem; }
.skills { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.skill {
  font-size: 0.7rem;
  font-family: var(--mono);
  background: var(--bg);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  color: var(--amber);
}

.actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }

.btn {
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border-color: transparent;
  color: var(--bg);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { border-color: var(--rose); color: var(--rose); }

.checkbox { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1rem;
}
.hidden { display: none !important; }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-family: var(--mono);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-weight: 500;
}
.badge.green { background: rgba(82, 183, 136, 0.2); color: var(--green); }
.badge.amber { background: rgba(244, 162, 97, 0.2); color: var(--amber); }
.badge.blue { background: rgba(61, 214, 195, 0.15); color: var(--accent); }
.badge.rose { background: rgba(231, 111, 122, 0.2); color: var(--rose); }

.cache-meter {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  margin: 0.75rem 0;
}
.cache-meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width 0.4s ease;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  text-align: center;
}
.stat .val { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat .lbl { font-size: 0.75rem; color: var(--muted); }

.section-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--border);
}
.section-item[data-level="1"] { border-left-color: var(--accent); margin-left: 0; }
.section-item[data-level="2"] { border-left-color: var(--amber); margin-left: 1rem; }
.section-item[data-level="3"] { border-left-color: var(--muted); margin-left: 2rem; }
.section-item h4 { font-size: 0.9rem; margin-bottom: 0.35rem; }
.section-item p { font-size: 0.82rem; color: var(--muted); }
.hash { font-family: var(--mono); font-size: 0.68rem; color: var(--muted); word-break: break-all; }

.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.search-bar input {
  flex: 1;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.95rem;
}
.search-bar input:focus { outline: none; border-color: var(--accent); }

.hit {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.65rem;
}
.hit-header { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.hit-title { font-weight: 600; font-size: 0.95rem; }
.hit-score { font-family: var(--mono); font-size: 0.75rem; color: var(--accent); }
.hit-snippet { font-size: 0.85rem; color: var(--muted); }
.breadcrumb { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.35rem; }

.contract-form label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.75rem; }
.contract-form select,
.contract-form input {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--sans);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.75rem; }

.contract-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.contract-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.contract-meta { font-size: 0.8rem; color: var(--muted); }
.contract-meta dt { display: inline; font-weight: 600; color: var(--text); }
.contract-meta dd { display: inline; margin: 0 0.75rem 0 0; }
.explorer-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.explorer-links a {
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--accent);
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.explorer-links a:hover { background: var(--surface2); }

.graph-wrap { margin-top: 1.5rem; }
.graph-wrap h3 { font-size: 1rem; margin-bottom: 0.75rem; }
.graph-canvas {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 220px;
  padding: 1rem;
  overflow: auto;
  font-size: 0.75rem;
  font-family: var(--mono);
}
.graph-edge { color: var(--muted); padding: 0.15rem 0; }

.footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translateY(120%);
  transition: transform 0.25s ease;
  max-width: 360px;
  font-size: 0.9rem;
  z-index: 100;
}
.toast.show { transform: translateY(0); }
.toast.error { border-color: var(--rose); }

.muted { color: var(--muted); font-size: 0.85rem; }
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle; margin-right: 0.35rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.agent-card { margin-bottom: 0; }
.agent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.agent-header h3 { font-size: 1rem; }
.mcp-tools { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.75rem 0; }
.agent-log {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.7rem;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--muted);
}
.web-hit .hit-title { color: var(--accent); text-decoration: none; }
.web-hit .hit-title:hover { text-decoration: underline; }
.market-context { margin: 0.75rem 0; padding: 0.75rem 1rem; font-size: 0.9rem; }
.solscan-preview { margin: 1rem 0; text-align: center; }
.solscan-img {
  width: 64px;
  height: 64px;
  margin: 0.5rem auto;
  display: block;
  opacity: 0.9;
}
.x402-panel { margin: 1rem 0; }
.btn.amber {
  background: var(--amber);
  color: var(--bg);
  border: none;
}
.btn.amber:hover { filter: brightness(1.1); }

.deal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.deal-tab {
  padding: 0.55rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.deal-tab:hover { border-color: var(--accent-dim); color: var(--text); }
.deal-tab.active { border-color: var(--accent); color: var(--accent); background: var(--surface2); }
.stress-select {
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.85rem;
}
.deal-viewer { margin-top: 1rem; max-height: 480px; overflow: auto; }
.deal-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.deal-viewer-header h3 { font-size: 1rem; }
.deal-markdown {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-wrap;
  font-family: var(--sans);
}
.deal-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.deal-metric {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem;
  text-align: center;
}
.deal-metric .val { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.deal-metric .lbl { font-size: 0.7rem; color: var(--muted); }
.milestone-calendar { margin: 0.75rem 0 1rem; padding: 0.75rem; background: var(--bg); }
.milestone-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.milestone-table th, .milestone-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.milestone-table th { color: var(--muted); font-weight: 500; }
.milestone-table td:last-child { font-family: var(--mono); color: var(--accent); }
.milestone-table tr.selected { background: rgba(61, 214, 195, 0.08); }
