/* =========================================================
   HLDASH — Design system foundation
   Phase 1 of the redesign per ENGINEERING_HANDOFF §10.
   Tokens, base type, and the .num / .mono number treatment.
   Shell, hero, groups, and positions layers ship in later phases.
   ========================================================= */

:root {
  /* Surfaces */
  --bg-0:        #07080a;   /* page */
  --bg-1:        #0e0f12;   /* primary surface */
  --bg-2:        #14161a;   /* raised surface (cards) */
  --bg-3:        #1b1e23;   /* hover / row band */
  --bg-4:        #23272e;   /* pressed */

  /* Lines */
  --line-1:      #1f2228;
  --line-2:      #2a2e36;
  --line-3:      #3a3f49;

  /* Text */
  --fg-1:        #e8e8e8;
  --fg-2:        #b6bac1;
  --fg-3:        #7d828c;
  --fg-4:        #4f545d;

  /* Semantic */
  --pos:         #5fd6a4;
  --pos-dim:     #2b6b51;
  --pos-glow:    rgba(95,214,164,0.12);
  --neg:         #f43f5e;
  --neg-dim:     #6b2532;
  --neg-glow:    rgba(244,63,94,0.12);
  --warn:        #f59e0b;
  --warn-glow:   rgba(245,158,11,0.14);

  /* Brand accents (non-semantic) */
  --cy:          #5fbad6;
  --cy-dim:      #2a5b6b;
  --cy-glow:     rgba(95,186,214,0.12);

  /* Source-tag tones */
  --src-hl:      #5fd6a4;
  --src-lighter: #5fbad6;
  --src-bybit:   #f59e0b;
  --src-var:     #b48ce8;

  /* Type */
  --f-sans: "Geist", "Helvetica Neue", "Helvetica", Arial, sans-serif;
  --f-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, "Menlo", monospace;

  /* Size scale */
  --s-9:   9px;
  --s-10:  10px;
  --s-11:  11px;
  --s-12:  12px;
  --s-13:  13px;
  --s-14:  14px;
  --s-16:  16px;
  --s-20:  20px;
  --s-24:  24px;
  --s-32:  32px;
  --s-48:  48px;
  --s-64:  64px;
  --s-80:  80px;

  /* Spacing scale (4px → 32px) */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;

  /* Motion */
  --dur-fast: 90ms;
  --dur:      150ms;
  --dur-slow: 280ms;
  --ease:     cubic-bezier(0.2, 0.6, 0.2, 1);

  /* Bridge: route the legacy --font-main token through the new sans stack
     so existing markup picks up Geist without per-rule edits.
     Legacy color tokens (--bg-black etc.) stay in the inline <style> block
     for now; they're migrated layer-by-layer in subsequent phases. */
  --font-main: var(--f-sans);
}

/* Tabular numerals on every figure that represents money / data.
   Per the brief this is non-negotiable: digits must align column-to-column
   so prices, PnL, and balances don't shift width as values tick. */
.num,
.mono {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "zero", "ss01";
  letter-spacing: -0.01em;
}

/* Visible-only focus ring; uniform cyan across every interactive element. */
:focus-visible {
  outline: 1px solid var(--cy);
  outline-offset: 1px;
}

::selection {
  background: var(--cy);
  color: #001318;
}

/* Thin square scrollbars that match the terminal aesthetic. */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--line-3); }

/* =========================================================
   PHASE 2 — Shell: topbar / sidebar / main / statusbar.
   The body gets class="app" and the legacy <div class="container">
   is wrapped inside <main class="main"><div class="main__inner">.
   Existing equity/positions/groups markup continues to render inside;
   phases 3–5 replace those surfaces.
   ========================================================= */

body.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  grid-template-rows: 28px 1fr 22px;
  grid-template-areas:
    "topbar topbar"
    "sidebar main"
    "statusbar statusbar";
  height: 100vh;
  width: 100vw;
  /* Override the legacy centered flex layout — the grid is the container now. */
  align-items: stretch;
  flex-direction: row;
  background: var(--bg-0);
}

body.app > .topbar    { grid-area: topbar; }
body.app > .sidebar   { grid-area: sidebar; }
body.app > .main      { grid-area: main; overflow: auto; min-width: 0; }
body.app > .statusbar { grid-area: statusbar; }

/* When the shell is active, the legacy .container fills .main and stops
   centering itself horizontally. */
body.app .main > .container {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 16px 20px 32px;
}

/* ───── TOPBAR ───── */
.topbar {
  display: flex;
  align-items: stretch;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line-1);
  font-size: 11px;
}
.topbar__brand {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  border-right: 1px solid var(--line-1);
  font-weight: 600;
  letter-spacing: 0.04em;
  min-width: 248px;
}
.topbar__brand .dot {
  width: 7px; height: 7px;
  background: var(--cy);
  box-shadow: 0 0 8px var(--cy);
}
.topbar__brand .name { color: var(--fg-1); }
.topbar__brand .v    { color: var(--fg-3); font-family: var(--f-mono); }

.topbar__nav { display: flex; }
.topbar__tab {
  padding: 0 14px;
  display: flex; align-items: center; gap: 6px;
  color: var(--fg-3);
  border-right: 1px solid var(--line-1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  font-weight: 500;
  background: transparent;
  font-family: inherit;
}
.topbar__tab .key {
  color: var(--cy);
  font-family: var(--f-mono);
  font-size: 9px;
  background: var(--bg-2);
  padding: 1px 4px;
  border: 1px solid var(--line-2);
}
.topbar__tab:hover { color: var(--fg-1); background: var(--bg-2); }
.topbar__tab.is-active {
  color: var(--fg-1);
  background: var(--bg-2);
  box-shadow: inset 0 -1px 0 var(--cy);
}

.topbar__spacer { flex: 1; }

.topbar__right {
  display: flex; align-items: center; gap: 16px;
  padding: 0 12px;
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
}
.topbar__right .label { color: var(--fg-4); margin-right: 4px; text-transform: uppercase; }
.topbar__right .v       { color: var(--fg-2); }
.topbar__right .v.live  { color: var(--pos); }
.topbar__right .v.stale { color: var(--warn); }
.topbar__right .v.down  { color: var(--neg); }

.live-dot {
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--pos);
  margin-right: 4px;
  vertical-align: middle;
  animation: hldash-pulse 1.4s var(--ease) infinite;
}
.live-dot.stale { background: var(--warn); animation: none; }
.live-dot.down  { background: var(--neg);  animation: none; }
@keyframes hldash-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ───── SIDEBAR ───── */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar__head {
  padding: 12px 12px 8px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line-1);
}
.sidebar__title {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-3);
}
.sidebar__add {
  width: 18px; height: 18px;
  display: grid; place-items: center;
  color: var(--fg-3);
  border: 1px solid var(--line-2);
  font-family: var(--f-mono);
  background: transparent;
  cursor: pointer;
}
.sidebar__add:hover { color: var(--cy); border-color: var(--cy-dim); }

.sidebar__scroll { flex: 1; overflow-y: auto; }
.sidebar__empty {
  padding: 16px 12px;
  font-size: 10px;
  color: var(--fg-4);
  line-height: 1.5;
}

