/**
 * BrighterTrading design system -- components
 *
 * bt-* component classes. References tokens.css ONLY: no raw
 * hex colors, no hard-coded spacings, no fixed radii. This rule
 * is what makes theming + density + radius variants compose
 * without touching this file.
 *
 * Conventions:
 *   - All classes are bt- prefixed. Coexists with legacy CSS.
 *   - Variant classes follow .bt-<base>-<variant> (e.g. .bt-btn-primary).
 *   - Modifier states use is- prefix (e.g. .is-active, .is-disabled).
 *   - Loaded after compatibility/base CSS. Existing markup is unaffected
 *     unless it explicitly opts in by adding bt-* classes.
 *
 * Coverage in Phase 1 (per DESIGN_SYSTEM_PLAN.md):
 *   - Buttons: .bt-btn + variants + sizes
 *   - Dialogs: .bt-dialog and parts (visual only -- behaviour comes
 *     from BT.dialog primitive in Phase 2)
 *   - Form fields: .bt-input, .bt-select, .bt-textarea, .bt-field,
 *                  .bt-label, .bt-help-text, .bt-error-text
 *   - Layout: .bt-panel, .bt-toolbar
 *   - Navigation: .bt-tabs, .bt-tab; .bt-menu, .bt-menu-item
 *   - Utilities: .bt-stack, .bt-cluster (the 80%-of-inline-styles
 *     patterns identified in the audit)
 *
 * Phase 2 will add a JS-rendered .bt-dialog overlay; this file is
 * static layout only.
 */

/* ============================================================ */
/* Buttons                                                      */
/* ============================================================ */

.bt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--bt-space-2);
  padding: var(--bt-space-3) var(--bt-space-5);
  font-family: inherit;
  font-size: var(--bt-font-size-md);
  font-weight: var(--bt-font-weight-bold);
  line-height: var(--bt-line-height-tight);
  color: var(--bt-text);
  background: var(--bt-surface-2);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-md);
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition:
    background var(--bt-transition-fast),
    border-color var(--bt-transition-fast),
    color var(--bt-transition-fast),
    box-shadow var(--bt-transition-fast);
}

.bt-btn:hover {
  background: var(--bt-surface);
  border-color: var(--bt-text-faint);
}

.bt-btn:focus-visible {
  outline: none;
  box-shadow: var(--bt-focus-ring);
}

.bt-btn:disabled,
.bt-btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Variants --- */

.bt-btn-primary {
  color: var(--bt-accent-fg);
  background: var(--bt-accent);
  border-color: var(--bt-accent);
}
.bt-btn-primary:hover {
  background: var(--bt-accent-hover);
  border-color: var(--bt-accent-hover);
}

.bt-btn-danger {
  color: var(--bt-danger-fg);
  background: var(--bt-danger);
  border-color: var(--bt-danger);
}
.bt-btn-danger:hover {
  background: var(--bt-danger-hover);
  border-color: var(--bt-danger-hover);
}

.bt-btn-success {
  color: var(--bt-success-fg);
  background: var(--bt-success);
  border-color: var(--bt-success);
}
.bt-btn-success:hover {
  background: var(--bt-success-hover);
  border-color: var(--bt-success-hover);
}

.bt-btn-warning {
  color: var(--bt-warning-fg);
  background: var(--bt-warning);
  border-color: var(--bt-warning);
}
.bt-btn-warning:hover {
  background: var(--bt-warning-hover);
  border-color: var(--bt-warning-hover);
}

.bt-btn-ghost {
  color: var(--bt-text);
  background: transparent;
  border-color: transparent;
}
.bt-btn-ghost:hover {
  background: var(--bt-surface-2);
  border-color: var(--bt-border-soft);
}

.bt-btn-link {
  color: var(--bt-accent);
  background: transparent;
  border-color: transparent;
  padding: 0;
  text-decoration: underline;
}
.bt-btn-link:hover {
  color: var(--bt-accent-hover);
  background: transparent;
}

/* --- Sizes --- */

.bt-btn-sm {
  padding: var(--bt-space-2) var(--bt-space-3);
  font-size: var(--bt-font-size-sm);
}

.bt-btn-lg {
  padding: var(--bt-space-4) var(--bt-space-6);
  font-size: var(--bt-font-size-lg);
}

/* --- Block layout helper --- */

.bt-btn-block {
  width: 100%;
}

/* ============================================================ */
/* Form fields                                                  */
/* ============================================================ */

/* The HTML ``hidden`` attribute should always win over any
 * bt-* component's display rule. Without this, ``<div class="bt-field"
 * hidden>`` still renders because ``.bt-field { display: flex }``
 * outweighs the user-agent ``[hidden] { display: none }`` default.
 * ``!important`` is the canonical pattern (used by Tailwind, GOV.UK,
 * etc.) -- the alternative is plumbing per-class hidden rules into
 * every utility. */
[hidden] {
  display: none !important;
}

