/* Chart engine (/candles.js) inside the new desk: its layout rules plus the
   token names it reads, mapped onto the new palette (tokens.css). */
.cc {
  position: relative;
  /* The chart handles every touch itself (drag = pan, two fingers = zoom,
     long press = crosshair, double tap = fit). Without this the tablet's
     browser took the pinch for page zoom and cancelled the chart's fingers. */
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  --border: var(--line); --border-2: var(--line-strong); --surface-3: var(--sunken); --surface-hover: var(--hover);
  --text: var(--ink); --text-2: var(--ink-2); --muted: var(--ink-3); --faint: var(--ink-3);
  --pos: var(--up); --neg: var(--down); --accent: var(--ink); --accent-d: var(--ink); --accent-bg: var(--brand-soft); --accent-bd: var(--brand-edge); --accent-ring: var(--brand-soft);
  --ink-text: var(--ink-inv); --on-accent: var(--on-brand);
  --cc-up: var(--up); --cc-down: var(--down); --cc-up-border: var(--up); --cc-down-border: var(--down);
  --cc-up-wick: var(--up); --cc-down-wick: var(--down); --cc-guide: var(--line);
  --cc-grid: color-mix(in srgb, var(--line) 60%, transparent); --cc-grid-strong: var(--line); --cc-cross: var(--ink-3); --cc-grip: var(--line-strong);
  --s1: var(--c1); --s2: var(--c2); --s3: var(--c3); --s4: var(--c4); --s5: var(--c5); --s6: var(--c6); --s7: var(--bk-swing); --s8: var(--down);
  --shadow-sm: var(--shadow-1); --dur: var(--t-fast); --spring: var(--ease); --r-sm: 6px;
}
/* The chart takes focus on every touch / click (for its keys); a full focus
   ring then framed the chart in black after each pinch. A hairline is enough. */