.acct-group {
  border-bottom: 1px solid var(--line-1);
  padding: 4px 0 8px;
}
.acct-group__head {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px 4px;
  color: var(--fg-3);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.acct-group__head .swatch { width: 6px; height: 6px; }
.acct-group__head .count  { color: var(--fg-4); margin-left: auto; font-family: var(--f-mono); }

.acct {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  cursor: pointer;
  border-left: 2px solid transparent;
  font-size: 12px;
}
.acct:hover { background: var(--bg-2); }
.acct.is-active { background: var(--bg-2); border-left-color: var(--cy); }
.acct__id { display: flex; flex-direction: column; min-width: 0; }
.acct__label {
  color: var(--fg-1);
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.acct__addr {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
}

.sidebar__foot {
  padding: 10px 12px;
  border-top: 1px solid var(--line-1);
  display: flex; flex-direction: column; gap: 6px;
  font-size: 10px;
  color: var(--fg-3);
}
.sidebar__foot .row {
  display: flex; justify-content: space-between;
  font-family: var(--f-mono);
}
.sidebar__foot .row .v { color: var(--fg-2); }

/* ───── FRESHBAR ───── */
.freshbar {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line-1);
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-wrap: wrap;
  row-gap: 6px;
}
.freshbar .group { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.freshbar .label { color: var(--fg-4); }
.freshbar .v     { color: var(--fg-2); }
.freshbar .v.pos { color: var(--pos); }
.freshbar .v.neg { color: var(--neg); }
.freshbar .sep   { width: 1px; height: 12px; background: var(--line-2); }
.freshbar .spacer { flex: 1; }
.freshbar .pill-warn {
  color: var(--warn);
  border: 1px solid var(--warn);
  padding: 2px 6px;
  font-size: 9px;
  background: var(--warn-glow);
}
.freshbar .pill-warn.is-down {
  color: var(--neg);
  border-color: var(--neg);
  background: var(--neg-glow);
}

/* ───── STATUSBAR ───── */
.statusbar {
  background: var(--bg-1);
  border-top: 1px solid var(--line-1);
  display: flex; align-items: center;
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
  padding: 0 12px;
  gap: 16px;
  overflow: hidden;
}
.statusbar .seg-block { display: flex; gap: 6px; align-items: center; }
.statusbar .label   { color: var(--fg-4); }
.statusbar .v       { color: var(--fg-2); }
.statusbar .v.pos   { color: var(--pos); }
.statusbar .v.warn  { color: var(--warn); }
.statusbar .v.neg   { color: var(--neg); }
.statusbar .spacer  { flex: 1; }
.statusbar .ticker {
  display: flex; gap: 18px; overflow: hidden; white-space: nowrap;
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}
.statusbar .ticker .tk  { display: inline-flex; gap: 6px; }
.statusbar .ticker .sym { color: var(--fg-2); }
.statusbar .ticker .pos { color: var(--pos); }
.statusbar .ticker .neg { color: var(--neg); }

/* =========================================================
   PHASE 3 — Equity hero.
   A two-column card at the top of .main: number + curve + meta cells
   on the left, 24H / 7D / ALL period tiles on the right. Painted by
   renderAccountEquitySummary() in index.html.
   ========================================================= */

.hero {
  margin: 16px 24px 0;
  border: 1px solid var(--line-1);
  background:
    radial-gradient(800px 200px at 90% -20%, var(--cy-glow), transparent 60%),
    var(--bg-1);
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr);
}
.hero.hero--empty {
  padding: 18px 24px;
  color: var(--fg-3);
  font-family: var(--f-mono);
  font-size: 12px;
  display: block;
}

.hero__main {
  padding: 20px 24px 18px;
  border-right: 1px solid var(--line-1);
  position: relative;
  min-height: 220px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.hero__label {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--fg-3);
  margin-bottom: 6px;
}
.hero__label .src {
  font-family: var(--f-mono);
  font-size: 9px;
  border: 1px solid var(--src-hl);
  color: var(--src-hl);
  padding: 1px 5px;
  letter-spacing: 0.06em;
}
.hero__label .addr {
  font-family: var(--f-mono);
  color: var(--fg-3);
  font-size: 10px;
  letter-spacing: 0;
  text-transform: none;
}
.hero__label .addr--muted { color: var(--fg-4); }
.hero__label .info-i {
  display: inline-grid; place-items: center;
  width: 12px; height: 12px;
  border: 1px solid var(--line-3);
  border-radius: 50%;
  font-size: 8px;
  color: var(--fg-3);
  cursor: help;
}

.hero__num {
  font-family: var(--f-mono);
  font-size: clamp(34px, 4.8vw, 56px);
  font-weight: 500;
  letter-spacing: -0.03em;
  color: var(--fg-1);
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.hero__num .currency { font-size: 0.36em; color: var(--fg-3); font-weight: 400; }
.hero__num .frac     { color: var(--fg-3); font-weight: 400; font-size: 0.55em; }

.hero__pnl {
  display: flex; align-items: center; gap: 12px;
  margin-top: 10px;
  font-family: var(--f-mono);
  font-size: 16px;
}
.hero__pnl .arrow {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px;
  border: 1px solid currentColor;
}
.hero__pnl.pos { color: var(--pos); }
.hero__pnl.neg { color: var(--neg); }
.hero__pnl .abs { font-weight: 500; }
.hero__pnl .pct { color: var(--fg-2); }
.hero__pnl .since {
  margin-left: 6px;
  color: var(--fg-4);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hero__chart {
  height: 80px;
  margin: 12px -24px 0;
  border-top: 1px solid var(--line-1);
  border-bottom: 1px solid var(--line-1);
  background: var(--bg-0);
  pointer-events: none;
  position: relative;
  overflow: hidden;
}
.hero__chart::after {
  content: 'EQUITY · ' attr(data-period);
  position: absolute;
  top: 6px; left: 12px;
  font-family: var(--f-mono);
  font-size: 9px;
  color: var(--fg-4);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.hero__chart::before {
  /* Placeholder horizontal rule until §4.2 equity history lands. */
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: var(--line-1);
}

.hero__meta {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0;
  position: relative;
  z-index: 1;
}
.hero__meta .cell {
  border-left: 1px solid var(--line-1);
  padding: 6px 10px;
  min-width: 0;
}
.hero__meta .cell:first-child { border-left: 0; padding-left: 0; }
.hero__meta .cell .lbl {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--fg-4);
  white-space: nowrap;
}
.hero__meta .cell .v {
  font-family: var(--f-mono);
  font-size: 13px;
  color: var(--fg-1);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hero__meta .cell .v.warn { color: var(--warn); }
.hero__meta .cell .v.pos  { color: var(--pos); }
.hero__meta .cell .v.neg  { color: var(--neg); }
.hero__meta .cell .sub {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
}

/* Period tiles (right column). Realized PnL per period and daily PnL
   baseline are §4.1/§4.2 — backend work. Tiles render '--' until then,
   click is wired and persisted in localStorage.hldash.period. */
.hero__tiles {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
}
.hero__tile {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-1);
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 80px;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: transparent;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}
.hero__tile:last-child { border-bottom: 0; }
.hero__tile.is-active {
  background: var(--bg-2);
  box-shadow: inset 2px 0 0 var(--cy);
}
.hero__tile:hover:not(.is-active) { background: var(--bg-2); }
.hero__tile .period {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-3);
  font-family: var(--f-mono);
}
.hero__tile .period .pct {
  display: block;
  color: var(--fg-4);
  font-size: 9px;
  margin-top: 2px;
}
.hero__tile .vals { display: flex; flex-direction: column; }
.hero__tile .vals .abs {
  font-family: var(--f-mono);
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--fg-3);
}
.hero__tile.pos .vals .abs { color: var(--pos); }
.hero__tile.neg .vals .abs { color: var(--neg); }
.hero__tile .vals .row2 {
  display: flex; gap: 6px; flex-wrap: wrap;
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
  line-height: 1.4;
  margin-top: 2px;
}
.hero__tile .vals .row2 .real { color: var(--fg-2); }
.hero__tile .spark {
  width: 80px; height: 26px;
  border-top: 1px solid var(--line-1);
  position: relative;
}
.hero__tile .spark::after {
  /* Placeholder midline. Phase 4.1/4.2 ships real sparkline data. */
  content: '';
  position: absolute;
  left: 4px; right: 4px; top: 50%;
  height: 1px; background: var(--line-2);
}

/* Hero responsive: stack the period tiles below the main pane. */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .hero__main { border-right: 0; border-bottom: 1px solid var(--line-1); }
}

