/* ════════════════════════════════════════════════════════════════
   Dashboard Financeiro — tema escuro (layout Claude Design)
   Alvo: iPad 4 / Safari iOS 10.3, tela 1024×768, kiosk 24h.
   Animações restritas a opacity e transform (compostas na GPU).
   Fontes do sistema no lugar de webfonts: kiosk não depende de CDN.
   ════════════════════════════════════════════════════════════════ */

:root {
  /* A sintaxe var() é suportada no Safari 10.1; valores centralizados aqui */
  --bg: #0b0d10;
  --bg-raised: #0d0f13;
  --line: rgba(255,255,255,0.07);
  --line-soft: rgba(255,255,255,0.05);
  --text: #f4f5f7;
  --text-2: #e6e8eb;
  --text-sec: #8b93a1;
  --text-muted: #6a7280;
  --text-faint: #565f6c;
  --green: #34c77b;
  --red: #ff5c5c;
  --blue: #4d9fff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

.mono, .clock-main, .clock-secondary, .clock-temp,
.quote-value, .quote-change, .chart-asset-value, .chart-asset-change,
.chart-btn, .chart-pause-label, .news-time, .movers-index-label,
.mover-ticker, .mover-pct, .footer-updated, #night-clock {
  font-family: "SF Mono", Menlo, Monaco, monospace;
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }

/* ── Pixel shift: wrapper de todo o conteúdo ── */
#app-shift {
  height: 100%;
  display: flex;
  flex-direction: column;
  -webkit-transform: translate(0px, 0px);
  transform: translate(0px, 0px);
  will-change: transform;
}

/* ── Pontos pulsantes (status) ── */
@-webkit-keyframes pulseDot {
  0%, 100% { opacity: 1; -webkit-transform: scale(1); }
  50%      { opacity: 0.5; -webkit-transform: scale(1.3); }
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(1.3); }
}
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}
.pulse-dot.ok, .pulse-dot.open {
  background: var(--green);
  -webkit-animation: pulseDot 2.6s ease-in-out infinite;
  animation: pulseDot 2.6s ease-in-out infinite;
}
.pulse-dot.stale { background: var(--red); }

/* ── Cabeçalho ── */
.topbar {
  flex: none;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
}
.date-label {
  font-size: 14px; font-weight: 600;
  letter-spacing: 0.04em;
  color: #c9cdd4;
}
.clocks { display: flex; align-items: center; }
.clock-block {
  display: flex; flex-direction: column; align-items: center;
  line-height: 1;
}
.clock-caption {
  font-size: 9px; font-weight: 600;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 3px;
}
.clock-main { font-size: 26px; font-weight: 600; color: var(--text); }
.clock-secondary { font-size: 19px; font-weight: 600; color: var(--text-sec); }
.clock-divider {
  width: 1px; height: 26px;
  background: rgba(255,255,255,0.09);
  margin: 0 20px;
  flex: none;
}
.header-right { display: flex; align-items: center; }
.market-status { display: flex; align-items: center; margin-left: 14px; }
.market-status:first-child { margin-left: 0; }
.market-status .pulse-dot { margin-right: 7px; }
.market-status-label { font-size: 12px; font-weight: 600; color: var(--text-2); letter-spacing: 0.03em; }
.pulse-dot.closed { background: var(--red); }
.clock-temp { font-size: 10px; color: var(--text-faint); margin-top: 2px; line-height: 1; }
.night-preview-btn {
  background: none; border: none;
  padding: 4px; margin-left: 18px;
  cursor: pointer;
  font-size: 17px; line-height: 1;
  color: #3a4149;
  opacity: 0.75;
}
.night-preview-btn.armed { color: var(--blue); opacity: 1; }

