/* History section (public/history.js). Mobile first: one column, 2-up metric cards, swipeable
   charts. Tablet 768+: 3-up cards. Desktop 1100+: metrics row, charts side by side, fills list
   and summary in two columns. Motion: transform/opacity only, 150-300 ms, off with reduce-motion. */
.hist { --pos: var(--blue); --neg: var(--bad); --hist-ease: cubic-bezier(.2, .8, .2, 1);
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: var(--bg);
  color: var(--fg); opacity: 0; transform: translate3d(0, 16px, 0); pointer-events: none;
  transition: opacity 220ms var(--hist-ease), transform 260ms var(--hist-ease); }
.hist.in { opacity: 1; transform: none; pointer-events: auto; }
.hist[hidden] { display: none; }
.hist-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.hist-wrap { width: 100%; max-width: 1360px; margin: 0 auto; padding: 0 16px calc(var(--safe-b, 0px) + 32px); box-sizing: border-box; }

/* header: the Higgsfield intro plays once behind the title, then rests on its last frame */
.hist-hero { position: relative; overflow: hidden; height: 132px; border-bottom: 1px solid var(--line); }
.hist-hero video, .hist-hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .55; }
.hist-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11, 13, 16, .2), var(--bg) 96%); }
.hist-head { position: absolute; inset: auto 0 0; z-index: 1; display: flex; align-items: flex-end; gap: 12px;
  max-width: 1360px; margin: 0 auto; padding: 0 16px 14px; box-sizing: border-box; }
.hist-back { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line-2);
  background: rgba(10, 10, 10, .6); color: var(--fg); cursor: pointer; padding-top: calc(var(--safe-t, 0px) * 0); }
.hist-back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hist-title { min-width: 0; }
.hist-title h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.hist-title small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* period selector: sticky, swipeable on small screens */
.hist-periods { position: sticky; top: 0; z-index: 3; margin: 0 -16px; padding: 10px 16px; background: rgba(11, 13, 16, .92);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.hist-seg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); }   /* the fade says: swipe for more */
.hist-seg::-webkit-scrollbar { display: none; }
.hist-seg button { flex: none; min-width: 52px; min-height: 44px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--line-2);
  background: transparent; color: var(--fg-2); font: 600 13.5px/1 var(--font); cursor: pointer;
  transition: background 180ms var(--hist-ease), color 180ms var(--hist-ease), transform 120ms var(--hist-ease); }