/* =========================================================
   PHASE 4 — Groups view.
   Full-width grid of group cards above the positions list.
   Painted by renderGroupsCards() in index.html.
   ========================================================= */

.groups-section { margin: 16px 24px 0; }
.groups-section__head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.groups-section__title {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--fg-2); font-weight: 500;
}
.groups-section__sub { font-family: var(--f-mono); font-size: 10px; color: var(--fg-4); }
.groups-section__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.groups-section__btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  border: 1px solid var(--line-2); color: var(--fg-2);
  background: transparent; font-family: var(--f-mono); cursor: pointer;
}
.groups-section__btn:hover { color: var(--fg-1); border-color: var(--line-3); background: var(--bg-2); }
.groups-section__btn.is-active {
  border-color: var(--cy-dim); color: var(--cy); background: var(--cy-glow);
}

.groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0;
  border: 1px solid var(--line-1);
  border-bottom: 0;
}
.groups--empty {
  border-bottom: 1px solid var(--line-1);
  padding: 16px;
  color: var(--fg-3);
  font-family: var(--f-mono);
  font-size: 11px;
}
.group-card {
  border-right: 1px solid var(--line-1);
  border-bottom: 1px solid var(--line-1);
  padding: 12px 14px 10px;
  background: var(--bg-1);
  cursor: pointer;
  position: relative;
  transition: background var(--dur) var(--ease);
  text-align: left;
  font-family: inherit;
  color: inherit;
}
.group-card:hover { background: var(--bg-2); }
.group-card.is-selected { background: var(--bg-2); box-shadow: inset 2px 0 0 var(--cy); }

.group-card__head { display: flex; align-items: center; gap: 8px; }
.group-card__dot  { width: 8px; height: 8px; }
.group-card__name {
  font-size: 12px; font-weight: 500; color: var(--fg-1);
  text-transform: uppercase; letter-spacing: 0.04em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.group-card__count { margin-left: auto; font-family: var(--f-mono); font-size: 10px; color: var(--fg-3); }
.group-card__pnl {
  font-family: var(--f-mono);
  font-size: 22px;
  margin-top: 8px;
  letter-spacing: -0.01em;
}
.group-card__pnl.pos { color: var(--pos); }
.group-card__pnl.neg { color: var(--neg); }
.group-card__pnl .pct { font-size: 11px; color: var(--fg-3); margin-left: 6px; }
.group-card__row {
  display: flex; justify-content: space-between; gap: 8px;
  font-family: var(--f-mono); font-size: 10px; color: var(--fg-3);
  margin-top: 3px; white-space: nowrap;
}
.group-card__row > span:first-child {
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-4);
}
.group-card__row .v       { color: var(--fg-2); }
.group-card__row .v.pos   { color: var(--pos); }
.group-card__row .v.neg   { color: var(--neg); }
.group-card__row .v .sub  { color: var(--fg-4); margin: 0 2px; }

.group-card__bar { display: flex; height: 4px; margin-top: 10px; background: var(--bg-3); overflow: hidden; }
.group-card__bar .long  { background: var(--pos); }
.group-card__bar .short { background: var(--neg); }

.group-card__spark {
  margin-top: 8px; height: 28px; width: 100%; position: relative;
  border-top: 1px solid var(--line-1);
}
.group-card__spark::after {
  content: '';
  position: absolute; left: 4px; right: 4px; top: 50%;
  height: 1px; background: var(--line-2);
}

/* §12.3 — inline actions at the bottom of each group card. Replaces
   the legacy MB / FC pill buttons. Four equal-flex chips, monospace,
   hairline divider on top and between, edge-to-edge inside the card. */
/* §14.2 — per-side ticker breakdown rows sit between the L/S exposure
   bar and the action chips. Always visible (independent of card
   selection). Compact mono, descending-weight order, ellipsis on
   overflow. */
