/* Trading Assistant — refined fintech UI
   Dark by default; [data-theme="light"] overrides the palette. All colors flow
   through CSS variables so both themes stay in sync. */
:root {
  /* Surfaces */
  --bg: #0a0f11; --bg-glow: rgba(22, 199, 192, .08);
  --panel: #111a1c; --panel-2: #162124; --input-bg: #0d1517;
  --border: #21332f; --border-soft: #1a2724;
  /* Text */
  --text: #e8f2f0; --muted: #86a09b; --heading: #f2fbf9;
  /* Brand — electric teal */
  --accent: #16c7c0; --accent-2: #0b8f9e; --accent-weak: rgba(22, 199, 192, .16);
  --accent-ring: rgba(22, 199, 192, .34);
  /* Status */
  --green: #33c281; --red: #ff5b57; --amber: #e2b23e;
  --badge-blue-bg: rgba(91, 140, 255, .16); --badge-amber-bg: rgba(226, 178, 62, .16);
  --badge-green-bg: rgba(51, 194, 129, .16); --badge-red-bg: rgba(255, 91, 87, .16);
  --live-banner-bg: rgba(255, 91, 87, .16); --live-banner-fg: #ff8b87;
  --canvas-dot: #1c2431;
  /* Depth */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
  --radius: 14px; --radius-sm: 9px;
}
:root[data-theme="light"] {
  --bg: #f2f7f6; --bg-glow: rgba(12, 147, 160, .06);
  --panel: #ffffff; --panel-2: #f4f9f8; --input-bg: #f3f8f7;
  --border: #dde8e6; --border-soft: #e9f1ef;
  --text: #14201f; --muted: #566662; --heading: #0c1817;
  --accent: #0c93a0; --accent-2: #0b7f8c; --accent-weak: rgba(12, 147, 160, .11);
  --accent-ring: rgba(12, 147, 160, .3);
  --green: #158f57; --red: #d93a34; --amber: #9a6f12;
  --badge-blue-bg: #e7efff; --badge-amber-bg: #fbf1d3; --badge-green-bg: #ddf5e9;
  --badge-red-bg: #ffe6e5; --live-banner-bg: #ffe6e5; --live-banner-fg: #c02f2a;
  --canvas-dot: #e2e8f1;
  --shadow-sm: 0 1px 2px rgba(60, 70, 90, .08);
  --shadow: 0 8px 28px rgba(60, 70, 90, .12);
  --shadow-lg: 0 18px 50px rgba(60, 70, 90, .16);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; color: var(--text);
  background:
    radial-gradient(1200px 600px at 78% -8%, var(--bg-glow), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  font: 14px/1.55 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body, .card, header, input, select, textarea, button, .badge, nav#tabs button {
  transition: background-color .16s ease, border-color .16s ease,
    color .16s ease, box-shadow .16s ease, transform .1s ease;
}
::selection { background: var(--accent-weak); }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1em; }
.spacer { flex: 1; }
code { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: .92em;
  background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }

/* Auth */
.auth-wrap { display: flex; justify-content: center; padding-top: 11vh; }
.auth-card { width: 380px; box-shadow: var(--shadow-lg); }
.auth-card h1 {
  margin: 0 0 2px; font-size: 26px; letter-spacing: -.02em;
  background: linear-gradient(120deg, var(--text), var(--accent));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.tagline {
  margin: 0 0 10px; font-size: 13px; font-weight: 600; letter-spacing: .04em;
  color: var(--accent); text-transform: uppercase;
}

/* Header */
header {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 24px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  position: sticky; top: 0; z-index: 50;
}
header h1 {
  font-size: 17px; margin: 0; letter-spacing: -.01em; font-weight: 650;
}

/* Brand / logo */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-text { font-weight: 650; letter-spacing: -.01em; }
.brand-mark { display: block; filter: drop-shadow(0 3px 8px var(--accent-ring)); }
.brand-mark .g0 { stop-color: var(--accent); }
.brand-mark .g1 { stop-color: var(--accent-2); }
.auth-brand { display: flex; justify-content: center; margin-bottom: 16px; }
.brand-mark-lg { filter: drop-shadow(0 8px 22px var(--accent-ring)); }

/* Tabs — segmented */
nav#tabs {
  display: flex; gap: 4px; padding: 14px 24px 0; flex-wrap: wrap;
}
nav#tabs button {
  background: none; border: 1px solid transparent;
  color: var(--muted); padding: 8px 15px; cursor: pointer;
  border-radius: 9px; font-weight: 550; font-size: 13.5px;
}
nav#tabs button:hover { color: var(--text); background: var(--panel-2); }
nav#tabs button.active {
  color: var(--accent); background: var(--accent-weak);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
main { padding: 20px 24px 48px; max-width: 1140px; margin: 0 auto; }

