/* Macro Trend Grid — escopo fechado (.macro-trend-grid) · Intel Hub */
.macro-trend-grid {
  --mtg-bg0: var(--bg0, #000000);
  --mtg-bg1: var(--bg1, #05070a);
  --mtg-border: var(--inst-border, rgba(0, 168, 204, 0.12));
  --mtg-border-dim: rgba(255, 255, 255, 0.06);
  --mtg-amber: #d4af37;
  --mtg-amber-line: #c8883a;
  --mtg-amber-fill-top: rgba(200, 136, 58, 0.25);
  --mtg-amber-fill-bot: rgba(200, 136, 58, 0.02);
  --mtg-cyan: #4a8fa0;
  --mtg-cyan-badge: rgba(74, 143, 160, 0.18);
  --mtg-amber-badge: rgba(200, 136, 58, 0.14);
  --mtg-text-dim: #6a7a88;
  --mtg-text-faint: #3a4856;
  --mtg-mono: 'Bloomberg Prop Unicode N', var(--font-bloomberg), monospace;
  --mtg-fs-xs: 14px;
  --mtg-fs-sm: 16px;
  --mtg-fs-md: 17px;
  --mtg-fs-lg: 22px;
  --mtg-fs-xl: 38px;
  --mtg-row-h: 320px;
  --mtg-cyan-tech: rgba(0, 168, 204, 1);
  --mtg-cyan-tech-soft: rgba(0, 168, 204, 0.22);
  --mtg-bear-fire: #e8a020;
  --mtg-bear-red: rgba(220, 72, 58, 0.92);
  box-sizing: border-box;
  display: flex;
  flex: 1;
  flex-direction: column;
  font-family: var(--mtg-mono);
  min-height: 0;
  overflow: hidden;
  width: 100%;
}

.macro-trend-grid *,
.macro-trend-grid *::before,
.macro-trend-grid *::after {
  box-sizing: border-box;
}

.macro-trend-grid.hidden,
.macro-trend-grid.ih-hidden {
  display: none !important;
}

.macro-trend-grid__scroll,
.macro-trend-grid .mtg-scroll-pages {
  container-name: mtg-scroll;
  container-type: size;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.macro-trend-grid .mtg-scroll-pages {
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.macro-trend-grid .mtg-page {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-height: 100%;
  min-width: 0;
}

.macro-trend-grid .mtg-page--grid {
  background: var(--mtg-bg0);
}

.macro-trend-grid .mtg-page--log {
  background: var(--mtg-bg0);
  border-top: 1px solid var(--mtg-border-dim);
}

.macro-trend-grid .mtg-page-hd {
  background: var(--mtg-bg1);
  border-bottom: 1px solid var(--mtg-border-dim);
  color: var(--mtg-text-dim);
  flex-shrink: 0;
  font-size: var(--mtg-fs-sm);
  letter-spacing: 1.4px;
  padding: 12px 14px;
  text-transform: uppercase;
}

.macro-trend-grid .mtg-page-hd--log {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.macro-trend-grid .mtg-log-clear-all {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(74, 143, 160, 0.45);
  color: rgba(255, 255, 255, 0.82);
  cursor: pointer;
  flex-shrink: 0;
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-sm);
  letter-spacing: 0.8px;
  line-height: 1;
  padding: 6px 10px;
  text-transform: uppercase;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.macro-trend-grid .mtg-log-clear-all:hover {
  background: rgba(180, 40, 40, 0.82);
  border-color: rgba(224, 134, 134, 0.55);
  color: #fff;
}

/* ── Toolbar timeframe (H1 / H4 / D1) ── */
.macro-trend-grid__toolbar {
  align-items: center;
  background: var(--mtg-bg1);
  border-bottom: 1px solid var(--mtg-border-dim);
  display: flex;
  flex-shrink: 0;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 14px;
}

/* CPM Alerts — mesma barra da Overview (#tf-bar) */
#view-alertas.al-alerts-desk #al-toolbar.al-tf-bar {
  align-items: center;
  background: var(--bg1, #0a0e14);
  border-bottom: 1px solid var(--border2, rgba(255, 255, 255, 0.08));
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  gap: 3px;
  justify-content: center;
  min-height: 46px;
  padding: 12px 12px 9px;
}

#view-alertas.al-alerts-desk #al-toolbar .al-tf-search-slot {
  display: flex;
  align-items: center;
  min-width: 0;
}

#view-alertas.al-alerts-desk #al-toolbar .al-tf-search-slot .tf-search-wrap,
#view-alertas.al-alerts-desk #al-toolbar .al-tf-candle-slot .candle-preset-wrap {
  margin: 0;
}

#view-alertas.al-alerts-desk #al-toolbar .al-tf-candle-slot {
  display: flex;
  align-items: center;
  min-width: 0;
}

#view-alertas.al-alerts-desk #al-toolbar .tf-sep {
  width: 1px;
  align-self: stretch;
  min-height: 22px;
  margin: 0 6px;
  background: rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

#view-alertas.al-alerts-desk #al-toolbar .tf-btn,
#view-alertas.al-alerts-desk #al-toolbar .tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#view-alertas.al-alerts-desk #al-toolbar .mtg-toolbar-label,
#view-alertas.al-alerts-desk #al-toolbar .mtg-tf-group {
  display: none !important;
}

body.view-alertas-active #view-alertas.al-alerts-desk.monitor-cell-fs #al-toolbar.al-tf-bar {
  display: flex !important;
}