.bt-field {
  display: flex;
  flex-direction: column;
  gap: var(--bt-space-2);
}

.bt-label {
  font-size: var(--bt-font-size-sm);
  font-weight: var(--bt-font-weight-bold);
  color: var(--bt-text);
}

.bt-input,
.bt-select,
.bt-textarea {
  display: block;
  width: 100%;
  padding: var(--bt-space-3) var(--bt-space-4);
  font-family: inherit;
  font-size: var(--bt-font-size-md);
  line-height: var(--bt-line-height-normal);
  color: var(--bt-text);
  background: var(--bt-surface);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-sm);
  transition:
    border-color var(--bt-transition-fast),
    box-shadow var(--bt-transition-fast);
}

.bt-input::placeholder,
.bt-textarea::placeholder {
  color: var(--bt-text-faint);
}

.bt-input:focus,
.bt-select:focus,
.bt-textarea:focus {
  outline: none;
  border-color: var(--bt-accent);
  box-shadow: var(--bt-focus-ring);
}

.bt-input:disabled,
.bt-select:disabled,
.bt-textarea:disabled {
  background: var(--bt-surface-2);
  color: var(--bt-text-muted);
  cursor: not-allowed;
}

.bt-input.is-error,
.bt-select.is-error,
.bt-textarea.is-error {
  border-color: var(--bt-danger);
}

.bt-textarea {
  min-height: 80px;
  resize: vertical;
}

.bt-help-text {
  font-size: var(--bt-font-size-sm);
  color: var(--bt-text-muted);
}

.bt-error-text {
  font-size: var(--bt-font-size-sm);
  color: var(--bt-danger);
}

/* Checkbox + radio: minimal styling, native a11y semantics. */

.bt-check {
  display: inline-flex;
  align-items: center;
  gap: var(--bt-space-2);
  font-size: var(--bt-font-size-md);
  color: var(--bt-text);
  cursor: pointer;
}

.bt-check input[type="checkbox"],
.bt-check input[type="radio"] {
  accent-color: var(--bt-accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ============================================================ */
/* Dialogs (visual layer only -- BT.dialog ships in Phase 2)   */
/* ============================================================ */

.bt-dialog {
  display: flex;
  flex-direction: column;
  background: var(--bt-surface);
  color: var(--bt-text);
  border-radius: var(--bt-radius-lg);
  box-shadow: var(--bt-shadow-modal);
  overflow: hidden;
  max-width: 90vw;
  max-height: 90vh;
  /* Native <dialog> element resets: it ships with a default
     border, padding, and white background that fights our tokens. */
  padding: 0;
  border: none;
  color: var(--bt-text);
}

/* Native <dialog>::backdrop tinting. When BT.dialog calls
   showModal() the browser supplies a default semi-transparent
   backdrop that doesn't honour our --bt-overlay-scrim token. */
.bt-dialog::backdrop {
  background: var(--bt-overlay-scrim);
}

/* Size variants used by BT.dialog. */
.bt-dialog-sm { width: 360px; }
.bt-dialog-md { width: 520px; }
.bt-dialog-lg { width: 720px; }

.bt-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bt-space-4);
  padding: var(--bt-space-4) var(--bt-space-5);
  background: var(--bt-accent);
  color: var(--bt-accent-fg);
  border-bottom: 1px solid var(--bt-border);
}

/* For destructive/sensitive dialogs (e.g. wallet keys export, account
   deletion). Distinct from is-warning -- danger is "irreversible";
   warning would be "cautionary but recoverable." */
.bt-dialog-header.is-danger {
  background: var(--bt-danger);
}

.bt-dialog-header.is-warning {
  background: var(--bt-warning);
  color: var(--bt-warning-fg);
}
.bt-dialog-header.is-warning .bt-dialog-close {
  color: var(--bt-warning-fg);
}

.bt-dialog-title {
  margin: 0;
  font-size: var(--bt-font-size-xl);
  font-weight: var(--bt-font-weight-bold);
  line-height: var(--bt-line-height-tight);
}

.bt-dialog-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: var(--bt-font-size-lg);
  line-height: 1;
  color: var(--bt-accent-fg);
  background: var(--bt-overlay-soft);
  border: none;
  border-radius: var(--bt-radius-pill);
  cursor: pointer;
  transition: background var(--bt-transition-fast);
}

.bt-dialog-close:hover {
  background: var(--bt-overlay-strong);
}

.bt-dialog-body {
  flex: 1 1 auto;
  padding: var(--bt-space-5);
  overflow: auto;
}

.bt-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--bt-space-3);
  padding: var(--bt-space-4) var(--bt-space-5);
  background: var(--bt-surface-2);
  border-top: 1px solid var(--bt-border);
}

/* Mobile: fill viewport, stack footer buttons. */
@media (max-width: 480px) {
  .bt-dialog {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: var(--bt-radius-none);
  }
  .bt-dialog-footer {
    flex-direction: column-reverse;
  }
  .bt-dialog-footer .bt-btn {
    width: 100%;
  }
}