.gc-sides {
  margin: 8px -14px 0;
  padding: 6px 14px 4px;
  border-top: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.gc-side {
  display: grid;
  grid-template-columns: 14px 44px minmax(0, 1fr);
  align-items: baseline;
  gap: 6px;
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
  white-space: nowrap;
  overflow: hidden;
}
.gc-side .g { font-size: 10px; }
.gc-side .lbl {
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-4);
}
.gc-side--long  .g { color: var(--pos); }
.gc-side--short .g { color: var(--neg); }
.gc-side--empty .empty { color: var(--fg-4); }
.gc-side .list {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.gc-side .list .t {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  color: var(--fg-2);
}
.gc-side .list .t .w {
  color: var(--fg-4);
  font-size: 9px;
}
.gc-side .list .sep {
  color: var(--fg-4);
  margin: 0 6px;
}

/* §14.3 — expanded weight / target / Δ panel for the SELECTED group card.
   Per-side mini table with right-aligned numerics; β value and refresh
   affordance at the bottom. Recessed background so it reads as an inset
   under the card, not a separate card. */
.gc-detail {
  margin: 6px -14px 0;
  padding: 8px 14px 8px;
  background: var(--bg-0);
  border-top: 1px solid var(--line-1);
  border-bottom: 1px solid var(--line-1);
  font-family: var(--f-mono);
}
.gc-detail__side { margin-bottom: 6px; }
.gc-detail__side:last-of-type { margin-bottom: 0; }
.gc-detail__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 168px;
  align-items: baseline;
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--fg-4);
  margin-bottom: 2px;
}
.gc-detail__side--long  .gc-detail__head .lbl { color: var(--pos); }
.gc-detail__side--short .gc-detail__head .lbl { color: var(--neg); }
.gc-detail__head .cols {
  display: grid;
  grid-template-columns: 48px 48px 56px;
  text-align: right;
  gap: 8px;
}
.gc-detail__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px 48px 56px;
  gap: 8px;
  font-size: 10px;
  align-items: baseline;
  padding: 2px 0;
}
.gc-detail__row .coin {
  color: var(--fg-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gc-detail__row .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.gc-detail__row .num.w      { color: var(--fg-1); }
.gc-detail__row .num.target { color: var(--fg-3); }
.gc-detail__row .num.delta.pos  { color: var(--pos); }
.gc-detail__row .num.delta.warn { color: var(--warn); }
.gc-detail__row .num.delta.dim  { color: var(--fg-3); }

.gc-beta {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--line-2);
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 10px;
  color: var(--fg-3);
}
.gc-beta .k { color: var(--cy); font-weight: 600; }
.gc-beta .v {
  color: var(--fg-1);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.gc-beta .meta { color: var(--fg-4); font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; }
.gc-beta .meta.dot { padding: 0 2px; }
.gc-beta .refresh {
  margin-left: auto;
  background: transparent; border: 0; padding: 0;
  color: var(--cy); cursor: pointer;
  font-family: var(--f-mono); font-size: 10px;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.gc-beta .refresh:hover { color: var(--fg-1); }
.gc-beta .refresh:disabled { color: var(--fg-4); cursor: wait; }

/* §14.1 — Weight / Target / Δ columns in the positions table. */
.pos-table .num.target { color: var(--fg-3); }
.pos-table .num.delta.pos  { color: var(--pos); }
.pos-table .num.delta.warn { color: var(--warn); }
.pos-table .num.delta.dim  { color: var(--fg-3); }

.group-card__actions {
  display: flex;
  gap: 0;
  margin: 8px -14px -10px;
  border-top: 1px solid var(--line-1);
}
.gca {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px;
  border: 0;
  border-right: 1px solid var(--line-1);
  background: transparent;
  color: var(--fg-3);
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.gca:last-child { border-right: 0; }
.gca:hover { background: var(--bg-3); color: var(--fg-1); }
.gca .lbl { letter-spacing: 0.04em; }
.gca--danger:hover { background: var(--neg-glow); color: var(--neg); }

.group-card--new {
  display: grid; place-items: center;
  color: var(--fg-3); text-align: center; min-height: 140px;
}
.group-card--new .plus {
  font-family: var(--f-mono); font-size: 24px; color: var(--fg-3);
  border: 1px dashed var(--line-3); width: 36px; height: 36px;
  display: grid; place-items: center; margin-bottom: 6px;
}
.group-card--new .t { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; }

/* §13.3 — the legacy .header-section, .dashboard-grouped-positions-pane,
   and .dashboard-panels-row subtrees were deleted from index.html.
   No CSS guard needed anymore; the markup is gone. */
body.app .dashboard-panels-row { display: none !important; }

/* =========================================================
   PHASE 5 — Positions cards + Cards/Table toggle.
   Cards render alongside the legacy table; the toggle persists in
   localStorage.hldash.posView. The legacy table view is preserved
   intact (its refreshPositionsInPlace fast-path, group dropdowns,
   sort handlers, multibeta/FC buttons all still work).
   ========================================================= */

.pos-section { margin: 16px 24px 24px; }
.pos-section__head {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 8px;
}
.pos-section__title {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--fg-2); font-weight: 500;
}
.pos-section__sub { font-family: var(--f-mono); font-size: 10px; color: var(--fg-4); }
.pos-section__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.pos-section__btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  border: 1px solid var(--line-2); color: var(--fg-2);
  background: transparent; font-family: var(--f-mono); cursor: pointer;
}
.pos-section__btn:hover { color: var(--fg-1); border-color: var(--line-3); background: var(--bg-2); }

.pos-seg { display: inline-flex; border: 1px solid var(--line-2); }
.pos-seg__btn {
  padding: 4px 10px; font-family: var(--f-mono);
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fg-3); background: transparent; cursor: pointer;
  border-right: 1px solid var(--line-2);
}
.pos-seg__btn:last-child { border-right: 0; }
.pos-seg__btn.is-active { background: var(--bg-3); color: var(--fg-1); }
.pos-seg__btn:hover:not(.is-active) { color: var(--fg-1); }

.pos-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  border: 1px solid var(--line-1);
}
.pos-cards--empty {
  grid-template-columns: 1fr;
  padding: 16px;
  color: var(--fg-3);
  font-family: var(--f-mono);
  font-size: 11px;
}

.pos-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  border-right: 1px solid var(--line-1);
  border-bottom: 1px solid var(--line-1);
  background: var(--bg-1);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.pos-card:hover { background: var(--bg-2); }
.pos-card.is-open {
  background: var(--bg-2);
  /* When the drawer opens, the card takes the full row so the chart
     + side-table aren\'t cramped and the neighbor card doesn\'t squish. */
  grid-column: 1 / -1;
}

.pos-card__side {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-family: var(--f-mono);
  font-size: 10px; letter-spacing: 0.1em;
  border-right: 1px solid var(--line-1);
  gap: 4px;
}
.pos-card__side.long {
  background: linear-gradient(180deg, var(--pos-glow), transparent 70%);
  color: var(--pos);
}
.pos-card__side.short {
  background: linear-gradient(180deg, var(--neg-glow), transparent 70%);
  color: var(--neg);
}
.pos-card__side .lev {
  color: var(--fg-2);
  background: var(--bg-3);
  padding: 1px 4px;
  border: 1px solid var(--line-2);
  font-size: 9px;
}

.pos-card__body {
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px 16px;
  min-width: 0;
}
.pos-card__head {
  grid-column: 1 / -1;
  display: flex; align-items: baseline; gap: 8px;
}
.pos-card__coin {
  font-size: 18px; font-weight: 500;
  color: var(--fg-1); letter-spacing: -0.01em;
}
.pos-card__size {
  font-family: var(--f-mono);
  font-size: 11px; color: var(--fg-3);
}
.pos-card__group {
  margin-left: auto;
  font-family: var(--f-mono); font-size: 10px;
  color: var(--fg-3);
  display: flex; align-items: center; gap: 4px;
  border: 1px solid var(--line-2); padding: 1px 6px;
}
.pos-card__group .dot { width: 6px; height: 6px; }

.pos-card__pnl {
  grid-column: 1 / 3;
  font-family: var(--f-mono);
  font-size: 22px; letter-spacing: -0.01em;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.pos-card__pnl.pos { color: var(--pos); }
.pos-card__pnl.neg { color: var(--neg); }
.pos-card__pnl .pct { color: var(--fg-3); font-size: 12px; }

.pos-card__spark {
  grid-column: 3 / 5;
  grid-row: 2 / 4;
  width: 100%; height: 56px;
  align-self: center;
  border-top: 1px solid var(--line-1);
  position: relative;
}
.pos-card__spark::after {
  /* Placeholder midline. Per-position price chart ships with §4.4. */
  content: '';
  position: absolute;
  left: 4px; right: 4px; top: 50%;
  height: 1px; background: var(--line-2);
}

.pos-card__kv { display: flex; flex-direction: column; font-family: var(--f-mono); }
.pos-card__kv .k {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-4);
}
.pos-card__kv .v { font-size: 12px; color: var(--fg-1); }
.pos-card__kv .v.warn { color: var(--warn); }
.pos-card__kv .v.pos  { color: var(--pos); }
.pos-card__kv .v.neg  { color: var(--neg); }

.pos-card__more {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line-1);
  margin: 4px -14px 0;
  padding: 6px 14px;
  display: flex; align-items: center; gap: 12px;
  font-family: var(--f-mono);
  font-size: 10px; color: var(--fg-3);
  flex-wrap: wrap;
}
.pos-card__more .k { color: var(--fg-4); margin-right: 4px; }
.pos-card__more .sep { width: 1px; height: 10px; background: var(--line-2); }
.pos-card__more .chev { margin-left: auto; color: var(--fg-3); font-family: var(--f-mono); }

/* Expanded drawer. Per-position price chart (§4.4) and live funding-rate
   breakdown (§4.3) are backend work — the drawer renders the structure
   with placeholders until those land. */