.macro-trend-grid .mtg-toolbar-label {
  color: var(--mtg-text-faint);
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-sm);
  font-weight: 500;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

.macro-trend-grid .mtg-tf-btn.mtg-tf-btn--term {
  display: none;
}

/* Terminal CPM Alerts usa a barra Overview (#al-toolbar) — esconde TF legado do painel MTG */
body.view-alertas-active #ih-panel-macro-trend .macro-trend-grid__toolbar,
body.view-alertas-active #term-alerts-host .macro-trend-grid__toolbar,
#term-alerts-host .macro-trend-grid__toolbar,
#view-alertas .mtg-tf-group,
#view-alertas .mtg-tf-btn,
#view-alertas .mtg-toolbar-label {
  display: none !important;
}

#view-alertas.al-alerts-desk {
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#view-alertas.al-alerts-desk.active {
  display: flex !important;
}

#view-alertas.al-alerts-desk .al-scroll-pages {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #000000;
}

/* Scroll por páginas — cada .al-page = 1 sub-aba (6 gráficos 2×3) */
#view-alertas.al-alerts-desk #al-grid.al-mtg-grid.mtg-grid--term-pages {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  background: #000000;
  padding: 0;
  gap: 0;
}

#view-alertas.al-alerts-desk #al-grid.mtg-grid--term-pages .al-page {
  flex-shrink: 0;
  height: 100%;
  min-height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 1px;
  box-sizing: border-box;
  background: #000000;
}

#view-alertas.al-alerts-desk #al-grid.mtg-grid--term-pages .al-page .mtg-card {
  min-height: 0;
  height: 100%;
  max-height: none;
  display: flex;
  flex-direction: column;
}

#view-alertas.al-alerts-desk #al-grid.mtg-grid--term-pages .al-page .mtg-mountain {
  flex: 1;
  min-height: 0;
  position: relative;
}

#view-alertas.al-alerts-desk .mtg-chart-host {
  position: absolute;
  inset: 0;
  overflow: visible;
  container-type: size;
  container-name: al-chart-host;
}

#view-alertas.al-alerts-desk .mtg-mountain {
  overflow: visible;
}

/* CPM Alerts — Cortex Desk compacto (não cobrir o gráfico / sem faixa preta) */
#view-alertas.al-alerts-desk .mtg-chart-host #imperium-desk.monitor-desk-embedded {
  left: 0;
  bottom: 0;
  width: 248px;
  max-width: 38%;
  height: auto;
  max-height: none;
  overflow: visible;
  z-index: 42;
  background: var(--bg1, #05070a);
  border: 1px solid var(--inst-border, rgba(255, 255, 255, 0.12));
  border-left: none;
  border-bottom: none;
  border-radius: 0;
  box-shadow: none;
  transform-origin: bottom left;
  /* Sempre aplica escala — não depende só de --card/--fs */
  zoom: var(--imd-embed-scale, clamp(0.14, min(28cqw / 248, 46cqh / 280), 0.38));
}

#view-alertas.al-alerts-desk .mtg-chart-host #imperium-desk.monitor-desk-embedded--card {
  zoom: var(--imd-embed-scale, clamp(0.14, min(30cqw / 248, 48cqh / 280), 0.36));
}

