/* CEX Positions admin tab — observability panel for the CEX integration.
   See public/js/pages/cex.js for the page module. */

/* Title-row pattern: card title + a segmented control (or other inline
   action) on the same line. Used by Recent closed P&L's lookback-range
   switcher. The title takes its natural width, the action floats right.
   Both stack on narrow viewports rather than colliding. */
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.card-title-row .card-title { margin-bottom: 0; }
.cex-closed-range {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}


.cex-filter-bar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  margin-bottom: 14px;
}
.cex-filter-bar .field-inline { gap: 6px; }
.cex-filter-bar input[type="text"],
.cex-filter-bar input[type="search"] {
  width: 100px;
  padding: 6px 8px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 12px;
}
.cex-filter-bar select {
  padding: 6px 8px;
}

.cex-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.cex-kpi {
  background: var(--surface-tinted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.cex-kpi-label {
  font-size: 10px; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .1em; font-weight: 500;
}
.cex-kpi-value {
  margin-top: 4px;
  font-size: 18px; font-weight: 600;
  font-family: var(--font-mono);
  color: var(--foreground);
}

#cex-funding-table       td .tdd-cex-logo-wrap,
#cex-closed-table        td .tdd-cex-logo-wrap,
#cex-sync-runs-table     td .tdd-cex-logo-wrap,
#cex-timeline-day-table  td .tdd-cex-logo-wrap {
  width: 18px; height: 18px;
  flex: 0 0 18px;
  margin-right: 0;
}

/* Venue cells contain a logo wrap + venue name as siblings. Wrap them
   in a flex container at the cell level so the logo and text share a
   single baseline (vertical-align on the wrap alone wasn't enough —
   the text and image were measured against different baselines and
   nudged apart by ~2px). */
#cex-funding-table       td:first-child > *,
#cex-closed-table        td:first-child > *,
#cex-sync-runs-table     td:first-child > *,
#cex-timeline-day-table  td:first-child > * {
  vertical-align: middle;
}
#cex-funding-table       td:first-child,
#cex-closed-table        td:first-child,
#cex-sync-runs-table     td:first-child,
#cex-timeline-day-table  td:first-child {
  white-space: nowrap;
}
.cex-venue-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}
.cex-venue-credlabel {
  font-size: 12px;
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  letter-spacing: .01em;
}

.cex-side-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cex-side-tag.long  { background: rgba(40, 200, 130, .15); color: var(--pos); }
.cex-side-tag.short { background: rgba(220, 90, 90, .15);  color: var(--neg); }
.cex-side-tag.net   { background: var(--surface-tinted);   color: var(--muted-foreground); }

.cex-status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cex-status-tag.ok      { background: rgba(40, 200, 130, .15); color: var(--pos); }
.cex-status-tag.error   { background: rgba(220, 90, 90, .15);  color: var(--neg); }
.cex-status-tag.running { background: var(--surface-tinted);   color: var(--muted-foreground); }

/* ── Position timeline scrubber ──────────────────────────────────────
   Slim horizontal bar with date gradations + a draggable handle.
   Native <input type="range"> drives the value; we overlay tick marks
   for date markers. Below the scrubber, a breakdown table mirrors the
   Open Positions table column-for-column so the user reads the
   historical state in the same shape they read the current state. */
.cex-timeline-card {
  position: relative;
}
.cex-timeline-card .card-title {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}
/* Title text + muted hint group on the left edge of the row. Wrapping
   them in a single grid cell lets us reserve the centre column for the
   date pill and the right column for the view-mode switcher. */
.cex-timeline-title-text {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  justify-self: start;
}
/* View-mode + status-filter switchers — same chrome as .cex-closed-range.
   Wrapped in a flex container that occupies the right column of the
   card-title's 3-column grid (1fr auto 1fr). The two seg-btn groups sit
   side-by-side; on narrow viewports the mobile media query stacks them. */
.cex-timeline-toggles {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-self: end;
}
.cex-timeline-mode,
.cex-timeline-status,
.cex-timeline-type {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
/* In combined mode, cell 1 holds a small chip showing how many venues
   contribute to the net exposure (with a hover tooltip listing them).
   Width-budget on the venue column is ~48px so a single subtle pill
   fits while leaving room for cell padding. */
.cex-combined-venue-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-tinted);
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.cex-scrubber-current {
  /* Centred between the title text and the view-mode switcher via the
     grid layout above. justify-self:center centres the pill within its
     auto-sized column; the surrounding 1fr columns balance the slack. */
  justify-self: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--foreground);
  font-variant-numeric: tabular-nums;
  padding: 2px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--foreground) 6%, transparent);
}