.cc:focus, .cc:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--line-strong); border-radius: 0; }
.cc .cc-canvas { display: block; cursor: crosshair; }
.cc .cc-canvas.cc-ns { cursor: ns-resize; } .cc .cc-canvas.cc-ew { cursor: ew-resize; }
.cc .cc-legend, .cc .cc-legend2 {
  position: absolute; left: 14px; top: 10px; z-index: 2; pointer-events: none; display: flex; align-items: center; gap: 4px 11px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; max-width: calc(100% - 96px);
  text-shadow: 0 0 1px var(--surface), 0 0 2px var(--surface), 0 1px 2px var(--surface);
}
.cc .cc-legend b { color: var(--text); font-weight: 600; }
.cc .cc-legend b.pos, .cc .cc-legend .cc-chg.pos { color: var(--pos); }
.cc .cc-legend b.neg, .cc .cc-legend .cc-chg.neg { color: var(--neg); }
.cc .cc-sym { font-weight: 650; font-size: 13px; color: var(--text); }
.cc .cc-tf { font-weight: 550; color: var(--muted); }
.cc .cc-live { color: var(--pos); font-weight: 650; font-size: 11px; }
.cc .cc-when { color: var(--text-2); }
.cc .cc-ov { display: inline-flex; align-items: center; gap: 5px; }
.cc .cc-ov i { display: inline-block; width: 10px; height: 2px; border-radius: 2px; }
.cc .cc-legend2 { top: 46px; display: block; color: var(--text-2); line-height: 1.5; }
.cc .cc-legend2 .pos { color: var(--pos); font-weight: 650; } .cc .cc-legend2 .neg { color: var(--neg); font-weight: 650; } .cc .cc-legend2 .warn { color: var(--warn); font-weight: 650; }
.cc .cc-empty { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; color: var(--muted); pointer-events: none; padding: 20px; text-align: center; }
.cc .cc-latest {
  position: absolute; right: 78px; bottom: 38px; z-index: 3; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text-2); box-shadow: var(--shadow-2); cursor: pointer; display: grid; place-items: center; padding: 0;
}
.cc .cc-latest:hover { background: var(--brand-soft); color: var(--ink); }
.cc .cc-overlay { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.cc .cc-pane-grip { position: absolute; left: 0; right: 0; height: 8px; cursor: row-resize; pointer-events: auto; }
.cc .cc-pane-grip::after { content: ""; position: absolute; left: 50%; top: 3px; width: 36px; height: 2px; margin-left: -18px; border-radius: 2px; background: var(--cc-grip); opacity: 0; }
.cc .cc-pane-grip:hover::after { opacity: 1; }
.cc .cc-panelegend { position: absolute; left: 14px; font-size: 11.5px; color: var(--muted); pointer-events: none; display: flex; gap: 8px; align-items: center; }
.cc .cc-panelegend b { color: var(--text); font-weight: 550; }
.cc .cc-panelegend .cc-pane-acts { display: none; }
.cc .cc-corner { position: absolute; right: 0; bottom: 0; height: 26px; z-index: 3; display: flex; align-items: center; justify-content: center; gap: 2px; border-left: 1px solid var(--border); background: var(--surface); }
.cc .cc-corner button { min-width: 18px; height: 18px; padding: 0 3px; border: 0; border-radius: 4px; background: transparent; color: var(--faint); font: 600 10.5px/1 var(--font); cursor: pointer; }
.cc .cc-corner button:hover { background: var(--hover); color: var(--text); }
.cc .cc-corner button.on { color: var(--ink); background: var(--brand-soft); }

/* Chart page extras: indicators panel, Technicals read-out */
.cp-bar .btn .cnt { font-weight: 700; color: var(--brand-ink); }
.ind-quick { display: flex; flex-wrap: wrap; gap: 6px; }
.ind-quick .chip { cursor: pointer; height: 28px; }
.ind-quick .chip:hover { background: var(--brand-soft); color: var(--ink); }
.ind-row { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
.ind-row .ind-p .input { width: 64px; height: 28px; padding: 0 6px; font-size: var(--fs-12); }
.ind-list { display: flex; flex-direction: column; margin-top: var(--s3); }
.ind-def { display: flex; align-items: center; gap: var(--s3); height: 40px; padding: 0 var(--s2); border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; text-align: left; font-size: var(--fs-14); color: var(--ink); border-radius: var(--r-sm); }
.ind-def:hover { background: var(--hover); }
.ind-def .faint { font-size: var(--fs-12); }
.ind-def .ic { color: var(--ink-3); }
.tech { display: flex; flex-direction: column; gap: var(--s3); }
.tech-head { display: flex; align-items: center; gap: var(--s6); flex-wrap: wrap; }
.tech-verdict { font-size: var(--fs-20); line-height: var(--lh-20); font-weight: 700; letter-spacing: -.01em; }
.tech-meter { flex: 1 1 280px; display: flex; flex-direction: column; gap: 6px; }
.tech-counts { display: flex; gap: var(--s4); font-size: var(--fs-13); font-weight: 600; }
.tech-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--sunken); gap: 2px; }
.tech-bar i { display: block; min-width: 0; }
.tech-bar .u { background: var(--up); } .tech-bar .n { background: var(--line-strong); } .tech-bar .d { background: var(--down); }

/* ── Chart desk: drawing strip, tabbed side panel, signals, details,
   ticket and strategy tester (pages/chart-*.js) ── */
.cp-main { grid-column: 1; grid-row: 2; }
.cp-side { grid-column: 2; grid-row: 2 / 4; min-height: 0; }
.cp-drawer { grid-column: 1; grid-row: 3; }
.cp-host { position: absolute; inset: 0; }

/* Resizable panels (pages/chart.js): a 10 px grab strip on each dividing
   line, a hairline that lights up while you hover or drag, and a small pill
   in the middle so the handle is findable without hovering (§7). */
.cp-drawer { position: relative; }
.cp-grip { position: relative; z-index: 6; touch-action: none; user-select: none; -webkit-user-select: none; }
.cp-grip::after { content: ""; position: absolute; background: transparent; transition: background var(--t-fast); }
.cp-grip::before { content: ""; position: absolute; border-radius: var(--r-full); background: var(--line-strong); opacity: .9; transition: background var(--t-fast), opacity var(--t-fast); }
.cp-grip:hover::after, .cp-grip.on::after, .cp-grip:focus-visible::after { background: var(--brand-edge); }
.cp-grip:hover::before, .cp-grip.on::before, .cp-grip:focus-visible::before { background: var(--brand-edge); opacity: 1; }
.cp-grip:focus-visible { box-shadow: none; }
.cp-grip-v { grid-column: 2; grid-row: 2 / 4; justify-self: start; align-self: stretch; width: 10px; margin-left: -5px; cursor: col-resize; }
.cp-grip-v::after { top: 0; bottom: 0; left: 4px; width: 2px; }
.cp-grip-v::before { top: 50%; left: 3px; width: 4px; height: 28px; margin-top: -14px; }
.cp-grip-h { position: absolute; left: 0; right: 0; top: -5px; height: 10px; cursor: row-resize; }
.cp-grip-h::after { left: 0; right: 0; top: 4px; height: 2px; }
.cp-grip-h::before { left: 50%; top: 3px; width: 28px; height: 4px; margin-left: -14px; }
.cp.cp-resizing { user-select: none; -webkit-user-select: none; }
.cp.cp-resizing .cp-host, .cp.cp-resizing .cp-side, .cp.cp-resizing .cp-drawer-b { pointer-events: none; }
/* Hidden side panel: the column closes and the grip stays at the edge as
   the way back (drag it left, double-click, or Enter). */