.pos-expand {
  grid-column: 1 / -1;
  background: var(--bg-0);
  border-top: 1px solid var(--line-1);
  padding: 16px;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
}
.pos-expand__chart {
  height: 220px;
  position: relative;
  border: 1px solid var(--line-1);
  background: var(--bg-1);
}
.pos-expand__chart canvas { width: 100% !important; height: 100% !important; }
.pos-expand__chart--empty::before {
  /* Faint midline only while the canvas is being hydrated. */
  content: '';
  position: absolute;
  left: 12px; right: 12px; top: 50%;
  height: 1px; background: var(--line-2);
}
.pos-expand__sidetable {
  font-family: var(--f-mono);
  font-size: 11px;
  display: flex; flex-direction: column;
}
.pos-expand__sidetable .ttl {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--fg-3); margin-bottom: 6px;
}
.pos-expand__sidetable table {
  width: 100%; border-collapse: collapse;
}
.pos-expand__sidetable td {
  padding: 4px 6px; border-bottom: 1px solid var(--line-1);
  white-space: nowrap;
}
.pos-expand__sidetable td:first-child { color: var(--fg-3); width: 80px; }
.pos-expand__sidetable td.pos { color: var(--pos); }
.pos-expand__sidetable td.neg { color: var(--neg); }
.pos-expand__sidetable td.right { text-align: right; }
.pos-expand__sidetable td.dim { color: var(--fg-4); }

/* The legacy positions table wraps its own .table-scroll. When the user
   toggles to Cards, we hide that wrap; switching to Table shows it. */
body.app .positions-section-centered > h2 { display: none; }
body.app .positions-section-centered { padding-top: 0 !important; }

/* Responsive: single-column cards under 720px. */
@media (max-width: 720px) {
  .pos-cards { grid-template-columns: 1fr; }
  .pos-card__body { grid-template-columns: 1fr 1fr; }
  .pos-card__spark { grid-column: 1 / -1; grid-row: auto; height: 40px; margin-top: 8px; }
  .pos-card__pnl { grid-column: 1 / -1; }
}

/* =========================================================
   PHASE 6 — Dialog primitive + Add Source flow.
   One scrim + dialog component; ESC closes, click-outside closes, focus
   is restored on close. Add Source replaces the legacy prompt('Label?')
   for saved addresses.
   ========================================================= */

.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  z-index: 1000;
  animation: hldash-scrim-in var(--dur) var(--ease);
}
@keyframes hldash-scrim-in { from { opacity: 0; } }

.dialog {
  background: var(--bg-1);
  border: 1px solid var(--line-3);
  min-width: 480px;
  max-width: 640px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  animation: hldash-dialog-in var(--dur-slow) var(--ease);
  font-family: var(--f-sans);
  color: var(--fg-1);
}
.dialog.dialog--wide { min-width: 620px; }
@keyframes hldash-dialog-in {
  from { opacity: 0; transform: translateY(4px); }
}

.dialog__head {
  display: flex; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-2);
  background: var(--bg-2);
  font-family: var(--f-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-2);
}
.dialog__head .key { color: var(--cy); margin-right: 8px; }
.dialog__close {
  margin-left: auto;
  color: var(--fg-3);
  font-family: var(--f-mono);
  background: transparent;
  border: 0; cursor: pointer;
}
.dialog__close:hover { color: var(--fg-1); }
.dialog__body { padding: 18px 18px 14px; }
.dialog__foot {
  display: flex; gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line-2);
  justify-content: flex-end;
  background: var(--bg-1);
}
.dialog .btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  border: 1px solid var(--line-2); color: var(--fg-2);
  background: transparent;
  font-family: var(--f-mono);
  cursor: pointer;
}
.dialog .btn:hover { color: var(--fg-1); border-color: var(--line-3); background: var(--bg-2); }
.dialog .btn--cy { border-color: var(--cy-dim); color: var(--cy); }
.dialog .btn--cy:hover { background: var(--cy-glow); border-color: var(--cy); }
.dialog .btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* Form fields shared across dialogs. */
.field { margin-bottom: 12px; }
.field__lbl {
  display: block;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--fg-3); margin-bottom: 6px;
}
.field__input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-0);
  border: 1px solid var(--line-2);
  color: var(--fg-1);
  font-family: var(--f-mono);
  font-size: 12px;
  letter-spacing: 0;
}
.field__input:focus { border-color: var(--cy); outline: none; }
.field__hint {
  margin-top: 4px;
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
}
.field__hint.ok  { color: var(--pos); }
.field__hint.err { color: var(--neg); }

/* Source picker chips (Add Source dialog body). */
.src-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.src-chip {
  border: 1px solid var(--line-2);
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  background: transparent;
  font-family: inherit;
  color: inherit;
}
.src-chip:hover { border-color: var(--line-3); background: var(--bg-2); }
.src-chip.is-selected {
  border-color: var(--cy);
  background: var(--cy-glow);
}
.src-chip__name {
  font-size: 12px;
  color: var(--fg-1);
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px;
}
.src-chip__name .dot { width: 7px; height: 7px; }
.src-chip__desc {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--fg-3);
  line-height: 1.4;
}

.dropzone {
  border: 1px dashed var(--line-3);
  padding: 22px 14px;
  text-align: center;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--fg-3);
  background: var(--bg-0);
}
.dropzone .big {
  font-size: 16px;
  color: var(--fg-2);
  margin-bottom: 6px;
}
.dropzone .accent { color: var(--cy); cursor: pointer; }

/* §12.4 — Settings & utilities dialog. Tab strip across the top, per-tab
   body below. Replaces the legacy Changelog/Help/Export/Import/Bybit
   buttons that lived in the hidden toolbar. */
.sd-tabs {
  display: flex;
  border-bottom: 1px solid var(--line-2);
  margin: -18px -18px 16px;
}
.sd-tab {
  padding: 10px 14px;
  font-family: var(--f-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-3);
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  margin-bottom: -1px;
}
.sd-tab:last-child { border-right: 0; }
.sd-tab:hover { color: var(--fg-1); }
.sd-tab.is-active {
  color: var(--fg-1);
  border-bottom-color: var(--cy);
}

.sd-pane { font-family: var(--f-mono); font-size: 11px; }
.sd-pane p { margin: 0 0 14px; color: var(--fg-3); line-height: 1.6; }
.sd-pane .scroll { max-height: 340px; overflow-y: auto; }

.sd-changelog .entry { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line-1); }
.sd-changelog .entry:last-child { border-bottom: 0; padding-bottom: 0; }
.sd-changelog .v   { color: var(--cy); font-size: 13px; }
.sd-changelog .d   { color: var(--fg-4); margin-left: 10px; }
.sd-changelog ul   { margin: 6px 0 0; padding: 0; list-style: none; }
.sd-changelog li   { color: var(--fg-2); line-height: 1.7; padding-left: 14px; position: relative; }
.sd-changelog li::before { content: '·'; position: absolute; left: 0; color: var(--fg-4); }

.sd-help table { width: 100%; border-collapse: collapse; }
.sd-help td    { padding: 4px 0; color: var(--fg-2); line-height: 1.5; }
.sd-help td.k  { color: var(--cy); padding-right: 12px; white-space: nowrap; vertical-align: top; }
.sd-help h4    { color: var(--fg-4); text-transform: uppercase; letter-spacing: 0.1em; font-size: 9px; margin: 14px 0 6px; font-weight: 500; }
.sd-help h4:first-child { margin-top: 0; }