.cex-scrubber {
  margin: 16px 0 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.cex-scrubber-track-wrap {
  position: relative;
  padding: 16px 4px 6px;
}
/* Custom-styled native range input — keyboard + touch + a11y for free. */
.cex-scrubber-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
.cex-scrubber-range:focus-visible {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ring) 35%, transparent);
}
.cex-scrubber-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--foreground);
  border: 3px solid var(--background);
  cursor: grab;
  transition: transform .12s ease;
}
.cex-scrubber-range::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.15); }
.cex-scrubber-range::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--foreground);
  border: 3px solid var(--background);
  cursor: grab;
}
.cex-scrubber-range::-moz-range-thumb:active { cursor: grabbing; }
.cex-scrubber-range:disabled { opacity: .4; cursor: not-allowed; }

/* Tick marks above the track — date labels at evenly-spaced positions.
   Absolutely positioned so they line up with the actual track positions
   regardless of how the browser sizes the range input internally. */
.cex-scrubber-ticks {
  position: absolute;
  left: 4px; right: 4px;
  top: 0; height: 14px;
  pointer-events: none;
}
.cex-scrubber-tick {
  position: absolute;
  top: 0; bottom: 0;
  display: flex; align-items: flex-start; justify-content: center;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--muted-foreground);
  white-space: nowrap;
  transform: translateX(-50%);
}
.cex-scrubber-tick::before {
  content: '';
  position: absolute;
  top: 13px; left: 50%;
  width: 1px; height: 4px;
  background: var(--border);
  transform: translateX(-50%);
}

.cex-scrubber-bounds {
  display: flex; justify-content: space-between;
  font-family: var(--font-mono);
  padding: 0 4px;
}
.cex-scrubber-bounds.is-empty { justify-content: center; }
.cex-scrubber-bounds.is-empty span { font-style: italic; }

/* Snapshot table — historical position state at a scrubbed date.
   Closed rows are greyed in place (rows never move on scrub). */
/* Fixed-layout table — table is responsive (width: 100%) but column
   widths are calibrated to sum to EXACTLY 100% so the browser has no
   leftover space to distribute. The original CSS used percentages
   that summed to ~95% (with 5% leftover); table-layout:fixed
   distributes that leftover across all columns on every layout pass,
   and any subpixel container-width wobble (page scrollbar toggling,
   font-rendering rounding) re-runs that distribution and you see it
   as columns "breathing" during scrub.
   With this rule each pixel column claims an exact pixel slice and
   each data column claims `(100% - sum-of-pixel-cols) / 6` via
   calc — so the six data cols together fill exactly the remaining
   space, no leftover, no per-frame redistribution. */
