/**
 * Dashboard stat row + swap readout (terminal HUD)
 * Resolves clipped labels, weak hierarchy, and conflicting legacy stat-card rules.
 * Scope: body.dx-dashboard-terminal only. Load before light-mode-optimization.css.
 */

body.dx-dashboard-terminal {
  --dxfi-readout-label: 0.6875rem;
  --dxfi-readout-label-tracking: 0.11em;
  --dxfi-readout-value-min: 1.125rem;
  --dxfi-readout-value-preferred: calc(0.9rem + 1.1vw);
  --dxfi-readout-value-max: 1.6rem;
  --dxfi-readout-tile-min-h: 162px;
  --dxfi-readout-header-h: 34px;
}

@media (max-width: 768px) {
  body.dx-dashboard-terminal {
    --dxfi-readout-value-max: 1.45rem;
    --dxfi-readout-tile-min-h: 144px;
    --dxfi-readout-header-h: 32px;
  }
}

/* Top-row metric tiles: never clip captions; drop rigid aspect box */
body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small {
  aspect-ratio: unset !important;
  min-height: var(--dxfi-readout-tile-min-h) !important;
  max-height: none !important;
  height: auto !important;
  padding: 0.75rem 0.875rem !important;
  display: grid !important;
  grid-template-rows: var(--dxfi-readout-header-h) minmax(0, 1fr) auto !important;
  align-content: start !important;
  justify-items: start !important;
  gap: 0 !important;
  overflow: visible !important;
}

body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-header-compact {
  grid-row: 1;
  width: 100%;
  min-height: var(--dxfi-readout-header-h);
  margin: 0 !important;
  display: flex;
  align-items: center;
}

/* Figure: mono, bounded size so label always fits */
body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-value-compact,
body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-value-compact.positive,
body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-value-compact.negative {
  grid-row: 2;
  align-self: end;
  flex: 0 0 auto !important;
  margin: 0 0 0.1rem !important;
  padding: 0 !important;
  overflow: visible !important;
  line-height: 1.12 !important;
  font-family: var(--dxfi-font-mono) !important;
  font-variant-numeric: tabular-nums slashed-zero;
  font-weight: 600 !important;
  letter-spacing: -0.02em !important;
  font-size: clamp(
    var(--dxfi-readout-value-min),
    var(--dxfi-readout-value-preferred),
    var(--dxfi-readout-value-max)
  ) !important;
  -webkit-font-smoothing: antialiased;
}

/* Caption: Inter uppercase micro-label (high contrast, never faded) */
body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-label-compact {
  grid-row: 3;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding: 0 0 3px !important;
  flex-shrink: 0 !important;
  align-self: flex-start !important;
  max-width: 100%;
  overflow: visible !important;
  white-space: normal !important;
  word-break: break-word;
  font-family:
    'Inter',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    'Helvetica Neue',
    Arial,
    sans-serif !important;
  font-size: var(--dxfi-readout-label) !important;
  font-weight: 600 !important;
  letter-spacing: var(--dxfi-readout-label-tracking) !important;
  text-transform: uppercase !important;
  line-height: 1.45 !important;
  opacity: 1 !important;
  color: rgba(203, 213, 225, 0.96) !important;
  -webkit-font-smoothing: antialiased;
}

html.light body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-label-compact {
  color: rgba(51, 65, 85, 0.96) !important;
}

/* Preserve semantic PnL colours from dashboard / terminal */
body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-value-compact.positive {
  color: var(--color-success, #10b981) !important;
}

body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-value-compact.negative {
  color: var(--color-danger, #ef4444) !important;
}

html.light body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-value-compact.positive {
  color: var(--color-success-dark, #059669) !important;
}

html.light body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-value-compact.negative {
  color: var(--color-danger-dark, #dc2626) !important;
}

html.light body.dx-dashboard-terminal .dashboard-stats-row > .dashboard-card.stat-card-small .stat-value-compact:not(.positive):not(.negative) {
  color: rgba(15, 23, 42, 0.94) !important;
}

/* Swap column: section chrome matches stat captions */
body.dx-dashboard-terminal .swap-card-compact .swap-section-label {
  font-family:
    'Inter',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    sans-serif !important;
  font-size: var(--dxfi-readout-label) !important;
  font-weight: 700 !important;
  letter-spacing: var(--dxfi-readout-label-tracking) !important;
  text-transform: uppercase !important;
  line-height: 1.35 !important;
  opacity: 1 !important;
  color: rgba(186, 198, 214, 0.92) !important;
}

body.dx-dashboard-terminal .swap-card-compact .swap-balance-text {
  font-size: 0.6875rem !important;
  line-height: 1.35 !important;
  opacity: 1 !important;
  color: rgba(148, 163, 184, 0.95) !important;
}

body.dx-dashboard-terminal .swap-card-compact .swap-token-symbol {
  font-size: 0.8125rem !important;
  font-weight: 600 !important;
}

html.light body.dx-dashboard-terminal .swap-card-compact .swap-section-label {
  color: rgba(71, 85, 105, 0.95) !important;
}

html.light body.dx-dashboard-terminal .swap-card-compact .swap-balance-text {
  color: rgba(100, 116, 139, 0.95) !important;
}
