:root {
  --bg: #0b0e14;
  --panel: #131722;
  --panel-2: #1a2030;
  --line: #232b3d;
  --text: #dfe5ef;
  --muted: #8a94a6;
  --green: #26a69a;
  --red: #ef5350;
  --blue: #4f7cff;
  --amber: #ffb300;
  --purple: #ab47bc;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.45;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(11,14,20,.94); backdrop-filter: blur(8px); z-index: 10;
  flex-wrap: wrap; gap: 12px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex: none;
}
.logo svg { width: 38px; height: 38px; display: block; }
.brand h1 { margin: 0; font-size: 19px; letter-spacing: .3px; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }
/* "Built with TradeFlow" header badge */
.badge-row { margin: 6px 0 0 !important; }
.tf-badge { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  text-decoration: none; color: var(--text); }
.tf-badge .mk { width: 16px; height: 16px; border-radius: 5px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 10px; color: #fff;
  background: linear-gradient(135deg, var(--green), var(--blue)); }
.tf-badge.pill { border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 999px; padding: 3px 11px 3px 4px; font-size: 12px; }
.tf-badge.pill:hover { border-color: var(--muted); }
.controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button {
  background: none; border: none; color: var(--muted); padding: 7px 14px;
  cursor: pointer; font-size: 13px;
}
.seg button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.datenav { display: flex; align-items: center; gap: 8px; }
.datenav button {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px;
}
.datenav button.ghost { color: var(--muted); }
.datenav button:disabled { opacity: .35; cursor: default; }
#dateLabel { min-width: 190px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

