/* Builder chrome (2026-10-11 redesign, docs/BUILDER_UX_AUDIT.md): toolbox,
   export menu, template picker, "next step" check bar. Plain CSS on the same
   values as assets/ui/tokens.css (the backtest panel), not Tailwind utilities:
   the project ships a precompiled Tailwind build and a class missing from it
   silently styles nothing. Everything is prefixed .ap-* or targets Blockly's
   own toolbox classes, so it cannot restyle the rest of the page. */
:root {
  --b-bg: #030712; --b-surface: #0a101c; --b-surface-2: #111827;
  --b-border: #1f2937; --b-border-strong: #374151;
  --b-text: #f3f4f6; --b-text-2: #d1d5db; --b-muted: #9ca3af;
  --b-accent: #10b981; --b-accent-hover: #34d399; --b-on-accent: #03140d;
  --b-warn: #fbbf24; --b-focus: #6ee7b7;
  --b-font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- toolbox ----------
   Deliberately plain, like the builder has always had: a flat list of
   drawers, each with its block colour on the left edge. No captions, icons,
   rounded rows or other decoration. */
.blocklyToolbox {
  width: 196px; padding: 0 !important;
  border-right: 1px solid var(--b-border);
  font-family: var(--b-font);
  scrollbar-width: thin;
}
.blocklyToolbox .blocklyToolboxCategory {
  height: auto; padding: 10px 12px !important; margin: 0;
  border-left-width: 6px !important;
  cursor: pointer; line-height: 1.2;
}
.blocklyToolbox .blocklyToolboxCategory:hover { background: var(--b-surface-2); }
.blocklyToolbox .blocklyToolboxCategoryLabel { font: 400 15px/1.2 var(--b-font); color: var(--b-text-2); }
.blocklyToolbox .blocklyToolboxSelected .blocklyToolboxCategoryLabel { color: #fff; }
.blocklyToolbox .blocklyToolboxCategoryIcon { display: none; }
.blocklyToolbox .blocklyTreeSeparator { border-bottom: 1px solid var(--b-border); margin: 6px 0; height: 0; }
.blocklyFlyoutLabelText { font: 500 13px var(--b-font) !important; fill: var(--b-muted) !important; }

/* search box, prepended to the toolbox by builder.js */
.ap-search { position: relative; margin: 0 0 6px; border-bottom: 1px solid var(--b-border); }
.ap-search svg { position: absolute; left: 12px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%); color: var(--b-muted); pointer-events: none; }
.ap-search input {
  width: 100%; height: 40px; padding: 0 8px 0 34px; box-sizing: border-box;
  border: 0; background: transparent; color: var(--b-text);
  font: 400 14px var(--b-font); outline: none;
}
.ap-search input::placeholder { color: var(--b-muted); }
.ap-search input:focus { background: var(--b-surface); }

/* ---------- "next step" check bar ---------- */
.ap-check {
  /* Centred on the canvas itself: the part of the screen right of the
     toolbox (196px) - and left of the chat panel when that is open. The
     side margin keeps it clear of the zoom controls and the bin.
     bottom: Blockly's horizontal scrollbar runs along the canvas bottom,
     15px thick (25px on touch screens) and drawn above this bar
     (z-index 20), so the bar sits clear of it rather than under it. Not
     raising the z-index instead: that would cover the toolbox flyout,
     which shares the scrollbar's layer. */
  --ap-canvas-left: 196px; --ap-canvas-right: 0px;
  position: absolute; bottom: 32px; z-index: 10;
  left: calc(var(--ap-canvas-left) + (100% - var(--ap-canvas-left) - var(--ap-canvas-right)) / 2);
  transform: translateX(-50%);
  width: min(600px, calc(100% - var(--ap-canvas-left) - var(--ap-canvas-right) - 200px));
  border: 1px solid var(--b-border-strong); border-radius: 10px;
  background: rgba(17, 24, 39, .97); box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  font-family: var(--b-font); color: var(--b-text-2);
}
.ap-check[hidden], body.ap-bt-on .ap-check { display: none; }
.ap-check-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 14px; }
.ap-check-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--b-warn); }
.ap-check.is-ok .ap-check-dot { background: var(--b-accent); }
.ap-check-text { flex: 1; min-width: 0; font-size: 14px; line-height: 1.4; }
.ap-check-text b { display: block; font-weight: 600; color: var(--b-text); }
.ap-check-text span { display: block; color: var(--b-muted); font-size: 13px; }
.ap-check-actions { display: flex; gap: 8px; flex: none; }
.ap-check button {
  height: 34px; padding: 0 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--b-border-strong); background: transparent; color: var(--b-text);
  font: 500 13px var(--b-font);
}
.ap-check button:hover { background: var(--b-border); }
.ap-check button.is-primary { background: var(--b-accent); border-color: transparent; color: var(--b-on-accent); font-weight: 600; }
.ap-check button.is-primary:hover { background: var(--b-accent-hover); }
.ap-check button:focus-visible { outline: 2px solid var(--b-focus); outline-offset: 2px; }
.ap-check-list { margin: 0; padding: 4px 8px 8px; list-style: none; border-top: 1px solid var(--b-border); }
.ap-check-list button { display: block; width: 100%; height: auto; padding: 8px; border: 0; text-align: left; white-space: normal; font-weight: 400; color: var(--b-text-2); }
.ap-check.is-pulse { animation: ap-check-pulse .9s ease-out 1; }
@keyframes ap-check-pulse {
  0% { box-shadow: 0 0 0 0 rgba(251, 191, 36, .7), 0 10px 30px rgba(0, 0, 0, .45); }
  100% { box-shadow: 0 0 0 14px rgba(251, 191, 36, 0), 0 10px 30px rgba(0, 0, 0, .45); }
}
/* the block "Show me" points at */
.ap-flash > .blocklyPath { animation: ap-flash 1.1s ease-in-out 2; }
@keyframes ap-flash { 50% { filter: drop-shadow(0 0 3px #fbbf24) drop-shadow(0 0 10px rgba(251, 191, 36, .9)); } }

/* ---------- template picker ---------- */
.ap-start {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(0, 0, 0, .62); font-family: var(--b-font);
}
.ap-start[hidden] { display: none; }
.ap-start-card {
  width: 100%; max-width: 860px; max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 28px; border: 1px solid var(--b-border-strong); border-radius: 14px;
  background: var(--b-surface); box-shadow: 0 30px 80px rgba(0, 0, 0, .6); color: var(--b-text-2);
}
.ap-start-card h2 { margin: 0; font: 700 22px/1.25 var(--b-font); letter-spacing: -.01em; color: var(--b-text); }
.ap-start-sub { margin: 6px 0 0; font-size: 15px; line-height: 1.5; color: var(--b-muted); }
.ap-start-note { margin: 12px 0 0; padding: 10px 12px; border: 1px solid var(--b-border); border-left: 3px solid var(--b-warn); border-radius: 8px; font-size: 14px; color: var(--b-text-2); }
.ap-start-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.ap-tpl {
  display: flex; flex-direction: column; gap: 10px; padding: 16px; text-align: left; cursor: pointer;
  border: 1px solid var(--b-border); border-radius: 10px; background: var(--b-surface-2); color: inherit; font: inherit;
}
.ap-tpl:hover { border-color: var(--b-accent); }
.ap-tpl:focus-visible { outline: 2px solid var(--b-focus); outline-offset: 2px; }
.ap-tpl-name { font: 600 16px/1.3 var(--b-font); color: var(--b-text); }
.ap-tpl-desc { font-size: 13px; line-height: 1.45; color: var(--b-muted); }
.ap-tpl-rule { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: auto; font: 600 11px var(--b-font); letter-spacing: .06em; color: var(--b-muted); }
.ap-chip { padding: 4px 9px; border-radius: 999px; font: 500 12px var(--b-font); letter-spacing: 0; color: #fff; white-space: nowrap; }
.ap-chip-if { background: #9a600a; }
.ap-chip-then { background: #0a7a55; }
.ap-tpl-blank { border-style: dashed; background: transparent; justify-content: center; }
.ap-start-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; font-size: 12px; line-height: 1.5; color: var(--b-muted); }
.ap-start-foot button { flex: none; height: 36px; padding: 0 14px; border: 1px solid var(--b-border-strong); border-radius: 8px; background: transparent; color: var(--b-text); font: 500 14px var(--b-font); cursor: pointer; }
.ap-start-foot button:hover { background: var(--b-surface-2); }

@media (max-width: 639px) {
  .blocklyToolbox { width: 190px; }
  .ap-check { left: 8px; right: 8px; bottom: 32px; width: auto; transform: none; }
  .ap-check-row { flex-wrap: wrap; }
  .ap-check-actions { width: 100%; }
  .ap-check-actions button { flex: 1; }
  .ap-start-card { padding: 18px; }
  .ap-start-grid { grid-template-columns: 1fr; }
  .ap-start-foot { flex-direction: column; align-items: stretch; }
}


/* The one-time "New: test your strategy" popover (assets/backtest/ui/) sat on
   top of the canvas and under the Export menu. The check bar's own Backtest
   button, shown the moment a strategy is complete, does its job now. */
.ap-bt-hint { display: none !important; }

/* placeholder blocks: an empty slot that says what goes in it */
.blocklyDraggable[data-ap-placeholder] > .blocklyPath { stroke-dasharray: 4 3; }

/* toasts sit above the check bar instead of on top of it */
#toast { bottom: 104px; }

/* the drawer(s) "Show me" points at */
.blocklyToolbox .blocklyToolboxCategory.ap-cat-pulse { animation: ap-cat-pulse 1.2s ease-in-out 2; }
@keyframes ap-cat-pulse { 50% { background: rgba(251, 191, 36, .28); box-shadow: inset 0 0 0 1px #fbbf24; } }

/* ---------- assistant chat (assets/builder/assistant.js) ---------- */
.ap-chat-launcher {
  position: absolute; right: 16px; top: 14px; z-index: 11;
  display: inline-flex; align-items: center; gap: 12px; height: 48px; padding: 0 20px 0 16px;
  border: 1px solid rgba(52, 211, 153, .55); border-radius: 10px; cursor: pointer;
  background: var(--b-surface-2); color: var(--b-text);
  font: 500 15px var(--b-font);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
}
.ap-chat-launcher:hover { background: var(--b-border); border-color: var(--b-accent-hover); }
/* the lamp: a green light that breathes */
.ap-chat-lamp {
  flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--b-accent-hover);
  animation: ap-chat-lamp 1.8s ease-in-out infinite;
}
@keyframes ap-chat-lamp {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(52, 211, 153, .7), 0 0 8px 2px rgba(52, 211, 153, .8); }
  50% { opacity: .45; box-shadow: 0 0 0 7px rgba(52, 211, 153, 0), 0 0 3px 0 rgba(52, 211, 153, .3); }
}
@media (prefers-reduced-motion: reduce) { .ap-chat-lamp { animation: none; } }
.ap-chat-head .ap-chat-lamp { margin-right: 10px; vertical-align: 1px; }
.ap-chat-launcher[hidden], .ap-chat[hidden], body.ap-bt-on .ap-chat-launcher, body.ap-bt-on .ap-chat,
body.ap-chat-open .ap-chat-launcher { display: none; }
.ap-chat {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 12; width: 380px;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--b-border); background: var(--b-bg);
  font-family: var(--b-font); color: var(--b-text-2);
}
/* the canvas makes room instead of being covered */
body.ap-chat-open:not(.ap-bt-on) #blocklyDiv { right: 380px; width: calc(100% - 380px); }
body.ap-chat-open .ap-check { --ap-canvas-right: 380px; }
.ap-chat-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--b-border); }
.ap-chat-head b { font: 600 16px var(--b-font); color: var(--b-text); }
.ap-chat-close { width: 30px; height: 30px; border: 0; border-radius: 6px; background: none; color: var(--b-muted); font-size: 22px; line-height: 1; cursor: pointer; }
.ap-chat-close:hover { background: var(--b-surface-2); color: var(--b-text); }
.ap-chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin; }
.ap-chat-msg { max-width: 92%; padding: 9px 12px; border-radius: 10px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.ap-chat-msg.is-user { align-self: flex-end; background: var(--b-surface-2); color: var(--b-text); border: 1px solid var(--b-border-strong); }
.ap-chat-msg.is-assistant { align-self: flex-start; background: var(--b-surface); border: 1px solid var(--b-border); }
.ap-chat-msg.is-note { align-self: stretch; max-width: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border: 1px solid var(--b-border); border-left: 3px solid var(--b-accent); border-radius: 8px; font-size: 13px; color: var(--b-muted); }
.ap-chat-msg.is-note button { flex: none; height: 28px; padding: 0 10px; border: 1px solid var(--b-border-strong); border-radius: 6px; background: transparent; color: var(--b-text); font: 500 12px var(--b-font); cursor: pointer; }
.ap-chat-msg.is-note button:hover { background: var(--b-surface-2); }
.ap-chat-intro { margin: auto 0; display: flex; flex-direction: column; gap: 8px; }
.ap-chat-intro p { margin: 0 0 6px; font-size: 14px; line-height: 1.55; color: var(--b-muted); }
.ap-chat-intro button { text-align: left; padding: 9px 12px; border: 1px solid var(--b-border); border-radius: 8px; background: transparent; color: var(--b-text-2); font: 400 14px var(--b-font); cursor: pointer; }
.ap-chat-intro button:hover { border-color: var(--b-border-strong); background: var(--b-surface); color: var(--b-text); }
.ap-chat-form { display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px 8px; border-top: 1px solid var(--b-border); }
.ap-chat-form textarea { flex: 1; min-height: 44px; max-height: 160px; resize: none; padding: 10px 12px; border: 1px solid var(--b-border-strong); border-radius: 8px; background: var(--b-surface); color: var(--b-text); font: 400 14px/1.45 var(--b-font); outline: none; }
.ap-chat-form textarea:focus { border-color: var(--b-accent); }
.ap-chat-form button { flex: none; height: 44px; padding: 0 16px; border: 0; border-radius: 8px; background: var(--b-accent); color: var(--b-on-accent); font: 600 14px var(--b-font); cursor: pointer; }
.ap-chat-form button:hover:not(:disabled) { background: var(--b-accent-hover); }
.ap-chat-form button:disabled { opacity: .6; cursor: default; }
.ap-chat-foot { margin: 0; padding: 0 16px 12px; font-size: 11.5px; line-height: 1.45; color: var(--b-muted); }
.ap-chat-launcher:focus-visible, .ap-chat button:focus-visible { outline: 2px solid var(--b-focus); outline-offset: 2px; }
@media (max-width: 899px) {
  .ap-chat { position: fixed; inset: 0; width: auto; z-index: 90; border-left: 0; }
  body.ap-chat-open:not(.ap-bt-on) #blocklyDiv { right: 0; width: 100%; }
  body.ap-chat-open .ap-check { display: none; }
  .ap-chat-launcher { height: 40px; padding: 0 12px; gap: 8px; font-size: 14px; top: 8px; right: 8px; }
}