#view-alertas.al-alerts-desk .mtg-chart-host #imperium-desk.monitor-desk-embedded--fs {
  max-width: 22%;
  zoom: var(--imd-embed-scale, clamp(0.14, min(22cqw / 248, 40cqh / 280), 0.42));
}

#view-alertas.al-alerts-desk.monitor-cell-fs .mtg-chart-host #imperium-desk.monitor-desk-embedded,
#view-alertas.al-alerts-desk .mtg-card.mt-cell--fs-active .mtg-chart-host #imperium-desk.monitor-desk-embedded {
  width: 248px;
  max-width: 22%;
}

#view-alertas.al-alerts-desk .mtg-chart-host:has(#imperium-desk.monitor-desk-embedded.visible) {
  overflow: visible !important;
}

#view-alertas.al-alerts-desk .mtg-chart-host .mtg-crosshair-time {
  font-size: clamp(7px, 2.4cqw, 10px);
  padding: 1px 6px;
  z-index: 44;
}

#view-alertas.al-alerts-desk .mtg-chart-host:not(.ls-mode),
body.view-alertas-active #view-alertas.al-alerts-desk .mtg-mountain {
  cursor: crosshair;
}

#view-alertas.al-alerts-desk .mtg-chart-host.ls-mode {
  cursor: crosshair;
}

#view-alertas.al-alerts-desk .mtg-card.mt-cell--oms-target {
  border-color: rgba(0, 168, 204, 0.72) !important;
  box-shadow: 0 0 0 1px rgba(0, 168, 204, 0.35), 0 0 14px rgba(0, 168, 204, 0.18);
}

#view-alertas.al-alerts-desk .mtg-card.mt-cell--oms-target .mtg-card-hdr {
  background: rgba(0, 168, 204, 0.08);
}

.macro-trend-grid .mtg-tf-group {
  display: flex;
  gap: 4px;
}

.macro-trend-grid .mtg-tf-btn {
  background: var(--mtg-bg0);
  border: 1px solid var(--mtg-border-dim);
  color: var(--mtg-text-dim);
  cursor: pointer;
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-md);
  font-weight: 600;
  letter-spacing: 1px;
  min-width: 52px;
  padding: 7px 14px;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.macro-trend-grid .mtg-tf-btn:hover {
  border-color: rgba(0, 168, 204, 0.35);
  color: var(--mtg-cyan);
}

.macro-trend-grid .mtg-tf-btn.active {
  background: rgba(0, 168, 204, 0.1);
  border-color: rgba(0, 168, 204, 0.45);
  color: var(--mtg-cyan);
  font-weight: 700;
}

.macro-trend-grid__cards {
  align-content: start;
  display: grid;
  flex: 1;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px 14px 16px;
  scrollbar-color: rgba(0, 168, 204, 0.35) rgba(255, 255, 255, 0.04);
  scrollbar-width: thin;
}

.macro-trend-grid .mtg-page--grid .macro-trend-grid__cards {
  flex: 1 1 auto;
  min-height: calc(100% - 52px);
}

.macro-trend-grid__cards::-webkit-scrollbar { width: 7px; }
.macro-trend-grid__cards::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
}
.macro-trend-grid__cards::-webkit-scrollbar-thumb {
  background: rgba(0, 168, 204, 0.35);
  border-radius: 0;
}
.macro-trend-grid__cards::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 168, 204, 0.55);
}

/* ── Card — ~50% da altura útil por linha (2 linhas visíveis, 3 colunas) ── */
.macro-trend-grid .mtg-card,
.macro-trend-grid .macro-card {
  background: var(--mtg-bg0);
  border: 1px solid var(--mtg-border);
  display: flex;
  flex-direction: column;
  min-height: var(--mtg-row-h);
  min-width: 0;
  overflow: hidden;
  transition: border-color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

.macro-trend-grid .mtg-card-hdr {
  align-items: center;
  background: var(--mtg-bg1);
  border-bottom: 1px solid var(--mtg-border-dim);
  display: flex;
  flex-shrink: 0;
  justify-content: space-between;
  min-height: 48px;
  padding: 10px 14px;
}

.macro-trend-grid .mtg-symbol {
  color: var(--mtg-amber);
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-lg);
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1;
  text-transform: uppercase;
}