.cp.side-hidden { grid-template-columns: minmax(0, 1fr) 0px; }
.cp.side-hidden .cp-side { visibility: hidden; border-left: 0; overflow: hidden; }
.cp.side-hidden .cp-grip-v { margin-left: -10px; }
.cp.side-hidden .cp-grip-v::before { height: 44px; margin-top: -22px; background: var(--ink-3); }
/* Animated only for button / double-click changes; a drag follows the hand. */
.cp.cp-anim { transition: grid-template-columns var(--t-med) var(--ease); }
.cp.cp-anim .cp-drawer-b { transition: height var(--t-med) var(--ease); }
/* Full screen (pages/chart.js): the page covers the top bar and rail; the
   Live stripe, menus, dialogs and tooltips stay above it. Panel chips in
   the bar show the selection tint when their panel is out. */
.cp.cp-full { position: fixed; inset: 0; z-index: 60; height: auto; padding-top: var(--safe-t); background: var(--bg); }
body.live .cp.cp-full { padding-top: calc(var(--safe-t) + 2px); }
body.chart-full { overflow: hidden; }
.cp-fs-chips { display: inline-flex; gap: var(--s1); }
.cp-fs-chips:empty { display: none; }
.cp-fs-chips .btn.on { background: var(--brand-soft); border-color: var(--brand-edge); color: var(--brand-ink); }
/* Narrower screens: the chips keep their icon (name in the tooltip) so the bar fits on one line. */
@media (max-width: 1599px) { .cp-fs-chips .btn > span { display: none; } }
/* A finger needs a wider strip than a mouse (the line itself stays 2 px). */
@media (pointer: coarse) {
  .cp-grip-v { width: 24px; margin-left: -12px; }
  .cp-grip-v::after { left: 11px; } .cp-grip-v::before { left: 10px; }
  .cp.side-hidden .cp-grip-v { margin-left: -24px; }
  .cp-grip-h { top: -12px; height: 24px; }
  .cp-grip-h::after { top: 11px; } .cp-grip-h::before { top: 10px; }
}
.cp-main.has-tools .cp-host { left: 40px; }
.cp-tools { position: absolute; left: 0; top: 0; bottom: 0; width: 40px; z-index: 3; display: flex; flex-direction: column; align-items: center; gap: var(--s1); padding: var(--s2) 0; border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto; scrollbar-width: none; }
.cp-tools::-webkit-scrollbar { display: none; }
.cp-tool { flex: none; width: 32px; height: 32px; display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2); cursor: pointer; transition: background var(--t-fast), color var(--t-fast); }
.cp-tool:hover { background: var(--hover); color: var(--ink); }
.cp-tool.on { background: var(--brand-soft); color: var(--ink); box-shadow: inset 0 0 0 1px var(--brand-edge); }
.cp-tool:disabled { opacity: .4; cursor: not-allowed; background: none; }
.cp-tool-sep { flex: none; width: 20px; height: 1px; margin: var(--s1) 0; background: var(--line); }

.cp-stabs { flex: none; padding: 0 var(--s2); }
.cp-side-b { flex: 1 1 auto; min-height: 0; overflow: auto; }
.cp-wl-bar { flex: none; display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.cp-wl-bar[hidden] { display: none; }
.cp-wl-bar .input { flex: 1 1 auto; min-width: 0; }
.cp-side .wl-row { padding-left: var(--s2); }
.cp-wl-foot { padding: var(--s3) var(--s4); font-size: var(--fs-12); }
.cp-flag { flex: none; width: 28px; height: 28px; display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--r-sm); background: none; color: var(--line-strong); cursor: pointer; }
button.cp-flag:hover { background: var(--hover); color: var(--ink-3); }
.cp-swatch { flex: none; width: 12px; height: 12px; margin: 0 2px; border-radius: 3px; }