.hist-seg button:active { transform: scale(.96); }
.hist-seg button[aria-pressed="true"] { background: rgba(201, 204, 209, .16); color: var(--accent); border-color: rgba(201, 204, 209, .5); }
.hist-custom { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.hist-custom[hidden] { display: none; }
.hist-custom input { min-height: 44px; padding: 0 10px; border-radius: var(--r-btn); border: 1px solid var(--line-2); background: var(--bg-sunk); color: var(--fg);
  font: 14px var(--font); color-scheme: dark; min-width: 0; flex: 1 1 130px; }
.hist-custom button { min-height: 44px; }

/* states */
.hist-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 40px 16px; color: var(--fg-2); }
.hist-state[hidden] { display: none; }
.hist-anim { width: 140px; height: 140px; border-radius: 22px; overflow: hidden; background: var(--bg-sunk); }
.hist-anim video, .hist-anim img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hist-state b { color: var(--fg); font-size: 16px; }
.hist-state p { margin: 0; max-width: 36ch; font-size: 14px; }
.hist-bar { width: min(240px, 70%); height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.hist-bar i { display: block; height: 100%; background: var(--accent-2); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform 250ms var(--hist-ease); }

/* entry motion: staggered */
.hist-rise { opacity: 0; transform: translate3d(0, 10px, 0); }
.hist-go .hist-rise { opacity: 1; transform: none; transition: opacity 260ms var(--hist-ease), transform 300ms var(--hist-ease); transition-delay: calc(var(--i, 0) * 40ms); }

/* metric cards */
.hist-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.hm { min-width: 0; padding: 12px 14px; border-radius: var(--r-card); border: 1px solid var(--line); background: var(--surface); }
.hm span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hm b { display: block; margin-top: 4px; font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hm small { display: block; margin-top: 2px; font-size: 12px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.hist .pos { color: var(--pos); } .hist .neg { color: var(--neg); }        /* profit blue, loss red (over the app's green/red) */
.hm.hero { grid-column: 1 / -1; }
.hm.hero b { font-size: 30px; }
.hm.wide { grid-column: 1 / -1; }

/* charts: swipe sideways on phones */
.hist-charts { display: flex; gap: 10px; margin: 16px -16px 0; padding: 0 16px 4px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.hist-charts::-webkit-scrollbar { display: none; }
.hc { flex: 0 0 calc(100% - 28px); scroll-snap-align: center; min-width: 0; padding: 12px 14px 14px; border-radius: var(--r-card); border: 1px solid var(--line); background: var(--surface); box-sizing: border-box; }
.hc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.hc-head b { font-size: 14px; }
.hc-head small { font-size: 12px; color: var(--fg-2); font-variant-numeric: tabular-nums; text-align: right; }
.hc-plot { position: relative; height: 170px; }
.hc-dots { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.hc-dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--line-2); transition: transform 200ms var(--hist-ease), background 200ms; }
.hc-dots i.on { background: var(--accent-2); transform: scaleX(1.6); }

/* daily P/L: bars grow from the zero baseline */
.hd { position: absolute; inset: 0; display: flex; align-items: stretch; gap: 2px; }
.hd-col { flex: 1 1 0; min-width: 0; position: relative; cursor: pointer; }
.hd-col::before { content: ""; position: absolute; inset: 0 -1px; }                 /* a bigger hit target */
.hd-bar { position: absolute; left: 12%; right: 12%; border-radius: 3px; transform: scaleY(0); }
.hd-bar.p { bottom: var(--zero); height: var(--h); background: var(--pos); transform-origin: bottom; }
.hd-bar.n { top: calc(100% - var(--zero)); height: var(--h); background: var(--neg); transform-origin: top; }
.hist-go .hd-bar { transform: scaleY(1); transition: transform 300ms var(--hist-ease); transition-delay: calc(var(--k, 0) * 8ms); }
.hd-col.on .hd-bar, .hd-col:hover .hd-bar { filter: brightness(1.25); }
.hd-zero { position: absolute; left: 0; right: 0; bottom: var(--zero); height: 1px; background: var(--line-2); }

/* P/L by symbol: horizontal bars from a centre line */
.hs { display: flex; flex-direction: column; gap: 8px; max-height: 170px; overflow-y: auto; }
.hs-row { display: grid; grid-template-columns: 76px 1fr 84px; align-items: center; gap: 8px; font-size: 12.5px; }
.hs-row span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hs-row em { font-style: normal; text-align: right; font-variant-numeric: tabular-nums; }
.hs-track { position: relative; height: 12px; }
.hs-track::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line-2); }
.hs-bar { position: absolute; top: 0; bottom: 0; border-radius: 3px; transform: scaleX(0); }
.hs-bar.p { left: 50%; width: var(--w); background: var(--pos); transform-origin: left; }
.hs-bar.n { right: 50%; width: var(--w); background: var(--neg); transform-origin: right; }
.hist-go .hs-bar { transform: scaleX(1); transition: transform 300ms var(--hist-ease); transition-delay: calc(var(--k, 0) * 30ms); }

/* balance line: revealed left to right */
.he { position: absolute; inset: 0; overflow: hidden; }
.he svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.he path.l { fill: none; stroke: var(--accent-2); stroke-width: 2; vector-effect: non-scaling-stroke; }
.he path.a { fill: url(#heFill); stroke: none; }
.he .cover { position: absolute; inset: 0; background: var(--surface); transform-origin: right; transform: scaleX(1); }
.hist-go .he .cover { transform: scaleX(0); transition: transform 600ms var(--hist-ease) 120ms; }

/* fills list + summary */
.hist-lower { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 16px; }
.hl, .hai { min-width: 0; border-radius: var(--r-card); border: 1px solid var(--line); background: var(--surface); }
.hl-head, .hai-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.hl-head b, .hai-head b { font-size: 15px; }
.hl-mode { display: flex; gap: 4px; padding: 3px; border-radius: var(--r-pill); background: var(--bg-sunk); border: 1px solid var(--line); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.hl-mode button { flex: none; min-height: 38px; padding: 0 12px; border: 0; border-radius: var(--r-pill); background: none; color: var(--fg-2); font: 600 12.5px var(--font); cursor: pointer; }
.hl-mode button[aria-pressed="true"] { background: rgba(201, 204, 209, .16); color: var(--accent); }
.hl-mode .s { display: none; }
@media (max-width: 479px) { .hl-head { flex-direction: column; align-items: stretch; } .hl-mode { width: 100%; } .hl-mode button { flex: 1; min-height: 44px; } .hl-mode .l { display: none; } .hl-mode .s { display: inline; } }
.hl-meta { padding: 8px 14px 0; font-size: 12px; color: var(--muted); }
.hl-view { position: relative; height: min(64vh, 620px); overflow-y: auto; overscroll-behavior: contain; contain: strict; }
.hl-space { position: relative; }
.hg { position: absolute; left: 0; right: 0; top: 0; will-change: transform; transition: transform 220ms var(--hist-ease); }
.hist-noanim .hg { transition: none; }
.hg-row { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; height: 72px; padding: 0 14px;
  border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--fg); text-align: left; font: inherit; cursor: pointer; box-sizing: border-box; }
.hg-row:hover { background: rgba(255, 255, 255, .02); }
.hg-row .side { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font: 700 11px var(--font); }
.hg-row .side.buy { background: rgba(158, 163, 171, .16); color: var(--pos); }
.hg-row .side.sell { background: rgba(255, 92, 92, .14); color: var(--neg); }
.hg-row .tx { min-width: 0; }
.hg-row .tx b { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-size: 13.5px; line-height: 1.3; font-weight: 600; }
.hg-row .tx small { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.hg-row .pl { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.hg-row .pl.pos { color: var(--pos); } .hg-row .pl.neg { color: var(--neg); }
.hg-row .chev { width: 14px; height: 14px; margin-left: 6px; vertical-align: -2px; fill: none; stroke: var(--muted); stroke-width: 2; transition: transform 220ms var(--hist-ease); }
.hg.open .chev { transform: rotate(90deg); }
.hg-fills { position: relative; overflow-y: auto; overscroll-behavior: contain; background: var(--bg-sunk); border-bottom: 1px solid var(--line);
  opacity: 0; transform: translate3d(0, -6px, 0); transition: opacity 200ms var(--hist-ease), transform 220ms var(--hist-ease); }
.hg.open .hg-fills { opacity: 1; transform: none; }
.hf { position: absolute; left: 0; right: 0; height: 34px; display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 0 14px 0 46px; font-size: 12px; color: var(--fg-2); font-variant-numeric: tabular-nums; box-sizing: border-box; }
.hf span:nth-child(2) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hf em { font-style: normal; text-align: right; }
.hl-empty { padding: 28px 14px; text-align: center; color: var(--muted); font-size: 14px; }

/* summary (rule-based) */
.hai-list { list-style: none; margin: 0; padding: 6px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.hai-list li { display: grid; grid-template-columns: 10px minmax(0, 1fr); gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.hai-list li:first-child { border-top: 0; }
.hai-list .lv { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--muted); }
.hai-list .lv.alert { background: var(--bad); box-shadow: 0 0 0 3px rgba(255, 92, 92, .18); }
.hai-list .lv.warn { background: var(--warn); }
.hai-list .lv.good { background: var(--good); }
.hai-list p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--fg); }
.hai-basis { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.hai-basis i { font-style: normal; font-size: 11px; padding: 2px 8px; border-radius: var(--r-pill); border: 1px solid var(--line-2); color: var(--muted); }
.hai-regen { min-height: 40px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--line-2); background: none; color: var(--fg-2); font: 600 13px var(--font); cursor: pointer; }
.hai-regen:disabled { opacity: .5; cursor: default; }
.hai-loading { display: flex; align-items: center; gap: 12px; padding: 16px 14px; color: var(--fg-2); font-size: 13.5px; }
.hai-loading[hidden] { display: none; }
.hai-loading .hist-anim { width: 48px; height: 48px; border-radius: 12px; }
.hai-note { margin: 0; padding: 0 14px 14px; font-size: 11.5px; color: var(--muted); }

/* tablet */
@media (min-width: 768px) {
  .hist-wrap { padding: 0 24px 40px; }
  .hist-head { padding: 0 24px 16px; }
  .hist-hero { height: 160px; }
  .hist-periods { margin: 0 -24px; padding: 12px 24px; }
  .hist-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hm.hero { grid-column: span 3; }
  .hm.wide { grid-column: auto; }
  .hist-charts { margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .hc { flex: none; }
  .hc:last-child { grid-column: 1 / -1; }
  .hc-dots { display: none; }
}
/* desktop */
@media (min-width: 1100px) {
  .hist-hero { height: 180px; }
  .hist-metrics { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .hm.hero { grid-column: span 2; }
  .hm.wide { grid-column: span 2; }
  .hist-charts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hc:last-child { grid-column: auto; }
  .hc-plot { height: 200px; }
  .hs { max-height: 200px; }
  .hist-lower { grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr); align-items: start; }
  .hai { position: sticky; top: 84px; }
}
@media (prefers-reduced-motion: reduce) {
  .hist, .hist-go .hist-rise, .hist-go .hd-bar, .hist-go .hs-bar, .hist-go .he .cover, .hg, .hg-fills, .hg-row .chev, .hist-seg button, .hc-dots i, .hist-bar i { transition: none !important; }
  .hist-rise { opacity: 1; transform: none; }
}