/* Cards */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  margin: 0 0 14px; font-size: 15px; font-weight: 650;
  letter-spacing: -.01em; color: var(--heading);
}
/* Dashboard KPI tiles */
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat.highlight {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: linear-gradient(180deg, var(--accent-weak), transparent 60%), var(--panel);
}
.stat-label { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Plain-language intro line at the top of a tab/card */
.intro { margin: 0 0 4px; font-size: 13.5px; line-height: 1.6; color: var(--text); }
.intro b { color: var(--heading); }
.key-list { margin: 10px 0 0; padding-left: 20px; }
.key-list li { margin-bottom: 7px; line-height: 1.55; }
.key-list b { color: var(--heading); }

/* Getting-started checklist */
.checklist { list-style: none; margin: 14px 0 0; padding: 0; }
.checklist li {
  padding: 9px 12px; margin-bottom: 6px; border-radius: 9px;
  background: var(--panel-2); border: 1px solid var(--border-soft); font-size: 13.5px;
}
.checklist li.done { background: var(--badge-green-bg); border-color: transparent; }
.checklist b { color: var(--heading); }
.ready { margin: 10px 0 0; font-size: 13.5px; font-weight: 550; color: var(--heading); }

/* "How do I get this key?" guides */
.guides { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.guide {
  border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2);
  padding: 2px 12px;
}
.guide > summary {
  cursor: pointer; padding: 10px 2px; font-weight: 600; color: var(--heading);
  font-size: 13.5px; list-style-position: inside;
}
.guide[open] > summary { border-bottom: 1px solid var(--border-soft); margin-bottom: 8px; }
.guide ol { margin: 4px 0 12px; padding-left: 22px; }
.guide li { margin-bottom: 8px; line-height: 1.6; }
.guide a { color: var(--accent); font-weight: 600; }

/* Test-key button + result */
.cred-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cred-test-result { font-size: 13px; font-weight: 600; }
.cred-test-result.ok { color: var(--green); }
.cred-test-result.bad { color: var(--red); }
.cred-test-result.pending { color: var(--muted); }

/* Forms */
label {
  display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  letter-spacing: .01em;
}
input, select, textarea {
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 11px; font: inherit; width: 100%; outline: none;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.grid .full { grid-column: 1 / -1; }
.grid textarea { resize: vertical; min-height: 96px; }
.row { display: flex; gap: 8px; }

/* Buttons */
button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 15px; cursor: pointer; font: inherit; font-weight: 550;
}
button:hover { border-color: var(--muted); background: color-mix(in srgb, var(--panel-2) 60%, var(--border)); }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; color: #fff; box-shadow: 0 4px 14px var(--accent-ring);
}
button.primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
button.primary:active { transform: translateY(0); }
button.refresh { padding: 3px 9px; font-size: 12px; float: right; font-weight: 500; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
#theme-toggle, #tour-btn { padding: 8px 11px; font-size: 14px; line-height: 1; }

/* Tables */
table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
th { color: var(--muted); font-weight: 550; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; letter-spacing: .01em;
}
.badge.proposed { background: var(--badge-blue-bg); color: var(--accent); }
.badge.executing { background: var(--badge-amber-bg); color: var(--amber); }
.badge.executed, .badge.filled, .badge.accepted, .badge.new { background: var(--badge-green-bg); color: var(--green); }
.badge.rejected, .badge.failed, .badge.risk_rejected, .badge.halted { background: var(--badge-red-bg); color: var(--red); }
.badge.live { background: var(--red); color: #fff; font-weight: 700; }
.badge.paper { background: var(--badge-blue-bg); color: var(--muted); }

/* Banners */
.kill-banner {
  background: var(--red); color: #fff; padding: 5px 14px; border-radius: 20px;
  font-weight: 650; font-size: 12.5px; box-shadow: 0 2px 10px rgba(255, 91, 87, .35);
}
.live-banner {
  background: var(--live-banner-bg); color: var(--live-banner-fg);
  padding: 5px 14px; border-radius: 20px; font-weight: 650; font-size: 12.5px;
  border: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
}
.live-banner::before { content: "● "; }

/* Toggles */
.toggle-row {
  display: flex; align-items: center; gap: 16px; padding: 14px 0;
  border-bottom: 1px solid var(--border-soft);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row > div { flex: 1; }
.toggle-row b { color: var(--heading); }
.toggle-row p { margin: 3px 0 0; font-size: 12px; }
button.toggle {
  min-width: 66px; font-weight: 700; letter-spacing: .03em; border-radius: 20px;
}
button.toggle.on { background: linear-gradient(135deg, var(--green), #2aa870); border: none; color: #fff; }
button.toggle.off { color: var(--muted); }

/* Kill switch */
.danger-card { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }
.kill-button {
  width: 100%; padding: 15px; font-size: 15px; font-weight: 750; border-radius: 11px;
  background: linear-gradient(135deg, var(--red), #d13d38); border: none; color: #fff;
  box-shadow: 0 6px 18px rgba(255, 91, 87, .3);
}
.kill-button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.kill-button.engaged { background: linear-gradient(135deg, var(--green), #2aa870); box-shadow: none; }

/* Quick-start (beginner) card */
.quickstart-card {
  border-color: color-mix(in srgb, var(--accent) 32%, var(--border));
  background: linear-gradient(180deg, var(--accent-weak), transparent 55%), var(--panel);
}
.quickstart { margin: 6px 0 16px; padding-left: 22px; }
.quickstart li { margin-bottom: 9px; line-height: 1.6; }
.quickstart b { color: var(--heading); }
.config-desc { margin: -4px 0 12px; font-size: 12.5px; }
.starter-done {
  margin: 12px 0 0; padding: 10px 14px; font-size: 13px; line-height: 1.55;
  background: var(--badge-green-bg); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--green) 40%, transparent); border-radius: 9px;
}
.starter-done b { color: var(--heading); }

/* Canvas "something just appeared here" flash */
@keyframes canvasFlash {
  0% { box-shadow: 0 0 0 0 var(--accent-ring); }
  25% { box-shadow: 0 0 0 7px var(--accent-ring); }
  100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}
#agent-canvas.flash { animation: canvasFlash 1.3s ease-out; }

/* Agent builder canvas */
.agent-bar { align-items: center; flex-wrap: wrap; gap: 10px; }
.agent-bar select, .agent-bar .agent-name { width: auto; min-width: 180px; }
.canvas-toolbar { align-items: center; flex-wrap: wrap; gap: 10px; }
.toolbar-label { font-weight: 600; color: var(--heading); font-size: 13.5px; }
.canvas-hint { font-size: 12.5px; margin: 12px 0; line-height: 1.6; }

/* Palette — one aligned column per numbered step */
#palette {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px; align-items: start; margin-top: 12px;
  padding: 14px; background: var(--panel-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
.palette-group { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.palette-step {
  font-size: 10.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; padding-bottom: 4px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.palette-btns { display: flex; flex-direction: column; gap: 6px; }
.palette-btns .block-btn {
  width: 100%; text-align: left; font-size: 12.5px; padding: 8px 11px;
  font-weight: 550; background: var(--panel); border-radius: 8px;
}
.palette-btns .block-btn:hover { filter: brightness(1.12); transform: translateX(2px); }
#agent-canvas {
  width: 100%; height: 380px; background:
    radial-gradient(circle, var(--canvas-dot) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--input-bg);
  border: 1px solid var(--border); border-radius: var(--radius); touch-action: none;
}
#agent-canvas .node rect { rx: 10; stroke-width: 1.5; cursor: grab;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, .35)); }
#agent-canvas .node.selected rect { stroke: #fff !important; stroke-width: 2.5; }
#agent-canvas .node text { fill: #fff; font-size: 13px; font-weight: 600; pointer-events: none; }
#agent-canvas .node .sub { font-size: 10px; font-weight: 400; fill: rgba(255, 255, 255, .78); }
#agent-canvas .wire { stroke: var(--muted); stroke-width: 2; marker-end: url(#arrow); }
#agent-canvas .wire-hit { stroke: transparent; stroke-width: 14; cursor: pointer; }
#agent-canvas .wire-hit:hover + .wire, #agent-canvas g.wireg:hover .wire { stroke: var(--red); }
#agent-canvas.wiring .node rect { cursor: crosshair; }
.block-btn.trigger { border-color: var(--amber); color: var(--amber); }
.block-btn.generate { border-color: var(--accent); color: var(--accent); }
.block-btn.filter { border-color: #b083f0; color: #b083f0; }
.block-btn.outcome { border-color: var(--green); color: var(--green); }
#wire-mode.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; }
.node-config {
  margin-top: 14px; padding: 14px 16px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--panel-2);
}
.node-config h3 { margin: 0 0 10px; font-size: 13px; color: var(--heading); }
.node-config .grid { align-items: start; }
.checks { display: flex; gap: 14px; align-items: center; }
.checks label { flex-direction: row; align-items: center; gap: 6px; margin: 0; }
.checks input { width: auto; }

/* Guided tour (walkthrough) */
.tour-overlay { position: fixed; inset: 0; z-index: 1000; pointer-events: auto;
  background: rgba(6, 9, 14, .4); backdrop-filter: blur(1px); }
.tour-spot {
  position: fixed; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(6, 9, 14, .68); outline: 2px solid var(--accent);
  outline-offset: 3px; transition: all .22s ease; z-index: 1001;
}
.tour-pop {
  position: fixed; z-index: 1002; width: 336px; max-width: calc(100vw - 24px);
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-lg);
  transition: top .22s ease, left .22s ease;
}
.tour-pop h3 { margin: 0 0 9px; font-size: 15.5px; font-weight: 650; color: var(--heading); }
.tour-pop p { margin: 0 0 15px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.tour-nav { display: flex; align-items: center; gap: 8px; }
.tour-nav .tour-count { flex: 1; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tour-nav button { padding: 7px 13px; }
.tour-skip { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; }
.tour-skip:hover { color: var(--text); border: none; background: none; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; right: 22px; max-width: 420px;
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: 13px 17px; box-shadow: var(--shadow-lg);
  z-index: 1100;
}
.toast.err { border-left-color: var(--red); }
