/* The Backtester screen (spec 0149 D-12 – D-14): full screen over the dashboard, in its theme. */
.bt { position: fixed; inset: 0; z-index: 990; display: flex; flex-direction: column; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: 13px; }
.bt[hidden] { display: none; }
.bt-top { display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--surface); }
.bt-top h1 { margin: 0; font-size: 16px; font-family: var(--font-display); letter-spacing: 0.3px; }
.bt-sub { color: var(--text-muted); font-size: 12px; }
.bt-close { margin-left: auto; background: transparent; border: 1px solid var(--border); color: var(--text-secondary); border-radius: 6px;
  width: 28px; height: 28px; font-size: 18px; line-height: 1; cursor: pointer; flex: none; }
.bt-close:hover { border-color: var(--border-hover); color: var(--text); }
.bt-body { flex: 1; overflow: auto; display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; padding: 16px 18px; align-items: start; }

.bt-form { display: flex; flex-direction: column; gap: 12px; }
.bt-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.bt-grow { flex: 1 1 100%; }
.bt-group { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 12px; margin: 0; background: var(--surface);
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bt-group legend { padding: 0 6px; font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.6px; }
.bt-span { grid-column: 1 / -1; }
.bt-f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.bt-f > span:first-child { font-size: 11.5px; color: var(--text-muted); }
.bt-f input, .bt-f select { width: 100%; box-sizing: border-box; background: var(--elevated); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font: inherit; min-width: 0; }
.bt-f input:focus, .bt-f select:focus { outline: none; border-color: var(--accent-blue); }
.bt-in { position: relative; display: flex; align-items: center; }
.bt-in i { position: absolute; font-style: normal; color: var(--text-muted); pointer-events: none; font-size: 12px; }
.bt-in i:first-child { left: 8px; }
.bt-in i:last-child:not(:first-child) { right: 8px; }
.bt-in i:first-child + input { padding-left: 18px; }
.bt-in input:has(+ i) { padding-right: 22px; }
.bt-wallet input[data-k="wallet"] { font-family: var(--font-mono); font-size: 12px; }
.bt-wallet .bt-f:not(.bt-grow) { flex: 1; }
.bt-run { background: var(--accent-blue); color: #fff; border: 0; border-radius: 6px; padding: 7px 18px; font: inherit; font-weight: 600; cursor: pointer; }
.bt-run:hover { filter: brightness(1.1); }

.bt-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.bt-msg { margin: 0; padding: 28px 16px; text-align: center; color: var(--text-secondary); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.bt-err { color: var(--accent-red, #e5534b); }
.bt-results { display: flex; flex-direction: column; gap: 14px; }
.bt-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; }
.bt-card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.bt-card h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.6px; }
.bt-legend { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-muted); }

.bt-hero { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; }
.bt-hero-lbl { font-size: 14px; color: var(--text-secondary); }
.bt-hero-lbl b { color: var(--text); }
.bt-hero-sub { margin-top: 10px; color: var(--text-muted); }
.bt-hero-val { display: flex; align-items: center; gap: 12px; font-size: 40px; font-weight: 700; line-height: 1.15; color: var(--accent-green, #4cc274);
  font-variant-numeric: tabular-nums; }
.bt-hero-val.bt-neg { color: var(--accent-red, #e5534b); }
.bt-pill { font-size: 15px; font-weight: 600; padding: 4px 10px; border-radius: 6px; background: color-mix(in srgb, currentColor 14%, transparent); }
.bt-hero-foot { color: var(--text-secondary); margin-top: 4px; }
.bt-hero-none p { margin: 6px 0 0; color: var(--text-secondary); }
.bt-gold { color: #f2c94c; font-weight: 600; }
.bt-pos { color: var(--accent-green, #4cc274); }
.bt-neg { color: var(--accent-red, #e5534b); }

.bt-chart { width: 100%; height: auto; display: block; }
.bt-grid { stroke: var(--border); stroke-width: 1; }
.bt-base { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.7; }
/* D-34: the site's chart rules: 12 px labels in the secondary colour, axis titles, a translucent grid both ways. */
.bt-ax { fill: var(--text-secondary); font-size: 12px; font-family: var(--font-sans); font-variant-numeric: tabular-nums; }
.bt-ax-title { fill: var(--text-secondary); font-size: 12px; font-family: var(--font-sans); }
.bt-grid-v { opacity: 0.35; }
.bt-line { fill: none; stroke: var(--text-muted); stroke-width: 1.4; opacity: 0.55; stroke-linejoin: round; }
.bt-line:hover { opacity: 1; stroke-width: 2.2; }
.bt-best { fill: none; stroke-width: 2.6; stroke-linejoin: round; }
.bt-sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; background: var(--text-muted); opacity: 0.7; margin-right: 8px; vertical-align: middle; }
.bt-sw-gold { background: #f2c94c; opacity: 1; }

.bt-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.bt-table th { text-align: left; font-weight: 500; font-size: 11.5px; color: var(--text-muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.bt-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.bt-table tbody tr:last-child td { border-bottom: 0; }
.bt-num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
th.bt-num { font-family: var(--font-sans); }
.bt-best-row td { background: color-mix(in srgb, #f2c94c 9%, transparent); }
.bt-over td { color: var(--text-secondary); }
.bt-tag { margin-left: 6px; font-size: 10.5px; font-weight: 600; color: #f2c94c; border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; }
.bt-tag-over { color: var(--text-muted); }
.bt-meta { margin: 0; color: var(--text-muted); font-size: 12px; }
.bt-notes { margin: 0; padding-left: 18px; color: var(--text-secondary); font-size: 12px; line-height: 1.55; }

@media (max-width: 860px) {
  .bt-body { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; }
  .bt-sub { display: none; }
  .bt-hero-val { font-size: 32px; }
}

/* Review fixes (spec 0149 D-18 – D-26). */
.bt-hint { margin: 0; color: var(--text-muted); font-size: 11.5px; line-height: 1.5; }
.bt-hero-when { margin-top: 4px; color: var(--text-muted); font-size: 12px; }
.bt-hero-self { margin-top: 8px; color: var(--text-secondary); font-size: 12.5px; }
.bt-warn { color: #f2c94c; }
.bt-tag-low { color: #f2c94c; font-size: 11px; align-self: center; }
.bt-low { color: #f2c94c; }
.bt-split { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 2 4; }
.bt-self { fill: none; stroke-width: 1.8; stroke-dasharray: 6 4; opacity: 0.9; }
.bt-sw-blue { background: #5aa9ff; opacity: 1; }
.bt-self-row td { color: var(--text-secondary); }
.bt-none-row td { color: var(--text-muted); }
.bt-muted { color: var(--text-muted); white-space: normal; }
.bt-line { opacity: 0.35; stroke-width: 1.1; }

/* Categories and portfolios (spec 0149 D-28 – D-33). */
.bt-tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; flex: none; }
.bt-tabs button { background: transparent; color: var(--text-secondary); border: 0; padding: 4px 12px; font: inherit; cursor: pointer; }
.bt-tabs button + button { border-left: 1px solid var(--border); }
.bt-tabs button[aria-selected="true"] { background: var(--accent-blue-dim); color: var(--accent-blue); font-weight: 600; }
.bt-count { display: inline-block; min-width: 16px; padding: 0 4px; border-radius: 8px; background: var(--elevated); font-size: 11px; text-align: center; }
.bt-cats input { accent-color: #f2c94c; cursor: pointer; }
.bt-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.bt-btn { background: var(--elevated); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px; font: inherit; cursor: pointer; }
.bt-btn:hover { border-color: var(--border-hover); }
.bt-btn-gold { border-color: #f2c94c; color: #f2c94c; font-weight: 600; }
.bt-added { color: var(--text-muted); font-size: 12px; }
.bt-sleeves { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.bt-sleeves li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--elevated); }
.bt-x { background: transparent; border: 0; color: var(--text-muted); font-size: 16px; line-height: 1; cursor: pointer; }
.bt-x:hover { color: var(--text); }
.bt-status { display: flex; flex-direction: column; gap: 14px; }

/* Markets in each category (spec 0149 D-35). */
.bt-open { background: transparent; border: 0; color: var(--text); font: inherit; padding: 0; cursor: pointer; text-align: left; }
.bt-open:hover { color: var(--accent-blue); }
.bt-mkt td { font-size: 12px; color: var(--text-secondary); background: color-mix(in srgb, var(--elevated) 45%, transparent); }
.bt-mkt td:nth-child(2) { padding-left: 26px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-state { font-family: var(--font-sans); font-size: 11px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--border); }
.bt-state-won { color: var(--accent-green); border-color: currentColor; }
.bt-state-lost { color: var(--accent-red); border-color: currentColor; }
.bt-state-open { color: var(--accent-blue); border-color: currentColor; }

/* Headline B, legends, kinds of bet, explanations (spec 0149 D-36 – D-41). */
.bt-hero-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: center; }
.bt-hero-how { margin-top: 4px; font-size: 13.5px; }
.bt-hero-eg { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.bt-hero-cmp { font-size: 12.5px; }
.bt-bar-row { display: flex; justify-content: space-between; gap: 10px; margin: 6px 0 3px; color: var(--text-secondary); }
.bt-bar-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-bar { height: 8px; border-radius: 4px; background: var(--elevated); overflow: hidden; }
.bt-bar div { height: 8px; border-radius: 4px; }
.bt-hero-kept { margin-top: 8px; color: var(--text-muted); }
.bt-hero-b .bt-hero-foot { margin-top: 12px; }
.bt-hero-explain { margin-top: 6px; color: var(--text-muted); font-size: 12.5px; line-height: 1.5; }
.bt-hero-b .bt-hero-when { margin-top: 6px; }
.bt-tipped { border-bottom: 1px dotted var(--text-muted); cursor: help; }
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%);
  width: max-content; max-width: 280px; white-space: normal; background: var(--elevated); color: var(--text); border: 1px solid var(--border-hover, var(--border));
  border-radius: 6px; padding: 8px 10px; font: 400 12px/1.45 var(--font-sans); text-align: left; text-transform: none; letter-spacing: 0; z-index: 40;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); pointer-events: none; }
th.bt-num[data-tip]:hover::after, th.bt-num[data-tip]:focus-visible::after { left: auto; right: 0; transform: none; }
th[data-tip] { cursor: help; text-decoration: underline dotted var(--text-muted); text-underline-offset: 3px; }
.bt-card:has(th[data-tip]:hover) { overflow: visible; }
.bt-segbtns { display: flex; border: 1px solid var(--border); border-radius: 6px; }
.bt-segbtns button { flex: 1; background: var(--elevated); color: var(--text-secondary); border: 0; padding: 6px 4px; font: inherit; font-size: 12px; cursor: pointer; }
.bt-segbtns button + button { border-left: 1px solid var(--border); }
.bt-segbtns button:first-child { border-radius: 5px 0 0 5px; }
.bt-segbtns button:last-child { border-radius: 0 5px 5px 0; }
.bt-segbtns button[aria-pressed="true"] { background: var(--accent-blue-dim); color: var(--accent-blue); font-weight: 600; }
.bt-legend-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.bt-key { display: inline-flex; align-items: center; gap: 6px; background: var(--elevated); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; max-width: 100%; }
.bt-key:hover { border-color: var(--border-hover); }
.bt-key-off { opacity: 0.45; }
.bt-key-off .bt-key-sw { background: transparent !important; border: 1px solid var(--text-muted); }
.bt-key-sw { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.bt-key-dash { height: 0; border-top: 2px dashed; background: transparent; }
.bt-mode { fill: none; stroke-width: 1.8; stroke-linejoin: round; opacity: 0.95; }
.bt-kind td { font-size: 12.5px; color: var(--text-secondary); background: color-mix(in srgb, var(--elevated) 45%, transparent); }
.bt-kind td:nth-child(2) { padding-left: 28px; }
.bt-half { opacity: 0.6; outline: 2px solid #f2c94c; outline-offset: -2px; }
.bt-open-none { padding-left: 14px; }
@media (max-width: 860px) { .bt-hero-grid { grid-template-columns: minmax(0, 1fr); } }

/* Zoom, Reset view, sorting, Import / Save / Share, explanations kept on screen (spec 0149 D-42 – D-51). */
.bt-io-btns { display: flex; gap: 6px; margin-left: auto; }
.bt-io-btns + .bt-close { margin-left: 8px; }
.bt-io { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--surface); }
.bt-io[hidden] { display: none; }
.bt-io textarea, .bt-io-link { width: 100%; box-sizing: border-box; background: var(--elevated); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font: 12px var(--font-mono); resize: vertical; }
.bt-io-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bt-io-msg { color: var(--text-secondary); font-size: 12.5px; }
.bt-file-btn { cursor: pointer; }
.bt-plot { position: relative; overflow: hidden; user-select: none; }
.bt-chart { cursor: crosshair; }
.bt-brush { position: absolute; border: 1px solid var(--accent-blue); background: rgba(79, 172, 254, 0.12); box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35); pointer-events: none; }
.bt-brush span { position: absolute; left: 4px; top: 2px; font-size: 11px; color: var(--text); white-space: nowrap; }
.bt-reset { padding: 3px 10px; font-size: 12px; }
.bt-sort { background: transparent; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; text-align: inherit; }
.bt-sort:hover { color: var(--text); }
th[aria-sort] .bt-sort { color: var(--text); }
/* Explanations open into the screen: from the left edge in the side panel, the last button's from its right edge. */
.bt-side [data-tip]:hover::after, .bt-side [data-tip]:focus-visible::after { left: 0; transform: none; max-width: 260px; }
.bt-segbtns button:last-child[data-tip]:hover::after, .bt-segbtns button:last-child[data-tip]:focus-visible::after { left: auto; right: 0; }
.bt-cats th:nth-child(2)[data-tip]:hover::after { left: 0; right: auto; transform: none; }