#cex-timeline-day-table {
  table-layout: fixed;
  width: 100%;
}
#cex-timeline-day-table th:nth-child(1),
#cex-timeline-day-table td:nth-child(1)  { width: 96px;  }   /* Venue — icon (18px) + 6px gap + credential label (e.g. "Main", "Sub-1") + 24px cell padding. Was 48px when only the icon rendered; the credLabel addition pushed text past the cell edge and tripped ellipsis. */
#cex-timeline-day-table th:nth-child(2),
#cex-timeline-day-table td:nth-child(2)  { width: 126px; }   /* Symbol — widened from 110 by reclaiming whitespace from Side; longer venue-suffixed symbols (e.g. PLUMEUSDT-…, RIVERUSDT-…, NIGHTUSDT-…) used to ellipsis-truncate at 110. */
#cex-timeline-day-table th:nth-child(3),
#cex-timeline-day-table td:nth-child(3)  {
  width: 64px;        /* Side — narrowed from 80; combined with the tighter horizontal padding below this still seats the SHORT/LONG tag (~51px) with a small buffer. */
  padding-left: 4px;
  padding-right: 4px;
}
#cex-timeline-day-table th:nth-child(13),
#cex-timeline-day-table td:nth-child(13) { width: 90px;  }   /* Status — 90px (not 80) so the CLOSED tag (~55px) plus cell padding (~24px) plus border-collapse rounding fits without tripping text-overflow:ellipsis. */
/* APR + ROI — percentage columns. Worst-case value is ~"-100.00%" (8 mono chars ≈ 60px) plus 24px cell padding ≈ 84px, so 88px seats them with a small buffer. They share the same width because they share a data type. */
#cex-timeline-day-table th:nth-child(11),
#cex-timeline-day-table td:nth-child(11),
#cex-timeline-day-table th:nth-child(12),
#cex-timeline-day-table td:nth-child(12) { width: 88px; }
#cex-timeline-day-table th:nth-child(4),
#cex-timeline-day-table td:nth-child(4),
#cex-timeline-day-table th:nth-child(5),
#cex-timeline-day-table td:nth-child(5),
#cex-timeline-day-table th:nth-child(6),
#cex-timeline-day-table td:nth-child(6),
#cex-timeline-day-table th:nth-child(7),
#cex-timeline-day-table td:nth-child(7),
#cex-timeline-day-table th:nth-child(8),
#cex-timeline-day-table td:nth-child(8),
#cex-timeline-day-table th:nth-child(9),
#cex-timeline-day-table td:nth-child(9),
#cex-timeline-day-table th:nth-child(10),
#cex-timeline-day-table td:nth-child(10) {
  /* `--cex-data-col-w` is set to an INTEGER pixel value by JS
     (pinBreakdownColumnWidths in cex.js) so column boundaries fall
     on whole pixels and don't accumulate subpixel-rounding error
     left-to-right during scrub. The calc() fallback is responsive
     for the brief window before JS runs, but we want integer-pixel
     layout once JS has measured the container.
     Covers the 7 wide data cols (Qty, Entry, Mark, Unrealised,
     Realised, Notional, Funding) — they all carry similarly-sized
     mono numerics so equal-width keeps the grid even. APR + ROI are
     pinned narrower above. */
  width: var(--cex-data-col-w, calc((100% - 552px) / 7));
}
#cex-timeline-day-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Row animation is driven by a continuous rAF lerp in cex.js — every
   frame, each row's transform: translateY(...) is updated toward its
   target visual slot. CSS transitions are intentionally NOT used
   here: layered CSS transitions interrupt each other on rapid
   scrubbing (the "stuck" feeling) because every render fires a fresh
   `transition: none` snap before re-arming the play step.
   `will-change: transform` is intentionally NOT set: it would force
   Chrome/Edge to keep every row on its own compositor layer, and
   compositor layers always use greyscale antialiasing rather than
   subpixel/ClearType AA — visibly blurrier. Without will-change,
   the browser only promotes a row to a layer while its transform is
   non-empty (during animation), and demotes it back when transforms
   clear (after settle, see settleAndDeglossDOM in cex.js). Demoted
   rows render through the main paint pipeline and pick up subpixel
   AA — crisp text matching the rest of the page. */
#cex-timeline-day-table tbody tr {
  /* (intentionally no will-change — see comment above) */
}

/* Allow horizontal scroll on the timeline breakdown wrapper. The
   table is pinned by pinBreakdownColumnWidths() with SAFETY_PX of
   headroom to absorb the 1–2 px of border-collapse rounding overshoot,
   so the fits-fine case doesn't show a phantom sliver. When the
   container is narrower than the column-width floor (e.g. browser
   zoom-in), the table is genuinely wider than the container and we
   need a real scrollbar so the right-most columns aren't clipped. */
.cex-timeline-card .table-scroll {
  overflow-x: auto;
  /* Themed scrollbar — the global base.css thumb is a near-white at .10
     alpha (built for the dark theme) and disappears against the light
     theme's white card. Use --border-strong like the other scrollable
     panels in the app so the bar is visible in both themes. */
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.cex-timeline-card .table-scroll::-webkit-scrollbar { height: 8px; }
.cex-timeline-card .table-scroll::-webkit-scrollbar-track { background: transparent; }
.cex-timeline-card .table-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
.cex-timeline-card .table-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

.cex-timeline-day {
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
.cex-timeline-day-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.cex-timeline-day-label {
  font-size: 13px; color: var(--foreground);
}
.cex-timeline-day-label strong {
  font-family: var(--font-mono);
  font-weight: 600;
}

#cex-timeline-day-table tbody tr.is-closed {
  opacity: .42;
}
#cex-timeline-day-table tbody tr.is-closed td .mono,
#cex-timeline-day-table tbody tr.is-closed td:not(.num) {
  color: var(--muted-foreground);
}
#cex-timeline-day-table tbody tr.is-pre-open,
#cex-timeline-day-table tbody tr.is-hidden {
  display: none;
}

