/* ============================================================================
   Xtrading — shared design system (served VM-direct via Caddy, CSP style-src 'self').
   One cohesive dark "quant terminal" theme across the lab, marketplace and admin.
   Pages link this first, then add a small page-specific <style> for their own bits.
   Class names match what the page JS already renders, so markup is restyled in place.
   ============================================================================ */

:root {
  color-scheme: dark;

  /* surfaces */
  --bg: #090c11;
  --bg-grad-1: #0e141d;
  --bg-grad-2: #090c11;
  --panel: #121822;
  --panel-2: #0d121a;
  --panel-3: #0a0e14;
  --inset: #0a0e13;

  /* lines */
  --line: rgba(255, 255, 255, 0.075);
  --line-2: rgba(255, 255, 255, 0.13);

  /* text */
  --text: #e9eef5;
  --muted: #93a0ad;
  --faint: #6b7682;

  /* brand + semantics */
  --blue: #4da3ff;
  --teal: #2fd5ad;
  --green: #16c784;
  --red: #f0616d;
  --amber: #f0b90b;
  --accent: linear-gradient(135deg, #34e0b4 0%, #4da3ff 100%);
  --accent-soft: rgba(77, 163, 255, 0.13);
  --green-soft: rgba(22, 199, 132, 0.13);
  --red-soft: rgba(240, 97, 109, 0.13);
  --amber-soft: rgba(240, 185, 11, 0.13);

  /* radii */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --pill: 999px;

  /* depth */
  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --sh-2: 0 8px 28px rgba(0, 0, 0, 0.42);
  --sh-pop: 0 18px 50px rgba(0, 0, 0, 0.6);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --maxw: 1120px;
  --bar-h: 58px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 70% -200px, rgba(77, 163, 255, 0.10), transparent 60%),
    radial-gradient(900px 500px at -100px 0, rgba(47, 213, 173, 0.07), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2) 420px);
  background-attachment: fixed;
  color: var(--text);
  font: 14.5px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--blue); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: #7fbdff; }