/* ============================================================ */
/* Cards + toolbar (static container; not the floating panel)   */
/* ============================================================ */
/*
 * .bt-card is the static "labelled box with header" used for HUDs
 * and grouped content. The floating-panel primitive (BT.panel,
 * draggable+resizable) is below under "Panels (floating)" -- they
 * are different concerns and use different classes.
 */

.bt-card {
  background: var(--bt-surface);
  color: var(--bt-text);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-md);
  box-shadow: var(--bt-shadow-sm);
}

.bt-card-header {
  padding: var(--bt-space-3) var(--bt-space-4);
  font-size: var(--bt-font-size-sm);
  font-weight: var(--bt-font-weight-bold);
  color: var(--bt-text-strong);
  background: var(--bt-surface-2);
  border-bottom: 1px solid var(--bt-border);
  border-top-left-radius: var(--bt-radius-md);
  border-top-right-radius: var(--bt-radius-md);
}

.bt-card-body {
  padding: var(--bt-space-4);
}

/* Card status variants: tinted background + border in the relevant
   palette. Used to telegraph risk/state on grouped sections (e.g.
   the Increase / Reduce / Add / Remove tabs in edit_position_dialog,
   which were color-coded in the legacy template). The bt-card
   border is the source of truth; the tint is a soft surface. */
.bt-card.is-info {
  background: var(--bt-info-soft);
  border-color: var(--bt-info);
}
.bt-card.is-success {
  background: var(--bt-success-soft);
  border-color: var(--bt-success);
}
.bt-card.is-warning {
  background: var(--bt-warning-soft);
  border-color: var(--bt-warning);
}
.bt-card.is-danger {
  background: var(--bt-danger-soft);
  border-color: var(--bt-danger);
}

.bt-toolbar {
  display: flex;
  align-items: center;
  gap: var(--bt-space-3);
  padding: var(--bt-space-3) var(--bt-space-4);
  background: var(--bt-surface-2);
  border-bottom: 1px solid var(--bt-border);
}

/* ============================================================ */
/* Panels (floating, draggable, resizable)                      */
/* ============================================================ */
/*
 * Rendered output of BT.panel.open(). Replaces the legacy
 * .form-popup pattern. Position/size controlled by inline left/top/
 * width/height set by the JS primitive (the only inline styles
 * BT.panel.open emits, since by definition each panel's geometry is
 * unique). All other styling is token-driven.
 *
 * Reuses .bt-dialog-header / -body / -footer / -close content
 * classes, so dialogs and panels share theming + density behavior.
 */

.bt-panel {
  display: flex;
  flex-direction: column;
  position: fixed;
  background: var(--bt-surface);
  color: var(--bt-text);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-lg);
  box-shadow: var(--bt-shadow-modal);
  overflow: hidden;
  /* Force border-box so width/height set inline by BT.panel
     include the 1px border on each side. base.css applies
     ``* { box-sizing: border-box }`` globally, but bt-* primitives
     can render on pages that don't load the legacy stylesheet
     (e.g. /admin/ui-preview), so set it explicitly here. */
  box-sizing: border-box;
  /* z-index is set inline by BT.panel.bringToFront() so multiple
     panels stack predictably. The base value sits between sticky
     (200) and modal-backdrop (1000). */
  z-index: 600;
}
.bt-panel *,
.bt-panel *::before,
.bt-panel *::after {
  box-sizing: border-box;
}

/* The header is the drag affordance when .is-draggable is set
   (BT.panel always adds this when draggable!==false). Cursor cue
   only applies on the empty header surface; interactive children
   (close button, future toolbar buttons) reset to pointer below. */
.bt-panel .bt-dialog-header.is-draggable {
  cursor: move;
  user-select: none;
}
.bt-panel .bt-dialog-header.is-draggable button,
.bt-panel .bt-dialog-header.is-draggable a,
.bt-panel .bt-dialog-header.is-draggable input,
.bt-panel .bt-dialog-header.is-draggable select {
  cursor: pointer;
  user-select: auto;
}

/* Body fills remaining vertical space and scrolls. */
.bt-panel .bt-dialog-body {
  flex: 1 1 auto;
  overflow: auto;
}

/* Bottom-right resize grip. Uses corner gradient to suggest
   resizability without a graphical asset. Hidden when the caller
   passes resizable:false. */
.bt-panel-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: se-resize;
  background:
    linear-gradient(
      135deg,
      transparent 0,
      transparent 50%,
      var(--bt-text-faint) 50%,
      var(--bt-text-faint) 60%,
      transparent 60%,
      transparent 70%,
      var(--bt-text-faint) 70%,
      var(--bt-text-faint) 80%,
      transparent 80%
    );
  z-index: 1;
}

.bt-panel[data-resizable="false"] .bt-panel-resize {
  display: none;
}