.sd-export { display: flex; flex-direction: column; gap: 8px; }
.sd-keys {
  border: 1px solid var(--line-2);
}
.sd-keys .row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center; gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-1);
}
.sd-keys .row:last-child { border-bottom: 0; }
.sd-keys .label { color: var(--fg-1); }
.sd-keys .hint  { color: var(--fg-3); font-size: 10px; margin-top: 2px; }
.sd-keys .readonly {
  color: var(--pos);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Topbar settings button (right cluster ⚙). */
.topbar__icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--fg-3);
  font-family: var(--f-mono);
  font-size: 12px;
  cursor: pointer;
}
.topbar__icon-btn:hover { color: var(--cy); border-color: var(--cy-dim); }

/* =========================================================
   PHASE 7 — Error banner + loading skeletons.
   Banner sits between the freshbar and the hero. Driven by the Phase 2
   shell's tick() loop (which already tracks lastSuccessAt + lastError).
   Skeletons replace empty placeholders when an account is loading data.
   ========================================================= */

.banner {
  margin: 12px 24px 0;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 12px;
  font-family: var(--f-mono);
  font-size: 11px;
  animation: hldash-banner-in var(--dur) var(--ease);
}
.banner.warn {
  border: 1px solid var(--warn);
  background: var(--warn-glow);
  color: var(--warn);
}
.banner.err {
  border: 1px solid var(--neg);
  background: var(--neg-glow);
  color: var(--neg);
}
.banner .b-kind { font-weight: 600; }
.banner .b-msg  { color: var(--fg-2); }
.banner__close {
  margin-left: auto;
  font-family: var(--f-mono);
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
  opacity: 0.7;
}
.banner__close:hover { opacity: 1; }
@keyframes hldash-banner-in {
  from { opacity: 0; transform: translateY(-2px); }
}

/* Skeleton loader. A `.sk` element renders a shimmering placeholder
   rectangle whose width/height are set inline. Used inside .hero--empty
   and .pos-cards--empty when an initial load is in progress. */
.sk {
  background: linear-gradient(90deg, var(--bg-2) 0%, var(--bg-3) 50%, var(--bg-2) 100%);
  background-size: 200% 100%;
  animation: hldash-sk 1.4s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes hldash-sk {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* Skeleton layout overrides for the hero + positions placeholders. */
.hero.hero--loading {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr);
  padding: 0;
}
.hero.hero--loading .hero__main { padding: 20px 24px; }
.hero.hero--loading .sk-row { display: flex; gap: 16px; margin-top: 14px; }
.hero.hero--loading .hero__tiles { padding: 14px; display: grid; gap: 12px; grid-template-rows: repeat(3, 1fr); }

.pos-cards.pos-cards--loading {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 0;
}
.pos-cards.pos-cards--loading > div {
  padding: 14px;
  border-right: 1px solid var(--line-1);
  border-bottom: 1px solid var(--line-1);
}

/* §3.4 — table view: lightweight, sticky-header, mono numerics, L/S pill
   leading the coin cell instead of a row-background tint. */
.pos-table-wrap {
  border: 1px solid var(--line-1);
  background: var(--bg-1);
  overflow: auto;
  max-height: 70vh;
}
.pos-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--f-mono);
  font-size: 11px;
}
.pos-table thead th {
  position: sticky; top: 0;
  background: var(--bg-2);
  color: var(--fg-3);
  font-weight: 500;
  text-align: right;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 9px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
.pos-table thead th:first-child,
.pos-table thead th.left { text-align: left; }
.pos-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-1);
  text-align: right;
  color: var(--fg-1);
  white-space: nowrap;
}
.pos-table tbody td.left { text-align: left; }
.pos-table tbody tr:hover { background: var(--bg-2); }
.pos-table tbody tr.is-selected { background: var(--bg-2); box-shadow: inset 2px 0 0 var(--cy); }
.pos-table tbody td.pos { color: var(--pos); }
.pos-table tbody td.neg { color: var(--neg); }
.pos-table tbody td.warn { color: var(--warn); }
.pos-table tbody td.dim { color: var(--fg-3); }
.pos-table .empty {
  padding: 16px;
  color: var(--fg-3);
  font-family: var(--f-mono);
  font-size: 11px;
  text-align: left;
}
.side-pill {
  display: inline-block;
  min-width: 16px;
  padding: 1px 4px;
  margin-right: 6px;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-align: center;
  border: 1px solid currentColor;
  vertical-align: 1px;
}
.side-pill.long  { color: var(--pos); }
.side-pill.short { color: var(--neg); }
.coin-cell .lev {
  color: var(--fg-3);
  font-size: 9px;
  margin-left: 4px;
  letter-spacing: 0.04em;
}

/* Flash-on-change cells (used by refreshPositionsInPlace per the brief).
   Apply .flash-pos or .flash-neg to a cell after writing a new value;
   the animation drops the highlight back to transparent over 600ms. */
.flash-pos { animation: hldash-flash-pos 600ms var(--ease); }
.flash-neg { animation: hldash-flash-neg 600ms var(--ease); }
@keyframes hldash-flash-pos {
  0%   { background: var(--pos-glow); }
  100% { background: transparent; }
}
@keyframes hldash-flash-neg {
  0%   { background: var(--neg-glow); }
  100% { background: transparent; }
}

/* Responsive: under 900px, collapse the sidebar above main. */
@media (max-width: 900px) {
  body.app {
    grid-template-columns: 1fr;
    grid-template-rows: 28px auto 1fr 22px;
    grid-template-areas:
      "topbar"
      "sidebar"
      "main"
      "statusbar";
    height: auto;
    min-height: 100vh;
  }
  .topbar__brand { min-width: 0; }
  .sidebar { max-height: 240px; }
}