/* ── Grade principal 2×2 (flexbox, sem grid: máxima compatibilidade) ── */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.main-row {
  flex: 1;
  min-height: 0;
  display: flex;
  border-bottom: 1px solid var(--line);
}
.main-row:last-child { border-bottom: none; }
.panel {
  min-width: 0; min-height: 0;
  padding: 20px 26px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-quotes, .panel-news { flex: 1; border-right: 1px solid var(--line); }
.panel-chart, .panel-movers { flex: 1.4; }
.panel-title {
  flex: none;
  margin: 0 0 12px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.panel-head {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-head .panel-title { margin: 0; }

/* ── Cotações ── */
.quotes-grid {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: stretch;
}
.quote-card {
  position: relative;
  width: 50%;
  height: 25%;
  overflow: hidden;           /* degrada sem vazar em alturas menores */
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2px 12px;
  border-radius: 8px;
  background-color: rgba(77,159,255,0);
  transition: background-color 700ms ease;
}
.quote-card.flash { background-color: rgba(77,159,255,0.16); }
/* Movimento forte (|variação| >= ALERT_PCT): borda pulsante.
   Pseudo-elemento animando só opacity — nada de layout/paint pesado. */
@-webkit-keyframes alertPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.15; } }
@keyframes alertPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.15; } }
.quote-card.alert::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: 8px;
  pointer-events: none;
  -webkit-animation: alertPulse 1.8s ease-in-out infinite;
  animation: alertPulse 1.8s ease-in-out infinite;
}
.quote-card.alert.alert-up::after { border: 1px solid rgba(52,199,123,0.7); }
.quote-card.alert.alert-down::after { border: 1px solid rgba(255,92,92,0.7); }
.quote-name {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.quote-value { font-size: 20px; font-weight: 600; color: var(--text); margin: 2px 0; }
.quote-change { font-size: 13px; font-weight: 600; }
.quote-change.up { color: var(--green); }
.quote-change.down { color: var(--red); }
.quote-change.na { color: var(--text-faint); }

/* ── Gráfico ── */
.chart-quote { display: flex; align-items: baseline; }
.chart-asset-label {
  font-size: 12px; font-weight: 600;
  color: var(--text-sec); letter-spacing: 0.04em;
  margin-right: 10px;
}
.chart-asset-value { font-size: 15px; font-weight: 600; color: var(--text-2); margin-right: 10px; }
.chart-asset-change { font-size: 13px; font-weight: 600; }
.chart-asset-change.up { color: var(--green); }
.chart-asset-change.down { color: var(--red); }
.chart-box { flex: 1; min-height: 0; }
#chart-svg { width: 100%; height: 100%; display: block; }
.chart-gridline { stroke: var(--line-soft); stroke-width: 1; }
.chart-buttons { flex: none; display: flex; align-items: center; margin-top: 12px; }
.chart-btn {
  font-size: 13px; font-weight: 600;
  padding: 7px 16px;
  margin-right: 8px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.03em;
  background: transparent;
  color: var(--text-sec);
  border: 1px solid rgba(255,255,255,0.08);
}
.chart-btn.active {
  background: rgba(77,159,255,0.14);
  color: #dce6f5;
  border-color: rgba(77,159,255,0.4);
}
/* Progresso da rotação: animado via scaleX (nunca width) */
.chart-progress-track {
  flex: none;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.07);
  overflow: hidden;
  margin-top: 10px;
}
.chart-progress-fill {
  height: 100%;
  background: var(--green);
  -webkit-transform-origin: left center;
  transform-origin: left center;
  -webkit-transform: scaleX(0);
  transform: scaleX(0);
  transition: -webkit-transform 1s linear;
  transition: transform 1s linear;
}
.chart-pause-label { flex: none; margin-top: 10px; font-size: 11px; color: var(--text-sec); }