/* Mobile: panels go fullscreen-ish; drag/resize make less sense. */
@media (max-width: 480px) {
  .bt-panel {
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    border-radius: var(--bt-radius-none);
  }
  .bt-panel-resize {
    display: none;
  }
}

/* ============================================================ */
/* Tabs                                                         */
/* ============================================================ */

.bt-tabs {
  display: flex;
  gap: var(--bt-space-2);
  border-bottom: 1px solid var(--bt-border);
}

.bt-tab {
  display: inline-flex;
  align-items: center;
  padding: var(--bt-space-3) var(--bt-space-5);
  font-family: inherit;
  font-size: var(--bt-font-size-md);
  color: var(--bt-text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition:
    color var(--bt-transition-fast),
    border-color var(--bt-transition-fast);
}

.bt-tab:hover {
  color: var(--bt-text);
}

.bt-tab.is-active {
  color: var(--bt-accent);
  border-bottom-color: var(--bt-accent);
}

.bt-tab:focus-visible {
  outline: none;
  box-shadow: var(--bt-focus-ring);
  border-radius: var(--bt-radius-sm);
}

/* Tab content panel. Visibility is driven by the HTML ``hidden``
 * attribute (toggled by JS); the global ``[hidden] { display: none
 * !important }`` rule earlier in this file beats the panel's own
 * display, so callers just flip ``el.hidden = true|false``. */
.bt-tab-panel {
  display: block;
}

/* ============================================================ */
/* Menus                                                        */
/* ============================================================ */

.bt-menu {
  display: flex;
  flex-direction: column;
  min-width: 160px;
  padding: var(--bt-space-2);
  background: var(--bt-surface);
  color: var(--bt-text);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-md);
  box-shadow: var(--bt-shadow-md);
  z-index: var(--bt-z-dropdown);
}

.bt-menu-item {
  display: flex;
  align-items: center;
  gap: var(--bt-space-2);
  padding: var(--bt-space-2) var(--bt-space-4);
  font-size: var(--bt-font-size-md);
  color: var(--bt-text);
  background: transparent;
  border: none;
  border-radius: var(--bt-radius-sm);
  cursor: pointer;
  text-align: left;
  text-decoration: none;
}

.bt-menu-item:hover {
  background: var(--bt-surface-2);
}

.bt-menu-item.is-active {
  color: var(--bt-accent);
  background: var(--bt-accent-soft);
}

.bt-menu-item.is-danger {
  color: var(--bt-danger);
}
.bt-menu-item.is-danger:hover {
  background: var(--bt-danger-soft);
}

.bt-menu-divider {
  height: 1px;
  margin: var(--bt-space-1) var(--bt-space-2);
  background: var(--bt-border-soft);
}

/* ============================================================ */
/* Layout helpers                                               */
/* ============================================================ */
/* These are the audit's "80% of inline styles" patterns: vertical
   stacks with rhythm, horizontal clusters with gap. They cover
   the bulk of old inline margin/flex/gap snippets
   churn without forcing every site into a real component. */

.bt-stack {
  display: flex;
  flex-direction: column;
  gap: var(--bt-space-3);
}
.bt-stack-sm { gap: var(--bt-space-2); }
.bt-stack-lg { gap: var(--bt-space-5); }

.bt-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--bt-space-3);
}
.bt-cluster-sm { gap: var(--bt-space-2); }
.bt-cluster-lg { gap: var(--bt-space-5); }

.bt-cluster-end {
  justify-content: flex-end;
}

.bt-grow { flex: 1 1 auto; }
.bt-shrink-0 { flex-shrink: 0; }
.bt-hidden-root { display: none; }
.bt-block { display: block; }
.bt-inline-block { display: inline-block; }
.bt-contents { display: contents; }
.bt-relative { position: relative; }
.bt-clickable { cursor: pointer; }
.bt-center { margin-left: auto; margin-right: auto; }
.bt-nowrap { white-space: nowrap; }
.bt-break-all { word-break: break-all; }
.bt-scroll-y { overflow-y: auto; }
.bt-scroll-x { overflow-x: auto; }

.bt-align-start { align-items: flex-start; }
.bt-align-center { align-items: center; }
.bt-align-end { align-items: flex-end; }
.bt-self-end { align-self: flex-end; }
.bt-justify-between { justify-content: space-between; }
.bt-justify-center { justify-content: center; }