h1 { font-size: 30px; line-height: 1.12; letter-spacing: -0.02em; margin: 22px 0 6px; font-weight: 800; }
h2 { letter-spacing: -0.01em; }
.sub { color: var(--muted); margin: 0 0 18px; max-width: 760px; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.cash { color: var(--amber); }
.mono { font-family: var(--mono); }
.error { color: var(--red); }
[hidden] { display: none !important; }

.wrap, .container { max-width: var(--maxw); margin: 0 auto; padding: 0 20px 56px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* ------------------------------------------------------------------ App bar */
.appbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(10, 13, 18, 0.72);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.appbar-inner {
  max-width: var(--maxw); margin: 0 auto; height: var(--bar-h);
  padding: 0 20px; display: flex; align-items: center; gap: 18px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 16.5px; letter-spacing: -0.01em; color: var(--text);
  white-space: nowrap;
}
.brand:hover { color: var(--text); }
.brand .logo {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: #04131f; font-weight: 900; font-size: 15px;
  box-shadow: 0 2px 10px rgba(47, 213, 173, 0.35);
}
.brand .logo svg { width: 17px; height: 17px; display: block; }
.brand small { color: var(--muted); font-weight: 600; font-size: 12px; }

.nav { display: flex; align-items: center; gap: 4px; margin-left: 6px; }
.nav a {
  color: var(--muted); font-weight: 600; font-size: 13.5px;
  padding: 7px 11px; border-radius: var(--r-sm); white-space: nowrap;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.nav a.active { color: var(--text); background: var(--accent-soft); }
.nav .spacer { flex: 1; }
.appbar .grow { flex: 1; }

/* wallet control (right side of the bar) */
.wallet { position: relative; display: inline-flex; align-items: center; }
.wallet-chip {
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text);
  border-radius: var(--pill); padding: 6px 12px; font-weight: 700; font-size: 13px;
  cursor: pointer; transition: border-color .15s var(--ease), background .15s var(--ease);
}
.wallet-chip:hover { border-color: var(--blue); background: rgba(77, 163, 255, 0.06); }
.wallet-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.wallet-chip .role { display: inline-flex; align-items: center; margin-left: 1px; padding: 1.5px 7px; border-radius: 999px; font-size: 9.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; line-height: 1.5; border: 1px solid transparent; }
.wallet-chip .role.free { color: var(--muted); background: rgba(147, 160, 173, 0.12); border-color: rgba(147, 160, 173, 0.32); }
.wallet-chip .role.paid { color: var(--green); background: var(--green-soft); border-color: rgba(22, 199, 132, 0.45); }
.wallet-chip .role.admin { color: var(--amber); background: var(--amber-soft); border-color: rgba(240, 185, 11, 0.45); }
.wallet-chip .caret { color: var(--muted); font-size: 10px; }
.wallet-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r);
  box-shadow: var(--sh-pop); padding: 7px; z-index: 60;
  opacity: 0; transform: translateY(-6px) scale(.98); pointer-events: none;
  transition: opacity .16s var(--ease), transform .16s var(--ease);
}
.wallet-menu.open { opacity: 1; transform: none; pointer-events: auto; }
.wallet-menu .who { padding: 9px 11px 11px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.wallet-menu .who .addr { font-family: var(--mono); font-size: 13px; font-weight: 700; }
.wallet-menu .who .tier { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.wallet-menu button, .wallet-menu a {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: none; border: 0; color: var(--text); font: inherit; font-size: 13.5px;
  padding: 9px 11px; border-radius: var(--r-sm); cursor: pointer;
}
.wallet-menu button:hover, .wallet-menu a:hover { background: rgba(255, 255, 255, 0.05); }
.wallet-menu .danger { color: var(--red); }
.wallet-menu .ico { width: 16px; opacity: .8; text-align: center; }

/* mobile nav toggle */
.nav-toggle { display: none; background: none; border: 1px solid var(--line-2); color: var(--text);
  border-radius: var(--r-sm); width: 38px; height: 36px; font-size: 16px; cursor: pointer; }

/* ------------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  border-radius: var(--r-sm); height: 40px; padding: 0 16px; font: inherit; font-weight: 700;
  cursor: pointer; white-space: nowrap; transition: transform .12s var(--ease), filter .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.btn:hover { border-color: var(--blue); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn:disabled { opacity: .45; cursor: not-allowed; filter: none; transform: none; }
.btn.primary, .btn.connect {
  background: var(--accent); color: #04131f; border: 0; font-weight: 800;
  box-shadow: 0 4px 16px rgba(47, 213, 173, 0.25);
}
.btn.primary:hover, .btn.connect:hover { filter: brightness(1.06); border: 0; }
.btn.secondary, .btn.ghost { background: var(--panel-2); color: var(--text); }
.btn.danger, .btn.bad { background: var(--red); color: #fff; border: 0; }
.btn.ok { background: var(--green); color: #04131f; border: 0; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.busy { opacity: 1; cursor: progress; }
.btn.busy::before {
  content: ""; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(4, 19, 31, 0.35); border-top-color: currentColor;
  animation: spin .7s linear infinite;
}
.btn.ghost.busy::before, .btn.secondary.busy::before { border-color: rgba(255,255,255,.25); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }
.linklike { background: none; border: 0; padding: 0; color: var(--blue); font: inherit; cursor: pointer; }
.linklike:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ Surfaces */
section, .panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.014), transparent), var(--panel);
  border: 1px solid var(--line); border-radius: var(--r); margin-top: 16px; overflow: hidden;
  box-shadow: var(--sh-1);
}
section > h2 {
  margin: 0; padding: 14px 18px; font-size: 14.5px; font-weight: 700;
  border-bottom: 1px solid var(--line); background: var(--panel-2);
}
.body { padding: 18px; }
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.015), transparent), var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--r); padding: 16px;
}
.label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }

/* stats grid */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px;
  transition: border-color .15s var(--ease);
}
.stat:hover { border-color: var(--line-2); }
.stat .label { font-size: 11px; }
.stat .value { margin-top: 7px; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }

/* badges / tags / chips */
.tag, .badge { display: inline-block; font-size: 10.5px; font-weight: 800; border-radius: var(--pill); padding: 3px 9px; letter-spacing: .02em; }
.tag.listed { color: #04131f; background: var(--amber); }
.tag.priced { color: var(--blue); border: 1px solid var(--blue); }
.badge.tier { color: var(--teal); background: var(--green-soft); }
.chip {
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted);
  border-radius: var(--pill); padding: 7px 13px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: color .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.chip:hover { color: var(--text); }
.chip.on { color: var(--text); border-color: var(--blue); background: var(--accent-soft); }

/* verdict banner */
.verdict { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--r-sm); font-weight: 700; font-size: 16px; margin-bottom: 14px; }
.verdict.good { background: var(--green-soft); border: 1px solid var(--green); color: var(--green); }
.verdict.bad { background: var(--red-soft); border: 1px solid var(--red); color: var(--red); }