/* Sortable column headers — clicking cycles asc → desc → off. The
   neutral state shows nothing (so tight columns like the 48px Venue
   header don't overflow); the active column shows a solid up/down
   triangle. Pseudo-element keeps the th text in place across state
   changes and lets the indicator share the cell's text styling. */
.cex-timeline-card thead th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.cex-timeline-card thead th.sortable:hover {
  color: var(--foreground);
}
.cex-timeline-card thead th.sortable[data-sort-dir]::after {
  display: inline-block;
  margin-left: 3px;
  font-size: 9px;
  font-weight: 600;
  vertical-align: middle;
  line-height: 1;
  /* `--foreground` is the readable-on-bg text color in both themes
     (~white in dark, ~black in light). `--accent` is a button-fill
     token — near-bg by design — so it'd render invisible here. */
  color: var(--foreground);
}
.cex-timeline-card thead th.sortable[data-sort-dir="asc"]::after {
  content: '▲';
}
.cex-timeline-card thead th.sortable[data-sort-dir="desc"]::after {
  content: '▼';
}

/* Search field — moved out of the top filter bar to live between the
   scrubber and the portfolio-state breakdown. Sits in its own row so
   the breakdown header stays clean. Mirrors the input chrome the
   filter bar used. */
.cex-timeline-search {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 8px;
}
.cex-timeline-search label {
  font-size: 12px;
  color: var(--muted-foreground);
}
.cex-timeline-search input[type="search"] {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* DeFi timeline breakdown — same chrome as #cex-timeline-day-table
   above but a different column count. Both tables are rendered by
   the shared timeline component (public/js/components/timeline.js)
   so the row classes (is-open / is-closed / is-pre-open / is-hidden)
   carry the same meaning across pages. Closed rows fade and lose
   colour on the muted text path, mirroring the CEX behaviour. */
#defi-timeline-day-table {
  table-layout: fixed;
  width: 100%;
}
#defi-timeline-day-table th,
#defi-timeline-day-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Chain (icon + name) — same width budget as the CEX Venue column. */
#defi-timeline-day-table th:nth-child(1),
#defi-timeline-day-table td:nth-child(1)  { width: 140px; }
/* Token — icon + ticker + optional name. Slightly wider than CEX's
   Symbol column because DeFi tickers often append a " · TokenName"
   suffix that we want to keep on one line. */
#defi-timeline-day-table th:nth-child(2),
#defi-timeline-day-table td:nth-child(2)  { width: 200px; }
/* Wallet label — operator-chosen short string. */
#defi-timeline-day-table th:nth-child(3),
#defi-timeline-day-table td:nth-child(3)  { width: 120px; }
/* Status — same column width as the CEX timeline so the HELD / CLEARED
   tag fits without ellipsis. */
#defi-timeline-day-table th:nth-child(8),
#defi-timeline-day-table td:nth-child(8)  { width: 90px; }
/* Hide button — fixed compact column on the right edge. */
#defi-timeline-day-table th:nth-child(9),
#defi-timeline-day-table td:nth-child(9)  { width: 36px; padding: 0; text-align: center; }

/* Recent transactions table — final hide column matches the timeline's
   compact treatment. The 8 preceding columns get default datatable
   widths; we only pin the action column so the eye/eye-off button
   stays right-aligned and doesn't collapse to icon width plus padding
   the rest of the table can absorb. */
#defi-tx-table th:last-child,
#defi-tx-table td:last-child { width: 36px; padding: 0; text-align: center; }

/* Same fade treatment for closed defi rows as the cex timeline. */
#defi-timeline-day-table tbody tr.is-closed {
  opacity: .42;
}
#defi-timeline-day-table tbody tr.is-closed td .mono,
#defi-timeline-day-table tbody tr.is-closed td:not(.num) {
  color: var(--muted-foreground);
}
#defi-timeline-day-table tbody tr.is-pre-open,
#defi-timeline-day-table tbody tr.is-hidden {
  display: none;
}