.bt-m-0 { margin: 0; }
.bt-mt-1 { margin-top: var(--bt-space-1); }
.bt-mt-2 { margin-top: var(--bt-space-2); }
.bt-mt-3 { margin-top: var(--bt-space-3); }
.bt-mt-4 { margin-top: var(--bt-space-4); }
.bt-mt-5 { margin-top: var(--bt-space-5); }
.bt-mb-0 { margin-bottom: 0; }
.bt-mb-2 { margin-bottom: var(--bt-space-2); }
.bt-mb-3 { margin-bottom: var(--bt-space-3); }
.bt-mb-4 { margin-bottom: var(--bt-space-4); }
.bt-ml-2 { margin-left: var(--bt-space-2); }
.bt-ml-3 { margin-left: var(--bt-space-3); }
.bt-pl-5 { padding-left: var(--bt-space-5); }
.bt-ol-compact { margin: var(--bt-space-2) 0 var(--bt-space-2) var(--bt-space-5); padding: 0; }
.bt-p-0 { padding: 0; }
.bt-p-3 { padding: var(--bt-space-3); }
.bt-p-4 { padding: var(--bt-space-4); }
.bt-p-5 { padding: var(--bt-space-5); }
.bt-p-6 { padding: var(--bt-space-6); }
.bt-pt-3 { padding-top: var(--bt-space-3); }
.bt-pb-2 { padding-bottom: var(--bt-space-2); }

.bt-w-xs { width: 80px; }
.bt-w-full { width: 100%; }
.bt-w-sm { width: 160px; }
.bt-w-md { width: 200px; }
.bt-h-blockly { height: 300px; }
.bt-max-xs { max-width: 80px; }
.bt-max-sm { max-width: 100px; }
.bt-max-input { max-width: 140px; }
.bt-max-md { max-width: 160px; }
.bt-max-lg { max-width: 520px; }
.bt-min-status { min-height: 14px; }
.bt-max-list { max-height: 150px; }

.bt-border-top {
  border-top: 1px solid var(--bt-border);
}

.bt-rule {
  border: 0;
  border-top: 1px solid var(--bt-border);
  margin: 0;
}

.bt-line-relaxed {
  line-height: 1.6;
}

.bt-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--bt-space-3);
}

.bt-grid-prop-editor {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: var(--bt-space-3);
  align-items: end;
}

.bt-label-normal {
  font-weight: normal;
}

.bt-inline-spinner {
  display: inline-block;
  vertical-align: middle;
  margin-right: var(--bt-space-2);
}

.bt-code-block {
  display: block;
  padding: var(--bt-space-3);
  overflow: auto;
}

.bt-help-panel {
  display: none;
  padding: var(--bt-space-3);
  background: var(--bt-info-soft);
  border-radius: var(--bt-radius-md);
  border: 1px solid var(--bt-border);
  line-height: 1.6;
  color: var(--bt-text);
}

.bt-status-box {
  display: none;
  padding: var(--bt-space-3);
  margin-top: var(--bt-space-3);
  border-radius: var(--bt-radius-sm);
}

.backtest-chart {
  width: 100%;
  height: 300px;
}

.backtest-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.backtest-stat-item {
  flex: 1 1 30%;
  padding: var(--bt-space-3);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-sm);
}

.backtest-scroll {
  max-height: 200px;
  overflow-y: auto;
}

.backtest-quality {
  border: 2px solid var(--bt-warning);
  background: var(--bt-warning-soft);
  padding: 10px;
  margin: 10px 0;
  border-radius: var(--bt-radius-sm);
}

.backtest-quality.is-severe {
  border-color: var(--bt-danger);
}

.backtest-quality h4 {
  margin-top: 0;
  color: var(--bt-warning);
}

.backtest-quality.is-severe h4 {
  color: var(--bt-danger);
}

.backtest-quality p {
  margin: 4px 0;
}

.backtest-quality ul {
  margin: 4px 0 0 20px;
}

.indicator-legend-value {
  color: var(--bt-info);
}

.indicator-update-card {
  background: var(--bt-surface);
  padding: 20px 40px;
  border-radius: var(--bt-radius-lg);
  font-size: 18px;
  font-weight: bold;
}

.bt-tooltip-title {
  font-weight: var(--bt-font-weight-bold);
  margin-bottom: var(--bt-space-2);
}

.bt-tooltip-desc {
  font-size: var(--bt-font-size-md);
  margin-bottom: var(--bt-space-3);
}

.bt-dd {
  margin: 0;
}

.bt-toolbar-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--bt-space-1);
}

.bt-toolbar-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--bt-space-3);
  padding: 0 var(--bt-space-2);
}

.bt-icon-lg {
  font-size: var(--bt-font-size-xl);
}

.bt-icon-md {
  font-size: var(--bt-font-size-lg);
}

.bt-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--bt-radius-pill);
  object-fit: cover;
}

.bt-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--bt-accent-fg);
  font-size: var(--bt-font-size-xl);
  font-weight: var(--bt-font-weight-bold);
  background: var(--bt-accent);
  border-radius: var(--bt-radius-pill);
}

.bt-risk-overlay {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: var(--bt-overlay-scrim);
  z-index: var(--bt-z-modal);
}

.bt-risk-card {
  width: 90%;
  max-width: 520px;
  margin: var(--bt-space-5);
  padding: var(--bt-space-6);
  border: 2px solid var(--bt-danger);
}

.bt-risk-checkbox {
  align-self: flex-start;
  margin-top: 3px;
  width: 18px;
  height: 18px;
}