/* pill (legacy connected indicator on pages not yet using the chip) */
.pill { display: inline-flex; align-items: center; gap: 7px; background: var(--panel-2);
  border: 1px solid var(--line-2); border-radius: var(--pill); padding: 6px 13px; font-size: 12.5px; color: var(--muted); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

/* inputs */
textarea, select, input[type="date"], input[type="text"], input[type="search"], .input {
  background: var(--inset); color: var(--text); border: 1px solid var(--line-2);
  border-radius: var(--r-sm); padding: 10px 12px; font: inherit; min-height: 40px;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
textarea { width: 100%; min-height: 92px; resize: vertical; line-height: 1.5; }
textarea:focus, select:focus, input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; }

/* empty / loading / skeleton */
.empty { color: var(--muted); padding: 36px 12px; text-align: center; }
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: .7; }
.loading { color: var(--muted); padding: 26px 10px; display: flex; align-items: center; gap: 10px; }
.loading::before { content: ""; width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--blue); animation: spin .7s linear infinite; }
.skeleton { position: relative; overflow: hidden; background: var(--panel-2); border-radius: var(--r-sm); }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent); animation: shimmer 1.4s infinite; }
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* toast */
.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  background: var(--panel); border: 1px solid var(--line-2); border-left: 3px solid var(--blue);
  border-radius: var(--r-sm); box-shadow: var(--sh-pop); padding: 12px 16px; font-size: 13.5px; font-weight: 600;
  max-width: min(420px, 92vw); animation: toastin .25s var(--ease);
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes toastin { from { opacity: 0; transform: translateY(10px); } }

/* overlay / modal (shared) */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(4, 7, 11, 0.74); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-lg);
  max-width: 720px; width: 100%; max-height: 92vh; overflow: auto; padding: 26px 28px; box-shadow: var(--sh-pop); }
.modal h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.01em; }

/* result-card shared bits (lab + marketplace) */
.asset-tag { font-size: 11.5px; color: var(--muted); font-weight: 800; letter-spacing: .02em; }
.chart { margin-top: 14px; padding: 4px 0; }
.chart svg { width: 100%; height: auto; }
.legend { display: flex; gap: 16px; padding: 6px 2px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.s, .legend .s { background: var(--green); }
.legend i.b, .legend .b { background: var(--blue); }
.spec { margin-top: 14px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel-2); overflow: hidden; }
.spec h3 { margin: 0; padding: 11px 13px; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line); }
.spec .body, .spec pre { padding: 13px; }
.spec pre { margin: 0; white-space: pre-wrap; word-break: break-word; font: 12px/1.5 var(--mono); }
.proof-card { background: var(--panel-3); }
.proof-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.proof-table th, .proof-table td { padding: 10px 9px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.proof-table thead th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; border-top: 0; }
.proof-table th:nth-child(1), .proof-table td:nth-child(1) { width: 22%; color: var(--text); font-weight: 700; }
.proof-table th:nth-child(2), .proof-table td:nth-child(2) { width: 25%; }
.proof-table td:nth-child(3) { color: var(--muted); }

/* footer */
.footer { margin-top: 28px; color: var(--faint); font-size: 12px; line-height: 1.6; }

svg { display: block; }

/* responsive */
@media (max-width: 820px) {
  .nav { display: none; position: absolute; top: var(--bar-h); left: 0; right: 0; flex-direction: column;
    align-items: stretch; gap: 2px; padding: 8px; background: var(--panel); border-bottom: 1px solid var(--line-2); }
  .nav.open { display: flex; }
  .nav a { padding: 11px 13px; }
  .nav-toggle { display: inline-grid; place-items: center; }
  h1 { font-size: 25px; }
  .proof-table, .proof-table thead, .proof-table tbody, .proof-table tr, .proof-table th, .proof-table td { display: block; width: 100% !important; }
  .proof-table thead { display: none; }
  .proof-table tr { padding: 10px 0; border-top: 1px solid var(--line); }
  .proof-table tr:first-child { border-top: 0; }
  .proof-table td { border-top: 0; padding: 3px 0; }
}