main { max-width: 1180px; margin: 0 auto; padding: 18px 22px 40px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 18px;
}
.panel h2 { margin: 0 0 12px; font-size: 14px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.panel h2 .sub { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.filter-chip {
  background: var(--panel-2); border: 1px solid var(--blue); color: var(--text);
  border-radius: 20px; padding: 3px 10px; font-size: 12px; cursor: pointer;
}
.hidden { display: none; }

.customrow { display: flex; gap: 12px; align-items: center; flex-basis: 100%; }
.customrow.hidden { display: none; }
.customrow label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.customrow input[type="date"] {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 6px 8px; font: inherit; color-scheme: dark;
}

/* health pill: bot cycle status in the header */
.health-pill {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 4px;
  font-size: 12px; color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px;
}
.health-pill .hdot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.health-ok .hdot { background: #26a69a; }
.health-ok { color: var(--text); }
.health-warn .hdot { background: #ffb300; }
.health-warn { color: var(--text); }
.health-err .hdot { background: #ef5350; }
.health-err { color: var(--text); }

.digest { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }

.grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid, .grid-2 { grid-template-columns: 1fr; } }

.tape { display: flex; flex-direction: column; gap: 2px; max-height: 720px; overflow-y: auto; }
.day-head {
  position: sticky; top: 0; background: var(--panel); padding: 8px 2px 4px;
  color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 1px solid var(--line); margin-top: 6px;
}
.trow {
  display: grid; grid-template-columns: 52px 1fr; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid var(--line);
}
.trow:last-child { border-bottom: none; }
.ttime { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.tmain { min-width: 0; }
.tline1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  font-size: 11px; font-weight: 700; border-radius: 5px; padding: 2px 7px; letter-spacing: .4px;
}
.b-BUY, .b-ADD { background: rgba(38,166,154,.16); color: var(--green); }
.b-SELL, .b-TRIM, .b-EXIT { background: rgba(239,83,80,.14); color: var(--red); }
.b-PLAN { background: rgba(79,124,255,.16); color: var(--blue); }
.b-HOLD, .b-WATCH { background: rgba(138,148,166,.14); color: var(--muted); }
.oc {
  font-size: 11px; font-weight: 700; border-radius: 10px; padding: 2px 9px; white-space: nowrap;
}
.oc-good { background: rgba(38,166,154,.16); color: var(--green); }
.oc-bad { background: rgba(239,83,80,.14); color: var(--red); }
.oc-flat { background: rgba(138,148,166,.16); color: var(--muted); }
.oc-hit { background: rgba(38,166,154,.16); color: var(--green); }
.oc-pend { background: rgba(255,179,0,.16); color: var(--amber); }
.trader-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.tcard { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.tcard:active { transform: scale(.99); }
.tc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.tc-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tc-record { font-size: 14px; font-weight: 600; margin-bottom: 6px; display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.tc-sub { color: var(--muted); font-size: 12px; font-weight: 400; }
.tc-row { font-size: 12.5px; margin-top: 4px; }
.tc-k { color: var(--muted); margin-right: 6px; }
/* tap-to-filter: every card, row, bar and day is tappable; .factive marks the active filter */
.tap { cursor: pointer; }
.tap:active { opacity: .72; }
.factive { outline: 2px solid var(--blue); outline-offset: -2px; border-radius: 8px; }
#donutLegend .tap { border-radius: 6px; padding: 1px 5px; margin: -1px -5px; }
/* tape filter dropdowns (shown when viewing a single trader) */
.tape-filters { display: flex; gap: 10px; flex-wrap: wrap; margin: 2px 0 10px; }
.tape-filters.hidden { display: none; }
.filter-toggle { margin: 2px 0 10px; }
.filter-toggle .farrow { font-size: 10px; color: var(--muted); }
/* insights: auto-spotted observations + one actionable line each */
.insights { display: grid; gap: 10px; }
.insight { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.insight .it { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.insight .id { font-size: 13px; color: var(--text); margin-bottom: 3px; }
.insight .ia { font-size: 13px; color: var(--muted); }
.insight .ia span { color: var(--blue); font-weight: 700; }
/* collapsible panels: tap the heading to expand */
.collapse-head { cursor: pointer; user-select: none; }
.collapse-head .farrow { font-size: 11px; color: var(--muted); margin-left: 2px; }
.tfilter { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.tfilter select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; min-width: 110px;
}
/* slice summary: the "more data" shown when filters are active */
.slice-summary { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 2px 0 10px; }

/* card detail popup: bottom sheet on mobile, centered dialog on desktop */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; }
.sheet-wrap.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.sheet {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 0;
  width: 100%; max-width: 520px; max-height: 72vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-bottom: none;
  border-radius: 16px 16px 0 0; padding: 18px 20px 26px;
  animation: sheetup .22s ease-out;
}
@keyframes sheetup { from { transform: translate(-50%, 32px); opacity: .4; } to { transform: translate(-50%, 0); opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 16px; }
.sheet-filter {
  margin-top: 16px; width: 100%; background: var(--blue); border: none; color: #fff;
  border-radius: 10px; padding: 11px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.sheet-filter.hidden { display: none; }
@media (min-width: 700px) {
  .sheet {
    bottom: auto; top: 50%; transform: translate(-50%, -50%);
    border-radius: 16px; border-bottom: 1px solid var(--line);
    animation: sheetpop .18s ease-out;
  }
  @keyframes sheetpop { from { transform: translate(-50%, -48%) scale(.97); opacity: .4; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
}
.ss-label { font-weight: 700; font-size: 13px; margin-bottom: 5px; display: flex; align-items: center; gap: 8px; }
.ss-x {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 50%; width: 22px; height: 22px; font-size: 11px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.ss-stats { font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.ss-dot { color: var(--muted); }
.tsym { font-weight: 700; font-size: 14px; }
.tinst { color: var(--muted); font-size: 12px; }
.ttrader { color: var(--muted); font-size: 12px; margin-left: auto; }
.tnote { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.conf { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.conf.high { background: var(--green); } .conf.medium { background: var(--amber); } .conf.low { background: var(--red); }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }

.donut-wrap { display: flex; justify-content: center; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; justify-content: center; }
.legend span { font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

.hbar-row { display: grid; grid-template-columns: 64px 1fr 34px; gap: 8px; align-items: center; margin: 7px 0; font-size: 12.5px; }
.hbar-row .lbl { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: var(--panel-2); border-radius: 5px; height: 16px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 5px; }
.hbar-row .num { text-align: right; font-variant-numeric: tabular-nums; }

.sym-row { cursor: pointer; border-radius: 8px; padding: 6px 8px; margin: 0 -8px; }
.sym-row:hover { background: var(--panel-2); }
.sym-row.active { background: var(--panel-2); outline: 1px solid var(--blue); }
.sym-top { display: flex; justify-content: space-between; align-items: baseline; }
.sym-top .s { font-weight: 700; }
.net { font-size: 11px; font-weight: 700; }
.net.pos { color: var(--green); } .net.neg { color: var(--red); } .net.flat { color: var(--muted); }
.hint { color: var(--muted); font-size: 11.5px; margin: 8px 0 0; }

.clusters { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.cluster {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
.cluster .cs { font-size: 18px; font-weight: 800; }
.cluster .cm { color: var(--muted); font-size: 12px; margin-top: 4px; }
.cluster .ca { font-size: 12px; margin-top: 6px; }

.opt-bucket { margin-bottom: 14px; }
.opt-bucket .ob-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.opt-bucket .ob-head b { font-weight: 600; }
.opt-ex { color: var(--muted); font-size: 12px; margin-top: 4px; }

.plan-row { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.plan-row:last-child { border-bottom: none; }
.plan-row .pd { color: var(--muted); font-size: 11.5px; }

.heatmap { display: grid; grid-template-columns: repeat(20, 1fr); gap: 4px; }
.hm-cell { aspect-ratio: 1; border-radius: 3px; background: var(--panel-2); cursor: pointer; position: relative; }
/* hover preview only where hover exists — on touch, tapping a cell opens that day */
@media (hover: hover) {
  .hm-cell:hover::after {
    content: attr(data-tip); position: absolute; bottom: 110%; left: 50%; transform: translateX(-50%);
    background: #000; color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 5px; white-space: nowrap; z-index: 5;
    max-width: 60vw; overflow: hidden; text-overflow: ellipsis;
  }
}
@media (max-width: 700px) { .heatmap { grid-template-columns: repeat(10, 1fr); } }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; border-top: 1px solid var(--line); }

/* ---------- guide + tips ---------- */
.guide { border-color: var(--blue); }
.guide-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.guide-head h2 { margin: 0 !important; color: var(--text) !important; }
.guide-head .ghost {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 5px 12px; cursor: pointer; font-size: 12.5px;
}
.guide-intro { margin: 6px 0 12px; }
.guide-defs { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.guide-defs > div { display: grid; grid-template-columns: 130px 1fr; gap: 10px; }
.guide-defs dt { font-weight: 700; color: var(--text); }
.guide-defs dd { margin: 0; color: var(--muted); }
.guide-defs dd b { color: var(--text); font-weight: 600; }
@media (max-width: 700px) { .guide-defs > div { grid-template-columns: 1fr; gap: 2px; } }

.tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--muted); color: var(--muted);
  font-size: 10px; font-style: normal; font-weight: 400;
  cursor: help; margin-left: 6px; position: relative; vertical-align: 2px;
  text-transform: none; letter-spacing: 0;
}
/* Tooltips are one JS-positioned bubble (#tooltip), clamped inside the viewport.
   (CSS-only ::after tooltips overflowed off-screen near the phone's edges.) */
.tooltip {
  position: fixed; z-index: 50; max-width: min(280px, calc(100vw - 24px));
  background: #000; color: #fff; font-size: 12.5px; font-weight: 400;
  padding: 9px 12px; border-radius: 9px; line-height: 1.5; text-align: left;
  text-transform: none; letter-spacing: 0;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
.tooltip[hidden] { display: none; }
/* tipx = tooltip on an element that already has its own shape (e.g. outcome
   pills). Same tap-to-show behavior as .tip, without the 16px circle chrome. */
.tipx { position: relative; cursor: help; }
/* Assumed entry price: muted + italic + dotted underline so it reads as a
   guess at a glance; tap/hover for the explanation tooltip. */
.pchip.assumed { color: var(--muted); font-style: italic; border-bottom: 1px dotted var(--muted); }
/* Incomplete post marker: small amber tag, tap/hover lists what's missing. */
.incomplete { font-size: 11px; color: var(--amber); border: 1px solid var(--amber); border-radius: 4px; padding: 0 5px; white-space: nowrap; }
.panel-head { flex-wrap: wrap; gap: 8px; }