.bt-risk-icon {
  font-size: var(--bt-font-size-2xl);
}

.bt-close-confirm-details {
  color: var(--bt-text);
  line-height: 1.8;
  margin-bottom: var(--bt-space-5);
}

.bt-position-product {
  color: var(--bt-warning);
}

.bt-position-product.is-futures {
  color: var(--bt-danger);
}

.health-bar.is-success { background: var(--bt-success); }
.health-bar.is-warning { background: var(--bt-warning); }
.health-bar.is-danger { background: var(--bt-danger); }

.bt-inline-stat {
  display: inline-flex;
  gap: var(--bt-space-1);
  align-items: baseline;
}

.bt-grid-span-2 {
  grid-column: span 2;
}

.bt-market-tabs {
  display: flex;
  gap: var(--bt-space-1);
  margin-bottom: var(--bt-space-6);
}

.bt-market-tab {
  padding: var(--bt-space-3) var(--bt-space-6);
  color: var(--bt-text-muted);
  font-size: var(--bt-font-size-lg);
  text-decoration: none;
  background: var(--bt-surface);
  border: 1px solid var(--bt-border);
  border-bottom: none;
  border-radius: var(--bt-radius-md) var(--bt-radius-md) 0 0;
}

.bt-market-tab.is-active {
  color: var(--bt-text-strong);
  background: var(--bt-surface-2);
  border-color: var(--bt-accent);
}

.bt-market-featured {
  margin-bottom: var(--bt-space-6);
}

.bt-market-featured-strip {
  display: flex;
  gap: var(--bt-space-4);
  overflow-x: auto;
}

.bt-market-creator-link {
  flex-shrink: 0;
  text-decoration: none;
}

.bt-market-creator-card {
  width: 200px;
  padding: var(--bt-space-4);
  text-align: center;
}

.bt-market-empty {
  max-width: 760px;
  margin: var(--bt-space-6) auto;
  color: var(--bt-text-muted);
  line-height: 1.6;
}

.bt-market-pagination {
  display: flex;
  justify-content: center;
  gap: var(--bt-space-3);
  margin-top: var(--bt-space-6);
}

/* ============================================================ */
/* Badge                                                        */
/* ============================================================ */

.bt-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--bt-space-1) var(--bt-space-3);
  font-size: var(--bt-font-size-xs);
  font-weight: var(--bt-font-weight-bold);
  line-height: var(--bt-line-height-tight);
  color: var(--bt-text);
  background: var(--bt-surface-2);
  border-radius: var(--bt-radius-pill);
}

.bt-badge-success {
  color: var(--bt-success-fg);
  background: var(--bt-success);
}

.bt-badge-danger {
  color: var(--bt-danger-fg);
  background: var(--bt-danger);
}

.bt-badge-warning {
  color: var(--bt-warning-fg);
  background: var(--bt-warning);
}

.bt-badge-info {
  color: var(--bt-info-fg);
  background: var(--bt-info);
}

.bt-badge-soft-success {
  color: var(--bt-success);
  background: var(--bt-success-soft);
}

.bt-badge-soft-warning {
  color: var(--bt-warning);
  background: var(--bt-warning-soft);
}

.bt-badge-soft-danger {
  color: var(--bt-danger);
  background: var(--bt-danger-soft);
}

.bt-badge-soft-info {
  color: var(--bt-info);
  background: var(--bt-info-soft);
}

.bt-badge-neutral {
  color: var(--bt-text-muted);
  background: var(--bt-surface-2);
}

.bt-badge-offset {
  margin-left: var(--bt-space-2);
}

.bt-list-item {
  padding: var(--bt-space-4);
  border-bottom: 1px solid var(--bt-border);
}

.bt-list-item.is-clickable {
  cursor: pointer;
}

.bt-list-title {
  color: var(--bt-text-strong);
  font-size: var(--bt-font-size-lg);
  font-weight: var(--bt-font-weight-bold);
}

.bt-list-meta {
  color: var(--bt-text-muted);
  font-size: var(--bt-font-size-sm);
}

.bt-list-subtitle {
  color: var(--bt-text-muted);
  font-size: var(--bt-font-size-md);
  margin-top: var(--bt-space-1);
}

.bt-list-actions {
  display: flex;
  gap: var(--bt-space-2);
  margin-top: var(--bt-space-3);
}

.bt-price {
  color: var(--bt-success);
  font-weight: var(--bt-font-weight-bold);
}

.bt-price-muted {
  color: var(--bt-text-muted);
}

.bt-market-metrics {
  display: flex;
  gap: var(--bt-space-4);
  color: var(--bt-text-muted);
  font-size: var(--bt-font-size-sm);
  margin-top: var(--bt-space-3);
}

/* ============================================================ */
/* Text utilities (limited, intentional)                        */
/* ============================================================ */