/* Per-row hide button — surfaces an unobtrusive eye/strikethrough
   glyph the operator clicks to filter a token out of the timeline.
   Filtered tokens stay hidden until the "Show filtered" toggle in the
   header reveals them; clicking the same button on a now-shown row
   un-hides it. */
.timeline-row-hide-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  line-height: 1;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
/* Lucide eye / eye-off SVG sits inside the button. Stroke inherits
   currentColor so hover + aria-pressed states tint it via the rules
   below; explicit width/height keeps it crisp at 22px button size. */
.timeline-row-hide-btn svg {
  width: 14px; height: 14px;
  display: block;
}
.timeline-row-hide-btn:hover {
  background: var(--surface-tinted);
  color: var(--foreground);
  border-color: var(--border);
}
.timeline-row-hide-btn[aria-pressed="true"] {
  color: var(--accent-foreground, var(--foreground));
  background: var(--surface-tinted);
}

/* "Show filtered" toggle in the timeline title bar. Mirrors the
   .seg-btn chrome but with a checkbox inside, so it reads as part
   of the same toggle group as the All/Held/Cleared filter. */
.defi-show-hidden-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.defi-show-hidden-toggle input[type="checkbox"] {
  width: 12px; height: 12px;
  margin: 0;
  cursor: pointer;
}
.defi-timeline-status,
.defi-timeline-type {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Token-type pill — colored chip in the Type column of the DeFi timeline
   table. Replaces Covalent's coarse `cryptocurrency`/`dust` text with a
   class-based bucket the desk reads at a glance:
     • cryptocurrency → blue (chart-1)   — volatile asset
     • stablecoin     → teal (chart-2)   — USD-pegged exposure
     • pendle         → purple (chart-4) — Pendle's brand color, signals
                                            split-yield principal/yield positions
     • pool           → orange (chart-3) — LP / vault yield strategy
     • spam           → red (loss)       — Covalent classifier flag
   Padding/font follow the existing .pill chrome so the chips line up
   with other badges in the same row. */
.token-type-pill {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: .04em;
  border: 1px solid transparent;
  background: var(--secondary);
  color: var(--secondary-foreground);
}
.token-type-pill--cryptocurrency {
  color: var(--chart-1);
  border-color: color-mix(in srgb, var(--chart-1) 25%, transparent);
  background: color-mix(in srgb, var(--chart-1) 8%, transparent);
}
.token-type-pill--stablecoin {
  color: var(--chart-2);
  border-color: color-mix(in srgb, var(--chart-2) 25%, transparent);
  background: color-mix(in srgb, var(--chart-2) 8%, transparent);
}
.token-type-pill--pendle {
  color: var(--chart-4);
  border-color: color-mix(in srgb, var(--chart-4) 25%, transparent);
  background: color-mix(in srgb, var(--chart-4) 8%, transparent);
}
.token-type-pill--pool {
  color: var(--chart-3);
  border-color: color-mix(in srgb, var(--chart-3) 25%, transparent);
  background: color-mix(in srgb, var(--chart-3) 8%, transparent);
}
.token-type-pill--spam {
  color: var(--loss);
  border-color: color-mix(in srgb, var(--loss) 30%, transparent);
  background: color-mix(in srgb, var(--loss) 8%, transparent);
}
/* "reward" — off-chain entitlements (Merkl/Aave Merit, Kamino Season
   airdrops). Chart-5 ties it to the gain color family so the operator
   reads it as a yield-like position vs the spot-position pills above. */
.token-type-pill--reward {
  color: var(--chart-5);
  border-color: color-mix(in srgb, var(--chart-5) 30%, transparent);
  background: color-mix(in srgb, var(--chart-5) 8%, transparent);
}

/* "deal custody" — wallet tokens an OTC deal already carries (deals.body.
   custody_chain, e.g. Sonic_Validator's staked loan tokens). Dashed and
   muted: the row is shown for the raw wallet view, but AUM values it inside
   the deal row at the deal's discount, not here. */
.token-type-pill--custody {
  color: var(--muted-foreground);
  border-style: dashed;
  border-color: color-mix(in srgb, var(--muted-foreground) 45%, transparent);
  background: transparent;
  white-space: nowrap;
}

/* Recent transactions — direction column. Lucide-style download/upload
   glyphs make the in/out signal readable at a glance even for color-
   blind operators (the arrow direction carries the meaning), and the
   green/red tint reinforces it for everyone else. The wrapper is the
   sole color anchor — both the SVG (currentColor stroke) and the
   sibling text inherit from it. */
.defi-tx-dir {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: lowercase;
}
.defi-tx-dir svg {
  width: 13px; height: 13px;
  flex: 0 0 auto;
}
.defi-tx-dir--in   { color: var(--profit); }
.defi-tx-dir--out  { color: var(--loss); }
.defi-tx-dir--self { color: var(--muted-foreground); }

/* Funding-by-symbol — symbols with no funding events in the last 30
   days are treated as closed (perp position closed → venue stops
   emitting bills) and rendered with the same grey treatment as the
   timeline's closed-position rows. Sort order pushes them to the
   bottom; the visual cue tells the operator at a glance which rows
   are still active. */
#cex-funding-table tbody tr.is-closed {
  opacity: .42;
}
#cex-funding-table tbody tr.is-closed td .mono,
#cex-funding-table tbody tr.is-closed td:not(.num) {
  color: var(--muted-foreground);
}