.macro-trend-grid .mtg-badge {
  border: 1px solid var(--mtg-border-dim);
  color: var(--mtg-text-dim);
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-sm);
  font-weight: 500;
  letter-spacing: 0.6px;
  line-height: 1.2;
  padding: 5px 10px;
  text-transform: uppercase;
  white-space: nowrap;
  transition: border-color 0.3s ease-in-out, color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

.macro-trend-grid .mtg-badge--amber {
  border-color: rgba(212, 175, 55, 0.28);
  color: var(--mtg-amber);
}

.macro-trend-grid .mtg-badge--cyan {
  border-color: rgba(74, 143, 160, 0.28);
  color: var(--mtg-cyan);
}

.macro-trend-grid .mtg-badge--alert {
  border-color: rgba(74, 143, 160, 0.35);
  color: var(--mtg-cyan);
}

/* ── Área do minichart (motor C++ injeta SVG/Canvas aqui) ── */
.macro-trend-grid .mtg-mountain {
  background: var(--mtg-bg0);
  cursor: grab;
  flex: 1 1 auto;
  height: auto;
  min-height: calc(var(--mtg-row-h) - 52px);
  overflow: hidden;
  position: relative;
  transition: box-shadow 0.3s ease-in-out;
  width: 100%;
}

/* Overlay de ignição — motor C++/JS aplica .cross-bullish / .cross-bearish no card */
.macro-trend-grid .mtg-mountain::after {
  content: '';
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  transition: opacity 0.35s ease-in-out;
  z-index: 2;
}

.macro-trend-grid .mtg-mountain:hover {
  box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.22);
}

.macro-trend-grid .mtg-card[data-chart-ready] .mtg-axis-badges {
  display: none;
}

.macro-trend-grid .mtg-chart-host {
  height: 100%;
  inset: 0;
  position: absolute;
  width: 100%;
  z-index: 3;
}

.macro-trend-grid .mtg-chart-host[data-macro-chart] {
  /* gancho principal — C++ substitui innerHTML ou desenha no canvas filho */
}

.macro-trend-grid .mtg-chart-svg {
  display: block;
  height: 100%;
  pointer-events: none;
  width: 100%;
}

.macro-trend-grid .mtg-grid-line {
  stroke: #0d0d0d;
  stroke-dasharray: 4 5;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.macro-trend-grid .mtg-area {
  opacity: 1;
}

.macro-trend-grid .mtg-line {
  fill: none;
  stroke: var(--mtg-amber-line);
  stroke-linejoin: round;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.macro-trend-grid .mtg-alert-line {
  stroke: var(--mtg-cyan);
  stroke-dasharray: 5 4;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.macro-trend-grid .mtg-watermark {
  fill: rgba(200, 136, 58, 0.08);
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-xl);
  font-weight: 700;
  letter-spacing: 1px;
}

.macro-trend-grid .mtg-loading {
  align-items: center;
  color: var(--mtg-text-faint);
  display: flex;
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-sm);
  inset: 0;
  justify-content: center;
  letter-spacing: 1px;
  pointer-events: none;
  position: absolute;
  text-transform: uppercase;
  z-index: 1;
}

.macro-trend-grid .mtg-loading[hidden],
.macro-trend-grid .mtg-loading.ih-hidden,
.macro-trend-grid .mtg-loading.hidden,
.macro-trend-grid .mtg-card[data-chart-ready] .mtg-loading {
  display: none !important;
}

/* Eixo de preços — badges à direita */
.macro-trend-grid .mtg-axis-badges {
  bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  position: absolute;
  right: 6px;
  top: 8px;
  width: 72px;
  z-index: 2;
}

.macro-trend-grid .mtg-price-badge {
  border: 1px solid transparent;
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-sm);
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1;
  padding: 4px 6px;
  position: absolute;
  right: 0;
  text-align: right;
  white-space: nowrap;
}

.macro-trend-grid .mtg-price-badge--cyan {
  background: var(--mtg-cyan-badge);
  border-color: rgba(74, 143, 160, 0.45);
  color: var(--mtg-cyan);
}

.macro-trend-grid .mtg-price-badge--amber {
  background: var(--mtg-amber-badge);
  border-color: rgba(200, 136, 58, 0.4);
  color: var(--mtg-amber-line);
}

.macro-trend-grid .mtg-price-badge[data-macro-price-level] {
  /* posição Y definida inline pelo motor C++ (top: N%) */
}