.bt-text-muted   { color: var(--bt-text-muted); }
.bt-text-faint   { color: var(--bt-text-faint); }
.bt-text-strong  { color: var(--bt-text-strong); font-weight: var(--bt-font-weight-bold); }
.bt-text-success { color: var(--bt-success); }
.bt-text-danger  { color: var(--bt-danger); }
.bt-text-warning { color: var(--bt-warning); }
.bt-text-center  { text-align: center; }
.bt-text-right   { text-align: right; }
.bt-text-mono    { font-family: var(--bt-font-mono); }
.bt-text-italic  { font-style: italic; }

.bt-divider-label {
  color: var(--bt-accent);
  font-weight: var(--bt-font-weight-bold);
  text-align: center;
}

.bt-condition-line {
  margin: var(--bt-space-1) 0;
}

.bt-preview-pre {
  display: block;
  max-height: 120px;
  margin-top: var(--bt-space-2);
  padding: var(--bt-space-3);
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ============================================================
 * Spinner (loading indicator)
 * ============================================================ */
.bt-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--bt-border);
  border-top-color: var(--bt-accent);
  border-radius: 50%;
  animation: bt-spin 1s linear infinite;
}
.bt-spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.bt-spinner-lg { width: 48px; height: 48px; border-width: 4px; }

@keyframes bt-spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============================================================
 * Fieldset (replaces inline-styled <fieldset> in legacy forms)
 * ============================================================ */
.bt-fieldset {
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-sm);
  padding: var(--bt-space-3);
  margin: 0;
}
.bt-legend {
  color: var(--bt-text-muted);
  font-size: var(--bt-font-size-xs);
  font-weight: var(--bt-font-weight-bold);
  letter-spacing: 0.04em;
  padding: 0 var(--bt-space-2);
  text-transform: uppercase;
}

/* ============================================================
 * Two-column layout (.bt-row, .bt-row-2)
 *
 * Equal-width columns with token-driven gap. .bt-row-2 forces
 * two columns; .bt-row leaves the count to flex children using
 * `flex: 1`. Collapses to a single column under 600px viewport.
 * ============================================================ */
.bt-row {
  display: flex;
  gap: var(--bt-space-3);
}
.bt-row > * {
  flex: 1;
  min-width: 0;
}
.bt-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--bt-space-3);
}
@media (max-width: 600px) {
  .bt-row,
  .bt-row-2 {
    grid-template-columns: 1fr;
    flex-direction: column;
  }
}

/* ============================================================
 * Alerts / inline status banners
 *
 * Used for "test connection succeeded" / "save failed" inline
 * banners. Variants follow the status palette in tokens.css.
 * Display is left to the caller (often toggled via JS) so this
 * does not assume `display: block`.
 * ============================================================ */
.bt-alert {
  padding: var(--bt-space-3);
  border-radius: var(--bt-radius-sm);
  border: 1px solid transparent;
  font-size: var(--bt-font-size-sm);
}
.bt-alert.is-success {
  background: var(--bt-success-soft);
  border-color: var(--bt-success);
  color: var(--bt-success);
}
.bt-alert.is-danger {
  background: var(--bt-danger-soft);
  border-color: var(--bt-danger);
  color: var(--bt-danger);
}
.bt-alert.is-warning {
  background: var(--bt-warning-soft);
  border-color: var(--bt-warning);
  color: var(--bt-warning-fg);
}
.bt-alert.is-info {
  background: var(--bt-info-soft);
  border-color: var(--bt-info);
  color: var(--bt-info);
}

/* ============================================================
 * Inline <code> within bt-* forms
 *
 * Tokenised replacement for the per-template ``<code>`` styling
 * that was duplicated across half a dozen legacy forms.
 * ============================================================ */
.bt-code {
  background: var(--bt-surface-2);
  color: var(--bt-text-strong);
  padding: var(--bt-space-1) var(--bt-space-2);
  border-radius: var(--bt-radius-sm);
  font-family: var(--bt-font-mono);
  font-size: var(--bt-font-size-xs);
}

/* ============================================================
 * Tabs (.bt-tabs / .bt-tab / .is-active)
 *
 * Generic horizontal tab bar. The active tab is marked with the
 * ``is-active`` modifier (not a separate class) so JS toggling
 * stays consistent with the rest of the bt-* primitives.
 * ============================================================ */
.bt-tabs {
  display: flex;
  gap: var(--bt-space-1);
  border-bottom: 1px solid var(--bt-border);
  margin-bottom: var(--bt-space-3);
  flex-wrap: wrap;
}
.bt-tab {
  padding: var(--bt-space-3) var(--bt-space-4);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--bt-radius-sm) var(--bt-radius-sm) 0 0;
  color: var(--bt-text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--bt-font-size-sm);
  font-weight: var(--bt-font-weight-bold);
  margin-bottom: -1px;
}
.bt-tab:hover {
  color: var(--bt-text);
  background: var(--bt-surface-2);
}
.bt-tab.is-active {
  color: var(--bt-accent);
  background: var(--bt-surface);
  border-color: var(--bt-border);
  border-bottom-color: var(--bt-surface);
}
.bt-tab-panel {
  padding-top: var(--bt-space-3);
}