.cp-sig, .cp-dt { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); }
.cp-sig-h { display: flex; align-items: flex-start; gap: var(--s2); }
.cp-sig-h b { font-weight: 650; }
.cp-sig-h .ell { font-size: var(--fs-13); }
.cp-sg-f { font-size: var(--fs-12); line-height: var(--lh-12); }
.cp-sec { margin-top: var(--s1); font-size: var(--fs-13); font-weight: 650; color: var(--ink-2); }
.cp-note { font-size: var(--fs-12); line-height: var(--lh-12); }
.cp-verdict { display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s3); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); font-size: var(--fs-13); font-weight: 500; }
.cp-verdict .ic { flex: none; margin-top: 1px; color: var(--ink-3); }
.cp-verdict.up .ic { color: var(--up); } .cp-verdict.info .ic { color: var(--info); }
.cp-verdict.warn .ic { color: var(--warn); } .cp-verdict.down .ic { color: var(--down); }
.cp-pos-id { display: block; margin-top: 2px; font-weight: 400; overflow-wrap: anywhere; }
.cp-verdict .btn { flex: none; align-self: center; }
.cp-sg-list { display: flex; flex-direction: column; }
.cp-sg-row { display: flex; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--line); font-size: var(--fs-13); }
.cp-sg-row:last-child { border-bottom: 0; }
.cp-sg-row .grow { min-width: 0; }
.cp-sg-row.warn b { color: var(--warn); }
.cp-sg-r { flex: none; display: flex; flex-direction: column; align-items: flex-end; text-align: right; font-variant-numeric: tabular-nums; }
.cp-sg-t { flex: none; min-width: 40px; padding-top: 1px; white-space: nowrap; font-size: var(--fs-12); color: var(--ink-3); }
.cp-desk-kv { gap: var(--s2) var(--s3); }
.cp-desk-kv dd { font-variant-numeric: tabular-nums; }
.cp-silence { display: flex; align-items: center; gap: var(--s2); width: 100%; padding: var(--s3); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs-13); text-align: left; cursor: pointer; transition: background var(--t-fast); }
.cp-silence:hover { background: var(--hover); }
.cp-silence .grow > span { display: block; }
.cp-full { width: 100%; justify-content: center; }

.cp-dt-h b { font-size: var(--fs-16); line-height: var(--lh-16); font-weight: 650; }
.cp-dt-l { margin-bottom: var(--s1); font-size: var(--fs-12); color: var(--ink-3); }
.cp-range { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-12); font-variant-numeric: tabular-nums; }
.cp-range i { position: relative; flex: 1 1 auto; height: 4px; border-radius: 2px; background: var(--sunken); }
.cp-range b { position: absolute; top: -3px; width: 2px; height: 10px; margin-left: -1px; border-radius: 1px; background: var(--ink); }
.cp-ba { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
.cp-ba > div { display: flex; flex-direction: column; font-size: var(--fs-12); }
.cp-ba b { font-size: var(--fs-14); font-weight: 650; }
.cp-perf { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2); }
.cp-perf > div { display: flex; flex-direction: column; padding: var(--s2); border-radius: var(--r-sm); background: var(--surface-2); font-size: var(--fs-12); }
.cp-perf b { font-size: var(--fs-13); font-weight: 650; }

.cp-tk, .cp-sil { display: flex; flex-direction: column; gap: var(--s4); }
.cp-tk .seg { align-self: flex-start; }
.cp-tk .cp-sec { margin: 0 0 calc(-1 * var(--s2)); }
.cp-tk-kv { padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface-2); }
.cp-tk .rule .sub-l { display: block; font-size: var(--fs-12); line-height: var(--lh-12); color: var(--ink-3); }
.cp-tk .rule > .ic, .cp-sil .ic { flex: none; }

.cp-bt-bar { margin-bottom: var(--s3); }
.cp-bt-out .bt-verdict { font-size: var(--fs-13); }
.cp-trc { position: relative; height: 360px; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }

