/* TradingView-style Strategy Tester, price-axis countdown and the sidebar's setup / previous trades.
   Uses the colour tokens from terminal.css. */

/* ---------- countdown under the last price, on the price scale (TradingView style) ---------- */
.price-countdown {
    position: absolute; right: 0; z-index: 30; pointer-events: none;
    height: 17px; line-height: 17px; text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Inter, Roboto, monospace;
    font-size: 11px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums;
    border-radius: 0 0 3px 3px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

/* ---------- sidebar: setup name, previous trades ---------- */
.setup-strategy {
    font-size: 12px; font-weight: 700; color: var(--blue); background: var(--blue-soft);
    padding: 4px 8px; border-radius: var(--radius); margin-bottom: 8px; display: inline-block;
}
.prev-trades { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
.prev-head { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.prev-trade {
    width: 100%; display: grid; grid-template-columns: 20px 1fr auto auto; align-items: center; gap: 8px;
    padding: 5px 4px; border-radius: var(--radius); font-size: 12px; text-align: left;
    transition: background var(--dur) var(--ease);
}
.prev-trade:hover { background: var(--bg-hover); }
.prev-trade:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.side-pill { width: 18px; height: 18px; border-radius: 3px; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: #fff; }
.side-pill.is-long { background: var(--green); }
.side-pill.is-short { background: var(--red); }
.prev-time { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.prev-result { color: var(--text-muted); }
.prev-pnl { font-family: var(--font-mono); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- tester header line + compact summary ---------- */
.tester-strip {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; padding: 6px 16px;
    font-size: 12px; color: var(--text-muted); border-bottom: 1px solid var(--border); background: var(--bg);
}
.ts-strip-name { color: var(--text); font-weight: 700; }
.bottom-head .summary { flex-wrap: nowrap; overflow: hidden; white-space: nowrap; gap: 18px; }
.bottom-tab-btn { font-weight: 500; padding: 6px 10px; border: 0; border-radius: var(--radius); }
.bottom-tab-btn.is-active { color: var(--text); background: var(--bg-hover); font-weight: 600; box-shadow: inset 0 -2px 0 var(--text); border-radius: var(--radius) var(--radius) 0 0; }

/* ---------- tester body ---------- */
.tester { padding: 12px 18px 20px; display: flex; flex-direction: column; gap: 18px; }
.ts-section h3 { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 10px; }
.ts-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 24px; }
.ts-stat { min-width: 0; }
.ts-label { display: block; font-size: 12px; color: var(--text); margin-bottom: 3px; }
.ts-value { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.ts-value strong { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ts-sub { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.ts-empty { color: var(--text-muted); font-size: 13px; padding: 20px 0; }
.ts-grid2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 28px; }

.ts-subtabs { display: flex; gap: 6px; }
.ts-subtabs button {
    padding: 4px 12px; border-radius: 14px; font-size: 12px; font-weight: 600;
    background: var(--bg-hover); color: var(--text); transition: background var(--dur) var(--ease);
}
.ts-subtabs button:hover { background: var(--border); }
.ts-subtabs button.is-active { background: var(--text); color: #fff; }

.ts-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); margin: 6px 0; }
.ts-key::before { content: ""; display: inline-block; width: 12px; height: 3px; margin-right: 6px; vertical-align: middle; background: currentColor; }
.ts-key.is-line::before { background: var(--green); }
.ts-key.is-bars::before { background: linear-gradient(90deg, var(--green) 50%, var(--red) 50%); height: 8px; }
.ts-key.is-up::before { background: var(--green); }
.ts-key.is-down::before { background: var(--red); }

/* plots: svg stretches, labels stay crisp */
.ts-plot { position: relative; height: 210px; margin: 4px 64px 22px 0; }
.ts-plot.is-hist { height: 170px; }
.ts-plot.is-streaks { height: 180px; }
.ts-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.ts-axis {
    position: absolute; left: calc(100% + 6px); transform: translateY(-50%);
    font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ts-axis.is-tag { color: #fff; font-weight: 600; padding: 1px 5px; border-radius: 2px; }
.ts-axis.is-tag.up { background: var(--green); }
.ts-axis.is-tag.down { background: var(--red); }
.ts-time { position: absolute; top: calc(100% + 6px); transform: translateX(-50%); font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.ts-time.is-start { transform: none; }
.ts-time.is-end { transform: translateX(-100%); }
.ts-line { fill: none; stroke: var(--green); stroke-width: 2; }
.ts-area { fill: var(--green); fill-opacity: 0.07; stroke: none; }
.ts-zero { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.ts-bar-up { fill: var(--green); }
.ts-bar-down { fill: var(--red); }
.ts-mark-up { stroke: var(--green); stroke-width: 1.5; stroke-dasharray: 3 3; }
.ts-mark-down { stroke: var(--red); stroke-width: 1.5; stroke-dasharray: 3 3; }

/* profits and losses by side */
.ts-pnl-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 130px; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--bg-hover); font-size: 12px; }
.ts-pnl-track { height: 8px; }
.ts-pnl-fill { display: flex; height: 100%; border-radius: 4px; overflow: hidden; min-width: 2px; }
.ts-pnl-loss { background: #f7a1a8; }
.ts-pnl-gain { background: var(--green); }
.ts-pnl-val { text-align: right; font-variant-numeric: tabular-nums; }

/* trades distribution donut */
.ts-donut-wrap { display: flex; align-items: center; gap: 22px; }
.ts-donut { width: 150px; height: 150px; flex: 0 0 auto; transform: rotate(-90deg); }
.ts-donut circle { fill: none; stroke-width: 16; }
.ts-donut text { transform: rotate(90deg); transform-origin: 60px 60px; }
.ts-ring-up { stroke: var(--green); }
.ts-ring-down { stroke: var(--red); }
.ts-ring-even { stroke: var(--orange); }
.ts-donut-n { font: 700 18px var(--font-sans); fill: var(--text); }
.ts-donut-l { font: 400 9px var(--font-sans); fill: var(--text-muted); }
.ts-donut-legend { display: grid; gap: 8px; font-size: 12px; }
.ts-donut-legend > div { display: grid; grid-template-columns: 12px 80px 80px auto; gap: 8px; align-items: center; }
.ts-dot { width: 9px; height: 9px; border-radius: 50%; }
.ts-dot.ts-ring-up { background: var(--green); }
.ts-dot.ts-ring-down { background: var(--red); }
.ts-dot.ts-ring-even { background: var(--orange); }

/* list of trades: an Exit row over an Entry row per trade, like TradingView */
.ts-trades td { vertical-align: middle; }
.ts-trades tr.ts-exit td { border-bottom: 0; padding-bottom: 2px; }
.ts-trades tr.ts-entry td { padding-top: 2px; }
.ts-trades tr.ts-exit td[rowspan] { border-bottom: 1px solid var(--border); }
.ts-trades tr.ts-entry td { border-bottom: 1px solid var(--border); }
.ts-trades tbody tr:hover { background: transparent; }
.ts-trades tr.is-open td { background: var(--blue-soft); }
.ts-num { font-weight: 600; }
.ts-io { display: inline-block; width: 38px; color: var(--text-muted); }
.ts-cell-sub { display: block; font-size: 11px; color: var(--text-muted); }

@media (max-width: 1100px) {
    .ts-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ts-grid2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
    .tester { padding: 10px 12px 16px; }
    .ts-pnl-row { grid-template-columns: 90px minmax(0, 1fr) 100px; }
    .ts-donut-wrap { flex-direction: column; align-items: flex-start; }
    .bottom-head .summary { display: none; }
}
