/* ============================================================================
 * tradeStack — EMA Gate bot pages
 * ========================================================================= */

/* ── Clock strip (replaces old hero) ──────────────────────────────────── */
.eg-clockbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin: -4px 0 14px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 12px;
}
.eg-clock-sep { opacity: 0.5; }
.eg-account-select {
  background: var(--bg-card, #1e1e2e);
  color: var(--text-primary, #c6d0f5);
  border: 1px solid var(--border-default, #363a4f);
  border-radius: 6px;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.eg-account-select:focus { outline: 2px solid var(--accent-primary, #7c3aed); outline-offset: 1px; }
.eg-countdown {
  color: var(--accent-secondary);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: right;
}

/* ── Panels stack with consistent gap ─────────────────────────────────── */
.eg-panel { margin-bottom: 14px; }

/* ── Range-selector header ────────────────────────────────────────────── */
.eg-range-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.eg-range-select {
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 4px 8px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
}
.eg-range-select:hover { border-color: var(--border-strong); }
.eg-range-select:focus { outline: none; border-color: var(--accent); }

/* ── Chart mount points ───────────────────────────────────────────────── */
.eg-chart { min-height: 260px; width: 100%; }
.eg-skeleton {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  font-size: 13px;
  font-style: italic;
}
.eg-empty {
  padding: 20px;
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
}

/* ── Portfolio summary grid ───────────────────────────────────────────── */
.eg-summary { margin-bottom: 14px; }
.eg-summary__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

/* Stat widget (RunPod-style: icon row + value + two-toned foot) */
.eg-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 92px;
}
.eg-stat__head {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-tertiary);
}
.eg-stat__icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.85;
  stroke-width: 1.75;
}
.eg-stat__label {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-tertiary);
  line-height: 1;
}
.eg-stat__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.1;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.eg-stat__value.up    { color: var(--up-bright); }
.eg-stat__value.down  { color: var(--down-bright); }
.eg-stat__value.warn  { color: var(--warning); }
.eg-stat__value.muted { color: var(--text-tertiary); }
.eg-stat__unit {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.7;
  margin-left: 1px;
}
.eg-stat__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.2;
  margin-top: auto;
}
.eg-stat__foot .sep { color: var(--text-muted); opacity: 0.55; }
.eg-stat__foot .muted { color: var(--text-tertiary); font-family: var(--font-sans); font-variant-numeric: normal; }
.eg-stat__foot .num { color: var(--text-primary); }
.eg-stat__foot .up    { color: var(--up-bright); }
.eg-stat__foot .down  { color: var(--down-bright); }
.eg-stat__foot .accent { color: var(--accent-secondary); }

/* Legacy .eg-kpi fallback (rendered by any non-live partial still using it) */
.eg-kpi {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.eg-kpi__label {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 400;
}
.eg-kpi__value {
  font-size: 18px;
  font-weight: 500;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  line-height: 1.2;
  margin-top: 2px;
}
.eg-kpi__value.warn { color: var(--warning); }
.eg-kpi__sub {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ── Symbol / direction pills in tables ───────────────────────────────── */
.eg-sym {
  font-family: var(--font-mono);
  font-weight: 450;
  color: var(--text-primary);
}
.eg-dir {
  font-family: var(--font-mono);
  font-weight: 450;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
}

/* ── Last 24h ─────────────────────────────────────────────────────────── */
.eg-24h__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.eg-24h__stat {
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.eg-24h__label {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1;
}
.eg-24h__value {
  font-size: 17px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.15;
}
.eg-24h__value.up   { color: var(--up-bright); }
.eg-24h__value.down { color: var(--down-bright); }
.eg-24h__sub {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.eg-24h__sub.up   { color: var(--up-bright); }
.eg-24h__sub.down { color: var(--down-bright); }
.eg-inset-table { margin-bottom: var(--space-3); }
.eg-24h__blocks { margin-top: var(--space-4); }
.eg-24h__blocks-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}
.eg-24h__block-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: var(--space-2);
  width: 100%;
}
.eg-24h__block {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: center;
  background: transparent;
}
.eg-24h__block.up {
  border-color: rgba(38, 166, 154, 0.35);
  background: rgba(38, 166, 154, 0.06);
}
.eg-24h__block.down {
  border-color: rgba(239, 83, 80, 0.35);
  background: rgba(239, 83, 80, 0.06);
}
.eg-24h__block-r { font-weight: 500; }
.eg-24h__block-t {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 2px;
}
.eg-24h__block.up .eg-24h__block-r { color: var(--up-bright); }
.eg-24h__block.down .eg-24h__block-r { color: var(--down-bright); }

/* ── Total row in perf tables ─────────────────────────────────────────── */
.eg-total-row td {
  border-top: 1px solid var(--border-default) !important;
  font-weight: 500;
  background: var(--bg-surface-raised);
}

/* ── Paging footer ────────────────────────────────────────────────────── */
.eg-paging {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}
.eg-paging__label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* ── Drawdown card ────────────────────────────────────────────────────── */
.eg-dd {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.eg-dd__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-faint);
}
.eg-dd__row:last-child { border-bottom: none; }
.eg-dd__label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.eg-dd__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-md);
  font-weight: 500;
}
.eg-dd__value.warn { color: var(--warning); }