/* ============================================================
 * Progress bar
 * ============================================================ */
.bt-progress {
  width: 100%;
  height: 20px;
  background: var(--bt-surface-2);
  border-radius: var(--bt-radius-sm);
  overflow: hidden;
}
.bt-progress-bar {
  width: 0%;
  height: 100%;
  background: var(--bt-accent);
  color: var(--bt-accent-fg);
  text-align: center;
  font-size: var(--bt-font-size-xs);
  line-height: 20px;
  transition: width 0.2s ease;
}
.bt-progress-bar.is-success { background: var(--bt-success); color: var(--bt-success-fg); }
.bt-progress-bar.is-danger  { background: var(--bt-danger);  color: var(--bt-danger-fg); }

/* ============================================================
 * Repeater rows (e.g. external-indicator outputs)
 *
 * Rows of "label + N inputs + remove button" added/removed
 * dynamically by JS. Layout token-driven; remove button uses
 * the danger palette.
 * ============================================================ */
.bt-repeater {
  display: flex;
  flex-direction: column;
  gap: var(--bt-space-2);
}
.bt-repeater-row {
  display: flex;
  gap: var(--bt-space-2);
  align-items: center;
  padding: var(--bt-space-2);
  background: var(--bt-surface-2);
  border-radius: var(--bt-radius-sm);
}
.bt-repeater-row > input,
.bt-repeater-row > select {
  flex: 1;
  min-width: 0;
}
.bt-repeater-row .bt-repeater-handle {
  flex: 0 0 100px;
}
.bt-repeater-remove {
  background: var(--bt-danger);
  color: var(--bt-danger-fg);
  border: none;
  border-radius: var(--bt-radius-sm);
  padding: var(--bt-space-1) var(--bt-space-3);
  cursor: pointer;
  font-size: var(--bt-font-size-sm);
}
.bt-repeater-remove:hover {
  background: var(--bt-danger-hover);
}

/* ============================================================
 * Summary grid -- 2-column key/value display
 *
 * Used inside ``.bt-card-body`` for "Current Position" /
 * "Projected After X" panels: pairs of label + value rendered
 * by JS as ``<div>label: value</div>`` items. Two columns of
 * equal width, small gap, slightly compact font. Items can
 * span both columns with ``bt-span-2``.
 * ============================================================ */
.bt-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--bt-space-2);
  font-size: var(--bt-font-size-sm);
}

/* ============================================================
 * Tag pill (toggleable selection chip)
 *
 * Used for the builder-profile "trading focus" tag selector. The
 * default state is muted; ``.is-active`` (or the legacy ``.active``
 * class kept for backwards-compat with template-side classlist
 * toggles) flips to the accent palette.
 * ============================================================ */
.bt-tag-pill {
  padding: var(--bt-space-1) var(--bt-space-3);
  font-size: var(--bt-font-size-xs);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-pill);
  background: var(--bt-surface-2);
  color: var(--bt-text-muted);
  cursor: pointer;
  transition:
    background var(--bt-transition-fast),
    color var(--bt-transition-fast),
    border-color var(--bt-transition-fast);
}
.bt-tag-pill:hover {
  border-color: var(--bt-accent);
  color: var(--bt-text);
}
.bt-tag-pill.is-active,
.bt-tag-pill.active {
  background: var(--bt-accent);
  color: var(--bt-accent-fg);
  border-color: var(--bt-accent);
}

/* ============================================================
 * Theme preview tile
 *
 * A self-contained block of bt-* markup used inside the account
 * settings theme tab so users can see what their theme settings
 * look like on a panel/buttons/input/alert without having to
 * navigate around the app. Inherits the global theme by default;
 * the accent picker re-applies its draft value to ``--bt-accent``
 * on this element only so the preview re-skins in real time
 * before the user clicks Save.
 * ============================================================ */
.theme-preview-tile {
  width: 100%;
  /* Slight inset so the card sits on a faint border, not the
     fieldset edge. */
  padding: var(--bt-space-3) 0;
}

.theme-preview-tile .theme-preview-card {
  background: var(--bt-surface);
  border: 1px solid var(--bt-border);
  border-radius: var(--bt-radius-md);
  overflow: hidden;
  box-shadow: var(--bt-shadow-sm);
}

.theme-preview-tile .theme-preview-header {
  background: var(--bt-accent);
  color: var(--bt-accent-fg);
  padding: var(--bt-space-3) var(--bt-space-4);
  font-weight: var(--bt-font-weight-bold);
}

.theme-preview-tile .theme-preview-body {
  padding: var(--bt-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--bt-space-3);
}

.theme-preview-tile .theme-preview-text {
  margin: 0;
  color: var(--bt-text);
  font-size: var(--bt-font-size-md);
}