/* ── Logs de alertas — página 2 do Alert System ── */
.macro-trend-grid__logs {
  border-top: none;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.macro-trend-grid__logs-hdr {
  background: var(--mtg-bg1);
  border-bottom: 1px solid var(--mtg-border-dim);
  color: var(--mtg-text-dim);
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-sm);
  letter-spacing: 1.2px;
  padding: 8px 14px;
  text-transform: uppercase;
}

.macro-trend-grid .mtg-page--log .macro-trend-grid__logs {
  flex: 1 1 auto;
  min-height: calc(100% - 44px);
}

.macro-trend-grid__logs-body {
  background: var(--mtg-bg0);
  color: var(--mtg-text-dim);
  flex: 1 1 auto;
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-md);
  line-height: 1.55;
  margin: 0;
  min-height: 280px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px 14px 14px;
  scrollbar-width: thin;
  white-space: pre-wrap;
  word-break: break-word;
}

.macro-trend-grid__logs-body:empty::before {
  color: var(--mtg-text-faint);
  content: '— aguardando eventos de alerta do motor —';
  font-style: normal;
  letter-spacing: 0.5px;
}

.macro-trend-grid__logs-body .mtg-log-line {
  align-items: center;
  display: flex;
  gap: 6px;
  min-height: 24px;
}

.macro-trend-grid__logs-body .mtg-log-del {
  align-items: center;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(74, 143, 160, 0.35);
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  display: inline-flex;
  flex-shrink: 0;
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-md);
  height: 22px;
  justify-content: center;
  line-height: 1;
  margin-left: auto;
  padding: 0;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  width: 22px;
}

.macro-trend-grid__logs-body .mtg-log-del:hover {
  background: rgba(180, 40, 40, 0.82);
  border-color: rgba(224, 134, 134, 0.55);
  color: #fff;
}

.macro-trend-grid__logs-body .mtg-log-ts {
  color: var(--mtg-text-faint);
  margin-right: 6px;
}

.macro-trend-grid__logs-body .mtg-log-sym {
  color: var(--mtg-amber);
  margin-right: 6px;
}

.macro-trend-grid__logs-body .mtg-log-px {
  color: var(--mtg-cyan);
  font-weight: 700;
}

/* ── Modal expandir — quase tela cheia ── */
.macro-trend-grid .mtg-expand {
  inset: 0;
  position: fixed;
  z-index: 9000;
}

.macro-trend-grid .mtg-expand.ih-hidden {
  display: none !important;
}

.macro-trend-grid .mtg-expand-backdrop {
  background: rgba(0, 0, 0, 0.88);
  inset: 0;
  position: absolute;
}

.macro-trend-grid .mtg-expand-panel {
  background: var(--mtg-bg0);
  border: 1px solid var(--mtg-border);
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  inset: 20px 24px;
  max-height: none;
  max-width: none;
  position: absolute;
  width: auto;
  left: 20px;
  right: 24px;
  top: 20px;
  bottom: 24px;
}

.macro-trend-grid .mtg-expand-hdr {
  align-items: center;
  background: var(--mtg-bg1);
  border-bottom: 1px solid var(--mtg-border-dim);
  display: flex;
  flex-shrink: 0;
  gap: 12px;
  min-height: 44px;
  padding: 10px 16px;
}

.macro-trend-grid .mtg-expand-title {
  color: var(--mtg-amber);
  font-family: var(--mtg-mono);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 1.2px;
}

.macro-trend-grid .mtg-expand-hint {
  color: var(--mtg-text-faint);
  flex: 1;
  font-family: var(--mtg-mono);
  font-size: var(--mtg-fs-sm);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.macro-trend-grid .mtg-expand-close {
  background: transparent;
  border: 1px solid var(--mtg-border-dim);
  color: var(--mtg-text-dim);
  cursor: pointer;
  font-family: var(--mtg-mono);
  font-size: 22px;
  line-height: 1;
  padding: 8px 12px;
}

.macro-trend-grid .mtg-expand-close:hover {
  border-color: var(--mtg-amber);
  color: var(--mtg-amber);
}

.macro-trend-grid .mtg-expand-body {
  flex: 1;
  min-height: 0;
  position: relative;
}

.macro-trend-grid .mtg-expand-chart-host {
  height: 100%;
  min-height: 0;
  width: 100%;
}

body.terminal-active.monitor-oms-dock.mtg-expand-open .mtg-expand-chart-host,
body.terminal-active.monitor-oms-dock.mtg-expand-open #mtg-expand-host {
  width: 100% !important;
  height: 100% !important;
  min-width: 0;
  box-sizing: border-box;
}