/* ── Decision log ─────────────────────────────────────────────────────── */
.eg-decisions {
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  max-height: 360px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: var(--space-4);
}

/* ── Anthropic: direction pills + review chips + mobile table scroll ── */
.eg-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border: 1px solid transparent;
}
.eg-pill--long {
  color: var(--up-bright);
  background: var(--up-soft);
  border-color: rgba(38, 166, 154, 0.28);
}
.eg-pill--short {
  color: var(--down-bright);
  background: var(--down-soft);
  border-color: rgba(239, 83, 80, 0.28);
}
.eg-pill--hold {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-weak);
}
.eg-pill--move {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: rgba(247, 185, 85, 0.28);
}
.eg-pill--dim {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--border-weak);
}

.eg-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  border: 1px solid var(--border-weak);
  white-space: nowrap;
}
.eg-chip + .eg-chip { margin-left: 4px; }
.eg-chip--n {
  background: rgba(99, 135, 255, 0.10);
  color: var(--brand);
  border-color: rgba(99, 135, 255, 0.28);
}
.eg-chip--dim {
  background: transparent;
  color: var(--muted);
}
.eg-chip--warn {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: rgba(247, 185, 85, 0.32);
}

.eg-review-cell {
  white-space: nowrap;
  font-size: 11px;
}

/* Reason row — structured rather than inline stringed. */
.eg-reason-row > .eg-reason-cell {
  padding: 4px 14px 12px;
  font-size: 12px;
  line-height: 1.5;
  background: rgba(255, 255, 255, 0.015);
  border-top: 1px dashed var(--border-weak);
}
.eg-reason-line {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 2px 0;
}
.eg-reason-line + .eg-reason-line { margin-top: 2px; }
.eg-reason-label {
  flex: 0 0 auto;
  min-width: 96px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.eg-reason-text {
  flex: 1 1 auto;
  color: var(--text-primary);
}
.eg-reason-text.muted { color: var(--text-secondary); }

/* Table polish — slightly tighter header, hover highlight. */
.eg-open-table thead th,
.eg-closed-table thead th,
.eg-reviews-table thead th {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.015);
}
.eg-open-table tbody tr:not(.eg-reason-row):hover,
.eg-closed-table tbody tr:not(.eg-reason-row):hover,
.eg-reviews-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

/* Trade group delimiter — purple accent line separates each trade block
   (primary row + its reason row read as one unit). Using box-shadow instead
   of border-top because the table has border-collapse which can swallow
   adjacent borders. */
.eg-trade-main > td {
  padding-top: 10px;
  padding-bottom: 6px;
}
.eg-trade-main.eg-trade-start > td {
  box-shadow: inset 0 1px 0 0 rgba(95, 76, 254, 0.45);
  padding-top: 18px;
}
.eg-trade-main + .eg-reason-row > .eg-reason-cell {
  border-top: none;
  padding-top: 4px;
  padding-bottom: 16px;
}

/* Horizontal scroll wrapper keeps wide tables inside the card on mobile
   AND prevents the card from being stretched by the table's intrinsic
   min-width on narrow desktop grid cells (e.g. 3-col layouts). */
.eg-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  min-width: 0;
}
.eg-table-scroll > .data-table {
  min-width: 640px;
}
/* Grid cells default to min-width:auto which defeats the scroll wrapper;
   force them to be shrinkable so the scroll container actually kicks in. */
.grid > .card,
.grid > .eg-panel {
  min-width: 0;
}