/* =========================================================
   §13.4 — legacy tail.
   Was an inline <style> block in index.html (lines 17–755).
   Relocated here per the v3 audit:
    - dead :root tokens (--bg-black / --bg-card / --accent-blue / etc.)
      removed; remaining consumers re-pointed at the design-system
      tokens (--bg-0 / --bg-2 / --cy / --line-2 / --fg-1 / --fg-3)
    - global input/button reset dropped (drift risk; new chrome
      targets specific classes)
   What remains is rules the still-present legacy DOM relies on:
    - .container reset (legacy positions table wrap)
    - .modal-overlay/.modal-content family (showModal toasts that
      haven't migrated yet)
    - #positions-table / .pnl-cell / .funding-cell / .long-bg /
      .short-bg (legacy table, hidden but still rendered to)
    - .group-name / .group-action-btn / .group-summary-* / .group-chart-*
   These will be trimmed further as their callers migrate.
   ========================================================= */
    /* §13.4 — legacy :root vars dropped (replaced by styles.css design tokens). The --font-main = var(--f-sans) bridge already lives in styles.css. */

    /* Removed Car Mode Styles */

    /* §13.4 — legacy html,body + centered body removed; body.app (styles.css) and login.html's .login-app set their own layout. */
    .container {
      width: 100%;
      max-width: 1500px;
      margin: 32px auto 0 auto;
      padding: 0 0 32px 0;
      display: flex;
      flex-direction: column;
      gap: 0;
      align-items: stretch;
    }
    .header-section.section,
    .section {
      box-sizing: border-box;
      padding-left: 24px !important;
      padding-right: 24px !important;
      margin-left: auto;
      margin-right: auto;
      width: 100%;
      max-width: 1500px;
    }
    .header-section.section {
      padding-top: 24px !important;
      padding-bottom: 18px !important;
      gap: 24px !important;
      display: flex;
      flex-direction: row;
      align-items: flex-start;
      margin-bottom: 2px;
    }
    .dashboard-header-left {
      flex: 1 1 0;
      min-width: 0;
      display: flex;
      flex-direction: column;
      gap: 0;
    }
    .dashboard-header-address {
      margin-bottom: 18px;
    }
    .dashboard-header-groups {
      margin-bottom: 0;
    }
    .dashboard-panels-row {
      display: flex;
      flex-direction: row;
      gap: 32px;
      align-items: flex-start;
      width: 100%;
    }
    .main-content-panels {
      flex: 1 1 0;
      min-width: 0;
      display: flex;
      flex-direction: column;
      gap: 20px;
      align-items: center;
    }
    .section {
      background: var(--bg-2);
      border-radius: 0;
      border: 1px solid var(--line-2);
      padding: 18px 16px 16px 16px;
      margin-bottom: 0;
      position: relative;
      box-shadow: none;
    }
    .row {
      display: flex;
      gap: 16px;
      flex-wrap: wrap;
    }
    .col {
      flex: 1 1 0;
      min-width: 320px;
    }
    h1 {
      color: var(--cy);
      font-weight: 600;
      font-size: 1.625rem;
      margin: 0 0 22px 0;
      letter-spacing: 0.01em;
      text-align: left;
    }
    h2 {
      color: var(--fg-1);
      font-weight: 500;
      font-size: 1.05rem;
      margin: 0 0 10px 0;
      letter-spacing: 0.01em;
    }
    .positions-section-centered {
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 100%;
    }
    #positions-section {
      width: 100%;
      max-width: 1500px;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    #positions-section h2 {
      text-align: left;
      width: 100%;
      margin-bottom: 10px;
    }
    .table-scroll {
      overflow-x: auto;
      width: 100%;
      display: block;
    }
    table#positions-table {
      margin: 0;
      width: max-content; /* allow full table to be scrollable if wider than container */
      min-width: 100%; /* but never smaller than container */
      max-width: none;
    }
    @media (max-width: 1200px) {
      .dashboard-panels-row { flex-direction: column; gap: 20px; }
      .ai-panel { width: 100% !important; min-width: 0 !important; max-width: 100vw !important; }
      .header-section.section { flex-direction: column !important; gap: 16px !important; }
      #equity-section { max-width: 100% !important; min-width: 0 !important; margin-top: 18px !important; }
      #positions-section { max-width: 100vw; }
    }
    /* Inputs, Buttons */
    /* §13.4 — legacy global input/button reset removed (drift risk; new chrome targets specific classes). */
    /* Table Styling */
    table {
      /* width removed to allow natural content width */
      border-collapse: separate;
      border-spacing: 0;
      background: var(--bg-1);
      border-radius: 0;
      overflow: hidden;
      box-shadow: none;
      margin-top: 6px;
      border: 1px solid var(--line-2);
      font-size: 13px;
      table-layout: auto;
    }
    th, td {
      padding: 8px 10px;
      border-bottom: 1px solid #23262f;
      text-align: left;
      font-size: 13px;
      color: var(--fg-1);
      white-space: nowrap;
    }
    th {
      background: #181818;
      color: var(--fg-3);
      font-weight: 500;
      border-bottom: 1.5px solid var(--line-2);
      font-size: 13px;
      cursor: pointer;
      user-select: none;
      transition: background-color 0.2s;
    }
    th:hover {
      background: #23262f;
    }
    th.sortable {
      position: relative;
      padding-right: 20px;
    }
    th.sortable::after {
      content: '';
      position: absolute;
      right: 6px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 12px;
      opacity: 0;
      transition: opacity 0.2s;
    }
    th.sortable:hover::after {
      content: '↑';
      opacity: 1;
      color: #fff;
    }
    th.sortable.asc::after {
      content: '↑';
      opacity: 1;
      color: var(--cy);
    }
    th.sortable.desc::after {
      content: '↓';
      opacity: 1;
      color: var(--cy);
    }
    tr:last-child td {
      border-bottom: none;
    }
    tr:hover td {
      background: #181818;
    }
    .placeholder {
      background: #181818;
      color: var(--fg-3);
      padding: 20px;
      border-radius: 8px;
      text-align: center;
      margin-top: 10px;
      font-size: 13px;
    }
    /* Custom cells */
    .coin-cell {
      font-weight: 500;
      display: flex;
      align-items: center;
      gap: 4px;
      font-size: 13px;
      padding-left: 2px;
      border-radius: 4px;
    }
    .lev {
      font-size: 12px;
      font-weight: 500;
      margin-left: 2px;
      opacity: 0.85;
    }
    .long-bg {
      background: linear-gradient(90deg, rgba(95,214,164,0.18) 0%, rgba(95,214,164,0.04) 80%, rgba(0,0,0,0) 100%);
      color: #5FD6A4;
    }
    .short-bg {
      background: linear-gradient(90deg, rgba(244,63,94,0.18) 0%, rgba(244,63,94,0.04) 80%, rgba(0,0,0,0) 100%);
      color: #f43f5e;
    }
    .pnl-cell.positive { color: #5FD6A4; }
    .pnl-cell.negative { color: #f43f5e; }
    .funding-cell.positive { color: #5FD6A4; }
    .funding-cell.negative { color: #f43f5e; }
    .group-summary-row {
      background: #181818;
      color: #fff;
      font-weight: 500;
      border-bottom: 2px solid var(--cy);
      height: 30px;
      font-size: 13px;
    }
    .group-summary-cell {
      padding-left: 8px !important;
      border: none !important;
      background: #181818 !important;
      width: 100%;
      text-align: left;
    }
    .group-summary-pnl.positive { color: #5FD6A4; }
    .group-summary-pnl.negative { color: #f43f5e; }
    /* Chart container */
    #spaghetti-chart {
      height: 340px;
      width: 100%;
      background: #181818;
      border-radius: 10px;
      margin-bottom: 32px;
      box-shadow: none;
      padding-bottom: 32px;
      border: 1px solid var(--line-2);
    }
    .col.section#equity-section {
      min-width: 320px;
      max-width: 400px;
      margin-bottom: 0;
      align-self: flex-start;
      padding-bottom: 12px !important;
      padding-top: 12px !important;
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      height: auto;
    }
    #equity-section h2 {
      margin-top: 0;
      margin-bottom: 12px;
    }
    #equity-summary {
      padding-bottom: 0 !important;
      margin-bottom: 0 !important;
    }
    /* Misc */
    ::selection {
      background: var(--cy);
      color: #fff;
    }
    /* Scrollbar */
    ::-webkit-scrollbar {
      width: 8px;
      background: #181818;
    }
    ::-webkit-scrollbar-thumb {
      background: #3a3e4a;
      border-radius: 8px;
      transition: opacity 0.3s;
      opacity: 1;
    }
    ::-webkit-scrollbar-thumb:window-inactive {
      opacity: 0.3;
    }
    /* Custom tooltip styling */
    .hl-tooltip {
      position: relative;
      display: inline-block;
    }
    .hl-tooltip .hl-tooltiptext {
      visibility: hidden;
      width: max-content;
      background-color: #23262f;
      color: #fff;
      text-align: center;
      border-radius: 6px;
      padding: 6px 10px;
      position: absolute;
      z-index: 1;
      bottom: 125%;
      left: 50%;
      transform: translateX(-50%);
      opacity: 0;
      transition: opacity 0.2s;
      font-size: 12px;
      pointer-events: none;
    }
    .hl-tooltip:hover .hl-tooltiptext {
      visibility: visible;
      opacity: 1;
      pointer-events: auto;
    }
    /* Thinner horizontal scrollbar for tables */
    .table-scroll::-webkit-scrollbar {
      height: 5px;
    }
    .ai-panel {
      width: 370px;
      min-width: 320px;
      max-width: 420px;
      background: #181818;
      border-left: 1.5px solid #23262f;
      box-shadow: -2px 0 12px 0 #000a;
      padding: 24px 18px 18px 18px;
      display: flex;
      flex-direction: column;
      gap: 18px;
      font-size: 14px;
      color: var(--fg-1);
      height: 100%;
      max-height: 90vh;
      overflow-y: auto;
      position: relative;
    }
    .ai-panel h2 {
      color: var(--cy);
      font-size: 1.1rem;
      font-weight: 600;
      margin-bottom: 10px;
    }
    #ai-suggestion-box {
      background: #141414;
      border-radius: 8px;
      border: 1px solid #23262f;
      padding: 14px 12px;
      min-height: 120px;
      color: var(--fg-1);
      font-size: 13.5px;
      white-space: pre-line;
      margin-bottom: 8px;
      max-height: 350px;
      overflow-y: auto;
    }
    #ai-fetch-btn {
      background: var(--cy);
      color: #fff;
      border: none;
      border-radius: 8px;
      padding: 8px 18px;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      margin-bottom: 8px;
      transition: background 0.2s;
    }
    #ai-fetch-btn:disabled {
      background: #23262f;
      color: #aaa;
      cursor: not-allowed;
    }
    #ai-loading {
      color: var(--cy);
      font-size: 13px;
      margin-bottom: 8px;
      display: none;
    }
    .scrollbar::-webkit-scrollbar-thumb {
      background: #23262f;
      border-radius: 8px;
    }
    .scrollbar::-webkit-scrollbar-track {
      background: transparent;
    }
    .tooltip {
      position: relative;
      display: inline-block;
    }
    .tooltip .tooltip-text {
      visibility: hidden;
      width: 120px;
      background-color: #23262f;
      color: #fff;
      text-align: center;
      border-radius: 6px;
      padding: 5px;
      position: absolute;
      z-index: 1;
      bottom: 125%;
      left: 50%;
      margin-left: -60px;
      opacity: 0;
      transition: opacity 0.3s;
    }
    .tooltip:hover .tooltip-text {
      visibility: visible;
      opacity: 1;
    }
    .container {
      display: flex;
      flex-direction: column;
      gap: 20px;
      padding: 20px;
      max-width: 1200px;
      margin: 0 auto;
    }
    .dashboard-grouped-positions-pane {
      background: var(--bg-2);
      border-radius: 0;
      border: 1px solid var(--line-2);
      box-shadow: none;
      padding: 12px 14px 10px 14px;
      margin-top: 18px;
      min-width: 260px;
      margin-bottom: 0;
      overflow-y: auto;
      max-height: 400px; /* will be set dynamically */
    }
    .grouped-positions-row {
      display: flex;
      align-items: center;
      gap: 18px;
      font-size: 13px;
      padding: 2px 0;
      border-bottom: 1px solid #23262f;
    }
    .grouped-positions-row:last-child {
      border-bottom: none;
    }
    .grouped-positions-name {
      font-weight: 600;
      color: #5FD6A4;
      min-width: 80px;
    }
    .grouped-positions-pnl.positive { color: #5FD6A4; }
    .grouped-positions-pnl.negative { color: #f43f5e; }
    .grouped-positions-exposure { color: #fff; }
    .grouped-positions-ratio.positive { color: #5FD6A4; }
    .grouped-positions-ratio.negative { color: #ff5c8a; }
    
    /* Modal/Popup Styles */
    .modal-overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.7);
      backdrop-filter: blur(4px);
      -webkit-backdrop-filter: blur(4px);
      z-index: 10000;
      display: none;
      align-items: center;
      justify-content: center;
    }
    
    .modal-content {
      background: var(--bg-2);
      border: 1px solid var(--line-2);
      border-radius: 0;
      max-width: 600px;
      max-height: 80vh;
      width: 90%;
      overflow-y: auto;
      position: relative;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }
    
    .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 20px 24px 16px 24px;
      border-bottom: 1px solid var(--line-2);
    }
    
    .modal-title {
      color: var(--cy);
      font-size: 1.25rem;
      font-weight: 600;
      margin: 0;
    }
    
    .modal-close {
      background: none;
      border: none;
      color: var(--fg-3);
      font-size: 24px;
      cursor: pointer;
      padding: 0;
      width: 32px;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px;
      transition: background-color 0.2s, color 0.2s;
    }
    
    .modal-close:hover {
      background: var(--line-2);
      color: var(--fg-1);
    }
    
    .modal-body {
      padding: 20px 24px 24px 24px;
      color: var(--fg-1);
      line-height: 1.6;
    }
    
    .modal-body h3 {
      color: var(--cy);
      font-size: 1.1rem;
      font-weight: 600;
      margin: 20px 0 10px 0;
    }
    
    .modal-body h3:first-child {
      margin-top: 0;
    }
    
    .modal-body p {
      margin: 0 0 12px 0;
      font-size: 14px;
    }
    
    .modal-body ul {
      margin: 0 0 12px 0;
      padding-left: 20px;
    }
    
    .modal-body li {
      margin: 4px 0;
      font-size: 14px;
    }
    
    .modal-body code {
      background: var(--bg-1);
      padding: 2px 6px;
      border-radius: 4px;
      font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
      font-size: 13px;
      color: var(--cy);
    }
    
    .changelog-entry {
      margin-bottom: 16px;
      padding-bottom: 16px;
      border-bottom: 1px solid var(--line-2);
    }
    
    .changelog-entry:last-child {
      border-bottom: none;
      margin-bottom: 0;
    }
    
    .changelog-date {
      color: var(--fg-3);
      font-size: 12px;
      font-weight: 500;
      margin-bottom: 4px;
    }
    
    .changelog-title {
      color: var(--cy);
      font-weight: 600;
      margin-bottom: 8px;
    }
    
    .changelog-description {
      color: var(--fg-1);
      font-size: 14px;
      line-height: 1.5;
    }
    
    /* Group Action Buttons */
    .group-actions {
      display: flex;
      gap: 4px;
      margin-left: auto;
    }
    
    .group-btn {
      background: #23262f;
      color: #5fbad6;
      font-weight: 600;
      border: none;
      border-radius: 4px;
      padding: 2px 6px;
      font-size: 10px;
      cursor: pointer;
      transition: background 0.2s;
    }
    
    .group-btn:hover {
      background: #2a2e38;
    }
    
    /* Groups Dropdown Styling */
    .group-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 0;
      border-bottom: 1px solid #23262f;
    }
    
    .group-item:last-child {
      border-bottom: none;
    }
    
    .group-name {
      flex: 1;
      color: #5FD6A4;
      font-weight: 600;
      font-size: 13px;
    }
    
    .group-actions-inline {
      display: flex;
      gap: 4px;
    }
    
    .group-action-btn {
      background: none;
      border: none;
      color: #aaa;
      cursor: pointer;
      padding: 2px 4px;
      border-radius: 3px;
      font-size: 12px;
      transition: background 0.2s, color 0.2s;
    }
    
    .group-action-btn:hover {
      background: #23262f;
      color: #fff;
    }
    
    .group-action-btn.delete:hover {
      background: #ff5c8a;
      color: #fff;
    }