/* Alertas — zoom +1× fora do hub fullscreen (no fullscreen o zoom vem do container) */
body:not(.ih-hub-full) #view-caleco.ih-macro-trend-layout {
  zoom: 1.1;
}

/* Alert System — corpo flexível; scroll em 2 páginas dentro do painel */
#view-caleco.ih-macro-trend-layout .ih-body {
  flex: 1 1 0;
  height: auto;
  max-height: none;
  min-height: 0;
}

#view-caleco.ih-macro-trend-layout .mtg-page--grid {
  min-height: clamp(520px, 72vh, 920px);
}

#view-caleco.ih-macro-trend-layout .mtg-page--log {
  min-height: clamp(360px, 58vh, 720px);
}

#view-caleco.ih-macro-trend-layout .macro-trend-grid__logs-body {
  min-height: 320px;
}

#term-alerts-host .mtg-scroll-pages {
  overflow: hidden;
}

#term-alerts-host .mtg-page--grid {
  min-height: 0;
  flex: 1;
  height: 100%;
}

#term-alerts-host .mtg-page--log {
  display: none;
}

#term-alerts-host .macro-trend-grid__cards.mtg-grid--term-pages {
  scroll-snap-type: y mandatory;
}

#term-alerts-host .mtg-grid--term-pages .mtg-card:nth-child(6n+1) {
  scroll-snap-align: start;
}

@container mtg-scroll (min-height: 280px) {
  #term-alerts-host .macro-trend-grid__cards.mtg-grid--term-pages,
  #term-alerts-host .mtg-grid--term-pages.macro-trend-grid__cards {
    --mtg-row-h: calc(50cqh - 8px);
  }

  #term-alerts-host .mtg-grid--term-pages .mtg-card {
    min-height: calc(50cqh - 8px);
  }

  #term-alerts-host .mtg-grid--term-pages .mtg-mountain {
    min-height: calc(50cqh - 48px);
  }
}

@container mtg-scroll (min-height: 280px) {
  .macro-trend-grid {
    --mtg-row-h: calc(50cqh - 6px);
  }

  .macro-trend-grid .mtg-card {
    min-height: calc(50cqh - 6px);
  }

  .macro-trend-grid .mtg-mountain {
    min-height: calc(50cqh - 46px);
  }
}

/* ═══════════════════════════════════════════════════════════════
   MA200 CROSS — estados dinâmicos (.cross-bullish / .cross-bearish)
   C++: card.classList.add('cross-bullish'|'cross-bearish') + badge text
   ═══════════════════════════════════════════════════════════════ */

@keyframes mtg-cross-pulse-cyan {
  0%, 100% { box-shadow: 0 0 2px rgba(0, 168, 204, 0.2); }
  50% { box-shadow: 0 0 4px rgba(0, 168, 204, 0.75); }
}

@keyframes mtg-cross-pulse-bear {
  0%, 100% { box-shadow: 0 0 2px rgba(232, 160, 32, 0.25); }
  50% { box-shadow: 0 0 4px rgba(220, 72, 58, 0.7); }
}

@keyframes mtg-mountain-ignite-cyan {
  0%, 100% { opacity: 0.12; }
  50% { opacity: 0.28; }
}

@keyframes mtg-mountain-pulse-bear {
  0%, 100% { opacity: 0.14; }
  50% { opacity: 0.32; }
}

/* ── Alta: ignição ciano tech ── */
.macro-trend-grid .mtg-card.cross-bullish,
.macro-trend-grid .macro-card.cross-bullish {
  border-color: rgba(0, 168, 204, 0.42);
  box-shadow: inset 0 0 0 1px rgba(0, 168, 204, 0.12);
}

.macro-trend-grid .mtg-card.cross-bullish .mtg-mountain::after,
.macro-trend-grid .macro-card.cross-bullish .mtg-mountain::after {
  animation: mtg-mountain-ignite-cyan 1.8s ease-in-out infinite;
  background: linear-gradient(
    180deg,
    rgba(0, 168, 204, 0.22) 0%,
    rgba(0, 168, 204, 0.06) 55%,
    transparent 100%
  );
  opacity: 1;
}