@media (min-width: 1400px) {
  .cp-bar { flex-wrap: nowrap; }
  .cp-bar #cStrat { flex: 0 1 220px; min-width: 120px; }
  .cp-bar .sym { white-space: nowrap; }
}
@media (max-width: 1023px) {
  .cp-main, .cp-side, .cp-drawer { grid-column: 1; grid-row: auto; }
  .cp-grip-v { display: none; }
  .cp.side-hidden { grid-template-columns: minmax(0, 1fr); }
  .cp.side-hidden .cp-side { visibility: visible; }
  /* Stacked layout: full screen scrolls, and Watchlist off really hides it. */
  .cp.cp-full { overflow: auto; }
  .cp.cp-full.side-hidden .cp-side { display: none; }
  .cp-side { max-height: none; }
  .cp-side .wl { max-height: 420px; overflow: auto; }
}

/* Open trades on this stock (Trades tab): selected strategy, then the rest. */
.cp-open { display: flex; flex-direction: column; gap: var(--s2); margin-bottom: var(--s4); }
.cp-tr-h { display: flex; align-items: center; gap: var(--s2); margin: var(--s2) 0 var(--s1); }
.cp-tr-none { font-size: var(--fs-13); margin: 0 0 var(--s2); }

/* ── Chart drawer: Performance tab (pages/chart-perf.js) and the
   Technicals quick-read tiles (pages/chart.js drawTechnicals) ── */
.pf { display: flex; flex-direction: column; gap: var(--s4); }
.pf-head { display: flex; align-items: flex-start; gap: var(--s3); }
.pf-cap { font-size: var(--fs-12); line-height: var(--lh-12); }
.pf-last { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s1); font-size: var(--fs-13); }
.pf-last b { font-size: var(--fs-20); line-height: var(--lh-20); font-weight: 600; }
.pf-kpis, .tech-kpis { grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); }
.pf-kpis .kpi-v, .tech-kpis .kpi-v { font-size: var(--fs-20); line-height: var(--lh-20); }
.pf-kpis .kpi, .tech-kpis .kpi { padding: var(--s2) var(--s3); }
.pf-kpis .kpi-d, .tech-kpis .kpi-d { overflow: hidden; }
.pf-kpis .kpi-d > *, .tech-kpis .kpi-d > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-kpis .kpi-d, .tech-kpis .kpi-d { font-size: var(--fs-12); line-height: var(--lh-12); }
.pf-periods { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s2); }
.pf-per { display: flex; flex-direction: column; gap: 2px; padding: var(--s2) var(--s3); border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.pf-per-l { font-size: var(--fs-12); line-height: var(--lh-12); color: var(--ink-3); font-weight: 500; }
.pf-per-v { font-size: var(--fs-16); line-height: var(--lh-16); font-weight: 600; font-variant-numeric: tabular-nums; }
.pf-per-b { font-size: var(--fs-12); line-height: var(--lh-12); color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pf-stack { display: flex; flex-direction: column; gap: var(--s4); }
.pf-season { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--s1); height: 96px; margin-bottom: var(--s3); }
.pf-sb { display: grid; grid-template-rows: 1fr 1fr 16px; min-width: 0; }
.pf-sb-up, .pf-sb-dn { display: flex; justify-content: center; }
.pf-sb-up { align-items: flex-end; border-bottom: 1px solid var(--line); }
.pf-sb-dn { align-items: flex-start; }
.pf-sb i { display: block; width: 60%; max-width: 24px; border-radius: 2px; }
.pf-sb i.up { background: var(--up); } .pf-sb i.down { background: var(--down); }
.pf-sb span { font-size: var(--fs-12); line-height: var(--lh-12); color: var(--ink-3); text-align: center; }
.pf-roll { margin-top: var(--s3); }
.pf-note { font-size: var(--fs-12); line-height: var(--lh-12); }
@media (max-width: 767px) {
  .pf-kpis, .tech-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pf-periods { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ── "View on chart": the focused backtest trade's chip in the chart bar ── */
.cp-focus { display: inline-flex; align-items: center; gap: var(--s1); min-width: 0; flex: 0 1 auto; overflow: hidden; }
.cp-focus .chip { cursor: pointer; max-width: 260px; min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; }
.cp-focus.miss .chip { background: var(--warn-soft); color: var(--warn); }
@media (max-width: 767px) { .cp-focus .chip { max-width: 200px; } }
.cp-bar #cFocus { display: inline-flex; min-width: 0; flex: 0 1 auto; overflow: hidden; }