@media (max-width: 640px) {
  .eg-table-scroll > .data-table { min-width: 560px; }
  .eg-reason-label { min-width: 72px; font-size: 10px; }
  .eg-reason-line { flex-direction: column; gap: 2px; }
  .eg-pill { font-size: 10px; padding: 1px 6px; }
  .eg-chip { font-size: 10px; padding: 0 6px; }
}



/* ── Open-trade chart (M5) ───────────────────────────────────────────── */
.eg-open-chart__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4, 12px);
  align-items: flex-end;
  margin-bottom: var(--space-4, 12px);
}
.eg-open-chart__label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted, #9aa0a8);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.eg-open-chart__hint {
  font-size: 11px;
  margin-left: auto;
  align-self: center;
}
.eg-open-chart__canvas {
  width: 100%;
  min-height: 420px;
}
.eg-select {
  background: #1a1d26;
  color: var(--text, #d1d4dc);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  min-width: 160px;
}
.eg-select:focus {
  outline: 1px solid var(--accent, #7c5cff);
  border-color: var(--accent, #7c5cff);
}
@media (max-width: 640px) {
  .eg-open-chart__canvas { min-height: 320px; }
  .eg-open-chart__hint   { display: none; }
  .eg-select             { min-width: 140px; }
}

/* ============================================================================
 * Mobile refinements (Anthropic + EMA Gate shared pages)
 * Targets phones <= 640px (and a narrower tier <= 420px). Keeps widgets
 * inside their card, prevents page-level horizontal spill, and reduces
 * row-wrap noise on dense tables / pre-blocks.
 * ========================================================================= */

@media (max-width: 640px) {
  /* Tighter card chrome gives content more room. */
  .card__header  { padding: 10px 12px; flex-wrap: wrap; row-gap: 4px; }
  .card__body    { padding: 12px; }
  .card__title   { font-size: 12px; }
  .card__eyebrow { font-size: 11px; }

  /* Cards inside any grid must be allowed to shrink below content width. */
  .card, .eg-panel { min-width: 0; }

  /* Clock bar wraps cleanly and aligns left on mobile. */
  .eg-clockbar       { justify-content: flex-start; flex-wrap: wrap; row-gap: 4px; margin: 0 0 10px; }
  .eg-account-select { max-width: 100%; }

  /* Portfolio summary: 2 columns on even the narrowest phones. */
  .eg-summary__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .eg-stat          { padding: 10px 10px 9px; min-height: 78px; gap: 6px; }
  .eg-stat__value   { font-size: 15px; }
  .eg-stat__foot    { font-size: 10px; gap: 4px; }

  /* 24h + Reviews stats: 2-up with lighter padding. */
  .eg-24h__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .eg-24h__stat  { padding: 9px 10px 8px; }
  .eg-24h__value { font-size: 14px; }

  /* _reviews.html applies inline style="padding: var(--space-6)" — shrink it. */
  .eg-panel .eg-24h__stats[style] { padding: 12px !important; }

  /* Dense data-table typography (applies to Anthropic tables on mobile). */
  .eg-table-scroll > .data-table { min-width: 520px; }
  .eg-open-table thead th,
  .eg-closed-table thead th,
  .eg-reviews-table thead th,
  .eg-table--anthropic thead th,
  .eg-inset-table thead th { padding: 6px 8px; font-size: 10.5px; }
  .eg-open-table tbody td,
  .eg-closed-table tbody td,
  .eg-reviews-table tbody td,
  .eg-table--anthropic tbody td,
  .eg-inset-table tbody td { padding: 6px 8px; font-size: 12px; }

  /* Decision log: horizontal scroll instead of wrapping every long line. */
  .eg-decisions {
    white-space: pre;
    word-break: normal;
    overflow-x: auto;
    max-height: 300px;
    font-size: 10.5px;
    padding: 10px 12px;
    margin: 10px;
  }

  /* Open-chart toolbar: selects flow to full width on narrow screens. */
  .eg-open-chart__toolbar { gap: 10px; }
  .eg-open-chart__label   { flex: 1 1 45%; min-width: 0; }
  .eg-select              { width: 100%; min-width: 0; }

  /* Range header wraps if title + selector don't fit. */
  .eg-range-header { flex-wrap: wrap; row-gap: 6px; }
}

@media (max-width: 420px) {
  .eg-summary__grid { grid-template-columns: 1fr; }
  .eg-24h__stats    { grid-template-columns: 1fr; }
  .eg-open-chart__label { flex: 1 1 100%; }
  .eg-table-scroll > .data-table { min-width: 480px; }
  .eg-stat__value { font-size: 14px; }
}