.macro-trend-grid .mtg-card.cross-bullish .mtg-chart-host,
.macro-trend-grid .macro-card.cross-bullish .mtg-chart-host {
  filter: drop-shadow(0 0 6px rgba(0, 168, 204, 0.18));
  transition: filter 0.3s ease-in-out;
}

.macro-trend-grid .mtg-card.cross-bullish .mtg-line,
.macro-trend-grid .macro-card.cross-bullish .mtg-line {
  stroke: var(--mtg-cyan-tech);
  transition: stroke 0.3s ease-in-out;
}

.macro-trend-grid .mtg-card.cross-bullish .mtg-area,
.macro-trend-grid .macro-card.cross-bullish .mtg-area {
  fill: rgba(0, 168, 204, 0.24);
  transition: fill 0.3s ease-in-out;
}

.macro-trend-grid .mtg-card.cross-bullish [data-macro-status],
.macro-trend-grid .macro-card.cross-bullish [data-macro-status],
.macro-trend-grid .mtg-card.cross-bullish .mtg-badge--cross-active,
.macro-trend-grid .macro-card.cross-bullish .mtg-badge--cross-active {
  animation: mtg-cross-pulse-cyan 1.6s ease-in-out infinite;
  border-color: rgba(0, 168, 204, 0.65);
  color: var(--mtg-cyan-tech);
  font-weight: 700;
}

/* ── Baixa: pulso âmbar intenso / vermelho saturação ── */
.macro-trend-grid .mtg-card.cross-bearish,
.macro-trend-grid .macro-card.cross-bearish {
  border-color: rgba(220, 72, 58, 0.38);
  box-shadow: inset 0 0 0 1px rgba(232, 160, 32, 0.1);
}

.macro-trend-grid .mtg-card.cross-bearish .mtg-mountain::after,
.macro-trend-grid .macro-card.cross-bearish .mtg-mountain::after {
  animation: mtg-mountain-pulse-bear 1.5s ease-in-out infinite;
  background: linear-gradient(
    180deg,
    rgba(220, 72, 58, 0.2) 0%,
    rgba(232, 160, 32, 0.12) 45%,
    transparent 100%
  );
  opacity: 1;
}

.macro-trend-grid .mtg-card.cross-bearish .mtg-chart-host,
.macro-trend-grid .macro-card.cross-bearish .mtg-chart-host {
  filter: drop-shadow(0 0 7px rgba(220, 72, 58, 0.22));
  transition: filter 0.3s ease-in-out;
}

.macro-trend-grid .mtg-card.cross-bearish .mtg-line,
.macro-trend-grid .macro-card.cross-bearish .mtg-line {
  stroke: var(--mtg-bear-fire);
  transition: stroke 0.3s ease-in-out;
}

.macro-trend-grid .mtg-card.cross-bearish .mtg-area,
.macro-trend-grid .macro-card.cross-bearish .mtg-area {
  fill: rgba(220, 72, 58, 0.18);
  transition: fill 0.3s ease-in-out;
}

.macro-trend-grid .mtg-card.cross-bearish [data-macro-status],
.macro-trend-grid .macro-card.cross-bearish [data-macro-status],
.macro-trend-grid .mtg-card.cross-bearish .mtg-badge--cross-active,.macro-trend-grid .macro-card.cross-bearish .mtg-badge--cross-active {
  animation: mtg-cross-pulse-bear 1.4s ease-in-out infinite;
  border-color: rgba(232, 160, 32, 0.55);
  color: var(--mtg-bear-fire);
  font-weight: 700;
}

/* Gatilho ativo — classe dedicada no badge (texto: ⚡ MA200 CROSS via C++/JS) */
.macro-trend-grid .mtg-badge--cross-active {
  letter-spacing: 0.8px;
  transition: border-color 0.3s ease-in-out, color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

/* Gatilho ativo — data attribute alternativo para C++ */
.macro-trend-grid .macro-card[data-macro-cross="bullish"] [data-macro-status],
.macro-trend-grid .macro-card[data-macro-cross="bearish"] [data-macro-status] {
  font-weight: 700;
}

.macro-trend-grid .macro-card[data-macro-cross="bullish"] {
  border-color: rgba(0, 168, 204, 0.42);
}

.macro-trend-grid .macro-card[data-macro-cross="bearish"] {
  border-color: rgba(220, 72, 58, 0.38);
}

/* ── Overlay GERAL (1 clique ALERTAS) ── */
#mtg-overlay-host {
  position: absolute;
  inset: 0;
  z-index: 220;
  display: none;
  pointer-events: none;
  background: var(--bg0, #000000);
}

body.mtg-overlay-active #mtg-overlay-host {
  display: block;
  pointer-events: auto;
}