/* ── Notícias ── */
.news-list { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.news-item {
  display: flex;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  opacity: 1;
  -webkit-transform: translateY(0);
  transform: translateY(0);
  transition: opacity 500ms ease, -webkit-transform 500ms ease;
  transition: opacity 500ms ease, transform 500ms ease;
}
.news-item.entering {
  opacity: 0;
  -webkit-transform: translateY(-8px);
  transform: translateY(-8px);
}
.news-time {
  flex: none;
  width: 42px;
  font-size: 12px;
  color: var(--text-faint);
  padding-top: 2px;
}
.news-body { display: flex; flex-direction: column; min-width: 0; margin-left: 14px; }
.news-title { font-size: 14.5px; font-weight: 500; line-height: 1.35; color: var(--text-2); }
.news-source {
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Movers ── */
.movers-index-label { font-size: 11px; font-weight: 600; color: var(--blue); letter-spacing: 0.04em; }
.movers-body {
  flex: 1;
  min-height: 0;
  display: flex;
  opacity: 1;
  transition: opacity 320ms ease;
}
.movers-body.fading { opacity: 0; }
.movers-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.movers-col:first-child { margin-right: 22px; }
.movers-col-title {
  flex: none;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.movers-col-title.gainers { color: var(--green); }
.movers-col-title.losers { color: var(--red); }
/* Linha condensada: ticker + nome + barra proporcional + % em uma linha,
   preenchendo o vazio horizontal e liberando altura para 7 papéis */
.mover-row {
  display: flex;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.mover-ticker { flex: none; width: 58px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.mover-name {
  flex: none; width: 62px;
  font-size: 10px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Barra proporcional à variação (escala pelo maior |%| do índice) */
.mover-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.05);
  margin: 0 10px 0 8px;
  overflow: hidden;
}
.mover-bar-fill { height: 100%; border-radius: 2px; }
.mover-bar-fill.up { background: var(--green); opacity: 0.75; }
.mover-bar-fill.down { background: var(--red); opacity: 0.75; }
.mover-pct { flex: none; width: 74px; text-align: right; font-size: 13px; font-weight: 600; white-space: nowrap; }
.mover-pct.up { color: var(--green); }
.mover-pct.down { color: var(--red); }

/* Amplitude do mercado: quantos papéis do universo sobem/estabilizam/caem */
.movers-breadth { flex: none; display: flex; align-items: center; margin-top: 10px; }
.breadth-caption {
  flex: none;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted);
}
.breadth-bar {
  flex: 1;
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin: 0 12px;
  background: rgba(255,255,255,0.05);
}
.breadth-seg { height: 100%; }
.breadth-seg.up { background: var(--green); }
.breadth-seg.flat { background: rgba(255,255,255,0.18); }
.breadth-seg.down { background: var(--red); }
.breadth-label { flex: none; font-size: 11px; font-weight: 600; color: var(--text-sec); }

/* ── Rodapé ── */
.footer {
  flex: none;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: var(--bg-raised);
}
.footer-updated { font-size: 11px; color: var(--text-faint); }
.footer-sources { font-size: 11px; color: #4a525d; letter-spacing: 0.02em; }
.footer-status { display: flex; align-items: center; }
.footer-status .pulse-dot { width: 6px; height: 6px; margin-right: 6px; }
.footer-status-label { font-size: 11px; font-weight: 500; color: var(--text-sec); }

/* ── Modo noturno ── */
#night-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: #000;
  z-index: 2147483647;
  cursor: pointer;
}
#night-overlay.active { display: block; }
/* Brilho global reduzido enquanto o modo noturno está ativo */
html.night-mode #app-shift {
  -webkit-filter: brightness(0.03);
  filter: brightness(0.03);
}
/* Relógio residual: quase apagado, deriva lentamente (anti burn-in) */
#night-content {
  position: absolute;
  top: 50%; left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  transition: -webkit-transform 20s linear;
  transition: transform 20s linear;
}
#night-clock {
  font-size: 19px; font-weight: 500;
  color: #2a2f36;
  letter-spacing: 0.02em;
}
#night-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #4a525d;
  opacity: 0.3;
  margin-top: 7px;
}
#night-dot.open { background: var(--green); }