/* Per-credential sync picker — sits between the filter bar and the
   KPI strip. One pill per active credential; checking it includes
   that credential in the next "Sync selected" run. The "Sync all"
   master toggle inverts to checked-when-all / indeterminate-when-some
   / unchecked-when-none. */
.cex-cred-picker {
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--surface-tinted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.cex-cred-picker-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.cex-cred-picker-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 500; cursor: pointer;
}
.cex-cred-picker-toggle input { cursor: pointer; }
.cex-cred-picker-list {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.cex-cred-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s;
}
.cex-cred-pill:hover {
  border-color: var(--border-strong);
}
.cex-cred-pill input { cursor: pointer; }
.cex-cred-pill .tdd-cex-logo-wrap {
  width: 18px; height: 18px;
}
.cex-cred-pill-label {
  display: flex; flex-direction: column; line-height: 1.2;
}
.cex-cred-pill-name {
  font-size: 12px; font-weight: 500;
}
.cex-cred-pill-sub {
  font-size: 10px;
}
.cex-cred-pill:has(input:not(:checked)) {
  opacity: .55;
}

/* ── Mobile (≤ 720px) ────────────────────────────────────────────────
   Filter row stacks vertically; KPI strip drops to a 2-col grid; the
   four data tables get a horizontal scroll wrapper (table-scroll
   already does this, but we tighten the cell padding so a phone can
   actually see two columns at once). */
@media (max-width: 720px) {
  .cex-filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .cex-filter-bar .field-inline {
    justify-content: space-between;
  }
  .cex-filter-bar #cex-refresh,
  .cex-filter-bar #cex-sync-all {
    width: 100%;
  }
  .cex-filter-bar #cex-sync-status {
    text-align: center;
    width: 100%;
  }
  .cex-kpis {
    grid-template-columns: repeat(2, 1fr);
  }
  .cex-kpi-value {
    font-size: 16px;
  }
  /* Tighter cells on tables in this tab so the most useful 4-5 columns
     are visible without scroll. */
  #cex-funding-table th,
  #cex-funding-table td,
  #cex-closed-table th,
  #cex-closed-table td,
  #cex-sync-runs-table th,
  #cex-sync-runs-table td,
  #cex-timeline-day-table th,
  #cex-timeline-day-table td {
    padding-left: 6px;
    padding-right: 6px;
    font-size: 11px;
  }
  .cex-timeline-card .card-title {
    /* On phones the 3-column grid is too cramped — fall back to a
       single-column stack so the title, date pill and toggle wrap onto
       their own lines. */
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .cex-timeline-title-text,
  .cex-scrubber-current,
  .cex-timeline-toggles {
    justify-self: stretch;
  }
  .cex-scrubber-current {
    text-align: center;
  }
  .cex-timeline-toggles {
    justify-self: center;
    flex-wrap: wrap;
    justify-content: center;
  }
  /* On phones, drop tick labels to every-other (or hide entirely if cramped) */
  .cex-scrubber-tick:nth-child(even) { display: none; }
}