body.mtg-overlay-active #mtg-overlay-host #ih-panel-macro-trend,
body.mtg-overlay-active #mtg-overlay-host .macro-trend-grid {
  background: var(--bg0, #000000);
}

body.mtg-overlay-active #mtg-overlay-host .macro-trend-grid__toolbar,
body.mtg-overlay-active #mtg-overlay-host .mtg-card-hdr {
  background: var(--bg1, #05070a);
}

body.mtg-overlay-active #header {
  z-index: 250;
}

#mtg-overlay-host #ih-panel-macro-trend {
  position: absolute;
  inset: 0;
  display: flex !important;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  z-index: auto;
}

body.mtg-overlay-active #chart-stage {
  visibility: hidden !important;
  pointer-events: none !important;
}

body.mtg-overlay-active #imperium-desk {
  display: none !important;
}

body.mtg-overlay-active #imperium-draw-canvas,
body.mtg-overlay-active canvas[id^="imperium-draw-canvas"] {
  visibility: hidden !important;
  pointer-events: none !important;
}

body.mtg-overlay-active #btn-alertas.active,
body.view-geral-active #btn-alertas.active {
  background: #00a8cc;
  border-color: #00a8cc;
  color: #000;
  font-weight: 700;
}

/* ── Terminal — aba ALERTS (painel macro-trend em tela cheia) ── */
.term-alerts-view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg0, #000000);
  z-index: 18;
  overflow: hidden;
}

.term-alerts-view.active {
  display: flex !important;
}

body.terminal-active .term-alerts-view.active {
  top: var(--term-subtabs-h);
}

.term-alerts-host {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--bg0, #000000);
}

#term-alerts-host #ih-panel-macro-trend,
#term-alerts-host .macro-trend-grid {
  position: absolute;
  inset: 0;
  display: flex !important;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--bg0, #000000);
}

#term-alerts-host .macro-trend-grid__toolbar,
#term-alerts-host .mtg-card-hdr {
  background: var(--bg1, #05070a);
}

#term-alerts-host .mtg-page--grid {
  min-height: 0;
  flex: 1;
  height: 100%;
}

#term-alerts-host .mtg-page--log {
  display: none;
}

#term-alerts-host .macro-trend-grid__logs-body {
  min-height: 0;
}

body.view-geral-active #term-alerts-host .macro-trend-grid__toolbar {
  background: var(--inst-panel, #05070a);
  border-bottom: 1px solid var(--inst-border-dim, rgba(255, 255, 255, 0.06));
}

body.view-geral-active #term-alerts-host .mtg-toolbar-label {
  color: var(--inst-text-dim, #6a7884);
  font-family: var(--inst-mono);
}

body.view-geral-active #term-alerts-host .mtg-tf-btn {
  color: var(--inst-text-dim, #6a7884);
  font-family: var(--inst-mono);
}

body.view-geral-active #term-alerts-host .mtg-tf-btn.active {
  background: var(--inst-cyan, #00a8cc);
  border-color: var(--inst-cyan, #00a8cc);
  color: #000;
}

#term-alerts-host .mtg-chart-host.ls-mode,
#mtg-grid .mtg-chart-host.ls-mode,
#mtg-expand-host.ls-mode,
[data-macro-chart-expand].ls-mode {
  cursor: crosshair;
}

#mtg-expand-host:not(.ls-mode) {
  cursor: default;
}

#term-alerts-host .mtg-chart-host:not(.ls-mode),
body.view-alertas-active #term-alerts-host .mtg-mountain {
  cursor: crosshair;
}

.mtg-card--oms-target {
  border-color: rgba(0, 168, 204, 0.72) !important;
  box-shadow: 0 0 0 1px rgba(0, 168, 204, 0.35), 0 0 14px rgba(0, 168, 204, 0.18);
}

.mtg-card--oms-target .mtg-card-hdr {
  background: rgba(0, 168, 204, 0.08);
}

.mtg-card--oms-target .mtg-symbol {
  color: #00a8cc;
}
